Commit ·
a9a489a
1
Parent(s): 8397e00
Prove the folded host of Remark 3.9 and Lemmas 8.1 and 8.2 in Rocq, and revise the paper
Browse files- README.md +17 -11
- paper/runs/paper_rocq.json +16 -3
- paper/universal_construction_ternary.pdf +2 -2
- paper/universal_construction_ternary.tex +31 -13
- rocq/Assumptions.v +14 -1
- rocq/Compile.v +83 -0
- rocq/FoldHost.v +505 -0
- rocq/Schedule.v +222 -0
- rocq/_CoqProject +3 -0
README.md
CHANGED
|
@@ -598,7 +598,8 @@ stored networks in its state, a ring of K banks of records and K tapes with
|
|
| 598 |
heads at absolute positions, and evaluates one record per step, which `rocq/`
|
| 599 |
proves for every window of 2^α cells, number of banks, bank and tape. `rocq/`
|
| 600 |
also proves that the host family computes SUBLEQ at every word width, with its
|
| 601 |
-
depth and its numbers of units and edges,
|
|
|
|
| 602 |
netlist computes its step, that a read and the branch need two ternary levels, that
|
| 603 |
the recipes and their encoder have the stated lengths, that the 21- and
|
| 604 |
27-instruction programs do what the paper states at every word width from 8 on, and
|
|
@@ -610,7 +611,9 @@ records: it writes them into the next bank, copies the recipe onto the next tape
|
|
| 610 |
and hands control to the copy, so that it reproduces itself, weights included, by
|
| 611 |
the dynamics alone, and the copies accumulate until every bank holds one;
|
| 612 |
`src/ring_run.c` runs six generations of 95,762,842,100 steps each in a ring of
|
| 613 |
-
three banks. `rocq/`
|
|
|
|
|
|
|
| 614 |
records `src/twohead.py` writes among them, and proves its universal
|
| 615 |
construction, its reproduction in every ring, the accumulation of the copies and
|
| 616 |
the period of the state, in the machine and in the network. An organism of 143
|
|
@@ -1024,15 +1027,18 @@ src/ the library; `python src/<file>.py <command>
|
|
| 1024 |
└── nsim.c the noise simulator of independent.py
|
| 1025 |
paper/ the manuscript, and the record of every run it reports
|
| 1026 |
rocq/ Rocq proofs: the host family H_A computes SUBLEQ for every word
|
| 1027 |
-
width, with its depth and sizes,
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
and reproduces in every ring
|
| 1035 |
-
|
|
|
|
|
|
|
|
|
|
| 1036 |
tools/play.py the playground, and a demonstration on each machine
|
| 1037 |
llm_integration/
|
| 1038 |
├── llm.py SmolLM2 with the frozen circuits: the circuit wrapper, the
|
|
|
|
| 598 |
heads at absolute positions, and evaluates one record per step, which `rocq/`
|
| 599 |
proves for every window of 2^α cells, number of banks, bank and tape. `rocq/`
|
| 600 |
also proves that the host family computes SUBLEQ at every word width, with its
|
| 601 |
+
depth and its numbers of units and edges, the same for the family of depth 11 that
|
| 602 |
+
folds the address decoders into the reads, that the levelization of every clocked
|
| 603 |
netlist computes its step, that a read and the branch need two ternary levels, that
|
| 604 |
the recipes and their encoder have the stated lengths, that the 21- and
|
| 605 |
27-instruction programs do what the paper states at every word width from 8 on, and
|
|
|
|
| 611 |
and hands control to the copy, so that it reproduces itself, weights included, by
|
| 612 |
the dynamics alone, and the copies accumulate until every bank holds one;
|
| 613 |
`src/ring_run.c` runs six generations of 95,762,842,100 steps each in a ring of
|
| 614 |
+
three banks. `rocq/` proves that one pass of the records of any netlist of
|
| 615 |
+
two-input units evaluates the netlist and that every unit of weights ±1 compiles
|
| 616 |
+
into such records, defines the stored host for every word width from 8 on, the
|
| 617 |
records `src/twohead.py` writes among them, and proves its universal
|
| 618 |
construction, its reproduction in every ring, the accumulation of the copies and
|
| 619 |
the period of the state, in the machine and in the network. An organism of 143
|
|
|
|
| 1027 |
└── nsim.c the noise simulator of independent.py
|
| 1028 |
paper/ the manuscript, and the record of every run it reports
|
| 1029 |
rocq/ Rocq proofs: the host family H_A computes SUBLEQ for every word
|
| 1030 |
+
width, with its depth and sizes, and so does its folded form
|
| 1031 |
+
of depth 11, levelization and the depth lower bounds, the
|
| 1032 |
+
recipe lengths, P and P* do what the paper states at every
|
| 1033 |
+
width from 8, the netlist of the ring machine computes its
|
| 1034 |
+
step for every window, ring, bank and tape, a pass of the
|
| 1035 |
+
records of a netlist evaluates it and every unit compiles into
|
| 1036 |
+
records, the host stored as records builds every image that
|
| 1037 |
+
fits a bank and reproduces in every ring at every width from
|
| 1038 |
+
8, the organism builds every image that fits a bank from any
|
| 1039 |
+
description of it and reproduces in every ring, the state
|
| 1040 |
+
periodic once every bank holds a copy, and the margin and
|
| 1041 |
+
noise bounds of Section 6
|
| 1042 |
tools/play.py the playground, and a demonstration on each machine
|
| 1043 |
llm_integration/
|
| 1044 |
├── llm.py SmolLM2 with the frozen circuits: the circuit wrapper, the
|
paper/runs/paper_rocq.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"rocq": "The Rocq Prover, version 9.1.1",
|
| 3 |
-
"files":
|
| 4 |
-
"build_seconds":
|
| 5 |
"theorems": {
|
| 6 |
"PhysSem.netlist_step": "closed",
|
| 7 |
"PhysMain.network_orbit": "closed",
|
|
@@ -41,6 +41,12 @@
|
|
| 41 |
"StoredWidth.width_exists": "closed",
|
| 42 |
"StoredWidth.recipe_of_image": "closed",
|
| 43 |
"StoredProp.stored_pass": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
"Recipe.desc_spec": "closed",
|
| 45 |
"Recipe.describe_spec": "closed",
|
| 46 |
"Recipe.recipes_complete": "closed",
|
|
@@ -68,6 +74,13 @@
|
|
| 68 |
"HostCount.host_memory_8": "closed",
|
| 69 |
"HostCount.host_lev_identity_8": "closed",
|
| 70 |
"HostCount.host_lev_nonzero_8": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
"StoredCount.stored_records": "closed",
|
| 72 |
"StoredCount.alpha_bounds": "closed",
|
| 73 |
"StoredCount.width_least": "closed",
|
|
@@ -131,7 +144,7 @@
|
|
| 131 |
"AmpHost.amp_selfrep": "closed"
|
| 132 |
},
|
| 133 |
"extraction_identical": true,
|
| 134 |
-
"lines":
|
| 135 |
"host_extraction": {
|
| 136 |
"members": [
|
| 137 |
{
|
|
|
|
| 1 |
{
|
| 2 |
"rocq": "The Rocq Prover, version 9.1.1",
|
| 3 |
+
"files": 66,
|
| 4 |
+
"build_seconds": 102.9,
|
| 5 |
"theorems": {
|
| 6 |
"PhysSem.netlist_step": "closed",
|
| 7 |
"PhysMain.network_orbit": "closed",
|
|
|
|
| 41 |
"StoredWidth.width_exists": "closed",
|
| 42 |
"StoredWidth.recipe_of_image": "closed",
|
| 43 |
"StoredProp.stored_pass": "closed",
|
| 44 |
+
"Schedule.pass_run": "closed",
|
| 45 |
+
"Schedule.sched_run": "closed",
|
| 46 |
+
"Schedule.netlist_pass": "closed",
|
| 47 |
+
"Compile.atleast_rec": "closed",
|
| 48 |
+
"Compile.compile_unit": "closed",
|
| 49 |
+
"Compile.compile_records": "closed",
|
| 50 |
"Recipe.desc_spec": "closed",
|
| 51 |
"Recipe.describe_spec": "closed",
|
| 52 |
"Recipe.recipes_complete": "closed",
|
|
|
|
| 74 |
"HostCount.host_memory_8": "closed",
|
| 75 |
"HostCount.host_lev_identity_8": "closed",
|
| 76 |
"HostCount.host_lev_nonzero_8": "closed",
|
| 77 |
+
"FoldHost.fold_wf": "closed",
|
| 78 |
+
"FoldHost.fold_step": "closed",
|
| 79 |
+
"FoldHost.fold_dmax": "closed",
|
| 80 |
+
"FoldHost.fold_units_count": "closed",
|
| 81 |
+
"FoldHost.fold_edges": "closed",
|
| 82 |
+
"FoldHost.fold_units_8": "closed",
|
| 83 |
+
"FoldHost.fold_edges_8": "closed",
|
| 84 |
"StoredCount.stored_records": "closed",
|
| 85 |
"StoredCount.alpha_bounds": "closed",
|
| 86 |
"StoredCount.width_least": "closed",
|
|
|
|
| 144 |
"AmpHost.amp_selfrep": "closed"
|
| 145 |
},
|
| 146 |
"extraction_identical": true,
|
| 147 |
+
"lines": 24178,
|
| 148 |
"host_extraction": {
|
| 149 |
"members": [
|
| 150 |
{
|
paper/universal_construction_ternary.pdf
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:305f38033584a59bc3532f2d7e92bf7fa8d96afbf75a9eebebaf387766b41b01
|
| 3 |
+
size 369468
|
paper/universal_construction_ternary.tex
CHANGED
|
@@ -158,7 +158,8 @@ every state, its depth and its numbers of units and edges are proved in Rocq for
|
|
| 158 |
every $A$. A read from memory and the branch predicate each need two levels of
|
| 159 |
ternary units, also proved in Rocq (Lemma~\ref{lem:muxdepth},
|
| 160 |
Remark~\ref{rem:ternarydepth}); folding the address decoders into the reads
|
| 161 |
-
gives depth $11$
|
|
|
|
| 162 |
\item \emph{Universal construction.} A program of $21$ instructions that emits
|
| 163 |
the byte string its tape describes, in a number of steps given in closed form,
|
| 164 |
proved in Rocq for every word width $A\ge8$. Every string $f$ has a description of
|
|
@@ -220,6 +221,7 @@ Levelization; the sizes of $\Lev(\Nhost)$ & Lem.~\ref{lem:lev}, Rem.~\ref{rem:le
|
|
| 220 |
The step of $H_A$ is the step of $\mathrm{SUBLEQ}_A$, every $A\ge3$ & Prop.~\ref{prop:host} & Rocq; the netlists extracted for $A=8,9,10$ equal the generator's\\
|
| 221 |
Depth $13$, units, edges, weights and biases of $H_A$, every $A\ge3$ & Prop.~\ref{prop:host} & Rocq; rebuilt independently for $A=3$ to $12$\\
|
| 222 |
A read and the branch need two ternary levels & Lem.~\ref{lem:muxdepth}, Rem.~\ref{rem:ternarydepth} & Rocq; exhaustive search on eight inputs\\
|
|
|
|
| 223 |
Length and optimality of the recipes and of $\describe$ & Lems.~\ref{lem:complete}, \ref{lem:describe}, Prop.~\ref{prop:optimal} & Rocq; checked on $971$ MB and on $68{,}061$ boundary strings\\
|
| 224 |
$P$ builds every string, in the stated steps, every $A\ge8$ & Thm.~\ref{thm:univ} & Rocq; $29$ recipes run on the reference and four on the netlist\\
|
| 225 |
$P^\ast$ reproduces the host, in the stated steps, every $A\ge8$ & Thm.~\ref{thm:selfrep}, Prop.~\ref{prop:steps} & Rocq; three generations on three evaluators\\
|
|
@@ -228,6 +230,7 @@ Amplification under the three noise models, and the threshold & Thm.~\ref{thm:am
|
|
| 228 |
Exact self-reproduction of the amplified host, every odd $r$ & Cor.~\ref{cor:amplifiedselfrep} & Rocq; $\Omega^\ast_3$ run on the evaluator in C\\
|
| 229 |
Restoration bound for $N_3$ & Prop.~\ref{prop:restore} & Rocq; its values computed along the run; measured rates of Table~\ref{tab:bound3}\\
|
| 230 |
The netlist computes the ring machine; its size, weights and depth & Thm.~\ref{thm:physnet} & Rocq; extraction equal to the generator's; random states\\
|
|
|
|
| 231 |
A pass of the stored host, every $A\ge8$ & Prop.~\ref{prop:storedpass} & Rocq, block by block; decision diagrams of all four blocks and random states, $A=8,9,10$\\
|
| 232 |
Construction and reproduction by the stored host: copies, period, network, counts, every $A\ge8$ & Thms.~\ref{thm:storedconstruct}--\ref{thm:widths} & Rocq; the extracted image equal to the generator's for $A=8,9$; six generations of $\mathcal S_8$ run\\
|
| 233 |
The stored host under noise & Cor.~\ref{cor:storednoise} & Rocq\\
|
|
@@ -711,11 +714,15 @@ Writing every fetch conjunction $FA_{o,t,j}$, every read
|
|
| 711 |
conjunction $RX_{t,j}$, $RY_{t,j}$ and every write enable $W_j$ as a single unit
|
| 712 |
that reads the bits of its address directly, of fan-in $A+1$, removes the decode
|
| 713 |
lines of $a$ and $b$ and one level each from the fetch and from the operand reads,
|
| 714 |
-
so the step has depth $11$ for every $A$.
|
| 715 |
-
$
|
| 716 |
-
|
| 717 |
-
$
|
| 718 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
\end{remark}
|
| 720 |
|
| 721 |
% =============================================================================
|
|
@@ -1831,7 +1838,12 @@ The slot head of the active bank moves on by one slot per step, the bank index,
|
|
| 1831 |
at the start of a step, selects the bank, and the empty slots change nothing.
|
| 1832 |
Induction over the records shows that each reads the values of its predecessors on
|
| 1833 |
the current state, a state bit being unchanged until the record of its next value,
|
| 1834 |
-
which follows its last reader.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1835 |
\end{proof}
|
| 1836 |
|
| 1837 |
Lemma~\ref{lem:feedback} is the rank-ordered schedule of gate-level simulation
|
|
@@ -1856,7 +1868,10 @@ the constants are the disjunction and the conjunction of a literal and its
|
|
| 1856 |
negation; a chain conjoins or disjoins each further literal with the result so
|
| 1857 |
far. The recursion holds because at least $t$ of $x_1,\dots,x_k$ are true exactly
|
| 1858 |
when at least $t$ of $x_2,\dots,x_k$ are, or $x_1$ is and at least $t-1$ of the
|
| 1859 |
-
others are, and its base cases are the chains and the constants.
|
|
|
|
|
|
|
|
|
|
| 1860 |
\end{proof}
|
| 1861 |
|
| 1862 |
\begin{construction}[The stored host]\label{con:stored}
|
|
@@ -2596,16 +2611,17 @@ measurements of Section~\ref{sec:certified} and Appendix~\ref{app:measure} in C
|
|
| 2596 |
on the accelerator; it gives the sizes, depths and exact runs stated here, and noisy
|
| 2597 |
runs within sampling error.
|
| 2598 |
|
| 2599 |
-
The Rocq development, \texttt{rocq/} in the artifact, has $
|
| 2600 |
-
$
|
| 2601 |
below, most of it in the kernel's evaluation of the $15{,}872$ abstract passes of
|
| 2602 |
Proposition~\ref{prop:pass} and in the device records of the stored host. It proves
|
| 2603 |
Lemma~\ref{lem:lev} for every clocked netlist. It defines the host family $H_A$
|
| 2604 |
block by block and proves that its step is the step of $\mathrm{SUBLEQ}_A$ for every
|
| 2605 |
$A\ge3$, with its depth, its numbers of units, memory units and edges, its weights
|
| 2606 |
and biases and the sizes of $\Lev(H_A)$ (Proposition~\ref{prop:host},
|
| 2607 |
-
Remark~\ref{rem:levsizes}), and
|
| 2608 |
-
Remark~\ref{rem:
|
|
|
|
| 2609 |
Definition~\ref{def:transducer} and the programs $P$ and $P^\ast$ in $2^A$ words, and
|
| 2610 |
proves Lemmas~\ref{lem:complete} and~\ref{lem:describe},
|
| 2611 |
Proposition~\ref{prop:optimal}, Theorems~\ref{thm:univ} and~\ref{thm:selfrep} and
|
|
@@ -2617,7 +2633,9 @@ decoder, and proves Theorem~\ref{thm:physnet} for every $\alpha\ge4$, $K\ge2$ an
|
|
| 2617 |
$S,L\ge1$, together with the numbers of units and edges, the weights and the depth;
|
| 2618 |
and it proves Lemma~\ref{lem:code}, Proposition~\ref{prop:pass},
|
| 2619 |
Theorem~\ref{thm:construct} and Theorem~\ref{thm:organism}, with the copies, the
|
| 2620 |
-
period and the network. It
|
|
|
|
|
|
|
| 2621 |
Construction~\ref{con:stored} for every $A\ge8$ and $w\ge1$ and proves its four
|
| 2622 |
blocks from every window (Proposition~\ref{prop:storedpass}), that every cell a pass
|
| 2623 |
reads after the startup is written earlier in the pass,
|
|
|
|
| 158 |
every $A$. A read from memory and the branch predicate each need two levels of
|
| 159 |
ternary units, also proved in Rocq (Lemma~\ref{lem:muxdepth},
|
| 160 |
Remark~\ref{rem:ternarydepth}); folding the address decoders into the reads
|
| 161 |
+
gives a family whose step has depth $11$ and is again the step of SUBLEQ, with its
|
| 162 |
+
numbers of units and edges, proved in Rocq for every $A$ (Remark~\ref{rem:fold}).
|
| 163 |
\item \emph{Universal construction.} A program of $21$ instructions that emits
|
| 164 |
the byte string its tape describes, in a number of steps given in closed form,
|
| 165 |
proved in Rocq for every word width $A\ge8$. Every string $f$ has a description of
|
|
|
|
| 221 |
The step of $H_A$ is the step of $\mathrm{SUBLEQ}_A$, every $A\ge3$ & Prop.~\ref{prop:host} & Rocq; the netlists extracted for $A=8,9,10$ equal the generator's\\
|
| 222 |
Depth $13$, units, edges, weights and biases of $H_A$, every $A\ge3$ & Prop.~\ref{prop:host} & Rocq; rebuilt independently for $A=3$ to $12$\\
|
| 223 |
A read and the branch need two ternary levels & Lem.~\ref{lem:muxdepth}, Rem.~\ref{rem:ternarydepth} & Rocq; exhaustive search on eight inputs\\
|
| 224 |
+
The folded host: its step, depth $11$, units and edges, every $A\ge3$ & Rem.~\ref{rem:fold} & Rocq; random states for $A=3$ to $12$\\
|
| 225 |
Length and optimality of the recipes and of $\describe$ & Lems.~\ref{lem:complete}, \ref{lem:describe}, Prop.~\ref{prop:optimal} & Rocq; checked on $971$ MB and on $68{,}061$ boundary strings\\
|
| 226 |
$P$ builds every string, in the stated steps, every $A\ge8$ & Thm.~\ref{thm:univ} & Rocq; $29$ recipes run on the reference and four on the netlist\\
|
| 227 |
$P^\ast$ reproduces the host, in the stated steps, every $A\ge8$ & Thm.~\ref{thm:selfrep}, Prop.~\ref{prop:steps} & Rocq; three generations on three evaluators\\
|
|
|
|
| 230 |
Exact self-reproduction of the amplified host, every odd $r$ & Cor.~\ref{cor:amplifiedselfrep} & Rocq; $\Omega^\ast_3$ run on the evaluator in C\\
|
| 231 |
Restoration bound for $N_3$ & Prop.~\ref{prop:restore} & Rocq; its values computed along the run; measured rates of Table~\ref{tab:bound3}\\
|
| 232 |
The netlist computes the ring machine; its size, weights and depth & Thm.~\ref{thm:physnet} & Rocq; extraction equal to the generator's; random states\\
|
| 233 |
+
A pass of a stored netlist; the compilation of a unit & Lems.~\ref{lem:feedback}, \ref{cor:compile} & Rocq\\
|
| 234 |
A pass of the stored host, every $A\ge8$ & Prop.~\ref{prop:storedpass} & Rocq, block by block; decision diagrams of all four blocks and random states, $A=8,9,10$\\
|
| 235 |
Construction and reproduction by the stored host: copies, period, network, counts, every $A\ge8$ & Thms.~\ref{thm:storedconstruct}--\ref{thm:widths} & Rocq; the extracted image equal to the generator's for $A=8,9$; six generations of $\mathcal S_8$ run\\
|
| 236 |
The stored host under noise & Cor.~\ref{cor:storednoise} & Rocq\\
|
|
|
|
| 714 |
conjunction $RX_{t,j}$, $RY_{t,j}$ and every write enable $W_j$ as a single unit
|
| 715 |
that reads the bits of its address directly, of fan-in $A+1$, removes the decode
|
| 716 |
lines of $a$ and $b$ and one level each from the fetch and from the operand reads,
|
| 717 |
+
so the step has depth $11$ for every $A$. The folded netlist has
|
| 718 |
+
$(8A+2)2^A+\tfrac12(A^2+39A+4)$ units and
|
| 719 |
+
$(10A^2+37A+2)2^{A-1}+\tfrac16(A^3+9A^2+194A+24)$ edges; for $A=8$ these are
|
| 720 |
+
$17{,}086$ and $120{,}508$, against $17{,}598$ and $51{,}132$ for $\Nhost$. For every
|
| 721 |
+
$A\ge3$ it is proved in Rocq that its step is the step of $\mathrm{SUBLEQ}_A$ from
|
| 722 |
+
every state, each of its units computing the value of the unit of $H_A$ in its place,
|
| 723 |
+
and that its depth and its numbers of units and edges are those stated. One step of
|
| 724 |
+
it also agreed with $\mathrm{SUBLEQ}_A$ on $2^{16}$ uniformly random full states for
|
| 725 |
+
every $A$ from $3$ to $10$, and on $2^{15}$ and $2^{14}$ for $A=11$ and $12$.
|
| 726 |
\end{remark}
|
| 727 |
|
| 728 |
% =============================================================================
|
|
|
|
| 1838 |
at the start of a step, selects the bank, and the empty slots change nothing.
|
| 1839 |
Induction over the records shows that each reads the values of its predecessors on
|
| 1840 |
the current state, a state bit being unchanged until the record of its next value,
|
| 1841 |
+
which follows its last reader. In Rocq the first statement is proved for every list
|
| 1842 |
+
of records in the bank, and the second for every netlist of units of at most two
|
| 1843 |
+
inputs with weights $\pm1$ and biases in $[-8,7]$ and every assignment of window
|
| 1844 |
+
cells to its state bits and units that meets the conditions of the lemma: one pass
|
| 1845 |
+
of its records, followed by empty slots, leaves the next state in the cells of the
|
| 1846 |
+
state bits.
|
| 1847 |
\end{proof}
|
| 1848 |
|
| 1849 |
Lemma~\ref{lem:feedback} is the rank-ordered schedule of gate-level simulation
|
|
|
|
| 1868 |
negation; a chain conjoins or disjoins each further literal with the result so
|
| 1869 |
far. The recursion holds because at least $t$ of $x_1,\dots,x_k$ are true exactly
|
| 1870 |
when at least $t$ of $x_2,\dots,x_k$ are, or $x_1$ is and at least $t-1$ of the
|
| 1871 |
+
others are, and its base cases are the chains and the constants. The lemma is proved
|
| 1872 |
+
in Rocq for every unit with weights $\pm1$: run on a window whose cells hold the
|
| 1873 |
+
values of its literals, its records leave the unit's value in the unit's cell, read
|
| 1874 |
+
and write the window alone and fit the code of the records.
|
| 1875 |
\end{proof}
|
| 1876 |
|
| 1877 |
\begin{construction}[The stored host]\label{con:stored}
|
|
|
|
| 2611 |
on the accelerator; it gives the sizes, depths and exact runs stated here, and noisy
|
| 2612 |
runs within sampling error.
|
| 2613 |
|
| 2614 |
+
The Rocq development, \texttt{rocq/} in the artifact, has $66$ files and
|
| 2615 |
+
$24{,}178$ lines and builds with Rocq 9.1.1 in about two minutes on the machine
|
| 2616 |
below, most of it in the kernel's evaluation of the $15{,}872$ abstract passes of
|
| 2617 |
Proposition~\ref{prop:pass} and in the device records of the stored host. It proves
|
| 2618 |
Lemma~\ref{lem:lev} for every clocked netlist. It defines the host family $H_A$
|
| 2619 |
block by block and proves that its step is the step of $\mathrm{SUBLEQ}_A$ for every
|
| 2620 |
$A\ge3$, with its depth, its numbers of units, memory units and edges, its weights
|
| 2621 |
and biases and the sizes of $\Lev(H_A)$ (Proposition~\ref{prop:host},
|
| 2622 |
+
Remark~\ref{rem:levsizes}), and does the same for the step, the depth and the
|
| 2623 |
+
numbers of units and edges of the folded host (Remark~\ref{rem:fold}). It proves
|
| 2624 |
+
Lemma~\ref{lem:muxdepth} and Remark~\ref{rem:ternarydepth}. It defines the recipes, $\describe$, the device of
|
| 2625 |
Definition~\ref{def:transducer} and the programs $P$ and $P^\ast$ in $2^A$ words, and
|
| 2626 |
proves Lemmas~\ref{lem:complete} and~\ref{lem:describe},
|
| 2627 |
Proposition~\ref{prop:optimal}, Theorems~\ref{thm:univ} and~\ref{thm:selfrep} and
|
|
|
|
| 2633 |
$S,L\ge1$, together with the numbers of units and edges, the weights and the depth;
|
| 2634 |
and it proves Lemma~\ref{lem:code}, Proposition~\ref{prop:pass},
|
| 2635 |
Theorem~\ref{thm:construct} and Theorem~\ref{thm:organism}, with the copies, the
|
| 2636 |
+
period and the network. It proves Lemma~\ref{lem:feedback} for every netlist of
|
| 2637 |
+
units of at most two inputs and Lemma~\ref{cor:compile} for every unit of weights
|
| 2638 |
+
$\pm1$. It defines the stored host $\mathcal S_{A,w}$ of
|
| 2639 |
Construction~\ref{con:stored} for every $A\ge8$ and $w\ge1$ and proves its four
|
| 2640 |
blocks from every window (Proposition~\ref{prop:storedpass}), that every cell a pass
|
| 2641 |
reads after the startup is written earlier in the pass,
|
rocq/Assumptions.v
CHANGED
|
@@ -6,7 +6,7 @@ Set Warnings "-ambiguous-paths".
|
|
| 6 |
From TH Require Import PhysSem PhysMain PhysFacts NetMain Complete Decoder Run PassLemma Main HostSem Pstar
|
| 7 |
StoredBoot StoredPass StoredDev StoredOk StoredRun StoredWbr StoredMain StoredWidth
|
| 8 |
Recipe Lower Lev HostLev HostCount StoredProp StoredCount PhysLev Margin Erfc Choose Noise NoiseNum Restore FlipLower
|
| 9 |
-
AmpHost.
|
| 10 |
Set Warnings "ambiguous-paths".
|
| 11 |
|
| 12 |
Print Assumptions PhysSem.netlist_step.
|
|
@@ -47,6 +47,12 @@ Print Assumptions StoredMain.network_periodic.
|
|
| 47 |
Print Assumptions StoredWidth.width_exists.
|
| 48 |
Print Assumptions StoredWidth.recipe_of_image.
|
| 49 |
Print Assumptions StoredProp.stored_pass.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
Print Assumptions Recipe.desc_spec.
|
| 51 |
Print Assumptions Recipe.describe_spec.
|
| 52 |
Print Assumptions Recipe.recipes_complete.
|
|
@@ -74,6 +80,13 @@ Print Assumptions HostCount.host_edges_8.
|
|
| 74 |
Print Assumptions HostCount.host_memory_8.
|
| 75 |
Print Assumptions HostCount.host_lev_identity_8.
|
| 76 |
Print Assumptions HostCount.host_lev_nonzero_8.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
Print Assumptions StoredCount.stored_records.
|
| 78 |
Print Assumptions StoredCount.alpha_bounds.
|
| 79 |
Print Assumptions StoredCount.width_least.
|
|
|
|
| 6 |
From TH Require Import PhysSem PhysMain PhysFacts NetMain Complete Decoder Run PassLemma Main HostSem Pstar
|
| 7 |
StoredBoot StoredPass StoredDev StoredOk StoredRun StoredWbr StoredMain StoredWidth
|
| 8 |
Recipe Lower Lev HostLev HostCount StoredProp StoredCount PhysLev Margin Erfc Choose Noise NoiseNum Restore FlipLower
|
| 9 |
+
AmpHost FoldHost Compile Schedule.
|
| 10 |
Set Warnings "ambiguous-paths".
|
| 11 |
|
| 12 |
Print Assumptions PhysSem.netlist_step.
|
|
|
|
| 47 |
Print Assumptions StoredWidth.width_exists.
|
| 48 |
Print Assumptions StoredWidth.recipe_of_image.
|
| 49 |
Print Assumptions StoredProp.stored_pass.
|
| 50 |
+
Print Assumptions Schedule.pass_run.
|
| 51 |
+
Print Assumptions Schedule.sched_run.
|
| 52 |
+
Print Assumptions Schedule.netlist_pass.
|
| 53 |
+
Print Assumptions Compile.atleast_rec.
|
| 54 |
+
Print Assumptions Compile.compile_unit.
|
| 55 |
+
Print Assumptions Compile.compile_records.
|
| 56 |
Print Assumptions Recipe.desc_spec.
|
| 57 |
Print Assumptions Recipe.describe_spec.
|
| 58 |
Print Assumptions Recipe.recipes_complete.
|
|
|
|
| 80 |
Print Assumptions HostCount.host_memory_8.
|
| 81 |
Print Assumptions HostCount.host_lev_identity_8.
|
| 82 |
Print Assumptions HostCount.host_lev_nonzero_8.
|
| 83 |
+
Print Assumptions FoldHost.fold_wf.
|
| 84 |
+
Print Assumptions FoldHost.fold_step.
|
| 85 |
+
Print Assumptions FoldHost.fold_dmax.
|
| 86 |
+
Print Assumptions FoldHost.fold_units_count.
|
| 87 |
+
Print Assumptions FoldHost.fold_edges.
|
| 88 |
+
Print Assumptions FoldHost.fold_units_8.
|
| 89 |
+
Print Assumptions FoldHost.fold_edges_8.
|
| 90 |
Print Assumptions StoredCount.stored_records.
|
| 91 |
Print Assumptions StoredCount.alpha_bounds.
|
| 92 |
Print Assumptions StoredCount.width_least.
|
rocq/Compile.v
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(* Lemma 8.2 for every unit of weights 1 and -1, whatever its fan-in: the unit fires exactly when at least t = tval of
|
| 2 |
+
its literals hold, at least t literals satisfy the recursion of the lemma, and the records the compiler gives the
|
| 3 |
+
unit, run on a window whose cells hold the values of its literals, leave the unit's value in the cell they write.
|
| 4 |
+
They read and write the window alone, fit the code of the records, and number rcount t k, one for a constant and
|
| 5 |
+
k - 1 for a chain of k >= 2 literals. *)
|
| 6 |
+
From Stdlib Require Import List Bool Arith ZArith Lia.
|
| 7 |
+
Import ListNotations.
|
| 8 |
+
From TH Require Import TwoHead Net Abstract Indep Run View Stored WinRun StoredStep StoredOk StoredCount.
|
| 9 |
+
|
| 10 |
+
(* at least t of l0 :: rest hold exactly when at least t of rest do, or l0 and at least t - 1 of rest do *)
|
| 11 |
+
Lemma atleast_rec : forall w l0 rest t,
|
| 12 |
+
Z.leb t (Z.of_nat (ntrue w (l0 :: rest)))
|
| 13 |
+
= Z.leb t (Z.of_nat (ntrue w rest)) || (wl w l0 && Z.leb (t - 1) (Z.of_nat (ntrue w rest))).
|
| 14 |
+
Proof.
|
| 15 |
+
intros w l0 rest t. unfold ntrue. cbn [filter]. destruct (wl w l0); cbn [length andb orb].
|
| 16 |
+
- rewrite Nat2Z.inj_succ. set (c := Z.of_nat (length (filter (wl w) rest))).
|
| 17 |
+
destruct (Z.leb_spec t (Z.succ c)), (Z.leb_spec t c), (Z.leb_spec (t - 1) c); cbn [orb]; first [reflexivity | lia].
|
| 18 |
+
- rewrite orb_false_r. reflexivity.
|
| 19 |
+
Qed.
|
| 20 |
+
|
| 21 |
+
(* a constant, a disjunction, a conjunction: one record, or k - 1 for k >= 2 literals *)
|
| 22 |
+
Lemma chlen_cases : forall k, chlen k = (if Nat.leb k 1 then k else k - 1).
|
| 23 |
+
Proof. intros [|[|k]]; reflexivity. Qed.
|
| 24 |
+
|
| 25 |
+
Section Compile.
|
| 26 |
+
Variables (W LV : nat) (xc : nat -> nat -> nat) (cell : nat -> nat).
|
| 27 |
+
Hypotheses (Hxgt : forall j k, k < 3 -> HO < xc j k) (Hxlt : forall j k, j < LV -> k < 3 -> xc j k < W)
|
| 28 |
+
(Hxinj : forall j k j' k', k < 3 -> k' < 3 -> xc j k = xc j' k' -> j = j' /\ k = k').
|
| 29 |
+
|
| 30 |
+
(* the literal of an input: the cell of its signal, negated for the weight -1 *)
|
| 31 |
+
Definition lit_in (p : nat * Z) : nat * bool := (cell (fst p), Z.ltb 0 (snd p)).
|
| 32 |
+
|
| 33 |
+
(* the records of unit u, writing d, accumulating its chains in acc, with the levels of scratch cells from 0 *)
|
| 34 |
+
Definition urecs (u : tu) (d acc : nat) : list rec := ucomp xc (tval u) (map lit_in (tin u)) d acc 0.
|
| 35 |
+
|
| 36 |
+
Lemma ntrue_in : forall w (E : nat -> bool) (l : list (nat * Z)),
|
| 37 |
+
(forall i z, In (i, z) l -> wcell w (cell i) = E i) -> ntrue w (map lit_in l) = length (filter (litE E) l).
|
| 38 |
+
Proof.
|
| 39 |
+
intros w E l H. unfold ntrue. induction l as [|[i z] l IH]; [reflexivity|]. cbn [map filter].
|
| 40 |
+
assert (Ep : wl w (lit_in (i, z)) = litE E (i, z)).
|
| 41 |
+
{ unfold wl, lit_in, litE. cbn [fst snd]. rewrite (H i z (or_introl eq_refl)). reflexivity. }
|
| 42 |
+
assert (IH' : length (filter (wl w) (map lit_in l)) = length (filter (litE E) l))
|
| 43 |
+
by (apply IH; intros i' z' Hin; apply (H i' z'); right; exact Hin).
|
| 44 |
+
rewrite Ep. destruct (litE E (i, z)); cbn [length]; rewrite IH'; reflexivity.
|
| 45 |
+
Qed.
|
| 46 |
+
|
| 47 |
+
Theorem compile_unit : forall (u : tu) (E : nat -> bool) w d acc,
|
| 48 |
+
(forall i z, In (i, z) (tin u) -> z = 1%Z \/ z = (-1)%Z) ->
|
| 49 |
+
(forall i z, In (i, z) (tin u) -> wcell w (cell i) = E i /\ cell i <> acc /\ ~ scr LV xc 0 (cell i)) ->
|
| 50 |
+
length w = W -> ok_cell W d -> ok_cell W acc -> ~ scr LV xc 0 d -> ~ scr LV xc 0 acc ->
|
| 51 |
+
((1 < tval u < Z.of_nat (length (tin u)))%Z -> length (tin u) <= LV + 2) ->
|
| 52 |
+
let w' := wrun (urecs u d acc) w in
|
| 53 |
+
length w' = W /\ wget w' d = fire u E /\ (forall c, c <> d -> c <> acc -> ~ scr LV xc 0 c -> wget w' c = wget w c).
|
| 54 |
+
Proof.
|
| 55 |
+
intros u E w d acc Hw Hlit Hl Hd Ha Hsd Hsa Hlev. unfold urecs. cbv zeta.
|
| 56 |
+
assert (Hls : forall l, In l (map lit_in (tin u)) -> fst l <> acc /\ ~ scr LV xc 0 (fst l)).
|
| 57 |
+
{ intros l Hin. apply in_map_iff in Hin as ([i z] & <- & Hin). cbn [lit_in fst].
|
| 58 |
+
destruct (Hlit i z Hin) as (_ & H1 & H2). split; assumption. }
|
| 59 |
+
destruct (ucomp_run W LV xc Hxgt Hxlt Hxinj (map lit_in (tin u)) (tval u) d acc 0 w Hl Hd Ha Hsd Hsa Hls
|
| 60 |
+
ltac:(rewrite length_map; intros H; specialize (Hlev H); lia)) as (L1 & V1 & U1).
|
| 61 |
+
split; [exact L1|]. split; [|exact U1].
|
| 62 |
+
rewrite V1, (fire_count u E Hw), (ntrue_in w E (tin u)) by (intros i z Hin; exact (proj1 (Hlit i z Hin))).
|
| 63 |
+
reflexivity.
|
| 64 |
+
Qed.
|
| 65 |
+
|
| 66 |
+
(* every record reads and writes the window alone, fits the code of a window of N cells, and they number rcount *)
|
| 67 |
+
Theorem compile_records : forall u d acc N,
|
| 68 |
+
HO < d -> HO < acc -> (forall i z, In (i, z) (tin u) -> rd_ok (cell i) /\ cell i < N) ->
|
| 69 |
+
(forall j k, j < LV -> k < 3 -> xc j k < N) -> d < N -> acc < N ->
|
| 70 |
+
((1 < tval u < Z.of_nat (length (tin u)))%Z -> length (tin u) <= LV + 2) ->
|
| 71 |
+
Forall wrec (urecs u d acc) /\ Forall (rok N) (urecs u d acc)
|
| 72 |
+
/\ length (urecs u d acc) = rcount (tval u) (length (tin u)).
|
| 73 |
+
Proof.
|
| 74 |
+
intros u d acc N Hd Ha Hc Hxn HdN HaN Hlev. unfold urecs. split; [|split].
|
| 75 |
+
- apply (ucomp_wrec xc Hxgt); [exact Hd | exact Ha|].
|
| 76 |
+
intros l Hin. apply in_map_iff in Hin as ([i z] & <- & Hin). exact (proj1 (Hc i z Hin)).
|
| 77 |
+
- apply (ucomp_rok N LV xc Hxn); [lia | exact HdN | exact HaN | |].
|
| 78 |
+
+ intros l Hin. apply in_map_iff in Hin as ([i z] & <- & Hin). exact (proj2 (Hc i z Hin)).
|
| 79 |
+
+ rewrite length_map. intros H. specialize (Hlev H). lia.
|
| 80 |
+
- rewrite length_ucomp_eq, length_map. reflexivity.
|
| 81 |
+
Qed.
|
| 82 |
+
|
| 83 |
+
End Compile.
|
rocq/FoldHost.v
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(* The folded host of Remark 3.9: every fetch conjunction, every read conjunction and every write enable is one unit
|
| 2 |
+
that reads the bits of its address, so the decode lines of the two operand addresses are gone. For every A >= 3
|
| 3 |
+
its step is the step of SUBLEQ, its depth is 11, and its units and edges are counted. *)
|
| 4 |
+
From Stdlib Require Import List Bool Arith ZArith NArith Lia Morphisms Setoid.
|
| 5 |
+
Import ListNotations.
|
| 6 |
+
From TH Require Import TwoHead Net Gates PhysSem Host HostWF Adder HostSem Lev BlockLev HostLev HostCount.
|
| 7 |
+
|
| 8 |
+
#[local] Instance nsum_proper' : Proper (eq ==> pointwise_relation nat eq ==> eq) nsum.
|
| 9 |
+
Proof. intros k k' -> f g H. apply nsum_ext. intros i _. apply H. Qed.
|
| 10 |
+
|
| 11 |
+
(* ---- a netlist computes the only valuation that agrees with its state bits and fires every unit ----------------- *)
|
| 12 |
+
Lemma net_unique : forall bs n X (V : sref -> bool), wf bs n ->
|
| 13 |
+
(forall i, i < n -> V (SIn i) = X i) ->
|
| 14 |
+
(forall b j r, valid bs n (SRef b j r) -> V (SRef b j r) = sfire' (sunit bs b j r) V) ->
|
| 15 |
+
forall x, valid bs n x -> run (compile n bs) n X (idx n bs x) = V x.
|
| 16 |
+
Proof.
|
| 17 |
+
intros bs n X V Hwf Hin Hun.
|
| 18 |
+
assert (G : forall k x, idx n bs x < k -> valid bs n x -> run (compile n bs) n X (idx n bs x) = V x).
|
| 19 |
+
{ induction k as [|k IH]; intros x Hk Hv; [lia|]. destruct x as [i|b j r].
|
| 20 |
+
- rewrite net_in by exact Hv. symmetry. apply Hin. exact Hv.
|
| 21 |
+
- pose proof Hv as (Hb & Hj & Hr). rewrite net_unit by assumption. rewrite (Hun b j r Hv).
|
| 22 |
+
unfold sfire'. f_equal. f_equal. apply swsum_ext. intros x w Hx.
|
| 23 |
+
destruct (pred_ok bs n Hwf b j r x w Hv Hx) as [Hvx Hlt]. apply IH; [lia | exact Hvx]. }
|
| 24 |
+
intros x Hv. exact (G (S (idx n bs x)) x (Nat.lt_succ_diag_r _) Hv).
|
| 25 |
+
Qed.
|
| 26 |
+
|
| 27 |
+
(* ---- the folded netlist --------------------------------------------------------------------------------------- *)
|
| 28 |
+
Section Fold.
|
| 29 |
+
Variable A : nat.
|
| 30 |
+
|
| 31 |
+
Definition blk_E : block := Blk 0 1 (fun _ => []).
|
| 32 |
+
Definition blk_FAF (o : nat) : block :=
|
| 33 |
+
Blk (A * SW A) 1 (fun m => [sAND ((mu A ((m mod SW A + o) mod SW A) (m / SW A), true) :: lits A pcb (m mod SW A))]).
|
| 34 |
+
Definition blk_WF : block := Blk (SW A) 1 (fun j => [sAND ((haltb A, false) :: lits A (opb A 1) j)]).
|
| 35 |
+
Definition blk_RXF : block :=
|
| 36 |
+
Blk (A * SW A) 1 (fun m => [sAND ((mu A (m mod SW A) (m / SW A), true) :: lits A (opb A 0) (m mod SW A))]).
|
| 37 |
+
Definition blk_RYF : block :=
|
| 38 |
+
Blk (A * SW A) 1 (fun m => [sAND ((mu A (m mod SW A) (m / SW A), true) :: lits A (opb A 1) (m mod SW A))]).
|
| 39 |
+
|
| 40 |
+
(* the blocks of H_A, those of the decode lines of a and b left empty *)
|
| 41 |
+
Definition fpre : list block :=
|
| 42 |
+
[blk_P A; blk_HP A; blk_FAF 0; blk_FAF 1; blk_FAF 2; blk_Q A; blk_F A; blk_E; blk_E; blk_AC A; blk_WF; blk_RXF;
|
| 43 |
+
blk_RYF; blk_KP A; blk_X A; blk_Y A; blk_PR A].
|
| 44 |
+
Definition fblocks : list block := fpre ++ map (blk_T A) (seq 1 (A - 1)) ++ hpost A.
|
| 45 |
+
|
| 46 |
+
Definition fold_units : list tu := compile (nH A) fblocks.
|
| 47 |
+
Definition fold_next : list nat := map (fun i => idx (nH A) fblocks (hout A i)) (seq 0 (nH A)).
|
| 48 |
+
|
| 49 |
+
End Fold.
|
| 50 |
+
|
| 51 |
+
(* the blocks the folding leaves as they are *)
|
| 52 |
+
Definition kept (b : nat) : Prop := b = 0 \/ b = 1 \/ b = 5 \/ b = 6 \/ b = 9 \/ 13 <= b.
|
| 53 |
+
|
| 54 |
+
Section FoldProofs.
|
| 55 |
+
Variable A : nat.
|
| 56 |
+
Hypothesis HA : 3 <= A.
|
| 57 |
+
|
| 58 |
+
Let HS : 8 <= SW A := SW_ge A HA.
|
| 59 |
+
|
| 60 |
+
Lemma SW_pos : 0 < SW A.
|
| 61 |
+
Proof. pose proof HS. lia. Qed.
|
| 62 |
+
|
| 63 |
+
Lemma length_fpre : length (fpre A) = 17.
|
| 64 |
+
Proof. reflexivity. Qed.
|
| 65 |
+
|
| 66 |
+
Lemma length_fblocks : length (fblocks A) = tb A + 15.
|
| 67 |
+
Proof. unfold fblocks, tb. rewrite !length_app, length_map, length_seq, length_fpre, length_hpost. lia. Qed.
|
| 68 |
+
|
| 69 |
+
Lemma nth_fb_pre : forall b, b < 17 -> nth b (fblocks A) blk0 = nth b (fpre A) blk0.
|
| 70 |
+
Proof. intros b H. unfold fblocks. rewrite app_nth1 by (rewrite length_fpre; exact H). reflexivity. Qed.
|
| 71 |
+
|
| 72 |
+
Lemma nth_fb_rest : forall b, 17 <= b -> nth b (fblocks A) blk0 = nth b (hblocks A) blk0.
|
| 73 |
+
Proof.
|
| 74 |
+
intros b H. unfold fblocks, hblocks.
|
| 75 |
+
rewrite (app_nth2 (fpre A)) by (rewrite length_fpre; exact H). rewrite (app_nth2 (hpre A)) by (rewrite length_hpre; exact H).
|
| 76 |
+
rewrite length_fpre, length_hpre. reflexivity.
|
| 77 |
+
Qed.
|
| 78 |
+
|
| 79 |
+
Lemma fb_kept : forall b, kept b -> nth b (fblocks A) blk0 = nth b (hblocks A) blk0.
|
| 80 |
+
Proof.
|
| 81 |
+
intros b Hb. destruct (Nat.lt_ge_cases b 17) as [Hl|Hg]; [|apply nth_fb_rest; exact Hg].
|
| 82 |
+
rewrite nth_fb_pre, nth_hb_pre by exact Hl.
|
| 83 |
+
destruct Hb as [->|[->|[->|[->|[->|Hb]]]]]; try reflexivity.
|
| 84 |
+
assert (Hc : b = 13 \/ b = 14 \/ b = 15 \/ b = 16) by lia. destruct Hc as [->|[->|[->| ->]]]; reflexivity.
|
| 85 |
+
Qed.
|
| 86 |
+
|
| 87 |
+
Lemma fb_dims : forall b, b <> 7 -> b <> 8 ->
|
| 88 |
+
bcount (nth b (fblocks A) blk0) = bcount (nth b (hblocks A) blk0)
|
| 89 |
+
/\ bsize (nth b (fblocks A) blk0) = bsize (nth b (hblocks A) blk0).
|
| 90 |
+
Proof.
|
| 91 |
+
intros b H7 H8. destruct (Nat.lt_ge_cases b 17) as [Hl|Hg]; [|rewrite nth_fb_rest by exact Hg; split; reflexivity].
|
| 92 |
+
rewrite nth_fb_pre, nth_hb_pre by exact Hl.
|
| 93 |
+
assert (Hc : b = 0 \/ b = 1 \/ b = 2 \/ b = 3 \/ b = 4 \/ b = 5 \/ b = 6 \/ b = 9 \/ b = 10 \/ b = 11 \/ b = 12
|
| 94 |
+
\/ b = 13 \/ b = 14 \/ b = 15 \/ b = 16) by lia.
|
| 95 |
+
destruct Hc as [->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->| ->]]]]]]]]]]]]]]; split; reflexivity.
|
| 96 |
+
Qed.
|
| 97 |
+
|
| 98 |
+
Lemma valid_kept : forall b j r, kept b ->
|
| 99 |
+
valid (fblocks A) (nH A) (SRef b j r) <-> valid (hblocks A) (nH A) (SRef b j r).
|
| 100 |
+
Proof.
|
| 101 |
+
intros b j r Hb. cbn [valid]. rewrite length_fblocks, length_hblocks by lia. rewrite fb_kept by exact Hb.
|
| 102 |
+
reflexivity.
|
| 103 |
+
Qed.
|
| 104 |
+
|
| 105 |
+
Lemma valid_up : forall b j r, 13 <= b -> valid (hblocks A) (nH A) (SRef b j r) -> valid (fblocks A) (nH A) (SRef b j r).
|
| 106 |
+
Proof. intros b j r Hb H. exact (proj2 (valid_kept b j r ltac:(unfold kept; lia)) H). Qed.
|
| 107 |
+
|
| 108 |
+
(* ---- every unit reads state bits and earlier units -------------------------------------------------------------- *)
|
| 109 |
+
Let rbf := reads_back (fblocks A) (nH A).
|
| 110 |
+
|
| 111 |
+
Lemma rbf_in : forall b j r i, i < nH A -> rbf b j r (SIn i).
|
| 112 |
+
Proof. intros b j r i H. exact H. Qed.
|
| 113 |
+
|
| 114 |
+
Lemma rbf_mu : forall b j r j' t, j' < SW A -> t < A -> rbf b j r (mu A j' t).
|
| 115 |
+
Proof. intros b j r j' t H1 H2. unfold mu. apply rbf_in. unfold nH. nia. Qed.
|
| 116 |
+
|
| 117 |
+
Lemma rbf_opb : forall b j r o t, 6 < b -> o < 3 -> t < A -> rbf b j r (opb A o t).
|
| 118 |
+
Proof.
|
| 119 |
+
intros b j r o t H1 H2 H3. unfold opb. left. rewrite nth_fb_pre by lia. cbn [nth fpre bcount bsize blk_F]. nia.
|
| 120 |
+
Qed.
|
| 121 |
+
|
| 122 |
+
(* the units of H_A after its carry terms lie at depth 7 at least *)
|
| 123 |
+
Lemma cd_post_ge : forall i j r, 7 <= cd_post A i j r.
|
| 124 |
+
Proof.
|
| 125 |
+
intros i j r. unfold cd_post.
|
| 126 |
+
do 14 (destruct i as [|i]; [repeat (destruct (_ <? _)); repeat (destruct (Nat.eqb _ _)); lia|]).
|
| 127 |
+
destruct (Nat.eqb _ _); lia.
|
| 128 |
+
Qed.
|
| 129 |
+
|
| 130 |
+
Lemma cdh_ge7 : forall b j r, 17 <= b -> 7 <= cdh A (SRef b j r).
|
| 131 |
+
Proof.
|
| 132 |
+
intros b j r Hb. cbn [cdh]. destruct (Nat.ltb_spec b 17); [lia|]. destruct (Nat.ltb_spec b (tb A)).
|
| 133 |
+
- unfold cd_T. destruct (Nat.eqb r 0); [lia|]. destruct (Nat.eqb r (b - 16)); lia.
|
| 134 |
+
- apply cd_post_ge.
|
| 135 |
+
Qed.
|
| 136 |
+
|
| 137 |
+
(* a unit of H_A that reads the decode lines of a or b has depth 5, so it lies in the blocks the folding replaces *)
|
| 138 |
+
Lemma cdh_five : forall b j r, cdh A (SRef b j r) = 5 -> b = 10 \/ b = 11 \/ b = 12.
|
| 139 |
+
Proof.
|
| 140 |
+
intros b j r H. destruct (Nat.lt_ge_cases b 17) as [Hb|Hb]; [|pose proof (cdh_ge7 b j r Hb); lia].
|
| 141 |
+
rewrite (cdh_pre A HA b j r Hb) in H.
|
| 142 |
+
do 17 (destruct b as [|b]; [cbn [cd_pre] in H; lia|]). lia.
|
| 143 |
+
Qed.
|
| 144 |
+
|
| 145 |
+
Lemma cdh_kept : forall b j r, 13 <= b -> 6 <= cdh A (SRef b j r).
|
| 146 |
+
Proof.
|
| 147 |
+
intros b j r H. destruct (Nat.lt_ge_cases b 17) as [Hb|Hb]; [|pose proof (cdh_ge7 b j r Hb); lia].
|
| 148 |
+
rewrite (cdh_pre A HA b j r Hb).
|
| 149 |
+
assert (Hc : b = 13 \/ b = 14 \/ b = 15 \/ b = 16) by lia. destruct Hc as [->|[->|[->| ->]]]; cbn [cd_pre]; lia.
|
| 150 |
+
Qed.
|
| 151 |
+
|
| 152 |
+
(* the units the folding keeps read what they read in H_A *)
|
| 153 |
+
Lemma rb_transfer : forall b j r x w, 13 <= b -> valid (hblocks A) (nH A) (SRef b j r) ->
|
| 154 |
+
In (x, w) (sin (sunit (hblocks A) b j r)) -> rbf b j r x.
|
| 155 |
+
Proof.
|
| 156 |
+
intros b j r x w Hb Hv Hin. pose proof Hv as (Hb' & Hj & Hr).
|
| 157 |
+
pose proof (proj2 (host_wf A HA) b j r x w Hb' Hj Hr Hin) as Hrb.
|
| 158 |
+
destruct x as [i|b0 j0 r0]; [exact Hrb|].
|
| 159 |
+
destruct Hrb as [(Hlt & Hj0 & Hr0)|(-> & -> & Hr0)]; [|right; auto].
|
| 160 |
+
destruct (Nat.eq_dec b0 7) as [E7|E7]; [|destruct (Nat.eq_dec b0 8) as [E8|E8]].
|
| 161 |
+
1, 2: exfalso; destruct (host_unit_ok A HA b j r Hv) as [Hall _]; destruct (Hall _ _ Hin) as [H1 H2];
|
| 162 |
+
rewrite (cdh_pre A HA b0 j0 r0) in H1 by lia; rewrite (clh_pre A HA b0 j0 r0) in H2 by lia; subst b0;
|
| 163 |
+
cbn [cd_pre cl_pre] in H1, H2; destruct (cdh_five b j r ltac:(lia)) as [->|[->| ->]]; lia.
|
| 164 |
+
left. destruct (fb_dims b0 E7 E8) as [Ec Es]. rewrite Ec, Es. auto.
|
| 165 |
+
Qed.
|
| 166 |
+
|
| 167 |
+
Ltac flits Hin := lits_in Hin; unfold lits in *; rewrite ?map_map in *; cbn [map fst] in *.
|
| 168 |
+
|
| 169 |
+
Theorem fold_wf : wf (fblocks A) (nH A).
|
| 170 |
+
Proof.
|
| 171 |
+
split.
|
| 172 |
+
{ unfold fblocks. apply Forall_app; split; [|apply Forall_app; split].
|
| 173 |
+
- unfold fpre. repeat apply Forall_cons; try apply Forall_nil; intros j Hj; cbn [bcount blk_E] in Hj;
|
| 174 |
+
first [reflexivity | lia].
|
| 175 |
+
- apply Forall_forall. intros blk Hin. apply in_map_iff in Hin as (k & <- & _).
|
| 176 |
+
intros j Hj. cbn [bshape bsize blk_T length]. rewrite length_map, length_seq. reflexivity.
|
| 177 |
+
- unfold hpost. repeat apply Forall_cons; try apply Forall_nil; intros j Hj; reflexivity. }
|
| 178 |
+
intros b j r x w Hb Hj Hr Hin. rewrite length_fblocks in Hb.
|
| 179 |
+
destruct (Nat.le_gt_cases 13 b) as [H13|H13].
|
| 180 |
+
{ assert (Hk : kept b) by (unfold kept; lia).
|
| 181 |
+
rewrite fb_kept in Hj, Hr by exact Hk. unfold sunit in Hin. rewrite fb_kept in Hin by exact Hk.
|
| 182 |
+
apply (rb_transfer b j r x w H13); [|exact Hin]. split; [rewrite length_hblocks by lia; lia | split; assumption]. }
|
| 183 |
+
rewrite nth_fb_pre in Hj, Hr by lia. unfold sunit in Hin. rewrite nth_fb_pre in Hin by lia.
|
| 184 |
+
assert (Hc : b = 0 \/ b = 1 \/ b = 2 \/ b = 3 \/ b = 4 \/ b = 5 \/ b = 6 \/ b = 7 \/ b = 8 \/ b = 9 \/ b = 10
|
| 185 |
+
\/ b = 11 \/ b = 12) by lia.
|
| 186 |
+
destruct Hc as [->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->| ->]]]]]]]]]]]];
|
| 187 |
+
cbn [nth fpre bcount bsize bshape blk_P blk_HP blk_FAF blk_Q blk_F blk_E blk_AC blk_WF blk_RXF blk_RYF] in Hj, Hr, Hin;
|
| 188 |
+
try lia; (destruct r as [|r]; [|lia]); cbn [nth] in Hin.
|
| 189 |
+
- (* P *) flits Hin. apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_in. unfold nH. nia.
|
| 190 |
+
- (* HP *) flits Hin. destruct H as [<-|[<-|[]]]; apply rbf_in; unfold nH; nia.
|
| 191 |
+
- (* FA 0 *) flits Hin. pose proof (mod_lt j (SW A) ltac:(lia)). pose proof (div_lt j A (SW A) ltac:(lia) ltac:(lia)).
|
| 192 |
+
destruct H as [<-|H]; [apply rbf_mu; [apply mod_lt|]; lia|].
|
| 193 |
+
apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_in. unfold nH. nia.
|
| 194 |
+
- (* FA 1 *) flits Hin. pose proof (mod_lt j (SW A) ltac:(lia)). pose proof (div_lt j A (SW A) ltac:(lia) ltac:(lia)).
|
| 195 |
+
destruct H as [<-|H]; [apply rbf_mu; [apply mod_lt|]; lia|].
|
| 196 |
+
apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_in. unfold nH. nia.
|
| 197 |
+
- (* FA 2 *) flits Hin. pose proof (mod_lt j (SW A) ltac:(lia)). pose proof (div_lt j A (SW A) ltac:(lia) ltac:(lia)).
|
| 198 |
+
destruct H as [<-|H]; [apply rbf_mu; [apply mod_lt|]; lia|].
|
| 199 |
+
apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_in. unfold nH. nia.
|
| 200 |
+
- (* Q *) flits Hin. apply in_map_iff in H as (j' & <- & Hj'). apply filter_In in Hj' as [Hj' _]. apply in_seq in Hj'.
|
| 201 |
+
left. rewrite nth_fb_pre by lia. cbn [nth fpre bcount bsize blk_P]. lia.
|
| 202 |
+
- (* F *) flits Hin. apply in_map_iff in H as (j' & <- & Hj'). apply in_seq in Hj'.
|
| 203 |
+
pose proof (div_lt j 3 A ltac:(lia) ltac:(lia)). pose proof (mod_lt j A ltac:(lia)).
|
| 204 |
+
left. rewrite nth_fb_pre by lia. split; [lia|].
|
| 205 |
+
assert (Ho : j / A = 0 \/ j / A = 1 \/ j / A = 2) by lia.
|
| 206 |
+
destruct Ho as [-> | [-> | ->]]; cbn [Nat.add nth fpre bcount bsize blk_FAF]; nia.
|
| 207 |
+
- (* AC *) flits Hin. apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_opb; lia.
|
| 208 |
+
- (* W *) flits Hin. destruct H as [<-|H]; [apply rbf_in; unfold nH; lia|].
|
| 209 |
+
apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht. apply rbf_opb; lia.
|
| 210 |
+
- (* RX *) flits Hin. pose proof (mod_lt j (SW A) ltac:(lia)). pose proof (div_lt j A (SW A) ltac:(lia) ltac:(lia)).
|
| 211 |
+
destruct H as [<-|H]; [apply rbf_mu; lia|]. apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht.
|
| 212 |
+
apply rbf_opb; lia.
|
| 213 |
+
- (* RY *) flits Hin. pose proof (mod_lt j (SW A) ltac:(lia)). pose proof (div_lt j A (SW A) ltac:(lia) ltac:(lia)).
|
| 214 |
+
destruct H as [<-|H]; [apply rbf_mu; lia|]. apply in_map_iff in H as (t & <- & Ht). apply in_seq in Ht.
|
| 215 |
+
apply rbf_opb; lia.
|
| 216 |
+
Qed.
|
| 217 |
+
|
| 218 |
+
Lemma hout_fvalid : forall i, i < nH A -> valid (fblocks A) (nH A) (hout A i).
|
| 219 |
+
Proof.
|
| 220 |
+
intros i Hi. pose proof (hout_valid A HA i Hi) as H. revert H. unfold hout.
|
| 221 |
+
destruct (Nat.ltb_spec i A); [|destruct (Nat.eqb_spec i A)];
|
| 222 |
+
(intro Hh; apply valid_up; [unfold tb; lia | exact Hh]).
|
| 223 |
+
Qed.
|
| 224 |
+
|
| 225 |
+
(* ---- the step ------------------------------------------------------------------------------------------------- *)
|
| 226 |
+
Section Step.
|
| 227 |
+
Variable s : hst.
|
| 228 |
+
Hypothesis Hv : hvalid A s.
|
| 229 |
+
|
| 230 |
+
Ltac side := first [apply mod_lt; exact SW_pos | apply div_lt; [assumption | exact SW_pos]].
|
| 231 |
+
|
| 232 |
+
Lemma fold_fires : forall b j r, valid (fblocks A) (nH A) (SRef b j r) ->
|
| 233 |
+
HF A s (SRef b j r) = sfire' (sunit (fblocks A) b j r) (HF A s).
|
| 234 |
+
Proof.
|
| 235 |
+
intros b j r Hvf.
|
| 236 |
+
destruct (Nat.le_gt_cases 13 b) as [H13|H13].
|
| 237 |
+
{ assert (Hk : kept b) by (unfold kept; lia).
|
| 238 |
+
pose proof (proj1 (valid_kept b j r Hk) Hvf) as (Hb & Hj & Hr).
|
| 239 |
+
unfold sunit. rewrite fb_kept by exact Hk. exact (HF_unit A s HA b j r Hb Hj Hr). }
|
| 240 |
+
pose proof Hvf as (Hb & Hj & Hr). rewrite nth_fb_pre in Hj, Hr by lia.
|
| 241 |
+
assert (Hc : b = 0 \/ b = 1 \/ b = 5 \/ b = 6 \/ b = 9 \/ b = 2 \/ b = 3 \/ b = 4 \/ b = 7 \/ b = 8 \/ b = 10
|
| 242 |
+
\/ b = 11 \/ b = 12) by lia.
|
| 243 |
+
destruct Hc as [Hk|[Hk|[Hk|[Hk|[Hk|Hc]]]]].
|
| 244 |
+
1-5: assert (Hkp : kept b) by (unfold kept; lia);
|
| 245 |
+
pose proof (proj1 (valid_kept b j r Hkp) Hvf) as (Hb' & Hj' & Hr');
|
| 246 |
+
unfold sunit; rewrite fb_kept by exact Hkp; exact (HF_unit A s HA b j r Hb' Hj' Hr').
|
| 247 |
+
unfold sunit. rewrite nth_fb_pre by lia.
|
| 248 |
+
destruct Hc as [->|[->|[->|[->|[->|[->|[->| ->]]]]]]];
|
| 249 |
+
cbn [nth fpre bcount bsize bshape blk_FAF blk_E blk_WF blk_RXF blk_RYF] in Hj, Hr |- *; try lia;
|
| 250 |
+
(destruct r as [|r]; [|lia]); cbn [nth]; rewrite sAND_fire; cbn [forallb].
|
| 251 |
+
- (* FA 0 *) change (SRef 2 j 0) with (SRef (2 + 0) j 0).
|
| 252 |
+
rewrite litv_pos, (HF_FA A s HA Hv 0 j ltac:(lia) Hj), (HF_mu A s HA Hv) by side.
|
| 253 |
+
rewrite (lits_fire A (HF A s) pcb (j mod SW A) (hp s) (mod_lt j (SW A) SW_pos) (hp_lt A s Hv))
|
| 254 |
+
by (intros t Ht; exact (HF_pc A s HA t Ht)).
|
| 255 |
+
reflexivity.
|
| 256 |
+
- (* FA 1 *) change (SRef 3 j 0) with (SRef (2 + 1) j 0).
|
| 257 |
+
rewrite litv_pos, (HF_FA A s HA Hv 1 j ltac:(lia) Hj), (HF_mu A s HA Hv) by side.
|
| 258 |
+
rewrite (lits_fire A (HF A s) pcb (j mod SW A) (hp s) (mod_lt j (SW A) SW_pos) (hp_lt A s Hv))
|
| 259 |
+
by (intros t Ht; exact (HF_pc A s HA t Ht)).
|
| 260 |
+
reflexivity.
|
| 261 |
+
- (* FA 2 *) change (SRef 4 j 0) with (SRef (2 + 2) j 0).
|
| 262 |
+
rewrite litv_pos, (HF_FA A s HA Hv 2 j ltac:(lia) Hj), (HF_mu A s HA Hv) by side.
|
| 263 |
+
rewrite (lits_fire A (HF A s) pcb (j mod SW A) (hp s) (mod_lt j (SW A) SW_pos) (hp_lt A s Hv))
|
| 264 |
+
by (intros t Ht; exact (HF_pc A s HA t Ht)).
|
| 265 |
+
reflexivity.
|
| 266 |
+
- (* W *) rewrite litv_neg, (HF_halt A s HA), (HF_W A s HA Hv j Hj).
|
| 267 |
+
rewrite (lits_fire A (HF A s) (opb A 1) j (hb A s) Hj (hb_lt A s HA Hv))
|
| 268 |
+
by (intros t Ht; rewrite (HF_opb A s HA Hv 1 t) by lia; reflexivity).
|
| 269 |
+
reflexivity.
|
| 270 |
+
- (* RX *) rewrite litv_pos, (HF_RX A s HA Hv j Hj), (HF_mu A s HA Hv) by side.
|
| 271 |
+
rewrite (lits_fire A (HF A s) (opb A 0) (j mod SW A) (ha s) (mod_lt j (SW A) SW_pos) (ha_lt A s HA Hv))
|
| 272 |
+
by (intros t Ht; exact (HF_opa A s HA Hv t Ht)).
|
| 273 |
+
reflexivity.
|
| 274 |
+
- (* RY *) rewrite litv_pos, (HF_RY A s HA Hv j Hj), (HF_mu A s HA Hv) by side.
|
| 275 |
+
rewrite (lits_fire A (HF A s) (opb A 1) (j mod SW A) (hb A s) (mod_lt j (SW A) SW_pos) (hb_lt A s HA Hv))
|
| 276 |
+
by (intros t Ht; rewrite (HF_opb A s HA Hv 1 t) by lia; reflexivity).
|
| 277 |
+
reflexivity.
|
| 278 |
+
Qed.
|
| 279 |
+
|
| 280 |
+
Lemma fold_values : forall x, valid (fblocks A) (nH A) x ->
|
| 281 |
+
run (fold_units A) (nH A) (HX A s) (idx (nH A) (fblocks A) x) = HF A s x.
|
| 282 |
+
Proof.
|
| 283 |
+
apply (net_unique (fblocks A) (nH A) (HX A s) (HF A s) fold_wf).
|
| 284 |
+
- intros i Hi. apply HF_in. exact Hi.
|
| 285 |
+
- exact fold_fires.
|
| 286 |
+
Qed.
|
| 287 |
+
|
| 288 |
+
End Step.
|
| 289 |
+
|
| 290 |
+
(* the step of the folded host is the step of SUBLEQ, from every state *)
|
| 291 |
+
Theorem fold_step : forall s, hvalid A s ->
|
| 292 |
+
netstep (nH A) (fold_units A) (fold_next A) (encodeH A s) = encodeH A (subleq A s).
|
| 293 |
+
Proof.
|
| 294 |
+
intros s Hv. rewrite <- (host_step A s HA Hv). unfold netstep, fold_next, host_next. rewrite !map_map.
|
| 295 |
+
apply map_ext_in. intros i Hi. apply in_seq in Hi.
|
| 296 |
+
change (fun i0 => nth i0 (encodeH A s) false) with (HX A s).
|
| 297 |
+
rewrite (fold_values s Hv (hout A i) (hout_fvalid i ltac:(lia))). reflexivity.
|
| 298 |
+
Qed.
|
| 299 |
+
|
| 300 |
+
(* ---- depth 11 ----------------------------------------------------------------------------------------------------- *)
|
| 301 |
+
Definition cdf_pre (b : nat) : nat :=
|
| 302 |
+
match b with 0 | 1 | 2 | 3 | 4 => 1 | 5 | 6 => 2 | 7 | 8 | 9 | 10 | 11 | 12 => 3 | 13 | 14 | 15 => 4 | _ => 5 end.
|
| 303 |
+
Definition cdf (x : sref) : nat :=
|
| 304 |
+
match x with SIn _ => 0 | SRef b j r => if b <? 17 then cdf_pre b else cdh A x - 2 end.
|
| 305 |
+
|
| 306 |
+
(* the units from block 10 on lie two levels lower than in H_A, and the others at level 3 at most *)
|
| 307 |
+
Lemma cdf_hi : forall x, 5 <= cdh A x -> cdf x = cdh A x - 2.
|
| 308 |
+
Proof.
|
| 309 |
+
intros [i|b j r] H; [cbn [cdh] in H; lia|]. cbn [cdf]. destruct (Nat.ltb_spec b 17) as [Hb|Hb]; [|reflexivity].
|
| 310 |
+
rewrite (cdh_pre A HA b j r Hb) in *. do 17 (destruct b as [|b]; [cbn [cd_pre cdf_pre] in *; lia|]). lia.
|
| 311 |
+
Qed.
|
| 312 |
+
|
| 313 |
+
Lemma cdf_lo : forall x, cdh A x <= 4 -> cdf x <= 3.
|
| 314 |
+
Proof.
|
| 315 |
+
intros [i|b j r] H; [cbn [cdf]; lia|]. cbn [cdf]. destruct (Nat.ltb_spec b 17) as [Hb|Hb].
|
| 316 |
+
- rewrite (cdh_pre A HA b j r Hb) in H. do 17 (destruct b as [|b]; [cbn [cd_pre cdf_pre] in *; lia|]). lia.
|
| 317 |
+
- pose proof (cdh_ge7 b j r Hb). lia.
|
| 318 |
+
Qed.
|
| 319 |
+
|
| 320 |
+
Lemma cdf_kept : forall b j r, valid (hblocks A) (nH A) (SRef b j r) -> 13 <= b ->
|
| 321 |
+
cdf (SRef b j r) = S (maxl (map (fun p => cdf (fst p)) (sin (sunit (hblocks A) b j r)))).
|
| 322 |
+
Proof.
|
| 323 |
+
intros b j r Hvh H13. pose proof (cdh_kept b j r H13) as H6.
|
| 324 |
+
destruct (host_unit_ok A HA b j r Hvh) as [Hall (p & z & Hin & E)]. apply cd_rec.
|
| 325 |
+
- intros p' z' Hin'. destruct (Hall p' z' Hin') as [H1 _]. rewrite (cdf_hi (SRef b j r)) by lia.
|
| 326 |
+
destruct (Nat.le_gt_cases 5 (cdh A p')) as [H5|H5]; [rewrite (cdf_hi p') by exact H5; lia|].
|
| 327 |
+
pose proof (cdf_lo p' ltac:(lia)). lia.
|
| 328 |
+
- exists p, z. split; [exact Hin|]. rewrite (cdf_hi (SRef b j r)), (cdf_hi p) by lia. lia.
|
| 329 |
+
Qed.
|
| 330 |
+
|
| 331 |
+
Lemma cdf_rec : forall b j r, valid (fblocks A) (nH A) (SRef b j r) ->
|
| 332 |
+
cdf (SRef b j r) = S (maxl (map (fun p => cdf (fst p)) (sin (sunit (fblocks A) b j r)))).
|
| 333 |
+
Proof.
|
| 334 |
+
intros b j r Hvf.
|
| 335 |
+
destruct (Nat.le_gt_cases 13 b) as [H13|H13].
|
| 336 |
+
{ assert (Hk : kept b) by (unfold kept; lia).
|
| 337 |
+
unfold sunit. rewrite fb_kept by exact Hk. apply cdf_kept; [|exact H13]. exact (proj1 (valid_kept b j r Hk) Hvf). }
|
| 338 |
+
pose proof Hvf as (Hb & Hj & Hr). rewrite nth_fb_pre in Hj, Hr by lia. unfold sunit. rewrite nth_fb_pre by lia.
|
| 339 |
+
apply cd_rec.
|
| 340 |
+
all: assert (Hc : b = 0 \/ b = 1 \/ b = 2 \/ b = 3 \/ b = 4 \/ b = 5 \/ b = 6 \/ b = 7 \/ b = 8 \/ b = 9 \/ b = 10
|
| 341 |
+
\/ b = 11 \/ b = 12) by lia.
|
| 342 |
+
all: destruct Hc as [->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->|[->| ->]]]]]]]]]]]];
|
| 343 |
+
cbn [nth fpre bcount bsize bshape blk_P blk_HP blk_FAF blk_Q blk_F blk_E blk_AC blk_WF blk_RXF blk_RYF] in Hj, Hr |- *;
|
| 344 |
+
try lia; (destruct r as [|r]; [|lia]); cbn [nth cdf Nat.ltb Nat.leb cdf_pre].
|
| 345 |
+
(* every predecessor lies below *)
|
| 346 |
+
- intros p z Hin. flits Hin. apply in_map_iff in H as (t & <- & _). cbn [cdf pcb]. lia.
|
| 347 |
+
- intros p z Hin. flits Hin. destruct H as [<-|[<-|[]]]; cbn [cdf pcb haltb]; lia.
|
| 348 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf mu]; lia|].
|
| 349 |
+
apply in_map_iff in H as (t & <- & _). cbn [cdf pcb]; lia.
|
| 350 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf mu]; lia|].
|
| 351 |
+
apply in_map_iff in H as (t & <- & _). cbn [cdf pcb]; lia.
|
| 352 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf mu]; lia|].
|
| 353 |
+
apply in_map_iff in H as (t & <- & _). cbn [cdf pcb]; lia.
|
| 354 |
+
- intros p z Hin. flits Hin. apply in_map_iff in H as (j' & <- & _). cbn [cdf Nat.ltb Nat.leb cdf_pre]. lia.
|
| 355 |
+
- intros p z Hin. flits Hin. apply in_map_iff in H as (j' & <- & _).
|
| 356 |
+
assert (Ho : j / A = 0 \/ j / A = 1 \/ j / A = 2) by (pose proof (div_lt j 3 A ltac:(lia) ltac:(lia)); lia).
|
| 357 |
+
destruct Ho as [-> | [-> | ->]]; cbn [cdf Nat.add Nat.ltb Nat.leb cdf_pre]; lia.
|
| 358 |
+
- intros p z Hin. flits Hin. apply in_map_iff in H as (t & <- & _). cbn [cdf opb Nat.ltb Nat.leb cdf_pre]. lia.
|
| 359 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf haltb]; lia|]. apply in_map_iff in H as (t & <- & _).
|
| 360 |
+
cbn [cdf opb Nat.ltb Nat.leb cdf_pre]. lia.
|
| 361 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf mu]; lia|]. apply in_map_iff in H as (t & <- & _).
|
| 362 |
+
cbn [cdf opb Nat.ltb Nat.leb cdf_pre]. lia.
|
| 363 |
+
- intros p z Hin. flits Hin. destruct H as [<-|H]; [cbn [cdf mu]; lia|]. apply in_map_iff in H as (t & <- & _).
|
| 364 |
+
cbn [cdf opb Nat.ltb Nat.leb cdf_pre]. lia.
|
| 365 |
+
(* one predecessor lies just below *)
|
| 366 |
+
- exists (pcb 0), (if bitof A j 0 then 1%Z else (-1)%Z). split; [|reflexivity].
|
| 367 |
+
apply (in_and _ _ (bitof A j 0)). unfold lits. apply (in_map (fun t => (pcb t, bitof A j t))). apply in_seq. lia.
|
| 368 |
+
- exists (pcb j), 1%Z. split; [apply (in_and _ _ true); left; reflexivity | reflexivity].
|
| 369 |
+
- exists (mu A ((j mod SW A + 0) mod SW A) (j / SW A)), 1%Z.
|
| 370 |
+
split; [apply (in_and _ _ true); left; reflexivity | reflexivity].
|
| 371 |
+
- exists (mu A ((j mod SW A + 1) mod SW A) (j / SW A)), 1%Z.
|
| 372 |
+
split; [apply (in_and _ _ true); left; reflexivity | reflexivity].
|
| 373 |
+
- exists (mu A ((j mod SW A + 2) mod SW A) (j / SW A)), 1%Z.
|
| 374 |
+
split; [apply (in_and _ _ true); left; reflexivity | reflexivity].
|
| 375 |
+
- exists (SRef 0 (SW A - 4) 0), 1%Z. split; [|reflexivity].
|
| 376 |
+
apply (in_or _ _ true). apply (in_map (fun j' => (SRef 0 j' 0, true))). apply Q_ne; lia.
|
| 377 |
+
- assert (Ho : j / A = 0 \/ j / A = 1 \/ j / A = 2) by (pose proof (div_lt j 3 A ltac:(lia) ltac:(lia)); lia).
|
| 378 |
+
exists (SRef (2 + j / A) ((j mod A) * SW A + 0) 0), 1%Z. split.
|
| 379 |
+
+ apply (in_or _ _ true). apply (in_map (fun j' => (SRef (2 + j / A) ((j mod A) * SW A + j') 0, true))).
|
| 380 |
+
apply in_seq. lia.
|
| 381 |
+
+ destruct Ho as [-> | [-> | ->]]; reflexivity.
|
| 382 |
+
- exists (opb A 2 0), 1%Z. split; [|reflexivity].
|
| 383 |
+
apply (in_and _ _ true). apply (in_map (fun t => (opb A 2 t, true))). apply in_seq. lia.
|
| 384 |
+
- exists (opb A 1 0), (if bitof A j 0 then 1%Z else (-1)%Z). split; [|reflexivity].
|
| 385 |
+
apply (in_and _ _ (bitof A j 0)). right. unfold lits. apply (in_map (fun t => (opb A 1 t, bitof A j t))).
|
| 386 |
+
apply in_seq. lia.
|
| 387 |
+
- exists (opb A 0 0), (if bitof A (j mod SW A) 0 then 1%Z else (-1)%Z). split; [|reflexivity].
|
| 388 |
+
apply (in_and _ _ (bitof A (j mod SW A) 0)). right. unfold lits.
|
| 389 |
+
apply (in_map (fun t => (opb A 0 t, bitof A (j mod SW A) t))). apply in_seq. lia.
|
| 390 |
+
- exists (opb A 1 0), (if bitof A (j mod SW A) 0 then 1%Z else (-1)%Z). split; [|reflexivity].
|
| 391 |
+
apply (in_and _ _ (bitof A (j mod SW A) 0)). right. unfold lits.
|
| 392 |
+
apply (in_map (fun t => (opb A 1 t, bitof A (j mod SW A) t))). apply in_seq. lia.
|
| 393 |
+
Qed.
|
| 394 |
+
|
| 395 |
+
Lemma cdf0 : forall i, cdf (SIn i) = 0.
|
| 396 |
+
Proof. reflexivity. Qed.
|
| 397 |
+
|
| 398 |
+
Lemma cdf_le11 : forall x, cdf x <= 11.
|
| 399 |
+
Proof.
|
| 400 |
+
intros [i|b j r]; cbn [cdf]; [lia|]. destruct (Nat.ltb_spec b 17) as [Hb|Hb].
|
| 401 |
+
- do 17 (destruct b as [|b]; [cbn [cdf_pre]; lia|]). lia.
|
| 402 |
+
- pose proof (cdh_le13 A HA (SRef b j r)). lia.
|
| 403 |
+
Qed.
|
| 404 |
+
|
| 405 |
+
Theorem fold_dep : forall x, valid (fblocks A) (nH A) x -> dep (nH A) (fold_units A) (idx (nH A) (fblocks A) x) = cdf x.
|
| 406 |
+
Proof. exact (dep_cd (fblocks A) (nH A) fold_wf cdf cdf0 cdf_rec). Qed.
|
| 407 |
+
|
| 408 |
+
(* the step of the folded host has depth 11 *)
|
| 409 |
+
Theorem fold_dmax : dmax (nH A) (fold_units A) = 11.
|
| 410 |
+
Proof.
|
| 411 |
+
apply (dmax_cd (fblocks A) (nH A) fold_wf cdf cdf0 cdf_rec 11).
|
| 412 |
+
- intros b j r _. apply cdf_le11.
|
| 413 |
+
- exists (tb A + 11), 0, 0. split.
|
| 414 |
+
+ apply valid_up; [unfold tb; lia|]. split; [rewrite length_hblocks by lia; lia|]. rewrite nth_hb_post by lia.
|
| 415 |
+
cbn. lia.
|
| 416 |
+
+ cbn [cdf]. destruct (Nat.ltb_spec (tb A + 11) 17); [unfold tb in *; lia|]. rewrite (cdh_post A HA). reflexivity.
|
| 417 |
+
Qed.
|
| 418 |
+
|
| 419 |
+
(* ---- units and edges ---------------------------------------------------------------------------------------------- *)
|
| 420 |
+
Lemma bsum_fold : forall g, bsum (fblocks A) g =
|
| 421 |
+
nsum 17 (fun b => nsum (bcount (nth b (fpre A) blk0)) (fun j => nsum (bsize (nth b (fpre A) blk0)) (fun r => g (SRef b j r))))
|
| 422 |
+
+ nsum (A - 1) (fun i => nsum (S (S i)) (fun r => g (SRef (17 + i) 0 r)))
|
| 423 |
+
+ nsum 15 (fun i => nsum (bcount (nth i (hpost A) blk0)) (fun j => nsum (bsize (nth i (hpost A) blk0))
|
| 424 |
+
(fun r => g (SRef (tb A + i) j r)))).
|
| 425 |
+
Proof.
|
| 426 |
+
intro g. unfold bsum, cnt, sz. rewrite length_fblocks. replace (tb A + 15) with (17 + (A - 1) + 15) by (unfold tb; lia).
|
| 427 |
+
rewrite !nsum_split. f_equal; [f_equal|].
|
| 428 |
+
all: apply nsum_ext; intros i Hi;
|
| 429 |
+
first [ rewrite nth_fb_pre by lia; reflexivity
|
| 430 |
+
| rewrite nth_fb_rest by lia; replace (17 + i) with (16 + S i) by lia; rewrite nth_hb_T by lia;
|
| 431 |
+
cbn [bcount bsize blk_T nsum]; reflexivity
|
| 432 |
+
| rewrite nth_fb_rest by (unfold tb; lia); replace (17 + (A - 1) + i) with (tb A + i) by (unfold tb; lia);
|
| 433 |
+
rewrite nth_hb_post by lia; reflexivity ].
|
| 434 |
+
Qed.
|
| 435 |
+
|
| 436 |
+
(* (8A + 2) 2^A + (A^2 + 39A + 4)/2 units *)
|
| 437 |
+
Theorem fold_units_count : 2 * length (fold_units A) = (16 * A + 4) * SW A + A * A + 39 * A + 4.
|
| 438 |
+
Proof.
|
| 439 |
+
change (fold_units A) with (fus (fblocks A) (nH A)).
|
| 440 |
+
rewrite (units_bsum (fblocks A) (nH A) (hout A) fold_wf hout_fvalid), bsum_fold.
|
| 441 |
+
rewrite (nsum_ext (A - 1) _ (fun i => S (S i))) by (intros i _; rewrite nsum_const; lia).
|
| 442 |
+
rewrite (nsum_SS A HA). pose proof (tri_eq A HA).
|
| 443 |
+
cbn [nsum nth fpre hpost bcount bsize blk_P blk_HP blk_FAF blk_Q blk_F blk_E blk_AC blk_WF blk_RXF blk_RYF blk_KP
|
| 444 |
+
blk_X blk_Y blk_PR blk_C blk_AX blk_NX blk_XN blk_EQ blk_R0 blk_H blk_R blk_LEQ blk_TA blk_TB blk_NP blk_HAB
|
| 445 |
+
blk_WR blk_NM].
|
| 446 |
+
rewrite !nsum_const. nia.
|
| 447 |
+
Qed.
|
| 448 |
+
|
| 449 |
+
Definition fpe (b : nat) : nat :=
|
| 450 |
+
nsum (bcount (nth b (fpre A) blk0)) (fun j => nsum (bsize (nth b (fpre A) blk0))
|
| 451 |
+
(fun r => length (sin (nth r (bshape (nth b (fpre A) blk0) j) su0)))).
|
| 452 |
+
|
| 453 |
+
Ltac fcnt := unfold fpe;
|
| 454 |
+
cbn [nth fpre bcount bsize bshape blk_P blk_HP blk_FAF blk_Q blk_F blk_E blk_AC blk_WF blk_RXF blk_RYF blk_KP blk_X
|
| 455 |
+
blk_Y blk_PR nsum sin sAND sOR lits map length app];
|
| 456 |
+
repeat setoid_rewrite length_map; repeat setoid_rewrite length_seq; rewrite ?nsum_const; try lia.
|
| 457 |
+
|
| 458 |
+
Lemma fpe_vals : fpe 0 = SW A * A /\ fpe 1 = A * 2 /\ fpe 2 = A * SW A * S A /\ fpe 3 = A * SW A * S A
|
| 459 |
+
/\ fpe 4 = A * SW A * S A /\ fpe 6 = 3 * A * SW A /\ fpe 7 = 0 /\ fpe 8 = 0 /\ fpe 9 = A /\ fpe 10 = SW A * S A
|
| 460 |
+
/\ fpe 11 = A * SW A * S A /\ fpe 12 = A * SW A * S A /\ fpe 13 = SW A * A * 2 /\ fpe 14 = A * SW A
|
| 461 |
+
/\ fpe 15 = A * SW A /\ fpe 16 = (A - 1) * 2.
|
| 462 |
+
Proof. repeat split; fcnt. Qed.
|
| 463 |
+
|
| 464 |
+
Lemma fpe5 : fpe 5 = A * 2 ^ (A - 1).
|
| 465 |
+
Proof.
|
| 466 |
+
unfold fpe. cbn [nth fpre bcount bsize bshape blk_Q nsum sin sOR].
|
| 467 |
+
rewrite (nsum_ext A _ (fun _ => 2 ^ (A - 1))); [rewrite nsum_const; lia|].
|
| 468 |
+
intros i Hi. cbn [nth Nat.add]. rewrite !length_map. apply (Q_count A HA). lia.
|
| 469 |
+
Qed.
|
| 470 |
+
|
| 471 |
+
(* 2^(A-1) (10A^2 + 37A + 2) + (A^3 + 9A^2 + 194A + 24)/6 edges *)
|
| 472 |
+
Theorem fold_edges : 6 * nsum (length (fold_units A)) (fun k => length (tin (nth k (fold_units A) tu0)))
|
| 473 |
+
= 3 * (10 * (A * A) + 37 * A + 2) * SW A + A * A * A + 9 * (A * A) + 194 * A + 24.
|
| 474 |
+
Proof.
|
| 475 |
+
change (fold_units A) with (fus (fblocks A) (nH A)).
|
| 476 |
+
rewrite (edges_bsum (fblocks A) (nH A) (hout A) fold_wf hout_fvalid), bsum_fold.
|
| 477 |
+
rewrite (nsum_ext 17 _ fpe)
|
| 478 |
+
by (intros b Hb; unfold fpe; apply nsum_ext; intros j _; apply nsum_ext; intros r _; cbn [usu]; unfold sunit;
|
| 479 |
+
rewrite nth_fb_pre by exact Hb; reflexivity).
|
| 480 |
+
rewrite (nsum_ext (A - 1) _ (te A))
|
| 481 |
+
by (intros i Hi; unfold te; apply nsum_ext; intros r _; cbn [usu]; unfold sunit;
|
| 482 |
+
rewrite nth_fb_rest by lia; replace (17 + i) with (16 + S i) by lia; rewrite nth_hb_T by lia; reflexivity).
|
| 483 |
+
rewrite (nsum_ext 15 _ (qe A))
|
| 484 |
+
by (intros i Hi; unfold qe; apply nsum_ext; intros j _; apply nsum_ext; intros r _; cbn [usu]; unfold sunit;
|
| 485 |
+
rewrite nth_fb_rest by (unfold tb; lia); rewrite nth_hb_post by lia; reflexivity).
|
| 486 |
+
cbn [nsum]. rewrite fpe5, (qe0 A HA).
|
| 487 |
+
destruct fpe_vals as (P0 & P1 & P2 & P3 & P4 & P6 & P7 & P8 & P9 & P10 & P11 & P12 & P13 & P14 & P15 & P16).
|
| 488 |
+
destruct (qe_vals A HA) as (Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & Q7 & Q8 & Q9 & Q10 & Q11 & Q12 & Q13 & Q14).
|
| 489 |
+
rewrite P0, P1, P2, P3, P4, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16.
|
| 490 |
+
rewrite Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14.
|
| 491 |
+
assert (HT : 2 * nsum (A - 1) (te A) = nsum (A - 1) (fun i => S i * S i + 5 * S i)).
|
| 492 |
+
{ generalize (A - 1) as K. induction K as [|K IH]; cbn [nsum]; [reflexivity|]. rewrite <- IH, <- (te_val A HA). lia. }
|
| 493 |
+
pose proof (sum_te A HA (A - 1)) as HS6. pose proof (tri_eq A HA) as Htri. pose proof (SW_half A HA) as Hh.
|
| 494 |
+
assert (Ea : exists a, A = S (S (S a))) by (exists (A - 3); lia). destruct Ea as [a Ea].
|
| 495 |
+
rewrite Ea in *. cbn [Nat.sub] in *. rewrite ?Nat.sub_0_r in *. nia.
|
| 496 |
+
Qed.
|
| 497 |
+
|
| 498 |
+
End FoldProofs.
|
| 499 |
+
|
| 500 |
+
(* ---- the folded host with eight-bit words ------------------------------------------------------------------------ *)
|
| 501 |
+
Lemma fold_units_8 : N.of_nat (length (fold_units 8)) = 17086%N.
|
| 502 |
+
Proof. pose proof (fold_units_count 8 ltac:(lia)) as H. assert (SW 8 = 256) by reflexivity. lia. Qed.
|
| 503 |
+
|
| 504 |
+
Lemma fold_edges_8 : N.of_nat (nsum (length (fold_units 8)) (fun k => length (tin (nth k (fold_units 8) tu0)))) = 120508%N.
|
| 505 |
+
Proof. pose proof (fold_edges 8 ltac:(lia)) as H. assert (SW 8 = 256) by reflexivity. lia. Qed.
|
rocq/Schedule.v
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(* Lemma 8.1. A pass of records that read and write the window alone, held in the active bank and followed by empty
|
| 2 |
+
slots, runs them in order on the window. The records of a clocked netlist of units of at most two inputs, one for
|
| 3 |
+
each unit in the order of the netlist, each writing a cell that holds the unit's value until the last record that
|
| 4 |
+
reads it, and the record of each next value writing its state bit after every record that reads the bit, leave the
|
| 5 |
+
next state in the cells of the state bits after one pass. *)
|
| 6 |
+
From Stdlib Require Import List Bool Arith ZArith Lia.
|
| 7 |
+
Import ListNotations.
|
| 8 |
+
From TH Require Import TwoHead Net Abstract Indep Run View Stored WinRun StoredBoot.
|
| 9 |
+
|
| 10 |
+
(* ---- a pass of window records ------------------------------------------------------------------------------------ *)
|
| 11 |
+
Lemma wrec_empty : wrec EMPTY.
|
| 12 |
+
Proof. unfold wrec, EMPTY. auto. Qed.
|
| 13 |
+
|
| 14 |
+
Lemma rec_ok_empty : forall al, rec_ok al EMPTY.
|
| 15 |
+
Proof. intro al. pose proof (Nat.pow_nonzero 2 al ltac:(lia)). unfold rec_ok, EMPTY. lia. Qed.
|
| 16 |
+
|
| 17 |
+
Lemma wrun_empty : forall p w, wrun (repeat EMPTY p) w = w.
|
| 18 |
+
Proof. induction p as [|p IH]; intro w; [reflexivity|]. cbn [repeat wrun]. unfold wexec. cbn [ao_of EMPTY]. apply IH. Qed.
|
| 19 |
+
|
| 20 |
+
Lemma Forall_prefix : forall (T : Type) (P : T -> Prop) l j, Forall P l -> Forall P (firstn j l).
|
| 21 |
+
Proof. intros T P l j H. rewrite <- (firstn_skipn j l) in H. apply Forall_app in H. exact (proj1 H). Qed.
|
| 22 |
+
|
| 23 |
+
Section Pass.
|
| 24 |
+
Variables (al K S0 L : nat) (s0 : st) (rs : list rec).
|
| 25 |
+
Hypotheses (Hal : 4 <= al) (HK : 2 <= K) (HS : 1 <= S0) (HL : 1 <= L) (Hfit : fits al K S0 L s0)
|
| 26 |
+
(Hbank : bq (nth (kap s0) (banks s0) bank0) = encA al (rs ++ repeat EMPTY (S0 - length rs)))
|
| 27 |
+
(Hslot : bs (nth (kap s0) (banks s0) bank0) = 0) (Hlen : length rs <= S0)
|
| 28 |
+
(Hok : Forall (rec_ok al) rs) (Hw : Forall wrec rs) (Hq : reqclear (win s0)).
|
| 29 |
+
|
| 30 |
+
Let pad : list rec := rs ++ repeat EMPTY (S0 - length rs).
|
| 31 |
+
|
| 32 |
+
Lemma pad_len : length pad = S0.
|
| 33 |
+
Proof. unfold pad. rewrite length_app, repeat_length. lia. Qed.
|
| 34 |
+
|
| 35 |
+
Lemma pad_wrec : Forall wrec pad.
|
| 36 |
+
Proof.
|
| 37 |
+
unfold pad. apply Forall_app. split; [exact Hw|]. apply Forall_forall. intros r Hr. apply repeat_spec in Hr. subst r.
|
| 38 |
+
exact wrec_empty.
|
| 39 |
+
Qed.
|
| 40 |
+
|
| 41 |
+
(* the S0 steps of a pass are the records of the bank run in order on the window; the heads and the bank index stay *)
|
| 42 |
+
Theorem pass_run :
|
| 43 |
+
View.mv al K S0 L s0 S0 (itern al K S0 L S0 s0)
|
| 44 |
+
(mkV (wrun rs (win s0)) (vr (view0 al K s0)) (va (view0 al K s0)) (vc (view0 al K s0)) false).
|
| 45 |
+
Proof.
|
| 46 |
+
assert (Hq0 : reqclear (vw (view0 al K s0))) by exact Hq.
|
| 47 |
+
assert (Hok' : Forall (rec_ok al) pad).
|
| 48 |
+
{ unfold pad. apply Forall_app. split; [exact Hok|]. apply Forall_forall. intros r Hr. apply repeat_spec in Hr.
|
| 49 |
+
subst r. apply rec_ok_empty. }
|
| 50 |
+
assert (Hho : forall j, 1 <= j < length pad -> vho (vrun (S0 * recw al) L (firstn j pad) (view0 al K s0)) = false).
|
| 51 |
+
{ intros j _. rewrite (vrun_wrun _ _ _ _ (Forall_prefix _ _ _ j pad_wrec) Hq0). reflexivity. }
|
| 52 |
+
pose proof (seg_run al K S0 L s0 Hal HK HS HL Hfit pad [] ltac:(rewrite app_nil_r; exact Hbank) Hslot
|
| 53 |
+
ltac:(rewrite pad_len; lia) Hok' Hho S0 ltac:(rewrite pad_len; lia)) as M.
|
| 54 |
+
rewrite firstn_all2 in M by (rewrite pad_len; lia).
|
| 55 |
+
rewrite (vrun_wrun _ _ _ _ pad_wrec Hq0) in M. unfold pad in M. rewrite wrun_app, wrun_empty in M. exact M.
|
| 56 |
+
Qed.
|
| 57 |
+
|
| 58 |
+
End Pass.
|
| 59 |
+
|
| 60 |
+
(* ---- the records of a netlist ----------------------------------------------------------------------------------- *)
|
| 61 |
+
Section Sched.
|
| 62 |
+
(* the n state bits in the cells sc i, unit k writing cell oc k *)
|
| 63 |
+
Variables (n : nat) (us : list tu) (sc oc : nat -> nat).
|
| 64 |
+
|
| 65 |
+
(* the cell of a signal: a state bit has its own, a unit's value is in the cell its record writes *)
|
| 66 |
+
Definition scell (p : nat) : nat := if p <? n then sc p else oc (p - n).
|
| 67 |
+
|
| 68 |
+
(* the record of unit k: its inputs by their cells, the empty places reading the sink with weight 0 *)
|
| 69 |
+
Definition rec_of (k : nat) (u : tu) : rec :=
|
| 70 |
+
match tin u with
|
| 71 |
+
| [] => Rec SINK 0 SINK 0 (Net.tb u) (oc k)
|
| 72 |
+
| [(p, z)] => Rec (scell p) z SINK 0 (Net.tb u) (oc k)
|
| 73 |
+
| (p0, z0) :: (p1, z1) :: _ => Rec (scell p0) z0 (scell p1) z1 (Net.tb u) (oc k)
|
| 74 |
+
end.
|
| 75 |
+
|
| 76 |
+
Definition net_recs : list rec := map (fun k => rec_of k (nth k us tu0)) (seq 0 (length us)).
|
| 77 |
+
|
| 78 |
+
(* the last of the first m records that writes cell c *)
|
| 79 |
+
Fixpoint lastw (m c : nat) : option nat :=
|
| 80 |
+
match m with O => None | S m' => if Nat.eqb (oc m') c then Some m' else lastw m' c end.
|
| 81 |
+
|
| 82 |
+
Variable w0 : list bool.
|
| 83 |
+
Hypotheses
|
| 84 |
+
(Hrb : forall k, k < length us -> reads_below (nth k us tu0) (n + k))
|
| 85 |
+
(Hsc : forall i, i < n -> HO < sc i < length w0)
|
| 86 |
+
(Hoc : forall k, k < length us -> HO < oc k < length w0).
|
| 87 |
+
|
| 88 |
+
(* the state the window holds, and the values of the netlist on it *)
|
| 89 |
+
Definition x0 : list bool := map (fun i => wget w0 (sc i)) (seq 0 n).
|
| 90 |
+
Definition E0 : nat -> bool := run us n (fun i => nth i x0 false).
|
| 91 |
+
|
| 92 |
+
(* the records read and write the window alone *)
|
| 93 |
+
Theorem net_recs_wrec : Forall wrec net_recs.
|
| 94 |
+
Proof.
|
| 95 |
+
apply Forall_forall. intros r Hr. unfold net_recs in Hr. apply in_map_iff in Hr as (k & <- & Hk). apply in_seq in Hk.
|
| 96 |
+
assert (Hc : forall p, p < n + k -> CPY < scell p).
|
| 97 |
+
{ intros p Hp. unfold scell. destruct (Nat.ltb_spec p n); [pose proof (Hsc p ltac:(lia)) | pose proof (Hoc (p - n) ltac:(lia))];
|
| 98 |
+
unfold CPY, HO in *; lia. }
|
| 99 |
+
pose proof (Hoc k ltac:(lia)) as Ho. pose proof (Hrb k ltac:(lia)) as Hb.
|
| 100 |
+
unfold rec_of. destruct (tin (nth k us tu0)) as [|[p0 z0] [|[p1 z1] t]] eqn:Et; unfold wrec.
|
| 101 |
+
- split; [auto|]. split; [auto | right; lia].
|
| 102 |
+
- split; [right; right; apply Hc; apply (Hb p0 z0); rewrite Et; left; reflexivity|]. split; [auto | right; lia].
|
| 103 |
+
- split; [right; right; apply Hc; apply (Hb p0 z0); rewrite Et; left; reflexivity|].
|
| 104 |
+
split; [right; right; apply Hc; apply (Hb p1 z1); rewrite Et; right; left; reflexivity | right; lia].
|
| 105 |
+
Qed.
|
| 106 |
+
|
| 107 |
+
(* they fit the code of the records when the weights are 1 and -1, the biases lie in [-8, 7] and the cells in 2^al *)
|
| 108 |
+
Theorem net_recs_ok : forall al, length w0 = 2 ^ al ->
|
| 109 |
+
(forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> z = 1%Z \/ z = (-1)%Z) ->
|
| 110 |
+
(forall k, k < length us -> (-8 <= Net.tb (nth k us tu0) <= 7)%Z) -> Forall (rec_ok al) net_recs.
|
| 111 |
+
Proof.
|
| 112 |
+
intros al HW Hz Hbias. apply Forall_forall. intros r Hr. unfold net_recs in Hr.
|
| 113 |
+
apply in_map_iff in Hr as (k & <- & Hk). apply in_seq in Hk.
|
| 114 |
+
assert (Hc : forall p, p < n + k -> scell p < 2 ^ al).
|
| 115 |
+
{ intros p Hp. unfold scell. destruct (Nat.ltb_spec p n); [pose proof (Hsc p ltac:(lia)) | pose proof (Hoc (p - n) ltac:(lia))];
|
| 116 |
+
lia. }
|
| 117 |
+
pose proof (Hoc k ltac:(lia)) as Ho. pose proof (Hrb k ltac:(lia)) as Hb. pose proof (Hbias k ltac:(lia)) as Hbs.
|
| 118 |
+
pose proof (Nat.pow_nonzero 2 al ltac:(lia)) as Hp2.
|
| 119 |
+
unfold rec_of. destruct (tin (nth k us tu0)) as [|[p0 z0] [|[p1 z1] t]] eqn:Et; unfold rec_ok, SINK.
|
| 120 |
+
- lia.
|
| 121 |
+
- assert (H0 : In (p0, z0) (tin (nth k us tu0))) by (rewrite Et; left; reflexivity).
|
| 122 |
+
pose proof (Hz k p0 z0 ltac:(lia) H0). pose proof (Hc p0 (Hb p0 z0 H0)). lia.
|
| 123 |
+
- assert (H0 : In (p0, z0) (tin (nth k us tu0))) by (rewrite Et; left; reflexivity).
|
| 124 |
+
assert (H1 : In (p1, z1) (tin (nth k us tu0))) by (rewrite Et; right; left; reflexivity).
|
| 125 |
+
pose proof (Hz k p0 z0 ltac:(lia) H0). pose proof (Hz k p1 z1 ltac:(lia) H1).
|
| 126 |
+
pose proof (Hc p0 (Hb p0 z0 H0)). pose proof (Hc p1 (Hb p1 z1 H1)). lia.
|
| 127 |
+
Qed.
|
| 128 |
+
|
| 129 |
+
Hypotheses
|
| 130 |
+
(Hfan : forall k, k < length us -> length (tin (nth k us tu0)) <= 2)
|
| 131 |
+
(* the cell of a unit's value holds it until every record that reads it *)
|
| 132 |
+
(Hunit : forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> n <= p -> lastw k (oc (p - n)) = Some (p - n))
|
| 133 |
+
(* the cell of a state bit is not written before a record that reads the bit *)
|
| 134 |
+
(Hbit : forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> p < n -> lastw k (sc p) = None).
|
| 135 |
+
|
| 136 |
+
Lemma wval_rec : forall k u w, length (tin u) <= 2 -> (forall p z, In (p, z) (tin u) -> wcell w (scell p) = E0 p) ->
|
| 137 |
+
wval w (rec_of k u) = fire u E0.
|
| 138 |
+
Proof.
|
| 139 |
+
intros k u w Hl H. unfold rec_of, fire. destruct (tin u) as [|[p0 z0] [|[p1 z1] t]] eqn:Et; cbn [length] in Hl.
|
| 140 |
+
- cbn [wval wsum]. f_equal. lia.
|
| 141 |
+
- cbn [wval wsum]. rewrite (H p0 z0 (or_introl eq_refl)). f_equal. lia.
|
| 142 |
+
- destruct t as [|? ?]; [|cbn [length] in Hl; lia]. cbn [wval wsum].
|
| 143 |
+
rewrite (H p0 z0 (or_introl eq_refl)), (H p1 z1 (or_intror (or_introl eq_refl))). f_equal. lia.
|
| 144 |
+
Qed.
|
| 145 |
+
|
| 146 |
+
Lemma net_recs_nth : forall k, k < length us -> nth_error net_recs k = Some (rec_of k (nth k us tu0)).
|
| 147 |
+
Proof.
|
| 148 |
+
intros k Hk. unfold net_recs. rewrite nth_error_map, nth_error_seq.
|
| 149 |
+
destruct (Nat.ltb_spec k (length us)); [reflexivity | lia].
|
| 150 |
+
Qed.
|
| 151 |
+
|
| 152 |
+
(* after the first m records every cell holds the value of the last record that wrote it, or its first value *)
|
| 153 |
+
Lemma sched_inv : forall m, m <= length us -> forall c,
|
| 154 |
+
wget (wrun (firstn m net_recs) w0) c = match lastw m c with Some k => E0 (n + k) | None => wget w0 c end.
|
| 155 |
+
Proof.
|
| 156 |
+
induction m as [|m IH]; intros Hm c; [reflexivity|].
|
| 157 |
+
rewrite (firstn_S_nth _ m _ (net_recs_nth m ltac:(lia))), wrun_app. cbn [wrun]. unfold wexec.
|
| 158 |
+
set (w := wrun (firstn m net_recs) w0).
|
| 159 |
+
assert (Hlw : length w = length w0) by apply length_wrun.
|
| 160 |
+
assert (Hao : ao_of (rec_of m (nth m us tu0)) = oc m) by (unfold rec_of; destruct (tin _) as [|[? ?] [|[? ?] ?]]; reflexivity).
|
| 161 |
+
rewrite Hao, wget_wnext by (pose proof (Hoc m ltac:(lia)); lia).
|
| 162 |
+
cbn [lastw]. rewrite (Nat.eqb_sym c (oc m)). destruct (Nat.eqb_spec (oc m) c) as [Ec|Ec]; [|apply IH; lia].
|
| 163 |
+
unfold E0. rewrite run_at by (lia || exact Hrb). apply wval_rec; [apply Hfan; lia|].
|
| 164 |
+
intros p z Hin. pose proof (Hrb m ltac:(lia) p z Hin) as Hp.
|
| 165 |
+
unfold scell, wcell. destruct (Nat.ltb_spec p n) as [Hpn|Hpn].
|
| 166 |
+
- pose proof (Hsc p Hpn) as Hs. replace (Nat.eqb (sc p) SINK) with false by (symmetry; apply Nat.eqb_neq; unfold SINK, HO in *; lia).
|
| 167 |
+
unfold w. rewrite (IH ltac:(lia)), (Hbit m p z ltac:(lia) Hin Hpn). unfold E0. rewrite run_prefix by exact Hpn.
|
| 168 |
+
unfold x0. rewrite (nth_map_seq _ (fun i => wget w0 (sc i)) n p false Hpn). reflexivity.
|
| 169 |
+
- pose proof (Hoc (p - n) ltac:(lia)) as Ho.
|
| 170 |
+
replace (Nat.eqb (oc (p - n)) SINK) with false by (symmetry; apply Nat.eqb_neq; unfold SINK, HO in *; lia).
|
| 171 |
+
unfold w. rewrite (IH ltac:(lia)), (Hunit m p z ltac:(lia) Hin Hpn). f_equal. lia.
|
| 172 |
+
Qed.
|
| 173 |
+
|
| 174 |
+
(* the cell of each state bit is written last by the unit of its next value *)
|
| 175 |
+
Variable nx : list nat.
|
| 176 |
+
Hypotheses (Hnx : length nx = n)
|
| 177 |
+
(Hnext : forall i, i < n -> exists k, nth i nx 0 = n + k /\ lastw (length us) (sc i) = Some k).
|
| 178 |
+
|
| 179 |
+
(* one run of the records leaves the next state of the netlist in the cells of the state bits *)
|
| 180 |
+
Theorem sched_run : forall i, i < n -> wget (wrun net_recs w0) (sc i) = nth i (netstep n us nx x0) false.
|
| 181 |
+
Proof.
|
| 182 |
+
intros i Hi. assert (Hl : length net_recs = length us) by (unfold net_recs; rewrite length_map, length_seq; reflexivity).
|
| 183 |
+
rewrite <- (firstn_all2 net_recs (le_n _)), Hl, (sched_inv (length us) (le_n _)).
|
| 184 |
+
destruct (Hnext i Hi) as (k & Ek & Lk). rewrite Lk.
|
| 185 |
+
unfold netstep. cbv zeta. rewrite (nth_map_d _ _ _ nx i false 0) by lia. rewrite Ek. reflexivity.
|
| 186 |
+
Qed.
|
| 187 |
+
|
| 188 |
+
End Sched.
|
| 189 |
+
|
| 190 |
+
(* ---- Lemma 8.1: one pass of the records of a netlist evaluates it ------------------------------------------------- *)
|
| 191 |
+
Theorem netlist_pass : forall al K S0 L s0 n us nx sc oc,
|
| 192 |
+
4 <= al -> 2 <= K -> 1 <= S0 -> 1 <= L -> fits al K S0 L s0 ->
|
| 193 |
+
let rs := net_recs n us sc oc in
|
| 194 |
+
bq (nth (kap s0) (banks s0) bank0) = encA al (rs ++ repeat EMPTY (S0 - length rs)) ->
|
| 195 |
+
bs (nth (kap s0) (banks s0) bank0) = 0 -> length us <= S0 -> reqclear (win s0) ->
|
| 196 |
+
(forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> z = 1%Z \/ z = (-1)%Z) ->
|
| 197 |
+
(forall k, k < length us -> (-8 <= Net.tb (nth k us tu0) <= 7)%Z) ->
|
| 198 |
+
(forall k, k < length us -> length (tin (nth k us tu0)) <= 2) ->
|
| 199 |
+
(forall k, k < length us -> reads_below (nth k us tu0) (n + k)) ->
|
| 200 |
+
(forall i, i < n -> HO < sc i < 2 ^ al) -> (forall k, k < length us -> HO < oc k < 2 ^ al) ->
|
| 201 |
+
(forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> n <= p -> lastw oc k (oc (p - n)) = Some (p - n)) ->
|
| 202 |
+
(forall k p z, k < length us -> In (p, z) (tin (nth k us tu0)) -> p < n -> lastw oc k (sc p) = None) ->
|
| 203 |
+
length nx = n -> (forall i, i < n -> exists k, nth i nx 0 = n + k /\ lastw oc (length us) (sc i) = Some k) ->
|
| 204 |
+
let s := itern al K S0 L S0 s0 in
|
| 205 |
+
(forall i, i < n -> wget (win s) (sc i) = nth i (netstep n us nx (x0 n sc (win s0))) false)
|
| 206 |
+
/\ View.mv al K S0 L s0 S0 s
|
| 207 |
+
(mkV (win s) (vr (view0 al K s0)) (va (view0 al K s0)) (vc (view0 al K s0)) false).
|
| 208 |
+
Proof.
|
| 209 |
+
intros al K S0 L s0 n us nx sc oc Hal HK HS HL Hfit rs Hbank Hslot Hlen Hq Hz Hbias Hfan Hrb Hsc Hoc Hunit Hbit
|
| 210 |
+
Hnx Hnext s.
|
| 211 |
+
assert (HW : length (win s0) = 2 ^ al) by (destruct Hfit; assumption).
|
| 212 |
+
assert (Hlr : length rs = length us) by (unfold rs, net_recs; rewrite length_map, length_seq; reflexivity).
|
| 213 |
+
rewrite <- HW in Hsc, Hoc.
|
| 214 |
+
pose proof (pass_run al K S0 L s0 rs Hal HK HS HL Hfit Hbank Hslot ltac:(lia)
|
| 215 |
+
(net_recs_ok n us sc oc (win s0) Hrb Hsc Hoc al HW Hz Hbias)
|
| 216 |
+
(net_recs_wrec n us sc oc (win s0) Hrb Hsc Hoc) Hq) as M.
|
| 217 |
+
fold s in M.
|
| 218 |
+
assert (Ew : win s = wrun rs (win s0)) by (destruct M as (_ & E & _); exact E).
|
| 219 |
+
split.
|
| 220 |
+
- intros i Hi. rewrite Ew. exact (sched_run n us sc oc (win s0) Hrb Hsc Hoc Hfan Hunit Hbit nx Hnx Hnext i Hi).
|
| 221 |
+
- rewrite Ew. exact M.
|
| 222 |
+
Qed.
|
rocq/_CoqProject
CHANGED
|
@@ -31,6 +31,7 @@ Lev.v
|
|
| 31 |
BlockLev.v
|
| 32 |
HostLev.v
|
| 33 |
HostCount.v
|
|
|
|
| 34 |
PhysLev.v
|
| 35 |
Margin.v
|
| 36 |
Erfc.v
|
|
@@ -59,6 +60,8 @@ StoredMain.v
|
|
| 59 |
StoredImage.v
|
| 60 |
StoredWidth.v
|
| 61 |
StoredCount.v
|
|
|
|
|
|
|
| 62 |
StoredFast.v
|
| 63 |
ExtrNat.v
|
| 64 |
ExtractStored.v
|
|
|
|
| 31 |
BlockLev.v
|
| 32 |
HostLev.v
|
| 33 |
HostCount.v
|
| 34 |
+
FoldHost.v
|
| 35 |
PhysLev.v
|
| 36 |
Margin.v
|
| 37 |
Erfc.v
|
|
|
|
| 60 |
StoredImage.v
|
| 61 |
StoredWidth.v
|
| 62 |
StoredCount.v
|
| 63 |
+
Compile.v
|
| 64 |
+
Schedule.v
|
| 65 |
StoredFast.v
|
| 66 |
ExtrNat.v
|
| 67 |
ExtractStored.v
|