BB(6) hunt
Machines / W5-4

1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB

W5-4local proof 31Kill claimedBell eats counterbbchallenge ↗Explorer

How we proved it never halts

A size bound plus a remainder that never hits zero

Most of the tape is a long row of 10 pairs, the "bell", with one 00 in it, the "wall"; at the right end sits a counter whose bits sit every third cell (a 0 means the bit is set). Each round trip of the head moves the wall two pairs right and counts the counter down by 1. When the bell ahead of the wall is used up, the wall bites the counter's low end, and usually the pairs behind the wall become the new bell. But a bite on set low bits starts smaller nested copies of the whole process on the rest of the counter.

The only way to halt is a bite on a counter with every bit set, exactly when two pairs of bell remain. At each cycle start the proof tracks two facts. The bell is long: at least 2 pairs more than a power of 2 set by the counter's width. And a certain mix of bell length, width and counter value leaves remainder 1 or 2 when divided by 3; each cycle swaps the two, so it is never 0.

Why that settles it: among long-bell starts, the ones headed for the halt all have remainder 0, apart from one small state the proof excludes separately. The nested copies, and the rest of a cycle after them, start with an odd bell when the width is not a multiple of 3, which cannot reach the halt either. Nobody knows whether nested copies always finish, so the proof shows "no halt within N steps" for every N, by induction, from the good start reached at step 327.

The Rocq proof checks every move as an exact run, the arithmetic of rounds and bites, both invariants and that induction, and runs the 327-step opening directly.

#31local proof number
1,039lines of Rocq
35 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

Wall walks the bell, counting a zone down; bites its low end each cycle. Halts only if an overflow hits q=4.

Submitted mechanism Counter and bell. A bell (10)^q with a wall 00, then a zone holding a binary counter whose bits sit 3 cells apart (a set bit is a 0). Each round trip from the wall moves the wall 2 pairs right and decrements the counter. At 0 an overflow resets the counter according to the zone width modulo 3 (rules O0–O2 of the write-up). (submission/README.md, Mechanism)

Upstream
Kill claimed · PR #28merged 2026-10-16 07:09 UTC by ccz181078 · PR_BEC.v · TM5 · on Submissions →
Rocq proof
check_kill PASS · first Oct 13 13:03
1,039 lines · 45 KB .v · compile 34.7 s · coqchk pass · 0 axioms · PASS Oct 13 13:03
· the .v file
Automatic review
6 of 6 checks passtemplate: verify/BECv5.v Module TM1 (adapted from) · details in Proof →
Class
Bell eats counterours: Bell eats counter (sheet) · ours adds: two-level: a down-counting binary zone (bits 3 cells apart, anchored at the far end) bitten from its low end; W4-2's architecture mirrored · med confidence
On the list
not on BB6_holdouts_663.txt (line 525 of the previous list) · historical 740 line 525
eqv ×1sim 1e15
Your calls on file 3
funded
option: proof · date: 2026-10-13
next
post the Discord draft (submission/discord.md, not posted; fill in <LINK>, search #bb6 first); add to the next upstream PR batch
2026-10-13 · proof
Fund one more stage on W5-4 to close the two open sub-lemmas and write proof.md, then formalize, or park it at the invariant stage? (Dennis 2026-10-13: 'go with recommendations')

Mechanism

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

How it works: 3 notes
  • R(p,q,Z) = 0^inf (10)^p 1 C> 0 0 (10)^q Z: each round the wall 00 moves 2 pairs right (q-2) and the zone Z counts down by 1 (zeros = set bits on the lattice j = w-1-3i); at v = 0 it refills (O0/O1/O2). At q <= 2 the wall bites Z's low end (B0/B1/B2/B2') and a new cycle starts with n one or two pairs longer.
  • Two levels: per two calm cycles v drops by 1; near n = 2^(L+1) the zone gains a bit (level-up), sometimes through a chaotic phase of nested bites (B2'', closed as a stack of the same rules in Wave 5). The closed rules reproduce the direct run at all 4,197 cycle starts to 1e11.
  • Why it never halts (Wave 5): the invariant I = {d = n - 2^(cap+1) >= 2, M = n + 2v - 2^(cap+2) != 0 mod 3}. Every rule keeps M or negates it mod 3, and the only halting starts from d >= 2 have M = 0. The blank run is in I from step 327. Checked on 7.9M states; two sub-lemmas (continuation cycles, nested levels) still need a paper argument.

Figures for Checkpoint A

Fig 1 · bbchallenge default view, first 10,000 steps

The site's view. The striped middle is the bell (10)^n; the dense band at the right edge is the zone.

bbchallenge default view, first 10,000 steps
bbchallenge-defaultStart blankRows 10,000 steps squeezed into 500 px rowsWindow cells -200..199, 1 px = 1 cellColors 1 0 or never visited head after a right/left move
Rows: 1 px row = 20 steps, the site's bilinear squeeze
Fig 2 · One cycle: the wall walks rightQ1

Each thin diagonal is one round. Compare the wall's start per round and the zone width at the right edge.

One cycle: the wall walks right
bbchallenge-defaultStart constructed: 0∞ C> 0 0 (10)36 12 0 12 0 12 0 12 0 13 0∞Rows every 4 stepsWindow cells -1..89, 1 px = 1 cellColors 1 0 or never visited head after a right/left move
Rows: 1,149 rows, steps 0..4,592 (= blank-tape steps 53,839..58,431, one cycle start to the next)
Fig 3 · Counter fill per cycle, levels 3 to 21Q2

One dot per cycle. Follow one descending curve (a calm level), then look at the scatter where curves restart (level-ups).

Counter fill per cycle, levels 3 to 21
customStart blankRows one dot per cycle start R(-1,n,Z)Window x = log2 n from 3 to 21Colors zone width w = 0 mod 3 w = 2 mod 3 w = 1 mod 3 y 0.25
Rows: cycles 1..1,100,000 of the abstract run (scripts/absim.py, equal to the direct run at all 4,200 cycle starts to 1e11 steps) · Window: (n = bell length at the cycle start), 1 px = 0.0205; y = v/2^L from 0 (bottom line) to 1 (top line) · Colors: grey vertical lines = integer log2 n; 0.5, 0.75
More figures (2)Fig 4–5: One round, step by step · Nested bite (no closed form yet)
Fig 4 · One round, step by step

A zig-zag carries a gadget right along the bell; it decrements the zone, then blue C walks back.

One round, step by step
bbchallenge-exploreStart constructed: 0∞ 1 0 1 C> 0 0 (10)8 15 0 12 0 12 0 13 0∞Rows every step, steps 0..99Window cells -3..32, 1 px = 1/10 cellColors 0 1
Rows: (one round: R(1,8,Z) to R(3,6,dec Z) at step 98), 10 px per row · Colors: head colour = state: red A, orange B, blue C, green D, magenta E, cyan F
Fig 5 · Nested bite (no closed form yet)

Two walls form at once; the inner one runs short rounds on the zone's low end first.

Nested bite (no closed form yet)
bbchallenge-exploreStart constructed: 0∞ (10)4 1 C> 0 0 (10)2 12 0 12 0 15 0 12 0 12 0 13 0∞Rows every step, steps 0..80Window cells -9..26, 1 px = 1/10 cellColors 0 1
Rows: (R(4,2,(110)^2 1^5 0 1^2 0 1^2 0 1^3) to R(6,5,1^4 0 1^2 0 1^3) at step 74), 10 px per row · Colors: head colour = state: red A, orange B, blue C, green D, magenta E, cyan F
Rules (11/12 validated)exact tape rewrites the proof will formalize, each re-checked by simulation
rulefrom ⟶ tocasesstepschecked
init
0∞ A> 0∞
⟶ 0∞ C> 0 0 12 0∞
= R(-1,0,11); the next cycle starts follow from the rules below (abstract run = direct run at 4,200 cycle starts)4✓1/1
R1 round
0∞ (10)p 1 C> 0 0 (10)q Z 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q-2 dec(Z) 0∞
q >= 3, Z has a zero, w = 0 or 2 mod 3; dec: leftmost zero j -> 1, zeros at j-3, j-6, ... >= 2—✓150/150
R2 round
0∞ (10)p 1 C> 0 0 (10)q Z 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q-3 11 dec(Z) 0∞
q >= 3, Z has a zero, w = 1 mod 3 (one bell pair joins the zone)—✓150/150
O2 overflow
0∞ (10)p 1 C> 0 0 (10)q 1w 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q-2 (110)(w-2)/3 111 0∞
q >= 3, w = 2 mod 3: zone + 1 cell, all bits set (v = 2^L - 1)—✓52/52
O1 overflow
0∞ (10)p 1 C> 0 0 (10)q 1w 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q-2 allset(w+1) 0∞
q >= 3, w = 1 mod 3; allset(u) = every lattice position >= 2 set—✓53/53
O0 overflow
0∞ (10)p 1 C> 0 0 (10)q 1w 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q-3 15 (0 12)w/3-1 0 13 0∞
q >= 3, w = 0 mod 3: zone + 3 cells, v = 2^L - 2—✓45/45
B2 bite
0∞ (10)p 1 C> 0 0 (10)2 111 Y 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 10 1 Y 0∞
q = 2, zone starts 111; re-parse: a leading 10 of 1Y joins the bell14✓150/150
B2' bite, k=1
0∞ (10)p 1 C> 0 0 (10)2 110 111 Y 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)3 Y 0∞
q = 2, lowest bit set, next clear; Y starts 1132✓150/150
H halt
0∞ (10)p 1 C> 0 0 (10)2 (110)k 111 0∞
⟶ halt
q = 2 and every bit set, k >= 1<= 60✓150/150
B1 bite
0∞ (10)p 1 C> 0 0 10 1 Y 0∞
⟶ 0∞ C> 0 0 (10)p+3 Y 0∞
q = 1, zone 1Y starts 11; re-parse leading 10 of Y; new cycle with n = p+3—✓150/150
B0 bite
0∞ (10)p 1 C> 0 0 Z 0∞
⟶ 0∞ C> 0 0 (10)p+3 dec(Z)[3:] 0∞
q = 0, w = 0 mod 3, Z starts 111 (f = 2: n = p+2 and zone 11 Z[3:], 30/30)—✓120/120
B2'' nested bite
0∞ (10)p 1 C> 0 0 (10)2 (110)k 13a+5 0 Y 0∞
⟶ 0∞ (10)p+2 1 C> 0 0 (10)q' Z' 0∞
q = 2, k >= 2 low bits set: an inner wall re-runs rounds on the low part; q' = 5..15, Z' a suffix of Z (top cells sometimes changed). No closed form yet; 49 of 204,953 transitions to 1e9—–untested
Compressed historythe tape as 0∞ C> 0 0 (10)n Z 0∞ (cycle start R(-1,n,Z); Z has width w, counter value v, L bits) at 37 moments: where the rules are read off
0∞ C> 0 0 (10)n Z 0∞ (cycle start R(-1,n,Z); Z has width w, counter value v, L bits)
stepnwvL
1163601
2444811
3276500
6758611
1,16710601
1,87511922
3,71215912
6,28118902
11,559221112
19,917271253
34,268321223
58,4303715144
104,5304515104
179,487541564
325,977661504
568,4948118305
1,015,5949818175
1,819,7921181875
3,217,29614121586
5,662,17917021446
10,090,49720621266
17,830,5182492146
31,972,323316261267
56,366,70739718155
100,571,21749324577
177,845,615608292128
317,209,75375420155
562,863,50287427778
1,002,875,7951,0142968
1,781,927,4171,196304279
3,167,681,3111,426303129
5,625,645,7421,711301699
10,005,286,0112,0721473
17,798,996,3342,5083379610
31,649,029,6403,0243353810
56,244,128,0793,6523522310
99,952,253,5204,417361,88811
nlast 4,417
4,41731161e11log xstep 116: n = 3step 244: n = 4step 327: n = 6step 675: n = 8step 1167: n = 10step 1875: n = 11step 3712: n = 15step 6281: n = 18step 11559: n = 22step 19917: n = 27step 34268: n = 32step 58430: n = 37step 104530: n = 45step 179487: n = 54step 325977: n = 66step 568494: n = 81step 1015594: n = 98step 1819792: n = 118step 3217296: n = 141step 5662179: n = 170step 10090497: n = 206step 17830518: n = 249step 31972323: n = 316step 56366707: n = 397step 100571217: n = 493step 177845615: n = 608step 317209753: n = 754step 562863502: n = 874step 1002875795: n = 1014step 1781927417: n = 1196step 3167681311: n = 1426step 5625645742: n = 1711step 10005286011: n = 2072step 17798996334: n = 2508step 31649029640: n = 3024step 56244128079: n = 3652step 99952253520: n = 4417
wlast 36
3651161e11log xstep 116: w = 6step 244: w = 8step 327: w = 5step 675: w = 6step 1167: w = 6step 1875: w = 9step 3712: w = 9step 6281: w = 9step 11559: w = 11step 19917: w = 12step 34268: w = 12step 58430: w = 15step 104530: w = 15step 179487: w = 15step 325977: w = 15step 568494: w = 18step 1015594: w = 18step 1819792: w = 18step 3217296: w = 21step 5662179: w = 21step 10090497: w = 21step 17830518: w = 21step 31972323: w = 26step 56366707: w = 18step 100571217: w = 24step 177845615: w = 29step 317209753: w = 20step 562863502: w = 27step 1002875795: w = 29step 1781927417: w = 30step 3167681311: w = 30step 5625645742: w = 30step 10005286011: w = 14step 17798996334: w = 33step 31649029640: w = 33step 56244128079: w = 35step 99952253520: w = 36
vlast 1,888
1,88801161e11log xstep 116: v = 0step 244: v = 1step 327: v = 0step 675: v = 1step 1167: v = 0step 1875: v = 2step 3712: v = 1step 6281: v = 0step 11559: v = 1step 19917: v = 5step 34268: v = 2step 58430: v = 14step 104530: v = 10step 179487: v = 6step 325977: v = 0step 568494: v = 30step 1015594: v = 17step 1819792: v = 7step 3217296: v = 58step 5662179: v = 44step 10090497: v = 26step 17830518: v = 4step 31972323: v = 126step 56366707: v = 15step 100571217: v = 57step 177845615: v = 212step 317209753: v = 15step 562863502: v = 77step 1002875795: v = 6step 1781927417: v = 427step 3167681311: v = 312step 5625645742: v = 169step 10005286011: v = 7step 17798996334: v = 796step 31649029640: v = 538step 56244128079: v = 223step 99952253520: v = 1888
Llast 11
1101161e11log xstep 116: L = 1step 244: L = 1step 327: L = 0step 675: L = 1step 1167: L = 1step 1875: L = 2step 3712: L = 2step 6281: L = 2step 11559: L = 2step 19917: L = 3step 34268: L = 3step 58430: L = 4step 104530: L = 4step 179487: L = 4step 325977: L = 4step 568494: L = 5step 1015594: L = 5step 1819792: L = 5step 3217296: L = 6step 5662179: L = 6step 10090497: L = 6step 17830518: L = 6step 31972323: L = 7step 56366707: L = 5step 100571217: L = 7step 177845615: L = 8step 317209753: L = 5step 562863502: L = 8step 1002875795: L = 8step 1781927417: L = 9step 3167681311: L = 9step 5625645742: L = 9step 10005286011: L = 3step 17798996334: L = 10step 31649029640: L = 10step 56244128079: L = 10step 99952253520: L = 11
Template comparison1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF.v: partly applies · the nearest solved proof, what carries over, and the transitions that differ
01
A1RB0RC
B1LC1RB
C0RE1LD
D0LC1LA
E1RF1RA
F---0RB
file
machines/1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF/1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF.v ⚠ not at pin (W4-2 kill, from BECv5.v TM1/TM2)
module
—
machine
1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF (11 transitions apart)
diff
not a near table: architecture match only (mirrored bell + counter + bite)
note
Same plan: bell with a moving defect, counter bumped per pass, low-end bite, rare nested eating, halting needs a coincidence; proof via an invariant in progress_nonhalt_cond. Different: counter counts down, bits 3 apart anchored at the far end, defect moves 2 pairs per round, two-level slow counter (v -1 per 2 cycles, level-up at n ~ 2^(L+1)). W4-2's phi/Sweep lemmas do not transfer.
Proof strategy & riskshow the formal proof will go · 3 risks to watch

proof.md on the invariant I: the rules, Lemma M (mod-3 sign law, proved), Lemma K (d >= 2 closure, proved for plain cycles, checked exhaustively), and the entry at step 327. Then Rocq: one lemma per rule, the nested bite by induction on depth, progress_nonhalt_cond over I (W4-2's shape).

  • ▲Lemma K for cycles with a B2'/B2'' continuation has no paper argument yet; the data show slack (min d' = 5 where 2 is needed).
  • ▲No halt inside nested levels from K is only checked, not argued.
  • ▲The Rocq build of the nested bite (a recursion over walls) is the long part.
Stats & provenance1011 steps simulated · 2,058 cells · the status in full · files
simulated
1011 steps
tape
2,058 cells · 1,040 nonzeros
growth
span ~ 2058 cells at 1e9 (tools/sim.py), ~1.2·n^3 steps for bell length n; n = 4,417 at 1e11 (direct C event logger); abstract run to 3e7 cycles
status now
check_kill PASS, independently re-verified (status.json, 2026-10-13)
observer's note
Mechanism and rules validated; non-halting invariant (parity split of O2 overflows) and nested-bite closed form open.
files
observe.json · notes.md · proof.md · how_proved.md · status.json · 1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.v

Proof & checks

6/6 automatic checks pass

Kill 31 · Bell eats counter · the kill file 1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.v: 1039 lines, 129 items · the package submission/

✓ 6/6 automatic checks pass · Checkpoint B: no note from Dennis yet · template (adapted from): verify/BECv5.v Module TM1 · 3% 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
1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB
vs holdout list
✓ byte-exact: the .v literal (L23) == 2026-10-07_778.txt line 558 (41 bytes, via tools/holdouts.py)
Theorem
✓ Lemma nonhalt: ~halts tm c0. L1008
check_kill
✓ PASS · 17/17 checks pass · compile 34.71 s · coqchk pass (4.57 s) · assumptions: 0 (closed) · 2026-10-13 20:03:57 UTC · submission/check_kill.txt
Checked .v
sha256 f61649bdc6b6e97b…
✓1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.vf61649bdc6b6e97b… = checked
✓submission/1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.vf61649bdc6b6e97b… = checked
Status
✓Killed: never 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 nonhalt
✓input45662 bytes, 1039 lines, 1168 sentences
✓frameworkHEAD 0940bb9cf434ba68f0c025dabfde45a219999973 == pin; no tracked changes under verify/
✓framework_build13 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)
✓structure5 Require name(s) allowed; no top-level Variable/Context; no shadowing; Module/Section balanced
✓tm_textline 23: TM_from_str "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB" == <tm> (41 bytes)
✓theorem_textline 1008: nonhalt : ~halts tm c0
✓coqcoqc 8.20.1 (<opam-switch>/bin/coqc)
✓nameshalts, c0, TM_from_str resolved inside Individual62
✓compilecompiled in 34.7s with all appended checks
✓tm_rocqBB6Kill.Candidate.tm = BusyCoq.Individual62.TM_from_str "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB" by eq_refl (in-file and isolated)
✓theorem_rocqnonhalt : ~ halts (TM_from_str "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB") c0 with absolute names (in-file and isolated)
✓isolationonly stock proof plugins loaded; guard/positivity/universe checking on, definitional UIP off
✓assumptions0 assumption(s), all in the baseline
✓coqchkcoqchk -norec BB6Kill.Candidate ok (4.6s); 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).
3%of our lines identical to the template
0changed lines
850added lines (ours only)
121template lines dropped
1 / 1 / 127items identical / adapted / new
What the package README says it reused and changed (submission/README.md line 18, Template and what changed), quoted:

Adapted from busycoq's verify/BECv5.v, Module TM1: one es lemma per low-level rule and one counter-form lemma per macro rule. Changes: a decrementing counter on a 3-cell lattice whose overflow rule depends on the zone width modulo 3; nested bites, so the left side is a stack of frames; and a bounded induction on steps with phase invariants instead of progress_nonhalt_cond. The file has 1,039 lines, every lemma top level.

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 873 lines
3% identical · 0 changed · 850 added
template 144 lines
16% kept verbatim · 121 not in ours
our items 129
1 identical · 1 adapted · 127 new · 11 template-only
identicalchanged / adaptedours only (new)template only
Template part: lines 1–29 (shared header, before the first Module) + 31–165 (body of Module TM1; the Module/End lines left out). Ours: lines 15–1039 (header comment 1–14 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: highbit, LC0, R, tm', LInc0, LIncs, LIncs', RIncs, ROv, S, BigStep

Side-by-side diff: template (144 lines) vs ours (873 lines), 971 lines differ; runs of identical lines and long template-only runs folded
identicalequal once each TM string is <TM>changedours onlytemplate only
templateours
1From BusyCoq Require Import Individual62.16From BusyCoq Require Import Individual62.
2Require Import ZifyNat Lia.17Require Import ZifyNat Lia.
3Require Import ZArith.18Require Import ZArith.
4Require Import String.19Require Import String.
5From BusyCoq Require Import BinaryCounter_v2.
6From BusyCoq Require Import Longitudinal.
8Open Scope list.21Open Scope list.
10Ltac flia := repeat (lia||f_equal).
12Lemma highbit x:
⋯ 14 template-only lines (template 13–26), not in ours
27 cbn; lia.
28Qed.
32Definition tm := Eval compute in (TM_from_str "1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA0RB").23Definition tm := Eval compute in (TM_from_str "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB").
34Notation "c -->* c'" := (c -[ tm ]->* c') (at level 40).25Notation "c -->* c'" := (c -[ tm ]->* c') (at level 40).
35Notation "c -->+ c'" := (c -[ tm ]->+ c') (at level 40).26Notation "c -->+ c'" := (c -[ tm ]->+ c') (at level 40).
37Notation "l <| r" :=
28(** ** Low-level rules (proof.md 3.1). Left-side lists are written outward from the head. *)
38 (l <{{A}} [] *> r) (at level 30).
30Lemma BR k: forall l r, l {{B}}> [1]^^k *> r -->* [1]^^k *> l {{B}}> r.
40Notation "l |> r" :=
31Proof. es. Qed.
41 (l <* [] {{B}}> r) (at level 30).
33Lemma SW k: forall l r, [1;0]^^k *> l <{{C}} r -->* l <{{C}} [0;1]^^k *> r.
43Definition LC0 n := BinInc <[0;1] n.
34Proof. es. Qed.
44Definition R n m := [1] *> [1;0]^^(1+n) *> [0] *> [1;0]^^(m) *> const 0.
36Lemma TT j: forall l r, [1;1;1]^^j *> l <{{C}} r -->* l <{{C}} [0;1;1]^^j *> r.
46Notation hL := (A,[]).
37Proof. es. Qed.
47Notation hR := (B,[]).
39Lemma PS b: forall l r, [1;1;0] *> l {{B}}> [1;0]^^b *> r -->* [1;1] *> [0;1]^^b *> [0] *> l {{B}}> r.
48Notation hLR := [(hL,hR)].
40Proof. es. Qed.
49Notation hRL := [(hR,hL)].
42(** The round W, PS^(q-3), ZA, in three cases by f mod 3 (f = 3j+2, 3j+4, 3j+3). *)
51Definition tm' := flip tm.
43Lemma RND2 q j: forall l r,
53Lemma LInc0 r n:
44 l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;0] *> r -->+
54 LC0 n <| r -->*
45 [1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^(q+1) *> [1;1;0]^^j *> [1;1;1] *> r.
55 LC0 (1+n) |> r.
46Proof. es. Qed.
48Lemma RND1 q j: forall l r,
49 l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;1;1;0] *> r -->+
50 [1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^(q+1) *> [1;1;1;1] *> [0;1;1]^^j *> [1] *> r.
51Proof. es. Qed.
53Lemma RND0 q j: forall l r,
54 l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;1;0] *> r -->+
55 [1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^q *> [1;1;1;1;1] *> [0;1;1]^^j *> [1] *> r.
56Proof. es. Qed.
58(** PUSH k: the bite at q = 2 (B2 for k = 0, the nested bite N for k >= 1). *)
59Lemma PUSH k: forall l r,
60 l {{C}}> [0;0] *> [1;0]^^2 *> [1;1;0]^^k *> [1;1;1] *> r -->+
61 [1;0;0]^^k *> [1;0;1;0] *> l {{C}}> [0;0] *> [1;0] *> [1] *> r.
62Proof. es. Qed.
64(** Ending bites B1, B0, B0c: they read the left part (10)^p 1 and the 00 left of it. *)
65Lemma BITE1 p: forall l r,
66 [1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;0] *> [1;1] *> r -->+
67 l {{C}}> [0;0] *> [1;0]^^(p+3) *> [1] *> r.
68Proof. es. Qed.
70Lemma BITE0 p j: forall l r,
71 [1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1]^^j *> [1;1;0] *> r -->+
72 l {{C}}> [0;0] *> [1;0]^^(p+2) *> [1] *> [0;1;1]^^j *> [1] *> r.
73Proof. es. Qed.
75Lemma BITE0c p j: forall l r,
76 [1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1]^^j *> [1;1;1;1;1;1;0] *> r -->+
77 l {{C}}> [0;0] *> [1;0]^^(p+2) *> [1;1;1] *> [1;1;0]^^j *> [1;1;1] *> r.
78Proof. es. Qed.
80Lemma BITE0c3 p: forall l r,
81 [1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1;0;0] *> r -->+
82 l {{C}}> [0;0] *> [1;0]^^(p+1) *> [1;1;1;1;1;1] *> r.
83Proof. es. Qed.
85(** ** The counter zone: zone r L v = 1^r (1 1 c_0) ... (1 1 c_(L-1)) 1 1 1, width 3L+3+r,
86 c_b = 0 iff bit b of v is set (proof.md 2: the lattice of a width-w zone). *)
88Definition bitc (v : nat) : sym := if Nat.odd v then 0 else 1.
90Fixpoint dg (L v : nat) : list sym :=
91 match L with
92 | O => []
93 | S L' => [1;1;bitc v] ++ dg L' (Nat.div2 v)
94 end.
96Definition zone (r L v : nat) : list sym := [1]^^r ++ dg L v ++ [1;1;1].
98Lemma bitc_even v: bitc (2*v) = 1.
99Proof. unfold bitc. rewrite Nat.odd_mul. reflexivity. Qed.
101Lemma bitc_odd v: bitc (2*v+1) = 0.
102Proof. unfold bitc. rewrite Nat.add_1_r, Nat.odd_succ, Nat.even_mul. reflexivity. Qed.
104Lemma div2_even v: Nat.div2 (2*v) = v.
105Proof. apply Nat.div2_double. Qed.
107Lemma div2_odd v: Nat.div2 (2*v+1) = v.
108Proof. rewrite Nat.add_1_r. apply Nat.div2_succ_double. Qed.
110Lemma dg_even L v: dg (S L) (2*v) = [1;1;1] ++ dg L v.
111Proof. cbn [dg]. rewrite bitc_even, div2_even. reflexivity. Qed.
113Lemma dg_odd L v: dg (S L) (2*v+1) = [1;1;0] ++ dg L v.
114Proof. cbn [dg]. rewrite bitc_odd, div2_odd. reflexivity. Qed.
116Lemma pow_pos P: 1 <= 2^P.
117Proof. pose proof (Nat.pow_nonzero 2 P). lia. Qed.
119Lemma dg_zero L: dg L 0 = [1;1;1]^^L.
56Proof.120Proof.
57 unfold LC0.
121 induction L as [|L IH]; [reflexivity|].
58 er.
122 change (dg (S L) 0) with ([1;1;1] ++ dg L 0). rewrite IH. reflexivity.
59 eapply evstep_trans.
60 1: apply progress_evstep.
61 1: apply LBinInc_spec with (qL:=[]) (qR:=[]); es.
62 er.
63Qed.123Qed.
65Lemma LIncs n:
125Lemma dg_full L: dg L (2^L - 1) = [1;1;0]^^L.
66 sideRLs tm' (hLR^^n) (LC0 0) (LC0 n).
67Proof.126Proof.
68 induction n.
127 induction L as [|L IH]; [reflexivity|].
69 - esx.
128 replace (2^(S L) - 1) with (2*(2^L-1)+1) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos L); lia).
70 - replace (S n) with (n+1) by lia.
129 rewrite dg_odd, IH. reflexivity.
71 rewrite lpow_add.
72 eapply sideRLs_trans.
⋯ 4 template-only lines (template 73–76), not in ours
77 rw_Bin.
78 esx.
79Qed.130Qed.
81Lemma LIncs' n:
132Lemma dg_low b L o: dg (b + S L) (2^b*(2*o+1)) = [1;1;1]^^b ++ [1;1;0] ++ dg L o.
82 sideRLs tm' (hLR^^(n*2)) (LC0 n <* [0]) (LC0 0).
83Proof.133Proof.
84 unfold LC0.
134 induction b as [|b IH].
85 induction n using lt_wf_ind.
135 - replace (2^0*(2*o+1)) with (2*o+1) by (cbn; lia). apply dg_odd.
86 divmod2_cases n.
136 - replace (2^(S b)*(2*o+1)) with (2*(2^b*(2*o+1))) by (rewrite Nat.pow_succ_r'; lia).
87 - destruct (Nat.eqb_spec n' 0).
137 cbn [Nat.add]. rewrite dg_even, IH. reflexivity.
88 + subst.
89 esx.
⋯ 14 template-only lines (template 90–103), not in ours
104 replace ((n'*2+1)*2) with (n'*2*2+2) by lia.
105 apply segRLs_addmul''; esx.
106Qed.138Qed.
108Lemma RIncs n m:
140Lemma dg_lowones k L o: dg (k + S L) (2^k - 1 + 2^(S k)*o) = [1;1;0]^^k ++ [1;1;1] ++ dg L o.
109 sideRLs tm (hRL^^n) (R n m) (R 0 (n+m)).
110Proof.141Proof.
111 gen m.
142 induction k as [|k IH].
112 induction n; intros.
143 - replace (2^0 - 1 + 2^1*o) with (2*o) by (cbn; lia). apply dg_even.
113 - esx.
144 - replace (2^(S k) - 1 + 2^(S (S k))*o) with (2*(2^k - 1 + 2^(S k)*o)+1)
114 - replace (S n) with (1+n) by lia.
145 by (rewrite !Nat.pow_succ_r'; pose proof (pow_pos k); lia).
115 rewrite lpow_add.
146 cbn [Nat.add]. rewrite dg_odd, IH. reflexivity.
116 eapply sideRLs_trans.
117 2: applys_eq (IHn (1+m)); flia.
118 esx.
119Qed.147Qed.
121Lemma ROv k i m:
149Lemma lowbit (x:nat): x <> 0%nat -> exists P o, x = 2^P*(2*o+1).
122 LC0 ((k*2+1)*2^i-1) <| R 0 m -->+
123 LC0 k <* [0] <| R (1+i+m) 0.
124Proof.150Proof.
125 unfold LC0,R.
151 induction x as [x IH] using lt_wf_ind. intros Hx.
126 rw_Bin.
152 destruct (Nat.Even_or_Odd x) as [[x' Hx']|[x' Hx']]; subst x.
127 es.
153 - destruct (IH x') as [P [o Ho]]; [lia|lia|].
154 exists (S P), o. rewrite Nat.pow_succ_r'. lia.
155 - exists 0%nat, x'. cbn. lia.
128Qed.156Qed.
130Definition S '(a,b) := LC0 a <| R 0 b.
158Lemma lowbit_lt b o L: 2^b*(2*o+1) < 2^L -> b < L /\ o < 2^(L-b-1).
132Lemma BigStep k i m:
133 k*2<=(1+i+m) ->
134 S ((k*2+1)*2^i-1,m) -->+
135 S (1+i+m-k*2,1+i+m).
136Proof.159Proof.
137 unfold S.
160 intros H.
138 intros.
161 assert (Hb: b < L).
139 follow10 ROv.
162 { apply (Nat.pow_lt_mono_r_iff 2); [lia|]. pose proof (pow_pos b). nia. }
140 replace (1+i+m) with (k*2+(1+i+m-k*2)) by lia.
163 split; [exact Hb|].
141 epose proof (sideRLs_concat_1L (RIncs _ 0)) as I1.
164 replace L with (b + S (L-b-1)) in H by lia.
142 follow I1.
165 rewrite Nat.pow_add_r, Nat.pow_succ_r' in H.
143 - rewrite lpow_add.
166 pose proof (pow_pos b). nia.
144 eapply sideRLs_trans.
167Qed.
145 + apply LIncs'.
169Lemma ones_comm b: [1;1] ++ [1;1;1]^^b = [1;1;1]^^b ++ [1;1].
146 + apply LIncs.
170Proof. induction b as [|b IH]; [reflexivity|]. cbn [lpow]. rewrite <-List.app_assoc, <-IH. reflexivity. Qed.
147 - unfold to_DH_config.
172Lemma one_comm b: [1] ++ [1;1;1]^^b = [1;1;1]^^b ++ [1].
148 finish.
173Proof. induction b as [|b IH]; [reflexivity|]. cbn [lpow]. rewrite <-List.app_assoc, <-IH. reflexivity. Qed.
175Lemma sh110 b: [1;1] ++ [0;1;1]^^b = [1;1;0]^^b ++ [1;1].
176Proof. induction b as [|b IH]; [reflexivity|]. cbn [lpow]. rewrite <-List.app_assoc, <-IH. reflexivity. Qed.
178Lemma S_ones2 b s: [1;1] *> [1;1;1]^^b *> s = [1;1;1]^^b *> [1;1] *> s.
179Proof. rewrite <-!Str_app_assoc, ones_comm. reflexivity. Qed.
181Lemma S_ones1 b s: [1] *> [1;1;1]^^b *> s = [1;1;1]^^b *> [1] *> s.
182Proof. rewrite <-!Str_app_assoc, one_comm. reflexivity. Qed.
184Lemma S_sh110 b s: [1;1] *> [0;1;1]^^b *> s = [1;1;0]^^b *> [1;1] *> s.
185Proof. rewrite <-!Str_app_assoc, sh110. reflexivity. Qed.
187(** ** Counter forms of the round (proof.md 3.2), for any left side l *)
189Definition RT (l : side) (q : nat) (Z : list sym) : Q * tape := l {{C}}> [0;0] *> [1;0]^^q *> Z *> const 0.
191Lemma R1z l q L v: 1 <= v -> v < 2^L ->
192 RT l (q+3) (zone 0 L v) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 0 L (v-1)).
193Proof.
194 intros H1 H2. destruct (lowbit v) as [b [o ->]]; [lia|].
195 destruct (lowbit_lt _ _ _ H2) as [Hb Ho].
196 remember (L-b-1) as L'. replace L with (b + S L') by lia.
197 replace (2^b*(2*o+1) - 1) with (2^b - 1 + 2^(S b)*o) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos b); nia).
198 unfold RT, zone. rewrite dg_low, dg_lowones. cbn [lpow app].
199 rewrite !Str_app_assoc. apply RND2.
200Qed.
202Lemma R1t l q L v: 1 <= v -> v < 2^L ->
203 RT l (q+3) (zone 2 L v) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 2 L (v-1)).
204Proof.
205 intros H1 H2. destruct (lowbit v) as [b [o ->]]; [lia|].
206 destruct (lowbit_lt _ _ _ H2) as [Hb Ho].
207 remember (L-b-1) as L'. replace L with (b + S L') by lia.
208 replace (2^b*(2*o+1) - 1) with (2^b - 1 + 2^(S b)*o) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos b); nia).
209 unfold RT, zone. rewrite dg_low, dg_lowones. rewrite !Str_app_assoc.
210 change ([1]^^2) with [1;1]. rewrite S_ones2.
211 change ([1;1] *> [1;1;0] *> ?Y) with ([1;1;1;1;0] *> Y).
212 eapply progress_evstep_trans. 1: apply RND1. apply evstep_refl'.
213 change ([1;1;1;1] *> ?X) with ([1;1] *> [1;1] *> X). rewrite S_sh110. reflexivity.
214Qed.
216Lemma R2r l q L v: 1 <= v -> v < 2^L ->
217 RT l (q+3) (zone 1 L v) -->+ RT ([1;0;1;0] *> l) q (zone 0 (S L) (2*v-2)).
218Proof.
219 intros H1 H2. destruct (lowbit v) as [b [o ->]]; [lia|].
220 destruct (lowbit_lt _ _ _ H2) as [Hb Ho].
221 remember (L-b-1) as L'. replace L with (b + S L') by lia.
222 replace (2*(2^b*(2*o+1))-2) with (2*(2^b - 1 + 2^(S b)*o)) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos b); nia).
223 unfold RT, zone. rewrite dg_low, dg_even, dg_lowones. rewrite !Str_app_assoc.
224 change ([1]^^1) with [1]. rewrite S_ones1.
225 change ([1] *> [1;1;0] *> ?Y) with ([1;1;1;0] *> Y).
226 eapply progress_evstep_trans. 1: apply RND0. apply evstep_refl'.
227 change ([1;1;1;1;1] *> ?X) with ([1;1;1] *> [1;1] *> X). rewrite S_sh110. reflexivity.
228Qed.
230Lemma O2r l q L:
231 RT l (q+3) (zone 2 L 0) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 0 (S L) (2^(S L)-1)).
232Proof.
233 unfold RT, zone. rewrite dg_zero, dg_full. rewrite !Str_app_assoc.
234 change ([1]^^2) with [1;1]. change ([1]^^0 *> ?X) with X.
235 assert (E: [1;1] *> [1;1;1]^^L *> [1;1;1] *> const 0 = [1;1;1]^^(S L) *> [1;1;0] *> const 0).
236 { rewrite S_ones2, lpow_S, Str_app_assoc, <-lpow_shift'. f_equal. cbn. repeat f_equal. apply const_unfold. }
237 rewrite E. apply RND2.
238Qed.
240Lemma O1r l q L:
241 RT l (q+3) (zone 1 L 0) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 2 L (2^L-1)).
242Proof.
243 unfold RT, zone. rewrite dg_zero, dg_full. rewrite !Str_app_assoc.
244 change ([1]^^2) with [1;1]. change ([1]^^1) with [1].
245 assert (E: [1] *> [1;1;1]^^L *> [1;1;1] *> const 0 = [1;1;1]^^L *> [1;1;1;1;0] *> const 0).
246 { rewrite S_ones1. f_equal. cbn. repeat f_equal. apply const_unfold. }
247 rewrite E. eapply progress_evstep_trans. 1: apply RND1. apply evstep_refl'.
248 change ([1;1;1;1] *> ?X) with ([1;1] *> [1;1] *> X). rewrite S_sh110. reflexivity.
249Qed.
251Lemma O0r l q L:
252 RT l (q+3) (zone 0 L 0) -->+ RT ([1;0;1;0] *> l) q (zone 0 (S L) (2^(S L)-2)).
253Proof.
254 replace (2^(S L)-2) with (2*(2^L-1)) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos L); lia).
255 unfold RT, zone. rewrite dg_zero, dg_even, dg_full. rewrite !Str_app_assoc.
256 change ([1]^^0 *> ?X) with X.
257 assert (E: [1;1;1]^^L *> [1;1;1] *> const 0 = [1;1;1]^^L *> [1;1;1;0] *> const 0).
258 { f_equal. cbn. repeat f_equal. apply const_unfold. }
259 rewrite E. eapply progress_evstep_trans. 1: apply RND0. apply evstep_refl'.
260 change ([1;1;1;1;1] *> ?X) with ([1;1;1] *> [1;1] *> X). rewrite S_sh110. reflexivity.
261Qed.
263(** ** Counter forms of the bites (proof.md 3.3). FR p l is the frame 00 (10)^p 1 on top of l. *)
265Definition FR (p : nat) (l : side) : side := [1] *> [0;1]^^p *> [0;0] *> l.
267Lemma PUSHr l k L o:
268 RT l 2 (zone 0 (k + S L) (2^k - 1 + 2^(S k)*o)) -->+ RT ([1;0;0]^^k *> [1;0;1;0] *> l) 1 (zone 1 L o).
269Proof.
270 unfold RT, zone. rewrite dg_lowones. rewrite !Str_app_assoc.
271 change ([1]^^0 *> ?X) with X.
272 eapply progress_evstep_trans. 1: apply PUSH. apply evstep_refl'. reflexivity.
273Qed.
275Lemma B1z0 p l L v: RT (FR p l) 1 (zone 0 (S L) (2*v)) -->+ RT l (p+3) (zone 2 L v).
276Proof.
277 unfold RT, FR, zone. rewrite dg_even. rewrite !Str_app_assoc.
278 change ([1]^^0 *> ?X) with X. change ([1;0]^^1 *> [1;1;1] *> ?X) with ([1;0] *> [1;1] *> [1] *> X).
279 eapply progress_evstep_trans. 1: apply BITE1. apply evstep_refl'. reflexivity.
280Qed.
282Lemma B1z1 p l L v: RT (FR p l) 1 (zone 0 (S L) (2*v+1)) -->+ RT l (p+4) (zone 0 L v).
283Proof.
284 unfold RT, FR, zone. rewrite dg_odd. rewrite !Str_app_assoc.
285 change ([1]^^0 *> ?X) with X. change ([1;0]^^1 *> [1;1;0] *> ?X) with ([1;0] *> [1;1] *> [0] *> X).
286 eapply progress_evstep_trans. 1: apply BITE1. apply evstep_refl'.
287 replace (p+4) with (S (p+3)) by lia. rewrite lpow_S, Str_app_assoc, <-lpow_shift'. reflexivity.
288Qed.
290Lemma B1o p l L v: RT (FR p l) 1 (zone 1 L v) -->+ RT l (p+3) (zone 0 L v).
291Proof.
292 unfold RT, FR, zone. destruct L as [|L].
293 - cbn [dg]. change ([1;0]^^1 *> ([1]^^1 ++ [] ++ [1;1;1]) *> ?X) with ([1;0] *> [1;1] *> [1;1] *> X).
294 eapply progress_evstep_trans. 1: apply BITE1. apply evstep_refl'. reflexivity.
295 - cbn [dg]. rewrite !Str_app_assoc.
296 change ([1;0]^^1 *> [1]^^1 *> [1;1;bitc v] *> ?X) with ([1;0] *> [1;1] *> [1;bitc v] *> X).
297 eapply progress_evstep_trans. 1: apply BITE1. apply evstep_refl'. reflexivity.
298Qed.
300Lemma B1t p l L v: RT (FR p l) 1 (zone 2 L v) -->+ RT l (p+3) (zone 1 L v).
301Proof.
302 unfold RT, FR, zone. rewrite !Str_app_assoc.
303 change ([1;0]^^1 *> [1]^^2 *> ?X) with ([1;0] *> [1;1] *> X).
304 eapply progress_evstep_trans. 1: apply BITE1. apply evstep_refl'. reflexivity.
305Qed.
307Lemma B0r p l b L o:
308 RT (FR p l) 0 (zone 0 (S b + S L) (2^(S b)*(2*o+1))) -->+ RT l (p+3) (zone 0 (b + S L) (2^b - 1 + 2^(S b)*o)).
309Proof.
310 unfold RT, FR, zone. rewrite dg_low, dg_lowones. rewrite !Str_app_assoc.
311 change ([1]^^0 *> ?X) with X. change ([1;0]^^0 *> ?X) with X.
312 eapply progress_evstep_trans. 1: apply BITE0. apply evstep_refl'.
313 rewrite lpow_S, Str_app_assoc.
314 change ([1] *> [0;1;1] *> ?X) with ([1;0] *> [1;1] *> X). rewrite S_sh110.
315 replace (p+3) with (S (p+2)) by lia. rewrite (lpow_S (p+2)), Str_app_assoc, <-lpow_shift'. reflexivity.
316Qed.
318Lemma B0cr p l L: RT (FR p l) 0 (zone 0 (S L) 0) -->+ RT l (p+2) (zone 0 (S L) (2^(S L)-2)).
319Proof.
320 replace (2^(S L)-2) with (2*(2^L-1)) by (rewrite Nat.pow_succ_r'; pose proof (pow_pos L); lia).
321 unfold RT, FR, zone. rewrite dg_zero, dg_even, dg_full. rewrite !Str_app_assoc.
322 change ([1]^^0 *> ?X) with X. change ([1;0]^^0 *> ?X) with X.
323 assert (E: [1;1;1]^^(S L) *> [1;1;1] *> const 0 = [1;1;1]^^L *> [1;1;1;1;1;1;0] *> const 0).
324 { rewrite lpow_S, Str_app_assoc, <-lpow_shift'. f_equal. cbn. repeat f_equal. apply const_unfold. }
325 rewrite E. apply BITE0c.
326Qed.
328Lemma B0c3r p l: RT (FR p l) 0 (zone 0 0 0) -->+ RT l (p+1) (zone 0 1 0).
329Proof.
330 unfold RT, FR, zone. cbn [dg lpow app].
331 assert (E: [1;1;1] *> const 0 = [1;1;1;0;0] *> const 0).
332 { cbn. rewrite <-!const_unfold. reflexivity. }
333 change ([1;0]^^0 *> ?X) with X. rewrite E.
334 eapply progress_evstep_trans. 1: apply BITE0c3. apply evstep_refl'. reflexivity.
335Qed.
337(** ** Frames *)
339Lemma FR_round p l: [1;0;1;0] *> FR p l = FR (p+2) l.
340Proof.
341 unfold FR. replace (p+2) with (S (S p)) by lia.
342 cbn [lpow]. rewrite !Str_app_assoc. reflexivity.
343Qed.
345(** ** Initial segment (proof.md 7): c0 -->(327) R(-1, 6, 11111) = (6,5,0) *)
347Lemma init: c0 -->* RT (const 0) 6 (zone 2 0 0).
348Proof. unfold RT, zone. cbn. solve_init. Qed.
350(** ** Levels. lev P l is the top frame in shifted coordinates P = p+1; P = 0 is the cycle
351 start (no frame), used only over the blank left side. *)
353Definition lev (P : nat) (l : side) : side :=
354 match P with
355 | O => l
356 | S p => FR p l
357 end.
359Definition okL (P : nat) (l : side) : Prop := P = 0%nat -> l = const 0.
361Lemma lev_round P l: okL P l -> [1;0;1;0] *> lev P l = lev (P+2) l.
362Proof.
363 unfold okL. destruct P as [|P]; intros H.
364 - rewrite H by reflexivity. cbn. repeat f_equal. apply const_unfold.
365 - cbn [lev]. replace (S P + 2) with (S (P+2)) by lia. apply FR_round.
366Qed.
368Lemma okL_S P l: okL (S P) l.
369Proof. unfold okL. intros H. discriminate H. Qed.
371(** The abstract round (proof.md 3.2 counter form): (q, r, L, v) -> (q', r', L', v'). *)
372Inductive Rnd : nat -> nat -> nat -> nat -> nat -> nat -> nat -> nat -> Prop :=
373| RR1z q L v: 1 <= v -> Rnd (q+3) 0 L v (q+1) 0 L (v-1)
374| RR1t q L v: 1 <= v -> Rnd (q+3) 2 L v (q+1) 2 L (v-1)
375| RR2 q L v: 1 <= v -> Rnd (q+3) 1 L v q 0 (S L) (2*v-2)
376| RO2 q L: Rnd (q+3) 2 L 0 (q+1) 0 (S L) (2^(S L)-1)
377| RO1 q L: Rnd (q+3) 1 L 0 (q+1) 2 L (2^L-1)
378| RO0 q L: Rnd (q+3) 0 L 0 q 0 (S L) (2^(S L)-2).
380Lemma Rnd_tape q r L v q' r' L' v' P l:
381 Rnd q r L v q' r' L' v' -> v < 2^L -> okL P l ->
382 RT (lev P l) q (zone r L v) -->+ RT (lev (P+2) l) q' (zone r' L' v').
383Proof.
384 intros H Hv Hl. rewrite <-(lev_round P l Hl).
385 destruct H.
386 - apply R1z; lia.
387 - apply R1t; lia.
388 - apply R2r; lia.
389 - apply O2r.
390 - apply O1r.
391 - apply O0r.
392Qed.
394Lemma Rnd_valid q r L v q' r' L' v':
395 Rnd q r L v q' r' L' v' -> v < 2^L -> r < 3 -> v' < 2^L' /\ r' < 3.
396Proof.
397 intros H Hv Hr. destruct H; rewrite ?Nat.pow_succ_r' in *; pose proof (pow_pos L); lia.
398Qed.
400Lemma Rnd_exists q r L v: 3 <= q -> r < 3 -> exists q' r' L' v', Rnd q r L v q' r' L' v'.
401Proof.
402 intros Hq Hr. replace q with ((q-3)+3) by lia.
403 destruct (Nat.eq_dec v 0) as [->|Hv].
404 - destruct r as [|[|[|]]]; [| | |lia]; eexists _, _, _, _.
405 + apply RO0.
406 + apply RO1.
407 + apply RO2.
408 - destruct r as [|[|[|]]]; [| | |lia]; eexists _, _, _, _.
409 + apply RR1z; lia.
410 + apply RR2; lia.
411 + apply RR1t; lia.
412Qed.
414Lemma okL_ge P l: 1 <= P -> okL P l.
415Proof. intros H. destruct P; [lia|apply okL_S]. Qed.
417(** ** The invariant (proof.md 5.1) on cycle starts t = (n, r, L, v): width w = 3L+3+r *)
419Definition cap (r L : nat) : nat := L + (if Nat.eqb r 1 then 1 else 0).
421(** K: d = n - 2^(cap+1) >= 2 *)
422Definition Kst (n r L : nat) : Prop := 2^(S (cap r L)) + 2 <= n.
424(** J: n >= 3, n odd when w = 1, 2 mod 3 *)
425Definition Jst (n r : nat) : Prop := 3 <= n /\ (r <> 0%nat -> n mod 2 = 1%nat).
427(** M (mod 3): n + 2v - 2^(cap+2) (w = 0, 2), n + v - 2^(cap+2) (w = 1); -x is written 2x *)
428Definition Mv (n r L v : nat) : nat :=
429 (n + (if Nat.eqb r 1 then v else 2*v) + 2 * 2^(cap r L + 2)) mod 3.
431(** The sign-law quantity Q of a frame (proof.md 5.4), P = p+1: Q = M - P = M + 2P (mod 3) *)
432Definition Qv (P q r L v : nat) : nat := (Mv q r L v + 2*P) mod 3.
434Definition Ist (n r L v : nat) : Prop :=
435 r < 3 /\ v < 2^L /\ Kst n r L /\ Mv n r L v <> 0%nat /\ ~ (n = 6 /\ r = 1 /\ L = 0 /\ v = 0)%nat.
437Lemma init_I: Ist 6 2 0 0.
438Proof. unfold Ist, Kst, Mv, cap. cbn. repeat split; lia. Qed.
440Lemma Rnd_sign P q r L v q' r' L' v':
441 Rnd q r L v q' r' L' v' -> Qv P q r L v = Qv (P+2) q' r' L' v'.
442Proof.
443 intros H. unfold Qv, Mv, cap.
444 destruct H as [q L v Hv|q L v Hv|q L v Hv|q L|q L|q L]; pose proof (pow_pos L);
445 cbn [Nat.eqb]; rewrite ?Nat.pow_add_r; cbn [Nat.pow]; lia.
446Qed.
448(** ** Ending bites as one relation: from frame P = p+1 the pop is RT l (P + e) (zone r' L' v') *)
450Inductive EB : nat -> nat -> nat -> nat -> nat -> nat -> nat -> nat -> Prop :=
451| EB1z0 L v: EB 1 0 (S L) (2*v) 2 2 L v
452| EB1z1 L v: EB 1 0 (S L) (2*v+1) 3 0 L v
453| EB1o L v: EB 1 1 L v 2 0 L v
454| EB1t L v: EB 1 2 L v 2 1 L v
455| EB0 b L o: EB 0 0 (S b + S L) (2^(S b)*(2*o+1)) 2 0 (b + S L) (2^b - 1 + 2^(S b)*o)
456| EB0c L: EB 0 0 (S L) 0 1 0 (S L) (2^(S L)-2)
457| EB0c3: EB 0 0 0 0 0 0 1 0.
459Lemma EB_tape q r L v e r' L' v' p l:
460 EB q r L v e r' L' v' -> RT (FR p l) q (zone r L v) -->+ RT l (S p + e) (zone r' L' v').
461Proof.
462 intros H. destruct H.
463 - replace (S p + 2) with (p+3) by lia. apply B1z0.
464 - replace (S p + 3) with (p+4) by lia. apply B1z1.
465 - replace (S p + 2) with (p+3) by lia. apply B1o.
466 - replace (S p + 2) with (p+3) by lia. apply B1t.
467 - replace (S p + 2) with (p+3) by lia. apply B0r.
468 - replace (S p + 1) with (p+2) by lia. apply B0cr.
469 - replace (S p + 0) with (p+1) by lia. apply B0c3r.
470Qed.
472(** Sign law for ending bites (proof.md 5.4): M(pop) = -Q(bite) (mod 3) *)
473Lemma EB_sign q r L v e r' L' v' P:
474 EB q r L v e r' L' v' -> (Mv (P + e) r' L' v' + Qv P q r L v) mod 3 = 0%nat.
475Proof.
476 intros H. unfold Qv, Mv, cap.
477 destruct H as [L v|L v|L v|L v|b L o|L|]; cbn [Nat.eqb]; rewrite ?Nat.pow_add_r; cbn [Nat.pow].
478 1-4,6: pose proof (pow_pos L); lia.
479 - pose proof (pow_pos L). pose proof (pow_pos b). nia.
480 - lia.
481Qed.
483(** ** The bite at q = 2 on a level: PUSH k leaves k pending inner levels (frames p = 0,
484 i.e. lev 1) over the level's own frame, now at P+2 (proof.md 3.4, the stack). *)
486Lemma iter_FR0 k X: [1;0;0]^^k *> X = Nat.iter k (FR 0) X.
487Proof.
488 induction k as [|k IH]; [reflexivity|].
489 rewrite lpow_S, Str_app_assoc, IH. reflexivity.
490Qed.
492Lemma PUSH_lev k L o P l: okL P l ->
493 RT (lev P l) 2 (zone 0 (k + S L) (2^k - 1 + 2^(S k)*o)) -->+
494 RT (Nat.iter k (FR 0) (lev (P+2) l)) 1 (zone 1 L o).
495Proof.
496 intros Hl. rewrite <-(lev_round P l Hl), <-iter_FR0. apply PUSHr.
497Qed.
499(** The innermost level of a nested bite is a single B1 bite: it pops into the next level's
500 start (lev 1 = the frame p = 0) with t_2 = (3, Y[3:]). *)
501Lemma inner1 k L o X:
502 RT (Nat.iter (S k) (FR 0) X) 1 (zone 1 L o) -->+ RT (Nat.iter k (FR 0) X) 3 (zone 0 L o).
503Proof. cbn [Nat.iter]. apply (EB_tape 1 1 L o 2 0 L o 0). constructor. Qed.
505(** ** Bounded safety (proof.md 6, route 3 of proof.md 9) *)
507Definition safe (c : Q * tape) (N : nat) : Prop := forall M, M <= N -> ~ halts_in tm c M.
509Lemma safe_mono c N N': safe c N -> N' <= N -> safe c N'.
510Proof. intros H Hle M HM. apply H. lia. Qed.
512Lemma safe_ev c c' N: c -->* c' -> safe c' N -> safe c N.
513Proof.
514 intros H HN M HM Hh. apply with_counter in H as [n Hn].
515 destruct (Nat.leb_spec n M).
516 - apply (HN (M - n)); [lia|]. eapply preceeds_halt; eauto.
517 - eapply exceeds_halt; eauto.
518Qed.
520Lemma safe_prog c c' N: c -->+ c' -> safe c' (N - 1) -> safe c N.
521Proof.
522 intros H HN M HM Hh. apply progress_multistep in H as [n Hn].
523 destruct (Nat.leb_spec (S n) M).
524 - apply (HN (M - S n)); [lia|]. eapply preceeds_halt; eauto.
525 - eapply exceeds_halt; eauto.
526Qed.
528Lemma safe_prog0 c c': c -->+ c' -> safe c 0.
529Proof.
530 intros H M HM Hh. apply progress_multistep in H as [n Hn].
531 eapply exceeds_halt; [exact Hh | | exact Hn]. lia.
532Qed.
534Lemma safe_RT0 l q Z: safe (RT l q Z) 0.
535Proof.
536 intros M HM [ch [Hrun Hh]]. assert (M = 0%nat) by lia. subst M.
537 inversion Hrun; subst. unfold RT in Hh. cbn in Hh. discriminate.
538Qed.
540(** ** The phase lemma: rounds from a phase start to its bite (q <= 2), carrying any
541 invariant that every round preserves. j is the frame offset from the level start. *)
543Lemma phase (Inv : nat -> nat -> nat -> nat -> nat -> Prop):
544 (forall j q r L v q' r' L' v', Rnd q r L v q' r' L' v' -> v < 2^L ->
545 Inv j q r L v -> Inv (j+2) q' r' L' v') ->
546 forall q j P l r L v, okL (P + j) l -> r < 3 -> v < 2^L -> Inv j q r L v ->
547 exists j' q' r' L' v', q' <= 2 /\ r' < 3 /\ v' < 2^L' /\ Inv j' q' r' L' v' /\
548 j <= j' /\ (3 <= q -> j + 2 <= j') /\
549 RT (lev (P + j) l) q (zone r L v) -->* RT (lev (P + j') l) q' (zone r' L' v').
550Proof.
551 intros Hstep q. induction q as [q IH] using lt_wf_ind. intros j P l r L v Hl Hr Hv HI.
552 destruct (Nat.le_gt_cases q 2) as [Hq|Hq].
553 - exists j, q, r, L, v. repeat split; try assumption; try lia. apply evstep_refl.
554 - destruct (Rnd_exists q r L v ltac:(lia) Hr) as [q' [r' [L' [v' HR]]]].
555 assert (Hq': q' < q) by (destruct HR; lia).
556 destruct (Rnd_valid _ _ _ _ _ _ _ _ HR Hv Hr) as [Hv' Hr'].
557 assert (Hl': okL (P + (j+2)) l) by (apply okL_ge; lia).
558 destruct (IH q' Hq' (j+2) P l r' L' v' Hl' Hr' Hv' (Hstep _ _ _ _ _ _ _ _ _ HR Hv HI))
559 as [j2 [q2 [r2 [L2 [v2 [H1 [H2 [H3 [H4 [H5 [H6 H7]]]]]]]]]]].
560 exists j2, q2, r2, L2, v2. repeat split; try assumption; try lia.
561 eapply evstep_trans. 2: exact H7.
562 apply progress_evstep. replace (P + (j+2)) with ((P+j)+2) by lia. apply Rnd_tape; assumption.
563Qed.
565(** ** Classes of level starts and the phase invariants (proof.md 5) *)
567Lemma cap0 L: cap 0 L = L. Proof. unfold cap. cbn. lia. Qed.
568Lemma cap1 L: cap 1 L = S L. Proof. unfold cap. cbn. lia. Qed.
569Lemma cap2 L: cap 2 L = L. Proof. unfold cap. cbn. lia. Qed.
571Ltac pw := rewrite ?Nat.pow_succ_r' in *.
573Lemma pow0 L: L = 0%nat -> 2^L = 1%nat.
574Proof. intros ->. reflexivity. Qed.
576(** K' = K minus T_c and (6,4,0) *)
577Definition Kx (n r L v : nat) : Prop :=
578 Kst n r L /\ ~ (r = 2%nat /\ v = 2^L - 1 /\ n = 2^(S L) + 2) /\
579 ~ (n = 6%nat /\ r = 1%nat /\ L = 0%nat /\ v = 0%nat).
581Definition Pre (n r L v : nat) : Prop := Jst n r \/ Kx n r L v.
583(** Safety along a phase (Lemma P): no H, and every bite has a rule. *)
584Definition Saf (q r L v : nat) : Prop :=
585 match r with
586 | O => (L = 0%nat -> 3 <= q) /\ ~ (q = 2%nat /\ v = 2^L - 1) /\ (q = 0%nat -> v mod 2 = 0%nat)
587 | 1%nat => 3 <= q /\ (v = 0%nat -> (q <= 2^(S L) + 2 -> q mod 2 = 1%nat) /\ q <> 2^(S L) + 4)
588 | _ => (q <= 2*v + 2 -> q mod 2 = 1%nat) /\ q <> 2*v + 4
589 end.
591(** The K bound along a phase from K' (Lemma K, Lemma A1); j is the frame offset. *)
592Definition KI (j q r L v : nat) : Prop :=
593 match r with
594 | O => 2^L <= j + q /\ (2^(S L) <= j + 2*v + 2 \/ 2^(S L) + 1 <= j + q) /\
595 (q = 0%nat -> v <> 0%nat) /\ (L = 0%nat -> 4 <= q)
596 | 1%nat => 2^(S (S L)) + 2 <= q /\ (v = 0%nat -> 2^(S L) + 5 <= q)
597 | _ => 2^(S L) + 2 <= j + q /\ 2*v + 5 <= q
598 end.
600(** The overflow bound along a phase from a zone-dominated start (Lemma Z'), target cap C. *)
601Definition ZI (C q r L v : nat) : Prop :=
602 1 <= C /\
603 match r with
604 | O => L <= S C /\ q + 2^(S (S L)) + C <= 2*v + L + 2^(S (S (S C))) + 1 /\
605 (q = 0%nat -> v = 0%nat -> L <= C)
606 | 1%nat => S (S L) <= C /\ q <= 2^(S (S L)) + 1 /\ 3 <= q
607 | _ => S L <= C /\ q <= 2*v + 2^(S L) + 1
608 end.
610Lemma Saf_step q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> Saf q r L v -> Saf q' r' L' v'.
611Proof.
612 intros H Hv HS. pose proof (pow_pos L) as HL. pose proof (pow0 L) as H0.
613 destruct H; cbn [Saf] in *; pw; lia.
614Qed.
616Lemma KI_step j q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> KI j q r L v -> KI (j+2) q' r' L' v'.
617Proof.
618 intros H Hv HK. pose proof (pow_pos L) as HL. pose proof (pow0 L) as H0.
619 destruct H; cbn [KI] in *.
620 1-5: pw; lia.
621 destruct L as [|L]; cbn [Nat.pow] in *; [lia|]. pose proof (pow_pos L). pw. lia.
622Qed.
624Lemma pow_mono a b: a <= b -> 2^a <= 2^b.
625Proof. intros H. apply Nat.pow_le_mono_r; lia. Qed.
627Lemma pow_lin a: S a <= 2^a.
628Proof. pose proof (Nat.pow_gt_lin_r 2 a ltac:(lia)). lia. Qed.
630Lemma ZI_step C q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> ZI C q r L v -> ZI C q' r' L' v'.
631Proof.
632 intros H Hv [HC HZ]. split; [exact HC|]. pose proof (pow_pos L) as HL. pose proof (pow_lin C) as HlC.
633 pose proof (pow0 L) as H0.
634 destruct H; cbn [ZI] in *.
635 - pw; lia.
636 - pw; lia.
637 - (* R2 *) pose proof (pow_mono (S (S L)) C ltac:(lia)). pw; lia.
638 - (* O2 *) pose proof (pow_mono (S L) C ltac:(lia)). pw; lia.
639 - (* O1 *) pw; lia.
640 - (* O0 *) destruct (Nat.eq_dec L (S C)) as [E|E].
641 + subst L. pw. lia.
642 + destruct L as [|L]; cbn [Nat.pow] in *; [lia|]. pose proof (pow_pos L). pw. lia.
643Qed.
645(** The phase invariant of a level started at t = (n, r, L, v): sign law (Qv), the U5 bound,
646 safety, the K bound (t in K') and the overflow bound (t in J, zone-dominated). *)
647Definition PI (n r L v j q r' L' v' : nat) : Prop :=
648 j mod 2 = 0%nat /\ Qv j q r' L' v' = Mv n r L v /\
649 (r' = 1%nat -> j = 0%nat) /\ (r' = 2%nat -> L' = 0%nat -> j <= 2) /\
650 Saf q r' L' v' /\ (Kx n r L v -> KI j q r' L' v') /\
651 (Jst n r -> ~ Kst n r L -> ZI (S (cap r L)) q r' L' v').
653Lemma PI_step n r L v j q r1 L1 v1 q' r' L' v':
654 Rnd q r1 L1 v1 q' r' L' v' -> v1 < 2^L1 -> PI n r L v j q r1 L1 v1 -> PI n r L v (j+2) q' r' L' v'.
655Proof.
656 intros H Hv [H1 [H2 [H3 [H4 [H5 [H6 H7]]]]]].
657 split; [lia|]. split; [rewrite <-H2; symmetry; apply Rnd_sign; exact H|].
658 split; [intros E; subst r'; inversion H|].
659 split.
660 { intros E1 E2. inversion H; subst; try discriminate.
661 - cbn in Hv. lia.
662 - specialize (H3 eq_refl). lia. }
663 split; [eapply Saf_step; eauto|].
664 split; [intros HK; eapply KI_step; eauto|].
665 intros HJ HK. eapply ZI_step; eauto.
666Qed.
668Lemma Mv_lt3 n r L v: Mv n r L v < 3.
669Proof. unfold Mv. apply Nat.mod_upper_bound. lia. Qed.
671Lemma Qv0 q r L v: Qv 0 q r L v = Mv q r L v.
672Proof. unfold Qv. rewrite Nat.mul_0_r, Nat.add_0_r. apply Nat.mod_small, Mv_lt3. Qed.
674Lemma Pre_n3 n r L v: Pre n r L v -> 3 <= n.
675Proof.
676 intros [[H _]|[H _]]; [exact H|]. unfold Kst in H. pose proof (pow_pos (S (cap r L))). lia.
677Qed.
679Lemma Saf_start n r L v: r < 3 -> v < 2^L -> Pre n r L v -> Saf n r L v.
680Proof.
681 intros Hr Hv HP. pose proof (pow_pos L) as HL. pose proof (pow0 L) as H0.
682 destruct HP as [[Hn Hp]|[HK [HT H6]]].
683 - destruct r as [|[|[|r]]]; cbn [Saf]; pw; lia.
684 - unfold Kst in HK. destruct r as [|[|[|r]]]; cbn [Saf]; rewrite ?cap0, ?cap1, ?cap2 in HK; pw; try lia.
685 destruct (Nat.eq_dec L 0) as [->|EL]; [cbn in *; lia|].
686 assert (2 <= 2^L) by (destruct L; [lia|]; cbn [Nat.pow]; pose proof (pow_pos L); lia). lia.
687Qed.
689Lemma KI_start n r L v: r < 3 -> v < 2^L -> Kx n r L v -> KI 0 n r L v.
690Proof.
691 intros Hr Hv [HK [HT H6]]. pose proof (pow_pos L) as HL. pose proof (pow0 L) as H0.
692 unfold Kst in HK. destruct r as [|[|[|r]]]; cbn [KI]; rewrite ?cap0, ?cap1, ?cap2 in HK; pw; try lia.
693 destruct (Nat.eq_dec L 0) as [->|EL]; [cbn in *; lia|].
694 assert (2 <= 2^L) by (destruct L; [lia|]; cbn [Nat.pow]; pose proof (pow_pos L); lia). lia.
695Qed.
697Lemma ZI_start n r L v: r < 3 -> v < 2^L -> Jst n r -> ~ Kst n r L -> ZI (S (cap r L)) n r L v.
698Proof.
699 intros Hr Hv [Hn Hp] HK. pose proof (pow_pos L) as HL. pose proof (pow0 L) as H0.
700 unfold Kst in HK. split; [lia|].
701 destruct r as [|[|[|r]]]; cbn [ZI]; rewrite ?cap0, ?cap1, ?cap2 in *; pw; lia.
702Qed.
704Lemma PI_start n r L v: r < 3 -> v < 2^L -> Pre n r L v -> PI n r L v 0 n r L v.
705Proof.
706 intros Hr Hv HP. split; [reflexivity|]. split; [apply Qv0|].
707 split; [reflexivity|]. split; [lia|]. split; [apply Saf_start; assumption|].
708 split; [intros HK; apply KI_start; assumption|].
709 intros HJ HK. apply ZI_start; assumption.
710Qed.
712(** ** What a level guarantees about its pop (proof.md 6, U1-U4, plus the (6,4,0) bound U5).
713 A level from t = (n, r, L, v) at frame P pops at RT l (P + n') (zone r' L' v'). *)
714Definition Post (n r L v n' r' L' v' : nat) : Prop :=
715 r' < 3 /\ v' < 2^L' /\
716 (Jst n r -> Jst (S n') r') /\
717 (Kx n r L v -> Kst n' r' L') /\
718 (Jst n r -> ~ Kst n r L -> Kst (S n') r' L' \/ cap r' L' <= S (cap r L)) /\
719 (Mv n' r' L' v' + Mv n r L v) mod 3 = 0%nat /\
720 (r' = 1%nat -> L' = 0%nat -> v' = 0%nat -> n' = 4%nat \/ 8 <= n').
722Definition U (N : nat) : Prop :=
723 forall P l n r L v, okL P l -> r < 3 -> v < 2^L -> Pre n r L v ->
724 (forall n' r' L' v', Post n r L v n' r' L' v' -> safe (RT l (P + n') (zone r' L' v')) (N - 1)) ->
725 safe (RT (lev P l) n (zone r L v)) N.
727(** ** Bites (proof.md 3.3, Lemma P3) *)
729Lemma lowones L: forall v, v < 2^L -> v <> 2^L - 1 ->
730 exists k L' o, L = k + S L' /\ v = 2^k - 1 + 2^(S k) * o /\ o < 2^L'.
731Proof.
732 induction L as [|L IH]; intros v Hv Hne.
733 - cbn in *. lia.
734 - rewrite Nat.pow_succ_r' in Hv, Hne.
735 destruct (Nat.Even_or_Odd v) as [[o Ho]|[v' Hv']].
736 + exists 0%nat, L, o. cbn. lia.
737 + destruct (IH v') as [k [L' [o [E1 [E2 E3]]]]]; [lia|lia|].
738 exists (S k), L', o. split; [lia|]. split; [|exact E3].
739 subst v v'. pose proof (pow_pos k). pw. lia.
740Qed.
742Lemma bite_shape j qb rb Lb vb: qb <= 2 -> rb < 3 -> vb < 2^Lb -> Saf qb rb Lb vb -> 2 <= j ->
743 (rb = 1%nat -> j = 0%nat) ->
744 (exists e r' L' v', EB qb rb Lb vb e r' L' v') \/
745 (qb = 2%nat /\ rb = 0%nat /\ exists k L' o, Lb = k + S L' /\ vb = 2^k - 1 + 2^(S k) * o /\ o < 2^L').
746Proof.
747 intros Hq Hr Hv HS Hj H1.
748 destruct rb as [|[|[|rb]]]; [| lia | | lia]; cbn [Saf] in HS.
749 - destruct HS as [HS1 [HS2 HS3]].
750 destruct qb as [|[|[|qb]]]; [| | |lia].
751 + destruct Lb as [|Lb]; [lia|]. left.
752 destruct (Nat.eq_dec vb 0) as [->|Hne].
753 * eexists _, _, _, _. apply EB0c.
754 * destruct (lowbit vb Hne) as [b [o ->]].
755 destruct b as [|b]; [rewrite Nat.pow_0_r, Nat.mul_1_l in HS3; lia|].
756 destruct (lowbit_lt _ _ _ Hv) as [Hb Ho].
757 replace (S Lb) with (S b + S (Lb - b - 1)) by lia.
758 eexists _, _, _, _. apply EB0.
759 + destruct Lb as [|Lb]; [lia|]. left.
760 destruct (Nat.Even_or_Odd vb) as [[w ->]|[w ->]]; eexists _, _, _, _; [apply EB1z0|apply EB1z1].
761 + right. split; [reflexivity|]. split; [reflexivity|]. apply lowones; [exact Hv|]. tauto.
762 - destruct HS as [HS1 HS2]. assert (qb = 1%nat) as -> by lia.
763 left. eexists _, _, _, _. apply EB1t.
764Qed.
766Lemma EB_valid q r L v e r' L' v': EB q r L v e r' L' v' -> v < 2^L -> r' < 3 /\ v' < 2^L'.
767Proof.
768 intros H Hv. destruct H; (split; [lia|]).
769 - pw. lia.
770 - pw. lia.
771 - exact Hv.
772 - exact Hv.
773 - rewrite Nat.pow_add_r in *. pw. pose proof (pow_pos b). pose proof (pow_pos L).
774 assert (o < 2^L) by nia. nia.
775 - pose proof (pow_pos L). pw. lia.
776 - cbn. lia.
777Qed.
779Lemma EB_lev q r L v e r' L' v' P l: 1 <= P -> EB q r L v e r' L' v' ->
780 RT (lev P l) q (zone r L v) -->+ RT l (P + e) (zone r' L' v').
781Proof. intros HP H. destruct P as [|p]; [lia|]. cbn [lev]. apply EB_tape. exact H. Qed.
783Lemma Kst_mono n n' r L: Kst n r L -> n <= n' -> Kst n' r L.
784Proof. unfold Kst. lia. Qed.
786(** A plain end: the first bite of the level is an ending bite (proof.md 5.5, 5.7 plain cases). *)
787Lemma ending n r L v j qb rb Lb vb e r' L' v':
788 EB qb rb Lb vb e r' L' v' -> PI n r L v j qb rb Lb vb -> 2 <= j -> vb < 2^Lb ->
789 Post n r L v (j + e) r' L' v'.
790Proof.
791 intros H [H1 [H2 [H3 [H4 [H5 [H6 H7]]]]]] Hj Hvb.
792 destruct (EB_valid _ _ _ _ _ _ _ _ H Hvb) as [Hr' Hv'].
793 pose proof (EB_sign _ _ _ _ _ _ _ _ j H) as HS. rewrite H2 in HS.
794 split; [exact Hr'|]. split; [exact Hv'|].
795 split.
796 { intros _. unfold Jst. destruct H; split; lia. }
797 split.
798 { intros HK. specialize (H6 HK). unfold Kst.
799 destruct H; cbn [KI] in H6; rewrite ?cap0, ?cap1, ?cap2; cbn [Nat.add] in *; pw; lia. }
800 split.
801 { intros HJ HK. destruct (H7 HJ HK) as [HC7 HZ7]. right.
802 destruct H; cbn [ZI] in HZ7; rewrite ?cap0, ?cap1, ?cap2; cbn [Nat.add] in *; lia. }
803 split; [exact HS|].
804 intros E1 E2 E3. destruct H; try discriminate E1. subst. left. specialize (H4 eq_refl eq_refl). lia.
805Qed.
807(** B2 then B1 (PUSH with k = 0, then the B1 of zone 1). *)
808Lemma ending_B2 n r L v j L' o:
809 PI n r L v j 2 0 (0 + S L') (2^0 - 1 + 2^1 * o) -> 2 <= j -> o < 2^L' ->
810 Post n r L v (j + 4) 0 L' o.
811Proof.
812 intros [H1 [H2 [H3 [H4 [H5 [H6 H7]]]]]] Hj Ho. cbn [Nat.add Nat.pow Nat.sub] in *.
813 split; [lia|]. split; [exact Ho|].
814 split; [intros _; unfold Jst; lia|].
815 split.
816 { intros HK. specialize (H6 HK). unfold Kst. cbn [KI] in H6. rewrite cap0. pw. lia. }
817 split.
818 { intros HJ HK. destruct (H7 HJ HK) as [HC7 HZ7]. right. cbn [ZI] in HZ7. rewrite cap0. lia. }
819 split.
820 { rewrite <-H2. unfold Qv, Mv, cap. cbn [Nat.eqb]. rewrite !Nat.pow_add_r. cbn [Nat.pow].
821 pose proof (pow_pos L'). lia. }
822 intros E. discriminate E.
823Qed.
825(** ** The stack of a nested bite (proof.md 3.4): budget and sign along the inner levels *)
827(** Budget(t, C): d(t) >= 2, or cap(t) <= C (Lemmas Kp and Z' carry it from level to level). *)
828Definition Budget (n r L C : nat) : Prop := Kst n r L \/ cap r L <= C.
830(** Sign relation after j levels: X - 1 alternates in sign (proof.md 5.4, rule N). *)
831Definition SR (j a b : nat) : Prop :=
832 (j mod 2 = 0%nat -> b = a) /\ (j mod 2 = 1%nat -> (a + b + 2) mod 3 = 0%nat).
834Lemma JK n r L v: Jst n r -> Kst n r L -> Kx n r L v.
835Proof.
836 intros [Hn Hp] HK. split; [exact HK|]. split.
837 - intros [-> [_ ->]]. pw. specialize (Hp ltac:(lia)). lia.
838 - intros [-> [-> _]]. specialize (Hp ltac:(lia)). lia.
839Qed.
841Lemma Budget_step n r L v C n' r' L' v': Jst n r -> Budget n r L C -> Post n r L v n' r' L' v' ->
842 Budget (S n') r' L' (S C).
843Proof.
844 intros HJ HB [_ [_ [_ [HU2 [HU3 _]]]]].
845 destruct (Nat.le_gt_cases (2^(S (cap r L)) + 2) n) as [HK|HK].
846 - left. apply (Kst_mono n'); [apply HU2, JK; assumption | lia].
847 - destruct HB as [HB|HB]; [unfold Kst in HB; lia|].
848 destruct (HU3 HJ ltac:(unfold Kst; lia)) as [H|H]; [left; exact H | right; lia].
849Qed.
851Lemma Mv_shift a n r L v: Mv (a + n) r L v = (Mv n r L v + a) mod 3.
852Proof. unfold Mv. generalize (if Nat.eqb r 1 then v else 2*v) (2 * 2^(cap r L + 2)). intros x y. lia. Qed.
854Lemma SR_step j n r L v n' r' L' v' b: b < 3 -> Post n r L v n' r' L' v' -> SR j (Mv (S n') r' L' v') b ->
855 SR (S j) (Mv n r L v) b.
856Proof.
857 intros Hb [_ [_ [_ [_ [_ [HU4 _]]]]]] [HE HO].
858 change (S n') with (1 + n') in HE, HO. rewrite Mv_shift in HE, HO.
859 pose proof (Mv_lt3 n r L v). pose proof (Mv_lt3 n' r' L' v').
860 split; intros Hj; lia.
861Qed.
863Lemma pow2_mod3 k: exists x, 2^k = 3*x + 1 + k mod 2.
864Proof.
865 induction k as [|k [x Hx]]; [exists 0%nat; reflexivity|].
866 exists (2*x + k mod 2). rewrite Nat.pow_succ_r', Hx. pose proof (Nat.mod_upper_bound k 2). lia.
867Qed.
869(** The sign of the bite zone (110)^k 111 Y against the zone of t_2 (proof.md 5.4, N row). *)
870Lemma QvN j k L o:
871 (k mod 2 = 0%nat -> Qv j 2 0 (S k + S L) (2^(S k) - 1 + 2^(S (S k)) * o) = (Mv 3 0 L o + 1 + 2*j) mod 3) /\
872 (k mod 2 = 1%nat -> Qv j 2 0 (S k + S L) (2^(S k) - 1 + 2^(S (S k)) * o) = (2 * (Mv 3 0 L o + 1) + 2*j) mod 3).
873Proof.
874 destruct (pow2_mod3 k) as [x Hx]. pose proof (pow_pos L).
875 unfold Qv, Mv, cap. cbn [Nat.eqb]. rewrite !Nat.pow_add_r. cbn [Nat.pow]. rewrite Hx.
876 split; intros Hk; rewrite Hk; lia.
877Qed.
879(** The composite form of a level with a nested bite (proof.md 3.4, 5.7): the outer level
880 resumes at t_(k+1) and its pop is that of the resumed phase, shifted by j + 2. *)
881Lemma compose n r L v j k L' o n1 r1 L1 v1 n3 r3 L3 v3:
882 PI n r L v j 2 0 (S k + S L') (2^(S k) - 1 + 2^(S (S k)) * o) -> 2 <= j ->
883 Jst n1 r1 -> Budget n1 r1 L1 (L' + k) -> SR k (Mv 3 0 L' o) (Mv n1 r1 L1 v1) ->
884 Post n1 r1 L1 v1 n3 r3 L3 v3 -> Post n r L v (j + 2 + n3) r3 L3 v3.
885Proof.
886 intros [H1 [H2 [H3 [H4 [H5 [H6 H7]]]]]] Hj HJ1 HB1 HSR HP.
887 pose proof (Budget_step _ _ _ _ _ _ _ _ _ HJ1 HB1 HP) as HB3.
888 destruct HP as [Hr3 [Hv3 [HU1 [HU2 [HU3 [HU4 HU5]]]]]].
889 destruct (HU1 HJ1) as [Hn3 Hp3].
890 split; [exact Hr3|]. split; [exact Hv3|].
891 split.
892 { intros _. split; [lia|]. intros E. specialize (Hp3 E). lia. }
893 split.
894 { intros HK. specialize (H6 HK). cbn [KI] in H6. unfold Kst.
895 destruct HB3 as [HB3|HB3]; [unfold Kst in HB3; lia|].
896 pose proof (pow_mono (S (cap r3 L3)) (S k + S L') ltac:(lia)). lia. }
897 split.
898 { intros HJ HK. destruct (H7 HJ HK) as [HC7 HZ7]. cbn [ZI] in HZ7.
899 destruct HB3 as [HB3|HB3]; [left; apply (Kst_mono (S n3)); [exact HB3|lia] | right; lia]. }
900 split.
901 { rewrite (Mv_shift (j + 2) n3). destruct HSR as [HE HO]. destruct (QvN j k L' o) as [QE QO].
902 pose proof (Mv_lt3 n3 r3 L3 v3). pose proof (Mv_lt3 n1 r1 L1 v1). pose proof (Mv_lt3 3 0 L' o).
903 pose proof (Nat.mod_upper_bound k 2 ltac:(lia)).
904 rewrite <-H2.
905 destruct (Nat.eq_dec (k mod 2) 0) as [Ek|Ek].
906 - rewrite (QE Ek). specialize (HE Ek). lia.
907 - assert (Ek1: k mod 2 = 1%nat) by lia. rewrite (QO Ek1). specialize (HO Ek1). lia. }
908 intros E1 E2 E3. right. destruct (HU5 E1 E2 E3); lia.
909Qed.
911Lemma STK: forall j B, (forall B', B' <= B -> U B') -> forall n r L v C X,
912 Jst n r -> Budget n r L C -> r < 3 -> v < 2^L ->
913 (forall n1 r1 L1 v1, Jst n1 r1 -> Budget n1 r1 L1 (C + j) -> r1 < 3 -> v1 < 2^L1 ->
914 SR j (Mv n r L v) (Mv n1 r1 L1 v1) -> safe (RT X n1 (zone r1 L1 v1)) (B - j)) ->
915 safe (RT (Nat.iter j (FR 0) X) n (zone r L v)) B.
916Proof.
917 induction j as [|j IH]; intros B HU n r L v C X HJ HB Hr Hv Hk.
918 - cbn [Nat.iter].
919 pose proof (Hk n r L v HJ ltac:(rewrite Nat.add_0_r; exact HB) Hr Hv
920 ltac:(split; intros; [reflexivity|lia])) as H.
921 rewrite Nat.sub_0_r in H. exact H.
922 - change (Nat.iter (S j) (FR 0) X) with (lev 1 (Nat.iter j (FR 0) X)).
923 apply (HU B (le_n B) 1%nat (Nat.iter j (FR 0) X) n r L v (okL_S 0 _) Hr Hv (or_introl HJ)).
924 intros n' r' L' v' HP.
925 change (1 + n') with (S n').
926 pose proof HP as [Hr' [Hv' [HU1 _]]].
927 apply (IH (B - 1) (fun B' HB' => HU B' ltac:(lia)) (S n') r' L' v' (S C) X (HU1 HJ)
928 (Budget_step _ _ _ _ _ _ _ _ _ HJ HB HP) Hr' Hv').
929 intros n1 r1 L1 v1 HJ1 HB1 Hr1 Hv1 HS1.
930 replace (B - 1 - j) with (B - S j) by lia.
931 apply Hk; try assumption.
932 + replace (C + S j) with (S C + j) by lia. exact HB1.
933 + eapply SR_step; [apply Mv_lt3 | eassumption | eassumption].
934Qed.
936(** ** U(N) for every N (proof.md 6): strong induction on the number of steps *)
938Lemma U_all: forall N, U N.
939Proof.
940 intros N. induction N as [N IH] using strong_induction.
941 intros P l n r L v Hl Hr Hv Hpre Hk.
942 pose proof (Pre_n3 _ _ _ _ Hpre) as Hn.
943 destruct N as [|N'].
944 { destruct (Rnd_exists n r L v Hn Hr) as [q' [r' [L' [v' HR]]]].
945 eapply safe_prog0. eapply Rnd_tape; eassumption. }
946 destruct (phase (PI n r L v) (PI_step n r L v) n 0 P l r L v)
947 as [j [qb [rb [Lb [vb [Hqb [Hrb [Hvb [HI [_ [Hj Hrun]]]]]]]]]]].
948 { rewrite Nat.add_0_r. exact Hl. }
949 { exact Hr. } { exact Hv. } { apply PI_start; assumption. }
950 specialize (Hj Hn). rewrite Nat.add_0_r in Hrun. cbn [Nat.add] in Hj.
951 eapply safe_ev; [exact Hrun|].
952 assert (HlP: okL (P + j) l) by (apply okL_ge; lia).
953 pose proof HI as [_ [_ [HI3 [_ [HI5 _]]]]].
954 destruct (bite_shape j qb rb Lb vb Hqb Hrb Hvb HI5 Hj HI3)
955 as [[e [r' [L' [v' HE]]]] | [Eq [Er [k [L' [o [EL [Ev Ho]]]]]]]].
956 - (* an ending bite: the pop *)
957 eapply safe_prog. { apply EB_lev; [lia | exact HE]. }
958 replace (P + j + e) with (P + (j + e)) by lia.
959 apply Hk. eapply ending; eassumption.
960 - subst qb rb Lb vb. destruct k as [|k].
961 + (* B2, then B1 *)
962 eapply safe_prog.
963 { eapply progress_trans. { apply (PUSH_lev 0 L' o (P + j) l HlP). }
964 cbn [Nat.iter]. apply (EB_lev 1 1 L' o 2 0 L' o (P + j + 2) l); [lia | constructor]. }
965 replace (P + j + 2 + 2) with (P + (j + 4)) by lia.
966 apply Hk. apply ending_B2; assumption.
967 + (* the nested bite N: PUSH, the innermost B1, the stack, then the rest of the level *)
968 assert (Hpush: RT (lev (P + j) l) 2 (zone 0 (S k + S L') (2^(S k) - 1 + 2^(S (S k)) * o)) -->+
969 RT (Nat.iter k (FR 0) (lev (P + j + 2) l)) 3 (zone 0 L' o)).
970 { eapply progress_trans. { apply (PUSH_lev (S k) L' o (P + j) l HlP). } apply inner1. }
971 eapply safe_prog; [exact Hpush|].
972 replace (S N' - 1) with N' by lia.
973 apply (STK k N' (fun B HB => IH B ltac:(lia)) 3 0 L' o L' (lev (P + j + 2) l)).
974 * split; [lia|]. intros E; lia.
975 * right. rewrite cap0. lia.
976 * lia.
977 * exact Ho.
978 * intros n1 r1 L1 v1 HJ1 HB1 Hr1 Hv1 HS1.
979 apply (IH (N' - k) ltac:(lia) (P + j + 2) l n1 r1 L1 v1 (okL_ge (P + j + 2) l ltac:(lia)) Hr1 Hv1 (or_introl HJ1)).
980 intros n3 r3 L3 v3 HP3.
981 replace (P + j + 2 + n3) with (P + (j + 2 + n3)) by lia.
982 apply (safe_mono _ (S N' - 1)); [| lia].
983 apply Hk. eapply compose; eassumption.
984Qed.
986(** ** Cycles from I (proof.md 5.8) and the main theorem *)
988Lemma Ist_Kx n r L v: Ist n r L v -> Kx n r L v.
989Proof.
990 unfold Ist, Kx. intros [Hr [Hv [HK [HM H6]]]]. split; [exact HK|]. split; [|exact H6].
991 intros [-> [-> ->]]. apply HM. unfold Mv, cap. cbn [Nat.eqb]. rewrite !Nat.pow_add_r. cbn [Nat.pow].
992 pose proof (pow_pos L). lia.
993Qed.
995Lemma cycles N: forall n r L v, Ist n r L v -> safe (RT (const 0) n (zone r L v)) N.
996Proof.
997 induction N as [N IH] using strong_induction. intros n r L v HI.
998 pose proof (Ist_Kx _ _ _ _ HI) as HK. destruct HI as [Hr [Hv [HKs [HM H6]]]].
999 apply (U_all N 0%nat (const 0) n r L v); [intros _; reflexivity | exact Hr | exact Hv | right; exact HK |].
1000 intros n' r' L' v' [Hr' [Hv' [_ [HU2 [_ [HU4 HU5]]]]]].
1001 destruct N as [|N']; [apply safe_RT0|].
1002 replace (S N' - 1) with N' by lia.
1003 change (0 + n')%nat with n'. apply IH; [lia|]. unfold Ist. split; [exact Hr'|]. split; [exact Hv'|]. split; [apply HU2, HK|].
1004 pose proof (Mv_lt3 n r L v). pose proof (Mv_lt3 n' r' L' v'). split; [lia|].
1005 intros [E1 [E2 [E3 E4]]]. destruct (HU5 E2 E3 E4); lia.
149Qed.1006Qed.
151Lemma nonhalt: ~halts tm c0.1008Lemma nonhalt: ~halts tm c0.
152Proof.1009Proof.
153 eapply multistep_nonhalt with (c':=S (6,6)).
1010 intros [N HN].
154 1: unfold S; esx.
1011 exact (safe_ev c0 _ N init (cycles N 6 2 0 0 init_I) N (le_n N) HN).
155 eapply progress_nonhalt_cond with (P:=fun '(a,b) => a<=1+b).
156 2: lia.
⋯ 5 template-only lines (template 157–161), not in ours
162 zify_le_mul_r; lia.
163 - lia.
164Qed.1012Qed.
1014(*
10151RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB (only F0 is undefined)
1017zone(r,L,v) = 1^r (1 1 c_0) ... (1 1 c_(L-1)) 1 1 1, c_b = 0 iff bit b of v is set (width 3L+3+r)
1018frame p = 0 0 (10)^p 1; RT l q Z = l C> 0 0 (10)^q Z 0^inf
1019lev P l = frame P-1 on top of l (P >= 1); lev 0 l = l = 0^inf (the cycle start)
1021R1 q -> q-2, v -> v-1 q >= 3, v >= 1, r = 0, 2
1022R2 q -> q-3, zone(1,L,v) -> zone(0,L+1,2v-2) q >= 3, v >= 1
1023O2 q -> q-2, zone(2,L,0) -> zone(0,L+1,2^(L+1)-1)
1024O1 q -> q-2, zone(1,L,0) -> zone(2,L,2^L-1)
1025O0 q -> q-3, zone(0,L,0) -> zone(0,L+1,2^(L+1)-2) (every round: P -> P+2)
1026PUSH q = 2, zone(0,k+1+L, 2^k-1 + 2^(k+1) o) -> k new frames 0 over P+2, q = 1, zone(1,L,o)
1027 (k = 0: B2; k >= 1: nested levels; all bits set: halts)
1028B1 q = 1: pop frame p, q -> p+3 (+1 if bit 0 set), zone loses its first cell
1029B0 q = 0, bit 0 clear: pop, q -> p+3; B0c q = 0, v = 0: pop, q -> p+2 (p+1 on 111)
1031level starts t = (n,r,L,v): cap = L + [r = 1], K: n >= 2^(cap+1) + 2, J: n >= 3, n odd if r <> 0
1032 K' = K minus (2^(L+1)+2, 2, L, 2^L-1) and (6, 1, 0, 0); M = n + (r = 1 ? v : 2v) + 2^(cap+3) mod 3
1033phase invariants, kept by every round: Saf (no halt, every bite has a rule), KI (start in K'),
1034 ZI (start in J with n < 2^(cap+1) + 2), Qv = M + 2P mod 3 (sign law)
1035U(N): a level from t in J or K' at any frame does not halt within N steps if every pop t' with
1036 U1-U5 is safe for N-1 steps; the inner levels of a nested bite and the rest of the level after
1037 it use U at fewer steps (STK, compose)
1038I = K' with M <> 0 is closed under cycles; start: c0 -->(327) q = 6, zone(2,0,0) = 11111, no frame
1039*)
3Proof outlineCheck: the new items (green) carry the argument; the names read like the proof.md rules.

129 items in 1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.v (1039 lines): 102 Lemma, 24 Definition, 2 Inductive, 1 Fixpoint. 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 "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB").
L23identicalexcept the TM string
2LemmaBR
Lemma BR k: forall l r, l {{B}}> [1]^^k *> r -->* [1]^^k *> l {{B}}> r.
L30new
3LemmaSW
Lemma SW k: forall l r, [1;0]^^k *> l <{{C}} r -->* l <{{C}} [0;1]^^k *> r.
L33new
4LemmaTT
Lemma TT j: forall l r, [1;1;1]^^j *> l <{{C}} r -->* l <{{C}} [0;1;1]^^j *> r.
L36new
5LemmaPS
Lemma PS b: forall l r, [1;1;0] *> l {{B}}> [1;0]^^b *> r -->* [1;1] *> [0;1]^^b *> [0] *> l {{B}}> r.
L39new
6LemmaRND2
Lemma RND2 q j: forall l r,
l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;0] *> r -->+
[1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^(q+1) *> [1;1;0]^^j *> [1;1;1] *> r.
L43new
7LemmaRND1
Lemma RND1 q j: forall l r,
l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;1;1;0] *> r -->+
[1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^(q+1) *> [1;1;1;1] *> [0;1;1]^^j *> [1] *> r.
L48new
8LemmaRND0
Lemma RND0 q j: forall l r,
l {{C}}> [0;0] *> [1;0]^^(q+3) *> [1;1;1]^^j *> [1;1;1;0] *> r -->+
[1;0;1;0] *> l {{C}}> [0;0] *> [1;0]^^q *> [1;1;1;1;1] *> [0;1;1]^^j *> [1] *> r.
L53new
9LemmaPUSH
Lemma PUSH k: forall l r,
l {{C}}> [0;0] *> [1;0]^^2 *> [1;1;0]^^k *> [1;1;1] *> r -->+
[1;0;0]^^k *> [1;0;1;0] *> l {{C}}> [0;0] *> [1;0] *> [1] *> r.
L59new
10LemmaBITE1
Lemma BITE1 p: forall l r,
[1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;0] *> [1;1] *> r -->+
l {{C}}> [0;0] *> [1;0]^^(p+3) *> [1] *> r.
L65new
11LemmaBITE0
Lemma BITE0 p j: forall l r,
[1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1]^^j *> [1;1;0] *> r -->+
l {{C}}> [0;0] *> [1;0]^^(p+2) *> [1] *> [0;1;1]^^j *> [1] *> r.
L70new
12LemmaBITE0c
Lemma BITE0c p j: forall l r,
[1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1]^^j *> [1;1;1;1;1;1;0] *> r -->+
l {{C}}> [0;0] *> [1;0]^^(p+2) *> [1;1;1] *> [1;1;0]^^j *> [1;1;1] *> r.
L75new
13LemmaBITE0c3
Lemma BITE0c3 p: forall l r,
[1] *> [0;1]^^p *> [0;0] *> l {{C}}> [0;0] *> [1;1;1;0;0] *> r -->+
l {{C}}> [0;0] *> [1;0]^^(p+1) *> [1;1;1;1;1;1] *> r.
L80new
14Definitionbitc
Definition bitc (v : nat) : sym := if Nat.odd v then 0 else 1.
L88new
15Fixpointdg
Fixpoint dg (L v : nat) : list sym :=
match L with
| O => []
| S L' => [1;1;bitc v] ++ dg L' (Nat.div2 v)
end.
L90new
16Definitionzone
Definition zone (r L v : nat) : list sym := [1]^^r ++ dg L v ++ [1;1;1].
L96new
17Lemmabitc_even
Lemma bitc_even v: bitc (2*v) = 1.
L98new
18Lemmabitc_odd
Lemma bitc_odd v: bitc (2*v+1) = 0.
L101new
19Lemmadiv2_even
Lemma div2_even v: Nat.div2 (2*v) = v.
L104new
20Lemmadiv2_odd
Lemma div2_odd v: Nat.div2 (2*v+1) = v.
L107new
21Lemmadg_even
Lemma dg_even L v: dg (S L) (2*v) = [1;1;1] ++ dg L v.
L110new
22Lemmadg_odd
Lemma dg_odd L v: dg (S L) (2*v+1) = [1;1;0] ++ dg L v.
L113new
23Lemmapow_pos
Lemma pow_pos P: 1 <= 2^P.
L116new
24Lemmadg_zero
Lemma dg_zero L: dg L 0 = [1;1;1]^^L.
L119new
25Lemmadg_full
Lemma dg_full L: dg L (2^L - 1) = [1;1;0]^^L.
L125new
26Lemmadg_low
Lemma dg_low b L o: dg (b + S L) (2^b*(2*o+1)) = [1;1;1]^^b ++ [1;1;0] ++ dg L o.
L132new
27Lemmadg_lowones
Lemma dg_lowones k L o: dg (k + S L) (2^k - 1 + 2^(S k)*o) = [1;1;0]^^k ++ [1;1;1] ++ dg L o.
L140new
28Lemmalowbit
Lemma lowbit (x:nat): x <> 0%nat -> exists P o, x = 2^P*(2*o+1).
L149new
29Lemmalowbit_lt
Lemma lowbit_lt b o L: 2^b*(2*o+1) < 2^L -> b < L /\ o < 2^(L-b-1).
L158new
30Lemmaones_comm
Lemma ones_comm b: [1;1] ++ [1;1;1]^^b = [1;1;1]^^b ++ [1;1].
L169new
31Lemmaone_comm
Lemma one_comm b: [1] ++ [1;1;1]^^b = [1;1;1]^^b ++ [1].
L172new
32Lemmash110
Lemma sh110 b: [1;1] ++ [0;1;1]^^b = [1;1;0]^^b ++ [1;1].
L175new
33LemmaS_ones2
Lemma S_ones2 b s: [1;1] *> [1;1;1]^^b *> s = [1;1;1]^^b *> [1;1] *> s.
L178new
34LemmaS_ones1
Lemma S_ones1 b s: [1] *> [1;1;1]^^b *> s = [1;1;1]^^b *> [1] *> s.
L181new
35LemmaS_sh110
Lemma S_sh110 b s: [1;1] *> [0;1;1]^^b *> s = [1;1;0]^^b *> [1;1] *> s.
L184new
36DefinitionRT
Definition RT (l : side) (q : nat) (Z : list sym) : Q * tape := l {{C}}> [0;0] *> [1;0]^^q *> Z *> const 0.
L189new
37LemmaR1z
Lemma R1z l q L v: 1 <= v -> v < 2^L ->
RT l (q+3) (zone 0 L v) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 0 L (v-1)).
L191new
38LemmaR1t
Lemma R1t l q L v: 1 <= v -> v < 2^L ->
RT l (q+3) (zone 2 L v) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 2 L (v-1)).
L202new
39LemmaR2r
Lemma R2r l q L v: 1 <= v -> v < 2^L ->
RT l (q+3) (zone 1 L v) -->+ RT ([1;0;1;0] *> l) q (zone 0 (S L) (2*v-2)).
L216new
40LemmaO2r
Lemma O2r l q L:
RT l (q+3) (zone 2 L 0) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 0 (S L) (2^(S L)-1)).
L230new
41LemmaO1r
Lemma O1r l q L:
RT l (q+3) (zone 1 L 0) -->+ RT ([1;0;1;0] *> l) (q+1) (zone 2 L (2^L-1)).
L240new
42LemmaO0r
Lemma O0r l q L:
RT l (q+3) (zone 0 L 0) -->+ RT ([1;0;1;0] *> l) q (zone 0 (S L) (2^(S L)-2)).
L251new
43DefinitionFR
Definition FR (p : nat) (l : side) : side := [1] *> [0;1]^^p *> [0;0] *> l.
L265new
44LemmaPUSHr
Lemma PUSHr l k L o:
RT l 2 (zone 0 (k + S L) (2^k - 1 + 2^(S k)*o)) -->+ RT ([1;0;0]^^k *> [1;0;1;0] *> l) 1 (zone 1 L o).
L267new
45LemmaB1z0
Lemma B1z0 p l L v: RT (FR p l) 1 (zone 0 (S L) (2*v)) -->+ RT l (p+3) (zone 2 L v).
L275new
46LemmaB1z1
Lemma B1z1 p l L v: RT (FR p l) 1 (zone 0 (S L) (2*v+1)) -->+ RT l (p+4) (zone 0 L v).
L282new
47LemmaB1o
Lemma B1o p l L v: RT (FR p l) 1 (zone 1 L v) -->+ RT l (p+3) (zone 0 L v).
L290new
48LemmaB1t
Lemma B1t p l L v: RT (FR p l) 1 (zone 2 L v) -->+ RT l (p+3) (zone 1 L v).
L300new
49LemmaB0r
Lemma B0r p l b L o:
RT (FR p l) 0 (zone 0 (S b + S L) (2^(S b)*(2*o+1))) -->+ RT l (p+3) (zone 0 (b + S L) (2^b - 1 + 2^(S b)*o)).
L307new
50LemmaB0cr
Lemma B0cr p l L: RT (FR p l) 0 (zone 0 (S L) 0) -->+ RT l (p+2) (zone 0 (S L) (2^(S L)-2)).
L318new
51LemmaB0c3r
Lemma B0c3r p l: RT (FR p l) 0 (zone 0 0 0) -->+ RT l (p+1) (zone 0 1 0).
L328new
52LemmaFR_round
Lemma FR_round p l: [1;0;1;0] *> FR p l = FR (p+2) l.
L339new
53Lemmainit
Lemma init: c0 -->* RT (const 0) 6 (zone 2 0 0).
L347new
54Definitionlev
Definition lev (P : nat) (l : side) : side :=
match P with
| O => l
| S p => FR p l
end.
L353new
55DefinitionokL
Definition okL (P : nat) (l : side) : Prop := P = 0%nat -> l = const 0.
L359new
56Lemmalev_round
Lemma lev_round P l: okL P l -> [1;0;1;0] *> lev P l = lev (P+2) l.
L361new
57LemmaokL_S
Lemma okL_S P l: okL (S P) l.
L368new
58InductiveRnd
Inductive Rnd : nat -> nat -> nat -> nat -> nat -> nat -> nat -> nat -> Prop :=
| RR1z q L v: 1 <= v -> Rnd (q+3) 0 L v (q+1) 0 L (v-1)
| RR1t q L v: 1 <= v -> Rnd (q+3) 2 L v (q+1) 2 L (v-1)
| RR2 q L v: 1 <= v -> Rnd (q+3) 1 L v q 0 (S L) (2*v-2)
| RO2 q L: Rnd (q+3) 2 L 0 (q+1) 0 (S L) (2^(S L)-1)
| RO1 q L: Rnd (q+3) 1 L 0 (q+1) 2 L (2^L-1)
… +1 lines
L372new
59LemmaRnd_tape
Lemma Rnd_tape q r L v q' r' L' v' P l:
Rnd q r L v q' r' L' v' -> v < 2^L -> okL P l ->
RT (lev P l) q (zone r L v) -->+ RT (lev (P+2) l) q' (zone r' L' v').
L380new
60LemmaRnd_valid
Lemma Rnd_valid q r L v q' r' L' v':
Rnd q r L v q' r' L' v' -> v < 2^L -> r < 3 -> v' < 2^L' /\ r' < 3.
L394new
61LemmaRnd_exists
Lemma Rnd_exists q r L v: 3 <= q -> r < 3 -> exists q' r' L' v', Rnd q r L v q' r' L' v'.
L400new
62LemmaokL_ge
Lemma okL_ge P l: 1 <= P -> okL P l.
L414new
63Definitioncap
Definition cap (r L : nat) : nat := L + (if Nat.eqb r 1 then 1 else 0).
L419new
64DefinitionKst
Definition Kst (n r L : nat) : Prop := 2^(S (cap r L)) + 2 <= n.
L422new
65DefinitionJst
Definition Jst (n r : nat) : Prop := 3 <= n /\ (r <> 0%nat -> n mod 2 = 1%nat).
L425new
66DefinitionMv
Definition Mv (n r L v : nat) : nat :=
(n + (if Nat.eqb r 1 then v else 2*v) + 2 * 2^(cap r L + 2)) mod 3.
L428new
67DefinitionQv
Definition Qv (P q r L v : nat) : nat := (Mv q r L v + 2*P) mod 3.
L432new
68DefinitionIst
Definition Ist (n r L v : nat) : Prop :=
r < 3 /\ v < 2^L /\ Kst n r L /\ Mv n r L v <> 0%nat /\ ~ (n = 6 /\ r = 1 /\ L = 0 /\ v = 0)%nat.
L434new
69Lemmainit_I
Lemma init_I: Ist 6 2 0 0.
L437new
70LemmaRnd_sign
Lemma Rnd_sign P q r L v q' r' L' v':
Rnd q r L v q' r' L' v' -> Qv P q r L v = Qv (P+2) q' r' L' v'.
L440new
71InductiveEB
Inductive EB : nat -> nat -> nat -> nat -> nat -> nat -> nat -> nat -> Prop :=
| EB1z0 L v: EB 1 0 (S L) (2*v) 2 2 L v
| EB1z1 L v: EB 1 0 (S L) (2*v+1) 3 0 L v
| EB1o L v: EB 1 1 L v 2 0 L v
| EB1t L v: EB 1 2 L v 2 1 L v
| EB0 b L o: EB 0 0 (S b + S L) (2^(S b)*(2*o+1)) 2 0 (b + S L) (2^b - 1 + 2^(S b)*o)
… +2 lines
L450new
72LemmaEB_tape
Lemma EB_tape q r L v e r' L' v' p l:
EB q r L v e r' L' v' -> RT (FR p l) q (zone r L v) -->+ RT l (S p + e) (zone r' L' v').
L459new
73LemmaEB_sign
Lemma EB_sign q r L v e r' L' v' P:
EB q r L v e r' L' v' -> (Mv (P + e) r' L' v' + Qv P q r L v) mod 3 = 0%nat.
L473new
74Lemmaiter_FR0
Lemma iter_FR0 k X: [1;0;0]^^k *> X = Nat.iter k (FR 0) X.
L486new
75LemmaPUSH_lev
Lemma PUSH_lev k L o P l: okL P l ->
RT (lev P l) 2 (zone 0 (k + S L) (2^k - 1 + 2^(S k)*o)) -->+
RT (Nat.iter k (FR 0) (lev (P+2) l)) 1 (zone 1 L o).
L492new
76Lemmainner1
Lemma inner1 k L o X:
RT (Nat.iter (S k) (FR 0) X) 1 (zone 1 L o) -->+ RT (Nat.iter k (FR 0) X) 3 (zone 0 L o).
L501new
77Definitionsafe
Definition safe (c : Q * tape) (N : nat) : Prop := forall M, M <= N -> ~ halts_in tm c M.
L507new
78Lemmasafe_mono
Lemma safe_mono c N N': safe c N -> N' <= N -> safe c N'.
L509new
79Lemmasafe_ev
Lemma safe_ev c c' N: c -->* c' -> safe c' N -> safe c N.
L512new
80Lemmasafe_prog
Lemma safe_prog c c' N: c -->+ c' -> safe c' (N - 1) -> safe c N.
L520new
81Lemmasafe_prog0
Lemma safe_prog0 c c': c -->+ c' -> safe c 0.
L528new
82Lemmasafe_RT0
Lemma safe_RT0 l q Z: safe (RT l q Z) 0.
L534new
83Lemmaphase
Lemma phase (Inv : nat -> nat -> nat -> nat -> nat -> Prop):
(forall j q r L v q' r' L' v', Rnd q r L v q' r' L' v' -> v < 2^L ->
   Inv j q r L v -> Inv (j+2) q' r' L' v') ->
forall q j P l r L v, okL (P + j) l -> r < 3 -> v < 2^L -> Inv j q r L v ->
exists j' q' r' L' v', q' <= 2 /\ r' < 3 /\ v' < 2^L' /\ Inv j' q' r' L' v' /\
  j <= j' /\ (3 <= q -> j + 2 <= j') /\
… +1 lines
L543new
84Lemmacap0
Lemma cap0 L: cap 0 L = L.
L567new
85Lemmacap1
Lemma cap1 L: cap 1 L = S L.
L568new
86Lemmacap2
Lemma cap2 L: cap 2 L = L.
L569new
87Lemmapow0
Lemma pow0 L: L = 0%nat -> 2^L = 1%nat.
L573new
88DefinitionKx
Definition Kx (n r L v : nat) : Prop :=
Kst n r L /\ ~ (r = 2%nat /\ v = 2^L - 1 /\ n = 2^(S L) + 2) /\
~ (n = 6%nat /\ r = 1%nat /\ L = 0%nat /\ v = 0%nat).
L577new
89DefinitionPre
Definition Pre (n r L v : nat) : Prop := Jst n r \/ Kx n r L v.
L581new
90DefinitionSaf
Definition Saf (q r L v : nat) : Prop :=
match r with
| O => (L = 0%nat -> 3 <= q) /\ ~ (q = 2%nat /\ v = 2^L - 1) /\ (q = 0%nat -> v mod 2 = 0%nat)
| 1%nat => 3 <= q /\ (v = 0%nat -> (q <= 2^(S L) + 2 -> q mod 2 = 1%nat) /\ q <> 2^(S L) + 4)
| _ => (q <= 2*v + 2 -> q mod 2 = 1%nat) /\ q <> 2*v + 4
end.
L584new
91DefinitionKI
Definition KI (j q r L v : nat) : Prop :=
match r with
| O => 2^L <= j + q /\ (2^(S L) <= j + 2*v + 2 \/ 2^(S L) + 1 <= j + q) /\
       (q = 0%nat -> v <> 0%nat) /\ (L = 0%nat -> 4 <= q)
| 1%nat => 2^(S (S L)) + 2 <= q /\ (v = 0%nat -> 2^(S L) + 5 <= q)
| _ => 2^(S L) + 2 <= j + q /\ 2*v + 5 <= q
… +1 lines
L592new
92DefinitionZI
Definition ZI (C q r L v : nat) : Prop :=
1 <= C /\
match r with
| O => L <= S C /\ q + 2^(S (S L)) + C <= 2*v + L + 2^(S (S (S C))) + 1 /\
       (q = 0%nat -> v = 0%nat -> L <= C)
| 1%nat => S (S L) <= C /\ q <= 2^(S (S L)) + 1 /\ 3 <= q
… +2 lines
L601new
93LemmaSaf_step
Lemma Saf_step q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> Saf q r L v -> Saf q' r' L' v'.
L610new
94LemmaKI_step
Lemma KI_step j q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> KI j q r L v -> KI (j+2) q' r' L' v'.
L616new
95Lemmapow_mono
Lemma pow_mono a b: a <= b -> 2^a <= 2^b.
L624new
96Lemmapow_lin
Lemma pow_lin a: S a <= 2^a.
L627new
97LemmaZI_step
Lemma ZI_step C q r L v q' r' L' v': Rnd q r L v q' r' L' v' -> v < 2^L -> ZI C q r L v -> ZI C q' r' L' v'.
L630new
98DefinitionPI
Definition PI (n r L v j q r' L' v' : nat) : Prop :=
j mod 2 = 0%nat /\ Qv j q r' L' v' = Mv n r L v /\
(r' = 1%nat -> j = 0%nat) /\ (r' = 2%nat -> L' = 0%nat -> j <= 2) /\
Saf q r' L' v' /\ (Kx n r L v -> KI j q r' L' v') /\
(Jst n r -> ~ Kst n r L -> ZI (S (cap r L)) q r' L' v').
L647new
99LemmaPI_step
Lemma PI_step n r L v j q r1 L1 v1 q' r' L' v':
Rnd q r1 L1 v1 q' r' L' v' -> v1 < 2^L1 -> PI n r L v j q r1 L1 v1 -> PI n r L v (j+2) q' r' L' v'.
L653new
100LemmaMv_lt3
Lemma Mv_lt3 n r L v: Mv n r L v < 3.
L668new
101LemmaQv0
Lemma Qv0 q r L v: Qv 0 q r L v = Mv q r L v.
L671new
102LemmaPre_n3
Lemma Pre_n3 n r L v: Pre n r L v -> 3 <= n.
L674new
103LemmaSaf_start
Lemma Saf_start n r L v: r < 3 -> v < 2^L -> Pre n r L v -> Saf n r L v.
L679new
104LemmaKI_start
Lemma KI_start n r L v: r < 3 -> v < 2^L -> Kx n r L v -> KI 0 n r L v.
L689new
105LemmaZI_start
Lemma ZI_start n r L v: r < 3 -> v < 2^L -> Jst n r -> ~ Kst n r L -> ZI (S (cap r L)) n r L v.
L697new
106LemmaPI_start
Lemma PI_start n r L v: r < 3 -> v < 2^L -> Pre n r L v -> PI n r L v 0 n r L v.
L704new
107DefinitionPost
Definition Post (n r L v n' r' L' v' : nat) : Prop :=
r' < 3 /\ v' < 2^L' /\
(Jst n r -> Jst (S n') r') /\
(Kx n r L v -> Kst n' r' L') /\
(Jst n r -> ~ Kst n r L -> Kst (S n') r' L' \/ cap r' L' <= S (cap r L)) /\
(Mv n' r' L' v' + Mv n r L v) mod 3 = 0%nat /\
… +1 lines
L714new
108DefinitionU
Definition U (N : nat) : Prop :=
forall P l n r L v, okL P l -> r < 3 -> v < 2^L -> Pre n r L v ->
(forall n' r' L' v', Post n r L v n' r' L' v' -> safe (RT l (P + n') (zone r' L' v')) (N - 1)) ->
safe (RT (lev P l) n (zone r L v)) N.
L722new
109Lemmalowones
Lemma lowones L: forall v, v < 2^L -> v <> 2^L - 1 ->
exists k L' o, L = k + S L' /\ v = 2^k - 1 + 2^(S k) * o /\ o < 2^L'.
L729new
110Lemmabite_shape
Lemma bite_shape j qb rb Lb vb: qb <= 2 -> rb < 3 -> vb < 2^Lb -> Saf qb rb Lb vb -> 2 <= j ->
(rb = 1%nat -> j = 0%nat) ->
(exists e r' L' v', EB qb rb Lb vb e r' L' v') \/
(qb = 2%nat /\ rb = 0%nat /\ exists k L' o, Lb = k + S L' /\ vb = 2^k - 1 + 2^(S k) * o /\ o < 2^L').
L742new
111LemmaEB_valid
Lemma EB_valid q r L v e r' L' v': EB q r L v e r' L' v' -> v < 2^L -> r' < 3 /\ v' < 2^L'.
L766new
112LemmaEB_lev
Lemma EB_lev q r L v e r' L' v' P l: 1 <= P -> EB q r L v e r' L' v' ->
RT (lev P l) q (zone r L v) -->+ RT l (P + e) (zone r' L' v').
L779new
113LemmaKst_mono
Lemma Kst_mono n n' r L: Kst n r L -> n <= n' -> Kst n' r L.
L783new
114Lemmaending
Lemma ending n r L v j qb rb Lb vb e r' L' v':
EB qb rb Lb vb e r' L' v' -> PI n r L v j qb rb Lb vb -> 2 <= j -> vb < 2^Lb ->
Post n r L v (j + e) r' L' v'.
L787new
115Lemmaending_B2
Lemma ending_B2 n r L v j L' o:
PI n r L v j 2 0 (0 + S L') (2^0 - 1 + 2^1 * o) -> 2 <= j -> o < 2^L' ->
Post n r L v (j + 4) 0 L' o.
L808new
116DefinitionBudget
Definition Budget (n r L C : nat) : Prop := Kst n r L \/ cap r L <= C.
L828new
117DefinitionSR
Definition SR (j a b : nat) : Prop :=
(j mod 2 = 0%nat -> b = a) /\ (j mod 2 = 1%nat -> (a + b + 2) mod 3 = 0%nat).
L831new
118LemmaJK
Lemma JK n r L v: Jst n r -> Kst n r L -> Kx n r L v.
L834new
119LemmaBudget_step
Lemma Budget_step n r L v C n' r' L' v': Jst n r -> Budget n r L C -> Post n r L v n' r' L' v' ->
Budget (S n') r' L' (S C).
L841new
120LemmaMv_shift
Lemma Mv_shift a n r L v: Mv (a + n) r L v = (Mv n r L v + a) mod 3.
L851new
121LemmaSR_step
Lemma SR_step j n r L v n' r' L' v' b: b < 3 -> Post n r L v n' r' L' v' -> SR j (Mv (S n') r' L' v') b ->
SR (S j) (Mv n r L v) b.
L854new
122Lemmapow2_mod3
Lemma pow2_mod3 k: exists x, 2^k = 3*x + 1 + k mod 2.
L863new
123LemmaQvN
Lemma QvN j k L o:
(k mod 2 = 0%nat -> Qv j 2 0 (S k + S L) (2^(S k) - 1 + 2^(S (S k)) * o) = (Mv 3 0 L o + 1 + 2*j) mod 3) /\
(k mod 2 = 1%nat -> Qv j 2 0 (S k + S L) (2^(S k) - 1 + 2^(S (S k)) * o) = (2 * (Mv 3 0 L o + 1) + 2*j) mod 3).
L870new
124Lemmacompose
Lemma compose n r L v j k L' o n1 r1 L1 v1 n3 r3 L3 v3:
PI n r L v j 2 0 (S k + S L') (2^(S k) - 1 + 2^(S (S k)) * o) -> 2 <= j ->
Jst n1 r1 -> Budget n1 r1 L1 (L' + k) -> SR k (Mv 3 0 L' o) (Mv n1 r1 L1 v1) ->
Post n1 r1 L1 v1 n3 r3 L3 v3 -> Post n r L v (j + 2 + n3) r3 L3 v3.
L881new
125LemmaSTK
Lemma STK: forall j B, (forall B', B' <= B -> U B') -> forall n r L v C X,
Jst n r -> Budget n r L C -> r < 3 -> v < 2^L ->
(forall n1 r1 L1 v1, Jst n1 r1 -> Budget n1 r1 L1 (C + j) -> r1 < 3 -> v1 < 2^L1 ->
   SR j (Mv n r L v) (Mv n1 r1 L1 v1) -> safe (RT X n1 (zone r1 L1 v1)) (B - j)) ->
safe (RT (Nat.iter j (FR 0) X) n (zone r L v)) B.
L911new
126LemmaU_all
Lemma U_all: forall N, U N.
L938new
127LemmaIst_Kx
Lemma Ist_Kx n r L v: Ist n r L v -> Kx n r L v.
L988new
128Lemmacycles
Lemma cycles N: forall n r L v, Ist n r L v -> safe (RT (const 0) n (zone r L v)) N.
L995new
129Lemmanonhalt
Lemma nonhalt: ~halts tm c0.
L1008adapted
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 92: 1. Rule table (busycoq comment-block style)

This block is a compact reference. §2 defines every symbol in it, and §3 derives every rule.

1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB            (only F0 is undefined)

lattice(w) = { j = w-1-3i : i >= 1, j >= 2 };   bit b of v (b = 0, 1, ...) sits on the b-th smallest lattice cell
enc(w,v)   = 1^w with 0 on the lattice cells of the set bits of v;   L(w) = #lattice(w) = floor(w/3) - 1
cap(w)     = L(w) + [w = 1 mod 3]                    allset(u) = enc(u, 2^L(u) - 1)
R(p,q,Z)   = 0^inf (10)^p 1 C> 0 0 (10)^q Z 0^inf  (p >= 0);   R(-1,q,Z) = 0^inf C> 0 0 (10)^q Z 0^inf  (cycle start)
             (Z never starts with 10: the bell takes every leading 10 pair; Z has no trailing 0)
R_L(p,q,Z) = L 0 0 (10)^p 1 C> 0 0 (10)^q Z 0^inf     (p >= 0, any left context L;  R = R_(0^inf))
R_L(-1,q,Z) = L C> 0 0 (10)^q Z 0^inf                  (only a name for the tape a level pops to)
             no rule is applied to R_L(-1, ..) unless L = 0^inf;  if L = L' 0 0 1 it is the tape R_L'(0, q, Z)

low-level rules (each run reads only the cells shown)
BR   B> 1^k              --> 1^k B>                                    k
S    (01)^k <C           --> <C (01)^k                                 2k       C1 D0
T    (111)^j <C          --> <C (011)^j                                5j       C1 D1 A1 C1 D0
W    C> 00 101010        --> 0101 0011 B>                              10
PS   011 B> (10)^b       --> 0 (10)^b 11 B>                            12b
ZA   00 (10)^a 11 B> 1^f 0  --> C> 0 (01)^(a+1) (011)^j 1              f = 2 mod 3, j = (f+1)/3
                            --> C> 0 (01)^(a+2) 111 (011)^(j-2) 1      f = 1 mod 3, f >= 4, j = (f+2)/3
                            --> C> 0 (01)^a 011111 (011)^(j-1) 1       f = 0 mod 3, f >= 3, j = f/3
PUSH C> 00 1010 (110)^k 111  --> 0101 (001)^k C> 00 101                14+3k   (k >= 0)
B1   00 (10)^p 1 C> 00 10 11 --> C> 00 (10)^(p+3) 1                    2p+15
B0   00 (10)^p 1 C> 00 1^f 0 --> C> 00 (10)^(p+2) 1 (011)^j 1          f = 2 mod 3, j = (f-2)/3
B0c  00 (10)^p 1 C> 00 1^w 0 --> C> 00 (10)^(p+2) 11 allset(w-2)       w = 0 mod 3, w >= 6
     00 (10)^p 1 C> 00 111 00 --> C> 00 (10)^(p+1) 111111              2p+31
Ht   C> 00 101 000       --> 0101 001 F> 0  (F0 undefined)             9

macro rules (Z = enc(w,v), f = position of the first 0 of Z, or w if v = 0; p >= 0 and any left context L;
             the five rounds also hold at p = -1 with L = 0^inf, where they give R(1, ..), §3.2)
R1   R_L(p,q,Z) --> R_L(p+2, q-2, enc(w, v-1))              q >= 3, v >= 1, w = 0,2 mod 3
R2   R_L(p,q,Z) --> R_L(p+2, q-3, enc(w+2, 2v-2))           q >= 3, v >= 1, w = 1 mod 3
O2   R_L(p,q,Z) --> R_L(p+2, q-2, enc(w+1, 2^(L+1)-1))      q >= 3, v = 0,  w = 2 mod 3
O1   R_L(p,q,Z) --> R_L(p+2, q-2, enc(w+1, 2^L-1))          q >= 3, v = 0,  w = 1 mod 3, w >= 4
O0   R_L(p,q,Z) --> R_L(p+2, q-3, enc(w+3, 2^(L+1)-2))      q >= 3, v = 0,  w = 0 mod 3
     (all five = W, PS^(q-3), ZA; 10 + 12(q-3) + f + 1 + 5j + {2(q-2) | 5+2(q-1) | 11+2(q-3)} steps)
B2   R_L(p,2,Z) --> R_L(p+2, 1, Z[2:])  re-parsed           Z starts 111, w >= 6    (PUSH k=0)
                (w = 1, bit 0 set: R_L(p+2, 2, enc(w-4, (v-1)/2)); never occurs, Lemma P)
N    R_L(p,2,(110)^k Y) --> R_L(p+2, G^(k-1)(3, Y[3:]))     k >= 1, Y starts 111, |Y| >= 6
H    R_L(p,2,(110)^k 111) --> halts                         k >= 1  (PUSH k, then Ht: 23+3k steps)
                (also k = 0, Z = 111: PUSH 0, then Ht; never occurs, since a bite zone has width >= 5, P1)
B1   R_L(p,1,Z) --> R_L(-1, p+3, Z[1:])  re-parsed          p >= 0, Z starts 11
B0   R_L(p,0,Z) --> R_L(-1, p+3, enc(w-3, (v-2)/2))         w = 0 mod 3, v >= 1 even
                --> R_L(-1, p+2, enc(w-1, (v-1)/2))         w = 0 mod 3, v odd      (never occurs, Lemma P)
B0c  R_L(p,0,1^w) --> R_L(-1, p+2, enc(w, 2^L-2))           w = 0 mod 3, w >= 6;   1^3 --> R_L(-1,p+1,1^6)
     ending bites (B1, B0, B0c) need the 0 0 left of (10)^p 1 and read nothing left of it

levels:  t = (n,w,v);  F(t) = the cycle start R(-1, F t) reached from R(-1, n, enc(w,v));
         the run from R_L(p0, n, enc(w,v)), p0 >= 0, n >= 3, pops at R_L(-1, F(t) + (p0+1, 0, 0))  (L never read);
         G(t) = F(t) + (1,0,0) = where a level started at R_L(0, n, enc(w,v)) pops
stack:   N = PUSH k, then the innermost level R_L1(0,1,Y[2:]) --B1--> (3, Y[3:]); level i pops into
         level i+1 (R_L(-1, ..) of level i = R_L'(0, ..) of level i+1); level k pops into R(p+2, ..)

invariant:  d(t) = n - 2^(cap(w)+1);  M(t) = n + 2v - 2^(cap+2) (w = 0,2) | n + v - 2^(cap+2) (w = 1)  (mod 3)
   K = { w >= 3, d >= 2 };   I = { t in K : M(t) != 0 } minus (6,4,0)
   J = { w >= 3, n >= 3, n odd if w = 1,2 mod 3 }               (inner phase starts)
   H* = { w = 2: n = 2v+4 } u { w = 1: v = 0, n = 2^(L+1)+4 }    (the phase starts that halt)
   s in I  ->  the cycle from s never halts, and if it ends, F(s) is in I   (M(F s) = -M(s))
start:  c0 -->(327) R(-1, 6, 11111) = (6,5,0),  d = 4, M = 2:  in I
5FamilyCheck: related machines are killed together or have a reason to be left open.

1 machines, 1 killed, 0 not. Family links: status.json parent, same transition table with another start (tools/dashboard.py), targeting.md follow-on rows, ledger "= twin" notes. A machine string named in a .v header / proof.md / notes.md is listed but does not make a family.

whomachinestatusrelation to this kill
W5-4 kill 311RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB✓Killed: never haltsthis kill
Named in a file but not linked (not counted as family)
W4-2 kill 181RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF✓Killed: never haltsnamed in W5-4's proof.md; named in W5-4's notes.md · review · mechanism
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 558 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
    0 assumption(s); tools/assumptions_baseline.txt allows only functional_extensionality_dep
  • ✓
    coqchk finished (optional)
    coqchk pass in 4.57 s
  • ✓
    .v hash matches the checked hash
    .v = checked sha256 f61649bdc6b6…; submission/ copy = checked sha256 f61649bdc6b6…
  • ✓
    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
    • proof.md L634: ## 12. Checkpoint B (Dennis)
    • proof.md L651: - Open: Checkpoint B; a skeptic pass by a second agent; the Rocq build (§9).
  • ○
    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 never halts” (above), which quotes how_proved.md. Re-run: python3 -B tools/killreview.py 1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB

Files

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

namesizechanged
notes.md ↓36 KB2026-10-13 13:16
proof.md ↓55 KB2026-10-13 11:53
how_proved.md ↓1.6 KB2026-10-14 10:51
status.json ↓5.4 KB2026-10-16 10:28
observe.json ↓15 KB2026-10-13 02:13
deepen.json ↓3.7 KB2026-10-13 09:30
1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.v ↓45 KB2026-10-13 12:58
decisions/1 item2026-10-13 09:25
img/7 items2026-10-13 01:15
rocq/3 items2026-10-13 12:59
scripts/17 items2026-10-13 09:23
submission/6 items2026-10-15 15:49
work/43 items2026-10-13 11:33
check_proof.py ↓43 KB2026-10-13 11:22
status.json in full
{
 "tm": "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB",
 "status": "KILLED_NONHALT",
 "stage": "done",
 "updated": "2026-10-13",
 "reason": "check_kill PASS, independently re-verified",
 "label": "W5-4",
 "confidence": "high",
 "template": "verify/BECv5.v, Module TM1 (architecture: one es lemma per low-level rule, one counter-form lemma per macro rule; via our W4-2 kill)",
 "siblings": [],
 "family_note": "Canon over all 6 starts (renaming + mirror): only start A is on the 778/740 lists (starts B..F halt within 44 steps). No 740 entry within 2 transitions of any renamed/mirrored form. Eqv group in 2026-10-07_eqv_1590.txt is a singleton.",
 "checks": {
  "byte_exact": "data/holdouts/BB6_holdouts_740.txt line 525 (holdouts.py contains: exit 0)",
  "claims": "none (sheet results.csv row 1044: class only; no data/discord hit)",
  "upstream": "holdouts.py solved: absent from verify/ (no byte-exact, notation-only or equivalent entry)",
  "rules": "scripts/validate_rules.py seed 3, 150 per kind: all pass; B0c 180/180; nested B2'' model 252/252 + 4 halts (Y=111) vs TM brute force",
  "coverage": "closed rules + nested model on work/direct_all_events_1e9.txt: 204,951/204,953 exact (2 tiny events before step 30)",
  "abstract_vs_direct": "scripts/absim2.py (no TM simulation) = work/cycle_starts_1e11.txt at 4,197/4,197 cycle starts",
  "transients": "scripts/transient.py from T(L), L = 10..38 closed rules and 10..56 with TM fallback: all LOCK, no halt",
  "invariant": "scripts/invariant.py: Lemma K + M, 0 failures on w 3..31 n < 2^(cap+3) (6,810,622 states), w 3..16 n < 2^(cap+10) (1,132,222) and w 3..12 n < 2^(cap+14) (2,424,478); work/invariant_*.txt",
  "sign_law": "scripts/signlaw.py: TM level 7,977/7,977 random family configurations (seeds 1, 2); rule level 7.3M applications, 0 failures (work/signlaw_seed2.txt)",
  "F_vs_tm": "scripts/check_F_vs_tm.py: closed-rule cycle map = direct TM run on 300/300 random states of I (n <= 700)",
  "entry": "blank run: cycle start (6,5,0) at step 327 is in I, and so are all 304,194 later cycle starts checked (direct run to 1e11, then 300,000 closed-rule cycles)",
  "continuation_lemmas": "scripts/contlemmas.py kwin: A1 (p_c >= 2^L_c - 3, min slack 0), composite form F(s) = (p_c+2) + G^k(t_2) and A2 on 533,148 continuation cycles (w <= 27) + 151,880 (w <= 15, n < 2^(cap+10)), min d' = 5",
  "inner_levels": "scripts/contlemmas.py jwin: Lemma J (G maps J to J, no halt, no gap) on 1,920,333 + 479,621 states; Z' on 239,786 + 906; K-persistence on 1,680,547 + 478,715",
  "halting_set": "scripts/contlemmas.py hstar: the cycle from (n, w, v), w >= 3, n >= 3, halts iff it is in H* on 610,121 (w <= 24) + 606,121 (w <= 12, n < 2^(cap+12)) states",
  "nested_gform": "scripts/contlemmas.py gform: nested bite = k - 1 G-steps from (3, Z >> (k+1)), 20,000/20,000 vs scripts/nested.py",
  "random_large": "scripts/contlemmas.py random seed 2: 200,000 states, w <= 75, n up to 2^(cap+6): 0 failures (Lemma K, A1, CF, A2, J, Z', K-persistence)",
  "tm_level_shift": "scripts/contlemmas.py tm seeds 1, 2: 500 random states (151 J with d <= 1, 349 K): TM run from R(0, n, Z) pops at G(t) and from R(-1, n, Z) at F(t), 500/500 both",
  "check_proof": "check_proof.py (self-contained TM simulator + abstract model), after skeptic round 1: default seed 1 81/81 PASS in 107s (work/check_proof_seed1.log); quick seeds 1, 2 80/80 (work/check_proof_quick_seed*.log); --full seed 1 partial: T..CH 74/74 PASS (CH w <= 27, 1,527,624 K states) and INV window w <= 24, n < 2^(cap+4) PASS (610,121 states, 132,766 continuation cycles), work/check_proof_full_seed1.log + work/check_proof_full_seed1_INV.log; the second --full INV window (w <= 14, n < 2^(cap+11)), the random states and Z were stopped unfinished after 35 min (overflow_count/outer_trace step R1 rounds one at a time). New checks: MAC.round at p = -1 (450 runs, any L), SH with p0 in 0..8 (SL1 on the TM), ABS bite-zone widths, CH parts of NB and the w = 1 reductions, INV CF-J (own-frame composite form), NB as n(F s) >= n - m."
 },
 "funded": {
  "option": "proof",
  "date": "2026-10-13"
 },
 "outcome": "killed_nonhalt",
 "skeptic": [
  {
   "round": 1,
   "date": "2026-10-13",
   "verdict": "sound",
   "gaps": 5,
   "severity": "all minor",
   "result": "all fixed; proof.md Review log; no lemma changed"
  }
 ],
 "kill": {
  "file": "1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_---0RB.v",
  "sha256": "f61649bdc6b6e97b170ccd8b89a210e50f4714d06d97a352c620e62d712574fc",
  "lines": 1039,
  "check_kill": "PASS (fresh run 2026-10-13T20:03:57Z: compile 34.7 s native, coqchk pass 4.6 s, 0 assumptions; also rocq/check_kill_round2.log and the independent auditor run 2026-10-13T20:01:12Z, same sha256)",
  "route": "bounded induction on steps (U_all, CPS form) with phase invariants Saf/KI/ZI; stack of frames FR; (U5) in place of NB",
  "submission": "submission/",
  "discord": "submission/discord.md, not posted (fill in <LINK>; search #bb6 first)"
 },
 "next": "post the Discord draft (submission/discord.md, not posted; fill in <LINK>, search #bb6 first); add to the next upstream PR batch",
 "pr": "https://github.com/ccz181078/busycoq/pull/28",
 "pr_state": "merged",
 "pr_file": "verify/M_1RB0RC_1LC1RB_0RE1LD_0LC1LA_1RF1RA_HHH0RB.v",
 "pr_opened": "2026-10-15T22:48:46Z",
 "pr_comments": 0,
 "pr_head_sha": "051e8bb8e95d65bd1b0d905760f7e66e6cbf7a31",
 "posted": "2026-10-15 (Discord; user confirmed sent)",
 "pr_merged_at": "2026-10-16T07:09:19Z",
 "pr_merged_by": "ccz181078"
}
observe.json contract (tools/README-card.md):
3 contract warnings
  • rank: missing
  • diagrams[2].window: not "cells A..B, 1 px = k cells"
  • template file not in the pinned tree: machines/1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF/1RB1LF_0RC0RB_0LD1LA_1LC0LE_0LA---_1LA1LF.v