Rough draft of correctness for auxiliary methods.

This commit is contained in:
Aaron Huber 2020-08-19 13:43:56 -04:00
parent 282a3f370b
commit 2d7dd77d6a

View file

@ -31,8 +31,10 @@ Unless explicitly stated otherwise, when speaking of a polynomial, it is assumed
Before proceeding, some useful notation.
\AH{Note, that at present, we are undecided on the data structure for $\polytree$.}
\begin{Definition}[Expression Tree]\label{def:express-tree}
An expression tree $\polytree$ is an ADT logically viewed as an n-ary tree, whose internal nodes are from the set $\{+, \times\}$, with leaf nodes being either numerical coefficients or variables, but not both.
An expression tree $\polytree$ is a binary %an ADT logically viewed as an n-ary
tree, whose internal nodes are from the set $\{+, \times\}$, with leaf nodes being either numerical coefficients or variables.
\end{Definition}
Note that $\polytree$ is the expression tree corresponding to a general polynomial $\poly$, and is therefore generally \textit{not} in the standard monomial basis.
@ -41,7 +43,7 @@ Note that $\polytree$ is the expression tree corresponding to a general polynomi
Denote $poly(\polytree)$ to be the function that takes as input expression tree $\polytree$ and outputs the polynomial of the same factored form as corresponding to expression tree $\polytree$.
\end{Definition}
\begin{Definition}[Expression Tree Set]\label{def:express-tree-set}$\expresstree{\smb}$ is the set of all possible polynomial expression trees whose standard monomial basis is $\smb$.
\begin{Definition}[Expression Tree Set]\label{def:express-tree-set}$\expresstree{\smb}$ is the set of all possible expression trees each of whose corresponding polynomial in the standard monomial basis is $\smb$.
\end{Definition}
Note that \cref{def:express-tree-set} implies that $\polytree \subseteq \expresstree{\smb}$.
@ -50,10 +52,10 @@ Note that \cref{def:express-tree-set} implies that $\polytree \subseteq \express
$\expandtree$ is the pure SOP expansion of $\polytree$, where non-distinct monomials are not combined.
\end{Definition}
To illustrate \cref{def:expand-tree} with an example, consider when $\polytree$ models the polynoial $(x + 2y)(2x - y)$. The pure expansion then is $2x^2 - xy + 4xy - 2y^2 = \expandtree$.
To illustrate \cref{def:expand-tree} with an example, consider when $poly(\polytree)$ is $(x + 2y)(2x - y)$. (For preciseness, note that $\polytree$ would use a $+$ node to model the second factor, while storing a child coefficient of $-1$ for the variable $y$. The subtree $\polytree_S$ would be $+(\times(2, x), \times(-1, y))$, and one can see that $poly(\polytree_S)$ is indeed equivlent to $(2x - y)$). The pure expansion then is $2x^2 - xy + 4xy - 2y^2 = \expandtree$.
\begin{Definition}[Positive T]\label{def:positive-tree}
Let $\abstree$ denote the resulting expression tree when each coefficient $c_i$ in $\polytree$ is exchanged with its absolute value $|c_i|$, and then the resulting $\polytree'$ converted to the expression tree that directly models $poly(\polytree')$, with a root node $+$, whose children consist of all the monomials in the standard monomial basis of $poly(\polytree')$.
Let $\abstree$ denote the resulting expression tree when each coefficient $c_i$ in $\polytree$ is exchanged with its absolute value $|c_i|$, and then the resulting $\polytree'$ converted to the expression tree that directly models the standard monomial basis of $poly(\polytree')$.%, with a root node $+$, whose children consist of all the monomials in the standard monomial basis of $poly(\polytree')$.
\end{Definition}
Using the same polynomial from the above example, $poly(\abstree) = (x + 2y)(2x + y) = 2x^2 +xy +4xy + 2y^2 = 2x^2 + 5xy + 2y^2$.
@ -61,7 +63,7 @@ Using the same polynomial from the above example, $poly(\abstree) = (x + 2y)(2x
\subsection{Approximating $\rpoly$}
\subsubsection{Description}
Algorithm ~\ref{alg:mon-sam} approximates $\rpoly$ by employing some auxiiliary methods on its input $\polytree$, sampling $\polytree$ $\frac{\log{\frac{1}{\delta}}}{\epsilon^2}$ times, and then outputting an estimate of $\rpoly$ within a multiplicative error of $1 \pm \epsilon$ with a probability of $1 - \delta$.
Algorithm ~\ref{alg:mon-sam} approximates $\rpoly$ by employing some auxiliary methods on its input $\polytree$, sampling $\polytree$ $\frac{\log{\frac{1}{\delta}}}{\epsilon^2}$ times, and then outputting an estimate of $\rpoly$ within a multiplicative error of $1 \pm \epsilon$ with a probability of $1 - \delta$.
\subsubsection{Psuedo Code}
@ -70,7 +72,7 @@ Algorithm ~\ref{alg:mon-sam} approximates $\rpoly$ by employing some auxiiliary
\label{alg:mon-sam}
\begin{algorithmic}[1]
\State $acc \gets 0$
\State \textsc{OnePass($\polytree$)}\Comment{\textsc{OnePass} and \textsc{Sample} defined next}
\State \textsc{OnePass($\polytree$)}\Comment{\textsc{OnePass} and \textsc{Sample} defined subsequently}
\For{$sample$ $in$ $\frac{\log{\frac{1}{\delta}}}{\epsilon^2}$}\Comment{Perform the required number of samples}
\State $acc \gets acc + $\textsc{Sample($\polytree$)}\Comment{Store the sum over all samples}
\EndFor
@ -80,6 +82,7 @@ Algorithm ~\ref{alg:mon-sam} approximates $\rpoly$ by employing some auxiiliary
\end{algorithm}
\subsubsection{Correctness}
\AH{Unsure where to place the theorem. Maybe above.}
\begin{Theorem}\label{lem:approx-alg}
For any query polynomial $\poly(\vct{X})$, an approximation of $\rpoly(\prob_1,\ldots, \prob_n)$ can be computed in $O\left(|\poly|\cdot k \frac{\log\frac{1}{\conf}}{\error^2}\right)$, within $1 \pm \error$ multiplicative error with probability $\geq 1 - \conf$, where $k$ denotes the product width of $\poly$.
\end{Theorem}
@ -88,16 +91,16 @@ For any query polynomial $\poly(\vct{X})$, an approximation of $\rpoly(\prob_1,\
Algorithm \ref{alg:mon-sam} computes $\frac{\log\frac{1}{\conf}}{\error^2}$ samples, outputting an estimate of $\rpoly(\prob,\ldots, \prob)$ within a multiplicative $1 \pm \error$ error with probability $1 - \conf$.
\end{Lemma}
Before the proof, a brief summary of the sample scheme is necessary. Regardless of the $\polytree$, note that when one samples with a weighted distribution corresponding to the coefficients in $poly(\expandtree)$, it is the same as uniformly sampling over all individual terms of the equivalent polynomial whose terms have coefficients in the set $\{-1, 1\}$, i.e. collapsed monomials are decoupled. Following this reasoning, algorithim ~\ref{alg:one-pass} computes such a weighted distribution and algorithm ~\ref{alg:sample} produces samples accordingly. As a result, from here on, we can consider our sampling scheme to be uniform.
%Before the proof, a brief summary of the sample scheme is necessary. Regardless of the $\polytree$, note that when one samples with a weighted distribution corresponding to the coefficients in $poly(\expandtree)$, it is the same as uniformly sampling over all individual terms of the equivalent polynomial whose terms have coefficients in the set $\{-1, 1\}$, i.e. collapsed monomials are decoupled. Following this reasoning, algorithim ~\ref{alg:one-pass} computes such a weighted distribution and algorithm ~\ref{alg:sample} produces samples accordingly. As a result, from here on, we can consider our sampling scheme to be uniform.
%each of the $k$ product terms is sampled from individually, where the final output sample is sampled with a probability that is proportional to its coefficient in $\expandtree$. Note, that This is performed by \cref{alg:sample} and its correctness will be argued momentarily. For now it suffices to note that the sampling scheme samples from each of the $k$ products in a POS using a weighted distribution equivalent to sampling uniformly over all monomials.
\begin{proof}[Proof of Lemma \ref{lem:mon-samp}]
The first part of the claim in lemma ~\ref{lem:mon-samp} is trivial, as evidenced in the number of iterations in the for loop.
Next, consider $\expandtree$ and let $c_i$ be the coefficient of the $i^{th}$ monomial and $\distinctvars_i$ be the number of distinct variables appearing in the $i^{th}$ monomial. As discussed above, sampling each term $t$ in $\expandtree$ with probability $\frac{|c_i|}{\abstree(1,\ldots, 1)}$ is the equivalent of sampling uniformly over $\expandtree$. Now consider $\rpoly$ and note that $\coeffitem{i}$ is the value of the $i^{th}$ monomial term in $\rpoly(\prob_1,\ldots, \prob_n)$. Let $m$ be the number of terms in $\expandtree$ and $\coeffset$ to be the set $\{c_1,\ldots, c_m\}.$
Next, consider $\expandtree$ and let $c_i$ be the coefficient of the $i^{th}$ monomial and $\distinctvars_i$ be the number of distinct variables appearing in the $i^{th}$ monomial. As will be seen, the sampling scheme samples each term $t$ in $\expandtree$ with probability $\frac{|c_i|}{\abstree(1,\ldots, 1)}$. Now consider $\rpoly$ and note that $\coeffitem{i}$ is the value of the $i^{th}$ monomial term in $\rpoly(\prob_1,\ldots, \prob_n)$. Let $m$ be the number of terms in $\expandtree$ and $\coeffset$ to be the set $\{c_1,\ldots, c_m\}.$
Consider now a set of $\samplesize$ random variables $\vct{\randvar}$, where $\randvar_i \sim \unidist{\coeffset}$ Then for random variable $\randvar_i$, it is the case that $\expct\pbox{\randvar_i} = \sum_{i = 1}^{\setsize}\frac{c'_i \cdot \prob^{\distinctvars}}{\sum_{i = 1}^{\setsize}|c_i|} = \frac{\rpoly(\prob,\ldots, \prob)}{\abstree(1,\ldots, 1)}$. Let $\hoeffest = \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i$. It is also true that
Consider now a set of $\samplesize$ random variables $\vct{\randvar}$, where each $\randvar_i$ is distributed as described above. Then for random variable $\randvar_i$, it is the case that $\expct\pbox{\randvar_i} = \sum_{i = 1}^{\setsize}\frac{c'_i \cdot \prob^{\distinctvars_i}}{\sum_{i = 1}^{\setsize}|c_i|} = \frac{\rpoly(\prob,\ldots, \prob)}{\abstree(1,\ldots, 1)}$. Let $\hoeffest = \frac{1}{\samplesize}\sum_{i = 1}^{\samplesize}\randvar_i$. It is also true that
\[\expct\pbox{\hoeffest} = \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}\frac{1}{\setsize}\sum_{j = 1}^{\setsize}\frac{c'_i \cdot \prob^{\distinctvars}}{\setsize} = \frac{\rpoly(\prob,\ldots, \prob)}{\abstree(1,\ldots, 1)}.\]
@ -115,28 +118,28 @@ Solving for the number of samples $\samplesize$ we get
Equation \cref{eq:hoeff-1} results computing the sum in the denominator of the exponential. Equation \cref{eq:hoeff-2} is the result of dividing both sides by $2$. Equation \cref{eq:hoeff-3} follows from taking the reciprocal of both sides, and noting that such an operation flips the inequality sign. We then derive \cref{eq:hoeff-4} by the taking the base $e$ log of both sides, and \cref{eq:hoeff-5} results from reducing common factors. We arrive at the final result of \cref{eq:hoeff-6} by simply multiplying both sides by the reciprocal of the RHS fraction without the $\samplesize$ factor.
By Hoeffding, then algorithm ~\ref{alg:mon-sam} takes the correct number of samples, and this concludes the proof of lemma ~\ref{lem:mon-samp}.
By Hoeffding, then algorithm ~\ref{alg:mon-sam} takes the correct number of samples to obtain the desired confidence bounds, and this concludes the proof of lemma ~\ref{lem:mon-samp}.
\end{proof}
\subsubsection{Run-time Analysis}
\AH{To be completed, this needs the analysis for the auxiliary methods and sampling scheme.}
\subsection{OnePass Algorithm}
\subsubsection{Description}
Auxiliary algorithm ~\ref{alg:one-pass} has the responsibility of computing the weighted (uniform) distribution over $\expandtree$. This consists of two parts. Computing the sum over the absolute values of each coefficient ($\abstree(1,\ldots, 1)$), and computing the distribution over each monomial term of $\expandtree$, without ever materializing $\expandtree$.
Auxiliary algorithm ~\ref{alg:one-pass} has the responsibility of computing the weighted distribution over $\expandtree$. This consists of two parts. Computing the sum over the absolute values of each coefficient ($\abstree(1,\ldots, 1)$), and computing the distribution over each monomial term of $\expandtree$, without ever materializing $\expandtree$.
Algorithm ~\ref{alg:one-pass} takes $\polytree$ as input, modifying $\polytree$ in place with the appropriate weight distribution across all nodes, and finally returning $\abstree(1,\ldots, 1)$. For concreteness, consider the example when $poly(\polytree) = (x_1 + x_2)(x_1 - x_2) + x_2^2$. The expression tree $\polytree$ would then be $+\left(\times\left(+\left(x_1, x_2\right), +\left(x_1, -x_2\right)\right), \times\left(y, y\right)\right)$.
\AH{A tree diagram would work much better, but to do that it appears that I need to spend time learning the tikz package, which I haven't had time for yet.}
To compute $\abstree(1,\ldots, 1)$, algorithm ~\ref{alg:one-pass} makes a bottom-up traversal of $\polytree$ and performs the following computations. For a leaf node whose value is a coefficient, the value is saved. When a $+$ node is visited, the coefficient values of its children are summed. Finally, for the case of a $\times$ node, the coefficient values of the children are multiplied. The algorithm returns the total value upon termination.
Algorithm ~\ref{alg:one-pass} computes the weighted (uniform) probability distribution in the same bottom-up traversal. When a leaf node is encountered, its value is saved if it is a coefficient. When a $\times$ node is visited, the coefficient values of its children are multiplied. When a $+$ node is visited, the algorithm computes and saves the relative probabilities of each one of its children. This is done by taking the sum of its children's coefficient absolute values, and for each child, dividing the child's coefficient absolute value by that sum. Note the difference in treatment between $+$ and $\times$ nodes, that the former stores probabilities for its children while the latter stores a probability measure for itself. Upon termination, all appropriate nodes have been annotated accordingly.
\AH{I've had a slight conflict here. The algorithm need not return $\abstree(1,\ldots, 1)$ upon completion, as $\polytree$ has been correctly annotated. But this requires a few more lines of pseudo code, and there is the concern of 'over complicating' things for the user.}
Algorithm ~\ref{alg:one-pass} computes the weighted probability distribution in the same bottom-up traversal. When a leaf node is encountered, its value is saved if it is a coefficient. When a $\times$ node is visited, the coefficient values of its children are multiplied, recording that value at the $\times$ node. When a $+$ node is visited, the algorithm computes and saves the relative probabilities of each one of its children. This is done by taking the sum of its children's coefficient absolute values, and for each child, dividing the child's coefficient absolute value by that sum. Lastly, the partial value of its subtree coefficients is stored at the $+$ node. Upon termination, all appropriate nodes have been annotated accordingly.
For the running example, after one pass, \cref{alg:one-pass} would have learned to sample the two children of the root $+$ node with $P\left(\times\left(+\left(x_1, x_2\right), +\left(x_1, -x_2\right)\right)\right) = \frac{4}{5}$ and $P\left(\times\left(x_2, x_2\right)\right) = \frac{1}{5}$. Similarly, the two inner $+$ nodes of the root's left child, call them $+_1$ and $+_2$, using $l$ for left child and $r$ for right child are $P_{+_1}(l) = P_{+_1}(r) = P_{+_2}(l) = P_{+_2}(r) = \frac{1}{2}$. Note that in this example, the sampling probabilities for the children of each inner $+$ node are equal to one another because both parents have the same number of children, and, in each case, the children of each parent $+$ node share the same $|c_i|$.
The following pseudo code assumes that $\polytree$ has the following members. $\polytree.val$ holds the value stored by $\polytree$, $\polytree.children$ contains all children of $\polytree$, $\polytree.weight$ is the probability of choosing $\polytree$, and $\polytree.partial$ is the coefficient of $\polytree$. A child of $\polytree$ is assumed to be an expression tree itself. The function $isnum(\cdot)$ returns true if the value is numeric.
The following pseudo code assumes that $\polytree$ has the following members. $\polytree.val$ holds the value stored by $\polytree$, $\polytree.children$ contains all children of $\polytree$, $\polytree.weight$ is the probability of choosing $\polytree$, and $\polytree.partial$ is the coefficient of $\polytree$. As in the recursive nature of trees, a child of $\polytree$ is assumed to be an expression tree itself. The function $isnum(\cdot)$ returns true if the value is numeric.
\AH{{\bf Next:}
5) Prove correctness for all algos.
@ -166,20 +169,40 @@ The following pseudo code assumes that $\polytree$ has the following members. $
\State $T.partial \gets acc$
\State Return $T.partial$
\ElsIf{$isnum(\polytree.val)$}\Comment{Base case}
\State Return $T.val$
\State Return $|T.val|$
\Else
\State Return 1
\EndIf
\end{algorithmic}
\end{algorithm}
\subsubsection{Correctness of Algorithm ~\ref{alg:one-pass}}
\begin{Lemma}\label{lem:one-pass}
Algorithm ~\ref{alg:one-pass} correctly computes $\abstree(1,\ldots, 1)$ for each subtree $S$ of $\polytree$. For the children of $+$ nodes, it correctly computes the weighted distrution across each child. All computations are performed in one traversal.
\end{Lemma}
\begin{proof}[Proof of Lemma ~\ref{lem:one-pass}]
Use proof by structural induction over the depth $d$ of the binary tree $\polytree$.
For the base case, $d = 0$, it is the case that the root 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 that $\abstree(1,\ldots, 1) = 1$ which is correct. When the root is a coefficient, the absolute value of the coefficient is returned, which is indeed $\abstree(1,\ldots, 1)$. Since the root node cannot be a $+$ node, this proves the base case.
Let the inductive hypothesis be the assumption that for $d \leq k \geq 0$, lemma ~\ref{lem:one-pass} is true for algorithm ~\ref{alg:one-pass}.
Now prove that lemma ~\ref{lem:one-pass} holds for $k + 1$. Notice that the root of $\polytree$ has at most two children, $\polytree_L$ and $\polytree_R$. Note also, that for each child, it is the case that $d = k$, since we have a maximal path from the root to each child of $1$. Then, by inductive hypothesis, lemma ~\ref{lem:one-pass} holds for each existing child, and we are left with two possibilities for the root node. The first case is when the root node is a $+$ node. When this happens, algorithm ~\ref{alg:one-pass} computes $\abstree(1,\ldots, 1) = |T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1)$ which is correct. For the distribution of the children of $+$, algorithm ~\ref{alg:one-pass} computes $P(\polytree_i) = \frac{|T_i|(1,\ldots, 1)}{|T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1)}$ which is indeed the case. The second case is when the root is a $\times$ node. Algorithm ~\ref{alg:one-pass} then computes the product of the subtree partial values, $|T_L|(1,\ldots, 1) \times |T_R|(1,\ldots, 1)$ which indeed equals $\abstree(1,\ldots, 1)$.
Since algorithm ~\ref{alg:one-pass} completes exactly one traversal, computing these values from the bottom up, it is the case that all subtree values are computed, and this completes the proof.
\end{proof}
\qed
\subsubsection{Run-time Analysis}
\subsection{Sample Algorithm}
Algorithm ~\ref{alg:sample} takes $\polytree$ as input and performs the equivalent of outputting a sample $\randvar_i$ such that $\randvar_i \sim Uniform(S)$, where $S$ represents the multiset of monomials in $\expandtree$. While one cannot compute $\expandtree$ in time better than $O(N^k)$, the algorithm uses a technique on $\polytree$ which produces a uniform sample from $\expandtree$ without ever materializing $\expandtree$.
Algorithm ~\ref{alg:sample} takes $\polytree$ as input and produces a sample $\randvar_i$ according to the weighted distribution computed by \textsc{OnePass}. While one cannot compute $\expandtree$ in time better than $O(N^k)$, the algorithm, similar to \textsc{OnePass}, uses a technique on $\polytree$ which produces a sample from $\expandtree$ without ever materializing $\expandtree$.
Algorithm ~\ref{alg:sample} then uniformly selects a monomial from $\expandtree$ by the following top-down traversal. For a parent $+$ node, a subtree is chosen over the previously computed weighted sampling distribution. When a parent $\times$ node is visited, the monomials sampled from its subtrees are combined into one monomial. For the case of a parent node with children that are leaf nodes, if the parent is a $\times$ node, then each leaf node is returned, with the coefficient reduced to either $\{-1, 1\}$ depending on its sign. If the parent node is a $+$ node, then one of the chidlren is sampled as discussed previously. The algorithm concludes outputting $sign(c_i)\cdot\prob^{d_i}$. The pseudo code uses $isdist(\cdot)$ to mean a function that takes a single variable from $\vct{X}$ as input and outputs whether or not we have seen this variable while computing the current sample.
Algorithm ~\ref{alg:sample} selects a monomial from $\expandtree$ by the following top-down traversal. For a parent $+$ node, a subtree is chosen over the previously computed weighted sampling distribution. When a parent $\times$ node is visited, the monomials sampled from its subtrees are combined into one monomial. For the case of a parent node with children that are leaf nodes, if the parent is a $\times$ node, then each leaf node is returned, with the coefficient reduced to either $\{-1, 1\}$ depending on its sign. If the parent node is a $+$ node, then one of the chidlren is sampled as discussed previously. The algorithm concludes outputting $sign(c_i)\cdot\prob^{d_i}$. The pseudo code uses $isdist(\cdot)$ to mean a function that takes a single variable from $\vct{X}$ as input and outputs whether or not we have seen this variable while computing the current sample.
\subsubsection{Pseudo Code}
Algorithm ~\ref{alg:sample} should be placed here.
\begin{algorithm}
\caption{Sample($\polytree$)}
@ -197,13 +220,27 @@ Algorithm ~\ref{alg:sample} should be placed here.
\State Return $sign(T.val)$
\ElsIf{$isdist(T.val)$}\Comment{The leaf is a variable; we need to know if it is distinct}
\State Return $\prob$
\Else
\Else \Comment{If the variable is not distinct}
\State Return $1$
\EndIf
\end{algorithmic}
\end{algorithm}
\subsubsection{Correctness of Algorithm ~\ref{alg:one-pass}}
\subsubsection{Correctness of Algorithm ~\ref{alg:sample}}
\begin{Lemma}\label{lem:sample}
Algorithm ~\ref{alg:sample} correctly samples a monomial from $\rpoly(\prob,\ldots, \prob)$ according to the weighted distribution computed by \textsc{OnePass}.
\end{Lemma}
\begin{proof}[Proof of Lemma ~\ref{lem:sample}]
Prove by structural induction on the depth $d$ of $\polytree$. 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. When the root is a variable, algorithm ~\ref{alg:sample} returns $\prob$. When the root is a coefficient, it returns $sign(c_i)$, both of which are correct.
\AH{1) I think we need to say more about this...more precision on why they are both correct.}
For the inductive hypothesis, assume that for $d \leq k \geq 0$ lemma ~\ref{lem:sample} is true.
Prove now, that when $d = k + 1$ lemma ~\ref{lem:sample} holds. It is the case that the root of $\polytree$ has up to two children $\polytree_L$ and $\polytree_R$. Since we have a maximal path of 1 from the root to either child, we know that by inductive hypothesis, $\polytree_L$ and $\polytree_R$ are both depth $d = k$, and lemma ~\ref{lem:sample} holds for either of them.
Then the root has to be either a $+$ or $\times$ node. When it is the former, the call to $WeightedSample$ over both subtrees will return either of the two subtrees with probability proportional to the distribution computed by \textsc{OnePass}. When the root is a $\times$ node, the algorithm returns the product of the sample output for existing subtrees. Both of these cases produce correct samples, and this concludes the proof.
\end{proof}
\qed
%The algorithm begins with recursively visiting the root node and all of its children, until it reaches all leaves. Thus, every node is visited. When going from the bottom up, it is the case for a parent node $+$ that the algorithm records the sum of its children's coefficient values, and produces a weighted distribution based on the partial values. This weighted distribution across each child subtree is in exact proportion to the probability of choosing either child given that it's parent's subtree was chosen. Consider the base case, when we have $n$ leaf nodes whose parent (root) node is $+$. For each $|c_i|$, it is the case that $\frac{|c_i|}{\sum_{i \in [n]}|c_i|}$ is exactly the uniform distribution of $\expandtree$.
%
%When a $\times$ node is visited, \cref{alg:one-pass} takes the product of each of its children. Note that this is correct, since it is the case that a product of polynomials has a sum of coefficients equal to the product of the sum of each polynomial's coefficients.