1-- Density and unboundedness of the rational order2-- 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.Rat.Density8import Operations910-- Every rational has a strictly smaller rational. On a displayed fraction11-- (a-b)/m, increasing the negative numerator by one gives (a-(b+1))/m.12theorem rationalLess.exists_below (q : Set)13requires qRational : Rational(q)14shows∃ p ∈ ℚ, p < q15proof16obtain⟨a, aNat, b, bNat, m, mNat, mNonzero, qShape⟩:=Rational.coordinates with qRational17have bSuccNat : Nat(succ(b)) byexact Naturals.constructor.succ at b with bNat18have bLess : b < succ(b)19apply Less.of_membership20 . exact membership.self_successor at b with bNat21have scaled := Less.mul_left with mNonzero, bLess22have maNat : Nat(m * a) bytypecheck23have leftReflexive := LessEqual.reflexive with maNat24have cross := LessEqual.add_Less with leftReflexive, scaled25have belowRational := rationalClass.rational with aNat, bSuccNat, mNat, mNonzero26have crossNormalized : m * a + m * b < m * a + m * succ(b)27ring_nfat cross28ring_nf29exact cross30have below := rationalLess.of_representatives with mNonzero, mNonzero, crossNormalized31witness rationalClass(a, succ(b), m)32constructor33exact belowRational34 . unfold rationalClass at qShape35rw qShape36unfold rationalClass37exact below3839-- Between two displayed fractions we use their midpoint. The proof40-- below exposes the two positive scaling certificates: density41-- is arithmetic, while descent to quotient classes is handled by the existing42-- rational-order boundary theorem.43theorem rationalLess.dense (q r : Set)44requires qRational : Rational(q)45requires rRational : Rational(r)46requires less : relates(rationalLess, q, r)47shows∃ s ∈ ℚ, q < s ∧ s < r48proof49obtain⟨a, aNat, b, bNat, m, mNat, mNonzero, qShape⟩:=Rational.coordinates with qRational50obtain⟨c, cNat, d, dNat, n, nNat, nNonzero, rShape⟩:=Rational.coordinates with rRational51have displayedLess : relates(52 rationalLess, rationalClass(a, b, m), rationalClass(c, d, n))53 simpa [qShape, rShape] using less54have crossLess := rationalLess.classes.forward with mNonzero, nNonzero, displayedLess5556have twoNonzero : 2≠057intro twoZero58arith59have mnNonzero := mul.nonzero with mNonzero, nNonzero60have mnNat : Nat(m * n) bytypecheck61have denominatorShape := mul.two_left with mnNat62have denominatorNonzero := mul.nonzero with twoNonzero, mnNonzero63have midpointRational := rationalClass.rational at64 n * a + m * c, n * b + m * d,652* (m * n) with denominatorNonzero6667have scaledLeft := Less.mul_left with mNonzero, crossLess68have leftCommonNat : Nat((m * n) * a + (m * n) * b) bytypecheck69have leftCommonReflexive := LessEqual.reflexive with leftCommonNat70have augmentedLeft := Less.add_LessEqual with scaledLeft, leftCommonReflexive71have leftCross : (2* (m * n)) * a + m * (n * b + m * d) < m * (n * a + m * c) + (2* (m * n)) * b72ring_nfat augmentedLeft73rw denominatorShape74ring_nf75exact augmentedLeft76have qMid := rationalLess.of_representatives with mNonzero, denominatorNonzero, leftCross7778have scaledRight := Less.mul_left with nNonzero, crossLess79have rightCommonNat : Nat((m * n) * c + (m * n) * d) bytypecheck80have rightCommonReflexive := LessEqual.reflexive with rightCommonNat81have augmentedRight := Less.add_LessEqual with scaledRight, rightCommonReflexive82have rightCross : n * (n * a + m * c) + (2* (m * n)) * d < (2* (m * n)) * c + n * (n * b + m * d)83ring_nfat augmentedRight84rw denominatorShape85ring_nf86exact augmentedRight87have midR := rationalLess.of_representatives with denominatorNonzero, nNonzero, rightCross8889witness rationalClass(n * a + m * c,90 n * b + m * d, 2* (m * n))91constructor92exact midpointRational93 . constructor94 . unfold rationalClass at qShape95rw qShape96unfold rationalClass97exact qMid98 . unfold rationalClass at rShape99rw rShape100unfold rationalClass101exact midR102