1-- Core laws of Dedekind cuts2-- 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.Core8import Defs9import Cumulus.Order1011theorem ProperSubset.subset (A B : Set)12requires h : A ⊂ B13shows (A ⊆ B)14proof15simp [ProperSubset]1617theorem ProperSubset.ne (A B : Set)18requires h : A ⊂ B19shows A ≠ B20proof21simp [ProperSubset]2223theorem ProperSubset.missing (A B : Set)24requires proper : A ⊂ B25shows∃ x ∈ B, ¬(x ∈ A)26proof27rcases proper with⟨subset, unequal⟩28by_contra noMissing29apply unequal30ext x31constructor32 . intro xInA33exact subset with x, xInA34 . intro xInB35by_contra xNotInA36apply noMissing37refine⟨x, xInB, xNotInA⟩3839theorem ProperSubset.irreflexive (A : Set)40shows¬(A ⊂ A)41proof42intro proper43rcases proper with⟨subset, unequal⟩44apply unequal45rfl4647theorem ProperSubset.transitive (A B C : Set)48requires hAB : A ⊂ B49requires hBC : B ⊂ C50shows (A ⊂ C)51proof52rcases hAB with⟨subsetAB, neAB⟩53rcases hBC with⟨subsetBC, neBC⟩54constructor55 . exact Subset.transitive with subsetAB, subsetBC56 . intro equalAC57rw← equalAC at subsetBC58have equalAB := Subset.antisymmetric with subsetAB, subsetBC59exact neAB with equalAB6061theorem DedekindCut.subset_rationals (A : Set)62requires cut : DedekindCut(A)63shows (A ⊆ ℚ)64proof65simp [DedekindCut]6667theorem DedekindCut.nonempty (A : Set)68requires cut : DedekindCut(A)69shows Nonempty(A)70proof71simp [DedekindCut]7273theorem DedekindCut.proper (A : Set)74requires cut : DedekindCut(A)75shows (A ⊂ ℚ)76proof77rcases cut with⟨subset, inhabited, proper, rest⟩78refine⟨subset, proper⟩7980theorem DedekindCut.downward (A p q : Set)81requires cut : DedekindCut(A)82requires hq : q ∈ A83requires hp : p ∈ ℚ84requires less : relates(rationalLess, p, q)85shows p ∈ A86proof87rcases cut with⟨subset, inhabited, proper, downward, rounded⟩88exact downward with q, hq, p, hp, less8990theorem DedekindCut.no_greatest (A q : Set)91requires cut : DedekindCut(A)92requires hq : q ∈ A93shows∃ r ∈ A, relates(rationalLess, q, r)94proof95rcases cut with⟨subset, inhabited, proper, downward, rounded⟩96exact rounded with q, hq9798-- Every member of a lower cut lies strictly below each rational omitted by99-- that cut. Connectedness rules out the reverse comparison by downward closure.100theorem DedekindCut.lt_missing (A a u : Set)101requires cut : DedekindCut(A)102requires aInA : a ∈ A103requires uInQ : u ∈ ℚ104requires uMissing : ¬(u ∈ A)105shows relates(rationalLess, a, u)106proof107have subset := DedekindCut.subset_rationals with cut108have aInQ := subset with a, aInA109have distinct : a ≠ u110intro equal111apply uMissing112 rwa ← equal113have connected := rationalLess.connected_on114have comparison := connected with a, aInQ, u, uInQ, distinct115cases comparison with aLessU | uLessA116 . exact aLessU117 . have uInA := DedekindCut.downward with cut, aInA, uInQ, uLessA118exfalso119exact uMissing with uInA120121theorem reals.membership (A : Set)122shows A ∈ ℝ ↔ DedekindCut(A)123proof124simp [ℝ, DedekindCut, Subset, set.powerset]125126theoremReal.characterization (A : Set)127showsReal(A) ↔ DedekindCut(A)128proof129simp [Real, reals.membership]130131theoremReal.extensionality (A B : Set)132requires realA : Real(A)133requires realB : Real(B)134requires same : ∀ q ∈ ℚ, (q ∈ A ↔ q ∈ B)135shows A = B136proof137ext q138have cutA :=Real.characterization.forward with realA139have cutB :=Real.characterization.forward with realB140have subsetA := DedekindCut.subset_rationals with cutA141have subsetB := DedekindCut.subset_rationals with cutB142constructor143 . intro hqA144specialize subsetA with q, hqA145specialize same with q, subsetA146apply same.forward147exact hqA148 . intro hqB149specialize subsetB with q, hqB150specialize same with q, subsetB151apply same.backward152exact hqB153154theorem RealLess.irreflexive (A : Set)155shows¬RealLess(A, A)156proof157intro h158rcases h with⟨realA, realAgain, proper⟩159exact ProperSubset.irreflexive with proper160161theorem RealLess.transitive (A B C : Set)162requires hAB : RealLess(A, B)163requires hBC : RealLess(B, C)164shows RealLess(A, C)165proof166rcases hAB with⟨realA, realB, properAB⟩167rcases hBC with⟨realBAgain, realC, properBC⟩168constructor169exact realA170constructor171exact realC172exact ProperSubset.transitive with properAB, properBC173174theorem realLess.membership (p : Set)175shows p ∈ realLess ↔ (p ∈ ℝ × ℝ ∧∃ x ∈ ℝ, ∃ y ∈ ℝ, p = (x, y) ∧ (x ⊂ y))176proof177simp178179theorem realLess.characterization (A B : Set)180shows relates(realLess, A, B) ↔ RealLess(A, B)181proof182constructor183 . intro less184unfold relates at less185simp [realLess.membership] at less186rcases less with⟨_, x, realX, y, realY, pairShape, proper⟩187obtain⟨equalA, equalB⟩:= orderedPair.injective with pairShape188constructor189 . unfoldReal190 rwa equalA191 . constructor192 . unfoldReal193 rwa equalB194 . rw [equalA, equalB]195exact proper196 . intro less197rcases less with⟨realA, realB, proper⟩198unfold relates199apply realLess.membership.backward200constructor201 . apply product.pair at A, B, ℝ, ℝ202exact realA203exact realB204 . witness A205constructor206exact realA207 . witness B208constructor209exact realB210refine⟨rfl, proper⟩211212theorem realLess.relation213shows RelationBetween(realLess, ℝ, ℝ)214proof215intros p hp216simp [realLess.membership] at hp217rcases hp with⟨bounded, witnesses⟩218exact bounded219220instance realLess.operation221shows LessOperation(ℝ, realLess)222proof223exact realLess.relation224225notationinfix50"<"=> relates via LessOperation(ℝ, _) forReal226227theorem realLess.irreflexive_on228shows IrreflexiveOn(ℝ, realLess)229proof230intros A realA less231have proposition := realLess.characterization.forward with less232exact RealLess.irreflexive with proposition233234theorem realLess.transitive_on235shows TransitiveOn(ℝ, realLess)236proof237intros A realA B realB C realC lessAB lessBC238have propositionAB := realLess.characterization.forward with lessAB239have propositionBC := realLess.characterization.forward with lessBC240have propositionAC := RealLess.transitive with propositionAB, propositionBC241exact realLess.characterization.backward with propositionAC242243-- Mainstream typed interface used by calculations and ordered algebra.244theorem realLess.transitive (A B C : Real)245requires AB : A < B246requires BC : B < C247shows A < C248proof249have transitive := realLess.transitive_on250exact transitive with A, B, C, AB, BC251252theorem realLess.strict_order253shows StrictOrder(ℝ, realLess)254proof255refine⟨realLess.relation, realLess.irreflexive_on, realLess.transitive_on⟩256257-- Lower cuts are nested. If some b belongs to B but not A, every member of258-- A lies below b and hence belongs to B by downward closure; otherwise B is259-- already a subset of A.260theorem DedekindCut.comparable (A B : Set)261requires cutA : DedekindCut(A)262requires cutB : DedekindCut(B)263shows (A ⊆ B) ∨ (B ⊆ A)264proof265by_contra incomparable266have notAB : ¬(A ⊆ B)267intro subsetAB268apply incomparable269left270exact subsetAB271have notBA : ¬(B ⊆ A)272intro subsetBA273apply incomparable274right275exact subsetBA276apply notBA277intros b bInB278by_contra bMissingA279apply notAB280intros a aInA281have subsetA := DedekindCut.subset_rationals with cutA282have subsetB := DedekindCut.subset_rationals with cutB283have aInQ := subsetA with a, aInA284have bInQ := subsetB with b, bInB285have aLessB := DedekindCut.lt_missing with cutA, aInA, bInQ, bMissingA286exact DedekindCut.downward with cutB, bInB, aInQ, aLessB287288theorem realLess.connected_on289shows ConnectedOn(ℝ, realLess)290proof291intros A realA B realB distinct292have typedA : Real(A) byexact realA293have typedB : Real(B) byexact realB294have cutA :=Real.characterization.forward with typedA295have cutB :=Real.characterization.forward with typedB296have comparable := DedekindCut.comparable with cutA, cutB297rcases comparable with subsetAB | subsetBA298 . left299have properAB : (A ⊂ B)300unfold ProperSubset301refine⟨subsetAB, distinct⟩302apply realLess.characterization.backward303unfold RealLess304refine⟨typedA, typedB, properAB⟩305 . right306have properBA : (B ⊂ A)307constructor308 . exact subsetBA309 . intro equalBA310apply distinct311rw equalBA312rfl313apply realLess.characterization.backward314unfold RealLess315refine⟨typedB, typedA, properBA⟩316317theorem realLess.strict_linear_order318shows StrictLinearOrder(ℝ, realLess)319proof320refine⟨realLess.strict_order, realLess.connected_on⟩321322theorem rationalCut.subset_rationals (q : Set)323shows (rationalCut(q) ⊆ ℚ)324proof325simp326327-- Rational lower segments are Dedekind cuts. Unboundedness supplies328-- an inhabitant, density supplies roundedness, and transitivity supplies329-- downward closure.330theorem rationalCut.cut (q : Set)331requires qRational : Rational(q)332shows DedekindCut(rationalCut(q))333proof334have qInQ := qRational335unfoldRationalat qInQ336unfold DedekindCut337refine⟨rationalCut.subset_rationals at q, _, _, _, _⟩338 . unfold Nonempty339obtain⟨p, pInQ, pLessQ⟩:= rationalLess.exists_below with qRational340witness p341apply rationalCut.membership.backward342constructor343 . exact pInQ344 . exact pLessQ345 . intro allRationals346have qInCut : q ∈ rationalCut(q) by rwa allRationals347obtain⟨_, selfLess⟩:= rationalCut.membership.forward with qInCut348have irreflexive := rationalLess.irreflexive_on349exact irreflexive with q, qInQ, selfLess350 . intros r rInCut p pInQ pLessR351obtain⟨rInQ, rLessQ⟩:= rationalCut.membership.forward with rInCut352have transitive := rationalLess.transitive_on353have pLessQ := transitive with354 p, pInQ, r, rInQ, q, qInQ, pLessR, rLessQ355apply rationalCut.membership.backward356constructor357 . exact pInQ358 . exact pLessQ359 . intros p pInCut360obtain⟨pInQ, pLessQ⟩:= rationalCut.membership.forward with pInCut361have pRational : Rational(p) byexact pInQ362obtain⟨s, sInQ, pLessS, sLessQ⟩:= rationalLess.dense with pRational, qRational, pLessQ363witness s364constructor365 . apply rationalCut.membership.backward at q, s366constructor367 . exact sInQ368 . exact sLessQ369 . exact pLessS370371theorem rationalCut.real (q : Set)372requires qRational : Rational(q)373showsReal(rationalCut(q))374proof375applyReal.characterization.backward376exact rationalCut.cut with qRational377378theorem rationalCut.strict_mono (q r : Set)379requires qRational : Rational(q)380requires rRational : Rational(r)381requires less : relates(rationalLess, q, r)382shows RealLess(rationalCut(q), rationalCut(r))383proof384have qInQ := qRational385have rInQ := rRational386unfold RealLess387refine⟨rationalCut.real at q with qRational,388 rationalCut.real at r with rRational, _⟩389constructor390intros p pInQCut391obtain⟨pInQ, pLessQ⟩:= rationalCut.membership.forward with pInQCut392have transitive := rationalLess.transitive_on393have pLessR := transitive with394 p, pInQ, q, qInQ, r, rInQ, pLessQ, less395apply rationalCut.membership.backward396constructor397 . exact pInQ398 . exact pLessR399 . intro cutsEqual400have qInRCut : q ∈ rationalCut(r) := rationalCut.membership.backward with⟨qInQ, less⟩401rw← cutsEqual at qInRCut402obtain⟨_, selfLess⟩:= rationalCut.membership.forward with qInRCut403have irreflexive := rationalLess.irreflexive_on404exact irreflexive with q, qInQ, selfLess405