We can think of $\poly(\vct{w})$ as a function whose input are the variables $X_1,\ldots, X_M$ as in $\poly(X_1,\ldots, X_M)$. Denote the sum of products expansion of $\poly(X_1,\ldots, X_\numTup)$ as $\poly(X_1,\ldots, X_\numTup)_{\Sigma}$
\begin{Definition}\label{def:qtilde}
Define $\rpoly(X_1,\ldots, X_\numTup)$ as the reduced version of $\poly(X_1,\ldots, X_\numTup)_{\Sigma}$, of the form
Intuitively, $\rpoly(\textbf{X})$ is the expanded sum of products form of $\poly(\textbf{X})$ such that if any $X_j$ term has an exponent $e > 1$, it is reduced to $1$, i.e. $X_j^e\mapsto X_j$ for any $e > 1$.
Alternatively, one can gain intuition for $\rpoly$ by thinking of $\rpoly$ as the resulting sum of product expansion of $\poly$ when $\poly$ is in a factorized form such that none of its terms have an exponent $e > 1$, with an idempotent product operator.
When $\poly(X_1,\ldots, X_\numTup)=\sum\limits_{\vct{d}\in\{0,\ldots, D\}^\numTup}q_{\vct{d}}\cdot\prod\limits_{\substack{i =1\\s.t. d_i\geq1}}^{\numTup}X_i^{d_i}$, we have then that $\rpoly(X_1,\ldots, X_\numTup)=\sum\limits_{\vct{d}\in\{0,\ldots, D\}^\numTup} q_{\vct{d}}\cdot\prod\limits_{\substack{i =1\\s.t. d_i\geq1}}^{\numTup}X_i$.
Note that any $\poly$ in factorized form is equivalent to its sum of product expansion. For each term in the expanded form, further note that for all $b \in\{0, 1\}$ and all $e \geq1$, $b^e =1$.
%Using the fact above, we need to compute \[\sum_{(\wbit_1,\ldots, \wbit_\numTup) \in \{0, 1\}}\rpoly(\wbit_1,\ldots, \wbit_\numTup)\]. We therefore argue that
Let $\poly$ be the generalized polynomial, i.e., the polynomial of $\numTup$ variables with highest degree $= D$: %, in which every possible monomial permutation appears,
In steps \cref{p1-s1} and \cref{p1-s2}, by linearity of expectation (recall the variables are independent), the expecation can be pushed all the way inside of the product. In \cref{p1-s3}, note that $w_i \in\{0, 1\}$ which further implies that for any exponent $e \geq1$, $w_i^e = w_i$. Next, in \cref{p1-s4} the expectation of a tuple is indeed its probability.
Finally, observe \cref{p1-s5} by construction in \cref{lem:pre-poly-rpoly}, that $\rpoly(\prob_1,\ldots, \prob_\numTup)$ is exactly the product of probabilities of each variable in each monomial across the entire sum.
If $\poly$ is given to us in a sum of monomials form, the expectation of $\poly$ ($\ex{\poly}$) can be computed in $O(|\poly|)$, where $|\poly|$ denotes the total number of multiplication/addition operators.
Note that \cref{lem:exp-poly-rpoly} shows that $\ex{\poly}=\rpoly(\prob_1,\ldots, \prob_\numTup)$. Therefore, if $\poly$ is already in sum of products form, one only needs to compute $\poly(\prob_1,\ldots, \prob_\numTup)$ ignoring exponent terms (note that such a polynomial is $\rpoly(\prob_1,\ldots, \prob_\numTup)$), which is indeed has $O(|\poly|)$ compututations.\qed
To this end, consider the following graph $G(V, E)$, where $|E| = m$, $|V| =\numTup$, and $i, j \in[\numTup]$. Consider the query $q_E(X_1,\ldots, X_\numTup)=\sum\limits_{(i, j)\in E} X_i \cdot X_j$.
\AH{I think that we are okay with this now. We can use both polynomial and query notation interchangably. Does it matter which we use in the lemmas, i.e. $\poly(\vct{w})$ vs. $\poly(\wElem_1,\ldots, \wElem_N)$. Please let me know.}
If we can compute $\poly(\wElem_1,\ldots, \wElem_\numTup)= q_E(\wElem_1,\dots, \wElem_\numTup)^3$ in T(m) time for $\wElem_1=\cdots=\wElem_\numTup=\prob$, then we can count the number of 3-matchings in $G$ in $T(m)+ O(m)$ time.
If we can compute $\poly(\wElem_1,\ldots, \wElem_\numTup)= q_E(\wElem_1,\ldots, \wElem_\numTup)^3$ in T(m) time for O(1) distinct values of $\prob$ then we can count the number of triangles (and the number of 3-paths, the number of 3-matchings) in $G$ in O(T(m) + m) time.
When we expand $\poly(\wElem_1,\ldots, \wElem_N)= q_E(\wElem_1,\ldots, \wElem_\numTup)^3$ out and assign all exponents $e \geq1$ a value of $1$, we have the following,
First, let us do a warm-up by computing $\rpoly(\wElem_1,\dots, \wElem_\numTup)$ when $\poly= q_E(\wElem_1,\ldots, \wElem_\numTup)$. Before doing so, we introduce a notation. Let $\numocc{H}$ denote the number of occurrences that $H$ occurs in $G$. So, e.g., $\numocc{\ed}$ is the number of edges ($m$) in $G$.
\AH{UPDATE: I did a quick google, and it \textit{appears} that there is a bit of a learning curve to implement node/edge symbols in LaTeX. So, maybe, if time is of the essence, we go with another notation.}
The proof basically follows by definition. When we expand $\poly^2$, and make all exponents $e =1$, substituting $\prob$ for all $\wElem_i$ we get $\rpoly_2(\prob,\ldots, \prob)=\numocc{\ed}\cdot\prob^2+2\cdot\numocc{\twopath}\cdot\prob^3+2\cdot\numocc{\twodis}\cdot\prob^4$.
Thus, since each of the summations can be computed in O(m) time, this implies that by \cref{eq:part-1}$\rpoly(\prob,\ldots, \prob)$ can be computed in O(m) time.\qed
Rather than list all the expressions in full detail, let us make some observations regarding the sum. Let $e_1=(i_1, j_1), e_2=(i_2, j_2), e_3=(i_3, j_3)$. Notice that each expression in the sum consists of a triple $(e_1, e_2, e_3)$. There are three forms the triple $(e_1, e_2, e_3)$ can take.
\underline{case 1:}$e_1= e_2= e_3$, where all edges are the same. There are exactly $m$ such triples, each with a $\prob^2$ factor.
\underline{case 2:} This case occurs when there are two distinct edges of the three. All 6 combinations of two distinct values consist of the same monomial in $\rpoly$, i.e. $(e_1, e_1, e_2)$ is the same as $(e_2, e_1, e_2)$. This case produces the following edge patterns: $\twodis, \twopath$.
\underline{case 3:}$e_1\neq e_2\neq e_3$, i.e., when all edges are distinct. This case consists of the following edge patterns: $\threedis, \twopathdis, \threepath, \oneint, \tri$.
It has already been shown previously that $\numocc{\ed}, \numocc{\twopath}, \numocc{\twodis}$ can be computed in O(m) time. Here are the arguments for the rest.
\[\numocc{\oneint}=\sum_{u \in V}\binom{d_u}{3}\]
$\numocc{\twopathdis}+\numocc{\threedis}=$ the number of occurrences of three distinct edges with five or six vertices. This can be counted in the following manner. For every edge $(u, v)\in E$, throw away all neighbors of $u$ and $v$ and pick two more distinct edges.
\[\numocc{\twopathdis}+\numocc{\threedis}=\sum_{(u, v)\in E}\binom{m - d_u - d_v +1}{2}\] The implication in \cref{claim:four-two} follows by the above and \cref{lem:qE3-exp}.
%\AR{Also you can modify the text of \textsc{Proof} by using the following latex command \texttt{\\begin\{proof\}[Proof of Lemma 2]} and Latex will typeset this as \textsc{Proof of Lemma 2}, which is what you really want.}
\cref{claim:four-two} says that if we know $\rpoly_3(\prob,\ldots, \prob)$, then we can know in O(m) additional time
\[\numocc{\tri}+\numocc{\threepath}\cdot\prob-\numocc{\threedis}\cdot(\prob^2-\prob^3).\] We can think of each term in the above equation as a variable, where one can solve a linear system given 3 distinct $\prob$ values, assuming independence of the three linear equations. In the worst case, without independence, 4 distince values of $\prob$ would suffice...because Atri said so, and I need to ask him for understanding why this is the case, of which I suspect that it has to do with basic result(s) in linear algebra.\AR{Follows from the fact that the corresponding coefficient matrix is the so called Vandermonde matrix, which has full rank.}
The argument for \cref{lem:gen-p} cannot be applied to \cref{lem:const-p} since we have that $\prob$ is fixed. We have hope in the following: we assume that we can solve this problem for all graphs, and the hope would be be to solve the problem for say $G_1, G_2, G_3$, where $G_1$ is arbitrary, and relate the values of $\numocc{H}$, where $H$ is a placeholder for the relevant edge combination. The hope is that these relations would result in three independent linear equations, and then we would be done.
Consider graph $G_2$, constructed from an arbitrary graph $G_1$. We wish to show that the number of 3-matchings in $G_2$ will always be the linear combination above, regardless of the construction of $G_1$.
\begin{proof}
Denote $3_{match}$ as the set of 3-matchings in $G_2$. Denote $SG$ as the set of subgraphs imposed on $G_1$. Notate each edge in $G_2$ as $(e, b)$ such that $b \in\{0, 1\}$, where $b$ identifies either the first or second edge of the two path that replaced the original $G_1$ edge. Let $f: 3_{match}\mapsto SG$ be a function that maps a distinct 3-matching in $G_2$ to its generating subgraph. An arbitrary $M \in3_{match}$ in $G_2$ is then denoted by $(e_1, b_1), (e_2, b_2), (e_3, b_3)$, and $f(M)=\{e_1, e_2, e_3\}$. Note that $f(M)$ is a set, i.e., the distinct edges of the generating subgraph in $G_1$.
\underline{f is a function}:
First, let us argue that $f$ is indeed a function. To do this, first note that for $G_2$ to contain a 3-matching, it must be that the generating subgraph in $G_1$ has at least 3 distinct edges. This is because, with only 2 distinct $G_1$ edges, there are only two subgraph patterns, i.e., disjoint and two-path, both of which when transformed into $G_2$ will not have enough disjoint edges to create a 3-matching.
Consider then a minimal $G_1$, i.e. a graph with at most 3 edges. Choose an arbitrary 3-matching $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ in the generated $G_2$ graph. Choose an arbitrary edge $(e_i, b_i)$ and remove its corresponding generating edge in $G_1$. Notice that this 3-matching now disappears from $G_2$. Now replace the removed edge in $G_1$ with a new edge, placing it anywhere other than its original position. Note that, no matter where the replacement edge lies, it cannot be that it generates the same 3-matching that the original edge helped uniquely generate, since a one-to-one correspondence exists between $(e_i, b_i)$ and $e_i$. Thus, since any $M \in3_{match}$ cannot be generated from more than one subgraph in $G_1$, $f$ must be a function.
\underline{For any $M \in3_{match}, | f(M) |\leq3$}
Since any arbitrary 3-matching $(e_1, b_1), (e_2, b_2), (e_3, b_3)$ has an image of $\{e_1, e_2, e_3\}$, which is a set, it has to be the case that $|f(M)|$ can be no more than $3$.
\underline{For any $G' \in SG: |s| \leq3$, there are a fixed number of 3-matchings}
\underline{$M'$ s.t. $f(M')= G'$}
First, note that there are a fixed number of 3-edge subgraphs that can appear on a given $G_1$. Second, these subgraphs themselves are fixed, with the number of edges, vertices, and intersections always being the same. Third, since each possible subgraph is fixed, it must then be the case that each possible subgraph will always generate the same number of 3-matchings in $G_2$.