Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-principia/blob/main/proofs/PellCfClassNumberLaw.lean # omega-principia This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-principia / proofs / PellCfClassNumberLaw.lean` 287 lines · 13395 bytes Raw Blame History 1 -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 -- proofs/PellCfClassNumberLaw.lean 3 -- Formal Lean 4.36.0 verification of Pell norm multiplicativity, negative-Pell 4 -- modular obstructions, SL_2(Z) indefinite binary quadratic form discriminant 5 -- invariance, continued-fraction convergent determinants, iconic Pell fundamental 6 -- units (D=2, 5, 13, 29, 61, 109), and 5 structural broken-model negative controls. 7 -- Zero sorry, zero native_decide, standard core axioms only. 8 9 namespace PellCfClassNumberLaw 10 11 /-! ### 1. Universal Brahmagupta–Fibonacci Norm Multiplicativity & Pell Group Laws -/ 12 13 /-- Theorem 1: Universal Brahmagupta–Fibonacci norm multiplicativity over ℤ. -/ 14 theorem pell_norm_mul (D x1 y1 x2 y2 : Int) : 15 (x1 ^ 2 - D * y1 ^ 2) * (x2 ^ 2 - D * y2 ^ 2) = 16 (x1 * x2 + D * y1 * y2) ^ 2 - D * (x1 * y2 + y1 * x2) ^ 2 := by 17 grind 18 19 /-- Theorem 2: Conjugate sign invariance of the Pell norm over ℤ. -/ 20 theorem pell_norm_conj (D x y : Int) : 21 ((-x) ^ 2 - D * y ^ 2 = x ^ 2 - D * y ^ 2) ∧ 22 (x ^ 2 - D * (-y) ^ 2 = x ^ 2 - D * y ^ 2) := by 23 grind 24 25 /-- Theorem 3: Squaring any negative-Pell solution (x^2 - D y^2 = -1) yields a positive-Pell solution. -/ 26 theorem neg_pell_square_is_pos_pell (D x y : Int) (h : x ^ 2 - D * y ^ 2 = -1) : 27 (x ^ 2 + D * y ^ 2) ^ 2 - D * (2 * x * y) ^ 2 = 1 := by 28 have hm := pell_norm_mul D x y x y 29 grind 30 31 /-- Theorem 4: Positive Pell solutions (x^2 - D y^2 = 1) are closed under Brahmagupta multiplication. -/ 32 theorem pos_pell_mul_closed (D x1 y1 x2 y2 : Int) 33 (h1 : x1 ^ 2 - D * y1 ^ 2 = 1) (h2 : x2 ^ 2 - D * y2 ^ 2 = 1) : 34 (x1 * x2 + D * y1 * y2) ^ 2 - D * (x1 * y2 + y1 * x2) ^ 2 = 1 := by 35 have hm := pell_norm_mul D x1 y1 x2 y2 36 grind 37 38 /-- Theorem 5: Cubing a negative-Pell solution preserves norm -1. -/ 39 theorem neg_pell_cube_is_neg_pell (D x y : Int) (h : x ^ 2 - D * y ^ 2 = -1) : 40 ((x ^ 2 + D * y ^ 2) * x + D * (2 * x * y) * y) ^ 2 - 41 D * ((x ^ 2 + D * y ^ 2) * y + (2 * x * y) * x) ^ 2 = -1 := by 42 have hsq := neg_pell_square_is_pos_pell D x y h 43 have hm := pell_norm_mul D (x ^ 2 + D * y ^ 2) (2 * x * y) x y 44 grind 45 46 /-! ### 2. Universal Negative-Pell Modular Obstruction Theorems -/ 47 48 /-- Theorem 6: General modular obstruction — if p > 0 divides D and -1 is a quadratic non-residue mod p, 49 then x^2 - D y^2 = -1 has NO integer solutions. -/ 50 theorem neg_pell_no_nonres_divisor (p D : Int) 51 (hnonres : ∀ r : Int, (r * r + 1) % p ≠ 0) (hdvd : ∃ k : Int, D = p * k) : 52 ∀ x y : Int, x ^ 2 - D * y ^ 2 ≠ -1 := by 53 intro x y h 54 rcases hdvd with ⟨k, rfl⟩ 55 have heq : x * x + 1 = p * (k * y ^ 2) := by grind 56 have hmod : (x * x + 1) % p = 0 := by 57 rw [heq, Int.mul_emod_right] 58 exact hnonres x hmod 59 60 /-- Theorem 7: Universal mod-4 obstruction — if 4 ∣ D then x^2 - D y^2 ≠ -1 for all x, y ∈ ℤ. -/ 61 theorem neg_pell_no_div4 (D : Int) (hdvd : ∃ k : Int, D = 4 * k) : 62 ∀ x y : Int, x ^ 2 - D * y ^ 2 ≠ -1 := by 63 apply neg_pell_no_nonres_divisor 4 D _ hdvd 64 intro r 65 have hlo : 0 ≤ r % 4 := Int.emod_nonneg r (by omega) 66 have hhi : r % 4 < 4 := Int.emod_lt_of_pos r (by omega) 67 have hmod : (r * r + 1) % 4 = ((r % 4) * (r % 4) + 1) % 4 := by 68 rw [Int.add_emod, Int.mul_emod, ← Int.add_emod] 69 rw [hmod] 70 have hcases : r % 4 = 0 ∨ r % 4 = 1 ∨ r % 4 = 2 ∨ r % 4 = 3 := by omega 71 rcases hcases with h | h | h | h <;> rw [h] <;> decide 72 73 /-- Theorem 8: Universal mod-3 obstruction — if 3 ∣ D then x^2 - D y^2 ≠ -1 for all x, y ∈ ℤ. -/ 74 theorem neg_pell_no_div3 (D : Int) (hdvd : ∃ k : Int, D = 3 * k) : 75 ∀ x y : Int, x ^ 2 - D * y ^ 2 ≠ -1 := by 76 apply neg_pell_no_nonres_divisor 3 D _ hdvd 77 intro r 78 have hlo : 0 ≤ r % 3 := Int.emod_nonneg r (by omega) 79 have hhi : r % 3 < 3 := Int.emod_lt_of_pos r (by omega) 80 have hmod : (r * r + 1) % 3 = ((r % 3) * (r % 3) + 1) % 3 := by 81 rw [Int.add_emod, Int.mul_emod, ← Int.add_emod] 82 rw [hmod] 83 have hcases : r % 3 = 0 ∨ r % 3 = 1 ∨ r % 3 = 2 := by omega 84 rcases hcases with h | h | h <;> rw [h] <;> decide 85 86 /-- Theorem 9: Universal mod-7 obstruction — if 7 ∣ D then x^2 - D y^2 ≠ -1 for all x, y ∈ ℤ. -/ 87 theorem neg_pell_no_div7 (D : Int) (hdvd : ∃ k : Int, D = 7 * k) : 88 ∀ x y : Int, x ^ 2 - D * y ^ 2 ≠ -1 := by 89 apply neg_pell_no_nonres_divisor 7 D _ hdvd 90 intro r 91 have hlo : 0 ≤ r % 7 := Int.emod_nonneg r (by omega) 92 have hhi : r % 7 < 7 := Int.emod_lt_of_pos r (by omega) 93 have hmod : (r * r + 1) % 7 = ((r % 7) * (r % 7) + 1) % 7 := by 94 rw [Int.add_emod, Int.mul_emod, ← Int.add_emod] 95 rw [hmod] 96 have hcases : r % 7 = 0 ∨ r % 7 = 1 ∨ r % 7 = 2 ∨ r % 7 = 3 ∨ 97 r % 7 = 4 ∨ r % 7 = 5 ∨ r % 7 = 6 := by omega 98 rcases hcases with h | h | h | h | h | h | h <;> rw [h] <;> decide 99 100 /-- Theorem 10: Universal mod-11 obstruction — if 11 ∣ D then x^2 - D y^2 ≠ -1 for all x, y ∈ ℤ. -/ 101 theorem neg_pell_no_div11 (D : Int) (hdvd : ∃ k : Int, D = 11 * k) : 102 ∀ x y : Int, x ^ 2 - D * y ^ 2 ≠ -1 := by 103 apply neg_pell_no_nonres_divisor 11 D _ hdvd 104 intro r 105 have hlo : 0 ≤ r % 11 := Int.emod_nonneg r (by omega) 106 have hhi : r % 11 < 11 := Int.emod_lt_of_pos r (by omega) 107 have hmod : (r * r + 1) % 11 = ((r % 11) * (r % 11) + 1) % 11 := by 108 rw [Int.add_emod, Int.mul_emod, ← Int.add_emod] 109 rw [hmod] 110 have hcases : r % 11 = 0 ∨ r % 11 = 1 ∨ r % 11 = 2 ∨ r % 11 = 3 ∨ 111 r % 11 = 4 ∨ r % 11 = 5 ∨ r % 11 = 6 ∨ r % 11 = 7 ∨ 112 r % 11 = 8 ∨ r % 11 = 9 ∨ r % 11 = 10 := by omega 113 rcases hcases with h | h | h | h | h | h | h | h | h | h | h <;> rw [h] <;> decide 114 115 /-! ### 3. Universal SL_2(Z) Binary Quadratic Form Discriminant Invariance -/ 116 117 def qfDisc (a b c : Int) : Int := b ^ 2 - 4 * a * c 118 119 /-- Theorem 11: Universal SL_2(Z) rho-operator discriminant invariance over ℤ. -/ 120 theorem qf_rho_preserves_disc (a b c k : Int) : 121 qfDisc c (-b + 2 * k * c) (a - k * b + k ^ 2 * c) = qfDisc a b c := by 122 unfold qfDisc 123 grind 124 125 /-- Theorem 12: General SL_2(Z) action (p*s - q*r = 1) discriminant invariance over ℤ. -/ 126 theorem qf_sl2_general_preserves_disc (a b c p q r s : Int) (hdet : p * s - q * r = 1) : 127 qfDisc (a * p ^ 2 + b * p * r + c * r ^ 2) 128 (2 * a * p * q + b * (p * s + q * r) + 2 * c * r * s) 129 (a * q ^ 2 + b * q * s + c * s ^ 2) = qfDisc a b c := by 130 unfold qfDisc 131 grind 132 133 /-- Theorem 13: Negating (a, b, c) ↦ (-a, b, -c) preserves discriminant identically over ℤ. -/ 134 theorem qf_neg_form_same_disc (a b c : Int) : 135 qfDisc (-a) b (-c) = qfDisc a b c := by 136 unfold qfDisc 137 grind 138 139 /-- Theorem 14: Reversing (a, b, c) ↦ (c, b, a) preserves discriminant identically over ℤ. -/ 140 theorem qf_swap_ac_same_disc (a b c : Int) : 141 qfDisc c b a = qfDisc a b c := by 142 unfold qfDisc 143 grind 144 145 /-! ### 4. Universal Continued-Fraction Convergent Determinant Theorem -/ 146 147 def cfStep (st : Int × Int × Int × Int) (a : Int) : Int × Int × Int × Int := 148 (st.2.1, a * st.2.1 + st.1, st.2.2.2, a * st.2.2.2 + st.2.2.1) 149 150 def cfRun (st : Int × Int × Int × Int) : List Int → Int × Int × Int × Int 151 | [] => st 152 | a :: rest => cfRun (cfStep st a) rest 153 154 def cfDet (st : Int × Int × Int × Int) : Int := 155 st.2.1 * st.2.2.1 - st.1 * st.2.2.2 156 157 /-- Theorem 15: Single continued-fraction convergent step negates the determinant identically. -/ 158 theorem cf_step_det_flip (p0 p1 q0 q1 a : Int) : 159 cfDet (cfStep (p0, p1, q0, q1) a) = -(cfDet (p0, p1, q0, q1)) := by 160 unfold cfDet cfStep 161 grind 162 163 /-- Theorem 16: Universal continued-fraction convergent determinant theorem by induction on any list of partial quotients. -/ 164 theorem cf_convergent_det_run (st : Int × Int × Int × Int) (as : List Int) : 165 cfDet (cfRun st as) = (-1 : Int) ^ as.length * cfDet st := by 166 induction as generalizing st with 167 | nil => 168 simp [cfRun] 169 | cons a rest ih => 170 simp only [cfRun, List.length_cons] 171 rw [ih (cfStep st a)] 172 rcases st with ⟨p0, p1, q0, q1⟩ 173 rw [cf_step_det_flip, Int.pow_succ] 174 grind 175 176 /-- Theorem 17: Standard CF initialization (1, a0, 0, 1) yields exact determinant (-1)^(k+1) after k steps. -/ 177 theorem cf_convergent_det_std (a0 : Int) (as : List Int) : 178 cfDet (cfRun (1, a0, 0, 1) as) = (-1 : Int) ^ (as.length + 1) := by 179 rw [cf_convergent_det_run] 180 have h0 : cfDet (1, a0, 0, 1) = -1 := by 181 unfold cfDet 182 grind 183 rw [h0, Int.pow_succ] 184 185 /-! ### 5. Concrete Verified Iconic Pell Fundamental Units (D = 2, 5, 13, 29, 61, 109) -/ 186 187 /-- Theorem 18: Verified D = 2 negative and positive Pell fundamental units. -/ 188 theorem pell_d2_neg_and_pos : 189 (1 : Int) ^ 2 - 2 * 1 ^ 2 = -1 ∧ (3 : Int) ^ 2 - 2 * 2 ^ 2 = 1 := by 190 decide 191 192 /-- Theorem 19: Verified D = 5 negative and positive Pell fundamental units. -/ 193 theorem pell_d5_neg_and_pos : 194 (2 : Int) ^ 2 - 5 * 1 ^ 2 = -1 ∧ (9 : Int) ^ 2 - 5 * 4 ^ 2 = 1 := by 195 decide 196 197 /-- Theorem 20: Verified D = 13 (L=5) negative and positive Pell fundamental units. -/ 198 theorem pell_d13_neg_and_pos : 199 (18 : Int) ^ 2 - 13 * 5 ^ 2 = -1 ∧ (649 : Int) ^ 2 - 13 * 180 ^ 2 = 1 := by 200 decide 201 202 /-- Theorem 21: Verified D = 29 (L=5) negative and positive Pell fundamental units. -/ 203 theorem pell_d29_neg_and_pos : 204 (70 : Int) ^ 2 - 29 * 13 ^ 2 = -1 ∧ (9801 : Int) ^ 2 - 29 * 1820 ^ 2 = 1 := by 205 decide 206 207 /-- Theorem 22: Verified iconic D = 61 (L=11) negative and positive Pell fundamental units. -/ 208 theorem pell_d61_iconic_neg_and_pos : 209 (29718 : Int) ^ 2 - 61 * 3805 ^ 2 = -1 ∧ 210 (`1766319049` : Int) ^ 2 - 61 * `226153980` ^ 2 = 1 := by 211 have hneg : (29718 : Int) ^ 2 - 61 * 3805 ^ 2 = -1 := by decide 212 refine ⟨hneg, ?_⟩ 213 have hpos := neg_pell_square_is_pos_pell 61 29718 3805 hneg 214 have hx : (29718 : Int) ^ 2 + 61 * 3805 ^ 2 = `1766319049` := by decide 215 have hy : 2 * (29718 : Int) * 3805 = `226153980` := by decide 216 rw [hx, hy] at hpos 217 exact hpos 218 219 /-- Theorem 21: Verified iconic D = 109 (L=15) negative and positive Pell fundamental units. -/ 220 theorem pell_d109_iconic_neg_and_pos : 221 (`8890182` : Int) ^ 2 - 109 * 851525 ^ 2 = -1 ∧ 222 (`158070671986249` : Int) ^ 2 - 109 * `15140424455100` ^ 2 = 1 := by 223 have hneg : (`8890182` : Int) ^ 2 - 109 * 851525 ^ 2 = -1 := by decide 224 refine ⟨hneg, ?_⟩ 225 have hpos := neg_pell_square_is_pos_pell 109 `8890182` 851525 hneg 226 have hx : (`8890182` : Int) ^ 2 + 109 * 851525 ^ 2 = `158070671986249` := by decide 227 have hy : 2 * (`8890182` : Int) * 851525 = `15140424455100` := by decide 228 rw [hx, hy] at hpos 229 exact hpos 230 231 /-! ### 6. Structural Broken-Model Negative Controls (5 neg_ctrl_* theorems) -/ 232 233 /-- Theorem 22 (Negative Control 1): x^2 - 3 y^2 = -1 is universally unsolvable over ℤ. -/ 234 theorem neg_ctrl_d3_no_neg_pell : ∀ x y : Int, x ^ 2 - 3 * y ^ 2 ≠ -1 := 235 neg_pell_no_div3 3 ⟨1, rfl⟩ 236 237 /-- Theorem 23 (Negative Control 2): x^2 - 4 y^2 = -1 is universally unsolvable over ℤ. -/ 238 theorem neg_ctrl_d4_no_neg_pell : ∀ x y : Int, x ^ 2 - 4 * y ^ 2 ≠ -1 := 239 neg_pell_no_div4 4 ⟨1, rfl⟩ 240 241 /-- Theorem 24 (Negative Control 3): x^2 - 7 y^2 = -1 is universally unsolvable over ℤ. -/ 242 theorem neg_ctrl_d7_no_neg_pell : ∀ x y : Int, x ^ 2 - 7 * y ^ 2 ≠ -1 := 243 neg_pell_no_div7 7 ⟨1, rfl⟩ 244 245 /-- Theorem 25 (Negative Control 4): Corrupting b ↦ b + 2 on any reduced form (b > 0) strictly breaks Δ. -/ 246 theorem neg_ctrl_corrupt_b_breaks_disc (a b c : Int) (hb : 0 < b) : 247 qfDisc a (b + 2) c ≠ qfDisc a b c := by 248 unfold qfDisc 249 grind 250 251 /-- Theorem 26 (Negative Control 5): Scaling a form by det=2 (2a, 2b, 2c) strictly breaks any non-zero Δ. -/ 252 theorem neg_ctrl_det2_breaks_disc (a b c : Int) (hΔ : qfDisc a b c ≠ 0) : 253 qfDisc (2 * a) (2 * b) (2 * c) ≠ qfDisc a b c := by 254 unfold qfDisc at * 255 grind 256 257 end PellCfClassNumberLaw 258 259 -- Axiom audit across ALL 28 theorems (must show only standard core axioms, 0 sorryAx) 260 #print axioms PellCfClassNumberLaw.pell_norm_mul 261 #print axioms PellCfClassNumberLaw.pell_norm_conj 262 #print axioms PellCfClassNumberLaw.neg_pell_square_is_pos_pell 263 #print axioms PellCfClassNumberLaw.pos_pell_mul_closed 264 #print axioms PellCfClassNumberLaw.neg_pell_cube_is_neg_pell 265 #print axioms PellCfClassNumberLaw.neg_pell_no_nonres_divisor 266 #print axioms PellCfClassNumberLaw.neg_pell_no_div4 267 #print axioms PellCfClassNumberLaw.neg_pell_no_div3 268 #print axioms PellCfClassNumberLaw.neg_pell_no_div7 269 #print axioms PellCfClassNumberLaw.neg_pell_no_div11 270 #print axioms PellCfClassNumberLaw.qf_rho_preserves_disc 271 #print axioms PellCfClassNumberLaw.qf_sl2_general_preserves_disc 272 #print axioms PellCfClassNumberLaw.qf_neg_form_same_disc 273 #print axioms PellCfClassNumberLaw.qf_swap_ac_same_disc 274 #print axioms PellCfClassNumberLaw.cf_step_det_flip 275 #print axioms PellCfClassNumberLaw.cf_convergent_det_run 276 #print axioms PellCfClassNumberLaw.cf_convergent_det_std 277 #print axioms PellCfClassNumberLaw.pell_d2_neg_and_pos 278 #print axioms PellCfClassNumberLaw.pell_d5_neg_and_pos 279 #print axioms PellCfClassNumberLaw.pell_d13_neg_and_pos 280 #print axioms PellCfClassNumberLaw.pell_d29_neg_and_pos 281 #print axioms PellCfClassNumberLaw.pell_d61_iconic_neg_and_pos 282 #print axioms PellCfClassNumberLaw.pell_d109_iconic_neg_and_pos 283 #print axioms PellCfClassNumberLaw.neg_ctrl_d3_no_neg_pell 284 #print axioms PellCfClassNumberLaw.neg_ctrl_d4_no_neg_pell 285 #print axioms PellCfClassNumberLaw.neg_ctrl_d7_no_neg_pell 286 #print axioms PellCfClassNumberLaw.neg_ctrl_corrupt_b_breaks_disc 287 #print axioms PellCfClassNumberLaw.neg_ctrl_det2_breaks_disc