Grace/Cumulus/Algebra/Field/QuadraticAdjoin.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Field.RealSubfield

Declarations

Source

1-- Adjoining a square root to a subfield of the reals: F(√d) as the set of2-- a + b√d with a, b in F, a subfield when d ∈ F is nonnegative, equal to F3-- when √d ∈ F, and with unique coefficients when √d ∉ F.4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Algebra.Field.QuadraticAdjoin10import Grace.Cumulus.Algebra.Field.RealSubfield1112-- The definition and its membership1314-- The total realSqrt keeps the comprehension unconditional; the laws below15-- take d nonnegative, where realSqrt(d) is √d.16def adjoinSqrt (F d : Set) : Set :=17  { z ∈ ℝ | ∃ a ∈ F, ∃ b ∈ F, z = (a:R) + (b:R) * (realSqrt(d):R) }1819theorem adjoinSqrt.mem_iff (F d z : Set)20  shows z ∈ adjoinSqrt(F, d) ↔21    z ∈ ℝ ∧ ∃ a ∈ F, ∃ b ∈ F, z = (a:R) + (b:R) * (realSqrt(d):R)22proof23  simp2425theorem adjoinSqrt.subset_reals (F d : Set)26  shows adjoinSqrt(F, d) ⊆ ℝ27proof28  intros z member29  obtain ⟨inReals, _⟩ := adjoinSqrt.mem_iff.forward with member30  exact inReals3132theorem adjoinSqrt.intro (F : Set) (d a b : Real)33  requires field : RealSubfield(F)34  requires dNonneg : (0:R) ≤ d35  requires aIn : a ∈ F36  requires bIn : b ∈ F37  shows a + b * √d ∈ adjoinSqrt(F, d)38proof39  have sumReal := realAddValue.real at a, b * √d40  apply adjoinSqrt.mem_iff.backward41  refine ⟨sumReal, a, aIn, b, bIn, ?_⟩42  unfold sqrt43  rfl4445theorem adjoinSqrt.cases (F : Set) (d : Real) (r : Set)46  requires dNonneg : (0:R) ≤ d47  requires rIn : r ∈ adjoinSqrt(F, d)48  shows ∃ a ∈ F, ∃ b ∈ F, r = (a:R) + (b:R) * √d49proof50  obtain ⟨_, a, aIn, b, bIn, same⟩ := adjoinSqrt.mem_iff.forward with rIn51  refine ⟨a, aIn, b, bIn, ?_⟩52  unfold sqrt53  exact same5455-- The inclusions5657-- x = x + 0 · √d.58theorem adjoinSqrt.contains (F : Set) (d : Real)59  requires field : RealSubfield(F)60  requires dNonneg : (0:R) ≤ d61  shows F ⊆ adjoinSqrt(F, d)62proof63  intros x xIn64  have realX := RealSubfield.real with field, xIn65  have member := adjoinSqrt.intro at F, d, x, (0:R) with *66  have same : (x:R) + (0:R) * √d = x by ring67  rwa same at member6869-- √d = 0 + 1 · √d.70theorem adjoinSqrt.sqrt_mem (F : Set) (d : Real)71  requires field : RealSubfield(F)72  requires dNonneg : (0:R) ≤ d73  shows √d ∈ adjoinSqrt(F, d)74proof75  have member := adjoinSqrt.intro at F, d, (0:R), (1:R) with *76  have same : (0:R) + (1:R) * √d = √d by ring77  rwa same at member7879theorem adjoinSqrt.mono (F G d : Set)80  requires sub : F ⊆ G81  shows adjoinSqrt(F, d) ⊆ adjoinSqrt(G, d)82proof83  intros z member84  obtain ⟨inReals, a, aIn, b, bIn, same⟩ :=85    adjoinSqrt.mem_iff.forward with member86  have aInG := sub with a, aIn87  have bInG := sub with b, bIn88  apply adjoinSqrt.mem_iff.backward89  exact ⟨inReals, a, aInG, b, bInG, same⟩9091-- Unique coefficients and the subfield9293-- If b ≠ 0 then √d = -a / b lies in F.94theorem adjoinSqrt.coefficients_unique (F : Set) (d a b : Real)95  requires field : RealSubfield(F)96  requires dNonneg : (0:R) ≤ d97  requires rootOut : √d ∉ F98  requires aIn : a ∈ F99  requires bIn : b ∈ F100  requires zero : a + b * √d = 0101  shows a = 0 ∧ b = 0102proof103  have bZero : b = 0104    by_contra nonzero105    have unit := realInvValue.mul_right with nonzero106    have quotient : √d = (-a) * realInvValue(b)107      linear_combination (-√d) * unit + realInvValue(b) * zero108    have inverseIn := RealSubfield.inv_mem with field, bIn, nonzero109    have negIn := RealSubfield.neg_mem with field, aIn110    have productIn := RealSubfield.mul_mem with field, negIn, inverseIn111    rw ← quotient at productIn112    exact rootOut with productIn113  have aZero : a = 0114    rw bZero at zero115    linear_combination zero116  exact ⟨aZero, bZero⟩117118theorem adjoinSqrt.eq_of_sqrt_mem (F : Set) (d : Real)119  requires field : RealSubfield(F)120  requires dNonneg : (0:R) ≤ d121  requires rootIn : √d ∈ F122  shows adjoinSqrt(F, d) = F123proof124  have includes := adjoinSqrt.contains with field, dNonneg125  have least : adjoinSqrt(F, d) ⊆ F126    intros z member127    obtain ⟨a, aIn, b, bIn, same⟩ := adjoinSqrt.cases with dNonneg, member128    have realA := RealSubfield.real with field, aIn129    have realB := RealSubfield.real with field, bIn130    rw same131    typecheck132  exact Subset.antisymmetric with least, includes133134-- The inverse of a + b√d is (a − b√d) / (a² − b²d). When √d ∈ F the135-- element lies in F and its inverse with it; otherwise a² − b²d ≠ 0 by136-- coefficients_unique applied to a − b√d.137theorem adjoinSqrt.subfield (F : Set) (d : Real)138  requires field : RealSubfield(F)139  requires dIn : d ∈ F140  requires dNonneg : (0:R) ≤ d141  shows RealSubfield(adjoinSqrt(F, d))142proof143  have bounded := adjoinSqrt.subset_reals at F, d144  have includes := adjoinSqrt.contains with field, dNonneg145  have nonnegative := NonnegativeReal.of_le with dNonneg146  have square := sqrt.square at d with nonnegative147  have zeroIn := RealSubfield.zero_mem with field148  have oneIn := RealSubfield.one_mem with field149  have zeroMember := includes with (0:R), zeroIn150  have oneMember := includes with (1:R), oneIn151  have negatives : ∀ x ∈ adjoinSqrt(F, d), -(x:R) ∈ adjoinSqrt(F, d)152    intros x xIn153    obtain ⟨a, aIn, b, bIn, same⟩ := adjoinSqrt.cases with dNonneg, xIn154    have realA := RealSubfield.real with field, aIn155    have realB := RealSubfield.real with field, bIn156    have negA := RealSubfield.neg_mem with field, aIn157    have negB := RealSubfield.neg_mem with field, bIn158    have member := adjoinSqrt.intro with field, dNonneg, negA, negB159    have value : -(x:R) = -(a:R) + (-(b:R)) * √d160      rw same161      ring162    rwa value163  have sums : ∀ x y ∈ adjoinSqrt(F, d), (x:R) + (y:R) ∈ adjoinSqrt(F, d)164    intros x xIn y yIn165    obtain ⟨a, aIn, b, bIn, sameX⟩ := adjoinSqrt.cases with dNonneg, xIn166    obtain ⟨p, pIn, q, qIn, sameY⟩ := adjoinSqrt.cases with dNonneg, yIn167    have realA := RealSubfield.real with field, aIn168    have realB := RealSubfield.real with field, bIn169    have realP := RealSubfield.real with field, pIn170    have realQ := RealSubfield.real with field, qIn171    have firstIn := RealSubfield.add_mem with field, aIn, pIn172    have secondIn := RealSubfield.add_mem with field, bIn, qIn173    have member := adjoinSqrt.intro with field, dNonneg, firstIn, secondIn174    have value : (x:R) + (y:R) = ((a:R) + (p:R)) + ((b:R) + (q:R)) * √d175      rw [sameX, sameY]176      ring177    rwa value178  have products : ∀ x y ∈ adjoinSqrt(F, d), (x:R) * (y:R) ∈ adjoinSqrt(F, d)179    intros x xIn y yIn180    obtain ⟨a, aIn, b, bIn, sameX⟩ := adjoinSqrt.cases with dNonneg, xIn181    obtain ⟨p, pIn, q, qIn, sameY⟩ := adjoinSqrt.cases with dNonneg, yIn182    have realA := RealSubfield.real with field, aIn183    have realB := RealSubfield.real with field, bIn184    have realP := RealSubfield.real with field, pIn185    have realQ := RealSubfield.real with field, qIn186    have firstIn : (a:R) * (p:R) + (b:R) * (q:R) * d ∈ F by typecheck187    have secondIn : (a:R) * (q:R) + (p:R) * (b:R) ∈ F by typecheck188    have member := adjoinSqrt.intro with field, dNonneg, firstIn, secondIn189    have value : (x:R) * (y:R) =190        ((a:R) * (p:R) + (b:R) * (q:R) * d) +191          ((a:R) * (q:R) + (p:R) * (b:R)) * √d192      rw [sameX, sameY]193      linear_combination ((b:R) * (q:R)) * square194    rwa value195  have inverses : ∀ x ∈ adjoinSqrt(F, d),196      x ≠ (0:R) → realInvValue(x) ∈ adjoinSqrt(F, d)197    intros x xIn nonzero198    obtain ⟨a, aIn, b, bIn, same⟩ := adjoinSqrt.cases with dNonneg, xIn199    have realA := RealSubfield.real with field, aIn200    have realB := RealSubfield.real with field, bIn201    have realX := bounded with x, xIn202    by_cases rootIn : √d ∈ F203    . have xInF : x ∈ F204        rw same205        typecheck206      have inverseIn := RealSubfield.inv_mem with field, xInF, nonzero207      exact includes with realInvValue(x), inverseIn208    . -- The norm a² − b²d is nonzero: otherwise the conjugate a − b√d209      -- vanishes and coefficients_unique makes x = 0.210      have normIn : (a:R) * (a:R) - (b:R) * (b:R) * d ∈ F by typecheck211      have normNonzero : (a:R) * (a:R) - (b:R) * (b:R) * d ≠ 0212        intro normZero213        have factored : ((a:R) + (b:R) * √d) * ((a:R) + (-(b:R)) * √d) = 0214          linear_combination normZero - ((b:R) * (b:R)) * square215        rcases realMulValue.eq_zero_or with factored with xZero | conjugateZero216        . apply nonzero217          rw same218          exact xZero219        . have negB := RealSubfield.neg_mem with field, bIn220          obtain ⟨aZero, negZero⟩ := adjoinSqrt.coefficients_unique221            with field, dNonneg, rootIn, aIn, negB, conjugateZero222          apply nonzero223          rw same224          linear_combination aZero - √d * negZero225      have inverseIn := RealSubfield.inv_mem with field, normIn, normNonzero226      have unit := realInvValue.mul_right with normNonzero227      have firstIn : (a:R) * realInvValue((a:R) * (a:R) - (b:R) * (b:R) * d) ∈ F228        typecheck229      have secondIn :230          -(b:R) * realInvValue((a:R) * (a:R) - (b:R) * (b:R) * d) ∈ F231        typecheck232      have member := adjoinSqrt.intro with field, dNonneg, firstIn, secondIn233      have product :234          x * ((a:R) * realInvValue((a:R) * (a:R) - (b:R) * (b:R) * d) +235            -(b:R) * realInvValue((a:R) * (a:R) - (b:R) * (b:R) * d) * √d) = 1236        rw same237        linear_combination unit -238          ((b:R) * (b:R) * realInvValue((a:R) * (a:R) - (b:R) * (b:R) * d)) *239            square240      have value := realInvValue.eq_of_mul_right with nonzero, product241      rw ← value242      exact member243  exact RealSubfield.mk with bounded, zeroMember, oneMember, negatives, sums,244    products, inverses245