Expand description
Int as a real inductive — Lean’s ofNat | negSucc with its arithmetic defined rather than
assumed (Init/Data/Int/Basic.lean:40-45, :78-166). The construction, packaged so the
prelude adopts it in one call; the module header carries how Lean keeps it fast anyway.
Int as a REAL INDUCTIVE — Lean’s ofNat | negSucc, with its arithmetic DEFINED.
The standard prelude represents integers with checked constructors and definitions.
Ring and order facts still need separate proof terms; installing a carrier does not
turn an assumed law into a theorem.
It is a block Lean does not pay: Init/Data/Int/Basic.lean:40–45 declares
inductive Int : Type where
| ofNat : Nat → Int
| negSucc : Nat → Intand then DEFINES negOfNat, neg, subNatNat, add, mul and sub by matching on those
two constructors (Init/Data/Int/Basic.lean:78–166). Every arithmetic identity Lean states
about Int is a theorem over that definition.
§How Lean keeps it fast anyway
The obvious objection to constructors is cost: ofNat n looks like a unary Peano spine, so
2 + 3 looks linear and 2 * 3 quadratic. Lean’s answer — read off its own source rather
than guessed — is that Int’s arithmetic BOTTOMS OUT IN Nat’s. Look at the ofNat/ofNat
arm of Int.add: it is ofNat (m + n), ONE Nat addition, and Nat literals are
GMP-accelerated in Lean’s kernel. The @[extern "lean_int_add"] attribute on the same
definition (Init/Data/Int/Basic.lean:126) is the COMPILER’s story, not the kernel’s:
Int.ofNat itself carries @[extern "lean_nat_to_int"] (line 47) so a runtime Int is
never a spine either.
LOGOS keeps compact arbitrary-precision literals and canonical constructor bridges. Public addition and multiplication have checked definition bodies. Their literal accelerations attest the complete program dependency chain and preserve each kernel’s independent arithmetic implementation. Rebinding any dependency disables the shortcut.
§What this module is for
The standard prelude calls this module to install checked constructors and arithmetic. Constructors pass positivity/universe checks; arithmetic remains ordinary definitions visible to both kernels. The literal bridge below activates only for the canonical declaration signatures. The standard prelude also installs the public add/mul aliases. Other primitive operations and the ring/order axioms remain separately auditable until their derived replacements are installed.
Functions§
- canonical_
int - The canonical
Intterm for a machine integer, in Lean’s representation:ofNat nforn ≥ 0,negSucc (-n-1)below. TheNatargument is aLiteral::Nat, not aSuccspine, so a large integer costs one node — which is the whole point of theNatliteral bridge. - register_
inductive_ int - The whole adoption, as one call:
Intgains Lean’s two constructors and Lean’s arithmetic. - register_
int_ arithmetic - register_
int_ constructors Int’s two constructors, through the CHECKED door.- register_
nat_ arithmetic - supports_
integer_ polynomial_ operations - Whether the public add/mul/sub vocabulary has the standard integer meaning.