1-- Order completeness of the Dedekind reals2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Real.Order8import Core910-- Non-strict order on lower cuts is inclusion. Keeping it proposition-valued11-- makes the mathematical content visible while the graph interface matures.12predicate RealLe (A B : Set) :=Real(A) ∧Real(B) ∧ (A ⊆ B)1314-- Non-strict real order as a set-valued relation graph. Its15-- proposition-level view remains RealLe; the graph supports typed ≤ notation16-- and the same inspectable elaboration boundary as realLess.17def realLe : Set:=18 { p ∈ ℝ × ℝ |∃ A ∈ ℝ, ∃ B ∈ ℝ, p = (A, B) ∧ (A ⊆ B) }1920theorem realLe.characterization (A B : Set)21shows relates(realLe, A, B) ↔ RealLe(A, B)22proof23constructor24 . intro le25unfold relates at le26simp [realLe.membership] at le27rcases le with⟨_, X, realX, Y, realY, pairShape, subset⟩28obtain⟨equalA, equalB⟩:= orderedPair.injective with pairShape29constructor30 . unfoldReal31 rwa equalA32 . constructor33 . unfoldReal34 rwa equalB35 . rw [equalA, equalB]36exact subset37 . intro le38rcases le with⟨realA, realB, subset⟩39unfold relates40apply realLe.membership.backward41constructor42 . apply product.pair at A, B, ℝ, ℝ43exact realA44exact realB45 . witness A46constructor47exact realA48 . witness B49constructor50exact realB51refine⟨rfl, subset⟩5253theorem realLe.relation54shows RelationBetween(realLe, ℝ, ℝ)55proof56intros p hp57obtain⟨bounded, witnesses⟩:= realLe.membership.forward with hp58exact bounded5960instance realLe.operation61shows LessEqualOperation(ℝ, realLe)62proof63exact realLe.relation6465notationinfix50"≤"=> relates via LessEqualOperation(ℝ, _) forReal6667theorem realLe.subset (A B : Real)68requires le : A ≤ B69shows A ⊆ B70proof71have proposition := realLe.characterization.forward with le72unfold RealLe at proposition73simp7475theorem realLe.of_subset (A B : Real)76requires subset : A ⊆ B77shows A ≤ B78proof79apply realLe.characterization.backward80unfold RealLe81tauto8283predicate RealUpperBound (S B : Set) :=84Real(B) ∧ (S ⊆ ℝ) ∧ (∀ A ∈ S, (A ⊆ B))8586predicate RealLeastUpperBound (S U : Set) :=87 RealUpperBound(S, U) ∧88 (∀ B, RealUpperBound(S, B) → (U ⊆ B))8990-- The union of a family of lower cuts is its candidate supremum.91def realSup (S : Set) : Set:=⋃(S)9293theorem RealLe.reflexive (A : Set)94requires realA : Real(A)95shows RealLe(A, A)96proof97refine⟨realA, realA, Subset.reflexive at A⟩9899theorem RealLe.transitive (A B C : Set)100requires hAB : RealLe(A, B)101requires hBC : RealLe(B, C)102shows RealLe(A, C)103proof104rcases hAB with⟨realA, realB, subsetAB⟩105rcases hBC with⟨realBAgain, realC, subsetBC⟩106constructor107exact realA108constructor109exact realC110exact Subset.transitive with subsetAB, subsetBC111112theorem RealLe.antisymmetric (A B : Set)113requires hAB : RealLe(A, B)114requires hBA : RealLe(B, A)115shows A = B116proof117rcases hAB with⟨realA, realB, subsetAB⟩118rcases hBA with⟨realBAgain, realAAgain, subsetBA⟩119exact Subset.antisymmetric with subsetAB, subsetBA120121theorem realSup.subset_upper (S B : Set)122requires upper : RealUpperBound(S, B)123shows (realSup(S) ⊆ B)124proof125rcases upper with⟨realB, reals, bounds⟩126unfold realSup127exact union.subset with bounds128129theorem realSup.cut (S B : Set)130requires inhabited : Nonempty(S)131requires upper : RealUpperBound(S, B)132shows DedekindCut(realSup(S))133proof134rcases upper with⟨realB, reals, bounds⟩135have cutB :=Real.characterization.forward with realB136constructor137intros q0 hq0138unfold realSup at hq0139simp [set.union] at hq0140obtain⟨A, hAS, hq0A⟩:= hq0141specialize reals with A, hAS142obtain⟨powerA, cutA⟩:= Grace.Cumulus.Real.Defs.reals.membership.forward with reals143have subsetA := DedekindCut.subset_rationals with cutA144exact subsetA with q0, hq0A145 . constructor146 . obtain⟨A0, hA0S⟩:= inhabited147specialize reals with A0, hA0S148obtain⟨powerA, cutA⟩:= Grace.Cumulus.Real.Defs.reals.membership.forward with reals149obtain⟨q1, hq1A⟩:= DedekindCut.nonempty with cutA150witness q1151unfold realSup152exact union.contains with hA0S, hq1A153 . constructor154 . intro equalQ155unfold realSup at equalQ156have unionBound := union.subset with bounds157rw equalQ at unionBound158have subsetB := DedekindCut.subset_rationals with cutB159have equalB := Subset.antisymmetric with subsetB, unionBound160have properB := DedekindCut.proper with cutB161exact ProperSubset.ne with properB, equalB162 . constructor163 . intros q2 hq2 p2 hp2 less2164unfold realSup at hq2165simp [set.union] at hq2166obtain⟨A1, hA1S, hq2A1⟩:= hq2167specialize reals with A1, hA1S168obtain⟨powerA, cutA⟩:= Grace.Cumulus.Real.Defs.reals.membership.forward with reals169have downward := DedekindCut.downward with cutA, hq2A1, hp2, less2170unfold realSup171exact union.contains with hA1S, downward172 . intros q3 hq3173unfold realSup at hq3174simp [set.union] at hq3175obtain⟨A2, hA2S, hq3A2⟩:= hq3176specialize reals with A2, hA2S177obtain⟨powerA, cutA⟩:= Grace.Cumulus.Real.Defs.reals.membership.forward with reals178obtain⟨r3, hr3A2, less3⟩:= DedekindCut.no_greatest with cutA, hq3A2179witness r3180constructor181 . unfold realSup182exact union.contains with hA2S, hr3A2183 . exact less3184185theorem realSup.least_upper_bound (S B : Set)186requires inhabited : Nonempty(S)187requires upper : RealUpperBound(S, B)188shows RealLeastUpperBound(S, realSup(S))189proof190constructor191constructor192 . applyReal.characterization.backward at realSup(S)193exact realSup.cut with inhabited, upper194 . rcases upper with⟨realB, reals, bounds⟩195constructor196 . exact reals197 . intros A hAS q hqA198unfold realSup199exact union.contains with hAS, hqA200 . intros C upperC201exact realSup.subset_upper with upperC202203-- Every inhabited family of reals with a real upper bound has a least one.204-- This is the least-upper-bound property used by real analysis.205theoremReal.least_upper_bound_property (S : Set)206requires inhabited : Nonempty(S)207requires bounded : ∃ B, RealUpperBound(S, B)208shows∃ U, RealLeastUpperBound(S, U)209proof210obtain⟨B, upper⟩:= bounded211witness realSup(S)212exact realSup.least_upper_bound with inhabited, upper213