Moved proofs into appendix (S3, S4)

master
Aaron Huber 2020-12-17 16:40:48 -05:00
parent 14cd501bfe
commit 7c4949ab6c
5 changed files with 308 additions and 393 deletions

View File

@ -1,6 +1,5 @@
%root: main.tex
\section{$1 \pm \epsilon$ Approximation Algorithm}
\label{sec:algo}
\section{$1 \pm \epsilon$ Approximation Algorithm}\label{sec:algo}
In~\cref{sec:hard}, we showed that computing the expected multiplicity of a compressed representation of a bag polynomial for TIDB (even just based on project-join queries) is unlikely to be possible in linear time (\cref{thm:mult-p-hard-result}), even if all tuples have the same probability of being present (\cref{cor:single-p-hard}). Given this, in this section we will design an approximation algorithm for our problem that runs in {\em linear time}. Unlike the results in~\cref{sec:hard} our approximation algorithm works for BIDB though our bounds are more meaningful for a non-trivial subclass of BIDB that includes TIDB as well as PDB benchmarks (\cref{sec:experiments}).
%it is then desirable to have an algorithm to approximate the multiplicity in linear time, which is what we describe next.
@ -170,6 +169,8 @@ P\left(\left|\mathcal{E} - \rpoly(\prob_1,\dots,\prob_\numvar)\right|> \error' \
%with multiplicative $(\error,\delta)$-bounds, where $k$ denotes the degree of $\poly$.
\end{Theorem}
The proof of~\Cref{lem:approx-alg} can be found in~\Cref{sec:proofs-approx-alg}.
It turns out that to get linear runtime results from~\cref{lem:approx-alg}, we will need to define another parameter (which roughly counts the (weighted) number of monomials in $\expandtree{\etree}$ that get `canceled' when modded with $\mathcal{B}$):
\begin{Definition}[Parameter $\gamma$]\label{def:param-gamma}
Given an expression tree $\etree$, define
@ -185,23 +186,14 @@ Let $\poly(\vct{X})$ be as in~\Cref{lem:approx-alg} and let $\gamma=\gamma(\etre
\[O\left(\treesize(\etree) + \frac{\log{\frac{1}{\conf}}\cdot k\cdot \log{k} \cdot depth(\etree))}{\inparen{\error'}^2\cdot(1-\gamma)^2\cdot p_0^{2k}}\right)\]
In particular, if $p_0>0$ and $\gamma<1$ are absolute constants then the above runtime simplifies to $O_k\left(\frac 1{\eps^2}\cdot\treesize(\etree)\cdot \log{\frac{1}{\conf}}\right)$.
\end{Corollary}
The proof for~\Cref{cor:approx-algo-const-p} can be seen in~\Cref{sec:proofs-approx-alg}.
We note that the restriction on $\gamma$ is satisfied by TIDB (where $\gamma=0$) and for some BIDB benchmarks (see~\Cref{sec:experiments} for more on this claim).
\AH{I am thinking that perhaps the terminology and presentation of~\Cref{sec:experiments} may need word-smithing to clearly illustrate the $\bi$ benchmarks satisfied--although the substance is already written there.}
\AR{Yes! E.g. $\gamma$ is not used at all in~\Cref{sec:experiments}}
\AR{{\bf Boris/Oliver:} Is there a way to claim that all probabilities in practice are actually constants: i.e. they do not increase with the number of tuples?}
\begin{proof}[Proof of~\Cref{cor:approx-algo-const-p}]
The result follows by first noting that by definition of $\gamma$, we have
%\AH{Just wondering why you use $\geq$ as opposed to $=$?}
%\AR{Ah, right-- fixed}
\[\rpoly(1,\dots,1)= (1-\gamma)\cdot \abs{\etree}(1,\dots,1).\]
Further, since each $p_i\ge p_0$ and $\poly(\vct{X})$ (and hence $\rpoly(\vct{X})$) has degree at most $k$, we have that
\[ \rpoly(1,\dots,1) \ge p_0^k\cdot \rpoly(1,\dots,1).\]
The above two inequalities implies $\rpoly(1,\dots,1) \ge p_0^k\cdot (1-\gamma)\cdot \abs{\etree}(1,\dots,1)$.
%\AH{This looks really nice!}
Applying this bound in the runtime bound in~\Cref{lem:approx-alg} gives the first claimed runtime. The final runtime of $O_k\left(\frac 1{\eps^2}\cdot\treesize(\etree)\cdot \log{\frac{1}{\conf}}\right)$ follows by noting that $depth(\etree)\le \treesize(\etree)$ and absorbing all factors that just depend on $k$.
\end{proof}
\subsection{Approximating $\rpoly$}
The algorithm to prove~\Cref{lem:approx-alg} follows from the following observation. Given a query polynomial $\poly(\vct{X})=poly(\etree)$ for expression tree $\etree$ over $\bi$, we note that we can exactly represent $\rpoly(\vct{X}$ as follows:
@ -360,7 +352,7 @@ In proving correctness of~\Cref{alg:mon-sam}, we will only use the following fac
The function $\sampmon$ completes in $O(\log{k} \cdot k \cdot depth(\etree))$ time, where $k = \degree(poly(\abs{\etree})$. Upon completion, every $\left(\monom, sign(\coef)\right)\in \expandtree{\abs{\etree}}$ is returned with probability $\frac{|\coef|}{\abs{\etree}(1,\ldots, 1)}$. %, $\sampmon$ returns the sampled term $\left(\monom, sign(\coef)\right)$ from $\expandtree{\abs{\etree}}$.
\end{Lemma}
Armed with the above two lemmas, we are ready to argue the following result:
Armed with the above two lemmas, we are ready to argue the following result (proof in~\Cref{sec:proofs-approx-alg}):
\begin{Theorem}\label{lem:mon-samp}
%If the contracts for $\onepass$ and $\sampmon$ hold, then
For any $\etree$ with $\degree(poly(|\etree|)) = k$, algorithm \ref{alg:mon-sam} outputs an estimate $\vari{acc}$ of $\rpoly(\prob_1,\ldots, \prob_\numvar)$ such that %$\expct\pbox{\empmean} = \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot(1 - \gamma)}{\abs{\etree}(1,\ldots, 1)}$. %within an additive $\error \cdot \abs{\etree}(1,\ldots, 1)$ error with
@ -369,108 +361,6 @@ $\empmean$ has bounds
in $O\left(\treesize(\etree)\right.$ $+$ $\left.\left(\frac{\log{\frac{1}{\conf}}}{\error^2} \cdot k \cdot\log{k} \cdot depth(\etree)\right)\right)$ time.
\end{Theorem}
Before proving~\Cref{lem:mon-samp}, we use it to argue our main result:
\begin{proof}[Proof of Theorem \ref{lem:approx-alg}]
%\begin{Corollary}\label{cor:adj-err}
Set $\mathcal{E}=\approxq(\etree, (p_1,\dots,p_\numvar),$ $\conf, \error')$, where
\[\error' = \error \cdot \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot (1 - \gamma)}{\abs{\etree}(1,\ldots, 1)},\]
which achieves the claimed accuracy bound on $\mathcal{E}$.
% achieves $1 \pm \epsilon$ multiplicative error bounds, in $O\left(\treesize(\etree) + \frac{\log{\frac{1}{\conf}}\cdot \abs{\etree}^2(1,\ldots, 1)}{\error^2\cdot\rpoly^2(\prob_1,\ldots, \prob_\numvar)(1 - \gamma)^2}\right)$.
%\end{Corollary}
%Since it is the case that we have $\error \cdot \abs{\etree}(1,\ldots, 1)$ additive error, one can set $\error = \error \cdot \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot (1 - \gamma)}{\abs{\etree}(1,\ldots, 1)}$, yielding a multiplicative error proportional to $\rpoly(\prob_1,\ldots, \prob_\numvar)$. This only affects the runtime in the number of samples taken, changing the first factor of the second summand of the original runtime accordingly.
%The derivation over the number of samples is then
The claim on the runtime follows since
\begin{align*}
\frac 1{\inparen{\error'}^2}\cdot \log\inparen{\frac 1\conf}=&\frac{\log{\frac{1}{\conf}}}{\error^2 \left(\frac{\rpoly(\prob_1,\ldots, \prob_N)}{\abs{\etree}(1,\ldots, 1)}\right)^2}\\
= &\frac{\log{\frac{1}{\conf}}\cdot \abs{\etree}^2(1,\ldots, 1)}{\error^2 \cdot \rpoly^2(\prob_1,\ldots, \prob_\numvar)},
\end{align*}
%and the runtime then follows, thus upholding ~\cref{lem:approx-alg}.
which completes the proof.
\end{proof}
\qed
We now return to the proof of~\Cref{lem:mon-samp}:
\begin{proof}[Proof of Theorem \ref{lem:mon-samp}]
%As previously noted, by lines ~\ref{alg:mon-sam-check} and ~\ref{alg:mon-sam-drop} the algorithm will resample when it encounters a sample with variables from the same block. The probability of sampling such a monomial is $\gamma$.
%Now, consider $\expandtree{\etree}$ and let $(\monom, \coef)$ be an arbitrary tuple in $\expandtree{\etree}$. For convenience, over an alphabet $\Sigma$ of size $\numvar$, define
%\begin{equation*}
%\evalmp: \left(\left\{\monom^a~|~\monom \in \Sigma^b, a \in \mathbb{N}, b \in [k]\right\}, [0, 1]^\numvar\right)\mapsto \mathbb{R},
%\end{equation*}
%a function that takes a monomial $\monom$ in $\left\{\monom^a ~|~ \monom \in \Sigma^b, a \in \mathbb{N}, b \in [k]\right\}$ and probability vector $\vct{p}$ (introduced in ~\cref{subsec:def-data}) as input and outputs the evaluation of $\monom$ over $\vct{p}$. By ~\cref{lem:sample}, the sampling scheme samples $(\monom, \coef)$ in $\expandtree{\etree}$ with probability $\frac{|\coef|}{\abs{\etree}(1,\ldots, 1)}$. Note that $\coef \cdot \evalmp(\monom, \vct{p})$ is the value of $(\monom, \coef)$ in $\expandtree{\etree}$ when all variables in $\monom$ are assigned their corresponding probabilities.
%Let $Vars(\monom) = \{X_{\block, i} \st X_{\block, i} \in \monom\}$. Define the set of elements containing no cross-terms in $\expandtree{\etree}$ as $\expandtree{\etree}' = \{(\monom, \coef) \st \forall (\monom, \coef) \in \expandtree{\etree}, \forall X_{\block, i}, X_{\block', j} \in Vars(\monom), \block \neq \block'\}$.
%Note again that the sum of $\coef \cdot \evalmp(\monom, \vct{p})$ over $\expandtree{\etree}'$ is equivalently $\rpoly(\prob_1,\ldots, \prob_\numvar)$.
Consider now the random variables $\randvar_1,\dots,\randvar_\numvar$, where each $\randvar_i$ is the value of $\vari{Y}_{\vari{i}}$ after~\Cref{alg:mon-sam-product} is executed. In particular, note that we have
\[Y_i= \onesymbol\inparen{\monom\mod{\mathcal{B}}\not\equiv 0}\cdot \prod_{X_i\in \var\inparen{v}} p_i,\]
where the indicator variable handles the check in~\Cref{alg:check-duplicate-block}
Then for random variable $\randvar_i$, it is the case that
\[\expct\pbox{\randvar_i} = \sum\limits_{(\monom, \coef) \in \expandtree{\etree} }\frac{\onesymbol\inparen{\monom\mod{\mathcal{B}}\not\equiv 0}\cdot c\cdot\prod_{X_i\in \var\inparen{v}} p_i }{\abs{\etree}(1,\dots,1)} = \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)}{\abs{\etree}(1,\ldots, 1)},\]
where in the first equality we use the fact that $\vari{sgn}_{\vari{i}}\cdot \abs{\coef}=\coef$ and the second equality follows from~\cref{eq:tilde-Q-bi} with $X_i$ substituted by $\prob_i$.
%\AH{I have always kind of 'tripped' when folks talk like this. Isn't it more accurate to say that the last equality follows by the \emph{construction} of~\cref{eq:tilde-Q-bi}, and this construction is equivalent of $\rpoly(\prob_1,\ldots, \prob_\numvar)$?}
%\AR{Added that the $X_i$ are subtituted by $p_i$. But it seems like you are tripping on something else. I'm not sure what you mean by \emph{construction} of~\cref{eq:tilde-Q-bi}? \cref{eq:tilde-Q-bi} is an identity and we just use it here.}
% = \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot (1 - \gamma)}{\abs{\etree}(1,\ldots, 1)}.\]
Let $\empmean = \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i$. It is also true that
\[\expct\pbox{\empmean} %\expct\pbox{ \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i}
= \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\expct\pbox{\randvar_i}
%&= \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\sum\limits_{(\monom, \coef) \in \expandtree{\etree}'}\frac{\coef \cdot \evalmp(\monom, \vct{p})}{\sum\limits_{(\monom, \coef) \in \expandtree{\etree}'}}
= \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)}{\abs{\etree}(1,\ldots, 1)}.\]
Hoeffding's inequality %can be used to compute an upper bound on the number of samples $\samplesize$ needed to establish the $(\error, \conf)$-bound. The inequality
states that if we know that each $\randvar_i$ (which are all independent) always lie in the intervals $[a_i, b_i]$, then it is true that
\begin{equation*}
P\left(\left|\empmean - \expct\pbox{\empmean}\right| \geq \error\right) \leq 2\exp{\left(-\frac{2\samplesize^2\error^2}{\sum_{i = 1}^{\samplesize}(b_i -a_i)^2}\right)}.
\end{equation*}
%As implied above, Hoeffding is assuming the sum of random variables be divided by the number of variables. Since $\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot(1 - \gamma) = \expct\pbox{\empmean} \cdot \abs{\etree}(1,\ldots, 1)$, then our estimate is the sum of random samples multiplied by $\frac{\abs{\etree}(1,\ldots, 1)}{\samplesize \cdot (1 - \gamma)}$. This computation is performed on ~\cref{alg:mon-sam-global3}.
%Also see that to properly estimate $\rpoly$, it is necessary to multiply by the number of monomials in $\rpoly$, i.e. $\abs{\etree}(1,\ldots, 1)$. Therefore it is the case that $\frac{acc}{N}$ gives the estimate of one monomial, and multiplying by $\abs{\etree}(1,\ldots, 1)$ yields the estimate of $\rpoly(\prob_1,\ldots, \prob_\numvar)$. This scaling is performed in line ~\ref{alg:mon-sam-global3}.
Line ~\ref{alg:mon-sam-sample} shows that $\vari{sgn}_\vari{i}$ has a value in $\{-1, 1\}$ that is multiplied with $O(k)$ %at most $\degree(\polyf(\abs{\etree}))$ factors from $\vct{p}$ (\cref{alg:mon-sam-product2}) such that each
$p_i\in [0, 1]$, the range for each $\randvar_i$ is $[-1, 1]$. % Bounding Hoeffding's results by $\conf$ ensures confidence no less than $1 - \conf$. Then by upper bounding Hoeffding with $\frac{\conf}{2}$ (since we take an additional estimate of $\gamma$), it is the case that
Using Hoeffding's inequality, we then get:
\begin{equation*}
P\pbox{~\left| \empmean - \expct\pbox{\empmean} ~\right| \geq \error} \leq 2\exp{\left(-\frac{2\samplesize^2\error^2}{2^2 \samplesize}\right)} = 2\exp{\left(-\frac{\samplesize\error^2}{2 }\right)}\leq \conf,
\end{equation*}
where the last inequality follows from our choice of $\samplesize$ in~\Cref{alg:mon-sam-global2}.
%\AH{What do you mean by the last inequality following from our choic of $\samplesize$? do you mean that our choice of $\samplesize$ is governed by the value of $\conf$?}
%\AR{Added in refernce to relevant line number.}
%Solving for the number of samples $\samplesize$ we get
%\begin{align}
%&\frac{\conf}{2} \geq 2\exp{-\left(\frac{2\samplesize^2\error^2}{4\samplesize}\right)}\label{eq:hoeff-1}\\
%&\frac{\conf}{2} \geq \exp{-\left(\frac{2\samplesize^2\error^2}{4\samplesize}\right)}\label{eq:hoeff-2}\\
%&\frac{2}{\conf} \leq \exp{\left(\frac{2\samplesize^2\error^2}{4\samplesize}\right)}\label{eq:hoeff-3}\\
%&\log{\frac{2}{\conf}} \leq \left(\frac{2\samplesize^2\error^2}{4\samplesize}\right)\label{eq:hoeff-4}\\
%&\log{\frac{2}{\conf}} \leq \frac{\samplesize\error^2}{2}\label{eq:hoeff-5}\\
%&\frac{2\log{\frac{4}{\conf}}}{\error^2} \leq \samplesize.\label{eq:hoeff-6}
%\end{align}
%By Hoeffding we obtain the number of samples necessary to achieve the claimed additive error bounds.
This concludes the proof for the first claim of theorem ~\ref{lem:mon-samp}.
\paragraph{Run-time Analysis}
%For a $\bi$ instance, it is possible that cancellations can occur as seen in ~\cref{alg:mon-sam-drop}, and by ~\cref{alg:mon-sam-resamp} the algorithm will then re-sample. This affects the overall runtime. Let us denote by $\gamma$ the number of cancellations.
%Note that lines ~\ref{alg:mon-sam-global1}, ~\ref{alg:mon-sam-global2}, and ~\ref{alg:mon-sam-global3} are $O(1)$ global operations. The call to $\onepass$ in line ~\ref{alg:mon-sam-onepass} by lemma ~\ref{lem:one-pass} is $O(\treesize(\etree))$ time.
%First, algorithm ~\ref{alg:mon-sam} calls \textsc{OnePass} which takes $O(|\etree|)$ time.
%Then for $\numsamp = \ceil{\frac{2 \log{\frac{4}{\conf}}}{\error^2}}$, the $O(1)$ assignment, product, and addition operations occur. Over the same $\numsamp$ iterations, $\sampmon$ is called, with a runtime of $O(\log{k}\cdot k \cdot depth(\etree))$ by lemma ~\ref{lem:sample}. Finally, over the same iterations, because $\degree(\polyf(\abs{\etree})) = k$, the assignment and product operations of line ~\ref{alg:mon-sam-product2} are called at most $k$ times.
%Thus we have $O(\treesize(\etree)) + O(\left(\frac{\log{\frac{1}{\conf}}}{\error^2}\right) \cdot \left(k + \log{k}\cdot k \cdot depth(\etree)\right) = O\left(\treesize(\etree) + \left(\left(\frac{\log{\frac{1}{\conf}}}{\error^2}\right) \cdot \left(k \cdot\log{k} \cdot depth(\etree)\right)\right)\right)$ overall running time.
The runtime of the algorithm is dominated by~\Cref{alg:mon-sam-onepass} (which by~\Cref{lem:one-pass} takes time $O(size(\etree))$) and the $\samplesize$ iterations of the loop in~\Cref{alg:sampling-loop}. Each iteration's run time is dominated by the call to~\Cref{alg:mon-sam-sample} (which by~\Cref{lem:sample} takes $O(\log{k} \cdot k \cdot depth(\etree))$) and~\Cref{alg:check-duplicate-block}, which by the subsequent argument takes $O(k\log{k})$ time. We sort the $O(k)$ variables by their block IDs and then check if there is a duplicate block ID or not. Adding up all the times discussed here gives us the desired overall runtime.
\end{proof}
\qed
\subsection{\onepass\ Algorithm}
\label{sec:onepass}
@ -641,32 +531,7 @@ level 2/.style={sibling distance=0.7cm},
\end{figure}
We prove the correctness of Algorithm ~\ref{alg:one-pass} by proving~\Cref{lem:one-pass}:
\begin{proof}[Proof of~\Cref{lem:one-pass}]
We prove the first part of lemma ~\ref{lem:one-pass}, i.e., correctness, by structural induction over the depth $d$ of the binary tree $\etree$.
For the base case, $d = 0$, it is the case that the node is a leaf and therefore by definition ~\ref{def:express-tree} must be a variable or coefficient. When it is a variable, \textsc{OnePass} returns $1$, and we have in this case that $\polyf(\etree) = X_i = \polyf(\abs{\etree})$ for some $i$ in $[\numvar]$, and this evaluated at all $1$'s indeed gives $1$, verifying the correctness of the returned value of $\abs{\etree}(1,\ldots, 1) = 1$. When the root is a coefficient, the absolute value of the coefficient is returned, which is indeed $\abs{\etree}(1,\ldots, 1)$. This proves the base case.
%\AH{The inductive step assumes $k \geq 0$ rather than $k \geq 1$, correct?}
%\AR{yep!}
For the inductive hypothesis, assume that for $d \leq k$ for some $k \geq 0$,~\Cref{lem:one-pass} is true for~\Cref{alg:one-pass}.
Now prove that lemma ~\ref{lem:one-pass} holds for $k + 1$. Notice that $\etree$ has at most two children, $\etree_\lchild$ and $\etree_\rchild$. Note also, that for each child, it is the case that $d \leq k$. Then, by inductive hypothesis, lemma ~\ref{lem:one-pass} holds for each existing child, and we are left with two possibilities for $\etree$. The first case is when $\etree$ is a $+$ node. When this happens,~\Cref{alg:one-pass} computes $|T_\lchild|(1,\ldots, 1) + |T_\rchild|(1,\ldots, 1)$ on line ~\ref{alg:one-pass-plus-add} which by definition is $\abs{\etree}(1,\ldots, 1)$ and hence the inductive hypothesis holds in this case. For the weight computation of the children of $+$, by lines ~\ref{alg:one-pass-plus-add}, ~\ref{alg:one-pass-plus-assign2}, and ~\ref{alg:one-pass-plus-prob} algorithm ~\ref{alg:one-pass} computes $\etree_i.\wght = \frac{|T_i|(1,\ldots, 1)}{|T_\lchild|(1,\ldots, 1) + |T_\rchild|(1,\ldots, 1)}$ which is indeed as claimed. The second case is when the $\etree.\val = \times$. By inductive hypothesis, it is the case that both $\abs{\etree_\lchild}\polyinput{1}{1}$ and $\abs{\etree_\rchild}\polyinput{1}{1}$ have been correctly computed. On line~\ref{alg:one-pass-times-product} algorithm ~\ref{alg:one-pass} then computes the product of the subtree partial values, $|T_\lchild|(1,\ldots, 1) \cdot |T_\rchild|(1,\ldots, 1)$ which by definition is $\abs{\etree}(1,\ldots, 1)$.
%That $\onepass$ makes exactly one traversal of $\etree$ follows by noting for lines ~\ref{alg:one-pass-equality1} and ~\ref{alg:one-pass-equality2} are the checks for the non-base cases, where in each matching exactly one recursive call is made on each of $\etree.\vari{children}$. For the base cases, lines ~\ref{alg:one-pass-equality3} and ~\ref{alg:one-pass-equality4} both return values without making any further recursive calls. Since all nodes are covered by the cases, and the base cases cover only leaf nodes, it follows that algorithm ~\ref{alg:one-pass} then terminates after it visits every node exactly one time.
%To conclude, note that when $\etree.\type = +$, the compuatation of $\etree_\lchild.\wght$ and $\etree_\rchild.\wght$ are solely dependent on the correctness of $\abs{\etree}\polyinput{1}{1}$, $\abs{\etree_\lchild}\polyinput{1}{1}$, and $\abs{\etree_\rchild}\polyinput{1}{1}$, which have already been argued to be correct.
\paragraph{Run-time Analysis}
The runtime for \textsc{OnePass} is fairly straight forward. Note first that each node is visited at most one time. Second, for each type of node visited, it can be trivially verified that there are only a constant number of operations. This concludes then with a $O\left(\treesize(\etree)\right)$ runtime.
%Note that line ~\ref{alg:one-pass-equality1}, ~\ref{alg:one-pass-equality2}, and ~\ref{alg:one-pass-equality3} give a constant number of equality checks per node. Then, for $+$ nodes, lines ~\ref{alg:one-pass-plus-add} and ~\ref{alg:one-pass-plus-prob} perform a constant number of arithmetic operations, while ~\ref{alg:one-pass-plus-assign1} ~\ref{alg:one-pass-plus-assign2}, and ~\ref{alg:one-pass-times-assign3} all have $O(1)$ assignments. Similarly, when a $\times$ node is visited, lines \ref{alg:one-pass-times-assign1}, \ref{alg:one-pass-times-assign2}, and \ref{alg:one-pass-times-assign3} have $O(1)$ assignments, while line ~\ref{alg:one-pass-times-product} has $O(1)$ product operations per node. For leaf nodes, ~\cref{alg:one-pass-leaf-assign1} and ~\cref{alg:one-pass-global-assign} are both $O(1)$ assignment.
%Thus, the algorithm visits each node of $\etree$ one time, with a constant number of operations for all of the $+$, $\times$, and leaf nodes, leading to a runtime of $O\left(\treesize(\etree)\right)$, and this completes the proof.
\end{proof}
\qed
We prove the correctness of Algorithm ~\ref{alg:one-pass} by proving~\Cref{lem:one-pass} in~\Cref{sec:proofs-approx-alg}.
\subsection{\sampmon\ Algorithm}
\label{sec:samplemonomial}
@ -720,73 +585,7 @@ See algorithm ~\ref{alg:sample} for the details of $\sampmon$ algorithm.
\end{algorithmic}
\end{algorithm}
We argue the correctness of Algorithm ~\ref{alg:sample} by proving~\Cref{lem:sample}:
\begin{proof}[Proof of~\Cref{lem:sample}]
First, we need to show that $\sampmon$ indeed returns a monomial $\monom$,\footnote{Technically it returns $\var(\monom)$ but for less cumbersome notation we will refer to $\var(\monom)$ simply by $\monom$ in this proof.} such that $(\monom, \coef)$ is in $\expandtree{\etree}$, which we do by induction on the depth of $\etree$.
For the base case, let the depth $d$ of $\etree$ be $0$. We have that the root node is either a constant $\coef$ for which by line ~\ref{alg:sample-num-return} we return $\{~\}$, or we have that $\etree.\type = \var$ and $\etree.\val = x$, and by line ~\ref{alg:sample-var-return} we return $\{x\}$. Both cases sample a monomial%satisfy ~\cref{def:monomial}
, and the base case is proven.
For the inductive hypothesis, assume that for $d \leq k$ for some $k \geq 0$, that it is indeed the case that $\sampmon$ returns a monomial.
For the inductive step, let us take a tree $\etree$ with $d = k + 1$. Note that each child has depth $d \leq k$, and by inductive hypothesis both of them return a valid monomial. Then the root can be either a $+$ or $\times$ node. For the case of a $+$ root node, line ~\ref{alg:sample-plus-bsamp} of $\sampmon$ will choose one of the children of the root. Since by inductive hypothesis it is the case that a monomial is being returned from either child, and only one of these monomials is selected, we have for the case of $+$ root node that a valid monomial is returned by $\sampmon$. When the root is a $\times$ node, lines ~\ref{alg:sample-times-union} and ~\ref{alg:sample-times-product} multiply the monomials returned by the two children of the root, and it is trivial to see that %by definition ~\ref{def:monomial}
the product of two monomials is also a monomial, which means that $\sampmon$ returns a valid monomial for the $\times$ root node, thus concluding the fact that $\sampmon$ indeed returns a monomial.
%Note that for any monomial sampled by algorithm ~\ref{alg:sample}, the nodes traversed form a subgraph of $\etree$ that is \textit{not} a subtree in the general case. We thus seek to prove that the subgraph traversed produces the correct probability corresponding to the monomial sampled.
We will next prove by induction on the depth $d$ of $\etree$ that the $(\monom,\coef)$ returned by $\sampmon$ has a probability %`that is in accordance with the monomial sampled,
$\frac{|\coef|}{\abs{\etree}\polyinput{1}{1}}$.
For the base case $d = 0$, by definition ~\ref{def:express-tree} we know that the root has to be either a coefficient or a variable. For either case, the probability of the value returned is $1$ since there is only one value to sample from. When the root is a variable $x$ the algorithm correctly returns $(\{x\}, 1 )$. When the root is a coefficient, \sampmon ~correctly returns $(\{~\}, sign(\coef_i))$.
For the inductive hypothesis, assume that for $d \leq k$ and $k \geq 0$ $\sampmon$ indeed samples $\monom$ in $(\monom, \coef)$ in $\expandtree{\etree}$ with probability $\frac{|\coef|}{\abs{\etree}\polyinput{1}{1}}$.%bove is true.%lemma ~\ref{lem:sample} is true.
We prove now, that when $d = k + 1$ the inductive step holds. It is the case that the root of $\etree$ has up to two children $\etree_\lchild$ and $\etree_\rchild$. Since $\etree_\lchild$ and $\etree_\rchild$ are both depth $d \leq k$, by inductive hypothesis, $\sampmon$ will sample both monomials $\monom_\lchild$ in $(\monom_\lchild, \coef_\lchild)$ of $\expandtree{\etree_\lchild}$ and $\monom_\rchild$ in $(\monom_\rchild, \coef_\rchild)$ of $\expandtree{\etree_\rchild}$, from $\etree_\lchild$ and $\etree_\rchild$ with probability $\frac{|\coef_\lchild|}{\abs{\etree_\lchild}\polyinput{1}{1}}$ and $\frac{|\coef_\rchild|}{\abs{\etree_\rchild}\polyinput{1}{1}}$.
Then the root has to be either a $+$ or $\times$ node.
Consider the case when the root is $\times$. Note that we are sampling a term from $\expandtree{\etree}$. Consider $(\monom, \coef)$ in $\expandtree{\etree}$, where $\monom$ is the sampled monomial. Notice also that it is the case that $\monom = \monom_\lchild \times \monom_\rchild$, where $\monom_\lchild$ is coming from $\etree_\lchild$ and $\monom_\rchild$ from $\etree_\rchild$. The probability that \sampmon$(\etree_{\lchild})$ returns $\monom_\lchild$ is $\frac{|\coef_{\monom_\lchild}|}{|\etree_\lchild|(1,\ldots, 1)}$ and $\frac{|\coef_{\monom_\lchild}|}{\abs{\etree_\rchild}\polyinput{1}{1}}$ for $\monom_\rchild$. Since both $\monom_\lchild$ and $\monom_\rchild$ are sampled with independent randomness, the final probability for sample $\monom$ is then $\frac{|\coef_{\monom_\lchild}| \cdot |\coef_{\monom_R}|}{|\etree_\lchild|(1,\ldots, 1) \cdot |\etree_\rchild|(1,\ldots, 1)}$. For $(\monom, \coef)$ in \expandtree{\etree}, it is indeed the case that $|\coef_i| = |\coef_{\monom_\lchild}| \cdot |\coef_{\monom_\rchild}|$ and that $\abs{\etree}(1,\ldots, 1) = |\etree_\lchild|(1,\ldots, 1) \cdot |\etree_\rchild|(1,\ldots, 1)$, and therefore $\monom$ is sampled with correct probability $\frac{|\coef_i|}{\abs{\etree}(1,\ldots, 1)}$.
For the case when $\etree.\val = +$, \sampmon ~will sample monomial $\monom$ from one of its children. By inductive hypothesis we know that any $\monom_\lchild$ in $\expandtree{\etree_\lchild}$ and any $\monom_\rchild$ in $\expandtree{\etree_\rchild}$ will both be sampled with correct probability $\frac{|\coef_{\monom_\lchild}|}{\etree_{\lchild}(1,\ldots, 1)}$ and $\frac{|\coef_{\monom_\rchild}|}{|\etree_\rchild|(1,\ldots, 1)}$, where either $\monom_\lchild$ or $\monom_\rchild$ will equal $\monom$, depending on whether $\etree_\lchild$ or $\etree_\rchild$ is sampled. Assume that $\monom$ is sampled from $\etree_\lchild$, and note that a symmetric argument holds for the case when $\monom$ is sampled from $\etree_\rchild$. Notice also that the probability of choosing $\etree_\lchild$ from $\etree$ is $\frac{\abs{\etree_\lchild}\polyinput{1}{1}}{\abs{\etree_\lchild}\polyinput{1}{1} + \abs{\etree_\rchild}\polyinput{1}{1}}$ as computed by $\onepass$. Then, since $\sampmon$ goes top-down, and each sampling choice is independent (which follows from the randomness in the root of $\etree$ being independent from the randomness used in its subtrees), the probability for $\monom$ to be sampled from $\etree$ is equal to the product of the probability that $\etree_\lchild$ is sampled from $\etree$ and $\monom$ is sampled in $\etree_\lchild$, and
\begin{align*}
&P(\sampmon(\etree) = \monom) = \\
&P(\sampmon(\etree_\lchild) = \monom) \cdot P(SampledChild(\etree) = \etree_\lchild)\\
&= \frac{|\coef_\monom|}{|\etree_\lchild|(1,\ldots, 1)} \cdot \frac{\abs{\etree_\lchild}(1,\ldots, 1)}{|\etree_\lchild|(1,\ldots, 1) + |\etree_\rchild|(1,\ldots, 1)}\\
&= \frac{|\coef_\monom|}{\abs{\etree}(1,\ldots, 1)},
\end{align*}
and we obtain the desired result.
\paragraph{Run-time Analysis}
We now bound the number of recursive calls in $\sampmon$ by $O\left(k\cdot depth(\etree)\right)$. Note that a sampled monomial corresponds to a subtree of $\etree$. Take an arbitrary sample subgraph of expression tree $\etree$ and note that since every monomial has degree $k$, the subgraph has $O(k)$ leaves and the number of nodes in each layer as one goes from leaves to the root can only go down. Since the sub-graph has depth at most $depth(\etree)$ and that each level has $O(k)$ nodes, the sub-graph as $O(k\cdot depth(\etree))$ nodes in it. Since each node in the sub-graph corresponds to a recursive call we get the desired bound.
%of degree $k$ and pick an arbitrary level $i$. Call the number of $\times$ nodes in this level $y_i$, and the total number of nodes $x_i$. Given that both children of a $\times$ node are traversed in $\sampmon$ while only one child is traversed for a $+$ parent node, note that the number of nodes on level $i + 1$ in the general case is at most $y_i + x_i$, and the increase in the number of nodes from level $i$ to level $i + 1$ is upper bounded by $x_{i + 1} - x_i \leq y_i$.
%Now, we prove by induction on the depth $d$ of tree $\etree$ the following claim.
%\begin{Claim}\label{claim:num-nodes-level-i}
%The number of nodes in a sample subgraph of expression tree $\etree$ at arbitrary level $i$ is bounded by the count of $\times$ nodes in levels $[0, i - 1] + 1$.
%\end{Claim}
%\begin{proof}[Proof of Claim ~\ref{claim:num-nodes-level-i}]
%For the base case, $d = 0$, we have the following cases. For both cases, when $\etree.\type = \tnum$ and when $\etree.\type = \var$, it is trivial to see that the number of nodes on level $0$ = 1, which satisfies the identity of ~\cref{claim:num-nodes-level-i}, i.e., the number of $\times$ nodes in previous levels $+ 1$ = 1, and the base case is upheld.
%Assume that for $d \leq k$ for $k \geq 0$ that ~\cref{claim:num-nodes-level-i} holds.
%The inductive step is to show that for arbitrary $\etree$ with depth = $d + 1 \leq k + 1$ the claim still holds. Note that we have two possibilities for the value of $\etree$. First, $\etree.\type = +$, and it is the case in ~\cref{alg:sample-plus-traversal} that only one of $\etree_\lchild$ or $\etree_\rchild$ are part of the subgraph traversed by $\sampmon$. By inductive hypothesis, both subtrees satisfy the claim. Since only one child is part of the subgraph, there is exactly one node at level 1, which, as in the base case analysis, satisfies ~\cref{claim:num-nodes-level-i}. For the second case, $\etree.\type = \times$, $\sampmon$ traverses both children, and the number of nodes at level $1$ in the subgraph is then $2$, which satisfies ~\cref{claim:num-nodes-level-i} since the sum of $\times$ nodes in previous levels (level $0$) is $1$, and $1 + 1 = 2$, proving the claim.
%\end{proof}
%\qed
%By ~\cref{def:degree}, a sampled monomial will have $O(k)$ $\times$ nodes, and this along with ~\cref{claim:num-nodes-level-i} implies $O(k)$ nodes at $\leq$ $depth(\etree)$ levels of the $\sampmon$ subgraph, bounding the number of recursive calls to $O(k \cdot depth(\etree))$.
%Globally, lines ~\ref{alg:sample-global1} and ~\ref{alg:sample-global2} are $O(1)$ time. For the $+$ node, line ~\ref{alg:sample-plus-bsamp} has $O(1)$ time by the fact that $\etree$ is binary. Line ~\ref{alg:sample-plus-union} has $O(\log{k})$ time by nature of the TreeSet data structure and the fact that by definition any monomial sampled from $\expandtree{\etree}$ has degree $\leq k$ and hence at most $k$ distinct variables, which in turn implies that the TreeSet has $\leq k$ elements in it at any time.
%Finally, line ~\ref{alg:sample-times-product} is in $O(1)$ for a product and an assignment operation. When a times node is visited, the same union, product, and assignment operations take place, and we again have $O(\log{k})$ runtime. When a variable leaf node is traversed, the same union operation occurs with $O(\log{k})$ runtime, and a constant leaf node has the above mentioned product and assignment operations. Thus for each node visited, we have $O(\log{k})$ runtime, and the final runtime for $\sampmon$ is $O(\log{k} \cdot k \cdot depth(\etree))$.
It is easy to check that except for~\Cref{alg:sample-times-union}, all other lines take $O(1)$ time. Thus, overall all lines except for~\Cref{alg:sample-times-union} take $O(k\cdot depth(\etree))$ time. Now consider all executions of~\Cref{alg:sample-times-union} together. We note that at each level we will be adding a given set of variables to some set at most once: since the sum of the sizes of the sets at a given level is at most $k$, each level involves $O(k\log{k})$ time. Thus, overall all executions of~\Cref{alg:sample-times-union} takes $O(k\log{k}\cdot depth(T))$ time, as desired.
\end{proof}
\qed
We argue the correctness of Algorithm ~\ref{alg:sample} by proving~\Cref{lem:sample} in~\Cref{sec:proofs-approx-alg}.
\subsection{Experimental results}
\label{sec:experiments}

View File

@ -9,3 +9,282 @@
A quick argument to why \cref{eq:2m} is true. Note that for edge $(i, j)$ connecting arbitrary vertices $i$ and $j$, finding all other edges in $G$ disjoint to $(i, j)$ is equivalent to finding all edges that are not connected to either vertex $i$ or $j$. The number of such edges is $m - d_i - d_j + 1$, where we add $1$ since edge $(i, j)$ is removed twice when subtracting both $d_i$ and $d_j$. Since the summation is iterating over all edges such that a pair $\left((i, j), (k, \ell)\right)$ will also be counted as $\left((k, \ell), (i, j)\right)$, division by $2$ then eliminates this double counting.
\cref{eq:2pd-3d} is true for similar reasons. For edge $(i, j)$, it is necessary to find two additional edges, disjoint or connected. As in ~\cref{eq:2m}, once the number of edges disjoint to $(i, j)$ have been computed, then we only need to consider all possible combinations of two edges from the set of disjoint edges, since it doesn't matter if the two edges are connected or not. Note, the factor $3$ of $\threedis$ is necessary to account for the triple counting of $3$-matchings. It is also the case that, since the two path in $\twopathdis$ is connected, that there will be no double counting by the fact that the summation automatically 'disconnects' the current edge, meaning that a two matching at the current vertex will not be counted. The sum over all such edge combinations is precisely then $\numocc{G}{\twopathdis} + 3\numocc{G}{\threedis}$.
\subsection{Proofs for~\Cref{lem:3m-G2}-\Cref{lem:lin-sys}}\label{subsec:proofs-struc-lemmas}
We are now ready to prove the structural lemmas. Note that $f_\ell$ maps subsets of three edges in $\graph{\ell}$ to a subset of at most three edges in $E_1$. To prove the structural lemmas, we will use the map $f_\ell^{-1}$. In particular, to count the number of occurrences of $\tri,\threepath,\threedis$ in $\graph{\ell}$ we count for each $S\in\binom{E_1}{\le 3}$, how many of $\tri/\threepath/\threedis$ subgraphs appear in $f_\ell^{-1}(S)$.
\subsubsection{Proof of Lemma \ref{lem:3m-G2}}
For each subset $\eset{1}\in \binom{E_1}{\le 3}$, we count the number of $3$-matchings in the $3$-edge subgraphs of $\graph{2}$ in $f_2^{-1}(\eset{1})$. We first consider the case of $\eset{1} \in \binom{E_1}{3}$, where $\eset{1}$ is composed of the edges $e_1, e_2, e_3$ and $f_2^{-1}(\eset{1})$ is the set of all $3$-edge subsets of the set
\begin{equation*}
\{(e_1, 0), (e_1, 1), (e_2, 0), (e_2, 1), (e_3, 0), (e_3, 1)\}.
\end{equation*}
We do a case analysis based on the `shape' of $\eset{1}$:
\begin{itemize}
\item $3$-matching ($\threedis$)
\end{itemize}
When $\eset{1} \equiv \threedis$, that edges in $\eset{2}$ are {\em not} disjoint only for the pairs $(e_i, 0), (e_i, 1)$ for $i\in \{1,2,3\}$. All choices for $b_1, b_2, b_3 \in \{0, 1\}$, $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ will compose a 3-matching. One can see that we have a total of two possible choicesi for $b_i$ for each edge $e_i$ in $\graph{1}$ yielding $2^3 = 8$ possible 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item Disjoint Two-Path ($\twopathdis$)
\end{itemize}
For $\eset{1} \equiv \twopathdis$ edges $e_2, e_3$ form a $2$-path with $e_1$ being disjoint. This means that $(e_2, 0), (e_2, 1), (e_3, 0), (e_3, 1)$ form a $4$-path while $(e_1, 0), (e_1, 1)$ is its own disjoint $2$-path. We can only pick either $(e_1, 0)$ or $(e_1, 1)$ for $f_2^{-1}(\eset{1})$, and then we need to pick a $2$-matching from $e_2$ and $e_3$. Note that the four path allows there to be 3 possible 2 matchings, specifically,
\begin{equation*}
\pbrace{(e_2, 0), (e_3, 0)}, \pbrace{(e_2, 0), (e_3, 1)}, \pbrace{(e_2, 1), (e_3, 1)}.
\end{equation*}
Since these two selections can be made independently, there are $2 \cdot 3 = 6$ choices for $3$-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-star ($\oneint$)
\end{itemize}
When $\eset{1} \equiv \oneint$, the inner edges $(e_i, 1)$ of $\eset{2}$ are all connected, and the outer edges $(e_i, 0)$ are all disjoint. Note that for a valid 3 matching it must be the case that at most one inner edge can be part of the set of disjoint edges. When exactly one inner edge is chosen, there are 3 such possibilities. The remaining possible 3-matching occurs when all 3 outer edges are chosen. Thus, there are $3 + 1 = 4$ many 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-path ($\threepath$)
\end{itemize}
When $\eset{1} \equiv\threepath$ it is the case that all edges beginning with $e_1$ and ending with $e_3$ are successively connected. This means that the edges of $\eset{2}$ form a $6$-path in the edges of $f_2^{-1}(\eset{1})$, where all edges from $(e_1, 0),\ldots,(e_3, 1)$ are successively connected. For a $3$-matching to exist in $f_2^{-1}(\eset{1})$, we cannot pick both $(e_i,0)$ and $(e_i,1)$. % there must be at least one edge separating edges picked from a sequence.
There are four such possibilities: $\pbrace{(e_1, 0), (e_2, 0), (e_3, 0)}, \pbrace{(e_1, 0), (e_2, 0), (e_3, 1)}, \pbrace{(e_1, 0), (e_2, 1), (e_3, 1)},$\newline $\pbrace{(e_1, 1), (e_2, 1), (e_3, 1)}$ . Thus, there are four possible 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item Triangle ($\tri$)
\end{itemize}
For $\eset{1} \equiv \tri$, note that it is the case that the edges in $\eset{2}$ are connected in a successive manner, but this time in a cycle, such that $(e_1, 0)$ and $(e_3, 1)$ are also connected. While this is similar to the discussion of the three path above, the first and last edges are not disjoint, since they are connected. This rules out both subsets of $(e_1, 0), (e_2, 0), (e_3, 1)$ and $(e_1, 0), (e_2, 1), (e_3, 1)$ leaving us with $2$ remaining edge combinations that produce a 3 matching.
Let us now consider when $S \in \binom{E_1}{\leq 2}$, i.e. patterns among
\begin{itemize}
\item $2$-matching ($\twodis$), $2$-path ($\twopath$), $1$ edge ($\ed$)
\end{itemize}
When $|\eset{1}| = 2$, we can only pick one from each of two pairs, $\pbrace{(e_1, 0), (e_1, 1)}$ and $\pbrace{(e_2, 0), (e_2, 1)}$. This implies that a $3$-matching cannot exist in $f_2^{-1}(\eset{1})$. The same argument holds for $|\eset{1}| = 1$, where we can only pick one edge from the pair $\pbrace{(e_1, 0), (e_1, 1)}$, thus no $3$-matching exists in $f_2^{-1}(\eset{1})$.
Observe that all of the arguments above focused solely on the shape/pattern of $S$. In other words, all $S$ of a given shape yield the same number of $3$-matchings in $f_2^{-1}(\eset{1})$, and this is why we get the required identity using the above case analysis.
\subsubsection{Proof of~\cref{lem:3m-G3}}
For any $\eset{1} \in \binom{E_1}{\leq3}$, we again then count the number of $3$-matchings in $f_3^{-1}(\eset{1})$ via a case analysis:
\begin{itemize}
\item $1$ edge ($\ed$)
\end{itemize}
When $\eset{1} \equiv \ed$, $f_3^{-1}(\eset{1})$ has one subset, $(e_1, 0), (e_1, 1), (e_1, 2)$, which clearly does not contain a $3$-matching. Thus there are no $3$-matchings in $f_3^{-1}(\eset{1})$ for this case.
\begin{itemize}
\item $2$-path ($\twopath$)
\end{itemize}
When $\eset{1} \equiv \twopath$ and now we have all edges in $\eset{3}$ form a $6$-path, and similar to the discussion in the proof of \cref{lem:3m-G2} (when $\eset{1} \equiv \threepath$ in $\graph{2}$), this leads to four $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $2$-matching ($\twodis$)
\end{itemize}
For $\eset{1} \equiv \twodis$, all edges of $\eset{3}$ are predicated on the fact that $(e_i, b)$ is disjoint with $(e_j, b)$ for $i \neq j\in \{1,2\}$ and $b \in \{0, 1, 2\}$. Pick an aribitrary $e_i$ and note, that $(e_i, 0), (e_i, 2)$ is a $2$-matching, which can combine with any of the $3$ edges in $(e_j, 0), (e_j, 1), (e_j, 2)$ again for $i \neq j$. Since the selections are independent, it follows that there exist $2 \cdot 3 = 6$ many $3$-matchings in $f_3^{-1}(\eset{1})$.
Now, we consider the 3-edge subgraphs of $\graph{1}$, starting with $\eset{1} = \tri$.
\begin{itemize}
\item Triangle ($\tri$)
\end{itemize}
As discussed in proof of \cref{lem:3m-G2} for the case of $\tri$, the edges of $\eset{3}$ are a cyclic sequence, and we must be careful not to pair $(e_1, 0)$ with $(e_3, 2)$ in a $3$-matching. For any $T \in f_3^{-1}(\eset{1})$, $T$ is a $3$-matching when we have that for the edges $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ where $b_1, b_2, b_3 \in \{0, 1, 2\}$, such that, for all $i \in [3]$ it is the case that if $b_i = 2$ then $b_{i \mod{3} + 1} \neq 0$. Iterating through all possible choices for $e_1$, we have
\begin{itemize}
\item For \textsc{$(e_1, 0)$}, there are five possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 0), (e_2, 0), (e_3, 0)}$
\item $\pbrace{(e_1, 0), (e_2, 0), (e_3, 1)}$
\item $\pbrace{(e_1, 0), (e_2, 1), (e_3, 0)}$
\item $\pbrace{(e_1, 0), (e_2, 1), (e_3, 1)}$
\item $\pbrace{(e_1, 0), (e_2, 2), (e_3, 1)}$
\end{itemize}
\item For \textsc{$(e_1, 1)$}, there are eight possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 1), (e_2, 0), (e_3, 0)}, \ldots\pbrace{(e_1, 1), (e_2, 1), (e_3, 2)}$
\item $\pbrace{(e_1, 1), (e_2, 2), (e_3, 1)}$
\item $\pbrace{(e_1, 1), (e_2, 2), (e_3, 2)}$
\end{itemize}
\item For \textsc{$(e_1, 2)$}, there are five possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 0)}$
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 1)}$
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 2)}$
\item $\pbrace{(e_1, 2), (e_2, 2), (e_3, 1)}$
\item $\pbrace{(e_1, 2), (e_2, 2), (e_3, 2)}$
\end{itemize}
\end{itemize}
for a total of 18 many 3-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-path ($\threepath$)
\end{itemize}
When $\eset{1} \equiv \threepath$ and all edges in $\eset{3}$ are successively connected to form a $9$-path. Since $(e_1, 0)$ is disjoint to $(e_3, 2)$, both of these edges can exist in a $3$-matching. This relaxation yields 3 other 3-matchings that couldn't be counted in the case of the $\eset{1} = \tri$, namely
\begin{equation*}
\pbrace{(e_1, 0), (e_2, 0), (e_3, 2)},\pbrace{(e_1, 0), (e_2, 1), (e_3, 2)}, \pbrace{(e_1, 0), (e_2, 2), (e_3, 2)}.
\end{equation*}
There are therefore $18 + 3 = 21$ $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item Disjoint Two-Path ($\twopathdis$)
\end{itemize}
Assume $\eset{1} = \twopathdis$, then the edges of $\eset{3}$ have successive connectivity from $(e_1, 0)$ through $(e_1, 2)$, and successive connectivity from $(e_2, 0)$ through $(e_3, 2)$. It is the case that the edges in $\eset{3}$ form a 6-path with a disjoint 3-path. There exist $8$ distinct two matchings (with at least one $(e_2,\cdot)$ and at least one $(e_3,\cdot)$ edge) in the $6$-path $(e_2, 0),\ldots, (e_3, 2)$ of the form
\begin{equation*}
\pbrace{(e_2, 0), (e_3, 0)},\ldots, \pbrace{(e_2, 1), (e_3, 2)}, \pbrace{(e_2, 2), (e_3, 1)}, \pbrace{(e_2, 2), (e_3, 2)}.
\end{equation*}
These matchings can be paired independently with either of the $3$ remaining edges of $(e_1, b)$, for a total of $8 \cdot 3 = 24$ many 3-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-star ($\oneint$)
\end{itemize}
When $\eset{1} \equiv \oneint$, the edges of $\eset{3}$ are restricted such that the outer edges $(e_i, 0)$ are disjoint from another, the middle edges $(e_i, 1)$ are also disjoint to each other, and only the inner edges $(e_i, 2)$ intersect with one another at exactly one common endpoint. To be precise, any outer edge $(e_i, 0)$ is disjoint to every middle edge $(e_j, 1)$ for $i \neq j$. As previously mentioned in the proof of \cref{lem:3m-G2}, at most one inner edge may appear in a $3$-matching. For arbitrary inner edge $(e_i, 2)$, we have $4$ combinations of the middle and outer edges of $e_j, e_m$, where $i \neq j \neq m$. These choices are independent and we have $4 \cdot 3 = 12$ many 3-matchings. We are not done yet, as we need to consider the middle and outer edge combinations. Notice that for each $e_i$, we have $2$ choices, i.e. a middle or outer edge, contributing $2^3 = 8$ additional $3$-matchings, for a total of $8 + 12 = 20$ many $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-matching ($\threedis$)
\end{itemize}
When $\eset{1} \equiv \threedis$ subgraph, we have the case that all edges in $\eset{3}$ have the property that $(e_i, b_i)$ is disjoint to $(e_j, b_j)$ for $i \neq j$. For each $e_i$, there are then $3$ choices, independent of each other, and it results that there are $3^3 = 27$ many 3-matchings in $f_3^{-1}(\eset{1})$.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-matchings, this implies the identity.
\subsubsection{Proof of~\cref{lem:3p-G2}}
For $\mathcal{P} \in f_2^{-1}\inparen{ \eset{2}}$ such that $\mathcal{P} $ is a $3$-path, it \textit{must} be the case by definition of $f_2$ that (i)eall edges in $f_2(\mathcal{P} )$ have at least one mapping from an edge in $\mathcal{P} $ and recall that (ii) $\mathcal{P} $ is connected. These constraint rules out every pattern $\eset{1}$ consisting of $3$ edges (it can be verified that in each three-edge pattern at least one of (i) or (ii) is violated), as well as when $\eset{1} = \twodis$. For $\eset{1} = \ed$, note that $\eset{1}$ doesn't have enough edges to have any output in $f_2^{-1}(\eset{1})$, i.e., there exists no $\eset{1} \in \binom{E_2}{3}$ such that $f_2(\mathcal{P} ) = \eset{1}$. The only surviving pattern is $\eset{1} \equiv \twopath$, where the edges of $\eset{2}$ have successive connectivity from $(e_1, 0)$ to $(e_2, 1)$. There are then two $3$-paths sharing edges $e_1$ and $e_2$ in $f_2^{-1}(\eset{1}), \pbrace{(e_1, 0), (e_1, 1), (e_2, 0)} \text{ and }\{(e_1, 1)$,$ (e_2, 0), (e_2, 1)\}$.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-paths, this implies the identity.
\subsubsection{Proof of~\cref{lem:3p-G3}}
The argument follows along the same lines as in the proof of \cref{lem:3p-G2}. Given $\mathcal{P} \in f_3^{-1}\inparen{\eset{1}}$, it \textit{must} be that every edge in $f_3(\mathcal{P})$ has at least one edge in $\mathcal{P}$ mapped to it (and $\mathcal{P}$ is connected). Notice again that this cannot be the case for any $\eset{1} \in \binom{E_1}{3}$, nor is it the case when $\eset{1} = \twodis$. This leaves us with two patterns, $\eset{1} = \twopath$ and $\eset{1} = \ed$. For the former, it is the case that we have two $3$-paths across $e_1$ and $e_2$, $\pbrace{(e_1, 1), (e_1, 2), (e_2, 0)}$ and $\pbrace{(e_1, 2), (e_2, 0), (e_2, 1)}$. For the latter pattern $\ed$, it it trivial to see that an edge in $\graph{1}$ becomes a $3$-path in $\graph{3}$, and this proves the identity.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-paths, this implies the identity.
\subsubsection{Proof of~\cref{lem:tri}}
The number of triangles in $\graph{\ell}$ for $\ell \geq 2$ will always be $0$ for the simple fact that all cycles in $\graph{\ell}$ will have at least six edges.
\input{lin_sys}
\subsubsection{Proof of~\cref{lem:fk-func}}\label{subsubsec:proof-fk}%[Proof of Lemma \ref{lem:fk-func}]
Note that $f_\ell$ is properly defined. For any $S \in \binom{E_\ell}{3}$, $|f(S)| \leq 3$, since it has to be the case that any subset of $3$ edges in $E_\ell$ will map to at most three edges in $E_1$. All mappings are in the required range. Then, since for any $b \in \{0,\ldots, \ell-1\}$ the map $(e, b) \mapsto e$ is a function, which %` mapping for which $(e, b)$ maps to no other edge than $e$, and this
implies that $f_\ell$ is a function.
\section{Missing Details from Section~\ref{sec:algo}}\label{sec:proofs-approx-alg}
Before proving~\Cref{lem:mon-samp}, we use it to argue our main result,~\Cref{lem:approx-alg}:
\subsection{Proof of Theorem \ref{lem:approx-alg}}
Set $\mathcal{E}=\approxq(\etree, (p_1,\dots,p_\numvar),$ $\conf, \error')$, where
\[\error' = \error \cdot \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)\cdot (1 - \gamma)}{\abs{\etree}(1,\ldots, 1)},\]
which achieves the claimed accuracy bound on $\mathcal{E}$.
The claim on the runtime follows since
\begin{align*}
\frac 1{\inparen{\error'}^2}\cdot \log\inparen{\frac 1\conf}=&\frac{\log{\frac{1}{\conf}}}{\error^2 \left(\frac{\rpoly(\prob_1,\ldots, \prob_N)}{\abs{\etree}(1,\ldots, 1)}\right)^2}\\
= &\frac{\log{\frac{1}{\conf}}\cdot \abs{\etree}^2(1,\ldots, 1)}{\error^2 \cdot \rpoly^2(\prob_1,\ldots, \prob_\numvar)},
\end{align*}
%and the runtime then follows, thus upholding ~\cref{lem:approx-alg}.
which completes the proof.
We now return to the proof of~\Cref{lem:mon-samp}:
\subsection{Proof of Theorem \ref{lem:mon-samp}}
Consider now the random variables $\randvar_1,\dots,\randvar_\numvar$, where each $\randvar_i$ is the value of $\vari{Y}_{\vari{i}}$ after~\Cref{alg:mon-sam-product} is executed. In particular, note that we have
\[Y_i= \onesymbol\inparen{\monom\mod{\mathcal{B}}\not\equiv 0}\cdot \prod_{X_i\in \var\inparen{v}} p_i,\]
where the indicator variable handles the check in~\Cref{alg:check-duplicate-block}
Then for random variable $\randvar_i$, it is the case that
\[\expct\pbox{\randvar_i} = \sum\limits_{(\monom, \coef) \in \expandtree{\etree} }\frac{\onesymbol\inparen{\monom\mod{\mathcal{B}}\not\equiv 0}\cdot c\cdot\prod_{X_i\in \var\inparen{v}} p_i }{\abs{\etree}(1,\dots,1)} = \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)}{\abs{\etree}(1,\ldots, 1)},\]
where in the first equality we use the fact that $\vari{sgn}_{\vari{i}}\cdot \abs{\coef}=\coef$ and the second equality follows from~\cref{eq:tilde-Q-bi} with $X_i$ substituted by $\prob_i$.
Let $\empmean = \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i$. It is also true that
\[\expct\pbox{\empmean} %\expct\pbox{ \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i}
= \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\expct\pbox{\randvar_i}
= \frac{\rpoly(\prob_1,\ldots, \prob_\numvar)}{\abs{\etree}(1,\ldots, 1)}.\]
Hoeffding's inequality states that if we know that each $\randvar_i$ (which are all independent) always lie in the intervals $[a_i, b_i]$, then it is true that
\begin{equation*}
P\left(\left|\empmean - \expct\pbox{\empmean}\right| \geq \error\right) \leq 2\exp{\left(-\frac{2\samplesize^2\error^2}{\sum_{i = 1}^{\samplesize}(b_i -a_i)^2}\right)}.
\end{equation*}
Line ~\ref{alg:mon-sam-sample} shows that $\vari{sgn}_\vari{i}$ has a value in $\{-1, 1\}$ that is multiplied with $O(k)$ $p_i\in [0, 1]$, the range for each $\randvar_i$ is $[-1, 1]$.
Using Hoeffding's inequality, we then get:
\begin{equation*}
P\pbox{~\left| \empmean - \expct\pbox{\empmean} ~\right| \geq \error} \leq 2\exp{\left(-\frac{2\samplesize^2\error^2}{2^2 \samplesize}\right)} = 2\exp{\left(-\frac{\samplesize\error^2}{2 }\right)}\leq \conf,
\end{equation*}
where the last inequality follows from our choice of $\samplesize$ in~\Cref{alg:mon-sam-global2}.
This concludes the proof for the first claim of theorem ~\ref{lem:mon-samp}.
\paragraph{Run-time Analysis}
The runtime of the algorithm is dominated by~\Cref{alg:mon-sam-onepass} (which by~\Cref{lem:one-pass} takes time $O(size(\etree))$) and the $\samplesize$ iterations of the loop in~\Cref{alg:sampling-loop}. Each iteration's run time is dominated by the call to~\Cref{alg:mon-sam-sample} (which by~\Cref{lem:sample} takes $O(\log{k} \cdot k \cdot depth(\etree))$) and~\Cref{alg:check-duplicate-block}, which by the subsequent argument takes $O(k\log{k})$ time. We sort the $O(k)$ variables by their block IDs and then check if there is a duplicate block ID or not. Adding up all the times discussed here gives us the desired overall runtime.
\subsection{Proof of~\Cref{cor:approx-algo-const-p}}
The result follows by first noting that by definition of $\gamma$, we have
%\AH{Just wondering why you use $\geq$ as opposed to $=$?}
%\AR{Ah, right-- fixed}
\[\rpoly(1,\dots,1)= (1-\gamma)\cdot \abs{\etree}(1,\dots,1).\]
Further, since each $p_i\ge p_0$ and $\poly(\vct{X})$ (and hence $\rpoly(\vct{X})$) has degree at most $k$, we have that
\[ \rpoly(1,\dots,1) \ge p_0^k\cdot \rpoly(1,\dots,1).\]
The above two inequalities implies $\rpoly(1,\dots,1) \ge p_0^k\cdot (1-\gamma)\cdot \abs{\etree}(1,\dots,1)$.
%\AH{This looks really nice!}
Applying this bound in the runtime bound in~\Cref{lem:approx-alg} gives the first claimed runtime. The final runtime of $O_k\left(\frac 1{\eps^2}\cdot\treesize(\etree)\cdot \log{\frac{1}{\conf}}\right)$ follows by noting that $depth(\etree)\le \treesize(\etree)$ and absorbing all factors that just depend on $k$.
\subsection{Proof of~\Cref{lem:one-pass}}
We prove the first part of lemma ~\ref{lem:one-pass}, i.e., correctness, by structural induction over the depth $d$ of the binary tree $\etree$.
For the base case, $d = 0$, it is the case that the node is a leaf and therefore by definition ~\ref{def:express-tree} must be a variable or coefficient. When it is a variable, \textsc{OnePass} returns $1$, and we have in this case that $\polyf(\etree) = X_i = \polyf(\abs{\etree})$ for some $i$ in $[\numvar]$, and this evaluated at all $1$'s indeed gives $1$, verifying the correctness of the returned value of $\abs{\etree}(1,\ldots, 1) = 1$. When the root is a coefficient, the absolute value of the coefficient is returned, which is indeed $\abs{\etree}(1,\ldots, 1)$. This proves the base case.
%\AH{The inductive step assumes $k \geq 0$ rather than $k \geq 1$, correct?}
%\AR{yep!}
For the inductive hypothesis, assume that for $d \leq k$ for some $k \geq 0$,~\Cref{lem:one-pass} is true for~\Cref{alg:one-pass}.
Now prove that lemma ~\ref{lem:one-pass} holds for $k + 1$. Notice that $\etree$ has at most two children, $\etree_\lchild$ and $\etree_\rchild$. Note also, that for each child, it is the case that $d \leq k$. Then, by inductive hypothesis, lemma ~\ref{lem:one-pass} holds for each existing child, and we are left with two possibilities for $\etree$. The first case is when $\etree$ is a $+$ node. When this happens,~\Cref{alg:one-pass} computes $|T_\lchild|(1,\ldots, 1) + |T_\rchild|(1,\ldots, 1)$ on line ~\ref{alg:one-pass-plus-add} which by definition is $\abs{\etree}(1,\ldots, 1)$ and hence the inductive hypothesis holds in this case. For the weight computation of the children of $+$, by lines ~\ref{alg:one-pass-plus-add}, ~\ref{alg:one-pass-plus-assign2}, and ~\ref{alg:one-pass-plus-prob} algorithm ~\ref{alg:one-pass} computes $\etree_i.\wght = \frac{|T_i|(1,\ldots, 1)}{|T_\lchild|(1,\ldots, 1) + |T_\rchild|(1,\ldots, 1)}$ which is indeed as claimed. The second case is when the $\etree.\val = \times$. By inductive hypothesis, it is the case that both $\abs{\etree_\lchild}\polyinput{1}{1}$ and $\abs{\etree_\rchild}\polyinput{1}{1}$ have been correctly computed. On line~\ref{alg:one-pass-times-product} algorithm ~\ref{alg:one-pass} then computes the product of the subtree partial values, $|T_\lchild|(1,\ldots, 1) \cdot |T_\rchild|(1,\ldots, 1)$ which by definition is $\abs{\etree}(1,\ldots, 1)$.
\paragraph{Run-time Analysis}
The runtime for \textsc{OnePass} is fairly straight forward. Note first that each node is visited at most one time. Second, for each type of node visited, it can be trivially verified that there are only a constant number of operations. This concludes then with a $O\left(\treesize(\etree)\right)$ runtime.
\subsubsection{Proof of~\Cref{lem:sample}}
First, we need to show that $\sampmon$ indeed returns a monomial $\monom$,\footnote{Technically it returns $\var(\monom)$ but for less cumbersome notation we will refer to $\var(\monom)$ simply by $\monom$ in this proof.} such that $(\monom, \coef)$ is in $\expandtree{\etree}$, which we do by induction on the depth of $\etree$.
For the base case, let the depth $d$ of $\etree$ be $0$. We have that the root node is either a constant $\coef$ for which by line ~\ref{alg:sample-num-return} we return $\{~\}$, or we have that $\etree.\type = \var$ and $\etree.\val = x$, and by line ~\ref{alg:sample-var-return} we return $\{x\}$. Both cases sample a monomial%satisfy ~\cref{def:monomial}
, and the base case is proven.
For the inductive hypothesis, assume that for $d \leq k$ for some $k \geq 0$, that it is indeed the case that $\sampmon$ returns a monomial.
For the inductive step, let us take a tree $\etree$ with $d = k + 1$. Note that each child has depth $d \leq k$, and by inductive hypothesis both of them return a valid monomial. Then the root can be either a $+$ or $\times$ node. For the case of a $+$ root node, line ~\ref{alg:sample-plus-bsamp} of $\sampmon$ will choose one of the children of the root. Since by inductive hypothesis it is the case that a monomial is being returned from either child, and only one of these monomials is selected, we have for the case of $+$ root node that a valid monomial is returned by $\sampmon$. When the root is a $\times$ node, lines ~\ref{alg:sample-times-union} and ~\ref{alg:sample-times-product} multiply the monomials returned by the two children of the root, and it is trivial to see that %by definition ~\ref{def:monomial}
the product of two monomials is also a monomial, which means that $\sampmon$ returns a valid monomial for the $\times$ root node, thus concluding the fact that $\sampmon$ indeed returns a monomial.
We will next prove by induction on the depth $d$ of $\etree$ that the $(\monom,\coef)$ returned by $\sampmon$ has a probability %`that is in accordance with the monomial sampled,
$\frac{|\coef|}{\abs{\etree}\polyinput{1}{1}}$.
For the base case $d = 0$, by definition ~\ref{def:express-tree} we know that the root has to be either a coefficient or a variable. For either case, the probability of the value returned is $1$ since there is only one value to sample from. When the root is a variable $x$ the algorithm correctly returns $(\{x\}, 1 )$. When the root is a coefficient, \sampmon ~correctly returns $(\{~\}, sign(\coef_i))$.
For the inductive hypothesis, assume that for $d \leq k$ and $k \geq 0$ $\sampmon$ indeed samples $\monom$ in $(\monom, \coef)$ in $\expandtree{\etree}$ with probability $\frac{|\coef|}{\abs{\etree}\polyinput{1}{1}}$.%bove is true.%lemma ~\ref{lem:sample} is true.
We prove now, that when $d = k + 1$ the inductive step holds. It is the case that the root of $\etree$ has up to two children $\etree_\lchild$ and $\etree_\rchild$. Since $\etree_\lchild$ and $\etree_\rchild$ are both depth $d \leq k$, by inductive hypothesis, $\sampmon$ will sample both monomials $\monom_\lchild$ in $(\monom_\lchild, \coef_\lchild)$ of $\expandtree{\etree_\lchild}$ and $\monom_\rchild$ in $(\monom_\rchild, \coef_\rchild)$ of $\expandtree{\etree_\rchild}$, from $\etree_\lchild$ and $\etree_\rchild$ with probability $\frac{|\coef_\lchild|}{\abs{\etree_\lchild}\polyinput{1}{1}}$ and $\frac{|\coef_\rchild|}{\abs{\etree_\rchild}\polyinput{1}{1}}$.
Then the root has to be either a $+$ or $\times$ node.
Consider the case when the root is $\times$. Note that we are sampling a term from $\expandtree{\etree}$. Consider $(\monom, \coef)$ in $\expandtree{\etree}$, where $\monom$ is the sampled monomial. Notice also that it is the case that $\monom = \monom_\lchild \times \monom_\rchild$, where $\monom_\lchild$ is coming from $\etree_\lchild$ and $\monom_\rchild$ from $\etree_\rchild$. The probability that \sampmon$(\etree_{\lchild})$ returns $\monom_\lchild$ is $\frac{|\coef_{\monom_\lchild}|}{|\etree_\lchild|(1,\ldots, 1)}$ and $\frac{|\coef_{\monom_\lchild}|}{\abs{\etree_\rchild}\polyinput{1}{1}}$ for $\monom_\rchild$. Since both $\monom_\lchild$ and $\monom_\rchild$ are sampled with independent randomness, the final probability for sample $\monom$ is then $\frac{|\coef_{\monom_\lchild}| \cdot |\coef_{\monom_R}|}{|\etree_\lchild|(1,\ldots, 1) \cdot |\etree_\rchild|(1,\ldots, 1)}$. For $(\monom, \coef)$ in \expandtree{\etree}, it is indeed the case that $|\coef_i| = |\coef_{\monom_\lchild}| \cdot |\coef_{\monom_\rchild}|$ and that $\abs{\etree}(1,\ldots, 1) = |\etree_\lchild|(1,\ldots, 1) \cdot |\etree_\rchild|(1,\ldots, 1)$, and therefore $\monom$ is sampled with correct probability $\frac{|\coef_i|}{\abs{\etree}(1,\ldots, 1)}$.
For the case when $\etree.\val = +$, \sampmon ~will sample monomial $\monom$ from one of its children. By inductive hypothesis we know that any $\monom_\lchild$ in $\expandtree{\etree_\lchild}$ and any $\monom_\rchild$ in $\expandtree{\etree_\rchild}$ will both be sampled with correct probability $\frac{|\coef_{\monom_\lchild}|}{\etree_{\lchild}(1,\ldots, 1)}$ and $\frac{|\coef_{\monom_\rchild}|}{|\etree_\rchild|(1,\ldots, 1)}$, where either $\monom_\lchild$ or $\monom_\rchild$ will equal $\monom$, depending on whether $\etree_\lchild$ or $\etree_\rchild$ is sampled. Assume that $\monom$ is sampled from $\etree_\lchild$, and note that a symmetric argument holds for the case when $\monom$ is sampled from $\etree_\rchild$. Notice also that the probability of choosing $\etree_\lchild$ from $\etree$ is $\frac{\abs{\etree_\lchild}\polyinput{1}{1}}{\abs{\etree_\lchild}\polyinput{1}{1} + \abs{\etree_\rchild}\polyinput{1}{1}}$ as computed by $\onepass$. Then, since $\sampmon$ goes top-down, and each sampling choice is independent (which follows from the randomness in the root of $\etree$ being independent from the randomness used in its subtrees), the probability for $\monom$ to be sampled from $\etree$ is equal to the product of the probability that $\etree_\lchild$ is sampled from $\etree$ and $\monom$ is sampled in $\etree_\lchild$, and
\begin{align*}
&P(\sampmon(\etree) = \monom) = \\
&P(\sampmon(\etree_\lchild) = \monom) \cdot P(SampledChild(\etree) = \etree_\lchild)\\
&= \frac{|\coef_\monom|}{|\etree_\lchild|(1,\ldots, 1)} \cdot \frac{\abs{\etree_\lchild}(1,\ldots, 1)}{|\etree_\lchild|(1,\ldots, 1) + |\etree_\rchild|(1,\ldots, 1)}\\
&= \frac{|\coef_\monom|}{\abs{\etree}(1,\ldots, 1)},
\end{align*}
and we obtain the desired result.
\paragraph{Run-time Analysis}
We now bound the number of recursive calls in $\sampmon$ by $O\left(k\cdot depth(\etree)\right)$. Note that a sampled monomial corresponds to a subtree of $\etree$. Take an arbitrary sample subgraph of expression tree $\etree$ and note that since every monomial has degree $k$, the subgraph has $O(k)$ leaves and the number of nodes in each layer as one goes from leaves to the root can only go down. Since the sub-graph has depth at most $depth(\etree)$ and that each level has $O(k)$ nodes, the sub-graph as $O(k\cdot depth(\etree))$ nodes in it. Since each node in the sub-graph corresponds to a recursive call we get the desired bound.
It is easy to check that except for~\Cref{alg:sample-times-union}, all other lines take $O(1)$ time. Thus, overall all lines except for~\Cref{alg:sample-times-union} take $O(k\cdot depth(\etree))$ time. Now consider all executions of~\Cref{alg:sample-times-union} together. We note that at each level we will be adding a given set of variables to some set at most once: since the sum of the sizes of the sets at a given level is at most $k$, each level involves $O(k\log{k})$ time. Thus, overall all executions of~\Cref{alg:sample-times-union} takes $O(k\log{k}\cdot depth(T))$ time, as desired.

View File

@ -8,19 +8,25 @@ Note that our goal is to compute $\vct{b}[i]$ for $i\in [3]$ in $O(m)$such that
\label{eq:lin-eq-1}
&\numocc{G}{\tri} +\numocc{G}{\threepath}\cdot p - \numocc{G}{\threedis}\cdot (3p^2-p^3) =\vct{b}[1]\\
\label{eq:lin-eq-2}
&-2\numocc{G}{\tri}\cdot (3p^2-p^3) -4\numocc{G}{\threepath}\cdot (3p^2-p^3) + 10\cdot \numocc{G}{\threedis}\cdot (3p^2-p^3) =\vct{b}[2]\\
&-2\numocc{G}{\tri}\cdot (3p^2-p^3) -4\numocc{G}{\threepath}\cdot (3p^2-p^3) \nonumber\\
&+ 10\cdot \numocc{G}{\threedis}\cdot (3p^2-p^3) =\vct{b}[2]\\
\label{eq:lin-eq-3}
&-18\numocc{G}{\tri}\cdot (3p^2-p^3) -21\numocc{G}{\threepath}\cdot (3p^2-p^3) +45 \numocc{G}{\threedis}\cdot (3p^2-p^3) =\vct{b}[3]
&-18\numocc{G}{\tri}\cdot (3p^2-p^3) -21\numocc{G}{\threepath}\cdot (3p^2-p^3) \nonumber\\
&+45 \numocc{G}{\threedis}\cdot (3p^2-p^3) =\vct{b}[3]
\end{align}
%Our goal is to build a linear system $M \cdot (x~y~z)^T = \vct{b}$, such that, assuming an indexing starting at $1$, each $i^{th}$ row in $M$ corresponds to the RHS of ~\cref{eq:LS-subtract} for $\graph{i}$ \textit{in} terms of $\graph{1}$. The vector $\vct{b}$ analogously has the terms computable in $O(\numedge)$ time for each $\graph{i}$ at its corresponing $i^{th}$ entry for the LHS of ~\cref{eq:LS-subtract}. Lemma ~\ref{lem:qE3-exp} gives the identity for $\rpoly_{G}(\prob,\ldots, \prob)$ when $\poly_{G}(\vct{X}) = q_E(X_1,\ldots, X_\numvar)^3$, and using
Towards that end, we first state the values in $\vct{b}$ (where $\graph{1}=G$ while $\graph{2}$ and $\graph{3}$ follow from~\cref{def:Gk}):
\[\vct{b}[1] = \frac{\rpoly_{\graph{1}}^3(\prob,\ldots, \prob)}{6\prob^3} - \frac{\numocc{\graph{\graph{1}}}{\ed}}{6\prob} - \numocc{\graph{1}}{\twopath} - \numocc{\graph{1}}{\twodis}\prob - \numocc{\graph{1}}{\oneint}\prob - \big(\numocc{\graph{1}}{\twopathdis} + 3\numocc{\graph{1}}{\threedis}\big)\prob^2\]
\begin{align*}
&\vct{b}[1] = \frac{\rpoly_{\graph{1}}^3(\prob,\ldots, \prob)}{6\prob^3} - \frac{\numocc{\graph{\graph{1}}}{\ed}}{6\prob} - \numocc{\graph{1}}{\twopath} - \numocc{\graph{1}}{\twodis}\prob \nonumber\\
&- \numocc{\graph{1}}{\oneint}\prob - \big(\numocc{\graph{1}}{\twopathdis} + 3\numocc{\graph{1}}{\threedis}\big)\prob^2
\end{align*}
\begin{align*}
&\vct{b}[2] = \frac{\rpoly^3_{\graph{2}}(\prob,\ldots, \prob)}{6\prob^3} - \frac{\numocc{\graph{2}}{\ed}}{6\prob} - \numocc{\graph{2}}{\twopath} - \numocc{\graph{2}}{\twodis}\prob \nonumber\\
&- \numocc{\graph{2}}{\oneint}\prob- \left(\numocc{\graph{2}}{\twopathdis} + 3\numocc{\graph{2}}{\threedis}\right)\prob^2- 2\cdot \numocc{\graph{1}}{\twopath}\prob \\
&+ \left(4\cdot\numocc{\graph{1}}{\oneint}+ 6\cdot\left(\numocc{\graph{1}}{\twopathdis} + 3\cdot\numocc{\graph{1}}{\threedis}\right)\right)\left(3\prob^2 - \prob^3\right).
&- \numocc{\graph{2}}{\oneint}\prob- \left(\numocc{\graph{2}}{\twopathdis} + 3\numocc{\graph{2}}{\threedis}\right)\prob^2 \\
&- 2\cdot \numocc{\graph{1}}{\twopath}\prob+ \left(4\cdot\numocc{\graph{1}}{\oneint}+ 6\cdot\left(\numocc{\graph{1}}{\twopathdis}\right.\right.\nonumber\\
&\left.\left. + 3\cdot\numocc{\graph{1}}{\threedis}\right)\right)\left(3\prob^2 - \prob^3\right).
\end{align*}
\begin{align*}
&\vct{b}[3] = \frac{\rpoly^3_{\graph{3}}(\prob,\ldots, \prob)}{6\prob^3} - \frac{\numocc{\graph{3}}{\ed}}{6\prob} - \numocc{\graph{3}}{\twopath} - \numocc{\graph{3}}{\twodis}\prob \nonumber\\
@ -163,7 +169,7 @@ Note that the LHS of~\cref{eq:lem3-G3-3} is $\vct{b}[3]$ and that~\cref{eq:lem3
\paragraph*{Wrapping it up.}
%We now have a linear system consisting of three linear combinations, for $\graph{1}, \graph{2}, \graph{3}$ in terms of $\graph{1}$. Note that the constants for $\graph{1}$ follow the RHS of ~\cref{eq:LS-subtract}. To make it easier,
For notational convenience, define $x = \numocc{\graph{1}}{\tri}, y = \numocc{\graph{1}}{\threepath}, z = \numocc{\graph{1}}{\threedis}$.
For notational convenience, define $x = \numocc{\graph{1}}{\tri}$, $y = \numocc{\graph{1}}{\threepath}, z = \numocc{\graph{1}}{\threedis}$.
% Using $\linsys{2}$ and $\linsys{3}$, the following matrix is obtained,
If we denote
\[ \mtrix{\rpoly} = \begin{pmatrix}

View File

@ -167,7 +167,7 @@ sensitive=true
%\input{poly-form}
\input{mult_distinct_p}
\input{single_p}
\input{lin_sys}
%\input{lin_sys}
\input{approx_alg}
% \input{bi_cancellation}
\input{circuits-model-runtime}

View File

@ -94,7 +94,7 @@ Since $e\ne e'$, this case produces the following edge patterns: $\twopath, \two
\end{proof}
\qed
Since $p$ is fixed,~\cref{lem:qE3-exp} gives us one linear equation in $\numocc{G}{\tri}, \numocc{G}{\threepath}$ and $\numocc{G}{\threedis}$ (we can handle the other counts due to~\cref{eq:1e}-\cref{eq:2pd-3d}). However, we plan to generate two more independent linear equations in these three variables. Towards, this end we generate more graphs that are related to $G$:
Since $p$ is fixed,~\cref{lem:qE3-exp} gives us one linear equation in $\numocc{G}{\tri},$ $\numocc{G}{\threepath}$ and $\numocc{G}{\threedis}$ (we can handle the other counts due to~\cref{eq:1e}-\cref{eq:2pd-3d}). However, we plan to generate two more independent linear equations in these three variables. Towards, this end we generate more graphs that are related to $G$:
\begin{Definition}\label{def:Gk}
For $\ell > 1$, let graph $\graph{\ell}$ be a graph generated from an arbitrary graph $\graph{1}$, by replacing every edge $e$ of $\graph{1}$ with a $\ell$-path, such that all $\ell$-path replacement edges are disjoint. % in the sense that they only intersect at the original intersection endpoints as seen in $\graph{1}$.
\end{Definition}
@ -132,8 +132,8 @@ The number of $3$-paths in $\graph{3}$ satisfies the following identity,
For $\ell > 1$, any graph $\graph{\ell}$ has the property that $\numocc{\graph{\ell}}{\tri} = 0$.
\end{Lemma}
Due to lack of space we defer the proof of the above results to~\cref{app:hard}.
\AR{Need to do this move.}
Using the results we have obtained so far, we will prove the following reduction result:
\begin{Lemma}\label{lem:lin-sys}
@ -155,7 +155,9 @@ Fix $p\in (0,1)$. Given $\rpoly_{\graph{\ell}}^3(\prob,\dots,\prob)$ for $\ell\i
from which we can compute $\numocc{G}{\tri}, \numocc{G}{\threepath}$ and $\numocc{G}{\threedis}$ in $O(1)$ time.
\end{Lemma}
The above result immediately imples~\cref{th:single-p}:
Due to lack of space we defer the proof of the above results to~\Cref{subsec:proofs-struc-lemmas}.
The above result immediately implies~\cref{th:single-p}:
\begin{proof}[Proof of~\cref{th:single-p}]
It is easy to check that in $O(m)$ time we can compute $\graph{2}$ and $\graph{3}$ from $\graph{1}=G$ (and further note that these graphs also have $O(m)$ edges). Thus,
in time $O(T(m))$, we can compute $\rpoly_{\graph{\ell}}^3(\prob,\dots,\prob)$ for $\ell\in [3]$.~\Cref{lem:lin-sys} then completes the proof.
@ -189,13 +191,6 @@ Let $f_\ell: \binom{E_\ell}{3} \mapsto \binom{E_1}{\leq3}$ be defined as follows
\[ f_\ell\left(\pbrace{(e_1, b_1), (e_2, b_2), (e_3, b_3)}\right) = \pbrace{e_1, e_2, e_3}.\]
\end{Definition}
%\AH{Just questioning if the notation is clear in the ~\cref{def:fk-inv}. For more details, see the immediately following todo note which is commented out.}
%\AH{I found ~\cref{def:fk-inv} a bit imprecise and bulky and have attempted to refine it.
%\par Since this an inverse function, the signature is reversed, \vari{but},
%\par...the challenge is in quantifying the size of the set (of 3 edge subsets) that is returned...
%\par...where the main observation is that for an input edge of size $r$, a set of size $\leq \binom{r\cdot k}{3}$ is returned...
%\par...but the catch is that for $r \geq 3$, the set will be strictly less than $\binom{r\cdot k}{3}$ since $f_k$ does not map e.g. an input $\{(e_a, b_1), (e_a, b_2), (e_a, b_3)\}$ (where $a$ is constant and $b_1, b_2, b_3 \in \{0,\ldots, k -1\}$) to more than one edge, \textit{and} it is the case for $r \geq 3$ that $f_k^{-1}$ will not map such an input to its input of size $r$, meaning we must subtract off all such subsets of $\binom{E_k}{3}$.
%\par My fix was to use a variable in the exponent and explain in prose. Perhaps there is a better, simpler notation/solution.}
\begin{Definition}[$f_\ell^{-1}$]\label{def:fk-inv}
The inverse function $f_\ell^{-1}: \binom{E_1}{\leq 3}\mapsto 2^{\binom{E_\ell}{3}}$ takes an arbitrary subset $S\subseteq E_1$ of at most $3$ edges and outputs the set of all subsets of $\binom{\eset{\ell}}{3}$ such that each set $T\in f_\ell^{-1}(S)$ is mapped to the input set $S$ by $f_\ell$, i.e. $f_\ell(T) = S$. %The set returned by $f_\ell^{-1}$ is of size $h$, where $h$ depends on $\abs{s^{(1)}}$, such that $h \leq \binom{\abs{s^{(1)}} \cdot \ell}{3}$.
@ -207,170 +202,6 @@ We first note that $f_\ell$ is well-defined:
\begin{Lemma}\label{lem:fk-func}
$f_k$ is a function.
\end{Lemma}
\begin{proof}%[Proof of Lemma \ref{lem:fk-func}]
Note that $f_\ell$ is properly defined. For any $S \in \binom{E_\ell}{3}$, $|f(S)| \leq 3$, since it has to be the case that any subset of $3$ edges in $E_\ell$ will map to at most three edges in $E_1$. All mappings are in the required range. Then, since for any $b \in \{0,\ldots, \ell-1\}$ the map $(e, b) \mapsto e$ is a function, which %` mapping for which $(e, b)$ maps to no other edge than $e$, and this
implies that $f_\ell$ is a function.
\end{proof}
\qed
\AR{TODO for {\em later}: I think the proof will be much easier to follow with figures: just drawing out $S\times \{0,1\}$ along with the $(e_i,b_i)$ explicity notated on the edges will make the proof much easier to follow.}
The proof is in~\Cref{subsubsec:proof-fk}.
We are now ready to prove the structural lemmas. Note that $f_\ell$ maps subsets of three edges in $\graph{\ell}$ to a subset of at most three edges in $E_1$. To prove the structural lemmas, we will use the map $f_\ell^{-1}$. In particular, to count the number of occurrences of $\tri,\threepath,\threedis$ in $\graph{\ell}$ we count for each $S\in\binom{E_1}{\le 3}$, how many of $\tri/\threepath/\threedis$ subgraphs appear in $f_\ell^{-1}(S)$.
%\subsubsection{Three Matchings in $\graph{2}$}
\subsubsection{Proof of Lemma \ref{lem:3m-G2}}
For each subset $\eset{1}\in \binom{E_1}{\le 3}$, we count the number of $3$-matchings in the $3$-edge subgraphs of $\graph{2}$ in $f_2^{-1}(\eset{1})$. We first consider the case of $\eset{1} \in \binom{E_1}{3}$, where $\eset{1}$ is composed of the edges $e_1, e_2, e_3$ and $f_2^{-1}(\eset{1})$ is the set of all $3$-edge subsets of the set
\begin{equation*}
\{(e_1, 0), (e_1, 1), (e_2, 0), (e_2, 1), (e_3, 0), (e_3, 1)\}.
\end{equation*}
We do a case analysis based on the `shape' of $\eset{1}$:
\begin{itemize}
\item $3$-matching ($\threedis$)
\end{itemize}
When $\eset{1} \equiv \threedis$, that edges in $\eset{2}$ are {\em not} disjoint only for the pairs $(e_i, 0), (e_i, 1)$ for $i\in \{1,2,3\}$. All choices for $b_1, b_2, b_3 \in \{0, 1\}$, $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ will compose a 3-matching. One can see that we have a total of two possible choicesi for $b_i$ for each edge $e_i$ in $\graph{1}$ yielding $2^3 = 8$ possible 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item Disjoint Two-Path ($\twopathdis$)
\end{itemize}
For $\eset{1} \equiv \twopathdis$ edges $e_2, e_3$ form a $2$-path with $e_1$ being disjoint. This means that $(e_2, 0), (e_2, 1), (e_3, 0), (e_3, 1)$ form a $4$-path while $(e_1, 0), (e_1, 1)$ is its own disjoint $2$-path. We can only pick either $(e_1, 0)$ or $(e_1, 1)$ for $f_2^{-1}(\eset{1})$, and then we need to pick a $2$-matching from $e_2$ and $e_3$. Note that the four path allows there to be 3 possible 2 matchings, specifically,
\begin{equation*}
\pbrace{(e_2, 0), (e_3, 0)}, \pbrace{(e_2, 0), (e_3, 1)}, \pbrace{(e_2, 1), (e_3, 1)}.
\end{equation*}
Since these two selections can be made independently, there are $2 \cdot 3 = 6$ choices for $3$-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-star ($\oneint$)
\end{itemize}
When $\eset{1} \equiv \oneint$, the inner edges $(e_i, 1)$ of $\eset{2}$ are all connected, and the outer edges $(e_i, 0)$ are all disjoint. Note that for a valid 3 matching it must be the case that at most one inner edge can be part of the set of disjoint edges. When exactly one inner edge is chosen, there are 3 such possibilities. The remaining possible 3-matching occurs when all 3 outer edges are chosen. Thus, there are $3 + 1 = 4$ many 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-path ($\threepath$)
\end{itemize}
When $\eset{1} \equiv\threepath$ it is the case that all edges beginning with $e_1$ and ending with $e_3$ are successively connected. This means that the edges of $\eset{2}$ form a $6$-path in the edges of $f_2^{-1}(\eset{1})$, where all edges from $(e_1, 0),\ldots,(e_3, 1)$ are successively connected. For a $3$-matching to exist in $f_2^{-1}(\eset{1})$, we cannot pick both $(e_i,0)$ and $(e_i,1)$. % there must be at least one edge separating edges picked from a sequence.
There are four such possibilities: $\pbrace{(e_1, 0), (e_2, 0), (e_3, 0)}, \pbrace{(e_1, 0), (e_2, 0), (e_3, 1)}, \pbrace{(e_1, 0), (e_2, 1), (e_3, 1)},$\newline $\pbrace{(e_1, 1), (e_2, 1), (e_3, 1)}$ . Thus, there are four possible 3-matchings in $f_2^{-1}(\eset{1})$.
\begin{itemize}
\item Triangle ($\tri$)
\end{itemize}
For $\eset{1} \equiv \tri$, note that it is the case that the edges in $\eset{2}$ are connected in a successive manner, but this time in a cycle, such that $(e_1, 0)$ and $(e_3, 1)$ are also connected. While this is similar to the discussion of the three path above, the first and last edges are not disjoint, since they are connected. This rules out both subsets of $(e_1, 0), (e_2, 0), (e_3, 1)$ and $(e_1, 0), (e_2, 1), (e_3, 1)$ leaving us with $2$ remaining edge combinations that produce a 3 matching.
Let us now consider when $S \in \binom{E_1}{\leq 2}$, i.e. patterns among
\begin{itemize}
\item $2$-matching ($\twodis$), $2$-path ($\twopath$), $1$ edge ($\ed$)
\end{itemize}
When $|\eset{1}| = 2$, we can only pick one from each of two pairs, $\pbrace{(e_1, 0), (e_1, 1)}$ and $\pbrace{(e_2, 0), (e_2, 1)}$. This implies that a $3$-matching cannot exist in $f_2^{-1}(\eset{1})$. The same argument holds for $|\eset{1}| = 1$, where we can only pick one edge from the pair $\pbrace{(e_1, 0), (e_1, 1)}$, thus no $3$-matching exists in $f_2^{-1}(\eset{1})$.
Observe that all of the arguments above focused solely on the shape/pattern of $S$. In other words, all $S$ of a given shape yield the same number of $3$-matchings in $f_2^{-1}(\eset{1})$, and this is why we get the required identity using the above case analysis.
%\end{proof}
%\qed
\subsubsection{Proof of~\cref{lem:3m-G3}}
For any $\eset{1} \in \binom{E_1}{\leq3}$, we again then count the number of $3$-matchings in $f_3^{-1}(\eset{1})$ via a case analysis:
\begin{itemize}
\item $1$ edge ($\ed$)
\end{itemize}
When $\eset{1} \equiv \ed$, $f_3^{-1}(\eset{1})$ has one subset, $(e_1, 0), (e_1, 1), (e_1, 2)$, which clearly does not contain a $3$-matching. Thus there are no $3$-matchings in $f_3^{-1}(\eset{1})$ for this case.
\begin{itemize}
\item $2$-path ($\twopath$)
\end{itemize}
When $\eset{1} \equiv \twopath$ and now we have all edges in $\eset{3}$ form a $6$-path, and similar to the discussion in the proof of \cref{lem:3m-G2} (when $\eset{1} \equiv \threepath$ in $\graph{2}$), this leads to four $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $2$-matching ($\twodis$)
\end{itemize}
For $\eset{1} \equiv \twodis$, all edges of $\eset{3}$ are predicated on the fact that $(e_i, b)$ is disjoint with $(e_j, b)$ for $i \neq j\in \{1,2\}$ and $b \in \{0, 1, 2\}$. Pick an aribitrary $e_i$ and note, that $(e_i, 0), (e_i, 2)$ is a $2$-matching, which can combine with any of the $3$ edges in $(e_j, 0), (e_j, 1), (e_j, 2)$ again for $i \neq j$. Since the selections are independent, it follows that there exist $2 \cdot 3 = 6$ many $3$-matchings in $f_3^{-1}(\eset{1})$.
Now, we consider the 3-edge subgraphs of $\graph{1}$, starting with $\eset{1} = \tri$.
\begin{itemize}
\item Triangle ($\tri$)
\end{itemize}
As discussed in proof of \cref{lem:3m-G2} for the case of $\tri$, the edges of $\eset{3}$ are a cyclic sequence, and we must be careful not to pair $(e_1, 0)$ with $(e_3, 2)$ in a $3$-matching. For any $T \in f_3^{-1}(\eset{1})$, $T$ is a $3$-matching when we have that for the edges $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ where $b_1, b_2, b_3 \in \{0, 1, 2\}$, such that, for all $i \in [3]$ it is the case that if $b_i = 2$ then $b_{i \mod{3} + 1} \neq 0$. Iterating through all possible choices for $e_1$, we have
\begin{itemize}
\item For \textsc{$(e_1, 0)$}, there are five possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 0), (e_2, 0), (e_3, 0)}$
\item $\pbrace{(e_1, 0), (e_2, 0), (e_3, 1)}$
\item $\pbrace{(e_1, 0), (e_2, 1), (e_3, 0)}$
\item $\pbrace{(e_1, 0), (e_2, 1), (e_3, 1)}$
\item $\pbrace{(e_1, 0), (e_2, 2), (e_3, 1)}$
\end{itemize}
\item For \textsc{$(e_1, 1)$}, there are eight possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 1), (e_2, 0), (e_3, 0)}, \ldots\pbrace{(e_1, 1), (e_2, 1), (e_3, 2)}$
\item $\pbrace{(e_1, 1), (e_2, 2), (e_3, 1)}$
\item $\pbrace{(e_1, 1), (e_2, 2), (e_3, 2)}$
\end{itemize}
\item For \textsc{$(e_1, 2)$}, there are five possibilities:
\begin{itemize}
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 0)}$
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 1)}$
\item $\pbrace{(e_1, 2), (e_2, 1), (e_3, 2)}$
\item $\pbrace{(e_1, 2), (e_2, 2), (e_3, 1)}$
\item $\pbrace{(e_1, 2), (e_2, 2), (e_3, 2)}$
\end{itemize}
\end{itemize}
for a total of 18 many 3-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-path ($\threepath$)
\end{itemize}
When $\eset{1} \equiv \threepath$ and all edges in $\eset{3}$ are successively connected to form a $9$-path. Since $(e_1, 0)$ is disjoint to $(e_3, 2)$, both of these edges can exist in a $3$-matching. This relaxation yields 3 other 3-matchings that couldn't be counted in the case of the $\eset{1} = \tri$, namely
\begin{equation*}
\pbrace{(e_1, 0), (e_2, 0), (e_3, 2)},\pbrace{(e_1, 0), (e_2, 1), (e_3, 2)}, \pbrace{(e_1, 0), (e_2, 2), (e_3, 2)}.
\end{equation*}
There are therefore $18 + 3 = 21$ $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item Disjoint Two-Path ($\twopathdis$)
\end{itemize}
Assume $\eset{1} = \twopathdis$, then the edges of $\eset{3}$ have successive connectivity from $(e_1, 0)$ through $(e_1, 2)$, and successive connectivity from $(e_2, 0)$ through $(e_3, 2)$. It is the case that the edges in $\eset{3}$ form a 6-path with a disjoint 3-path. There exist $8$ distinct two matchings (with at least one $(e_2,\cdot)$ and at least one $(e_3,\cdot)$ edge) in the $6$-path $(e_2, 0),\ldots, (e_3, 2)$ of the form
\begin{equation*}
\pbrace{(e_2, 0), (e_3, 0)},\ldots, \pbrace{(e_2, 1), (e_3, 2)}, \pbrace{(e_2, 2), (e_3, 1)}, \pbrace{(e_2, 2), (e_3, 2)}.
\end{equation*}
These matchings can be paired independently with either of the $3$ remaining edges of $(e_1, b)$, for a total of $8 \cdot 3 = 24$ many 3-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-star ($\oneint$)
\end{itemize}
When $\eset{1} \equiv \oneint$, the edges of $\eset{3}$ are restricted such that the outer edges $(e_i, 0)$ are disjoint from another, the middle edges $(e_i, 1)$ are also disjoint to each other, and only the inner edges $(e_i, 2)$ intersect with one another at exactly one common endpoint. To be precise, any outer edge $(e_i, 0)$ is disjoint to every middle edge $(e_j, 1)$ for $i \neq j$. As previously mentioned in the proof of \cref{lem:3m-G2}, at most one inner edge may appear in a $3$-matching. For arbitrary inner edge $(e_i, 2)$, we have $4$ combinations of the middle and outer edges of $e_j, e_m$, where $i \neq j \neq m$. These choices are independent and we have $4 \cdot 3 = 12$ many 3-matchings. We are not done yet, as we need to consider the middle and outer edge combinations. Notice that for each $e_i$, we have $2$ choices, i.e. a middle or outer edge, contributing $2^3 = 8$ additional $3$-matchings, for a total of $8 + 12 = 20$ many $3$-matchings in $f_3^{-1}(\eset{1})$.
\begin{itemize}
\item $3$-matching ($\threedis$)
\end{itemize}
When $\eset{1} \equiv \threedis$ subgraph, we have the case that all edges in $\eset{3}$ have the property that $(e_i, b_i)$ is disjoint to $(e_j, b_j)$ for $i \neq j$. For each $e_i$, there are then $3$ choices, independent of each other, and it results that there are $3^3 = 27$ many 3-matchings in $f_3^{-1}(\eset{1})$.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-matchings, this implies the identity.
%\end{proof}
%\qed
\subsubsection{Proof of~\cref{lem:3p-G2}}
For $\mathcal{P} \in f_2^{-1}\inparen{ \eset{2}}$ such that $\mathcal{P} $ is a $3$-path, it \textit{must} be the case by definition of $f_2$ that (i)eall edges in $f_2(\mathcal{P} )$ have at least one mapping from an edge in $\mathcal{P} $ and recall that (ii) $\mathcal{P} $ is connected. These constraint rules out every pattern $\eset{1}$ consisting of $3$ edges (it can be verified that in each three-edge pattern at least one of (i) or (ii) is violated), as well as when $\eset{1} = \twodis$. For $\eset{1} = \ed$, note that $\eset{1}$ doesn't have enough edges to have any output in $f_2^{-1}(\eset{1})$, i.e., there exists no $\eset{1} \in \binom{E_2}{3}$ such that $f_2(\mathcal{P} ) = \eset{1}$. The only surviving pattern is $\eset{1} \equiv \twopath$, where the edges of $\eset{2}$ have successive connectivity from $(e_1, 0)$ to $(e_2, 1)$. There are then two $3$-paths sharing edges $e_1$ and $e_2$ in $f_2^{-1}(\eset{1}), \pbrace{(e_1, 0), (e_1, 1), (e_2, 0)} \text{ and }\{(e_1, 1)$,$ (e_2, 0), (e_2, 1)\}$.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-paths, this implies the identity.
%\end{proof}
%\qed
\subsubsection{Proof of~\cref{lem:3p-G3}}
The argument follows along the same lines as in the proof of \cref{lem:3p-G2}. Given $\mathcal{P} \in f_3^{-1}\inparen{\eset{1}}$, it \textit{must} be that every edge in $f_3(\mathcal{P})$ has at least one edge in $\mathcal{P}$ mapped to it (and $\mathcal{P}$ is connected). Notice again that this cannot be the case for any $\eset{1} \in \binom{E_1}{3}$, nor is it the case when $\eset{1} = \twodis$. This leaves us with two patterns, $\eset{1} = \twopath$ and $\eset{1} = \ed$. For the former, it is the case that we have two $3$-paths across $e_1$ and $e_2$, $\pbrace{(e_1, 1), (e_1, 2), (e_2, 0)}$ and $\pbrace{(e_1, 2), (e_2, 0), (e_2, 1)}$. For the latter pattern $\ed$, it it trivial to see that an edge in $\graph{1}$ becomes a $3$-path in $\graph{3}$, and this proves the identity.
All of the observations above focused only on the shape of $\eset{1}$, and since we see that for fixed $\eset{1}$, we have a fixed number of $3$-paths, this implies the identity.
%\end{proof}
%\qed
\subsubsection{Proof of~\cref{lem:tri}}
The number of triangles in $\graph{\ell}$ for $\ell \geq 2$ will always be $0$ for the simple fact that all cycles in $\graph{\ell}$ will have at least six edges.
%\end{proof}
%\qed