Download data/lean/OAI/Combinatorics/CompleteCrossing/Hill.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.97 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CompleteCrossing/Hill.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/CompleteCrossing/Hill.lean
-
curl -L -o Hill.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CompleteCrossing/Hill.lean
9.97 kB
| import Mathlib.Algebra.BigOperators.Group.Finset.Defs | |
| import Mathlib.Algebra.BigOperators.Intervals | |
| import Mathlib.Algebra.Order.Archimedean.Real.Basic | |
| import Mathlib.Algebra.Ring.Parity | |
| import Mathlib.Data.Finset.Card | |
| import Mathlib.Data.Finset.Prod | |
| import Mathlib.Data.Fintype.Pi | |
| import Mathlib.Data.Nat.Cast.Field | |
| import Mathlib.Data.Nat.Choose.Basic | |
| import Mathlib.Data.Nat.Choose.Cast | |
| import Mathlib.Order.Interval.Finset.Nat | |
| import Mathlib.Tactic.IntervalCases | |
| import Mathlib.Tactic.Linarith | |
| import Mathlib.Tactic.NormNum | |
| import Mathlib.Tactic.Ring | |
| import Mathlib.Tactic.Zify | |
| namespace OAI | |
| /-! HararyβHill arithmetic, residue-page definitions, and the even-order deletion inequality. -/ | |
| section | |
| /-! The HararyβHill formula and two-page crossing counts. | |
| -/ | |
| open scoped BigOperators | |
| noncomputable section | |
| namespace Paper170 | |
| /-- The integer in the HararyβHill formula. -/ | |
| def hill (n : β) : β := | |
| (n / 2 * ((n - 1) / 2) * ((n - 2) / 2) * ((n - 3) / 2)) / 4 | |
| /-- The two contiguous residue blocks used by the explicit drawing. -/ | |
| def residueColor (n r : β) : Bool := decide (r % n < n / 2) | |
| /-- Increasing four-tuples whose alternating edges occupy the same page. -/ | |
| def crossingTuples (n : β) : Finset (Fin 4 β Fin n) := by | |
| classical | |
| exact Finset.univ.filter (fun v => StrictMono v β§ | |
| residueColor n ((v 0).val + (v 2).val) = | |
| residueColor n ((v 1).val + (v 3).val)) | |
| /-- Residues with the same color after a cyclic shift by k. -/ | |
| def sameColorResidues (n k : β) : Finset β := | |
| (Finset.range n).filter (fun r => residueColor n r = residueColor n (r + k)) | |
| /-- Cyclic starting points and the first two positive gaps in the source count. -/ | |
| def sameColorGapTuples (n k : β) : Finset (β Γ β Γ β) := | |
| ((Finset.range n) ΓΛ’ ((Finset.Icc 1 (k - 1)) ΓΛ’ (Finset.Icc 1 (n - k - 1)))).filter | |
| (fun v => residueColor n (2 * v.1 + v.2.1 + v.2.2) = | |
| residueColor n (2 * v.1 + v.2.1 + v.2.2 + k)) | |
| /-- Starting labels producing a prescribed diagonal-sum residue. -/ | |
| def residueFiber (n b r : β) : Finset β := | |
| (Finset.range n).filter (fun a => (2 * a + b) % n = r) | |
| /-- One parity class of the same-color residues. -/ | |
| def sameColorResiduesParity (n k p : β) : Finset β := | |
| (sameColorResidues n k).filter (fun r => r % 2 = p) | |
| /-- One parity class of the first-gap choices after a fixed offset. -/ | |
| def firstGapParity (k b p : β) : Finset β := | |
| (Finset.Icc 1 (k - 1)).filter (fun g => (g + b) % 2 = p) | |
| /-- The polynomial whose finite difference evaluates the crossing sum. -/ | |
| def crossingAntiderivative (n k : β€) : β€ := | |
| k * (k - 1) * (n - k - 1) * (n - k - 2) | |
| end Paper170 | |
| end | |
| end | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace Paper170 | |
| theorem crossingAntiderivative_sub (n k : β€) : | |
| crossingAntiderivative n k - crossingAntiderivative n (k - 1) = | |
| 2 * (k - 1) * (n - k - 1) * (n - 2 * k) := by | |
| unfold crossingAntiderivative | |
| ring | |
| theorem hill_numerator_dvd (n : β) : | |
| 4 β£ n / 2 * ((n - 1) / 2) * ((n - 2) / 2) * ((n - 3) / 2) := by | |
| have hβ : (n - 2) / 2 = n / 2 - 1 := by omega | |
| have hβ : (n - 3) / 2 = (n - 1) / 2 - 1 := by omega | |
| rw [hβ, hβ] | |
| convert Nat.mul_dvd_mul (Nat.two_dvd_mul_sub_one (n / 2)) | |
| (Nat.two_dvd_mul_sub_one ((n - 1) / 2)) using 1 | |
| ring | |
| theorem hill_even (s : β) : hill (2 * s) = s * (s - 1) ^ 2 * (s - 2) / 4 := by | |
| have hβ : (2 * s - 1) / 2 = s - 1 := by omega | |
| have hβ : (2 * s - 2) / 2 = s - 1 := by omega | |
| have hβ : (2 * s - 3) / 2 = s - 2 := by omega | |
| simp only [hill, Nat.mul_div_right s (by decide : 0 < 2), hβ, hβ, hβ] | |
| congr 1 | |
| ring | |
| theorem hill_odd (s : β) : hill (2 * s + 1) = (s.choose 2) ^ 2 := by | |
| have hβ : (2 * s + 1) / 2 = s := by omega | |
| have hβ : (2 * s + 1 - 1) / 2 = s := by omega | |
| have hβ : (2 * s + 1 - 2) / 2 = s - 1 := by omega | |
| have hβ : (2 * s + 1 - 3) / 2 = s - 1 := by omega | |
| have hdiv := Nat.two_dvd_mul_sub_one s | |
| obtain β¨a, haβ© := hdiv | |
| rw [hill, hβ, hβ, hβ, hβ, Nat.choose_two_right] | |
| have hp : s * s * (s - 1) * (s - 1) = 4 * a ^ 2 := by nlinarith [ha] | |
| rw [hp, ha] | |
| simp | |
| theorem hill_eq_floor_product {n : β} (hn : 1 β€ n) : | |
| (hill n : β) = (1 / 4 : β) * (β(n : β) / 2β : β) * | |
| (β((n : β) - 1) / 2β : β) * (β((n : β) - 2) / 2β : β) * | |
| (β((n : β) - 3) / 2β : β) := by | |
| by_cases hsmall : n < 3 | |
| Β· interval_cases n <;> norm_num [hill] | |
| have hf (j : β) (hj : j β€ n) : | |
| (β((n : β) - j) / 2β : β) = ((n - j) / 2 : β) := by | |
| rw [β Nat.cast_sub hj, show (2 : β) = ((2 : β) : β) by rfl, | |
| Int.floor_div_natCast, Int.floor_natCast] | |
| norm_cast | |
| rw [hill, Nat.cast_div (hill_numerator_dvd n) (by norm_num : (4 : β) β 0)] | |
| have hfβ := hf 0 (by omega) | |
| have hfβ := hf 1 (by omega) | |
| have hfβ := hf 2 (by omega) | |
| have hfβ := hf 3 (by omega) | |
| simp only [Nat.cast_zero, sub_zero, Nat.sub_zero] at hfβ | |
| norm_num only [Nat.cast_one, Nat.cast_ofNat] at hfβ hfβ hfβ | |
| rw [hfβ, hfβ, hfβ, hfβ] | |
| push_cast | |
| ring | |
| theorem crossing_sum_partial {n m : β} (hn : 3 β€ n) (hm : 2 * m β€ n) : | |
| 2 * β k β Finset.Icc 1 m, (k - 1) * (n - k - 1) * (n - 2 * k) = | |
| m * (m - 1) * (n - m - 1) * (n - m - 2) := by | |
| induction m with | |
| | zero => simp | |
| | succ m ih => | |
| rw [Finset.sum_Icc_succ_top (by omega : 1 β€ m + 1), mul_add, | |
| ih (by omega)] | |
| by_cases hzero : m = 0 | |
| Β· subst m; simp | |
| have hmβ : 1 β€ m := by omega | |
| zify | |
| simp (disch := omega) only [Nat.cast_sub, Nat.cast_add, Nat.cast_mul, | |
| Nat.cast_one, Nat.cast_ofNat] | |
| ring | |
| theorem crossing_sum_telescope {n : β} (hn : 3 β€ n) : | |
| (2 * β k β Finset.Icc 1 (n / 2), (k - 1) * (n - k - 1) * (n - 2 * k)) = | |
| (n / 2) * (n / 2 - 1) * (n - n / 2 - 1) * (n - n / 2 - 2) := | |
| crossing_sum_partial hn (by omega) | |
| end Paper170 | |
| end | |
| end | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace Paper170 | |
| theorem cyclic_count_pairing {n : β} (hn : 3 β€ n) : | |
| (β k β Finset.Icc 2 (n - 2), | |
| (k - 1) * (n - k - 1) * (n - 2 * min k (n - k))) = | |
| 2 * β k β Finset.Icc 1 (n / 2), (k - 1) * (n - k - 1) * (n - 2 * k) := by | |
| let F : β β β := fun k => (k - 1) * (n - k - 1) * (n - 2 * min k (n - k)) | |
| have hsym (k : β) (hk : k β€ n) : F (n - k) = F k := by | |
| dsimp [F] | |
| rw [Nat.sub_sub_self hk, min_comm] | |
| ring | |
| have hfull : (β k β Finset.Icc 2 (n - 2), F k) = β k β Finset.Ico 1 n, F k := by | |
| apply Finset.sum_subset | |
| Β· intro k hk | |
| simp only [Finset.mem_Icc, Finset.mem_Ico] at hk β’ | |
| omega | |
| Β· intro k hk hnot | |
| simp only [Finset.mem_Ico, Finset.mem_Icc, not_and] at hk hnot | |
| have he : k = 1 β¨ k = n - 1 := by omega | |
| rcases he with rfl | rfl | |
| Β· simp [F] | |
| Β· have he : n - (n - 1) - 1 = 0 := by omega | |
| simp [F, he] | |
| have hsplit := Finset.sum_Ico_consecutive F (show 1 β€ n / 2 + 1 by omega) | |
| (show n / 2 + 1 β€ n by omega) | |
| have htail : (β k β Finset.Ico (n / 2 + 1) n, F k) = | |
| β k β Finset.Ico 1 (n - n / 2), F k := by | |
| calc | |
| _ = β k β Finset.Ico (n / 2 + 1) n, F (n - k) := by | |
| apply Finset.sum_congr rfl | |
| intro k hk | |
| exact (hsym k (by have := (Finset.mem_Ico.mp hk).2; omega)).symm | |
| _ = _ := by | |
| simpa only [Nat.add_sub_cancel_left, Nat.add_sub_add_right] using | |
| (Finset.sum_Ico_reflect F (n / 2 + 1) (m := n) (n := n) (by omega)) | |
| have hlow : (β k β Finset.Ico 1 (n - n / 2), F k) = | |
| β k β Finset.Ico 1 (n / 2 + 1), F k := by | |
| apply Finset.sum_subset | |
| Β· intro k hk | |
| simp only [Finset.mem_Ico] at hk β’ | |
| omega | |
| Β· intro k hk hnot | |
| simp only [Finset.mem_Ico, not_and] at hk hnot | |
| have he : n = 2 * k := by omega | |
| subst n | |
| simp [F, show 2 * k - k = k by omega] | |
| have hterm : (β k β Finset.Ico 1 (n / 2 + 1), F k) = | |
| β k β Finset.Icc 1 (n / 2), (k - 1) * (n - k - 1) * (n - 2 * k) := by | |
| rw [Finset.Ico_add_one_right_eq_Icc] | |
| apply Finset.sum_congr rfl | |
| intro k hk | |
| dsimp [F] | |
| rw [min_eq_left (by have := (Finset.mem_Icc.mp hk).2; omega)] | |
| change (β k β Finset.Icc 2 (n - 2), F k) = _ | |
| rw [hfull, β hsplit, htail, hlow, hterm] | |
| omega | |
| end Paper170 | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace Paper170 | |
| lemma four_mul_hill (n : β) : | |
| 4 * hill n = n / 2 * ((n - 1) / 2) * ((n - 2) / 2) * ((n - 3) / 2) := by | |
| exact Nat.mul_div_cancel' (hill_numerator_dvd n) | |
| lemma four_mul_hill_even (s : β) : | |
| 4 * hill (2 * s) = s * (s - 1) ^ 2 * (s - 2) := by | |
| rw [four_mul_hill] | |
| have h0 : 2 * s / 2 = s := by omega | |
| have h1 : (2 * s - 1) / 2 = s - 1 := by omega | |
| have h2 : (2 * s - 2) / 2 = s - 1 := by omega | |
| have h3 : (2 * s - 3) / 2 = s - 2 := by omega | |
| rw [h0, h1, h2, h3] | |
| ring | |
| lemma four_mul_hill_preceding (s : β) : | |
| 4 * hill (2 * s - 1) = (s - 1) ^ 2 * (s - 2) ^ 2 := by | |
| rw [four_mul_hill] | |
| have h0 : (2 * s - 1) / 2 = s - 1 := by omega | |
| have h1 : (2 * s - 1 - 1) / 2 = s - 1 := by omega | |
| have h2 : (2 * s - 1 - 2) / 2 = s - 2 := by omega | |
| have h3 : (2 * s - 1 - 3) / 2 = s - 2 := by omega | |
| rw [h0, h1, h2, h3] | |
| ring | |
| lemma hill_deletion_relation (s : β) : | |
| (2 * s - 4) * hill (2 * s) = 2 * s * hill (2 * s - 1) := by | |
| have hs : 2 * s - 4 = 2 * (s - 2) := by omega | |
| apply Nat.eq_of_mul_eq_mul_left (by decide : 0 < 4) | |
| calc | |
| 4 * ((2 * s - 4) * hill (2 * s)) = | |
| (2 * s - 4) * (4 * hill (2 * s)) := by ring | |
| _ = (2 * s - 4) * (s * (s - 1) ^ 2 * (s - 2)) := by rw [four_mul_hill_even] | |
| _ = 2 * s * ((s - 1) ^ 2 * (s - 2) ^ 2) := by rw [hs]; ring | |
| _ = 4 * (2 * s * hill (2 * s - 1)) := by rw [β four_mul_hill_preceding]; ring | |
| lemma even_lower_bound_of_deletion (s c : β) (hs : 3 β€ s) | |
| (h : 2 * s * hill (2 * s - 1) β€ (2 * s - 4) * c) : hill (2 * s) β€ c := by | |
| rw [β hill_deletion_relation] at h | |
| have hp : 0 < 2 * s - 4 := by omega | |
| nlinarith | |
| end Paper170 | |
| end | |
| end | |
| end OAI | |