Cast of natural numbers #
This file defines the canonical homomorphism from the natural numbers into an
AddMonoid with a one. In additive monoids with one, there exists a unique
such homomorphism and we store it in the natCast : ℕ → R field.
Preferentially, the homomorphism is written as the coercion Nat.cast.
Main declarations #
NatCast: Type class forNat.cast.AddMonoidWithOne: Type class for whichNat.castis a canonical monoid homomorphism fromℕ.Nat.cast: Canonical homomorphismℕ → R.
Recognize numeric literals which are at least 2 as terms of R via Nat.cast. This
instance is what makes things like 37 : R type check. Note that 0 and 1 are not needed
because they are recognized as terms of R (at least when R is an AddMonoidWithOne) through
Zero and One, respectively.
Equations
- instOfNatAtLeastTwo = { ofNat := ↑n }
When writing lemmas about OfNat.ofNat that assume Nat.AtLeastTwo, the term needs to be wrapped
in no_index so as not to confuse simp, as no_index (OfNat.ofNat n).
Rather than referencing this library note, use ofNat(n) as a shorthand for
no_index (OfNat.ofNat n).
Some discussion is on Zulip here.
Instances For
Additive monoids with one #
An AddMonoidWithOne is an AddMonoid with a 1.
It also contains data for the unique homomorphism ℕ → R.
- add : R → R → R
- zero : R
- one : R
The canonical map
ℕ → Rsends0 : ℕto0 : R.The canonical map
ℕ → Ris a homomorphism.
Instances
An AddCommMonoidWithOne is an AddMonoidWithOne satisfying a + b = b + a.
Instances
Coercions such as Nat.castCoe that go from a concrete structure such as
ℕ to an arbitrary ring R should be set up as follows:
instance : CoeTail ℕ R where coe := ...
instance : CoeHTCT ℕ R where coe := ...
It needs to be CoeTail instead of Coe because otherwise type-class
inference would loop when constructing the transitive coercion ℕ → ℕ → ℕ → ....
Sometimes we also need to declare the CoeHTCT instance
if we need to shadow another coercion
(e.g. Nat.cast should be used over Int.ofNat).
Equations
Instances For
Computationally friendlier cast than Nat.unaryCast, using binary representation.
Equations
Instances For
AddMonoidWithOne implementation using unary recursion.
Equations
- AddMonoidWithOne.unary = { natCast := Nat.unaryCast, toAddMonoid := inst✝¹, toOne := inst✝, natCast_zero := ⋯, natCast_succ := ⋯ }
Instances For
AddMonoidWithOne implementation using binary recursion.
Equations
- AddMonoidWithOne.binary = { natCast := Nat.binCast, toAddMonoid := inst✝¹, toOne := inst✝, natCast_zero := ⋯, natCast_succ := ⋯ }