1-- Natural numbers as reals: the embedding, its numerals, and its 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.Real.Natural8import Ring9import Algebra.Ring.Numeral1011def realNat (n : Nat) →Set12| zero => realZero13| succ(k) => realAddValue(realNat(k), realOne)1415theorem realNat.zero16shows realNat(0) = (0:R)17proof18simp1920theorem realNat.succ (n : Nat)21shows realNat(succ(n)) = realAddValue(realNat(n), realOne)22proof23rw realNat24rfl2526theorem realNat.real (n : Nat)27showsReal(realNat(n))28proof29induction n30| zero =>31rw realNat32exact realZero.real33| succ(k) using ih =>34rw realNat35have typed := realAddValue.real with ih, realOne.real36unfold call2 at typed37unfold realAddValue38exact typed3940theorem realNat.one41shows realNat(1) = (1:R)42proof43rw [realNat.succ, realNat.zero]44have zero := realAddValue.zero_left with realOne.real45unfold call2 at zero46unfold realAddValue47exact zero4849theorem realNat.numeral (n : Nat)50shows realNat(n) = ringNat(realAdd, realZero, realOne, n)51proof52induction n53| zero =>54rw [realNat.zero, ringNat.zero]55rfl56| succ(k) using ih =>57rw [realNat.succ, ringNat.succ, ih]58unfold realAddValue59unfold call260rfl6162-- The real numeral: every literal above one elaborates to realNumeral(n), a63-- name of its own so that rewriting zero, one, or realNat leaves numerals64-- intact. The bridge to ringNat lets ring read it as the n-fold sum of one.65def realNumeral (n : Nat) : Set:= realNat(n)6667theorem realNumeral.nat (n : Nat)68shows realNumeral(n) = realNat(n)69proof70unfold realNumeral71rfl7273theorem realNumeral.real (n : Nat)74showsReal(realNumeral(n))75proof76rw realNumeral.nat77exact realNat.real7879theorem realNumeral.numeral (n : Nat)80shows realNumeral(n) = ringNat(realAdd, realZero, realOne, n)81proof82rw [realNumeral.nat, realNat.numeral]83rfl8485notation numeral _ => realNumeral(_) forReal8687-- A natural number in a real position, an operand of a real operation or88-- comparison or one side of a real equation, is read as realNat(n) and89-- prints without the cast: n! * X is realNat(n!) * X.90notation coercion realNat forNat, Real9192theorem realNumeral.zero93shows (0:R) = realZero94proof95rfl9697theorem realNumeral.succ (k : Nat)98shows realNumeral(succ(k)) = realNumeral(k) + (1:R)99proof100rw [realNumeral.numeral, ringNat.succ, realNumeral.numeral]101rfl102103theorem realNat.add (m n : Nat)104shows realNat(add(m, n)) = (realNat(m):R) + (realNat(n):R)105proof106induction m107| zero =>108rw [add, realNat.zero]109ring110| succ(k) using ih =>111rw [add, realNat.succ, ih, realNat.succ]112ring113114theorem realNat.mul (m n : Nat)115shows realNat(mul(m, n)) = (realNat(m):R) * (realNat(n):R)116proof117induction m118| zero =>119rw [mul, realNat.zero]120ring121| succ(k) using ih =>122rw [mul, realNat.add, ih, realNat.succ]123ring124125-- Natural numbers embedded in the reals are nonnegative, and positive126-- above zero.127theorem realNat.zero_le (n : Nat)128shows (0:R) ≤ (realNat(n):R)129proof130induction n131| zero =>132rw realNat.zero133exact realLe.reflexive with realZero.real134| succ(k) using ih =>135have natural := realNat.real at k136rw realNat.succ137linarith138139theorem realNat.positive_succ (n : Nat)140shows (0:R) < (realNat(succ(n)):R)141proof142have natural := realNat.real at n143have nonnegative := realNat.zero_le at n144rw realNat.succ145linarith146147theorem realNat.positive (n : Nat)148requires nonzero : n ≠0149shows (0:R) < (realNat(n):R)150proof151have alternatives := natural.zero_or_successor at n152cases alternatives with zero | successor153 . exfalso154exact nonzero with zero155 . obtain⟨k, natural, shape⟩:= successor156rw shape157exact realNat.positive_succ at k158159theorem realNat.le_of_natural_le (m n : Nat)160requires le : m ≤ n161shows (realNat(m):R) ≤ (realNat(n):R)162proof163obtain⟨d, natural, split⟩:= le164have naturalM := realNat.real at m165have naturalD := realNat.real at d166have nonnegative := realNat.zero_le at d167have sum := realNat.add at m, d168rwsplitat sum169rw sum170linarith171172theorem realNat.ne_zero (n : Nat)173requires nonzero : n ≠0174shows (realNat(n):R) ≠0175proof176have positive := realNat.positive with nonzero177intro zero178rw zero at positive179linarith180