Grace/Cumulus/Algebra/Field/QuadraticTower.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Field.QuadraticAdjoin · Grace.Cumulus.List.TakeDrop

Declarations

Source

1-- Towers of quadratic extensions of the rationals, as lists of2-- discriminants with the top discriminant first: the field of a tower,3-- the tower condition on every suffix, and the compositum of two towers.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.QuadraticTower10import Grace.Cumulus.Algebra.Field.QuadraticAdjoin11import Grace.Cumulus.List.TakeDrop1213-- The definitions1415-- The head of the list is the last square root adjoined.16def towerField (ds : List(ℝ)) → Set17  | List.nil => rationalReals18  | List.cons(d, rest) => adjoinSqrt(towerField(rest), d)1920-- A predicate cannot recurse, so the tower condition quantifies over the21-- suffixes listDrop(k, ds): each discriminant is a nonnegative element of22-- the field of the discriminants below it.23predicate QuadraticTower (ds : List(ℝ)) :=24  ∀ k < length(ds), ∃ d ∈ ℝ, ∃ rest, List(ℝ, rest) ∧25    listDrop(k, ds) = d :: rest ∧ d ∈ towerField(rest) ∧ (0:R) ≤ d2627theorem towerField.nil28  shows towerField([]) = rationalReals29proof30  rw towerField31  rfl3233theorem towerField.cons (ds : List(ℝ)) (d : Real)34  shows towerField(d :: ds) = adjoinSqrt(towerField(ds), d)35proof36  rw towerField37  rfl3839-- The tower condition, built and taken apart4041theorem QuadraticTower.nil42  shows QuadraticTower([])43proof44  unfold QuadraticTower45  intros k kNat hk46  rw length.nil at hk47  exfalso48  arith4950-- listDrop.zero for k = 0 and listDrop.succ_cons for the rest.51theorem QuadraticTower.cons (ds : List(ℝ)) (d : Real)52  requires tower : QuadraticTower(ds)53  requires dIn : d ∈ towerField(ds)54  requires dNonneg : (0:R) ≤ d55  shows QuadraticTower(d :: ds)56proof57  have dReal : d ∈ ℝ by typecheck58  have whole : List(ℝ, d :: ds) by typecheck59  unfold QuadraticTower at tower60  unfold QuadraticTower61  intros k kNat hk62  rw length.cons at hk63  rcases natural.zero_or_successor at k with zero | successor64  . refine ⟨d, dReal, ds, ?_, ?_, dIn, dNonneg⟩65    . typecheck66    . rw [zero, listDrop.zero]67      rfl68  . obtain ⟨j, jNat, equal⟩ := successor69    rw equal at hk70    have smaller : j < length{ℝ}(ds) by arith71    obtain ⟨e, eReal, rest, restList, dropped, eIn, eNonneg⟩ :=72      tower with j, jNat, smaller73    refine ⟨e, eReal, rest, restList, ?_, eIn, eNonneg⟩74    rw [equal, listDrop.succ_cons]75    exact dropped7677theorem QuadraticTower.head (ds : List(ℝ)) (d : Real)78  requires tower : QuadraticTower(d :: ds)79  shows d ∈ towerField(ds) ∧ (0:R) ≤ d80proof81  have dReal : d ∈ ℝ by typecheck82  have whole : List(ℝ, d :: ds) by typecheck83  have positive := length.cons_positive at ℝ, d, ds with dReal84  unfold QuadraticTower at tower85  have zeroNat : (0:N) ∈ ℕ by typecheck86  obtain ⟨e, _, rest, _, equal, eIn, eNonneg⟩ :=87    tower with (0:N), zeroNat, positive88  rw listDrop.zero at equal89  have sameHead := List.cons_head with equal90  have sameTail := List.cons_tail with equal91  rw [sameHead, sameTail]92  exact ⟨eIn, eNonneg⟩9394theorem QuadraticTower.tail (ds : List(ℝ)) (d : Real)95  requires tower : QuadraticTower(d :: ds)96  shows QuadraticTower(ds)97proof98  unfold QuadraticTower at tower99  unfold QuadraticTower100  intros k kNat hk101  have bound : succ(k) < length{ℝ}(d :: ds)102    rw length.cons103    arith104  have succNat : succ(k) ∈ ℕ by typecheck105  obtain ⟨e, eReal, rest, restList, equal, eIn, eNonneg⟩ :=106    tower with succ(k), succNat, bound107  rw listDrop.succ_cons at equal108  exact ⟨e, eReal, rest, restList, equal, eIn, eNonneg⟩109110-- The field of a tower111112theorem towerField.subset_reals (ds : List(ℝ))113  shows towerField(ds) ⊆ ℝ114proof115  induction ds116  | List.nil =>117    rw towerField.nil118    intros x hx119    exact rationalReals.real with hx120  | List.cons(d, tail) using ih =>121    rw towerField.cons122    exact adjoinSqrt.subset_reals at towerField(tail), d123124-- Induction on ds with adjoinSqrt.subfield.125theorem towerField.subfield (ds : List(ℝ))126  requires tower : QuadraticTower(ds)127  shows RealSubfield(towerField(ds))128proof129  induction ds130  | List.nil =>131    intro tower132    rw towerField.nil133    exact RealSubfield.rationals134  | List.cons(d, tail) using ih =>135    intro tower136    have below := QuadraticTower.tail with tower137    obtain ⟨dIn, dNonneg⟩ := QuadraticTower.head with tower138    have field := ih with below139    rw towerField.cons140    exact adjoinSqrt.subfield with field, dIn, dNonneg141142theorem towerField.rationals (ds : List(ℝ))143  requires tower : QuadraticTower(ds)144  shows rationalReals ⊆ towerField(ds)145proof146  have field := towerField.subfield with tower147  exact RealSubfield.rationals_subset with field148149-- Stacking two towers150151-- append(ds, es) is es followed by ds: the discriminants of es are152-- stacked on top of the tower ds. The field of es sits in the field of153-- the stack: induction on es with adjoinSqrt.mono, the base case being154-- the rationals in the field of ds.155theorem towerField.subset_append_right (ds es : List(ℝ))156  requires towerD : QuadraticTower(ds)157  shows towerField(es) ⊆ towerField(append(ds, es))158proof159  induction es160  | List.nil =>161    rw [append.nil, towerField.nil]162    exact towerField.rationals with towerD163  | List.cons(e, tail) using ih =>164    have joined : List(ℝ, append(ds, tail)) by typecheck165    rw [append.cons, towerField.cons, towerField.cons]166    exact adjoinSqrt.mono with ih167168-- The stack is a tower whose field contains the field of ds. The two169-- conclusions share one induction on es: the subfield of the stacked170-- tower is what adjoinSqrt.contains needs for the inclusion.171theorem QuadraticTower.append_subset (ds es : List(ℝ))172  requires towerD : QuadraticTower(ds)173  requires towerE : QuadraticTower(es)174  shows QuadraticTower(append(ds, es)) ∧175    towerField(ds) ⊆ towerField(append(ds, es))176proof177  induction es178  | List.nil =>179    intro towerE180    rw append.nil181    have reflexive : towerField(ds) ⊆ towerField(ds) by simp [Subset]182    exact ⟨towerD, reflexive⟩183  | List.cons(e, tail) using ih =>184    intro towerE185    have joined : List(ℝ, append(ds, tail)) by typecheck186    have below := QuadraticTower.tail with towerE187    obtain ⟨eIn, eNonneg⟩ := QuadraticTower.head with towerE188    obtain ⟨stackTower, stackContains⟩ := ih with below189    have lifted := towerField.subset_append_right at ds, tail with towerD190    have eUp := lifted with e, eIn191    have tower := QuadraticTower.cons with stackTower, eUp, eNonneg192    have field := towerField.subfield with stackTower193    have contains := adjoinSqrt.contains with field, eNonneg194    rw [append.cons, towerField.cons]195    refine ⟨tower, ?_⟩196    exact Subset.transitive with stackContains, contains197198theorem towerField.subset_append (ds es : List(ℝ))199  requires towerD : QuadraticTower(ds)200  requires towerE : QuadraticTower(es)201  shows towerField(ds) ⊆ towerField(append(ds, es))202proof203  have both := QuadraticTower.append_subset with towerD, towerE204  exact both.right205206-- The compositum: each discriminant of es lies in the field of its suffix207-- within es, hence in the field of that suffix stacked on ds.208theorem QuadraticTower.append (ds es : List(ℝ))209  requires towerD : QuadraticTower(ds)210  requires towerE : QuadraticTower(es)211  shows QuadraticTower(append(ds, es))212proof213  have both := QuadraticTower.append_subset with towerD, towerE214  exact both.left215