Pushing changes to OnePass Correctness and SampleMon Runtime Analysis; the latter is not correct as of yet.

This commit is contained in:
Aaron Huber 2021-02-26 17:03:16 -05:00
parent 36538a6b2d
commit 40b38acbc6

View file

@ -641,12 +641,12 @@ For the base case, we have only one gate, which by definition is a source gate a
For the inductive hypothesis, assume that \onepass correctly computes \subcircuit.\prt, \subcircuit.\lwght, and \subcircuit.\rwght for all gates \subcircuit in \circuit with $k > 0$ iterations over \topord.
We now prove for $k + 1$ iterations that \onepass correctly computes the \prt, \lwght, and \rwght values for each gate \gate in \circuit. %By the hypothesis the first $k$ gates (alternatively \textit{iterations}) have correctly computed values.
Note that the $k+ 1$ iteration must be the last gate in the topological order, and this gate must be the sink gate $\gate_\vari{s}$. It is also the case that $\gate_\vari{s}$ has at most two children. Finally, note that $\gate_\vari{s}$ is an internal node and implying that $\gate_\vari{s}.\type = \circplus$ or $\gate_\vari{s}.\type = \circmult$.
We now prove for $k + 1$ iterations that \onepass correctly computes the \prt, \lwght, and \rwght values for each gate $\gate_\vari{i}$ in \circuit. %By the hypothesis the first $k$ gates (alternatively \textit{iterations}) have correctly computed values.
Note that the $\gate_\vari{k + 1}$ must be in the last ordering of all gates $\gate_\vari{i}$ for $i \in [k + 1]$. It is also the case that $\gate_{k+1}$ has at most two children. Finally, note that for \size(\circuit) > 1, $\gate_{k+1}$ is an internal node and implying that $\gate_\vari{s}.\type = \circplus$ or $\gate_\vari{s}.\type = \circmult$.
When $\gate_\vari{s}.\type = \circplus$, then by line ~\ref{alg:one-pass-plus} $\gate_\vari{s}.\prt = \gate_{\vari{s}_\lchild}.\prt + \gate_{\vari{s}_\rchild}.\prt$, a correct computation, as per ~\ref{eq:T-all-ones}. Further, lines ~\ref{alg:one-pass-lwght} and ~\ref{alg:one-pass-rwght} compute $\gate_{\vari{s}}.\lwght = \frac{\gate_{\vari{s}_\lchild}.\prt}{\gate_{\vari{s}}.\prt}$ and analogously for $\gate_{\vari{s}}.\rwght$. Note that all values needed for each computation have been correctly computed by the I.H.
When $\gate_{k+1}.\type = \circplus$, then by line ~\ref{alg:one-pass-plus} $\gate_{k+1}.\prt = \gate_{{k+1}_\lchild}.\prt + \gate_{{k+1}_\rchild}.\prt$, a correct computation, as per ~\ref{eq:T-all-ones}. Further, lines ~\ref{alg:one-pass-lwght} and ~\ref{alg:one-pass-rwght} compute $\gate_{{k+1}}.\lwght = \frac{\gate_{{k+1}_\lchild}.\prt}{\gate_{{k+1}}.\prt}$ and analogously for $\gate_{{k+1}}.\rwght$. Note that all values needed for each computation have been correctly computed by the I.H.
When $\gate_\vari{s}.\type = \circmult$, then line ~\ref{alg:one-pass-mult} computes $\gate_\vari{s}.\prt = \gate_{\vari{s}_\lchild.\prt} \circmult \gate_{\vari{s}_\rchild}.\prt$, which indeed is correct, as per ~\ref{eq:T-all-ones}.
When $\gate_{k+1}.\type = \circmult$, then line ~\ref{alg:one-pass-mult} computes $\gate_{k+1}.\prt = \gate_{{k+1}_\lchild.\prt} \circmult \gate_{{k+1}_\rchild}.\prt$, which indeed is correct, as per ~\ref{eq:T-all-ones}.
%We first note that all DAGs have a topological ordering. By definition, for a graph $G = (V, E)$, a topological ordering $\topord(G)$ orders the elements of V in correspondence to the directed edges of $E$, such that for each edge $(u, v)$ the gate $u$ will be ordered before gate $v$, since the edge goes from $u$ to $v$. Since the directed edges of circuit \circuit go from the children to the parent, it is then invariant in $\topord(G)$ that all the children $v_\linput$ and/or $v_\rinput$ appear before their parental internal gate $v \in V$ in $\topord(G)$. Since \onepass follows $\topord(\circuit)$ (~\Cref{alg:one-pass-loop}), it has to be the case that before an internal gate is visited, both of its subcircuits $\subcircuit_\linput$ and $\subcircuit_\rinput$ will have previously been visited, computing \prt, \lwght, and \rwght values in a bottom-up traversal. When the node visited by \onepass is a source node, it is trivial to see in ~\Cref{alg:one-pass-var} and ~\Cref{alg:one-pass-num} that such a child node's \prt value is correctly computed. This implies the correctness of the \prt annotations across all gates in both $\subcircuit_\linput$ and $\subcircuit_\rinput$. Recall that all internal gates are either $\circplus$ or $\circmult$. When an internal gate \subcircuit is visited in \topord(\circuit), if \subcircuit.\type is $\circplus$, \onepass will add the values of the two source nodes $\subcircuit_\linput.\prt + \subcircuit_\rinput.\prt$ to correctly annotate \subcircuit.\prt. Further \subcircuit.\lwght will be computed correctly as $\frac{\subcircuit_\linput.\prt}{\subcircuit.\prt}$ and analogously for \subcircuit.\rwght. If the parent gate \subcircuit visited is a $\circmult$, then \onepass will correctly annotate \subcircuit.\prt as $\subcircuit_\linput.\prt \times \subcircuit_\rinput.\prt$. As gates further in the order are subsequently visited, note that it is the case that all previous gates visited will always contain the correct \prt values and it follows that all subsequent gates visited in \topord(\circuit) will correctly compute their respective \prt values. Since \lwght and \rwght are computed dependent only on \prt values, it follows that all \lwght and \rwght values will then be computed correctly.
\paragraph{\onepass Runtime}
@ -717,30 +717,30 @@ Let \cost be a function that models an upper bound on the number of gates that c
First note that the runtime of \sampmon is $O\left(\cost(\circuit)\right)$. When \sampmon visits a gate such that \circuit.\type $ =\circmult$, line ~\ref{alg:sample-times-for-loop} visits each input of \circuit. For the case when \circuit.\type $= \circplus$, line ~\ref{alg:sample-plus-bsamp} visits exactly one of the input gates. Finally, it is trivial to see that when \circuit.\type $\in \{\var, \tnum\}$, i.e., a source gate, that only one gate is visited.
We prove $\degree(\circuit) \cdot \depth(\circuit) \geq \cost(\circuit)$ for the number of gates traversed in \sampmon using induction over $\depth(\circuit)$. To simplify the math, we consider $\depth(\circuit)$ to be $1$-based instead of $0$-based, e.g., $\size(\circuit) = 1$ has $\depth(\circuit) = 1$. This will not change the final asymptotic analysis, since $O(k \cdot (d + 1))$ simplifies to $O(k \cdot d)$.%of \circuit, where $\degree(\circuit) = k$, and $\size(\circuit) = \ell$.
We prove $(\degree(\circuit) + 1) \cdot (\depth(\circuit) + 1) \geq \cost(\circuit)$ for the number of gates traversed in \sampmon using induction over $\depth(\circuit)$.
For the base case $\degree(\circuit) = \depth(\circuit) = 0$, $\cost(\circuit) = 1$, and it is trivial to see that the inequality $(\degree(\circuit) + 1) \cdot (\depth(\circuit) + 1) \geq \cost(\circuit)$ holds.
For the base case $\depth(\circuit) = 1$, $\cost(\circuit) = 1$, and it is trivial to see that $\degree(\circuit) = 1$, $\depth(\circuit) = 1$, and the inequality $\degree(\circuit) \cdot \depth(\circuit) \geq \cost(\circuit)$ holds.
For the inductive hypothesis, we assume the bound holds for a circuit where $\depth(\circuit) \leq \ell$ for $\ell \geq 0$.
For the inductive hypothesis, we assume the bound holds for a circuit where $0 \leq \depth(\circuit) \leq \ell$.
Now consider the case when \sampmon has an arbitrary circuit \circuit input with $\depth(\circuit) \leq \ell + 1$. By the hypothesis, we know all inputs of the sink gate \circuit uphold the bound. It is true then that $\depth(\circuit_\linput) \leq \depth(\circuit)$ and $\depth(\circuit_\rinput) \leq \depth(\circuit)$ where at least one of the inequalities is a strict equality.
%Fix $\degree(\circuit_\linput) = k'$ and $\degree(\circuit_\rinput) = k''$.
If \circuit.\type $= \circplus$, then $\degree(\circuit) = \max\left(\degree(\circuit_\linput), \degree(\circuit_\rinput)\right)$. Otherwise \circuit.\type = $\circmult$ and $\degree(\circuit) = \degree(\circuit_\linput) + \degree(\circuit_\rinput)$. For both cases it is true that $\depth(\circuit) = \max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 1$, and there exist the inequalities $\degree(\circuit_\linput) \cdot \depth(\circuit_\linput) \geq \cost(\circuit_\linput)$, and $\degree(\circuit_\rinput) \cdot \depth(\circuit_\rinput) \geq \cost(\circuit_\rinput)$.
If \circuit.\type $= \circplus$, then $\degree(\circuit) = \max\left(\degree(\circuit_\linput), \degree(\circuit_\rinput)\right)$. Otherwise \circuit.\type = $\circmult$ and $\degree(\circuit) = \degree(\circuit_\linput) + \degree(\circuit_\rinput)$. For both cases it is true that $\depth(\circuit) = \max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 1$, and there exist the inequalities $(\degree(\circuit_\linput) + 1) \cdot (\depth(\circuit_\linput) + 1) \geq \cost(\circuit_\linput)$, and $(\degree(\circuit_\rinput) + 1) \cdot (\depth(\circuit_\rinput) + 1) \geq \cost(\circuit_\rinput)$. Further note that a parent gate always will have a depth that is at least $1$ greater than either of its inputs.
If \circuit.\type $= \circmult$, then,
%$\degree(\circuit) = \degree(\circuit_\linput) + \degree(\circuit_\linput), \depth(\circuit) = \max(\depth(\circuit_\linput), \depth(\circuit_\rinput))$, and there exist inequalities $\degree(\circuit_\linput) \cdot \depth(\circuit_\linput) \geq \cost(\circuit_\linput)$ and $\degree(\circuit_\rinput) \cdot \depth(\circuit_\rinput) \geq \cost(\circuit_\rinput)$. Then
substituing values, we have that
\begin{align*}
&\left(\degree(\circuit_\linput) + \degree(\circuit_\linput)\right) \cdot \left(\max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 1\right)\\
&\qquad\geq \degree(\circuit_\linput)\cdot \depth(\circuit_\linput) + \degree(\circuit_\rinput) \cdot \depth(\circuit_\rinput) + 1 \\
&\left(\degree(\circuit_\linput) + \degree(\circuit_\rinput) + 1\right) \cdot \left(\max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 2\right)\\
&\qquad\geq (\degree(\circuit_\linput) + 1) \cdot (\depth(\circuit_\linput) + 1) + (\degree(\circuit_\rinput) + 1) \cdot (\depth(\circuit_\rinput) + 1) + 1 \\
&\qquad\qquad\geq 1 + \cost(\circuit_\linput) + \cost(\circuit_\rinput).
\end{align*}
The left inequality holds since it is always the case that $\degree(\circuit_i) \cdot (\depth(\circuit_i) + 1) > \degree(\circuit_i) \cdot \depth(\circuit_i)$ for $\degree(\circuit_i), \depth(\circuit_i) > 0$ . The second inequality holds by I.H. It follows that $\degree(\circuit) \cdot \depth(\circuit) \geq \cost(\circuit)$.
The left inequality holds since it is always the case that $(\degree(\circuit_i) + 1) \cdot (\depth(\circuit_i) + 2) > (\degree(\circuit_i) + 1) \cdot (\depth(\circuit_i) + 1)$ for $\degree(\circuit_i), \depth(\circuit_i) \geq 0$ . The second inequality holds by I.H. It follows that $\degree(\circuit) \cdot \depth(\circuit) \geq \cost(\circuit)$.
% we have already seen that \sampmon visits all inputs of \circuit. Then \sampmon visits at most $\cost(\circuit) = 1 + \cost(\circuit_\linput) + \cost(\circuit_\rinput)$ gates. Since we have that $\degree(\circuit_\linput) \cdot \depth(\circuit_\linput) \geq \cost(\circuit_\linput)$ for $\circuit_\linput$ and $\degree(\circuit_\rinput) \cdot \depth(\circuit_\rinput) \geq \cost(\circuit_\rinput)$ for $\circuit_\rinput$, then we have that $\degree(\circuit_\linput) \cdot \depth(\circuit_\linput) + \degree(\circuit_\rinput) \cdot \depth(\circuit_\rinput)$ gates have been traversed. It is trivial to see that the sink gate \circuit has $\leq k$ gates, thus holding the $O(k\cdot d)\geq\cost(\circuit)$ bound.
If \circuit.\type $= \circplus$, then substituting values yields
\begin{align*}
&\max(\degree(\circuit_\linput), \degree(\circuit_\rinput)) \cdot \left(\max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 1\right)\\
&\qquad \geq \left(\degree(\circuit_\linput) \cdot \depth(\circuit_\rinput)\right) + \left(\degree(\circuit_\rinput) \cdot \depth(\circuit_\linput)\right) + 1\\
&(\max(\degree(\circuit_\linput), \degree(\circuit_\rinput)) + 1) \cdot \left(\max(\depth(\circuit_\linput), \depth(\circuit_\rinput)) + 2\right)\\
&\qquad \geq \max\left((\degree(\circuit_\linput) + 1) \cdot \left(\depth(\circuit_\linput) + 1\right), \left(\degree(\circuit_\rinput) + 1\right) \cdot \left(\depth(\circuit_\linput) + 1\right)\right)\\
&\qquad \text{ } + 1\\
&\qquad\qquad \geq 1 + \max(\cost(\circuit_\linput), \cost(\circuit_\rinput))
\end{align*}
The above inequalities hold for the same reasons as for the case $\circuit.\type = \circmult$. Thus, $\degree(\circuit)\cdot\depth(\circuit) \geq \cost(\circuit)$.