BB(6) hunt
Machines / C2-552

1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB

C2-552local proof 19Kill claimedSkelet 1-like Class 2bbchallenge ↗Explorer

How we proved it halts

Replaying a binary counter until a digit runs out of fuel

Look at the tape each time the head reaches fresh tape on the right, and it reads as a binary counter, lowest digit on the right. Digits are fenced off by walls, runs of equal cells (usually 11). Inside each digit sit a bit marker (00 for 0, 1111 for 1), sometimes a few spare walls, and a final alternating stretch whose length is the digit's fuel. Each trip adds 1: the carry runs left past every 1 digit to the first 0, and every digit it touches burns fuel.

The key idea: spare walls are spare lives. A digit with a spare wall that runs out of fuel hands that wall to the fence on its right and takes the gap before it as new fuel; the wall later moves into the next digit. So walls drift toward the head, and a digit with no spare wall survives only if walls reach it in time. Between such events everything changes at a steady rate, so long runs of increments can be done in one batch by a formula.

Why it halts: from step 342, a checker replays the run in 107,781 moves, about half of them batches. In increment 11,631,266,794,472,450,654,093 (about 1.16 × 10^22), a carry reaches a digit with no spare wall, bit 0 and no fuel, and the machine hits its one missing instruction. Adding up every move's cost gives a 45-digit step count, about 1.77 × 10^44: exactly 176,522,930,997,643,289,094,015,905,898,381,767,890,130,463.

In Rocq (busycoq), every carry rule and batch formula is a proved lemma, and the checker, proved correct once, runs to the halt, re-checking each proposed batch. The step count is not part of that proof; its per-move costs match direct simulation over the first 10^11 steps.

#19local proof number
1,142lines of Rocq
70 sto compile
6/6automatic checks
space-time diagram, first 10,000 steps from blank
The first 10,000 steps from a blank tape. Time runs down; white is 1.
About this picture

The standard picture (bbchallenge.org's Default view): each row is the whole tape at one step, time runs downward, and the head's path draws the pattern.

bbchallenge-defaultStart blankRows steps 0 → 10,000, top to bottomWindow cells −200..199, left to rightColors 1 0 or unvisited

Overview

In one sentence

Fueled-unit binary counter, rules closed (27,813/27,813 to 1e9); halting = a k=1 unit losing the fuel race.

Submitted mechanism At each right record the tape is a binary counter of units [x, M, m_1, Q_1, …, y] cut by 11 walls. The lead M (00 or 1111) is the bit, the Q are passive walls, and the last gap y is fuel that every carry burns. (submission/README.md, Mechanism)

Upstream
Kill claimed · PR #18merged 2026-10-14 06:20 UTC by ccz181078 · Sk1Class2_v4.v · TM12 · on Submissions →
Rocq proof
check_kill PASS · first Oct 12 20:38
1,142 lines · 64 KB .v · compile 70.0 s · coqchk pass · 1 axioms · PASS Oct 12 20:38 (re-run Oct 13 10:33)
· the .v file
Automatic review
6 of 6 checks passtemplate: verify/Sk1Machines.v (adapted from) · details in Proof →
Class
Skelet 1-like Class 2ours: sheet Skelet 1-like Class 2 ≠ ours multi-level binary counter: #11-style carry M over fueled units, walls migrate unit to unit, edge fossils = Pascal rows · med confidence
On the list
not on BB6_holdouts_663.txt (line 552 of the previous list) · historical 740 line 552 · observe.json rank #552
eqv ×1sim 1e15
Your calls on file 1
funded
option: class2_closeout · date: 2026-10-12

Mechanism

What to check here: the pictures show the mechanism that the rule table describes.

How it works: 3 notes
  • Wall view: 1-blocks of length 3g+2 (11, 1^5, ...) are unit boundaries with g glued walls; 3j+1 (1111, 1^7, ...) are passive stacks; units are x M m Q .. y (lead M = 00/1111 is the bit, y = fuel); the leftmost block is the edge. Carry M: leads 1111->00 up to the first 00->1111, every touch burns fuel.
  • Markers flow right: a passive wall that reaches the boundary glues, then becomes the next unit's lead (unglue S) while that unit's old lead turns passive. The edge grows by 3 per overflow and fossilizes into passive stacks that seed the Pascal rows; resets turn the tail into a new LSB unit.
  • Halts iff F reads a 1 after 00: only a single-marker unit running dry does that. Its margin y-(2T-bit) is constant between resets; non-halting needs the reset ratio a_{n+1}/a_n < 2 (observed 1.79-1.86). No halt to 1e11 (direct) or in 3M more macro increments.

Figures for Checkpoint A

Fig 1 · bbchallenge Default view, 10,000 stepsviewer ↗

Orientation: the run as the site shows it. Note the slowly widening left zone and the drifting walls.

bbchallenge Default view, 10,000 steps
bbchallenge-defaultStart blankRows every step 0..9,999Window cells -200..199, 1 px = 1 cellColors 1 0 or unvisited head (last move right/left)
Rows: squeezed into 500 px by the site's bilinear filter (about one sample per 20 steps)
Fig 2 · Carries on a built unit tapeQ1

Each leftward diagonal is one increment; its depth is the carry length. Compare the depths of successive sweeps.

Carries on a built unit tape
bbchallenge-defaultStart constructed tape (below)Rows every 4 stepsWindow cells -211..41, 1 px = 0.5 cellsColors 1 0 or unvisited head (last move right/left)
Start: 0∞ 17 0 14 0 1 0 12 0 1 0 1 0 1 0 1 02 1 0 1 0 1 0 1 0 1 0 1 0 14 0 1 0 1 0 1 0 1 0 12 0 1 0 1 0 1 0 1 0 14 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 12 0 1 0 1 0 1 02 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 12 0 1 0 14 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 12 0 A> 0∞ · Rows: 0..5,100 (1,276 rows, 2 px each) · Window: (each cell 2x2 px); cell 0 = the head's start cell
Fig 3 · Edge records to 300,000 stepsQ2viewer ↗

White diagonals are 1111 markers drifting right as x grows; the vertical stripes at the left are the fossil zone.

Edge records to 300,000 steps
bbchallenge-defaultStart blankRows left/right recordsWindow cells -36..980, 1 px = 1 cellColors 1 0 or unvisited head (last move right/left)
Rows: the start, then one row per new leftmost or rightmost cell (1,017 rows to step 300,000; not evenly spaced in time)
More figures (1)Fig 4: Left records to 3 billion steps
Fig 4 · Left records to 3 billion steps

One row per carry reaching the far left (676 rows), tape mid-sweep. Watch the slow drift of wall bands.

Left records to 3 billion steps
bbchallenge-defaultStart blankRows left records onlyWindow cells -699..2300, 1 px = 1 cellColors 1 0 or unvisited head (last move right/left)
Rows: the start, then one row per new leftmost cell (677 rows to step 3,000,000,000; not evenly spaced in time) · Window: the tape continues to the right, to cell ~91,000
Rules (2/2 validated)exact tape rewrites the proof will formalize, each re-checked by simulation
rulefrom ⟶ tocasesstepschecked
M carry (wall view)
... 11 [x 00 m P .. y] {11 [x_i 1111 m_i P .. y_i]}_i 11 t A>
⟶ ... 11 [x-1 1111 m+1 P .. y-2] {11 [x_i+3 00 m_i+1 P .. y_i-2]}_i 11 (t+2) A> (k=1 units: no m, y-1)
carry stops at the first unit with lead 00; units left of it and the prefix untouched2t + sum_passed (20 + 16(k-1) + 2(x+sum m+y)) + (16 + 16(k-1) + 2(sum m + y))✓30033/30033
Closed unit rules (stage 2)
E U_0 b_1 U_1 ... b_N U_N b_T [t] A>
⟶ one increment: tail t+2; per unit from the right: M pass / S unglue (boundary 13g+2) / leadless +2 / M stop; edge e+=3 or fossilize (e = 1 mod 3) or absorb b_1; glue G when a last gap hits -1; reset R in two increments
see notes.md stage 2 table; executable spec work/rules3.pynot modelled (the macro step count is not needed for the non-halting argument)✓28413/28413
Compressed historythe tape as reset: ... 11 x M (a-1) 11 1 1111 (2a-1) 11 1 A> 0∞ at 17 moments: where the rules are read off
reset: ... 11 x M (a-1) 11 1 1111 (2a-1) 11 1 A> 0∞
stepalo
5372-10
8844-11
1,6657-14
3,13211-17
5,84117-19
11,63828-22
26,35550-25
70,21093-29
211,425173-34
677,044317-42
2,195,541574-51
7,122,9721,036-68
23,158,3431,875-95
75,751,0783,407-143
249,431,0216,205-228
824,902,77411,304-381
2,732,037,81520,577-658
alast 20,577
20,57725372.7e9log xstep 537: a = 2step 884: a = 4step 1665: a = 7step 3132: a = 11step 5841: a = 17step 11638: a = 28step 26355: a = 50step 70210: a = 93step 211425: a = 173step 677044: a = 317step 2195541: a = 574step 7122972: a = 1036step 23158343: a = 1875step 75751078: a = 3407step 249431021: a = 6205step 824902774: a = 11304step 2732037815: a = 20577
lolast -658
-10-6585372.7e9log xstep 537: lo = 10step 884: lo = 11step 1665: lo = 14step 3132: lo = 17step 5841: lo = 19step 11638: lo = 22step 26355: lo = 25step 70210: lo = 29step 211425: lo = 34step 677044: lo = 42step 2195541: lo = 51step 7122972: lo = 68step 23158343: lo = 95step 75751078: lo = 143step 249431021: lo = 228step 824902774: lo = 381step 2732037815: lo = 658
Template comparisonSBCv6.v TM21: partly applies · the nearest solved proof, what carries over, and the transitions that differ
01
A1RB0RD
B1LC0RA
C---1RD
D1RA1LE
E1RC0LF
F1LE0LB
file
SBCv6.v:3702
module
TM21 (via our kill #11)
machine
1RB0LE_1RC0RC_1LD0RB_1LA0LE_1LD1LF_1LD--- (11 transitions apart)
diff
no close table; architecture only
note
Level 0 is #11's per-carry M (one macro step per carry, every touch burns fuel). There is no global re-pairing O: new LSB units enter at the right, old units fossilize at the left into an unbounded Pascal-triangle zone (depth ~ log t). #3's down-counter with ghost-phase J does not fit (this counter increments).
Proof strategy & riskshow the formal proof will go · 3 risks to watch

Stage 3: an invariant for the k=1 fuel race (margin y-(2T-bit) >= 0 for every episode), closed under all rules and tested on the macro simulator. Needs a bound on the reset ratio a_{n+1}/a_n < 2, set by the Pascal-structured arrival schedule from U_0/U_1.

  • ▲The invariant must control future fuel-race episodes, whose start depends on the arrival schedule from an unbounded Pascal-structured fossil zone: far beyond #11's INV.
  • ▲The reset ratio a_{n+1}/a_n oscillates slowly (1.79-1.86 observed) with no closed form; a proof needs a uniform bound below 2.
  • ▲Rules are validated, not proved: the macro step uses shift rules over alternating stretches that a Coq proof would have to establish one by one.
Stats & provenance1011 steps simulated · 556,565 cells · the status in full · files
simulated
1011 steps
tape
556,565 cells · 283,762 nonzeros
growth
span ~ t^0.5 to the right; left edge +1 per far-left carry (-676 at 3e9, -3,671 at 1e11); walls ~ log t
status now
check_kill --halt PASS, independently re-verified (status.json, 2026-10-13)
observer's note
Rule closure done (Class 2 close-out stage 2): 27,813/27,813 increments from step 342 to 1e9; invariant (k=1 fuel race) open.
files
observe.json · notes.md · proof.md · how_proved.md · status.json · 1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v

Proof & checks

6/6 automatic checks pass

Kill 19 · Skelet 1-like Class 2 · the kill file 1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v: 1142 lines, 234 items · the package submission/

✓ 6/6 automatic checks pass · Checkpoint B: no note from Dennis yet · template (adapted from): verify/Sk1Machines.v · 5% of our lines identical
1What is provedCheck: the string, the theorem and every check_kill line are green, and the .v on disk is the one that was checked (same sha256).
Machine
1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB
vs holdout list
✓ byte-exact: the .v literal (L37) == 2026-10-07_778.txt line 587 (41 bytes, via tools/holdouts.py)
Theorem
✓ Lemma halt: halts tm c0. L1117
check_kill
✓ PASS · 17/17 checks pass · compile 69.98 s · coqchk pass (536.46 s) · assumptions: 1 (Axioms|FunctionalExtensionality.functional_extensionality_dep : forall (A : Type) (B : A -> Type) (f g : forall x : A, B x), (forall x : A, f x = g x) -> f = g) · 2026-10-13 17:33:35 UTC · submission/check_kill.txt
Checked .v
sha256 198b30225e7ccff8…
✓1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v198b30225e7ccff8… = checked
✓submission/1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v198b30225e7ccff8… = checked
Status
✓Killed: halts updated 2026-10-13
✓ args✓ input✓ framework✓ framework_build✓ forbidden✓ structure✓ tm_text✓ theorem_text✓ coq✓ names✓ compile✓ tm_rocq✓ theorem_rocq✓ isolation✓ assumptions✓ coqchk✓ integrity
All 17 check_kill checks with their one-line results
✓args6x2 machine, framework module Individual62, mode halt
✓input65774 bytes, 1142 lines, 1452 sentences
✓frameworkHEAD 0940bb9cf434ba68f0c025dabfde45a219999973 == pin; no tracked changes under verify/
✓framework_build14 needed framework .vo files present and fresh, with native code no older than the .vo
✓forbiddennone of 30 forbidden patterns occur (ground rule 1's words: anywhere; command words: outside comments and strings; comments never split a token)
✓structure10 Require name(s) allowed; no top-level Variable/Context; no shadowing; Module/Section balanced
✓tm_textline 37: TM_from_str "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB" == <tm> (41 bytes)
✓theorem_textline 1117: halt : halts tm c0
✓coqcoqc 8.20.1 (<opam-switch>/bin/coqc)
✓nameshalts, c0, TM_from_str resolved inside Individual62
✓compilecompiled in 70.0s with all appended checks
✓tm_rocqBB6Kill.Candidate.tm = BusyCoq.Individual62.TM_from_str "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB" by eq_refl (in-file and isolated)
✓theorem_rocqhalt : halts (TM_from_str "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB") c0 with absolute names (in-file and isolated)
✓isolationonly stock proof plugins loaded; guard/positivity/universe checking on, definitional UIP off
✓assumptions1 assumption(s), all in the baseline
✓coqchkcoqchk -norec BB6Kill.Candidate ok (536.5s); its context summary lists nothing of the file's own
✓integrityinput sha256 and framework HEAD/cleanliness identical before and after
2Where it came fromCheck: the template is the one you expect, and the measured reuse (tiles, the reuse figure, diff) agrees with what the README says was kept and changed (quoted).
5%of our lines identical to the template
1changed lines
1000added lines (ours only)
1849template lines dropped
0 / 11 / 223items identical / adapted / new
What the package README says it reused and changed (submission/README.md line 20, Template), quoted:

verify/Sk1Machines.v, Module TM91 (a halting Skelet 1 machine) with Module Sk1Auto: a checker iterated by Eqb.N_iter_until and proved sound once (check_spec), with untrusted proposals certified at each use.

  • Kept: the checker architecture (one step function iterated by N_iter_until and proved sound with N_iter_until_spec: advance on run-length tapes there, next on unit records here), the call-segment calculus of verify/Individual.v (instantiated in verify/Individual62.v), and sideRLs_halt of verify/LongitudinalHalt.v.
  • Changed: the records are this machine's units (stack lists with binary-number gaps) instead of run-length tapes; the rules are unit-level lemmas rather than scans; closed-form batches replace bulk steps; and the run is split into 22 chunks so that coqchk finishes.
Fig P1 · Reuse of the template, line by line and by name

Top two bars: non-blank lines after the TM string is replaced by <TM> and whitespace is collapsed. Bottom bar: our Definitions/Lemmas/… by name.

ours 1058 lines
5% identical · 1 changed · 1000 added
template 1907 lines
3% kept verbatim · 1849 not in ours
our items 234
0 identical · 11 adapted · 223 new · 177 template-only
identicalchanged / adaptedours only (new)template only
Template part: whole file, lines 3–2043 (leading comment left out). Ours: lines 31–1142 (header comment 1–30 left out). Line diff: Python difflib SequenceMatcher; inside a replaced block, line pairs at least 75% alike count as changed, the rest as removed + added.

Template-only names: W, digit, word, take, give, carry, walls, prefix_rule, effect, total, total_spec, total_add, total_six, total_period, effectN, denote_effect, totalN, totalN_spec, cells, cell_word, batch, totalN_rule, batch_spec, scan, scan_valid, head, start, calls_spec, batch_root, total_seven, nil_power, t, push, push_spec, pop, pop_spec, remove, remove_spec, commute_power, skip_block …

Side-by-side diff: template (1907 lines) vs ours (1058 lines), 2850 lines differ; runs of identical lines and long template-only runs folded
identicalequal once each TM string is <TM>changedours onlytemplate only
templateours
3From BusyCoq Require Import Individual62 Helper LongitudinalHalt Eqb FastRev.32From BusyCoq Require Import Individual62 LongitudinalHalt Flip Eqb.
4Require Import ZifyNat Lia NArith PeanoNat String List.33Require Import ZifyNat Lia NArith PeanoNat String List.
5Import BusyCoq.Eqb.
6Open Scope sym_scope.34Open Scope sym_scope.
8Module Sk1Counter.
35Open Scope list.
9Definition W : list Sym := [1;1;1;1;0;1;1;1;1;1].
37Definition tm := Eval compute in (TM_from_str "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB").
10Inductive digit := D0 | D1 | D2 | D3 | D4 | D5.
38Definition tmf := Eval compute in (flip tm).
11Definition word p : list Sym :=
39Notation "c -->* c'" := (c -[ tmf ]->* c') (at level 40).
12 match p with
40Notation "c -->+ c'" := (c -[ tmf ]->+ c') (at level 40).
13 | D0 => [0;1] | D1 => [1;1;1;1]
42(** * Generic composition of one-call segments *)
14 | D2 => [0;1;1;1;1;1] | D3 => [1;1;1;1;1;1;1;1]
43Lemma segRR_app {t h1 h2 h3 w1 w2 m1 m2}:
15 | D4 => [0;1;1;1;1;1;1;1;1;1]
44 segRR t h1 h2 w1 m1 -> segRR t h2 h3 w2 m2 -> segRR t h1 h3 (w1 ++ w2) (m2 ++ m1).
16 | D5 => [1;1;1;1;1;1;1;1;1;1;1;1]
17 end.
⋯ 18 template-only lines (template 19–39), not in ours
40 forall k, segRLs tm (h^^t) (h^^u)
41 (W^^k ++ word p ++ W^^b) (W^^(k+a) ++ word q ++ W^^c).
42Proof.45Proof.
43 intros H k. rewrite lpow_add, <-app_assoc.
46 unfold segRR. intros H1 H2 l r. destruct h1 as [q1 v1], h2 as [q2 v2], h3 as [q3 v3].
44 eapply segRLs_concat; [apply walls|exact H].
47 rewrite Str_app_assoc. eapply evstep_trans. 1: apply H1.
48 cbn in *. rewrite Str_app_assoc. apply (H2 (Str_app m1 l) r).
45Qed.49Qed.
47Record effect := Eff { phase : digit; used : nat; given : nat; sent : nat }.
50Lemma segLL_app {t h1 h2 h3 w1 w2 o1 o2}:
48Fixpoint total (p:digit) (t:nat) : effect :=
51 segLL t h1 h2 w1 o1 -> segLL t h2 h3 w2 o2 -> segLL t h1 h3 (w1 ++ w2) (o2 ++ o1).
49 match t with
50 | O => Eff p 0 0 0
⋯ 5 template-only lines (template 51–56), not in ours
57 segRLs tm (h^^t) (h^^sent a) (word p ++ W^^(used a+n))
58 (W^^given a ++ word (phase a) ++ W^^n).
59Proof.52Proof.
60 gen p n. induction t; intros p n; cbn [total phase used given sent].
53 unfold segLL. intros H1 H2 l r. destruct h1 as [q1 v1], h2 as [q2 v2], h3 as [q3 v3].
61 - constructor.
54 cbn in *. rewrite Str_app_assoc. eapply evstep_trans. 1: apply (H1 (Str_app w2 l) r).
62 - cbn [lpow]. rewrite <-Nat.add_assoc.
55 rewrite Str_app_assoc. apply H2.
63 rewrite (lpow_add _ (carry p)).
64 eapply segRLs_trans.
65 + apply one.
66 + apply prefix_rule, IHt.
67Qed.56Qed.
68End Counter.
57Lemma segRR_RL_LL {t h1 h2 h3 h4 w1 w2 m w1' w2'}:
70Lemma total_add p t u :
58 segRR t h1 h2 w1 m -> segRL t h2 h3 w2 w2' -> segLL t h3 h4 m w1' ->
71 total p (t+u) =
59 segRL t h1 h4 (w1 ++ w2) (w1' ++ w2').
72 let a := total p t in let b := total (phase a) u in
73 Eff (phase b) (used a+used b) (given a+given b) (sent a+sent b).
74Proof.60Proof.
75 gen p. induction t; intros p; cbn [Nat.add total phase used given sent].
61 unfold segRR,segRL,segLL. intros H1 H2 H3 l r.
76 - destruct (total p u); reflexivity.
62 destruct h1 as [q1 v1], h2 as [q2 v2], h3 as [q3 v3], h4 as [q4 v4]. cbn in *.
77 - rewrite IHt. cbn. f_equal; lia.
63 rewrite Str_app_assoc. eapply evstep_progress_trans. 1: apply H1.
64 eapply progress_evstep_trans. 1: apply H2.
65 rewrite Str_app_assoc. apply H3.
78Qed.66Qed.
80Lemma total_six p : total p 6 = Eff p 2 3 1.
68(** * Words (all near-first; a unit word is root-first) *)
81Proof. destruct p; reflexivity. Qed.
69Definition stack j : list Sym := [1] ++ [1;1;1]^^j.
83Lemma total_period p k r :
70Definition blk m j : list Sym := [0] ++ [1;0]^^m ++ stack j.
84 total p (k*6+r) = let a := total p r in
71Definition bmid m j : list Sym := [0;1] ++ [0;1;1]^^j ++ [0;1]^^m.
85 Eff (phase a) (k*2+used a) (k*3+given a) (k+sent a).
72Definition lbw m j : list Sym := [0;1;1]^^j ++ [0;1]^^(S m).
73Definition xbmid x : list Sym := [0;0;1] ++ [0;1]^^x.
75(** * Block lemmas (found with solve_seg) *)
76Lemma blkRR_F m j: segRR tmf (F,[]) (F,[]) (blk m j) (bmid m j).
77Proof. unfold blk,bmid,stack. solve_seg. Qed.
78Lemma blkRR_B m j: segRR tmf (B,[]) (F,[]) (blk m j) (bmid m j).
79Proof. unfold blk,bmid,stack. solve_seg. Qed.
80Lemma blkLL m j: segLL tmf (D,[]) (D,[]) (lbw m j) (blk m j).
81Proof. unfold blk,lbw,stack. solve_seg. Qed.
82Lemma sweepLL: segLL tmf (D,[]) (D,[]) [0;1] [0;1].
83Proof. solve_seg. Qed.
84Lemma leadLL a: segLL tmf (A,[]) (D,[]) (bmid a 1) ([0;1]^^a ++ [0;0] ++ [1;0;1]).
85Proof. unfold bmid. solve_seg. Qed.
86Lemma xbRR x: segRR tmf (F,[]) (B,[]) ([0] ++ [1;0]^^x ++ [1;1]) (xbmid x).
87Proof. unfold xbmid. solve_seg. Qed.
88Lemma xbLL x: segLL tmf (D,[]) (A,[]) (xbmid x) ([0] ++ [1;0]^^x ++ [1;1]).
89Proof. unfold xbmid. solve_seg. Qed.
90Lemma leadstopS a x: segRL tmf (F,[]) (D,[]) ([0;1]^^(S a) ++ [0;0] ++ [1;0]^^(S x))
91 ([0] ++ [1;0]^^a ++ [1;1;1;1] ++ [0] ++ [1;0]^^x).
92Proof. solve_seg. Qed.
93Lemma leadstop0 x: segRL tmf (F,[]) (D,[]) ([0;0] ++ [1;0]^^(S x)) ([1;1;1] ++ [0] ++ [1;0]^^x).
94Proof. solve_seg. Qed.
95Lemma stop1 c a: segRL tmf (B,[]) (D,[]) ([0;1]^^(S c) ++ [0;0] ++ [1;0]^^(S a))
96 ([0] ++ [1;0]^^c ++ [1;1;1;1] ++ [0] ++ [1;0]^^a).
97Proof. solve_seg. Qed.
98Lemma edge0L x f: sideRL tmf (F,[]) (D,[]) (([0] ++ [1;0]^^(S x) ++ [1;1;1]^^f) *> const 0)
99 (([0] ++ [1;0]^^x ++ [1;1;1]^^(S f)) *> const 0).
100Proof. unfold sideRL. intros l. unfold to_DH_config. es. Qed.
101Lemma edge0E y f: sideRL tmf (B,[]) (D,[]) (([0] ++ [1;0]^^(S y) ++ [1;1;1]^^f) *> const 0)
102 (([0] ++ [1;0]^^y ++ [1;1;1]^^(S f)) *> const 0).
103Proof. unfold sideRL. intros l. unfold to_DH_config. es. Qed.
105(** * Chains of passive blocks *)
106Definition blkp (p:nat*nat) := blk (fst p) (snd p).
107Definition bmidp (p:nat*nat) := bmid (fst p) (snd p).
108Definition lbwp (p:nat*nat) := lbw (fst p) (snd p).
109Fixpoint cw (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => blkp p ++ cw ch end.
110Fixpoint cmid (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => cmid ch ++ bmidp p end.
111Fixpoint clbw (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => clbw ch ++ lbwp p end.
113Lemma chainRR ch: segRR tmf (F,[]) (F,[]) (cw ch) (cmid ch).
86Proof.114Proof.
87 induction k; [cbn [Nat.mul Nat.add]; destruct (total p r); reflexivity|].
115 induction ch as [|p ch IH]; cbn [cw cmid].
88 replace (S k*6+r) with (6+(k*6+r)) by lia.
116 - unfold segRR. intros. cbn. finish.
89 rewrite total_add,total_six. cbn [phase used given sent].
117 - exact (segRR_app (blkRR_F (fst p) (snd p)) IH).
90 rewrite IHk. cbn. f_equal; lia.
91Qed.118Qed.
93Record effectN := EffN { phaseN : digit; usedN : N; givenN : N; sentN : N }.
119Lemma chainLL ch: segLL tmf (D,[]) (D,[]) (clbw ch) (cw ch).
94Definition denote_effect a :=
95 Eff (phaseN a) (N.to_nat (usedN a)) (N.to_nat (givenN a)) (N.to_nat (sentN a)).
⋯ 4 template-only lines (template 96–99), not in ours
100 (k*3+N.of_nat (given a)) (k+N.of_nat (sent a)).
102Lemma totalN_spec p t : denote_effect (totalN p t) = total p (N.to_nat t).
103Proof.120Proof.
104 unfold totalN,denote_effect; cbn [phaseN usedN givenN sentN].
121 induction ch as [|p ch IH]; cbn [cw clbw].
105 rewrite !N2Nat.inj_add, !N2Nat.inj_mul, !Nat2N.id.
122 - unfold segLL. intros. cbn. finish.
106 replace (N.to_nat t) with (N.to_nat (t/6)*6+N.to_nat (t mod 6)).
123 - exact (segLL_app IH (blkLL (fst p) (snd p))).
107 - apply eq_sym, total_period.
108 - pose proof (N.div_mod t 6 ltac:(lia)). nia.
109Qed.124Qed.
111Definition cells := list (digit*N).
125Lemma bmid_shift m j: bmid m j ++ [0;1] = [0;1] ++ lbw m j.
112Fixpoint cell_word (xs:cells) : list Sym := match xs with
126Proof. unfold bmid,lbw. rewrite <-!app_assoc. f_equal. f_equal. rewrite lpow_shift. reflexivity. Qed.
113 | [] => []
127Lemma cmid_shift ch: cmid ch ++ [0;1] = [0;1] ++ clbw ch.
114 | (p,n)::xs => word p ++ W^^N.to_nat n ++ cell_word xs
128Proof.
115 end.
129 induction ch as [|p ch IH]; cbn [cmid clbw]; [reflexivity|].
117Fixpoint batch (t:N) (xs:cells) : option (N*cells) :=
130 unfold bmidp,lbwp. rewrite <-app_assoc, bmid_shift.
118 match xs with
131 rewrite (app_assoc (cmid ch) [0;1]), IH. rewrite <-app_assoc. reflexivity.
119 | [] => if (t=?0)%N then Some (0%N,[]) else None
132Qed.
120 | (p,n)::xs =>
133Lemma bmid_S m j: bmid (S m) j = [0;1] ++ lbw m j.
121 let a := totalN p t in
134Proof. rewrite <-bmid_shift. unfold bmid. cbn [lpow]. rewrite <-!app_assoc. f_equal. f_equal.
122 if (usedN a<=?n)%N then
135 rewrite lpow_shift. reflexivity. Qed.
123 match batch (sentN a) xs with
137(** prefix = Y block (entered in B) followed by a chain *)
124 | Some (e,ys) => Some (givenN a,(phaseN a,(n-usedN a+e)%N)::ys)
138Definition pw c j ch := blk c j ++ cw ch.
125 | None => None
139Lemma prefRR c j ch: segRR tmf (B,[]) (F,[]) (pw c j ch) (cmid ch ++ bmid c j).
126 end
140Proof. exact (segRR_app (blkRR_B c j) (chainRR ch)). Qed.
127 else None
141Lemma prefLL c j ch: segLL tmf (D,[]) (D,[]) (cmid ch ++ bmid (S c) j) (pw c j ch ++ [0;1]).
128 end.
142Proof.
130Section BatchCorrect.
143 rewrite bmid_S, (app_assoc (cmid ch) [0;1]), cmid_shift, <-app_assoc.
131Variable tm : TM.
144 unfold pw.
132Variable h : list (DH0*DH0).
145 refine (segLL_app sweepLL _).
133Hypothesis wall : forall n, segRLs tm h h (W^^n) (W^^n).
146 exact (segLL_app (chainLL ch) (blkLL c j)).
134Hypothesis one : forall p n,
147Qed.
135 segRLs tm h (h^^carry p) (word p ++ W^^(take p+n))
149(** * Frames *)
136 (W^^give p ++ word (next p) ++ W^^n).
150Lemma segRL_frame {t h1 h2 w w'} u: segRL t h1 h2 w w' -> segRL t h1 h2 (w ++ u) (w' ++ u).
138Lemma totalN_rule p t n :
151Proof. unfold segRL. intros H l r. rewrite !Str_app_assoc. apply H. Qed.
139 (usedN (totalN p t)<=n)%N ->
153(** * Digits. lead1 a x: m1 = 2a+1 cells, lead 1111, x = 2x+1 cells;
140 segRLs tm (h^^N.to_nat t) (h^^N.to_nat (sentN (totalN p t)))
154 lead0 a x: m1 = 2a cells, lead 00, x = 2x cells. For k=1 the "m1" gap is the fuel y. *)
141 (word p ++ W^^N.to_nat n)
155Definition lead1 a x : list Sym := blk a 1 ++ [0] ++ [1;0]^^x.
142 (W^^N.to_nat (givenN (totalN p t)) ++ word (phaseN (totalN p t)) ++
156Definition lead0 a x : list Sym := [0;1]^^a ++ [0;0] ++ [1;0]^^x.
143 W^^N.to_nat (n-usedN (totalN p t))).
157Definition tailw g : list Sym := [1;1] ++ [1;1;1]^^g.
159Definition hB : DH0 := (B,[]).
160Definition hD : DH0 := (D,[]).
161Definition h : list (DH0*DH0) := [(hB,hD)].
163Lemma stopK c j ch a x: segRL tmf hB hD (pw (S c) j ch ++ lead0 a (S x)) (pw c j ch ++ lead1 a x).
164Proof.
165 destruct a as [|a].
166 - pose proof (segRR_RL_LL (prefRR (S c) j ch) (leadstop0 x) (prefLL c j ch)) as H.
167 unfold lead0,lead1. applys_eq H. cbn. rewrite <-!app_assoc. reflexivity.
168 - pose proof (segRR_RL_LL (prefRR (S c) j ch) (leadstopS a x) (prefLL c j ch)) as H.
169 unfold lead0,lead1. applys_eq H. unfold blk,stack. cbn. rewrite <-!app_assoc. reflexivity.
170Qed.
172Lemma stopK1 c a: segRL tmf hB hD (lead0 (S c) (S a)) (lead1 c a).
173Proof. unfold lead0,lead1,blk,stack. solve_seg. Qed.
175Definition passK_mid c j ch a x := (xbmid x ++ bmid a 1) ++ (cmid ch ++ bmid (S c) j).
176Lemma passK_RR c j ch a x: segRR tmf hB hB (pw (S c) j ch ++ lead1 a x ++ [1;1]) (passK_mid c j ch a x).
177Proof.
178 unfold lead1, passK_mid. rewrite <-!app_assoc.
179 pose proof (segRR_app (prefRR (S c) j ch) (segRR_app (blkRR_F a 1) (xbRR x))) as H.
180 rewrite <-!app_assoc in H. exact H.
181Qed.
182Lemma passK_LL c j ch a x: segLL tmf hD hD (passK_mid c j ch a x) (pw c j ch ++ lead0 (S a) (S (S x)) ++ [1;1]).
183Proof.
184 unfold passK_mid.
185 pose proof (segLL_app (segLL_app (xbLL x) (leadLL a)) (prefLL c j ch)) as H.
186 applys_eq H. unfold lead0. cbn [lpow]. rewrite <-!app_assoc. cbn. reflexivity.
187Qed.
188Lemma passK c j ch a x: segRLs tmf h h (pw (S c) j ch ++ lead1 a x ++ [1;1]) (pw c j ch ++ lead0 (S a) (S (S x)) ++ [1;1]).
189Proof.
190 unfold h. applys_eq (segRLs_lrcons tmf [] [] [] _ _ _ _ _ hB hD hB hD
191 (passK_RR c j ch a x) (passK_LL c j ch a x) (segLRs_O _ _) (segRLs_O _ _)).
192Qed.
194Definition passK1_mid c x := xbmid x ++ bmid c 1.
195Lemma passK1_RR c x: segRR tmf hB hB (lead1 c x ++ [1;1]) (passK1_mid c x).
196Proof. unfold lead1,passK1_mid. rewrite <-!app_assoc. exact (segRR_app (blkRR_B c 1) (xbRR x)). Qed.
197Lemma passK1_LL c x: segLL tmf hD hD (passK1_mid c x) (lead0 c (S (S x)) ++ [1;1]).
198Proof.
199 unfold passK1_mid. pose proof (segLL_app (xbLL x) (leadLL c)) as H.
200 applys_eq H. unfold lead0. cbn [lpow]. rewrite <-!app_assoc. cbn. reflexivity.
201Qed.
202Lemma passK1 c x: segRLs tmf h h (lead1 c x ++ [1;1]) (lead0 c (S (S x)) ++ [1;1]).
203Proof.
204 unfold h. applys_eq (segRLs_lrcons tmf [] [] [] _ _ _ _ _ hB hD hB hD
205 (passK1_RR c x) (passK1_LL c x) (segLRs_O _ _) (segRLs_O _ _)).
206Qed.
208(** halting call: a k=1 digit with lead 00 and no fuel *)
209Lemma halt0 x l r: halts tmf (l {{B}}> lead0 0 x *> r).
210Proof. unfold lead0. cbn. solve_halt. Qed.
212(** * U0 (the unit next to the edge) and the edge 1^(3f) *)
213Lemma edge0L0 f: sideRL tmf (F,[]) (D,[]) (([0] ++ [1;1;1]^^f) *> const 0)
214 (([1;1] ++ [1;1;1]^^f) *> const 0).
215Proof. unfold sideRL. intros l. unfold to_DH_config. es. Qed.
216Lemma segRR_sideRL_LL {t h1 h2 h3 h4 w m w' r r'}:
217 segRR t h1 h2 w m -> sideRL t h2 h3 r r' -> segLL t h3 h4 m w' ->
218 sideRL t h1 h4 (w *> r) (w' *> r').
219Proof.
220 unfold segRR,sideRL,segLL. intros H1 H2 H3 l.
221 destruct h1 as [q1 v1], h2 as [q2 v2], h3 as [q3 v3], h4 as [q4 v4]. cbn in *.
222 eapply evstep_progress_trans. 1: apply H1.
223 eapply progress_evstep_trans. 1: apply H2.
224 apply H3.
225Qed.
226Definition edgew x f : list Sym := [0] ++ [1;0]^^x ++ [1;1;1]^^f.
227(** leadless U0: prefix, then the gap x (2x+1 cells), then the edge *)
228Lemma u0L c j ch x f: sideRL tmf hB hD ((pw (S c) j ch ++ edgew x f) *> const 0)
229 ((pw c j ch ++ edgew x (S f)) *> const 0).
230Proof.
231 rewrite !Str_app_assoc. destruct x as [|x].
232 - pose proof (segRR_sideRL_LL (prefRR (S c) j ch) (edge0L0 f) (prefLL c j ch)) as H.
233 applys_eq H. unfold edgew. rewrite <-!Str_app_assoc. f_equal. rewrite <-!app_assoc. reflexivity.
234 - pose proof (segRR_sideRL_LL (prefRR (S c) j ch) (edge0L x f) (prefLL c j ch)) as H.
235 applys_eq H. unfold edgew. rewrite <-!Str_app_assoc. f_equal. rewrite <-!app_assoc. reflexivity.
236Qed.
237(** empty U0 *)
238Lemma u0E y f: sideRL tmf hB hD (edgew (S y) f *> const 0) (edgew y (S f) *> const 0).
239Proof. unfold edgew. exact (edge0E y f). Qed.
241(** * The root: tail gap 2t+1 and the tail boundary 11 *)
242Definition root t (X:side) : Q * tape := const 0 <{{A}} ([0;1]^^t ++ [0;1;1]) *> X.
243Definition wmid t : list Sym := [0] ++ [0;1]^^t ++ [0;1;0;1].
244Lemma root_in t X: root t X -->* wmid t *> const 0 {{B}}> X.
245Proof. unfold root,wmid. es. Qed.
246Lemma sweepA: forall l r n, l <* [0;1]^^n <{{A}} r -->* l <{{A}} [0;1]^^n *> r.
247Proof. apply (shift_rule_L [] tmf [0;1] [0;1] A). intros. es. Qed.
248Lemma root_out t X: wmid t *> const 0 <{{D}} X -->* root (S t) X.
249Proof.
250 unfold root,wmid. simpl_tape. step. follow sweepA. do 4 step.
251 apply evstep_refl'. cbn [lpow app Str_app].
252 change (0 >> 1 >> 1 >> X) with ([0;1] *> 1 >> X). rewrite lpow_shift'. reflexivity.
253Qed.
254Lemma root_step t X X': sideRL tmf hB hD X X' -> root t X -->+ root (S t) X'.
144Proof.255Proof.
145 intros H.256 intros H.
146 pose proof (total_spec tm h wall one (N.to_nat t) p
257 eapply evstep_progress_trans. 1: apply root_in.
147 (N.to_nat (n-usedN (totalN p t)))) as I.
258 eapply progress_evstep_trans. 1: apply (H (wmid t *> const 0)).
148 rewrite <-totalN_spec in I. cbn [denote_effect phase used given sent] in I.
259 apply root_out.
149 applys_eq I; flia.
150Qed.260Qed.
152Lemma batch_spec t xs e ys :
261Lemma root_steps n: forall t X X', sideRLs tmf (h^^n) X X' -> root t X -->* root (n+t) X'.
153 batch t xs = Some (e,ys) ->
154 segRLs tm (h^^N.to_nat t) [] (cell_word xs)
155 (W^^N.to_nat e ++ cell_word ys).
156Proof.262Proof.
157 gen t e ys. induction xs as [|[p n] xs IH]; intros t e ys H; cbn [batch] in H.
263 induction n; intros t X X' H.
158 - destruct (N.eqb_spec t 0); inverts H. subst t. constructor.
264 - inverts H. finish.
159 - destruct (N.leb_spec (usedN (totalN p t)) n); try discriminate.
265 - cbn [lpow h app] in H. inverts H.
160 destruct (batch (sentN (totalN p t)) xs) as [[e' ys']|] eqn:E; inverts H.
266 eapply evstep_trans. 1: apply progress_evstep, root_step; eassumption.
161 specialize (IH _ _ _ E).
267 replace (S n + t) with (n + S t) by lia. apply IHn. assumption.
162 pose proof (totalN_rule p t n H0) as I.
163 change (segRLs tm (h^^N.to_nat t) [] (cell_word ((p,n)::xs))
⋯ 4 template-only lines (template 164–167), not in ours
168 repeat rewrite app_assoc.
169 applys_eq (segRLs_concat I IH); repeat rewrite app_assoc; reflexivity.
170Qed.268Qed.
171End BatchCorrect.
269Lemma root_halt t X: sideRLs_halt tmf h X -> halts tmf (root t X).
173Record scan := Scan { scan_q : Q; scan_dir : dir;
270Proof. intros H. eapply halts_evstep. 2: apply root_in. apply (sideRLs_halt_single _ _ _ _ H). Qed.
174 scan_in : list Sym; scan_out : list Sym; scan_context : list Sym }.
273(** * Uniform touch lemmas. A unit is [cw bs ++ leadw b a x ++ far]; every touch moves all
175Definition scan_valid tm s := forall n l r,
274 passive walls two cells toward the root, i.e. consumes the two root-most cells [0;1]. *)
176 match scan_dir s with
275Definition hF : DH0 := (F,[]).
177 | R =>
276Definition leadw (b:bool) a x := if b then lead1 a x else lead0 a x.
178 l <* (rev (scan_context s)) {{scan_q s}}> (scan_in s)^^n *> r -[tm]->*
277Definition uw bs b a x (far:list Sym) := cw bs ++ leadw b a x ++ far.
179 l <* (rev (scan_out s))^^n <* (rev (scan_context s)) {{scan_q s}}> r
278Definition consume (bs: list (nat*nat)) (a:nat) : option (nat * list (nat*nat) * nat) :=
180 | L =>
279 match bs with
181 l <* (rev (scan_in s))^^n <{{scan_q s}} (scan_context s) *> r -[tm]->*
280 | (S c, j) :: r => Some (O, (c,j)::r, a)
182 l <{{scan_q s}} (scan_context s) *> (scan_out s)^^n *> r
281 | (O, j) :: r => Some (j, r, a)
282 | [] => match a with S a' => Some (O, [], a') | O => None end
183 end.283 end.
185Definition head q : list (DH0*DH0) := [((q,<[1;0;1]),(q,[1]))].
284Lemma cw_app l1 l2: cw (l1 ++ l2) = cw l1 ++ cw l2.
186Definition start (q:Q) (r:side) := 0inf <* <[1;0;1] {{q}}> r.
285Proof. induction l1 as [|p l1 IH]; cbn; [reflexivity|]. rewrite IH, app_assoc. reflexivity. Qed.
188Section RootCorrect.
287Lemma yLL_glue j: segLL tmf (D,[]) (D,[]) ([0;1;1]^^j) ([1;1;1]^^j).
189Variable tm : TM.
288Proof. solve_seg. Qed.
190Variable q : Q.
289Lemma prefLL_glue j ch: segLL tmf (D,[]) (D,[]) (cmid ch ++ bmid 0 j) ([1;1;1]^^j ++ cw ch ++ [0;1]).
191Hypothesis emit : forall r,
192 0inf <{{q}} [1] *> r -[tm]->* start q r.
194Lemma calls_spec t r r' : sideRLs tm ((head q)^^t) r r' ->
195 start q r -[tm]->* start q r'.
196Proof.290Proof.
197 gen r r'. induction t; intros r r' H; cbn [lpow head app] in H.
291 unfold bmid. cbn [lpow]. rewrite app_nil_r.
198 - inverts H. constructor.
292 rewrite (app_assoc (cmid ch) [0;1]), cmid_shift, <-app_assoc.
199 - inverts H.
293 pose proof (segLL_app sweepLL (segLL_app (chainLL ch) (yLL_glue j))) as H.
200 match goal with
294 applys_eq H. rewrite <-!app_assoc. reflexivity.
201 | Hret : sideRL _ _ _ _ _ |- _ => follow100 Hret
295Qed.
297(** generic compositions: prefix out (B->F), a core entered in F, prefix back (D->D) *)
298Lemma gen_RL {ci co} (HF: segRL tmf hF hD ci co) c j ch:
299 segRL tmf hB hD (pw (S c) j ch ++ ci) (pw c j ch ++ [0;1] ++ co).
300Proof.
301 pose proof (segRR_RL_LL (prefRR (S c) j ch) HF (prefLL c j ch)) as H.
302 applys_eq H. rewrite <-!app_assoc. reflexivity.
303Qed.
304Lemma gen_RLg {ci co} (HF: segRL tmf hF hD ci co) j ch:
305 segRL tmf hB hD (pw 0 j ch ++ ci) ([1;1;1]^^j ++ cw ch ++ [0;1] ++ co).
306Proof.
307 pose proof (segRR_RL_LL (prefRR 0 j ch) HF (prefLL_glue j ch)) as H.
308 applys_eq H. rewrite <-!app_assoc. reflexivity.
309Qed.
310Lemma lrcons1 {w1 w2 m}: segRR tmf hB hB w1 m -> segLL tmf hD hD m w2 -> segRLs tmf h h w1 w2.
311Proof.
312 intros H1 H2. unfold h.
313 applys_eq (segRLs_lrcons tmf [] [] [] _ _ _ _ _ hB hD hB hD H1 H2 (segLRs_O _ _) (segRLs_O _ _)).
314Qed.
315Lemma gen_fwd {ci m co} (HR: segRR tmf hF hB ci m) (HL: segLL tmf hD hD m co) c j ch:
316 segRLs tmf h h (pw (S c) j ch ++ ci) (pw c j ch ++ [0;1] ++ co).
317Proof.
318 pose proof (lrcons1 (segRR_app (prefRR (S c) j ch) HR) (segLL_app HL (prefLL c j ch))) as H.
319 applys_eq H. rewrite <-!app_assoc. reflexivity.
320Qed.
321Lemma gen_fwdg {ci m co} (HR: segRR tmf hF hB ci m) (HL: segLL tmf hD hD m co) j ch:
322 segRLs tmf h h (pw 0 j ch ++ ci) ([1;1;1]^^j ++ cw ch ++ [0;1] ++ co).
323Proof.
324 pose proof (lrcons1 (segRR_app (prefRR 0 j ch) HR) (segLL_app HL (prefLL_glue j ch))) as H.
325 applys_eq H. rewrite <-!app_assoc. reflexivity.
326Qed.
327Lemma gen_side {ci co R R'} (HF: sideRL tmf hF hD (ci *> R) (co *> R')) c j ch:
328 sideRL tmf hB hD ((pw (S c) j ch ++ ci) *> R) ((pw c j ch ++ [0;1] ++ co) *> R').
329Proof.
330 pose proof (segRR_sideRL_LL (prefRR (S c) j ch) HF (prefLL c j ch)) as H.
331 applys_eq H; rewrite <-!Str_app_assoc; f_equal; rewrite <-!app_assoc; reflexivity.
332Qed.
333Lemma gen_sideg {ci co R R'} (HF: sideRL tmf hF hD (ci *> R) (co *> R')) j ch:
334 sideRL tmf hB hD ((pw 0 j ch ++ ci) *> R) (([1;1;1]^^j ++ cw ch ++ [0;1] ++ co) *> R').
335Proof.
336 pose proof (segRR_sideRL_LL (prefRR 0 j ch) HF (prefLL_glue j ch)) as H.
337 applys_eq H; rewrite <-!Str_app_assoc; f_equal; rewrite <-!app_assoc; reflexivity.
338Qed.
339Lemma segRL_side {t h1 h2 w w'} R: segRL t h1 h2 w w' -> sideRL t h1 h2 (w *> R) (w' *> R).
340Proof. unfold segRL,sideRL. intros H l. destruct h1 as [q1 v1], h2 as [q2 v2]. cbn. apply H. Qed.
342Ltac injE E := injection E; intros; subst; clear E.
343Ltac lnorm2 := unfold uw,leadw,pw; do 3 (rewrite ?cw_app; cbn [cw]); unfold blkp,lead0,lead1,blk,stack,tailw,edgew; cbn [fst snd lpow];
344 rewrite ?app_nil_r, ?app_nil_l; repeat rewrite <-app_assoc; cbn [app];
345 repeat (rewrite lpow_rotate_list; cbn [app]); try reflexivity.
347(** ** cores *)
348Lemma cstopF a x far: exists co, segRL tmf hF hD (lead0 a (S x) ++ far) co /\ [0;1] ++ co = lead1 a x ++ far.
349Proof.
350 destruct a as [|a].
351 - eexists. split. 1: exact (segRL_frame far (leadstop0 x)). lnorm2.
352 - eexists. split. 1: exact (segRL_frame far (leadstopS a x)). lnorm2.
353Qed.
354Lemma t_stop bs a x far ov bs' a': consume bs a = Some (ov, bs', a') ->
355 segRL tmf hB hD (uw bs false a (S x) far) ([1;1;1]^^ov ++ uw bs' true a' x far).
356Proof.
357 destruct (cstopF a x far) as [co [HF HE]].
358 destruct bs as [|[[|c] j] r]; cbn [consume]; intros E.
359 - destruct a as [|a]; [discriminate|]. injection E as E1 E2 E3; subst ov bs' a'.
360 pose proof (segRL_frame far (stopK1 a x)) as H. applys_eq H; lnorm2.
361 - injection E as E1 E2 E3; subst ov bs' a'. pose proof (gen_RLg HF j r) as H. rewrite HE in H. applys_eq H; lnorm2.
362 - injection E as E1 E2 E3; subst ov bs' a'. pose proof (gen_RL HF c j r) as H. rewrite HE in H. applys_eq H; lnorm2.
363Qed.
365Definition cpass_mid a x := xbmid x ++ bmid a 1.
366Lemma cpassRR a x: segRR tmf hF hB (lead1 a x ++ [1;1]) (cpass_mid a x).
367Proof. unfold lead1,cpass_mid. rewrite <-!app_assoc. exact (segRR_app (blkRR_F a 1) (xbRR x)). Qed.
368Definition cpass_co a x := ([0;1]^^a ++ [0;0] ++ [1;0;1]) ++ ([0] ++ [1;0]^^x ++ [1;1]).
369Lemma cpassLL a x: segLL tmf hD hD (cpass_mid a x) (cpass_co a x).
370Proof. unfold cpass_mid,cpass_co. exact (segLL_app (xbLL x) (leadLL a)). Qed.
371Lemma t_pass bs a x ov bs' a': consume bs (S a) = Some (ov, bs', a') ->
372 segRLs tmf h h (uw bs true a x (tailw 0)) ([1;1;1]^^ov ++ uw bs' false a' (S (S x)) (tailw 0)).
373Proof.
374 destruct bs as [|[[|c] j] r]; cbn [consume]; intros E; injection E as E1 E2 E3; subst ov bs' a'.
375 - pose proof (passK1 a x) as H. applys_eq H; lnorm2.
376 - pose proof (gen_fwdg (cpassRR a x) (cpassLL a x) j r) as H. applys_eq H; unfold cpass_co; lnorm2.
377 - pose proof (gen_fwd (cpassRR a x) (cpassLL a x) c j r) as H. applys_eq H; unfold cpass_co; lnorm2.
378Qed.
380(** ** unglue: the glued walls of the far neighbour come in; the first becomes a 00 lead *)
381Definition um1 a x : list Sym := [0;0;1;0;1;1;0;1;0;1] ++ [0;1]^^x ++ [1] ++ [0;1]^^a.
382Definition um2 a x g : list Sym := [0;0;1;0;1;1;0;1;1;0;1] ++ [1;0;1]^^g ++ [0;1] ++ [0;1]^^x ++ [1] ++ [0;1]^^a.
383Definition uco1 a x : list Sym := [0;1]^^a ++ [1;1;1;0;1;0] ++ [1;0]^^x ++ [0;1;0;1;1].
384Definition uco2 a x g : list Sym := [0;1]^^a ++ [1;1;1;0;1] ++ [0;1]^^x ++ [1;1;1] ++ [1;1;1]^^g ++ [0;0;1;0;1;1].
385Lemma u1RF a x: segRR tmf hF hB (lead1 a x ++ tailw 1) (um1 a x).
386Proof. unfold lead1,blk,stack,tailw,um1,hF,hB. solve_seg. Qed.
387Lemma u1RB a x: segRR tmf hB hB (lead1 a x ++ tailw 1) (um1 a x).
388Proof. unfold lead1,blk,stack,tailw,um1,hB. solve_seg. Qed.
389Lemma u1L a x: segLL tmf hD hD (um1 a x) (uco1 a x).
390Proof. unfold um1,uco1,hD. solve_seg. Qed.
391Lemma u2RF a x g: segRR tmf hF hB (lead1 a x ++ tailw (S (S g))) (um2 a x g).
392Proof. unfold lead1,blk,stack,tailw,um2,hF,hB. solve_seg. Qed.
393Lemma u2RB a x g: segRR tmf hB hB (lead1 a x ++ tailw (S (S g))) (um2 a x g).
394Proof. unfold lead1,blk,stack,tailw,um2,hB. solve_seg. Qed.
395Lemma u2L a x g: segLL tmf hD hD (um2 a x g) (uco2 a x g).
396Proof. unfold um2,uco2,hD. solve_seg. Qed.
398Lemma t_ungl1 bs a x ov bs' a': consume (bs ++ [(a,1%nat)]) (S x) = Some (ov, bs', a') ->
399 segRLs tmf h h (uw bs true a x (tailw 1)) ([1;1;1]^^ov ++ uw bs' false a' 1 (tailw 0)).
400Proof.
401 destruct bs as [|[[|c] j] r]; cbn [app consume].
402 - destruct a as [|a]; intros E; injection E as E1 E2 E3; subst ov bs' a'.
403 + pose proof (lrcons1 (u1RB 0 x) (u1L 0 x)) as H. applys_eq H; unfold uco1; lnorm2.
404 + pose proof (lrcons1 (u1RB (S a) x) (u1L (S a) x)) as H. applys_eq H; unfold uco1; lnorm2.
405 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
406 pose proof (gen_fwdg (u1RF a x) (u1L a x) j r) as H. applys_eq H; unfold uco1; rewrite ?cw_app; lnorm2.
407 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
408 pose proof (gen_fwd (u1RF a x) (u1L a x) c j r) as H. applys_eq H; unfold uco1; rewrite ?cw_app; lnorm2.
409Qed.
410Lemma t_ungl2 bs a x g ov bs' a': consume (bs ++ [(a,1%nat);(x,S g)]) 0%nat = Some (ov, bs', a') ->
411 segRLs tmf h h (uw bs true a x (tailw (S (S g)))) ([1;1;1]^^ov ++ uw bs' false a' 1 (tailw 0)).
412Proof.
413 destruct bs as [|[[|c] j] r]; cbn [app consume].
414 - destruct a as [|a]; intros E; injection E as E1 E2 E3; subst ov bs' a'.
415 + pose proof (lrcons1 (u2RB 0 x g) (u2L 0 x g)) as H. applys_eq H; unfold uco2; lnorm2.
416 + pose proof (lrcons1 (u2RB (S a) x g) (u2L (S a) x g)) as H. applys_eq H; unfold uco2; lnorm2.
417 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
418 pose proof (gen_fwdg (u2RF a x g) (u2L a x g) j r) as H. applys_eq H; unfold uco2; rewrite ?cw_app; lnorm2.
419 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
420 pose proof (gen_fwd (u2RF a x g) (u2L a x g) c j r) as H. applys_eq H; unfold uco2; rewrite ?cw_app; lnorm2.
421Qed.
423(** ** the halting call *)
424Lemma t_halt x far l r: halts tmf (l {{B}}> uw [] false 0 x far *> r).
425Proof. unfold uw, leadw. cbn [cw app]. rewrite Str_app_assoc. apply halt0. Qed.
427(** ** U0 next to the edge. Edge class 0: [1;1;1]^^f; class 1: [1] ++ [1;1;1]^^f *)
428Definition edge1w f : list Sym := [1] ++ [1;1;1]^^f.
429Lemma z_lead bs x f ov bs' a': bs <> [] -> consume bs 0%nat = Some (ov, bs', a') ->
430 sideRL tmf hB hD ((cw bs ++ edgew x f) *> const 0) (([1;1;1]^^ov ++ cw bs' ++ edgew x (S f)) *> const 0).
431Proof.
432 intros NE. destruct bs as [|[[|c] j] r]; [congruence| |]; cbn [consume]; intros E; injection E as E1 E2 E3; subst ov bs' a'.
433 - destruct x as [|x].
434 + pose proof (gen_sideg (edge0L0 f) j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; lnorm2.
435 + pose proof (gen_sideg (edge0L x f) j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; lnorm2.
436 - destruct x as [|x].
437 + pose proof (gen_side (edge0L0 f) c j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; lnorm2.
438 + pose proof (gen_side (edge0L x f) c j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; lnorm2.
439Qed.
440Lemma z_empty y f: sideRL tmf hB hD (edgew (S y) f *> const 0) (edgew y (S f) *> const 0).
441Proof. apply u0E. Qed.
442Lemma z_absorb f: sideRL tmf hB hD (edgew 0 (S f) *> const 0) (([1;1] ++ [1;1;1]^^(S f)) *> const 0).
443Proof. unfold sideRL. intros l. unfold to_DH_config, edgew, hB, hD. es. Qed.
444Lemma z_stop bs a x f ov bs' a': consume bs a = Some (ov, bs', a') ->
445 sideRL tmf hB hD (uw bs false a (S x) (edge1w f) *> const 0) (([1;1;1]^^ov ++ uw bs' true a' x (edge1w f)) *> const 0).
446Proof. intros E. apply segRL_side, t_stop, E. Qed.
447Definition zco a x f : list Sym := [0;1]^^a ++ [1;1;1;0;1] ++ [0;1]^^x ++ [1;1;1]^^f ++ [0;1;1;1].
448Lemma z1F a x f: sideRL tmf hF hD ((lead1 a x ++ edge1w f) *> const 0) (zco a x f *> const 0).
449Proof. unfold sideRL. intros l. unfold to_DH_config, lead1, blk, stack, edge1w, zco, hF, hD. es. Qed.
450Lemma z1B a x f: sideRL tmf hB hD ((lead1 a x ++ edge1w f) *> const 0) (zco a x f *> const 0).
451Proof. unfold sideRL. intros l. unfold to_DH_config, lead1, blk, stack, edge1w, zco, hB, hD. es. Qed.
452Lemma z_1111 bs a x f ov bs' a': consume (bs ++ [(a,1%nat);(x,f)]) 0%nat = Some (ov, bs', a') ->
453 sideRL tmf hB hD (uw bs true a x (edge1w f) *> const 0) (([1;1;1]^^ov ++ cw bs' ++ edgew 0 1) *> const 0).
454Proof.
455 unfold uw, leadw. destruct bs as [|[[|c] j] r]; cbn [app consume].
456 - destruct a as [|a]; intros E; injection E as E1 E2 E3; subst ov bs' a'.
457 + pose proof (z1B 0 x f) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; unfold zco; lnorm2.
458 + pose proof (z1B (S a) x f) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; unfold zco; lnorm2.
459 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
460 pose proof (gen_sideg (z1F a x f) j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; unfold zco; rewrite ?cw_app; lnorm2.
461 - intros E; injection E as E1 E2 E3; subst ov bs' a'.
462 pose proof (gen_side (z1F a x f) c j r) as H. applys_eq H; rewrite <-?Str_app_assoc; f_equal; unfold zco; rewrite ?cw_app; lnorm2.
463Qed.
465(** ** resets at the root *)
466Definition NT s g (X:side) : Q * tape := const 0 <{{A}} ([1;0]^^s ++ [1] ++ [0;0] ++ [1;0] ++ tailw g) *> X.
467Definition rmid t : list Sym := [0;0;1;0;1;1;0;1;0] ++ [1;0]^^t.
468Lemma reset1_in t X: root t ([1;1;1] *> X) -->* rmid t *> const 0 {{B}}> X.
469Proof. unfold root,rmid. es. Qed.
470Lemma reset1_out t X: rmid t *> const 0 <{{D}} X -->* NT (S t) 0 X.
471Proof. unfold rmid,NT,tailw. es. Qed.
472Lemma reset1 t X X': sideRL tmf hB hD X X' -> root t ([1;1;1] *> X) -->* NT (S t) 0 X'.
473Proof.
474 intros H. eapply evstep_trans. 1: apply reset1_in.
475 eapply evstep_trans. 2: apply reset1_out.
476 apply progress_evstep. apply (H (rmid t *> const 0)).
477Qed.
478Lemma reset1_halt t X: sideRLs_halt tmf h X -> halts tmf (root t ([1;1;1] *> X)).
479Proof. intros H. eapply halts_evstep. 2: apply reset1_in. apply (sideRLs_halt_single _ _ _ _ H). Qed.
480Lemma reset2 s g X: NT (S s) g X -->* root 0 ((lead1 s 0 ++ tailw g) *> X).
481Proof. unfold NT,root,lead1,blk,stack,tailw. es. Qed.
483(** * Records with N fields (computation) and their words *)
484Definition cvp (p:N*N) : nat*nat := (N.to_nat (fst p), N.to_nat (snd p)).
485Definition cvl (bs:list (N*N)) := map cvp bs.
486Record unitN := UN { ubs : list (N*N); ubit : bool; ua : N; ux : N; ug : N }.
487Definition uwN u := uw (cvl (ubs u)) (ubit u) (N.to_nat (ua u)) (N.to_nat (ux u)) (tailw (N.to_nat (ug u))).
488Fixpoint dwords (us:list unitN) : list Sym := match us with [] => [] | u::us => uwN u ++ dwords us end.
489Inductive zN := Z0 (bs:list (N*N)) (x f:N) | ZD (bs:list (N*N)) (b:bool) (a x f:N).
490Definition zside z : side := match z with
491 | Z0 bs x f => (cw (cvl bs) ++ edgew (N.to_nat x) (N.to_nat f)) *> const 0
492 | ZD bs b a x f => uw (cvl bs) b (N.to_nat a) (N.to_nat x) (edge1w (N.to_nat f)) *> const 0 end.
493Inductive tailN := TT (t g:N) | NTl (s g:N).
494Record cfg := Cfg { ctl : tailN; cus : list unitN; cz : zN }.
495Definition denote c : Q * tape := match ctl c with
496 | TT t g => root (N.to_nat t) (([1;1;1]^^(N.to_nat g) ++ dwords (cus c)) *> zside (cz c))
497 | NTl s g => NT (N.to_nat s) (N.to_nat g) (dwords (cus c) *> zside (cz c)) end.
499Definition consumeN (bs:list (N*N)) (a:N) : option (N * list (N*N) * N) :=
500 match bs with
501 | (c, j) :: r => if N.eqb c 0 then Some (j, r, a) else Some (0%N, (N.pred c, j)::r, a)
502 | [] => if N.eqb a 0 then None else Some (0%N, [], N.pred a)
202 end.503 end.
203 follow emit. apply IHt; assumption.
504Lemma consumeN_spec bs a ov bs' a': consumeN bs a = Some (ov, bs', a') ->
505 consume (cvl bs) (N.to_nat a) = Some (N.to_nat ov, cvl bs', N.to_nat a').
506Proof.
507 destruct bs as [|[c j] r]; cbn.
508 - destruct (N.eqb_spec a 0); [discriminate|]. intros E; injection E as E1 E2 E3; subst.
509 replace (N.to_nat a) with (S (N.to_nat (N.pred a))) by lia. reflexivity.
510 - destruct (N.eqb_spec c 0) as [Hc|Hc]; intros E; injection E as E1 E2 E3; subst.
511 + reflexivity.
512 + unfold cvp; cbn. replace (N.to_nat c) with (S (N.to_nat (N.pred c))) by lia. reflexivity.
204Qed.513Qed.
206Hypothesis wall : forall n, segRLs tm (head q) (head q) (W^^n) (W^^n).
514Arguments consumeN : simpl never.
207Hypothesis one : forall p n,
515Lemma cvl_app l1 l2: cvl (l1 ++ l2) = cvl l1 ++ cvl l2.
208 segRLs tm (head q) ((head q)^^carry p) (word p ++ W^^(take p+n))
516Proof. apply map_app. Qed.
209 (W^^give p ++ word (next p) ++ W^^n).
518(** ** one touch *)
211Lemma batch_root t xs e ys k r : batch t xs=Some (e,ys) ->
519Inductive tres := TStop (ov:N) (u:unitN) | TPass (ov:N) (u:unitN) | THalt | TFail.
212 start q (W^^N.to_nat k *> cell_word xs *> r) -[tm]->*
520Definition touchN u : tres :=
213 start q (W^^N.to_nat (k+e) *> cell_word ys *> r).
521 if ubit u then
522 if N.eqb (ug u) 0 then
523 match consumeN (ubs u) (N.succ (ua u)) with Some (ov,bs',a') => TPass ov (UN bs' false a' (ux u + 2) 0) | None => TFail end
524 else if N.eqb (ug u) 1 then
525 match consumeN (ubs u ++ [(ua u, 1%N)]) (N.succ (ux u)) with Some (ov,bs',a') => TPass ov (UN bs' false a' 1 0) | None => TFail end
526 else
527 match consumeN (ubs u ++ [(ua u, 1%N); (ux u, ug u - 1)%N]) 0%N with Some (ov,bs',a') => TPass ov (UN bs' false a' 1 0) | None => TFail end
528 else
529 match ubs u, N.eqb (ua u) 0 with
530 | [], true => THalt
531 | _, _ => if N.eqb (ux u) 0 then TFail else
532 match consumeN (ubs u) (ua u) with Some (ov,bs',a') => TStop ov (UN bs' true a' (N.pred (ux u)) (ug u)) | None => TFail end
533 end.
535Ltac nat_of := cbn [cvp fst snd]; rewrite ?N2Nat.inj_succ, ?N2Nat.inj_add, ?N2Nat.inj_pred.
537Lemma touchN_stop u ov u': touchN u = TStop ov u' -> segRL tmf hB hD (uwN u) ([1;1;1]^^(N.to_nat ov) ++ uwN u').
214Proof.538Proof.
215 intros H. apply (calls_spec (N.to_nat t)).
539 destruct u as [bs [] a x g]; unfold touchN; cbn [ubit ubs ua ux ug].
216 rewrite N2Nat.inj_add,lpow_add,Str_app_assoc.
540 - destruct (N.eqb g 0); [|destruct (N.eqb g 1)];
217 eapply segRLs_sideRLs_concat; [apply walls,wall|].
541 match goal with |- context [consumeN ?b ?c] => destruct (consumeN b c) as [[[? ?] ?]|] end; discriminate.
218 pose proof (segRLs_sideRLs_concat
542 - intros E. assert (Hx: N.eqb x 0 = false /\ consumeN bs a = Some (ov, ubs u', ua u') /\ ubit u' = true
219 (batch_spec tm (head q) wall one t xs e ys H) (sideRLseq_O tm r)) as I.
543 /\ ux u' = N.pred x /\ ug u' = g).
220 rewrite Str_app_assoc in I. exact I.
544 { destruct bs as [|p bs]; [destruct (N.eqb a 0)|]; cbn in E; try discriminate;
545 destruct (N.eqb x 0); cbn in E; try discriminate;
546 destruct (consumeN _ a) as [[[o b'] a'']|]; try discriminate; injection E as <- <-; cbn; auto. }
547 destruct Hx as (Hx & Hc & Hb & Hux & Hg). apply consumeN_spec in Hc.
548 unfold uwN. rewrite Hb, Hux, Hg. cbn [ubs ubit ua ux ug].
549 apply N.eqb_neq in Hx. replace (N.to_nat x) with (S (N.to_nat (N.pred x))) by lia.
550 apply t_stop. exact Hc.
221Qed.551Qed.
222End RootCorrect.
552Lemma touchN_pass u ov u': touchN u = TPass ov u' -> segRLs tmf h h (uwN u) ([1;1;1]^^(N.to_nat ov) ++ uwN u') /\ ug u' = 0%N.
223End Sk1Counter.
553Proof.
225Module Sk1Counter7.
554 destruct u as [bs [] a x g]; unfold touchN; cbn [ubit ubs ua ux ug].
226Definition W : list Sym := [0;1;0;1;1;1].
555 - destruct (N.eqb_spec g 0) as [Hg0|Hg0]; [|destruct (N.eqb_spec g 1) as [Hg1|Hg1]].
227Inductive digit := D0 | D1 | D2 | D3 | D4 | D5 | D6.
556 + destruct (consumeN bs (N.succ a)) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
228Definition word p : list Sym :=
557 intros E; injection E as <- <-. split; [|reflexivity].
229 match p with
558 apply consumeN_spec in Ec. rewrite N2Nat.inj_succ in Ec. subst g.
230 | D0 => [0;1;0;1;0;1] | D1 => [1;1] | D2 => [0;1;1;1]
559 unfold uwN; cbn [ubs ubit ua ux ug].
231 | D3 => [0;1;0;1;0;1;1;1;0;1;1;1] | D4 => [1;1;1;1;0;1;1;1]
560 replace (N.to_nat (x + 2)) with (S (S (N.to_nat x))) by lia. apply t_pass, Ec.
232 | D5 => [0;1;0;1;0;1;1;1;1;1] | D6 => [1;1;1;1;1;1]
561 + destruct (consumeN (bs ++ [(a, 1%N)]) (N.succ x)) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
562 intros E; injection E as <- <-. split; [|reflexivity].
563 apply consumeN_spec in Ec. rewrite N2Nat.inj_succ, cvl_app in Ec. subst g.
564 cbn [cvl map] in Ec. unfold cvp in Ec; cbn [fst snd] in Ec. change (N.to_nat 1) with 1%nat in Ec.
565 unfold uwN; cbn [ubs ubit ua ux ug]. apply t_ungl1, Ec.
566 + destruct (consumeN (bs ++ [(a, 1%N); (x, g-1)%N]) 0%N) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
567 intros E; injection E as <- <-. split; [|reflexivity].
568 apply consumeN_spec in Ec. rewrite cvl_app in Ec. cbn [cvl map] in Ec. unfold cvp in Ec; cbn [fst snd] in Ec.
569 change (N.to_nat 1) with 1%nat in Ec. change (N.to_nat 0) with 0%nat in Ec.
570 unfold uwN; cbn [ubs ubit ua ux ug].
571 replace (N.to_nat g) with (S (S (N.to_nat (g-1) - 1))) by lia.
572 replace (N.to_nat (g-1)) with (S (N.to_nat (g-1) - 1)) in Ec by lia.
573 apply t_ungl2, Ec.
574 - intros E. destruct bs as [|p bs]; [destruct (N.eqb a 0)|]; cbn in E; try discriminate;
575 destruct (N.eqb x 0); cbn in E; try discriminate;
576 destruct (consumeN _ a) as [[[o b'] a'']|]; discriminate.
577Qed.
578Lemma touchN_halt u: touchN u = THalt -> forall l r, halts tmf (l {{B}}> uwN u *> r).
579Proof.
580 destruct u as [bs [] a x g]; unfold touchN; cbn [ubit ubs ua ux ug].
581 - destruct (N.eqb g 0); [|destruct (N.eqb g 1)];
582 match goal with |- context [consumeN ?b ?c] => destruct (consumeN b c) as [[[? ?] ?]|] end; discriminate.
583 - destruct bs as [|p bs]; [destruct (N.eqb_spec a 0) as [Ha|Ha]|].
584 + intros _ l r. unfold uwN; cbn [ubs ubit ua ux ug cvl map]. subst a. apply t_halt.
585 + intros E; cbn in E; destruct (N.eqb x 0); cbn in E; try discriminate;
586 destruct (consumeN _ a) as [[[o b'] a'']|]; discriminate.
587 + intros E; cbn in E; destruct (N.eqb x 0); cbn in E; try discriminate;
588 destruct (consumeN _ a) as [[[o b'] a'']|]; discriminate.
589Qed.
591(** ** U0 touch *)
592Inductive zres := ZRet (ov:N) (z:zN) | ZAbs (f:N) | ZFail.
593Definition ztouch z : zres := match z with
594 | Z0 [] y f => if N.eqb y 0 then (if N.eqb f 0 then ZFail else ZAbs f) else ZRet 0%N (Z0 [] (N.pred y) (N.succ f))
595 | Z0 bs x f => match consumeN bs 0%N with Some (ov,bs',_) => ZRet ov (Z0 bs' x (N.succ f)) | None => ZFail end
596 | ZD bs false a x f => if N.eqb x 0 then ZFail else
597 match consumeN bs a with Some (ov,bs',a') => ZRet ov (ZD bs' true a' (N.pred x) f) | None => ZFail end
598 | ZD bs true a x f => match consumeN (bs ++ [(a,1%N);(x,f)]) 0%N with Some (ov,bs',_) => ZRet ov (Z0 bs' 0 1) | None => ZFail end
233 end.599 end.
234Definition next p := match p with
600Lemma ztouch_ret z ov z': ztouch z = ZRet ov z' -> sideRL tmf hB hD (zside z) ([1;1;1]^^(N.to_nat ov) *> zside z').
235 | D0=>D1 | D1=>D2 | D2=>D3 | D3=>D4 | D4=>D5 | D5=>D6 | D6=>D0 end.
236Definition take p : nat := match p with D1 | D2=>1 | _=>0 end.
⋯ 15 template-only lines (template 237–254), not in ours
255 forall k, segRLs tm (h^^t) (h^^u)
256 (W^^k ++ word p ++ W^^b) (W^^(k+a) ++ word q ++ W^^c).
257Proof.601Proof.
258 intros H k. rewrite lpow_add, <-app_assoc.
602 destruct z as [[|p bs] x f|bs [] a x f]; cbn [ztouch zside].
259 eapply segRLs_concat; [apply walls|exact H].
603 - destruct (N.eqb_spec x 0) as [Hx|Hx]; [destruct (N.eqb f 0); discriminate|].
604 intros E; injection E as <- <-. cbn [zside cvl map cw app]. change (N.to_nat 0) with 0%nat.
605 cbn [lpow Str_app]. rewrite N2Nat.inj_succ.
606 replace (N.to_nat x) with (S (N.to_nat (N.pred x))) by lia. apply z_empty.
607 - destruct (consumeN (p::bs) 0%N) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
608 intros E; injection E as <- <-. apply consumeN_spec in Ec. cbn [zside].
609 rewrite <-Str_app_assoc, N2Nat.inj_succ. apply (z_lead _ _ _ _ _ (N.to_nat a'')); [discriminate|exact Ec].
610 - destruct (consumeN _ 0%N) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
611 intros E; injection E as <- <-. apply consumeN_spec in Ec. rewrite cvl_app in Ec.
612 cbn [cvl map] in Ec. unfold cvp in Ec; cbn [fst snd] in Ec. change (N.to_nat 1) with 1%nat in Ec.
613 cbn [zside]. rewrite <-Str_app_assoc. change (N.to_nat 0) with 0%nat. change (N.to_nat 1) with 1%nat.
614 apply (z_1111 _ _ _ _ _ _ (N.to_nat a'')), Ec.
615 - destruct (N.eqb_spec x 0) as [Hx|Hx]; [discriminate|].
616 destruct (consumeN bs a) as [[[o b'] a'']|] eqn:Ec; [|discriminate].
617 intros E; injection E as <- <-. apply consumeN_spec in Ec. cbn [zside]. rewrite <-Str_app_assoc.
618 replace (N.to_nat x) with (S (N.to_nat (N.pred x))) by lia. apply z_stop, Ec.
260Qed.619Qed.
262Record effect := Eff { phase : digit; used : nat; given : nat; sent : nat }.
620Lemma ztouch_abs z f: ztouch z = ZAbs f -> sideRL tmf hB hD (zside z) (([1;1] ++ [1;1;1]^^(N.to_nat f)) *> const 0).
263Fixpoint total (p:digit) (t:nat) : effect :=
264 match t with
⋯ 6 template-only lines (template 265–271), not in ours
272 segRLs tm (h^^t) (h^^sent a) (word p ++ W^^(used a+n))
273 (W^^given a ++ word (phase a) ++ W^^n).
274Proof.621Proof.
275 gen p n. induction t; intros p n; cbn [total phase used given sent].
622 destruct z as [[|p bs] x f'|bs [] a x f']; cbn [ztouch zside].
276 - constructor.
623 - destruct (N.eqb_spec x 0) as [Hx|Hx]; [|discriminate]. destruct (N.eqb_spec f' 0) as [Hf|Hf]; [discriminate|].
277 - cbn [lpow]. rewrite <-Nat.add_assoc.
624 intros E; injection E as <-. subst x. cbn [cvl map cw app].
278 rewrite (lpow_add _ (carry p)).
625 replace (N.to_nat f') with (S (N.to_nat f' - 1)) by lia. apply z_absorb.
279 eapply segRLs_trans.
626 - destruct (consumeN (p::bs) 0%N) as [[[o b'] a'']|]; discriminate.
280 + apply one.
627 - destruct (consumeN _ 0%N) as [[[o b'] a'']|]; discriminate.
281 + apply prefix_rule, IHt.
628 - destruct (N.eqb x 0); [discriminate|]. destruct (consumeN bs a) as [[[o b'] a'']|]; discriminate.
282Qed.629Qed.
283End Counter.
631(** ** one call from the root through the units *)
285Lemma total_add p t u :
632Inductive cres := CRet (ov:N) (us:list unitN) (z:zN) | CHalt | CFail.
286 total p (t+u) =
633Definition setg u g := UN (ubs u) (ubit u) (ua u) (ux u) g.
287 let a := total p t in let b := total (phase a) u in
634Fixpoint callN (us:list unitN) (z:zN) : cres := match us with
288 Eff (phase b) (used a+used b) (given a+given b) (sent a+sent b).
635 | [] => match ztouch z with ZRet ov z' => CRet ov [] z' | _ => CFail end
289Proof.
636 | u :: us1 => match touchN u with
290 gen p. induction t; intros p; cbn [Nat.add total phase used given sent].
637 | TStop ov u' => CRet ov (u' :: us1) z
291 - destruct (total p u); reflexivity.
638 | THalt => CHalt
292 - rewrite IHt. cbn. f_equal; lia.
639 | TFail => CFail
293Qed.
640 | TPass ov u' => match us1 with
295Lemma total_seven p : total p 7 = Eff p 2 4 1.
641 | [] => match ztouch z with
296Proof. destruct p; reflexivity. Qed.
642 | ZRet ov2 z' => CRet ov [setg u' ov2] z'
298Lemma total_period p k r :
643 | ZAbs f => CRet ov [] (ZD (ubs u') (ubit u') (ua u') (ux u') (ug u' + f + 1))
299 total p (k*7+r) = let a := total p r in
644 | ZFail => CFail end
300 Eff (phase a) (k*2+used a) (k*4+given a) (k+sent a).
645 | _ => match callN us1 z with
301Proof.
646 | CRet ov2 us' z' => CRet ov (setg u' ov2 :: us') z'
302 induction k; [cbn [Nat.mul Nat.add]; destruct (total p r); reflexivity|].
647 | CHalt => CHalt | CFail => CFail end
303 replace (S k*7+r) with (7+(k*7+r)) by lia.
304 rewrite total_add,total_seven. cbn [phase used given sent].
⋯ 30 template-only lines (template 305–338), not in ours
339 | Some (e,ys) => Some (givenN a,(phaseN a,(n-usedN a+e)%N)::ys)
340 | None => None
341 end648 end
342 else None
343 end.
⋯ 318 template-only lines (template 345–695), not in ours
696 | Some ys => remove_fast fuel w (N.pred n) ys
697 | None => None end
698 end649 end
699 end.650 end.
701Lemma remove_fast_spec fuel w n xs ys : remove_fast fuel w n xs=Some ys ->
652Lemma side1 {w w' r r'}: segRLs tmf h h w w' -> sideRL tmf hB hD r r' -> sideRL tmf hB hD (w *> r) (w' *> r').
702 denote xs=w^^N.to_nat n *> denote ys.
703Proof.653Proof.
704 gen n xs ys. induction fuel; intros n xs ys H; cbn [remove_fast] in H;
654 intros H1 H2. assert (H3: sideRLs tmf h r r'). { unfold h. econstructor; [exact H2|constructor]. }
705 destruct (N.eqb_spec n 0); try discriminate; subst; try solve [inverts H; reflexivity].
655 pose proof (segRLs_sideRLs_concat H1 H3) as H. unfold h in H. inversion H; subst.
706 destruct (skip w n xs) as [[k zs]|] eqn:E.
656 match goal with Hs: sideRLs _ [] _ _ |- _ => inversion Hs; subst end. assumption.
707 - destruct (skip_spec _ _ _ _ _ E) as [Hk E1].
708 rewrite E1,(IHfuel _ _ _ H),<-Str_app_assoc,<-lpow_add.
⋯ 3 template-only lines (template 709–711), not in ours
712 replace (N.to_nat n) with (1+N.to_nat (N.pred n)) by lia.
713 cbn [Nat.add lpow]. rewrite Str_app_assoc. reflexivity.
714Qed.657Qed.
716Fixpoint size (xs:t) : N := match xs with
658Lemma setg_word u g: ug u = 0%N -> uwN u ++ [1;1;1]^^(N.to_nat g) = uwN (setg u g).
717 | []=>0%N | (w,n)::xs=>(N.of_nat (length w)*n+size xs)%N end.
659Proof. intros E. unfold uwN, setg, uw, tailw. cbn [ubs ubit ua ux ug]. rewrite E. cbn. rewrite <-!app_assoc. reflexivity. Qed.
719End Runs.
660Lemma abs_word u f: ug u = 0%N -> uwN u ++ [1;1] ++ [1;1;1]^^(N.to_nat f) =
721Module RunMachine.
661 uw (cvl (ubs u)) (ubit u) (N.to_nat (ua u)) (N.to_nat (ux u)) (edge1w (N.to_nat (ug u + f + 1))).
722Record config := Cfg { left : Runs.t; right : Runs.t; state : Q; direction : dir }.
662Proof.
723Definition denote c := match direction c with
663 intros E. unfold uwN, uw, tailw, edge1w. rewrite E. rewrite <-!app_assoc. f_equal. f_equal.
724 | L => Runs.denote (left c) <{{state c}} Runs.denote (right c)
664 replace (N.to_nat (0 + f + 1)) with (S (N.to_nat f)) by lia. cbn. reflexivity.
725 | R => Runs.denote (left c) {{state c}}> Runs.denote (right c)
665Qed.
667Lemma callN_ret us: forall z ov us' z', callN us z = CRet ov us' z' ->
668 sideRL tmf hB hD (dwords us *> zside z) (([1;1;1]^^(N.to_nat ov) ++ dwords us') *> zside z').
669Proof.
670 induction us as [|u us1 IH]; intros z ov us' z' E; cbn [callN] in E.
671 - destruct (ztouch z) as [o z1|f|] eqn:Ez; try discriminate. injection E as <- <- <-.
672 cbn [dwords]. rewrite app_nil_r. cbn [Str_app]. apply ztouch_ret, Ez.
673 - destruct (touchN u) as [o u1|o u1| |] eqn:Et; try discriminate.
674 + injection E as <- <- <-. apply touchN_stop in Et. cbn [dwords].
675 rewrite (app_assoc ([1;1;1]^^(N.to_nat o))), !(Str_app_assoc _ (dwords us1)).
676 apply segRL_side, Et.
677 + apply touchN_pass in Et. destruct Et as [Ht Hg].
678 destruct us1 as [|v us2].
679 * destruct (ztouch z) as [o2 z1|f|] eqn:Ez; try discriminate.
680 -- injection E as <- <- <-. apply ztouch_ret in Ez. pose proof (side1 Ht Ez) as H.
681 cbn [dwords]. rewrite !app_nil_r. applys_eq H; rewrite <-?Str_app_assoc; f_equal.
682 rewrite <-!app_assoc, setg_word by exact Hg. reflexivity.
683 -- injection E as <- <- <-. apply ztouch_abs in Ez. pose proof (side1 Ht Ez) as H.
684 cbn [dwords zside]. rewrite !app_nil_r. applys_eq H; rewrite <-?Str_app_assoc; f_equal.
685 rewrite <-!app_assoc, abs_word by exact Hg. reflexivity.
686 * destruct (callN (v :: us2) z) as [o2 us3 z1| |] eqn:Ec; try discriminate.
687 injection E as <- <- <-. apply IH in Ec. pose proof (side1 Ht Ec) as H.
688 cbn [dwords] in *. applys_eq H; rewrite <-?Str_app_assoc; f_equal.
689 rewrite <-!app_assoc. f_equal. rewrite app_assoc, setg_word by exact Hg. reflexivity.
690Qed.
691Lemma callN_halt us: forall z, callN us z = CHalt -> sideRLs_halt tmf h (dwords us *> zside z).
692Proof.
693 induction us as [|u us1 IH]; intros z E; cbn [callN] in E.
694 - destruct (ztouch z); discriminate.
695 - destruct (touchN u) as [o u1|o u1| |] eqn:Et; try discriminate.
696 + apply touchN_pass in Et. destruct Et as [Ht Hg]. destruct us1 as [|v us2].
697 * destruct (ztouch z); discriminate.
698 * destruct (callN (v :: us2) z) as [o2 us3 z1| |] eqn:Ec; try discriminate.
699 apply IH in Ec. cbn [dwords]. rewrite Str_app_assoc.
700 exact (segRLs_sideRLs_halt_concat _ _ _ _ _ _ Ht Ec).
701 + pose proof (touchN_halt _ Et) as Hh.
702 cbn [dwords]. rewrite Str_app_assoc. unfold h. constructor. intros l. cbn. apply Hh.
703Qed.
705(** ** one increment *)
706Inductive ires := IOk (c:cfg) | IHalt | IFail.
707Definition inc1 c : ires := match ctl c with
708 | TT t g =>
709 if N.eqb g 0 then match callN (cus c) (cz c) with
710 | CRet ov us' z' => IOk (Cfg (TT (N.succ t) ov) us' z') | CHalt => IHalt | CFail => IFail end
711 else if N.eqb g 1 then match callN (cus c) (cz c) with
712 | CRet ov us' z' => IOk (Cfg (NTl (N.succ t) ov) us' z') | CHalt => IHalt | CFail => IFail end
713 else IFail
714 | NTl s g => if N.eqb s 0 then IFail else IOk (Cfg (TT 0 0) (UN [] true (N.pred s) 0 g :: cus c) (cz c))
726 end.715 end.
728Definition raw tm c : option config :=
716Lemma inc1_ok c c': inc1 c = IOk c' -> denote c -->* denote c'.
729 let '(b,l,r) := match direction c with
717Proof.
730 | L => let '(b,l) := Runs.pop (left c) in (b,l,right c)
718 destruct c as [[t g|s g] us z]; unfold inc1, denote; cbn [ctl cus cz].
731 | R => let '(b,r) := Runs.pop (right c) in (b,left c,r)
719 - destruct (N.eqb_spec g 0) as [Hg|Hg]; [|destruct (N.eqb_spec g 1) as [Hg1|Hg1]].
732 end in
720 + destruct (callN us z) as [ov us' z'| |] eqn:E; try discriminate. intros H; injection H as <-.
733 match tm (state c,b) with
721 apply callN_ret in E. cbn [ctl cus cz]. subst g. cbn [N.to_nat lpow app].
734 | None => None
722 rewrite N2Nat.inj_succ. apply progress_evstep, root_step, E.
735 | Some (b',L,q) => Some (Cfg l (Runs.push [b'] 1 r) q L)
723 + destruct (callN us z) as [ov us' z'| |] eqn:E; try discriminate. intros H; injection H as <-.
736 | Some (b',R,q) => Some (Cfg (Runs.push [b'] 1 l) r q R)
724 apply callN_ret in E. cbn [ctl cus cz]. subst g. change (N.to_nat 1) with 1%nat. cbn [lpow].
725 rewrite app_nil_r, Str_app_assoc, N2Nat.inj_succ.
726 eapply evstep_trans. 1: apply (reset1 _ _ _ E).
727 unfold NT. rewrite <-!Str_app_assoc. apply evstep_refl'. f_equal. f_equal. unfold tailw.
728 rewrite <-!app_assoc. reflexivity.
729 + discriminate.
730 - destruct (N.eqb_spec s 0) as [Hs|Hs]; [discriminate|]. intros H; injection H as <-. cbn [ctl cus cz dwords].
731 replace (N.to_nat s) with (S (N.to_nat (N.pred s))) by lia.
732 eapply evstep_trans. 1: apply reset2.
733 replace ((lead1 (N.to_nat (N.pred s)) 0 ++ tailw (N.to_nat g)) *> (dwords us *> zside z))
734 with (([1;1;1]^^(N.to_nat 0) ++ dwords (UN [] true (N.pred s) 0 g :: us)) *> zside z).
735 + apply evstep_refl.
736 + cbn [dwords N.to_nat lpow app]. rewrite Str_app_assoc. reflexivity.
737Qed.
738Lemma inc1_halt c: inc1 c = IHalt -> halts tmf (denote c).
739Proof.
740 destruct c as [[t g|s g] us z]; unfold inc1, denote; cbn [ctl cus cz].
741 - destruct (N.eqb_spec g 0) as [Hg|Hg]; [|destruct (N.eqb_spec g 1) as [Hg1|Hg1]].
742 + destruct (callN us z) as [ov us' z'| |] eqn:E; try discriminate. intros _.
743 apply callN_halt in E. subst g. cbn [N.to_nat lpow app]. apply root_halt, E.
744 + destruct (callN us z) as [ov us' z'| |] eqn:E; try discriminate. intros _.
745 apply callN_halt in E. subst g. change (N.to_nat 1) with 1%nat. cbn [lpow]. rewrite app_nil_r, Str_app_assoc.
746 apply reset1_halt, E.
747 + discriminate.
748 - destruct (N.eqb s 0); discriminate.
749Qed.
751(** * Batches: n touches of one unit with no structural event, in closed form *)
752Ltac fin := try reflexivity; cbn [lpow app]; try lia; try (f_equal; lia); try (f_equal; f_equal; lia); try (f_equal; f_equal; f_equal; lia).
753Lemma stop1s {bs a x far ov bs' a'}: consume bs a = Some (ov, bs', a') ->
754 segRLs tmf h [] (uw bs false a (S x) far) ([1;1;1]^^ov ++ uw bs' true a' x far).
755Proof. intros E. unfold h. econstructor; [apply (t_stop _ _ _ _ _ _ _ E)|constructor]. Qed.
756Lemma pairK q: forall c j r a x, segRLs tmf (h^^(q*2)) (h^^q)
757 (uw ((q*2+c, j)::r) false a (S x) (tailw 0)) (uw ((c,j)::r) false (q+a) (S (q+x)) (tailw 0)).
758Proof.
759 induction q as [|q IH]; intros c j r a x.
760 - apply segRLs_O.
761 - pose proof (@stop1s ((S (S (q*2+c)), j)::r) a x (tailw 0) 0 ((S (q*2+c), j)::r) a eq_refl) as H1.
762 pose proof (t_pass ((S (q*2+c), j)::r) a x 0 ((q*2+c,j)::r) (S a) eq_refl) as H2.
763 pose proof (IH c j r (S a) (S x)) as H3.
764 pose proof (segRLs_trans H1 (segRLs_trans H2 H3)) as H.
765 applys_eq H; fin.
766Qed.
767Lemma pair1 q: forall a x, segRLs tmf (h^^(q*2)) (h^^q)
768 (uw [] false (q+a) (S x) (tailw 0)) (uw [] false a (S (q+x)) (tailw 0)).
769Proof.
770 induction q as [|q IH]; intros a x.
771 - apply segRLs_O.
772 - pose proof (@stop1s [] (S (q+a)) x (tailw 0) 0 [] (q+a) eq_refl) as H1.
773 pose proof (t_pass [] (q+a) x 0 [] (q+a) eq_refl) as H2.
774 pose proof (IH a (S x)) as H3.
775 pose proof (segRLs_trans H1 (segRLs_trans H2 H3)) as H.
776 applys_eq H; fin.
777Qed.
778Definition b2n (b:bool) : nat := if b then 1 else 0.
779Lemma clK0 q rb c j r a x: segRLs tmf (h^^(q*2 + b2n rb)) (h^^q)
780 (uw ((q*2 + b2n rb + c, j)::r) false a (S x) (tailw 0)) (uw ((c,j)::r) rb (q+a) (q + S x - b2n rb) (tailw 0)).
781Proof.
782 destruct rb; cbn [b2n].
783 - pose proof (pairK q (S c) j r a x) as H1.
784 pose proof (@stop1s ((S c, j)::r) (q+a) (q+x) (tailw 0) 0 ((c,j)::r) (q+a) eq_refl) as H2.
785 pose proof (segRLs_trans H1 H2) as H. rewrite lpow_add.
786 rewrite app_nil_r in H. applys_eq H; fin.
787 - pose proof (pairK q c j r a x) as H. applys_eq H; fin.
788Qed.
789Lemma clK1 q rb c j r a x: segRLs tmf (h^^(S (q*2 + b2n rb))) (h^^(S q))
790 (uw ((S (q*2 + b2n rb + c), j)::r) true a x (tailw 0)) (uw ((c,j)::r) rb (q + S a) (q + S (S x) - b2n rb) (tailw 0)).
791Proof.
792 pose proof (t_pass ((S (q*2 + b2n rb + c), j)::r) a x 0 ((q*2 + b2n rb + c, j)::r) (S a) eq_refl) as H1.
793 pose proof (clK0 q rb c j r (S a) (S x)) as H2.
794 exact (segRLs_trans H1 H2).
795Qed.
796Lemma cl10 q rb a x: segRLs tmf (h^^(q*2 + b2n rb)) (h^^q)
797 (uw [] false (q + b2n rb + a) (S x) (tailw 0)) (uw [] rb a (q + S x - b2n rb) (tailw 0)).
798Proof.
799 destruct rb; cbn [b2n].
800 - pose proof (pair1 q (S a) x) as H1.
801 pose proof (@stop1s [] (S a) (q+x) (tailw 0) 0 [] a eq_refl) as H2.
802 pose proof (segRLs_trans H1 H2) as H. rewrite lpow_add.
803 rewrite app_nil_r in H. applys_eq H; fin.
804 - pose proof (pair1 q a x) as H. applys_eq H; fin.
805Qed.
806Lemma cl11 q rb a x: segRLs tmf (h^^(S (q*2 + b2n rb))) (h^^(S q))
807 (uw [] true (q + b2n rb + a) x (tailw 0)) (uw [] rb a (q + S (S x) - b2n rb) (tailw 0)).
808Proof.
809 pose proof (t_pass [] (q + b2n rb + a) x 0 [] (q + b2n rb + a) eq_refl) as H1.
810 pose proof (cl10 q rb a (S x)) as H2.
811 exact (segRLs_trans H1 H2).
812Qed.
814Definition b2N (b:bool) : N := if b then 1%N else 0%N.
815Lemma b2N_nat b: N.to_nat (b2N b) = b2n b.
816Proof. destruct b; reflexivity. Qed.
817Lemma div2_nat n: N.to_nat n = N.to_nat (N.div2 n) * 2 + b2n (N.odd n).
818Proof. rewrite <-b2N_nat. pose proof (N.div2_odd n) as E. unfold b2N. destruct (N.odd n); cbn [N.b2n] in E; lia. Qed.
820Definition closedU (n:N) (u:unitN) : option (unitN * N) :=
821 if N.eqb n 0 then Some (u, 0%N) else
822 match ubs u with
823 | (c,j)::r =>
824 if negb (ubit u) then
825 if N.eqb n 1 then
826 if N.eqb (ux u) 0 || N.eqb c 0 then None
827 else Some (UN ((N.pred c, j)::r) true (ua u) (N.pred (ux u)) (ug u), 0%N)
828 else
829 if negb (N.eqb (ug u) 0) || N.eqb (ux u) 0 || N.ltb c n then None
830 else Some (UN (((c - n)%N, j)::r) (N.odd n) (N.div2 n + ua u) (N.div2 n + ux u - b2N (N.odd n)) 0, N.div2 n)
831 else
832 if negb (N.eqb (ug u) 0) || N.ltb c n then None
833 else Some (UN (((c - n)%N, j)::r) (N.odd (N.pred n)) (N.div2 (N.pred n) + N.succ (ua u))
834 (N.div2 (N.pred n) + N.succ (N.succ (ux u)) - b2N (N.odd (N.pred n))) 0, N.succ (N.div2 (N.pred n)))
835 | [] =>
836 if negb (ubit u) then
837 if N.eqb n 1 then
838 if N.eqb (ux u) 0 || N.eqb (ua u) 0 then None
839 else Some (UN [] true (N.pred (ua u)) (N.pred (ux u)) (ug u), 0%N)
840 else
841 if negb (N.eqb (ug u) 0) || N.eqb (ux u) 0 || N.ltb (ua u) (N.div2 n + b2N (N.odd n)) then None
842 else Some (UN [] (N.odd n) (ua u - N.div2 n - b2N (N.odd n)) (N.div2 n + ux u - b2N (N.odd n)) 0, N.div2 n)
843 else
844 if negb (N.eqb (ug u) 0) || N.ltb (ua u) (N.div2 (N.pred n) + b2N (N.odd (N.pred n))) then None
845 else Some (UN [] (N.odd (N.pred n)) (ua u - N.div2 (N.pred n) - b2N (N.odd (N.pred n)))
846 (N.div2 (N.pred n) + N.succ (N.succ (ux u)) - b2N (N.odd (N.pred n))) 0, N.succ (N.div2 (N.pred n)))
737 end.847 end.
739Lemma raw_spec tm c : match raw tm c with
849Ltac bnorm := repeat match goal with
740 | None => halted tm (denote c)
850 | H: (_ || _) = false |- _ => apply Bool.orb_false_iff in H; destruct H
741 | Some c' => denote c -[tm]-> denote c'
851 | H: negb _ = false |- _ => apply Bool.negb_false_iff in H
852 | H: N.eqb _ _ = true |- _ => apply N.eqb_eq in H
853 | H: N.eqb _ _ = false |- _ => apply N.eqb_neq in H
854 | H: N.ltb _ _ = false |- _ => apply N.ltb_ge in H
742 end.855 end.
856Ltac dif := match goal with |- context [if ?b then _ else _] => destruct b eqn:G end.
857Ltac weq := unfold uwN; cbn [ubs ubit ua ux ug cvl map lpow app]; try unfold cvp; cbn [fst snd]; f_equal; try f_equal; try f_equal; try lia.
859Lemma closedU_spec n u u' p: closedU n u = Some (u', p) ->
860 segRLs tmf (h^^(N.to_nat n)) (h^^(N.to_nat p)) (uwN u) (uwN u').
743Proof.861Proof.
744 destruct c as [l r q []]; unfold raw; cbn [left right state direction denote].
862 unfold closedU. destruct (N.eqb_spec n 0) as [Hn|Hn].
745 - pose proof (Runs.pop_spec l) as H. destruct (Runs.pop l) as [b l']; cbn in H.
863 { intros E; injection E as <- <-. subst n. apply segRLs_O. }
746 rewrite H. destruct (tm (q,b)) as [[[b' []] q']|] eqn:E;
864 destruct u as [[|[c j] r] [] a x g]; cbn [ubs ubit ua ux ug negb].
747 cbn [denote left right state direction]; try rewrite Runs.push_spec;
865 - (* k=1, bit 1 *)
748 cbn [N.to_nat Pos.to_nat lpow app Str_app];
866 dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst g.
749 first [solve [unfold halted; cbn; exact E] | solve [econstructor; exact E]].
867 pose proof (div2_nat (N.pred n)) as Hd. rewrite <-b2N_nat in Hd.
750 - pose proof (Runs.pop_spec r) as H. destruct (Runs.pop r) as [b r']; cbn in H.
868 pose proof (cl11 (N.to_nat (N.div2 (N.pred n))) (N.odd (N.pred n))
751 rewrite H. destruct (tm (q,b)) as [[[b' []] q']|] eqn:E;
869 (N.to_nat (a - N.div2 (N.pred n) - b2N (N.odd (N.pred n)))) (N.to_nat x)) as HH.
752 cbn [denote left right state direction]; try rewrite Runs.push_spec;
870 rewrite <-b2N_nat in HH. applys_eq HH; try (f_equal; lia); weq.
753 cbn [N.to_nat Pos.to_nat lpow app Str_app];
871 - (* k=1, bit 0 *)
754 first [solve [unfold halted; cbn; exact E] | solve [econstructor; exact E]].
872 destruct (N.eqb_spec n 1) as [Hn1|Hn1]; cbn [negb].
873 + dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst n.
874 assert (Ec: consume [] (N.to_nat a) = Some (0%nat, [], N.to_nat (N.pred a))).
875 { unfold consume. replace (N.to_nat a) with (S (N.to_nat (N.pred a))) by lia. reflexivity. }
876 pose proof (@stop1s [] _ (N.to_nat (N.pred x)) (tailw (N.to_nat g)) _ _ _ Ec) as HH.
877 change (h^^(N.to_nat 1)) with h. change (h^^(N.to_nat 0)) with (@nil (DH0*DH0)).
878 applys_eq HH; weq.
879 + dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst g.
880 pose proof (div2_nat n) as Hd. rewrite <-b2N_nat in Hd.
881 pose proof (cl10 (N.to_nat (N.div2 n)) (N.odd n) (N.to_nat (a - N.div2 n - b2N (N.odd n))) (N.to_nat (N.pred x))) as HH.
882 rewrite <-b2N_nat in HH. applys_eq HH; try (f_equal; lia); weq.
883 - (* k>=2, bit 1 *)
884 dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst g.
885 pose proof (div2_nat (N.pred n)) as Hd. rewrite <-b2N_nat in Hd.
886 pose proof (clK1 (N.to_nat (N.div2 (N.pred n))) (N.odd (N.pred n)) (N.to_nat (c - n)) (N.to_nat j) (cvl r)
887 (N.to_nat a) (N.to_nat x)) as HH.
888 rewrite <-b2N_nat in HH. applys_eq HH; try (f_equal; lia); weq.
889 - (* k>=2, bit 0 *)
890 destruct (N.eqb_spec n 1) as [Hn1|Hn1]; cbn [negb].
891 + dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst n.
892 assert (Ec: consume ((N.to_nat c, N.to_nat j)::cvl r) (N.to_nat a) = Some (0%nat, (N.to_nat (N.pred c), N.to_nat j)::cvl r, N.to_nat a)).
893 { unfold consume. replace (N.to_nat c) with (S (N.to_nat (N.pred c))) by lia. reflexivity. }
894 pose proof (@stop1s _ _ (N.to_nat (N.pred x)) (tailw (N.to_nat g)) _ _ _ Ec) as HH.
895 change (h^^(N.to_nat 1)) with h. change (h^^(N.to_nat 0)) with (@nil (DH0*DH0)).
896 applys_eq HH; weq.
897 + dif; [discriminate|]. bnorm. intros E; injection E as <- <-. subst g.
898 pose proof (div2_nat n) as Hd. rewrite <-b2N_nat in Hd.
899 pose proof (clK0 (N.to_nat (N.div2 n)) (N.odd n) (N.to_nat (c - n)) (N.to_nat j) (cvl r) (N.to_nat a) (N.to_nat (N.pred x))) as HH.
900 rewrite <-b2N_nat in HH. applys_eq HH; try (f_equal; lia); weq.
755Qed.901Qed.
756End RunMachine.
903(** ** U0 in a batch *)
757End Sk1Tape.
904Lemma zLs m: forall c j r x f, sideRLs tmf (h^^m) ((cw ((m+c,j)::r) ++ edgew x f) *> const 0)
759Module Sk1Check.
905 ((cw ((c,j)::r) ++ edgew x (m+f)) *> const 0).
760Import Sk1Tape Sk1Counter.
761Module RT := Runs.
⋯ 8 template-only lines (template 762–770), not in ours
771 | _,_ => c end.
773Lemma orient_spec d c : denote (orient d c)=denote c.
774Proof.906Proof.
775 destruct c as [l r q []],d; unfold orient; cbn [left right state direction]; try reflexivity.
907 induction m as [|m IH]; intros c j r x f.
776 - pose proof (RT.pop_spec l) as H. destruct (RT.pop l) as [b l']; cbn in H.
908 - constructor.
777 cbn [denote left right state direction]. rewrite RT.push_spec,H. reflexivity.
909 - pose proof (z_lead ((S (m+c), j)::r) x f 0 ((m+c,j)::r) 0 ltac:(discriminate) eq_refl) as H1.
778 - pose proof (RT.pop_spec r) as H. destruct (RT.pop r) as [b r']; cbn in H.
910 cbn [lpow app] in H1. unfold h. cbn [lpow app]. econstructor. 1: exact H1.
779 cbn [denote left right state direction]. rewrite RT.push_spec,H. reflexivity.
911 replace (S m + f) with (m + S f) by lia. apply IH.
780Qed.912Qed.
781Lemma orient_direction d c : direction (orient d c)=d.
913Lemma zEs m: forall y f, sideRLs tmf (h^^m) (edgew (m+y) f *> const 0) (edgew y (m+f) *> const 0).
782Proof. destruct c as [l r q []],d; cbn [orient direction left right state]; try reflexivity;
914Proof.
783 first [solve [destruct (RT.pop l); reflexivity] | solve [destruct (RT.pop r); reflexivity]]. Qed.
915 induction m as [|m IH]; intros y f.
784Lemma orient_state d c : state (orient d c)=state c.
916 - constructor.
785Proof. destruct c as [l r q []],d; cbn [orient direction left right state]; try reflexivity;
917 - unfold h. cbn [lpow app]. econstructor. 1: apply (z_empty (m+y) f).
786 first [solve [destruct (RT.pop l); reflexivity] | solve [destruct (RT.pop r); reflexivity]]. Qed.
918 replace (S m + f) with (m + S f) by lia. apply IH.
788(* 32 is only a matching-work budget. Exhaustion rejects the certificate. *)
919Qed.
789Definition remove_run := RT.remove_fast 32.
920Definition closedZ (m:N) (z:zN) : option zN :=
791Definition scan_stacks s n l r : option (RT.t*RT.t) :=
921 if N.eqb m 0 then Some z else
792 match scan_dir s with
922 match z with
793 | L => match RT.remove (scan_context s) r,
923 | Z0 [] y f => if N.ltb y m then None else Some (Z0 [] (y - m) (f + m))
794 remove_run (fast_rev (scan_in s)) n l with
924 | Z0 ((c,j)::r) x f => if N.ltb c m then None else Some (Z0 (((c - m)%N, j)::r) x (f + m))
795 | Some r,Some l => Some (l,RT.push (scan_context s) 1 (RT.push (scan_out s) n r))
925 | ZD _ _ _ _ _ => None
796 | _,_ => None end
797 | R => match RT.remove (fast_rev (scan_context s)) l,
⋯ 2 template-only lines (template 798–799), not in ours
800 (RT.push (fast_rev (scan_out s)) n l),r)
801 | _,_ => None end
802 end.926 end.
804Lemma scan_stacks_spec tm s n l r l' r' : scan_valid tm s ->
927Lemma closedZ_spec m z z': closedZ m z = Some z' -> sideRLs tmf (h^^(N.to_nat m)) (zside z) (zside z').
805 scan_stacks s n l r=Some (l',r') ->
806 denote (Cfg l r (scan_q s) (scan_dir s)) -[tm]->*
807 denote (Cfg l' r' (scan_q s) (scan_dir s)).
808Proof.928Proof.
809 destruct s as [q d w v x]. unfold scan_valid,scan_stacks,remove_run.
929 unfold closedZ. destruct (N.eqb_spec m 0) as [Hm|Hm].
810 destruct d; cbn [scan_q scan_dir scan_in scan_out scan_context]; intros H E.
930 { intros E; injection E as <-. subst m. constructor. }
811 - destruct (RT.remove x r) as [r0|] eqn:Er; try discriminate.
931 destruct z as [[|[c j] r] x f|bs b a x f]; try discriminate.
812 destruct (RT.remove_fast 32 (fast_rev w) n l) as [l0|] eqn:El; inverts E.
932 - destruct (N.ltb_spec x m) as [Hx|Hx]; [discriminate|]. intros E; injection E as <-.
813 cbn [denote left right state direction].
933 cbn [zside cvl map cw app]. pose proof (zEs (N.to_nat m) (N.to_nat (x - m)) (N.to_nat f)) as H.
814 rewrite !RT.push_spec,(RT.remove_spec _ _ _ Er),(RT.remove_fast_spec _ _ _ _ _ El).
934 replace (N.to_nat x) with (N.to_nat m + N.to_nat (x - m)) by lia.
815 rewrite fast_rev_spec. change (N.to_nat 1) with 1%nat.
935 replace (N.to_nat (f + m)) with (N.to_nat m + N.to_nat f) by lia. exact H.
816 cbn [lpow]. rewrite app_nil_r. apply H.
936 - destruct (N.ltb_spec c m) as [Hc|Hc]; [discriminate|]. intros E; injection E as <-.
817 - destruct (RT.remove (fast_rev x) l) as [l0|] eqn:El; try discriminate.
937 cbn [zside cvl map]. unfold cvp; cbn [fst snd].
818 destruct (RT.remove_fast 32 w n r) as [r0|] eqn:Er; inverts E.
938 pose proof (zLs (N.to_nat m) (N.to_nat (c - m)) (N.to_nat j) (cvl r) (N.to_nat x) (N.to_nat f)) as H.
819 cbn [denote left right state direction].
939 replace (N.to_nat c) with (N.to_nat m + N.to_nat (c - m)) by lia.
820 rewrite !RT.push_spec,(RT.remove_spec _ _ _ El),(RT.remove_fast_spec _ _ _ _ _ Er).
940 replace (N.to_nat (f + m)) with (N.to_nat m + N.to_nat f) by lia. exact H.
821 rewrite !fast_rev_spec. change (N.to_nat 1) with 1%nat.
822 cbn [lpow]. rewrite app_nil_r. apply H.
823Qed.941Qed.
825Definition use_scan s n c : option config :=
943Fixpoint batchL (n:N) (us:list unitN) (z:zN) : option (list unitN * zN) := match us with
826 if eqb (state c) (scan_q s) then
944 | [] => match closedZ n z with Some z' => Some ([], z') | None => None end
827 let c := orient (scan_dir s) c in
945 | u :: us => match closedU n u with
828 match scan_stacks s n (left c) (right c) with
946 | Some (u', p) => match batchL p us z with Some (us', z') => Some (u' :: us', z') | None => None end
829 | Some (l,r) => Some (Cfg l r (scan_q s) (scan_dir s))
947 | None => None end end.
830 | None => None end
948Lemma batchL_spec us: forall n z us' z', batchL n us z = Some (us', z') ->
831 else None.
949 sideRLs tmf (h^^(N.to_nat n)) (dwords us *> zside z) (dwords us' *> zside z').
833Lemma use_scan_spec tm s n c c' : scan_valid tm s -> use_scan s n c=Some c' ->
834 denote c -[tm]->* denote c'.
835Proof.950Proof.
836 intros H. unfold use_scan. destruct (eqb_spec (state c) (scan_q s)); try discriminate.
951 induction us as [|u us IH]; intros n z us' z' E; cbn [batchL] in E.
837 pose proof (orient_direction (scan_dir s) c) as Hd.
952 - destruct (closedZ n z) as [z1|] eqn:Ez; [|discriminate]. injection E as <- <-. apply closedZ_spec, Ez.
838 pose proof (orient_state (scan_dir s) c) as Hq.
953 - destruct (closedU n u) as [[u1 p]|] eqn:Eu; [|discriminate].
839 rewrite <-(orient_spec (scan_dir s) c).
954 destruct (batchL p us z) as [[us1 z1]|] eqn:Eb; [|discriminate]. injection E as <- <-.
840 remember (orient (scan_dir s) c) as z.
955 cbn [dwords]. rewrite !Str_app_assoc.
841 destruct z as [l r q d]; cbn [left right state direction] in *; subst.
956 exact (segRLs_sideRLs_concat (closedU_spec _ _ _ _ Eu) (IH _ _ _ _ Eb)).
842 destruct (scan_stacks s n l r) as [[l' r']|] eqn:E; intros Hc; inverts Hc.
843 rewrite e. eapply scan_stacks_spec; eauto.
844Qed.957Qed.
846Fixpoint zeros (xs:RT.t) := match xs with
959(** ** batch-size proposal (untrusted; a port of the accelerated simulator) *)
847 | [] => true
960Definition evt_unit (u:unitN) : N :=
848 | (w,_)::xs => if forallb (fun b=>eqb b 0) w then zeros xs else false end.
961 let own := match ubs u with (c,_)::_ => N.succ c | [] => (2 * ua u + b2N (ubit u))%N end in
849Lemma zero_word w : forallb (fun b=>eqb b 0) w=true -> w *> 0inf=0inf.
962 let own := if negb (ubit u) && N.eqb (ux u) 0 then 1%N else own in
963 if N.eqb (ug u) 0 then own else N.min own (if ubit u then 1%N else 2%N).
964Definition evt_z z : N := match z with Z0 [] y _ => N.succ y | Z0 ((c,_)::_) _ _ => N.succ c | ZD _ _ _ _ _ => 1%N end.
965Definition first_inc (C q n : N) : N := (n * 2^q - C mod 2^q)%N.
966Fixpoint cval (us:list unitN) (i:N) : N := match us with
967 | [] => 0%N | u :: us => ((if ubit u then 2^i else 0) + cval us (N.succ i))%N end.
968Fixpoint pmin (us:list unitN) (i C:N) (z:zN) : N := match us with
969 | [] => first_inc C i (evt_z z)
970 | u :: us => N.min (first_inc C i (evt_unit u)) (pmin us (N.succ i) C z) end.
971Definition propose (us:list unitN) (z:zN) : N := N.pred (pmin us 0 (cval us 0) z).
973(** ** the checker *)
974Definition batch_step c : option cfg := match ctl c with
975 | TT t g => if N.eqb g 0 then
976 let d := propose (cus c) (cz c) in
977 if N.eqb d 0 then None else
978 match batchL d (cus c) (cz c) with Some (us', z') => Some (Cfg (TT (t + d) 0) us' z') | None => None end
979 else None
980 | NTl _ _ => None end.
981Lemma batch_step_spec c c': batch_step c = Some c' -> denote c -->* denote c'.
850Proof.982Proof.
851 induction w as [|b w IH]; cbn; intros H; [reflexivity|].
983 destruct c as [[t g|s g] us z]; unfold batch_step; cbn [ctl cus cz]; [|discriminate].
852 destruct b; cbn in H; try discriminate. rewrite IH by exact H. symmetry; apply const_unfold.
984 destruct (N.eqb_spec g 0) as [Hg|Hg]; [|discriminate]. subst g.
985 destruct (N.eqb (propose us z) 0); [discriminate|].
986 destruct (batchL (propose us z) us z) as [[us' z']|] eqn:E; [|discriminate]. intros H; injection H as <-.
987 apply batchL_spec in E. unfold denote; cbn [ctl cus cz N.to_nat lpow app].
988 replace (N.to_nat (t + propose us z)) with (N.to_nat (propose us z) + N.to_nat t) by lia.
989 apply root_steps, E.
853Qed.990Qed.
854Lemma zeros_spec xs : zeros xs=true -> RT.denote xs=0inf.
991Definition next c : cfg + unit := match batch_step c with
992 | Some c' => inl c'
993 | None => match inc1 c with IOk c' => inl c' | IHalt => inr tt | IFail => inl c end end.
994Lemma next_spec c: match next c with inl c' => denote c -->* denote c' | inr _ => halts tmf (denote c) end.
855Proof.995Proof.
856 induction xs as [|[w n] xs IH]; cbn [zeros RT.denote]; intros H; [reflexivity|].
996 unfold next. destruct (batch_step c) as [c'|] eqn:Eb; [apply batch_step_spec, Eb|].
857 destruct (forallb (fun b=>eqb b 0) w) eqn:E; try discriminate.
997 destruct (inc1 c) as [c'| |] eqn:Ei.
858 rewrite IH by exact H. apply lpow_all0,zero_word,E.
998 - apply inc1_ok, Ei.
999 - apply inc1_halt, Ei.
1000 - apply evstep_refl.
859Qed.1001Qed.
861Section Cells.
1002Definition c342 := Cfg (NTl 1 1) [] (Z0 [(0%N,3%N)] 0 1).
862Variable digit : Type.
1003Definition check fuel := match N_iter_until next (inl c342) fuel with inl _ => false | inr _ => true end.
863Variable word : digit -> list Sym.
1004Theorem check_spec fuel: check fuel = true -> halts tmf (denote c342).
864Variable W : list Sym.
865Fixpoint cells_word (xs:list(digit*N)) : list Sym := match xs with
⋯ 12 template-only lines (template 866–878), not in ours
880Lemma remove_cells_spec xs r r' : remove_cells xs r=Some r' ->
881 RT.denote r=cells_word xs *> RT.denote r'.
882Proof.1005Proof.
883 gen r. induction xs as [|[p n] xs IH]; intros r H; cbn [remove_cells] in H.
1006 pose proof (@N_iter_until_spec cfg unit next (inl c342) fuel
884 - inverts H; reflexivity.
1007 (fun c => denote c342 -->* denote c) (fun _ => halts tmf (denote c342))) as H.
885 - destruct (RT.remove (word p) r) as [s|] eqn:E; try discriminate.
1008 assert (Hstep: forall c, denote c342 -->* denote c ->
886 destruct (remove_run W n s) as [s'|] eqn:E'; try discriminate.
1009 match next c with inl c' => denote c342 -->* denote c' | inr _ => halts tmf (denote c342) end).
887 rewrite (RT.remove_spec _ _ _ E),(RT.remove_fast_spec _ _ _ _ _ E'),(IH _ H).
1010 { intros c E. pose proof (next_spec c) as I. destruct (next c).
888 cbn [cells_word]; rewrite !Str_app_assoc; reflexivity.
1011 - eapply evstep_trans; eauto.
1012 - eapply halts_evstep; [exact I|exact E]. }
1013 specialize (H Hstep (evstep_refl _ _)). unfold check.
1014 destruct (N_iter_until next (inl c342) fuel); [discriminate|]. intros _. exact H.
889Qed.1015Qed.
890Lemma push_cells_spec xs r : RT.denote (push_cells xs r)=cells_word xs *> RT.denote r.
1017(** * The run, in chunks of 5000 iterations (each intermediate configuration is computed once by the VM
1018 and stored; each chunk is then checked separately, which keeps kernel re-checking bounded) *)
1019Ltac vm_check_eq := match goal with |- _ = ?a => vm_cast_no_check (eq_refl a) end.
1020Definition run (T:N) (c:cfg) : cfg + unit := N_iter_until next (inl c) T.
1021Definition unl (x:cfg + unit) : cfg := match x with inl c => c | inr _ => c342 end.
1022Lemma run_ok T c c': run T c = inl c' -> denote c -->* denote c'.
891Proof.1023Proof.
892 induction xs as [|[p n] xs IH]; cbn [push_cells cells_word]; [reflexivity|].
1024 intros E. pose proof (@N_iter_until_spec cfg unit next (inl c) T
893 rewrite !RT.push_spec,IH. change (N.to_nat 1) with 1%nat.
1025 (fun x => denote c -->* denote x) (fun _ => halts tmf (denote c))) as H.
894 cbn [lpow]. rewrite app_nil_r,!Str_app_assoc. reflexivity.
1026 assert (Hstep: forall x, denote c -->* denote x ->
1027 match next x with inl x' => denote c -->* denote x' | inr _ => halts tmf (denote c) end).
1028 { intros x Ex. pose proof (next_spec x) as I. destruct (next x).
1029 - eapply evstep_trans; eauto.
1030 - eapply halts_evstep; [exact I|exact Ex]. }
1031 specialize (H Hstep (evstep_refl _ _)). unfold run in E. rewrite E in H. exact H.
895Qed.1032Qed.
897Definition bulk_stacks q (u:list Sym) t k xs c :=
1033Lemma run_halt T c: run T c = inr tt -> halts tmf (denote c).
898 if eqb (state c) q then
899 let c := orient R c in
⋯ 14 template-only lines (template 900–914), not in ours
916Lemma bulk_stacks_spec t k xs c c' : bulk_stacks q u t k xs c=Some c' ->
917 denote c -[tm]->* denote c'.
918Proof.1034Proof.
919 unfold bulk_stacks. destruct (eqb_spec (state c) q); try discriminate.
1035 intros E. pose proof (@N_iter_until_spec cfg unit next (inl c) T
920 pose proof (orient_direction R c) as Hd. pose proof (orient_state R c) as Hq.
1036 (fun x => denote c -->* denote x) (fun _ => halts tmf (denote c))) as H.
921 rewrite <-(orient_spec R c). remember (orient R c) as z.
1037 assert (Hstep: forall x, denote c -->* denote x ->
922 destruct z as [l r q' d]; cbn [left right state direction] in *; subst.
1038 match next x with inl x' => denote c -->* denote x' | inr _ => halts tmf (denote c) end).
923 destruct (RT.remove (fast_rev u) l) as [l0|] eqn:El; try discriminate.
1039 { intros x Ex. pose proof (next_spec x) as I. destruct (next x).
924 destruct (remove_run W k r) as [r0|] eqn:Er; try discriminate.
1040 - eapply evstep_trans; eauto.
925 destruct (batch t xs) as [[e ys]|] eqn:Eb; try discriminate.
1041 - eapply halts_evstep; [exact I|exact Ex]. }
926 destruct (zeros l0) eqn:Ez; try discriminate.
1042 specialize (H Hstep (evstep_refl _ _)). unfold run in E. rewrite E in H. exact H.
927 destruct (remove_cells xs r0) as [r1|] eqn:Ec; intros H; inverts H.
928 cbn [denote left right state direction].
929 rewrite !RT.push_spec,push_cells_spec,(RT.remove_spec _ _ _ El),
930 (zeros_spec _ Ez),(RT.remove_fast_spec _ _ _ _ _ Er),(remove_cells_spec _ _ _ Ec).
931 rewrite fast_rev_spec. eapply rule; exact Eb.
932Qed.1043Qed.
933End BulkCorrect.
1045Definition k1 := Eval vm_compute in unl (run 5000 c342).
934End Cells.
1046Lemma s1: run 5000 c342 = inl k1. Proof. vm_check_eq. Qed.
937Definition initial := Cfg [] [] A R.
1047Definition k2 := Eval vm_compute in unl (run 5000 k1).
938Lemma initial_spec : denote initial=c0.
1048Lemma s2: run 5000 k1 = inl k2. Proof. vm_check_eq. Qed.
939Proof. reflexivity. Qed.
1049Definition k3 := Eval vm_compute in unl (run 5000 k2).
940End Sk1Check.
1050Lemma s3: run 5000 k2 = inl k3. Proof. vm_check_eq. Qed.
942Module Sk1Auto.
1051Definition k4 := Eval vm_compute in unl (run 5000 k3).
943Import Sk1Check.
1052Lemma s4: run 5000 k3 = inl k4. Proof. vm_check_eq. Qed.
944Import RM.
1053Definition k5 := Eval vm_compute in unl (run 5000 k4).
945Local Opaque RT.remove_fast RT.remove RT.push.
1054Lemma s5: run 5000 k4 = inl k5. Proof. vm_check_eq. Qed.
947(* Proposals need not be complete: the bulk/scan checkers certify each use. *)
1055Definition k6 := Eval vm_compute in unl (run 5000 k5).
948Definition front_size (r:RT.t) := RT.size (firstn 2 r).
1056Lemma s6: run 5000 k5 = inl k6. Proof. vm_check_eq. Qed.
949Definition periodic (w:list Sym) (r:RT.t) :=
1057Definition k7 := Eval vm_compute in unl (run 5000 k6).
950 let '(x,v):=match r with
1058Lemma s7: run 5000 k6 = inl k7. Proof. vm_check_eq. Qed.
951 | (x,Npos xH)::(v,_)::_=>(x,v)
1059Definition k8 := Eval vm_compute in unl (run 5000 k7).
952 | (v,_)::_=>([],v) | []=>([],[]) end in
1060Lemma s8: run 5000 k7 = inl k8. Proof. vm_check_eq. Qed.
953 eqb (x++v^^length w) (w^^length v++x).
1061Definition k9 := Eval vm_compute in unl (run 5000 k8).
954Fixpoint count_run fuel w r : N*RT.t := match fuel with
1062Lemma s9: run 5000 k8 = inl k9. Proof. vm_check_eq. Qed.
955 | O=>(0%N,r)
1063Definition k10 := Eval vm_compute in unl (run 5000 k9).
956 | S fuel=>match (if periodic w r then RT.skip w (front_size r) r else None) with
1064Lemma s10: run 5000 k9 = inl k10. Proof. vm_check_eq. Qed.
957 | Some(k,s)=>let '(n,s):=count_run fuel w s in ((k+n)%N,s)
1065Definition k11 := Eval vm_compute in unl (run 5000 k10).
958 | None=>match RT.remove w r with
1066Lemma s11: run 5000 k10 = inl k11. Proof. vm_check_eq. Qed.
959 | Some s=>let '(n,s):=count_run fuel w s in ((1+n)%N,s)
1067Definition k12 := Eval vm_compute in unl (run 5000 k11).
960 | None=>(0%N,r) end end end.
1068Lemma s12: run 5000 k11 = inl k12. Proof. vm_check_eq. Qed.
962Section Proposal.
1069Definition k13 := Eval vm_compute in unl (run 5000 k12).
963Variable digit : Type.
1070Lemma s13: run 5000 k12 = inl k13. Proof. vm_check_eq. Qed.
964Variable W : list Sym.
1071Definition k14 := Eval vm_compute in unl (run 5000 k13).
965Variable word : digit -> list Sym.
1072Lemma s14: run 5000 k13 = inl k14. Proof. vm_check_eq. Qed.
966Variable next : digit -> digit.
1073Definition k15 := Eval vm_compute in unl (run 5000 k14).
967Variable take : digit -> nat.
1074Lemma s15: run 5000 k14 = inl k15. Proof. vm_check_eq. Qed.
968Variable index : digit -> N.
1075Definition k16 := Eval vm_compute in unl (run 5000 k15).
969Variable period : nat.
1076Lemma s16: run 5000 k15 = inl k16. Proof. vm_check_eq. Qed.
970Variable order : list digit.
1077Definition k17 := Eval vm_compute in unl (run 5000 k16).
971Fixpoint first_bad fuel p n : N := match fuel with
1078Lemma s17: run 5000 k16 = inl k17. Proof. vm_check_eq. Qed.
972 | O=>1%N
1079Definition k18 := Eval vm_compute in unl (run 5000 k17).
973 | S fuel=>if (N.of_nat(take p)<=?n)%N
1080Lemma s18: run 5000 k17 = inl k18. Proof. vm_check_eq. Qed.
974 then (1+first_bad fuel (next p) (n-N.of_nat(take p)))%N else 1%N end.
1081Definition k19 := Eval vm_compute in unl (run 5000 k18).
975Definition unsafe p n := (N.of_nat period*(n/2)+first_bad period p (n mod 2))%N.
1082Lemma s19: run 5000 k18 = inl k19. Proof. vm_check_eq. Qed.
976Definition better (a b:option(digit*N*RT.t)) := match a,b with
1083Definition k20 := Eval vm_compute in unl (run 5000 k19).
977 | Some(p,n,r),Some(q,m,s)=>if (n<?m)%N then b else a
1084Lemma s20: run 5000 k19 = inl k20. Proof. vm_check_eq. Qed.
978 | None,_=>b | _,None=>a end.
1085Definition k21 := Eval vm_compute in unl (run 5000 k20).
979Fixpoint choose ps r : option(digit*N*RT.t) := match ps with
1086Lemma s21: run 5000 k20 = inl k21. Proof. vm_check_eq. Qed.
980 | []=>None
1087Lemma s22: run 5000 k21 = inr tt. Proof. vm_check_eq. Qed.
981 | p::ps=>let cand:=match RT.remove (word p) r with
1088Lemma init: c0 -[tmf]->* denote c342.
982 | None=>None
1089Proof. unfold denote, c342, NT, zside; cbn. solve_init. Qed.
983 | Some r=>let '(n,r):=count_run 32 W r in Some(p,n,r) end in
1090Lemma halt_tmf: halts tmf c0.
984 better cand (choose ps r) end.
985Fixpoint propose_cells fuel r cap : N*list(digit*N) := match fuel with
⋯ 59 template-only lines (template 986–1047), not in ours
1049Lemma auto_scan_spec s c c': Sk1Counter.scan_valid tm s -> auto_scan s c=Some c' ->
1050 denote c -[tm]->* denote c'.
1051Proof.1091Proof.
1052 intros H. unfold auto_scan. destruct (N.ltb (scan_count s c) min_scan); try discriminate.
1092 eapply halts_evstep. 2: apply init.
1053 apply use_scan_spec,H.
1093 eapply halts_evstep. 2: apply (run_ok _ _ _ s1).
1094 eapply halts_evstep. 2: apply (run_ok _ _ _ s2).
1095 eapply halts_evstep. 2: apply (run_ok _ _ _ s3).
1096 eapply halts_evstep. 2: apply (run_ok _ _ _ s4).
1097 eapply halts_evstep. 2: apply (run_ok _ _ _ s5).
1098 eapply halts_evstep. 2: apply (run_ok _ _ _ s6).
1099 eapply halts_evstep. 2: apply (run_ok _ _ _ s7).
1100 eapply halts_evstep. 2: apply (run_ok _ _ _ s8).
1101 eapply halts_evstep. 2: apply (run_ok _ _ _ s9).
1102 eapply halts_evstep. 2: apply (run_ok _ _ _ s10).
1103 eapply halts_evstep. 2: apply (run_ok _ _ _ s11).
1104 eapply halts_evstep. 2: apply (run_ok _ _ _ s12).
1105 eapply halts_evstep. 2: apply (run_ok _ _ _ s13).
1106 eapply halts_evstep. 2: apply (run_ok _ _ _ s14).
1107 eapply halts_evstep. 2: apply (run_ok _ _ _ s15).
1108 eapply halts_evstep. 2: apply (run_ok _ _ _ s16).
1109 eapply halts_evstep. 2: apply (run_ok _ _ _ s17).
1110 eapply halts_evstep. 2: apply (run_ok _ _ _ s18).
1111 eapply halts_evstep. 2: apply (run_ok _ _ _ s19).
1112 eapply halts_evstep. 2: apply (run_ok _ _ _ s20).
1113 eapply halts_evstep. 2: apply (run_ok _ _ _ s21).
1114 exact (run_halt _ _ s22).
1054Qed.1115Qed.
1055Lemma try_scans_spec ss c c':Forall(Sk1Counter.scan_valid tm) ss -> try_scans ss c=Some c' ->
1117Lemma halt: halts tm c0.
1056 denote c -[tm]->* denote c'.
1118Proof. apply flip_halts_iff. exact halt_tmf. Qed.
1057Proof.
1120(*
1058 intros H. induction H; cbn [try_scans]; [discriminate|].
1121```
1059 destruct (auto_scan x c) as [c''|] eqn:E; [intros H'; inverts H'|apply IHForall].
1122mirror tmf = flip tm; words root-first (nearest the head first)
1060 eapply auto_scan_spec; eauto.
1123unit uw bs b a x far = cw bs ++ leadw b a x ++ far, blk c j = [0] ++ [1;0]^^c ++ [1] ++ [1;1;1]^^j
1061Qed.
1124lead leadw true a x = blk a 1 ++ [0] ++ [1;0]^^x, leadw false a x = [0;1]^^a ++ [0;0] ++ [1;0]^^x
1062Lemma advance_spec c:match advance tm scans c with
1125far tailw g = [1;1] ++ [1;1;1]^^g (boundary); edgew x f = [0] ++ [1;0]^^x ++ [1;1;1]^^f; edge1w f = [1] ++ [1;1;1]^^f
1063 | inl c'=>denote c -[tm]->* denote c' | inr _=>halted tm (denote c) end.
1126consume ((S c,j)::r) a = (0, (c,j)::r, a); ((0,j)::r) a = (j, r, a) (j walls glue root-ward); [] (S a) = (0, [], a)
1064Proof.
1128touch (call in B, return in D; [1;1;1]^^ov = walls glued onto the root-side boundary)
1065 unfold advance. destruct (auto_bulk c) as [c'|] eqn:E; [eapply bulk_ok; eauto|].
1129stop uw bs false a (S x) far -> [1;1;1]^^ov ++ uw bs' true a' x far (bs',a') from consume bs a
1066 destruct (try_scans scans c) as [c'|] eqn:Es; [eapply try_scans_spec; eauto|].
1130pass uw bs true a x (tailw 0) -> [1;1;1]^^ov ++ uw bs' false a' (x+2) (tailw 0), one call forwarded; consume bs (a+1)
1067 pose proof(RM.raw_spec tm c) as H. destruct(RM.raw tm c); [apply evstep_one,H|exact H].
1131unglue1 uw bs true a x (tailw 1) -> [1;1;1]^^ov ++ uw bs' false a' 1 (tailw 0), forwarded; consume (bs++[(a,1)]) (x+1)
1068Qed.
1132unglue2 uw bs true a x (tailw (g+2)) -> [1;1;1]^^ov ++ uw bs' false 0 1 (tailw 0), forwarded; consume (bs++[(a,1);(x,g+1)]) 0
1069Theorem check_spec fuel:check tm scans fuel=true -> halts tm c0.
1133halt uw [] false 0 x far -> halts
1070Proof.
1134U0 cw bs ++ edgew x f -> [1;1;1]^^ov ++ cw bs' ++ edgew x (f+1) (bs nonempty)
1071 rewrite <-initial_spec.
1135 edgew (y+1) f -> edgew y (f+1); edgew 0 (f+1) -> [1;1] ++ [1;1;1]^^(f+1) (absorb: U1 becomes U0, edge class 1)
1072 pose proof (@N_iter_until_spec config unit (advance tm scans) (inl initial) fuel
1136 uw bs true a x (edge1w f) -> [1;1;1]^^ov ++ cw bs' ++ edgew 0 1 consume (bs++[(a,1);(x,f)]) 0
1073 (fun c=>denote initial -[tm]->* denote c)
1137root root t X = 0inf <{{A}} ([0;1]^^t ++ [0;1;1]) *> X: root t X -->+ root (t+1) X' for a call X -> X'
1074 (fun _=>halts tm (denote initial))) as H.
1138reset1 root t ([1;1;1] *> X) -->* NT (t+1) 0 X' (NT s g X = 0inf <{{A}} ([1;0]^^s ++ [1;0;0;1;0] ++ tailw g) *> X)
1075 assert (Hstep:forall c,denote initial -[tm]->* denote c ->
1139reset2 NT (s+1) g X -->* root 0 ((leadw true s 0 ++ tailw g) *> X)
1076 match advance tm scans c with
1140start c0 -->* NT 1 1 ((blk 0 3 ++ edgew 0 1) *> 0inf) (342 steps)
1077 | inl c'=>denote initial -[tm]->* denote c' | inr _=>halts tm (denote initial) end).
1141```
1078 { intros c E. pose proof(advance_spec c) as I. destruct(advance tm scans c).
1142*)
1079 - eapply evstep_trans; eauto.
1080 - eapply halts_evstep; [apply halted_halts,I|exact E]. }
⋯ 927 template-only lines (template 1081–2041), not in ours
2042Qed.
2043End TM105.
3Proof outlineCheck: the new items (green) carry the argument; the names read like the proof.md rules.

234 items in 1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v (1142 lines): 136 Lemma, 81 Definition, 8 Fixpoint, 6 Inductive, 2 Record, 1 Theorem. Tags against the template: identical = same name and same text once each file's own TM string is <TM> (marked "except the TM string" when that is the only difference); adapted = same name, different text; new = no item of that name in the template part.

#kindnamestatement (no proof body)linevs template
1Definitiontm
Definition tm := Eval compute in (TM_from_str "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB").
L37adapted
2Definitiontmf
Definition tmf := Eval compute in (flip tm).
L38new
3LemmasegRR_app
Lemma segRR_app {t h1 h2 h3 w1 w2 m1 m2}:
segRR t h1 h2 w1 m1 -> segRR t h2 h3 w2 m2 -> segRR t h1 h3 (w1 ++ w2) (m2 ++ m1).
L43new
4LemmasegLL_app
Lemma segLL_app {t h1 h2 h3 w1 w2 o1 o2}:
segLL t h1 h2 w1 o1 -> segLL t h2 h3 w2 o2 -> segLL t h1 h3 (w1 ++ w2) (o2 ++ o1).
L50new
5LemmasegRR_RL_LL
Lemma segRR_RL_LL {t h1 h2 h3 h4 w1 w2 m w1' w2'}:
segRR t h1 h2 w1 m -> segRL t h2 h3 w2 w2' -> segLL t h3 h4 m w1' ->
segRL t h1 h4 (w1 ++ w2) (w1' ++ w2').
L57new
6Definitionstack
Definition stack j : list Sym := [1] ++ [1;1;1]^^j.
L69new
7Definitionblk
Definition blk m j : list Sym := [0] ++ [1;0]^^m ++ stack j.
L70new
8Definitionbmid
Definition bmid m j : list Sym := [0;1] ++ [0;1;1]^^j ++ [0;1]^^m.
L71new
9Definitionlbw
Definition lbw m j : list Sym := [0;1;1]^^j ++ [0;1]^^(S m).
L72new
10Definitionxbmid
Definition xbmid x : list Sym := [0;0;1] ++ [0;1]^^x.
L73new
11LemmablkRR_F
Lemma blkRR_F m j: segRR tmf (F,[]) (F,[]) (blk m j) (bmid m j).
L76new
12LemmablkRR_B
Lemma blkRR_B m j: segRR tmf (B,[]) (F,[]) (blk m j) (bmid m j).
L78new
13LemmablkLL
Lemma blkLL m j: segLL tmf (D,[]) (D,[]) (lbw m j) (blk m j).
L80new
14LemmasweepLL
Lemma sweepLL: segLL tmf (D,[]) (D,[]) [0;1] [0;1].
L82new
15LemmaleadLL
Lemma leadLL a: segLL tmf (A,[]) (D,[]) (bmid a 1) ([0;1]^^a ++ [0;0] ++ [1;0;1]).
L84new
16LemmaxbRR
Lemma xbRR x: segRR tmf (F,[]) (B,[]) ([0] ++ [1;0]^^x ++ [1;1]) (xbmid x).
L86new
17LemmaxbLL
Lemma xbLL x: segLL tmf (D,[]) (A,[]) (xbmid x) ([0] ++ [1;0]^^x ++ [1;1]).
L88new
18LemmaleadstopS
Lemma leadstopS a x: segRL tmf (F,[]) (D,[]) ([0;1]^^(S a) ++ [0;0] ++ [1;0]^^(S x))
([0] ++ [1;0]^^a ++ [1;1;1;1] ++ [0] ++ [1;0]^^x).
L90new
19Lemmaleadstop0
Lemma leadstop0 x: segRL tmf (F,[]) (D,[]) ([0;0] ++ [1;0]^^(S x)) ([1;1;1] ++ [0] ++ [1;0]^^x).
L93new
20Lemmastop1
Lemma stop1 c a: segRL tmf (B,[]) (D,[]) ([0;1]^^(S c) ++ [0;0] ++ [1;0]^^(S a))
([0] ++ [1;0]^^c ++ [1;1;1;1] ++ [0] ++ [1;0]^^a).
L95new
21Lemmaedge0L
Lemma edge0L x f: sideRL tmf (F,[]) (D,[]) (([0] ++ [1;0]^^(S x) ++ [1;1;1]^^f) *> const 0)
(([0] ++ [1;0]^^x ++ [1;1;1]^^(S f)) *> const 0).
L98new
22Lemmaedge0E
Lemma edge0E y f: sideRL tmf (B,[]) (D,[]) (([0] ++ [1;0]^^(S y) ++ [1;1;1]^^f) *> const 0)
(([0] ++ [1;0]^^y ++ [1;1;1]^^(S f)) *> const 0).
L101new
23Definitionblkp
Definition blkp (p:nat*nat) := blk (fst p) (snd p).
L106new
24Definitionbmidp
Definition bmidp (p:nat*nat) := bmid (fst p) (snd p).
L107new
25Definitionlbwp
Definition lbwp (p:nat*nat) := lbw (fst p) (snd p).
L108new
26Fixpointcw
Fixpoint cw (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => blkp p ++ cw ch end.
L109new
27Fixpointcmid
Fixpoint cmid (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => cmid ch ++ bmidp p end.
L110new
28Fixpointclbw
Fixpoint clbw (ch:list (nat*nat)) : list Sym := match ch with [] => [] | p::ch => clbw ch ++ lbwp p end.
L111new
29LemmachainRR
Lemma chainRR ch: segRR tmf (F,[]) (F,[]) (cw ch) (cmid ch).
L113new
30LemmachainLL
Lemma chainLL ch: segLL tmf (D,[]) (D,[]) (clbw ch) (cw ch).
L119new
31Lemmabmid_shift
Lemma bmid_shift m j: bmid m j ++ [0;1] = [0;1] ++ lbw m j.
L125new
32Lemmacmid_shift
Lemma cmid_shift ch: cmid ch ++ [0;1] = [0;1] ++ clbw ch.
L127new
33Lemmabmid_S
Lemma bmid_S m j: bmid (S m) j = [0;1] ++ lbw m j.
L133new
34Definitionpw
Definition pw c j ch := blk c j ++ cw ch.
L138new
35LemmaprefRR
Lemma prefRR c j ch: segRR tmf (B,[]) (F,[]) (pw c j ch) (cmid ch ++ bmid c j).
L139new
36LemmaprefLL
Lemma prefLL c j ch: segLL tmf (D,[]) (D,[]) (cmid ch ++ bmid (S c) j) (pw c j ch ++ [0;1]).
L141new
37LemmasegRL_frame
Lemma segRL_frame {t h1 h2 w w'} u: segRL t h1 h2 w w' -> segRL t h1 h2 (w ++ u) (w' ++ u).
L150new
38Definitionlead1
Definition lead1 a x : list Sym := blk a 1 ++ [0] ++ [1;0]^^x.
L155new
39Definitionlead0
Definition lead0 a x : list Sym := [0;1]^^a ++ [0;0] ++ [1;0]^^x.
L156new
40Definitiontailw
Definition tailw g : list Sym := [1;1] ++ [1;1;1]^^g.
L157new
41DefinitionhB
Definition hB : DH0 := (B,[]).
L159new
42DefinitionhD
Definition hD : DH0 := (D,[]).
L160new
43Definitionh
Definition h : list (DH0*DH0) := [(hB,hD)].
L161adapted
44LemmastopK
Lemma stopK c j ch a x: segRL tmf hB hD (pw (S c) j ch ++ lead0 a (S x)) (pw c j ch ++ lead1 a x).
L163new
45LemmastopK1
Lemma stopK1 c a: segRL tmf hB hD (lead0 (S c) (S a)) (lead1 c a).
L172new
46DefinitionpassK_mid
Definition passK_mid c j ch a x := (xbmid x ++ bmid a 1) ++ (cmid ch ++ bmid (S c) j).
L175new
47LemmapassK_RR
Lemma passK_RR c j ch a x: segRR tmf hB hB (pw (S c) j ch ++ lead1 a x ++ [1;1]) (passK_mid c j ch a x).
L176new
48LemmapassK_LL
Lemma passK_LL c j ch a x: segLL tmf hD hD (passK_mid c j ch a x) (pw c j ch ++ lead0 (S a) (S (S x)) ++ [1;1]).
L182new
49LemmapassK
Lemma passK c j ch a x: segRLs tmf h h (pw (S c) j ch ++ lead1 a x ++ [1;1]) (pw c j ch ++ lead0 (S a) (S (S x)) ++ [1;1]).
L188new
50DefinitionpassK1_mid
Definition passK1_mid c x := xbmid x ++ bmid c 1.
L194new
51LemmapassK1_RR
Lemma passK1_RR c x: segRR tmf hB hB (lead1 c x ++ [1;1]) (passK1_mid c x).
L195new
52LemmapassK1_LL
Lemma passK1_LL c x: segLL tmf hD hD (passK1_mid c x) (lead0 c (S (S x)) ++ [1;1]).
L197new
53LemmapassK1
Lemma passK1 c x: segRLs tmf h h (lead1 c x ++ [1;1]) (lead0 c (S (S x)) ++ [1;1]).
L202new
54Lemmahalt0
Lemma halt0 x l r: halts tmf (l {{B}}> lead0 0 x *> r).
L209new
55Lemmaedge0L0
Lemma edge0L0 f: sideRL tmf (F,[]) (D,[]) (([0] ++ [1;1;1]^^f) *> const 0)
(([1;1] ++ [1;1;1]^^f) *> const 0).
L213new
56LemmasegRR_sideRL_LL
Lemma segRR_sideRL_LL {t h1 h2 h3 h4 w m w' r r'}:
segRR t h1 h2 w m -> sideRL t h2 h3 r r' -> segLL t h3 h4 m w' ->
sideRL t h1 h4 (w *> r) (w' *> r').
L216new
57Definitionedgew
Definition edgew x f : list Sym := [0] ++ [1;0]^^x ++ [1;1;1]^^f.
L226new
58Lemmau0L
Lemma u0L c j ch x f: sideRL tmf hB hD ((pw (S c) j ch ++ edgew x f) *> const 0)
((pw c j ch ++ edgew x (S f)) *> const 0).
L228new
59Lemmau0E
Lemma u0E y f: sideRL tmf hB hD (edgew (S y) f *> const 0) (edgew y (S f) *> const 0).
L238new
60Definitionroot
Definition root t (X:side) : Q * tape := const 0 <{{A}} ([0;1]^^t ++ [0;1;1]) *> X.
L242new
61Definitionwmid
Definition wmid t : list Sym := [0] ++ [0;1]^^t ++ [0;1;0;1].
L243new
62Lemmaroot_in
Lemma root_in t X: root t X -->* wmid t *> const 0 {{B}}> X.
L244new
63LemmasweepA
Lemma sweepA: forall l r n, l <* [0;1]^^n <{{A}} r -->* l <{{A}} [0;1]^^n *> r.
L246new
64Lemmaroot_out
Lemma root_out t X: wmid t *> const 0 <{{D}} X -->* root (S t) X.
L248new
65Lemmaroot_step
Lemma root_step t X X': sideRL tmf hB hD X X' -> root t X -->+ root (S t) X'.
L254new
66Lemmaroot_steps
Lemma root_steps n: forall t X X', sideRLs tmf (h^^n) X X' -> root t X -->* root (n+t) X'.
L261new
67Lemmaroot_halt
Lemma root_halt t X: sideRLs_halt tmf h X -> halts tmf (root t X).
L269new
68DefinitionhF
Definition hF : DH0 := (F,[]).
L275new
69Definitionleadw
Definition leadw (b:bool) a x := if b then lead1 a x else lead0 a x.
L276new
70Definitionuw
Definition uw bs b a x (far:list Sym) := cw bs ++ leadw b a x ++ far.
L277new
71Definitionconsume
Definition consume (bs: list (nat*nat)) (a:nat) : option (nat * list (nat*nat) * nat) :=
match bs with
| (S c, j) :: r => Some (O, (c,j)::r, a)
| (O, j) :: r => Some (j, r, a)
| [] => match a with S a' => Some (O, [], a') | O => None end
end.
L278new
72Lemmacw_app
Lemma cw_app l1 l2: cw (l1 ++ l2) = cw l1 ++ cw l2.
L284new
73LemmayLL_glue
Lemma yLL_glue j: segLL tmf (D,[]) (D,[]) ([0;1;1]^^j) ([1;1;1]^^j).
L287new
74LemmaprefLL_glue
Lemma prefLL_glue j ch: segLL tmf (D,[]) (D,[]) (cmid ch ++ bmid 0 j) ([1;1;1]^^j ++ cw ch ++ [0;1]).
L289new
75Lemmagen_RL
Lemma gen_RL {ci co} (HF: segRL tmf hF hD ci co) c j ch:
segRL tmf hB hD (pw (S c) j ch ++ ci) (pw c j ch ++ [0;1] ++ co).
L298new
76Lemmagen_RLg
Lemma gen_RLg {ci co} (HF: segRL tmf hF hD ci co) j ch:
segRL tmf hB hD (pw 0 j ch ++ ci) ([1;1;1]^^j ++ cw ch ++ [0;1] ++ co).
L304new
77Lemmalrcons1
Lemma lrcons1 {w1 w2 m}: segRR tmf hB hB w1 m -> segLL tmf hD hD m w2 -> segRLs tmf h h w1 w2.
L310new
78Lemmagen_fwd
Lemma gen_fwd {ci m co} (HR: segRR tmf hF hB ci m) (HL: segLL tmf hD hD m co) c j ch:
segRLs tmf h h (pw (S c) j ch ++ ci) (pw c j ch ++ [0;1] ++ co).
L315new
79Lemmagen_fwdg
Lemma gen_fwdg {ci m co} (HR: segRR tmf hF hB ci m) (HL: segLL tmf hD hD m co) j ch:
segRLs tmf h h (pw 0 j ch ++ ci) ([1;1;1]^^j ++ cw ch ++ [0;1] ++ co).
L321new
80Lemmagen_side
Lemma gen_side {ci co R R'} (HF: sideRL tmf hF hD (ci *> R) (co *> R')) c j ch:
sideRL tmf hB hD ((pw (S c) j ch ++ ci) *> R) ((pw c j ch ++ [0;1] ++ co) *> R').
L327new
81Lemmagen_sideg
Lemma gen_sideg {ci co R R'} (HF: sideRL tmf hF hD (ci *> R) (co *> R')) j ch:
sideRL tmf hB hD ((pw 0 j ch ++ ci) *> R) (([1;1;1]^^j ++ cw ch ++ [0;1] ++ co) *> R').
L333new
82LemmasegRL_side
Lemma segRL_side {t h1 h2 w w'} R: segRL t h1 h2 w w' -> sideRL t h1 h2 (w *> R) (w' *> R).
L339new
83LemmacstopF
Lemma cstopF a x far: exists co, segRL tmf hF hD (lead0 a (S x) ++ far) co /\ [0;1] ++ co = lead1 a x ++ far.
L348new
84Lemmat_stop
Lemma t_stop bs a x far ov bs' a': consume bs a = Some (ov, bs', a') ->
segRL tmf hB hD (uw bs false a (S x) far) ([1;1;1]^^ov ++ uw bs' true a' x far).
L354new
85Definitioncpass_mid
Definition cpass_mid a x := xbmid x ++ bmid a 1.
L365new
86LemmacpassRR
Lemma cpassRR a x: segRR tmf hF hB (lead1 a x ++ [1;1]) (cpass_mid a x).
L366new
87Definitioncpass_co
Definition cpass_co a x := ([0;1]^^a ++ [0;0] ++ [1;0;1]) ++ ([0] ++ [1;0]^^x ++ [1;1]).
L368new
88LemmacpassLL
Lemma cpassLL a x: segLL tmf hD hD (cpass_mid a x) (cpass_co a x).
L369new
89Lemmat_pass
Lemma t_pass bs a x ov bs' a': consume bs (S a) = Some (ov, bs', a') ->
segRLs tmf h h (uw bs true a x (tailw 0)) ([1;1;1]^^ov ++ uw bs' false a' (S (S x)) (tailw 0)).
L371new
90Definitionum1
Definition um1 a x : list Sym := [0;0;1;0;1;1;0;1;0;1] ++ [0;1]^^x ++ [1] ++ [0;1]^^a.
L381new
91Definitionum2
Definition um2 a x g : list Sym := [0;0;1;0;1;1;0;1;1;0;1] ++ [1;0;1]^^g ++ [0;1] ++ [0;1]^^x ++ [1] ++ [0;1]^^a.
L382new
92Definitionuco1
Definition uco1 a x : list Sym := [0;1]^^a ++ [1;1;1;0;1;0] ++ [1;0]^^x ++ [0;1;0;1;1].
L383new
93Definitionuco2
Definition uco2 a x g : list Sym := [0;1]^^a ++ [1;1;1;0;1] ++ [0;1]^^x ++ [1;1;1] ++ [1;1;1]^^g ++ [0;0;1;0;1;1].
L384new
94Lemmau1RF
Lemma u1RF a x: segRR tmf hF hB (lead1 a x ++ tailw 1) (um1 a x).
L385new
95Lemmau1RB
Lemma u1RB a x: segRR tmf hB hB (lead1 a x ++ tailw 1) (um1 a x).
L387new
96Lemmau1L
Lemma u1L a x: segLL tmf hD hD (um1 a x) (uco1 a x).
L389new
97Lemmau2RF
Lemma u2RF a x g: segRR tmf hF hB (lead1 a x ++ tailw (S (S g))) (um2 a x g).
L391new
98Lemmau2RB
Lemma u2RB a x g: segRR tmf hB hB (lead1 a x ++ tailw (S (S g))) (um2 a x g).
L393new
99Lemmau2L
Lemma u2L a x g: segLL tmf hD hD (um2 a x g) (uco2 a x g).
L395new
100Lemmat_ungl1
Lemma t_ungl1 bs a x ov bs' a': consume (bs ++ [(a,1%nat)]) (S x) = Some (ov, bs', a') ->
segRLs tmf h h (uw bs true a x (tailw 1)) ([1;1;1]^^ov ++ uw bs' false a' 1 (tailw 0)).
L398new
101Lemmat_ungl2
Lemma t_ungl2 bs a x g ov bs' a': consume (bs ++ [(a,1%nat);(x,S g)]) 0%nat = Some (ov, bs', a') ->
segRLs tmf h h (uw bs true a x (tailw (S (S g)))) ([1;1;1]^^ov ++ uw bs' false a' 1 (tailw 0)).
L410new
102Lemmat_halt
Lemma t_halt x far l r: halts tmf (l {{B}}> uw [] false 0 x far *> r).
L424new
103Definitionedge1w
Definition edge1w f : list Sym := [1] ++ [1;1;1]^^f.
L428new
104Lemmaz_lead
Lemma z_lead bs x f ov bs' a': bs <> [] -> consume bs 0%nat = Some (ov, bs', a') ->
sideRL tmf hB hD ((cw bs ++ edgew x f) *> const 0) (([1;1;1]^^ov ++ cw bs' ++ edgew x (S f)) *> const 0).
L429new
105Lemmaz_empty
Lemma z_empty y f: sideRL tmf hB hD (edgew (S y) f *> const 0) (edgew y (S f) *> const 0).
L440new
106Lemmaz_absorb
Lemma z_absorb f: sideRL tmf hB hD (edgew 0 (S f) *> const 0) (([1;1] ++ [1;1;1]^^(S f)) *> const 0).
L442new
107Lemmaz_stop
Lemma z_stop bs a x f ov bs' a': consume bs a = Some (ov, bs', a') ->
sideRL tmf hB hD (uw bs false a (S x) (edge1w f) *> const 0) (([1;1;1]^^ov ++ uw bs' true a' x (edge1w f)) *> const 0).
L444new
108Definitionzco
Definition zco a x f : list Sym := [0;1]^^a ++ [1;1;1;0;1] ++ [0;1]^^x ++ [1;1;1]^^f ++ [0;1;1;1].
L447new
109Lemmaz1F
Lemma z1F a x f: sideRL tmf hF hD ((lead1 a x ++ edge1w f) *> const 0) (zco a x f *> const 0).
L448new
110Lemmaz1B
Lemma z1B a x f: sideRL tmf hB hD ((lead1 a x ++ edge1w f) *> const 0) (zco a x f *> const 0).
L450new
111Lemmaz_1111
Lemma z_1111 bs a x f ov bs' a': consume (bs ++ [(a,1%nat);(x,f)]) 0%nat = Some (ov, bs', a') ->
sideRL tmf hB hD (uw bs true a x (edge1w f) *> const 0) (([1;1;1]^^ov ++ cw bs' ++ edgew 0 1) *> const 0).
L452new
112DefinitionNT
Definition NT s g (X:side) : Q * tape := const 0 <{{A}} ([1;0]^^s ++ [1] ++ [0;0] ++ [1;0] ++ tailw g) *> X.
L466new
113Definitionrmid
Definition rmid t : list Sym := [0;0;1;0;1;1;0;1;0] ++ [1;0]^^t.
L467new
114Lemmareset1_in
Lemma reset1_in t X: root t ([1;1;1] *> X) -->* rmid t *> const 0 {{B}}> X.
L468new
115Lemmareset1_out
Lemma reset1_out t X: rmid t *> const 0 <{{D}} X -->* NT (S t) 0 X.
L470new
116Lemmareset1
Lemma reset1 t X X': sideRL tmf hB hD X X' -> root t ([1;1;1] *> X) -->* NT (S t) 0 X'.
L472new
117Lemmareset1_halt
Lemma reset1_halt t X: sideRLs_halt tmf h X -> halts tmf (root t ([1;1;1] *> X)).
L478new
118Lemmareset2
Lemma reset2 s g X: NT (S s) g X -->* root 0 ((lead1 s 0 ++ tailw g) *> X).
L480new
119Definitioncvp
Definition cvp (p:N*N) : nat*nat := (N.to_nat (fst p), N.to_nat (snd p)).
L484new
120Definitioncvl
Definition cvl (bs:list (N*N)) := map cvp bs.
L485new
121RecordunitN
Record unitN := UN { ubs : list (N*N); ubit : bool; ua : N; ux : N; ug : N }.
L486new
122DefinitionuwN
Definition uwN u := uw (cvl (ubs u)) (ubit u) (N.to_nat (ua u)) (N.to_nat (ux u)) (tailw (N.to_nat (ug u))).
L487new
123Fixpointdwords
Fixpoint dwords (us:list unitN) : list Sym := match us with [] => [] | u::us => uwN u ++ dwords us end.
L488new
124InductivezN
Inductive zN := Z0 (bs:list (N*N)) (x f:N) | ZD (bs:list (N*N)) (b:bool) (a x f:N).
L489new
125Definitionzside
Definition zside z : side := match z with
| Z0 bs x f => (cw (cvl bs) ++ edgew (N.to_nat x) (N.to_nat f)) *> const 0
| ZD bs b a x f => uw (cvl bs) b (N.to_nat a) (N.to_nat x) (edge1w (N.to_nat f)) *> const 0 end.
L490new
126InductivetailN
Inductive tailN := TT (t g:N) | NTl (s g:N).
L493new
127Recordcfg
Record cfg := Cfg { ctl : tailN; cus : list unitN; cz : zN }.
L494new
128Definitiondenote
Definition denote c : Q * tape := match ctl c with
| TT t g => root (N.to_nat t) (([1;1;1]^^(N.to_nat g) ++ dwords (cus c)) *> zside (cz c))
| NTl s g => NT (N.to_nat s) (N.to_nat g) (dwords (cus c) *> zside (cz c)) end.
L495adapted
129DefinitionconsumeN
Definition consumeN (bs:list (N*N)) (a:N) : option (N * list (N*N) * N) :=
match bs with
| (c, j) :: r => if N.eqb c 0 then Some (j, r, a) else Some (0%N, (N.pred c, j)::r, a)
| [] => if N.eqb a 0 then None else Some (0%N, [], N.pred a)
end.
L499new
130LemmaconsumeN_spec
Lemma consumeN_spec bs a ov bs' a': consumeN bs a = Some (ov, bs', a') ->
consume (cvl bs) (N.to_nat a) = Some (N.to_nat ov, cvl bs', N.to_nat a').
L504new
131Lemmacvl_app
Lemma cvl_app l1 l2: cvl (l1 ++ l2) = cvl l1 ++ cvl l2.
L515new
132Inductivetres
Inductive tres := TStop (ov:N) (u:unitN) | TPass (ov:N) (u:unitN) | THalt | TFail.
L519new
133DefinitiontouchN
Definition touchN u : tres :=
if ubit u then
  if N.eqb (ug u) 0 then
    match consumeN (ubs u) (N.succ (ua u)) with Some (ov,bs',a') => TPass ov (UN bs' false a' (ux u + 2) 0) | None => TFail end
  else if N.eqb (ug u) 1 then
    match consumeN (ubs u ++ [(ua u, 1%N)]) (N.succ (ux u)) with Some (ov,bs',a') => TPass ov (UN bs' false a' 1 0) | None => TFail end
… +8 lines
L520new
134LemmatouchN_stop
Lemma touchN_stop u ov u': touchN u = TStop ov u' -> segRL tmf hB hD (uwN u) ([1;1;1]^^(N.to_nat ov) ++ uwN u').
L537new
135LemmatouchN_pass
Lemma touchN_pass u ov u': touchN u = TPass ov u' -> segRLs tmf h h (uwN u) ([1;1;1]^^(N.to_nat ov) ++ uwN u') /\ ug u' = 0%N.
L552new
136LemmatouchN_halt
Lemma touchN_halt u: touchN u = THalt -> forall l r, halts tmf (l {{B}}> uwN u *> r).
L578new
137Inductivezres
Inductive zres := ZRet (ov:N) (z:zN) | ZAbs (f:N) | ZFail.
L592new
138Definitionztouch
Definition ztouch z : zres := match z with
| Z0 [] y f => if N.eqb y 0 then (if N.eqb f 0 then ZFail else ZAbs f) else ZRet 0%N (Z0 [] (N.pred y) (N.succ f))
| Z0 bs x f => match consumeN bs 0%N with Some (ov,bs',_) => ZRet ov (Z0 bs' x (N.succ f)) | None => ZFail end
| ZD bs false a x f => if N.eqb x 0 then ZFail else
    match consumeN bs a with Some (ov,bs',a') => ZRet ov (ZD bs' true a' (N.pred x) f) | None => ZFail end
| ZD bs true a x f => match consumeN (bs ++ [(a,1%N);(x,f)]) 0%N with Some (ov,bs',_) => ZRet ov (Z0 bs' 0 1) | None => ZFail end
… +1 lines
L593new
139Lemmaztouch_ret
Lemma ztouch_ret z ov z': ztouch z = ZRet ov z' -> sideRL tmf hB hD (zside z) ([1;1;1]^^(N.to_nat ov) *> zside z').
L600new
140Lemmaztouch_abs
Lemma ztouch_abs z f: ztouch z = ZAbs f -> sideRL tmf hB hD (zside z) (([1;1] ++ [1;1;1]^^(N.to_nat f)) *> const 0).
L620new
141Inductivecres
Inductive cres := CRet (ov:N) (us:list unitN) (z:zN) | CHalt | CFail.
L632new
142Definitionsetg
Definition setg u g := UN (ubs u) (ubit u) (ua u) (ux u) g.
L633new
143FixpointcallN
Fixpoint callN (us:list unitN) (z:zN) : cres := match us with
| [] => match ztouch z with ZRet ov z' => CRet ov [] z' | _ => CFail end
| u :: us1 => match touchN u with
  | TStop ov u' => CRet ov (u' :: us1) z
  | THalt => CHalt
  | TFail => CFail
… +11 lines
L634new
144Lemmaside1
Lemma side1 {w w' r r'}: segRLs tmf h h w w' -> sideRL tmf hB hD r r' -> sideRL tmf hB hD (w *> r) (w' *> r').
L652new
145Lemmasetg_word
Lemma setg_word u g: ug u = 0%N -> uwN u ++ [1;1;1]^^(N.to_nat g) = uwN (setg u g).
L658new
146Lemmaabs_word
Lemma abs_word u f: ug u = 0%N -> uwN u ++ [1;1] ++ [1;1;1]^^(N.to_nat f) =
uw (cvl (ubs u)) (ubit u) (N.to_nat (ua u)) (N.to_nat (ux u)) (edge1w (N.to_nat (ug u + f + 1))).
L660new
147LemmacallN_ret
Lemma callN_ret us: forall z ov us' z', callN us z = CRet ov us' z' ->
sideRL tmf hB hD (dwords us *> zside z) (([1;1;1]^^(N.to_nat ov) ++ dwords us') *> zside z').
L667new
148LemmacallN_halt
Lemma callN_halt us: forall z, callN us z = CHalt -> sideRLs_halt tmf h (dwords us *> zside z).
L691new
149Inductiveires
Inductive ires := IOk (c:cfg) | IHalt | IFail.
L706new
150Definitioninc1
Definition inc1 c : ires := match ctl c with
| TT t g =>
  if N.eqb g 0 then match callN (cus c) (cz c) with
    | CRet ov us' z' => IOk (Cfg (TT (N.succ t) ov) us' z') | CHalt => IHalt | CFail => IFail end
  else if N.eqb g 1 then match callN (cus c) (cz c) with
    | CRet ov us' z' => IOk (Cfg (NTl (N.succ t) ov) us' z') | CHalt => IHalt | CFail => IFail end
… +3 lines
L707adapted
151Lemmainc1_ok
Lemma inc1_ok c c': inc1 c = IOk c' -> denote c -->* denote c'.
L716new
152Lemmainc1_halt
Lemma inc1_halt c: inc1 c = IHalt -> halts tmf (denote c).
L738new
153Lemmastop1s
Lemma stop1s {bs a x far ov bs' a'}: consume bs a = Some (ov, bs', a') ->
segRLs tmf h [] (uw bs false a (S x) far) ([1;1;1]^^ov ++ uw bs' true a' x far).
L753new
154LemmapairK
Lemma pairK q: forall c j r a x, segRLs tmf (h^^(q*2)) (h^^q)
(uw ((q*2+c, j)::r) false a (S x) (tailw 0)) (uw ((c,j)::r) false (q+a) (S (q+x)) (tailw 0)).
L756new
155Lemmapair1
Lemma pair1 q: forall a x, segRLs tmf (h^^(q*2)) (h^^q)
(uw [] false (q+a) (S x) (tailw 0)) (uw [] false a (S (q+x)) (tailw 0)).
L767new
156Definitionb2n
Definition b2n (b:bool) : nat := if b then 1 else 0.
L778new
157LemmaclK0
Lemma clK0 q rb c j r a x: segRLs tmf (h^^(q*2 + b2n rb)) (h^^q)
(uw ((q*2 + b2n rb + c, j)::r) false a (S x) (tailw 0)) (uw ((c,j)::r) rb (q+a) (q + S x - b2n rb) (tailw 0)).
L779new
158LemmaclK1
Lemma clK1 q rb c j r a x: segRLs tmf (h^^(S (q*2 + b2n rb))) (h^^(S q))
(uw ((S (q*2 + b2n rb + c), j)::r) true a x (tailw 0)) (uw ((c,j)::r) rb (q + S a) (q + S (S x) - b2n rb) (tailw 0)).
L789new
159Lemmacl10
Lemma cl10 q rb a x: segRLs tmf (h^^(q*2 + b2n rb)) (h^^q)
(uw [] false (q + b2n rb + a) (S x) (tailw 0)) (uw [] rb a (q + S x - b2n rb) (tailw 0)).
L796new
160Lemmacl11
Lemma cl11 q rb a x: segRLs tmf (h^^(S (q*2 + b2n rb))) (h^^(S q))
(uw [] true (q + b2n rb + a) x (tailw 0)) (uw [] rb a (q + S (S x) - b2n rb) (tailw 0)).
L806new
161Definitionb2N
Definition b2N (b:bool) : N := if b then 1%N else 0%N.
L814new
162Lemmab2N_nat
Lemma b2N_nat b: N.to_nat (b2N b) = b2n b.
L815new
163Lemmadiv2_nat
Lemma div2_nat n: N.to_nat n = N.to_nat (N.div2 n) * 2 + b2n (N.odd n).
L817new
164DefinitionclosedU
Definition closedU (n:N) (u:unitN) : option (unitN * N) :=
if N.eqb n 0 then Some (u, 0%N) else
match ubs u with
| (c,j)::r =>
  if negb (ubit u) then
    if N.eqb n 1 then
… +22 lines
L820new
165LemmaclosedU_spec
Lemma closedU_spec n u u' p: closedU n u = Some (u', p) ->
segRLs tmf (h^^(N.to_nat n)) (h^^(N.to_nat p)) (uwN u) (uwN u').
L859new
166LemmazLs
Lemma zLs m: forall c j r x f, sideRLs tmf (h^^m) ((cw ((m+c,j)::r) ++ edgew x f) *> const 0)
((cw ((c,j)::r) ++ edgew x (m+f)) *> const 0).
L904new
167LemmazEs
Lemma zEs m: forall y f, sideRLs tmf (h^^m) (edgew (m+y) f *> const 0) (edgew y (m+f) *> const 0).
L913new
168DefinitionclosedZ
Definition closedZ (m:N) (z:zN) : option zN :=
if N.eqb m 0 then Some z else
match z with
| Z0 [] y f => if N.ltb y m then None else Some (Z0 [] (y - m) (f + m))
| Z0 ((c,j)::r) x f => if N.ltb c m then None else Some (Z0 (((c - m)%N, j)::r) x (f + m))
| ZD _ _ _ _ _ => None
… +1 lines
L920new
169LemmaclosedZ_spec
Lemma closedZ_spec m z z': closedZ m z = Some z' -> sideRLs tmf (h^^(N.to_nat m)) (zside z) (zside z').
L927new
170FixpointbatchL
Fixpoint batchL (n:N) (us:list unitN) (z:zN) : option (list unitN * zN) := match us with
| [] => match closedZ n z with Some z' => Some ([], z') | None => None end
| u :: us => match closedU n u with
  | Some (u', p) => match batchL p us z with Some (us', z') => Some (u' :: us', z') | None => None end
  | None => None end end.
L943new
171LemmabatchL_spec
Lemma batchL_spec us: forall n z us' z', batchL n us z = Some (us', z') ->
sideRLs tmf (h^^(N.to_nat n)) (dwords us *> zside z) (dwords us' *> zside z').
L948new
172Definitionevt_unit
Definition evt_unit (u:unitN) : N :=
let own := match ubs u with (c,_)::_ => N.succ c | [] => (2 * ua u + b2N (ubit u))%N end in
let own := if negb (ubit u) && N.eqb (ux u) 0 then 1%N else own in
if N.eqb (ug u) 0 then own else N.min own (if ubit u then 1%N else 2%N).
L960new
173Definitionevt_z
Definition evt_z z : N := match z with Z0 [] y _ => N.succ y | Z0 ((c,_)::_) _ _ => N.succ c | ZD _ _ _ _ _ => 1%N end.
L964new
174Definitionfirst_inc
Definition first_inc (C q n : N) : N := (n * 2^q - C mod 2^q)%N.
L965new
175Fixpointcval
Fixpoint cval (us:list unitN) (i:N) : N := match us with
| [] => 0%N | u :: us => ((if ubit u then 2^i else 0) + cval us (N.succ i))%N end.
L966new
176Fixpointpmin
Fixpoint pmin (us:list unitN) (i C:N) (z:zN) : N := match us with
| [] => first_inc C i (evt_z z)
| u :: us => N.min (first_inc C i (evt_unit u)) (pmin us (N.succ i) C z) end.
L968new
177Definitionpropose
Definition propose (us:list unitN) (z:zN) : N := N.pred (pmin us 0 (cval us 0) z).
L971adapted
178Definitionbatch_step
Definition batch_step c : option cfg := match ctl c with
| TT t g => if N.eqb g 0 then
    let d := propose (cus c) (cz c) in
    if N.eqb d 0 then None else
    match batchL d (cus c) (cz c) with Some (us', z') => Some (Cfg (TT (t + d) 0) us' z') | None => None end
  else None
… +1 lines
L974adapted
179Lemmabatch_step_spec
Lemma batch_step_spec c c': batch_step c = Some c' -> denote c -->* denote c'.
L981new
180Definitionnext
Definition next c : cfg + unit := match batch_step c with
| Some c' => inl c'
| None => match inc1 c with IOk c' => inl c' | IHalt => inr tt | IFail => inl c end end.
L991adapted
181Lemmanext_spec
Lemma next_spec c: match next c with inl c' => denote c -->* denote c' | inr _ => halts tmf (denote c) end.
L994new
182Definitionc342
Definition c342 := Cfg (NTl 1 1) [] (Z0 [(0%N,3%N)] 0 1).
L1002new
183Definitioncheck
Definition check fuel := match N_iter_until next (inl c342) fuel with inl _ => false | inr _ => true end.
L1003adapted
184Theoremcheck_spec
Theorem check_spec fuel: check fuel = true -> halts tmf (denote c342).
L1004adapted
185Definitionrun
Definition run (T:N) (c:cfg) : cfg + unit := N_iter_until next (inl c) T.
L1020new
186Definitionunl
Definition unl (x:cfg + unit) : cfg := match x with inl c => c | inr _ => c342 end.
L1021new
187Lemmarun_ok
Lemma run_ok T c c': run T c = inl c' -> denote c -->* denote c'.
L1022new
188Lemmarun_halt
Lemma run_halt T c: run T c = inr tt -> halts tmf (denote c).
L1033new
189Definitionk1
Definition k1 := Eval vm_compute in unl (run 5000 c342).
L1045new
190Lemmas1
Lemma s1: run 5000 c342 = inl k1.
L1046new
191Definitionk2
Definition k2 := Eval vm_compute in unl (run 5000 k1).
L1047new
192Lemmas2
Lemma s2: run 5000 k1 = inl k2.
L1048new
193Definitionk3
Definition k3 := Eval vm_compute in unl (run 5000 k2).
L1049new
194Lemmas3
Lemma s3: run 5000 k2 = inl k3.
L1050new
195Definitionk4
Definition k4 := Eval vm_compute in unl (run 5000 k3).
L1051new
196Lemmas4
Lemma s4: run 5000 k3 = inl k4.
L1052new
197Definitionk5
Definition k5 := Eval vm_compute in unl (run 5000 k4).
L1053new
198Lemmas5
Lemma s5: run 5000 k4 = inl k5.
L1054new
199Definitionk6
Definition k6 := Eval vm_compute in unl (run 5000 k5).
L1055new
200Lemmas6
Lemma s6: run 5000 k5 = inl k6.
L1056new
201Definitionk7
Definition k7 := Eval vm_compute in unl (run 5000 k6).
L1057new
202Lemmas7
Lemma s7: run 5000 k6 = inl k7.
L1058new
203Definitionk8
Definition k8 := Eval vm_compute in unl (run 5000 k7).
L1059new
204Lemmas8
Lemma s8: run 5000 k7 = inl k8.
L1060new
205Definitionk9
Definition k9 := Eval vm_compute in unl (run 5000 k8).
L1061new
206Lemmas9
Lemma s9: run 5000 k8 = inl k9.
L1062new
207Definitionk10
Definition k10 := Eval vm_compute in unl (run 5000 k9).
L1063new
208Lemmas10
Lemma s10: run 5000 k9 = inl k10.
L1064new
209Definitionk11
Definition k11 := Eval vm_compute in unl (run 5000 k10).
L1065new
210Lemmas11
Lemma s11: run 5000 k10 = inl k11.
L1066new
211Definitionk12
Definition k12 := Eval vm_compute in unl (run 5000 k11).
L1067new
212Lemmas12
Lemma s12: run 5000 k11 = inl k12.
L1068new
213Definitionk13
Definition k13 := Eval vm_compute in unl (run 5000 k12).
L1069new
214Lemmas13
Lemma s13: run 5000 k12 = inl k13.
L1070new
215Definitionk14
Definition k14 := Eval vm_compute in unl (run 5000 k13).
L1071new
216Lemmas14
Lemma s14: run 5000 k13 = inl k14.
L1072new
217Definitionk15
Definition k15 := Eval vm_compute in unl (run 5000 k14).
L1073new
218Lemmas15
Lemma s15: run 5000 k14 = inl k15.
L1074new
219Definitionk16
Definition k16 := Eval vm_compute in unl (run 5000 k15).
L1075new
220Lemmas16
Lemma s16: run 5000 k15 = inl k16.
L1076new
221Definitionk17
Definition k17 := Eval vm_compute in unl (run 5000 k16).
L1077new
222Lemmas17
Lemma s17: run 5000 k16 = inl k17.
L1078new
223Definitionk18
Definition k18 := Eval vm_compute in unl (run 5000 k17).
L1079new
224Lemmas18
Lemma s18: run 5000 k17 = inl k18.
L1080new
225Definitionk19
Definition k19 := Eval vm_compute in unl (run 5000 k18).
L1081new
226Lemmas19
Lemma s19: run 5000 k18 = inl k19.
L1082new
227Definitionk20
Definition k20 := Eval vm_compute in unl (run 5000 k19).
L1083new
228Lemmas20
Lemma s20: run 5000 k19 = inl k20.
L1084new
229Definitionk21
Definition k21 := Eval vm_compute in unl (run 5000 k20).
L1085new
230Lemmas21
Lemma s21: run 5000 k20 = inl k21.
L1086new
231Lemmas22
Lemma s22: run 5000 k21 = inr tt.
L1087new
232Lemmainit
Lemma init: c0 -[tmf]->* denote c342.
L1088adapted
233Lemmahalt_tmf
Lemma halt_tmf: halts tmf c0.
L1090new
234Lemmahalt
Lemma halt: halts tm c0.
L1117adapted
4What a maintainer readsCheck: the rule table below is what the .v proves, and proof.md / README read cleanly for a maintainer.
submission/proof.md line 134: 3. The rules

An increment is one carry. It enters at the right end and moves left one unit at a time. Each unit it reaches is touched: it changes as below and either stops the carry or passes it on to the left.

3.1 Stop and pass

In every touch of a digit, all of its passive stacks move two cells to the right and the right end of its lead moves one cell to the right. The lead flips.

touch when change the carry
stop lead 00, x ≥ 2 lead becomes 1111, x decreases by 1 stops
pass lead 1111, left boundary 11 lead becomes 00, x increases by 3 goes on to the left
halt single-marker, lead 00, y = 0 the machine halts (§3.6) —

The fuel changes the same way in a stop and in a pass:

digit change
single-marker y decreases by 1
multi-marker m_1 increases by 1, y decreases by 2 (glue when y = 1, §3.2)

The inner gaps m_2, …, m_r do not change.

3.2 Glue

A multi-marker digit touched with y = 1 would get y = −1. Instead its last stack runs into the boundary on its right:

… m_r  1^(3j+1)  [1]  1^(3g+2) …    ->    … m_r  1^(3(g+j)+2) …

The digit loses its last stack Q_r = 1^(3j+1), and the boundary to its right now carries g + j glued walls.

The digit's new fuel is the gap that was left of the lost stack, as it stands after the touch: m_r if r ≥ 2 (the touch leaves it unchanged), and m_1 + 1 if r = 1 (the touch adds 1 to m_1).

3.3 Unglue

A digit with lead 1111 whose left boundary carries g ≥ 1 glued walls is not passed as in §3.1. The glued walls came from the left neighbour, and now they enter this digit:

1^5      [x, 1111, m_1, Q_1, …, y]   ->   11 [2, 00, x+1, 1111, m_1, Q_1, …, y−2]
1^(3g+2) [x, 1111, m_1, Q_1, …, y]   ->   11 [2, 00, 0, 1^(3g−2), x, 1111, m_1, Q_1, …, y−2]     (g ≥ 2)
  • The first glued wall becomes the new lead. It has just been passed, so it is 00.
  • For g ≥ 2 the other g − 1 glued walls follow as one stack.
  • The old lead 1111 becomes a passive wall.
  • The boundary is plain 11 again, and the carry goes on to the left.

For a single-marker digit the part m_1, Q_1, … is empty, so [x, 1111, y] becomes [2, 00, x+1, 1111, y−2]. As always, y − 2 = −1 means a glue instead (§3.2).

3.4 The unit next to the edge

An increment whose carry passes every digit U_1, …, U_n is an overflow; it touches U_0.

U_0 edge effect
leadless [x, Q_1, …, y] e ≡ 0 e grows by 3; y decreases by 2, or glue when y = 1; x and the inner gaps stay
empty [y], y ≥ 3 e ≡ 0 e grows by 3; y decreases by 2
empty [1] e ≡ 0 absorption: the edge and b_1 = 11 merge into a new edge 1^(e+4); U_1 becomes U_0
a digit, lead 00 e ≡ 1 a stop, as in §3.1
a digit, lead 1111 e ≡ 1 fossilization, below

Fossilization. The old edge becomes a passive stack, the old lead becomes a passive wall, and a new edge 111 starts at the left end:

1^e [x, 1111, m_1, Q_1, …, y]   ->   111 [1, 1^e, x, 1111, m_1, Q_1, …, y−2]        (e ≡ 1 mod 3)

U_0 is then leadless and the edge is ≡ 0 again. The stacks left behind by the fossilizations form the far left part of the tape.

3.5 Tail and resets

Every increment adds 2 to the tail: t becomes t + 2.

A reset takes two increments. It starts when the least significant digit has glued its last stack onto the tail boundary, so that b_T = 1^5:

… 1^5 [t] A>          ->   … 11 [2, 00, t+2] A>                   (first increment)
… b [2, 00, y] A>     ->   … b [1, 1111, y−2] 11 [1] A>           (second increment)
  • In the first increment the old tail becomes the fuel of a new least significant digit. Its lead is the glued wall, already passed, so the carry goes on into the digits to the left.
  • In the second increment the new digit stops the carry at once, and a new tail [1] appears.
  • The boundary b left of the new digit is 11, unless the carry of the first increment glued walls onto it.

The configuration at step 342 is the state between the two increments of a reset, with b = 1^5.

3.6 The halt

A carry that touches a single-marker digit [x, 00, 0] halts the machine. There the tape reads

… 00 11 …

the lead 00 followed at once by the digit's right boundary. By §1 this is the halting pattern: the head reaches the left 1 of 11 in state F, with 0 0 to its left.

3.7 What the rules exclude

No rule covers these shapes:

  • a stop with x = 0;
  • a tail boundary with two or more glued walls;
  • an absorption when there is no digit left to become U_0;
  • the halting shape [x, 00, 0] in U_0.

If the run ever reached such a shape, the checker of §8 would stall and never report the halt. It does report it, so these shapes never occur on the run.

The edge class always matches U_0: an absorption leaves a U_0 digit with e ≡ 1, a fossilization leaves a leadless U_0 with e ≡ 0, and edge growth keeps e mod 3.

5FamilyCheck: related machines are killed together or have a reason to be left open.

No related machine found (no parent link, table twin, follow-on row or mention).

6ChecklistCheck: every ✓ is computed; the two ○ are yours to decide; an amber ! is an optional check that did not finish.
  • ✓
    Machine string exact
    the .v literal == holdout list line 587 byte for byte
  • ✓
    Statement is halts tm c0
    parsed from the .v and confirmed by check_kill (theorem_text, theorem_rocq)
  • ✓
    No axioms beyond baseline
    1 assumption(s); tools/assumptions_baseline.txt allows only functional_extensionality_dep
  • ✓
    coqchk finished (optional)
    coqchk pass in 536.46 s
  • ✓
    .v hash matches the checked hash
    .v = checked sha256 198b30225e7c…; submission/ copy = checked sha256 198b30225e7c…
  • ✓
    No repo-local paths in the .v
    comments name no path of ours (vendor/, machines/, tools/, rocq/, scripts/, reports/, atlas/, data/, journal/, /home/); busycoq's own verify/X.v is fine: none in the .v or the submission/ copy
  • ✓
    Public write-up is clean
    tools/writeup_lint.py on submission/proof.md: 0 error(s)
  • ○
    proof.md reviewed by Dennis (Checkpoint B)
    no Checkpoint B note from Dennis found
    • notes.md L564: - Checkpoint B is pending (non-blocking); there are no notes to fold in yet. Nothing posted.
    • proof.md L527: - Checkpoint B is pending (non-blocking); there are no notes to fold in yet.
  • ○
    Family posted together?
    no other kill in the family

Generated by tools/killreview.py at 2026-10-16 13:29 PDT in 0.1 s from the files linked above; nothing in this review is hand-written except the box “How we proved it halts” (above), which quotes how_proved.md. Re-run: python3 -B tools/killreview.py 1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB

Files

machines/<tm>/: 11 entries · raw notes, status, scripts, images

namesizechanged
notes.md ↓40 KB2026-10-12 20:47
proof.md ↓27 KB2026-10-12 21:04
how_proved.md ↓1.6 KB2026-10-14 10:51
status.json ↓1.7 KB2026-10-14 09:08
observe.json ↓9.2 KB2026-10-12 15:25
1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB.v ↓64 KB2026-10-13 10:20
img/6 items2026-10-12 14:50
rocq/11 items2026-10-13 10:49
submission/5 items2026-10-13 09:12
work/67 items2026-10-12 17:25
rocq-plan.md ↓17 KB2026-10-12 17:50
status.json in full
{
 "tm": "1RB0RD_1LC0RA_---1RD_1RA1LE_1RC0LF_1LE0LB",
 "label": "C2-552",
 "status": "KILLED_HALT",
 "stage": "done",
 "updated": "2026-10-13",
 "reason": "check_kill --halt PASS, independently re-verified",
 "halt_steps": {
  "exact": "176522930997643289094015905898381767890130463",
  "approx": "1.765e44",
  "convention": "steps including the halting transition (tools/sim convention); busycoq halts_in n = exact - 1",
  "busycoq_halts_in_n": "176522930997643289094015905898381767890130462",
  "proven_in_coq": false,
  "basis": "computed from per-rule step formulas summed over the same run (work/steps_exact/, exact_steps.json); formulas exact on all 276,427 increments to 1e11 and on all 53,973 single-stepped increments (reduced tapes); the .v proves halts tm c0 only",
  "lower_bound": "87364406466050439442427007228199699615332500",
  "halting_increment_after_step342": "11631266794472450654093",
  "resets_before_halt": 82
 },
 "check_kill": {
  "result": "PASS",
  "mode": "halt",
  "sha256": "198b30225e7ccff843808791746c4351a52277da10691ee5791a1cf205712805",
  "compile_s": 70.0,
  "coqchk_s": 536.5,
  "coqchk_cap_s": 600,
  "assumptions": [
   "functional_extensionality_dep"
  ],
  "log": "submission/check_kill.txt",
  "checked_at": "2026-10-13T17:33:35Z",
  "raw": [
   "rocq/check_kill_2026-10-13_fix1.out"
  ]
 },
 "funded": {
  "option": "class2_closeout",
  "date": "2026-10-12"
 },
 "pr": "https://github.com/ccz181078/busycoq/pull/18",
 "pr_state": "merged",
 "pr_comments": 0,
 "posted": "2026-10-13 (bbchallenge Discord, by Dennis)",
 "pr_file": "verify/Skelet1LikeC2Halt_1RB0RD_1LC0RA.v",
 "pr_merged_at": "2026-10-14T06:20:40Z",
 "pr_merged_by": "ccz181078",
 "pr_merge_commit": "cdaf693"
}