Download data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryInterpolation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryInterpolation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryInterpolation.lean
-
curl -L -o BinaryInterpolation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/CriticalPercolation/Entropy/BinaryInterpolation.lean
4.31 kB
| import Mathlib | |
| namespace OAI | |
| section | |
| section | |
| namespace CriticalPercolation.BinaryInterpolation | |
| open scoped Classical | |
| def midpoint (l r : β) : β := (l+r)/2 | |
| def bisect (l r : β) (side : Bool) : β Γ β := | |
| if r β€ l+1 then (l,r) else if side then (midpoint l r,r) else (l,midpoint l r) | |
| lemma midpoint_strict {l r : β} (h : l+1 < r) : | |
| l < midpoint l r β§ midpoint l r < r := by | |
| dsimp [midpoint] | |
| omega | |
| lemma bisect_bounds {l r : β} (h : l < r) (b : Bool) : | |
| l β€ (bisect l r b).1 β§ (bisect l r b).1 < (bisect l r b).2 β§ | |
| (bisect l r b).2 β€ r := by | |
| unfold bisect | |
| split_ifs with ht hb | |
| Β· simp [h] | |
| Β· have hm := midpoint_strict (by omega : l+1 < r) | |
| simp only | |
| omega | |
| Β· have hm := midpoint_strict (by omega : l+1 < r) | |
| simp only | |
| omega | |
| lemma bisect_length {l r : β} (h : l+1 < r) (b : Bool) : | |
| (bisect l r b).2 - (bisect l r b).1 β€ (r-l+1)/2 := by | |
| unfold bisect | |
| rw [ite_eq_right (by omega : Β¬ r β€ l+1)] | |
| cases b <;> simp only [Bool.false_eq_true, βreduceIte,midpoint] <;> omega | |
| lemma bisect_clog {l r : β} (h : l+1 < r) (b : Bool) : | |
| Nat.clog 2 ((bisect l r b).2 - (bisect l r b).1) + 1 β€ Nat.clog 2 (r-l) := by | |
| have hh := Nat.clog_mono_right 2 (bisect_length h b) | |
| rw [Nat.clog_of_one_lt (by decide : 1 < 2) (by omega : 1 < r-l)] | |
| have he : r-l+2-1 = r-l+1 := by omega | |
| rw [he] | |
| exact Nat.add_le_add_right hh 1 | |
| def terminal (l r : β) : List Bool β β Γ β | |
| | [] => (l,r) | |
| | b::bs => terminal (bisect l r b).1 (bisect l r b).2 bs | |
| lemma terminal_bounds {l r : β} (h : l < r) (bs : List Bool) : | |
| l β€ (terminal l r bs).1 β§ (terminal l r bs).1 < (terminal l r bs).2 β§ | |
| (terminal l r bs).2 β€ r := by | |
| induction bs generalizing l r with | |
| | nil => simpa [terminal] using h | |
| | cons b bs ih => | |
| have hb := bisect_bounds h b | |
| have hi := ih hb.2.1 | |
| change l β€ (terminal (bisect l r b).1 (bisect l r b).2 bs).1 β§ _ | |
| exact β¨hb.1.trans hi.1,hi.2.1,hi.2.2.trans hb.2.2β© | |
| lemma terminal_eq_of_adjacent {l r : β} (h : r = l+1) (bs : List Bool) : | |
| terminal l r bs = (l,r) := by | |
| induction bs with | |
| | nil => rfl | |
| | cons b bs ih => simpa only [terminal,bisect,ite_eq_left (by omega : r β€ l+1)] using ih | |
| theorem terminal_adjacent {l r : β} (h : l < r) (bs : List Bool) | |
| (hlen : Nat.clog 2 (r-l) β€ bs.length) : | |
| (terminal l r bs).2 = (terminal l r bs).1 + 1 := by | |
| induction bs generalizing l r with | |
| | nil => | |
| simp only [List.length_nil] at hlen | |
| have hh := (Nat.clog_le_iff_le_pow (by decide : 1 < 2)).mp hlen | |
| simp only [pow_zero] at hh | |
| simp only [terminal] | |
| omega | |
| | cons b bs ih => | |
| by_cases ht : r β€ l+1 | |
| Β· rw [terminal_eq_of_adjacent (by omega : r = l+1)] | |
| dsimp only | |
| omega | |
| Β· have hb := bisect_bounds h b | |
| have hc := bisect_clog (by omega : l+1 < r) b | |
| simp only [List.length_cons] at hlen | |
| exact ih hb.2.1 (by omega) | |
| def anchors (l r : β) : List Bool β Finset β | |
| | [] => {l,r} | |
| | b::bs => {l,r,midpoint l r} βͺ anchors (bisect l r b).1 (bisect l r b).2 bs | |
| lemma terminal_mem_anchors (l r : β) (bs : List Bool) : | |
| (terminal l r bs).1 β anchors l r bs β§ (terminal l r bs).2 β anchors l r bs := by | |
| induction bs generalizing l r with | |
| | nil => simp [terminal,anchors] | |
| | cons b bs ih => | |
| exact β¨Finset.mem_union_right _ (ih _ _).1, Finset.mem_union_right _ (ih _ _).2β© | |
| lemma midpoint_internal {d l r : β} (_hl : l β€ r) (hr : r β€ d) (h : l+1 < r) : | |
| midpoint l r < d β§ 0 < midpoint l r β§ midpoint l r-l < d β§ r-midpoint l r < d := by | |
| have hm := midpoint_strict h | |
| omega | |
| abbrev Descriptor (J : β) := (n : Fin (J+1)) Γ (Fin n.val β Fin 8) | |
| lemma descriptor_card (J : β) : Fintype.card (Descriptor J) = β j β Finset.range (J+1), 8^j := by | |
| simp only [Descriptor,Fintype.card_sigma,Fintype.card_fun,Fintype.card_fin] | |
| exact Fin.sum_univ_eq_sum_range (fun j => 8^j) (J+1) | |
| lemma descriptor_card_le (J : β) : Fintype.card (Descriptor J) β€ 8^(J+1) := by | |
| rw [descriptor_card] | |
| have hh : β n : β, (β j β Finset.range n, 8^j) < 8^n := by | |
| intro n | |
| induction n with | |
| | zero => simp | |
| | succ n ih => rw [Finset.sum_range_succ,pow_succ]; omega | |
| exact (hh (J+1)).le | |
| end CriticalPercolation.BinaryInterpolation | |
| end | |
| end | |
| end OAI | |