1-- The rational embedding into the Dedekind reals: the cut map is strictly2-- monotone and injective, reflects the order, and ℚ is dense in ℝ3-- Part of Cumulus, the Grace17 mathematics library.4-- Copyright (c) 2026 Grant Passmore.5-- Released under the Apache License 2.0. See LICENSE in the repository root.6-- Authors: Grant Passmore78module Grace.Cumulus.Real.Embedding9import Order1011-- The canonical map q ↦ { p ∈ ℚ | p < q } as a set-valued graph.12def rationalEmbedding : Set:=13 { p ∈ ℚ × ℝ |14∃ q ∈ ℚ, p = (q ↦ rationalCut(q)) }1516theorem rationalEmbedding.relates (q x : Set)17shows relates(rationalEmbedding, q, x) ↔18 (q ∈ ℚ ∧ x = rationalCut(q))19proof20constructor21 . intro related22unfold relates at related23simp [rationalEmbedding.membership] at related24rcases related with⟨bounded, r, rRational, shape⟩25obtain⟨qShape, xShape⟩:= orderedPair.injective with shape26constructor27 . rw qShape28exact rRational29 . rw qShape30exact xShape31 . intro data32rcases data with⟨qRational, rfl⟩33have qTyped : Rational(q) byexact qRational34unfold relates35apply rationalEmbedding.membership.backward36constructor37 . apply product.pair at q, rationalCut(q), ℚ, ℝ38 . exact qRational39 . exact rationalCut.real with qTyped40 . refine⟨q, qRational, rfl⟩4142theorem rationalEmbedding.total43shows TotalBetween(rationalEmbedding, ℚ, ℝ)44proof45intros q qRational46have qTyped : Rational(q) byexact qRational47witness rationalCut(q)48constructor49 . exact rationalCut.real with qTyped50 . apply rationalEmbedding.relates.backward at q, rationalCut(q)51refine⟨qRational, rfl⟩5253theorem rationalEmbedding.functional54shows Functional(rationalEmbedding)55proof56intros q x qx y qy57have xData := rationalEmbedding.relates.forward with qx58have yData := rationalEmbedding.relates.forward with qy59rcases xData with⟨_, xShape⟩60rcases yData with⟨_, yShape⟩61rw [xShape, yShape]62rfl6364theorem rationalEmbedding.function65shows rationalEmbedding : ℚ → ℝ66proof67constructor68intros p hp69simp [rationalEmbedding.membership] at hp70rcases hp with⟨bounded, witnesses⟩71exact bounded72 . constructor73 . exact rationalEmbedding.functional74 . exact rationalEmbedding.total7576theorem rationalEmbedding.value (q : Set)77requires qRational : Rational(q)78shows rationalEmbedding(q) = rationalCut(q)79proof80apply FunctionBetween.apply_value at rationalEmbedding, ℚ, ℝ, q, rationalCut(q)81 . exact rationalEmbedding.function82exact qRational83 . apply rationalEmbedding.relates.backward at q, rationalCut(q)84constructor85exact qRational86 . rfl8788-- Equality of lower cuts reflects equality of rationals. Connectedness of89-- the rational order leaves only the two strict cases, and strict monotonicity90-- makes either case incompatible with equal cuts.91theorem rationalCut.injective (q r : Set)92requires qRational : Rational(q)93requires rRational : Rational(r)94requires equalCuts : rationalCut(q) = rationalCut(r)95shows q = r96proof97by_contra distinct98have qInQ := qRational99have rInQ := rRational100have connected := rationalLess.connected_on101have comparison := connected with q, qInQ, r, rInQ, distinct102rcases comparison with qLessR | rLessQ103 . have strict := rationalCut.strict_mono at q, r with104 qRational, rRational, qLessR105rcases strict with⟨_, _, proper⟩106have unequal := ProperSubset.ne with proper107exact unequal with equalCuts108 . have strict := rationalCut.strict_mono at r, q with109 rRational, qRational, rLessQ110rcases strict with⟨_, _, proper⟩111have unequal := ProperSubset.ne with proper112apply unequal113rw equalCuts114rfl115116theorem rationalEmbedding.injective117shows InjectiveBetween(rationalEmbedding, ℚ, ℝ)118proof119constructor120 . exact rationalEmbedding.function121 . intros q qInQ r rInQ x xInR qx rx122have qData := rationalEmbedding.relates.forward with qx123have rData := rationalEmbedding.relates.forward with rx124rcases qData with⟨_, qShape⟩125rcases rData with⟨_, rShape⟩126have equalCuts : rationalCut(q) = rationalCut(r) by rwa ← qShape127exact rationalCut.injective with equalCuts128129-- The cut embedding reflects the order.130theorem rationalCut.lt_of_cut_lt (p q : Rational)131requires less : RealLess(rationalCut(p), rationalCut(q))132shows p < q133proof134have order := rationalLess.trichotomy at p, q135cases order with below | rest136 . exact below137 . exfalso138cases rest with equal | above139 . rw equal at less140exact RealLess.irreflexive with less141 . have reversed := rationalCut.strict_mono with above142have cycle := RealLess.transitive with less, reversed143exact RealLess.irreflexive with cycle144145-- The rationals are dense in the reals: between two reals lies a rational146-- cut. A real is a lower cut; a rational of y missing from x, pushed up147-- once inside y, has a cut strictly between the two.148theorem rationalCut.between (x y : Real)149requires less : x < y150shows∃ q ∈ ℚ, x < rationalCut(q) ∧ rationalCut(q) < y151proof152obtain⟨typedX, typedY, inclusion⟩:=153 realLess.characterization.forward with less154have cutX :=Real.characterization.forward with typedX155have cutY :=Real.characterization.forward with typedY156obtain⟨r, rInY, rMissing⟩:= ProperSubset.missing with inclusion157obtain⟨s, sInY, rLessS⟩:= DedekindCut.no_greatest with cutY, rInY158have rationalsX := DedekindCut.subset_rationals with cutX159have rationalsY := DedekindCut.subset_rationals with cutY160have rInQ := rationalsY with r, rInY161have sInQ := rationalsY with s, sInY162have cutS := rationalCut.real at s with sInQ163have transitive := rationalLess.transitive_on164witness s165refine⟨sInQ, ?_, ?_⟩166 . apply realLess.characterization.backward167refine⟨typedX, cutS, ?_⟩168constructor169 . intros p pInX170have pInQ := rationalsX with p, pInX171have pLessR := DedekindCut.lt_missing with cutX, pInX, rInQ, rMissing172have pLessS := transitive with173 p, pInQ, r, rInQ, s, sInQ, pLessR, rLessS174exact rationalCut.membership.backward with⟨pInQ, pLessS⟩175 . intro same176apply rMissing177rw same178exact rationalCut.membership.backward with⟨rInQ, rLessS⟩179 . apply realLess.characterization.backward180refine⟨cutS, typedY, ?_⟩181constructor182 . intros p pInCut183obtain⟨pInQ, pLessS⟩:= rationalCut.membership.forward with pInCut184exact DedekindCut.downward with cutY, sInY, pInQ, pLessS185 . intro same186have sInCut : s ∈ rationalCut(s)187rw same188exact sInY189obtain⟨_, selfLess⟩:= rationalCut.membership.forward with sInCut190have irreflexive := rationalLess.irreflexive_on191exact irreflexive with s, sInQ, selfLess192