The positive natural numbers #
This file contains the definitions, and basic results.
Most algebraic facts are deferred to Data.PNat.Basic, as they need more imports.
ℕ+ is the type of positive natural numbers. It is defined as a subtype,
and the VM representation of ℕ+ is the same as ℕ because the proof
is not stored.
Equations
- «termℕ+» = Lean.ParserDescr.node `termℕ+ 1024 (Lean.ParserDescr.symbol "ℕ+")
Instances For
Equations
- instOnePNat = { one := { val := 1, property := Nat.zero_lt_one } }
Equations
- instReprPNat = { reprPrec := fun (n : ℕ+) (n' : ℕ) => reprPrec (↑n) n' }
Equations
- instOfNatPNatHAddNatInstHAddInstAddNatOfNat n = { ofNat := { val := n + 1, property := ⋯ } }
Convert a natural number to a positive natural number. The
positivity assumption is inferred by dec_trivial.
Equations
- Nat.toPNat n h = { val := n, property := h }
Instances For
Write a successor as an element of ℕ+.
Equations
- Nat.succPNat n = { val := Nat.succ n, property := ⋯ }
Instances For
Convert a natural number to a PNat. n+1 is mapped to itself,
and 0 becomes 1.
Equations
- Nat.toPNat' n = Nat.succPNat (Nat.pred n)
Instances For
We now define a long list of structures on ℕ+ induced by similar structures on ℕ. Most of these behave in a completely obvious way, but there are a few things to be said about subtraction, division and powers.
Equations
- PNat.instInhabitedPNat = { default := 1 }
Equations
- PNat.instWellFoundedRelationPNat = measure fun (a : ℕ+) => ↑a
Strong induction on ℕ+.
Equations
- PNat.strongInductionOn n x = x n fun (a : ℕ+) (x_1 : a < n) => PNat.strongInductionOn a x
Instances For
We define m % k and m / k in the same way as for ℕ
except that when m = n * k we take m % k = k and
m / k = n - 1. This ensures that m % k is always positive
and m = (m % k) + k * (m / k) in all cases. Later we
define a function div_exact which gives the usual m / k
in the case where k divides m.
Equations
- PNat.modDivAux x✝¹ x✝ x = match x✝¹, x✝, x with | k, 0, q => (k, Nat.pred q) | x, Nat.succ r, q => ({ val := r + 1, property := ⋯ }, q)
Instances For
mod_div m k = (m % k, m / k).
We define m % k and m / k in the same way as for ℕ
except that when m = n * k we take m % k = k and
m / k = n - 1. This ensures that m % k is always positive
and m = (m % k) + k * (m / k) in all cases. Later we
define a function div_exact which gives the usual m / k
in the case where k divides m.
Equations
- PNat.modDiv m k = PNat.modDivAux k (↑m % ↑k) (↑m / ↑k)
Instances For
We define m / k in the same way as for ℕ except that when m = n * k we take
m / k = n - 1. This ensures that m = (m % k) + k * (m / k) in all cases. Later we
define a function div_exact which gives the usual m / k in the case where k divides m.
Equations
- PNat.div m k = (PNat.modDiv m k).2
Instances For
If h : k | m, then k * (div_exact m k) = m. Note that this is not equal to m / k.
Equations
- PNat.divExact m k = { val := Nat.succ (PNat.div m k), property := ⋯ }