Grace/Cumulus/Geometry/Construction/Numbers.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Field.RealSubfield

Declarations

Source

1-- Constructible real numbers: the least subset of ℝ that is a subfield2-- closed under square roots of its nonnegative elements, with its3-- induction principle and closure laws.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.Geometry.Construction.Numbers10import Grace.Cumulus.Algebra.Field.RealSubfield1112-- The definitions1314-- A set of reals closed under the field operations and square roots.15predicate ConstructiblyClosed (S : Set) :=16  RealSubfield(S) ∧ (∀ x ∈ S, (0:R) ≤ (x:R) → realSqrt(x) ∈ S)1718-- A real whose square lies in S lies in S: its absolute value is the19-- square root of the square, and the real is that value or its negation.20theorem ConstructiblyClosed.of_square_mem (S : Set) (s : Real)21  requires closed : ConstructiblyClosed(S)22  requires squareIn : s * s ∈ S23  shows s ∈ S24proof25  obtain ⟨field, roots⟩ := closed26  have squareNonneg := realMulValue.square_nonnegative at s27  have rootIn := roots with squareIn, squareNonneg28  have rootReal := realSqrt.real with squareNonneg29  have rootNonneg := realSqrt.nonneg with squareNonneg30  have rootSquare := realSqrt.square with squareNonneg31  by_cases nonneg : (0:R) ≤ s32  . have equal := realMulValue.eq_of_square_eq at realSqrt(s * s), s33      with rootNonneg, nonneg, rootSquare34    rw ← equal35    exact rootIn36  . have negNonneg : (0:R) ≤ -s by linarith37    have negSquare : realSqrt(s * s) * realSqrt(s * s) = (-s) * (-s)38      linear_combination rootSquare39    have equal := realMulValue.eq_of_square_eq at realSqrt(s * s), -s40      with rootNonneg, negNonneg, negSquare41    have negIn : -s ∈ S42      rw ← equal43      exact rootIn44    have involutive := realNegValue.involutive at s45    rw ← involutive46    exact RealSubfield.neg_mem with field, negIn4748-- The intersection of every constructibly closed set.49def constructibles : Set :=50  { x ∈ ℝ | ∀ S, ConstructiblyClosed(S) → x ∈ S }5152predicate Constructible (x : Set) := x ∈ constructibles5354-- Membership5556theorem constructibles.mem_iff (x : Set)57  shows x ∈ constructibles ↔58    x ∈ ℝ ∧ (∀ S, ConstructiblyClosed(S) → x ∈ S)59proof60  simp6162theorem constructibles.subset_reals63  shows constructibles ⊆ ℝ64proof65  simp6667theorem constructibles.intro (x : Real)68  requires every : ∀ S, ConstructiblyClosed(S) → x ∈ S69  shows x ∈ constructibles70proof71  have xReal : x ∈ ℝ by typecheck72  apply constructibles.mem_iff.backward73  exact ⟨xReal, every⟩7475-- The induction principle: a closed set contains every constructible.76theorem constructibles.least (S : Set)77  requires closed : ConstructiblyClosed(S)78  shows constructibles ⊆ S79proof80  intros x hx81  have data := constructibles.mem_iff.forward with hx82  exact data.right with S, closed8384theorem Constructible.real (x : Set)85  requires constructible : Constructible(x)86  shows Real(x)87proof88  have data := constructibles.mem_iff.forward with constructible89  exact data.left9091-- The least closed set is closed9293-- Each law holds in every closed set S, so it holds in the intersection.94theorem constructibles.closed95  shows ConstructiblyClosed(constructibles)96proof97  have bounded := constructibles.subset_reals98  have zeroMember : (0:R) ∈ constructibles99    apply constructibles.intro100    intros S closed101    exact RealSubfield.zero_mem with closed.left102  have oneMember : (1:R) ∈ constructibles103    apply constructibles.intro104    intros S closed105    exact RealSubfield.one_mem with closed.left106  have negatives : ∀ x ∈ constructibles, -(x:R) ∈ constructibles107    intros x hx108    have data := constructibles.mem_iff.forward with hx109    apply constructibles.intro110    intros S closed111    have xIn := data.right with S, closed112    exact RealSubfield.neg_mem with closed.left, xIn113  have sums : ∀ x y ∈ constructibles, (x:R) + (y:R) ∈ constructibles114    intros x hx y hy115    have first := constructibles.mem_iff.forward with hx116    have second := constructibles.mem_iff.forward with hy117    apply constructibles.intro118    intros S closed119    have xIn := first.right with S, closed120    have yIn := second.right with S, closed121    exact RealSubfield.add_mem with closed.left, xIn, yIn122  have products : ∀ x y ∈ constructibles, (x:R) * (y:R) ∈ constructibles123    intros x hx y hy124    have first := constructibles.mem_iff.forward with hx125    have second := constructibles.mem_iff.forward with hy126    apply constructibles.intro127    intros S closed128    have xIn := first.right with S, closed129    have yIn := second.right with S, closed130    exact RealSubfield.mul_mem with closed.left, xIn, yIn131  have inverses : ∀ x ∈ constructibles,132      x ≠ (0:R) → realInvValue(x) ∈ constructibles133    intros x hx nonzero134    have data := constructibles.mem_iff.forward with hx135    apply constructibles.intro136    intros S closed137    have xIn := data.right with S, closed138    exact RealSubfield.inv_mem with closed.left, xIn, nonzero139  have roots : ∀ x ∈ constructibles,140      (0:R) ≤ (x:R) → realSqrt(x) ∈ constructibles141    intros x hx nonneg142    have data := constructibles.mem_iff.forward with hx143    have rootReal := realSqrt.real with nonneg144    apply constructibles.intro145    intros S closed146    have xIn := data.right with S, closed147    exact closed.right with x, xIn, nonneg148  have field := RealSubfield.mk with149    bounded, zeroMember, oneMember, negatives, sums, products, inverses150  unfold ConstructiblyClosed151  exact ⟨field, roots⟩152153theorem constructibles.subfield154  shows RealSubfield(constructibles)155proof156  have closed := constructibles.closed157  exact closed.left158159-- The closure laws160161instance Constructible.add (x y : Real)162  requires xC : Constructible(x)163  requires yC : Constructible(y)164  shows Constructible(x + y)165proof166  have field := constructibles.subfield167  exact RealSubfield.add_mem with field, xC, yC168169instance Constructible.mul (x y : Real)170  requires xC : Constructible(x)171  requires yC : Constructible(y)172  shows Constructible(x * y)173proof174  have field := constructibles.subfield175  exact RealSubfield.mul_mem with field, xC, yC176177instance Constructible.neg (x : Real)178  requires xC : Constructible(x)179  shows Constructible(-x)180proof181  have field := constructibles.subfield182  exact RealSubfield.neg_mem with field, xC183184instance Constructible.sub (x y : Real)185  requires xC : Constructible(x)186  requires yC : Constructible(y)187  shows Constructible(x - y)188proof189  have field := constructibles.subfield190  exact RealSubfield.sub_mem with field, xC, yC191192-- The square root law takes its nonnegativity as the predicate193-- NonnegativeReal, which also discharges the soft type of √x.194instance Constructible.sqrt (x : Real)195  requires xC : Constructible(x)196  requires nonneg : NonnegativeReal(x)197  shows Constructible(√x)198proof199  have le := NonnegativeReal.le at x with nonneg200  have closed := constructibles.closed201  unfold sqrt202  exact closed.right with x, xC, le203204theorem Constructible.sqrt_of_le (x : Real)205  requires xC : Constructible(x)206  requires nonneg : (0:R) ≤ x207  shows Constructible(realSqrt(x))208proof209  have closed := constructibles.closed210  exact closed.right with x, xC, nonneg211212theorem Constructible.inv (x : Real)213  requires xC : Constructible(x)214  requires nonzero : x ≠ 0215  shows Constructible(realInvValue(x))216proof217  have field := constructibles.subfield218  exact RealSubfield.inv_mem with field, xC, nonzero219220theorem Constructible.div (x y : Real)221  requires xC : Constructible(x)222  requires yC : Constructible(y)223  requires nonzero : y ≠ 0224  shows Constructible(x / y)225proof226  have field := constructibles.subfield227  exact RealSubfield.div_mem with field, xC, yC, nonzero228229theorem Constructible.zero230  shows Constructible((0:R))231proof232  have field := constructibles.subfield233  exact RealSubfield.zero_mem with field234235theorem Constructible.one236  shows Constructible((1:R))237proof238  have field := constructibles.subfield239  exact RealSubfield.one_mem with field240241theorem Constructible.numeral (n : Nat)242  shows Constructible(realNat(n))243proof244  have field := constructibles.subfield245  exact RealSubfield.numeral_mem with field246247theorem Constructible.rational (x : Set)248  requires xIn : x ∈ rationalReals249  shows Constructible(x)250proof251  have field := constructibles.subfield252  have included := RealSubfield.rationals_subset with field253  exact included with x, xIn254