The type of integers. It is defined as an inductive type based on the
natural number type Nat
featuring two constructors: "a natural
number is an integer", and "the negation of a successor of a natural
number is an integer". The former represents integers between 0
(inclusive) and ∞
, and the latter integers between -∞
and -1
(inclusive).
This type is special-cased by the compiler. The runtime has a special
representation for Int
which stores "small" signed numbers directly,
and larger numbers use an arbitrary precision "bignum" library
(usually GMP). A "small number" is an integer
that can be encoded with 63 bits (31 bits on 32-bits architectures).
- ofNat: Nat → Int
A natural number is an integer (
0
to∞
). - negSucc: Nat → Int
The negation of the successor of a natural number is an integer (
-1
to-∞
).
Instances For
- AddCircle.instDivisibleByInt
- AddCommGroup.intIsScalarTower
- AddCommGroup.toIntModule
- AddCon.Quotient.zsmul
- AddGroup.continuousConstSMul_int
- AddGroup.continuousSMul_int
- AddGroup.intSMulWithZero
- AddGroup.int_smulCommClass
- AddGroup.int_smulCommClass'
- AddGroup.uniformContinuousConstSMul_int
- AddSubgroup.zsmul
- AddSubgroupClass.zsmul
- Batteries.instLawfulOrdInt
- BoundedContinuousFunction.instSMulInt
- CategoryTheory.Equivalence.instPowInt
- Con.zpowinst
- ContinuousMap.instZPow
- ContinuousMap.instZSMul
- DFinsupp.hasIntScalar
- Denumerable.int
- DivInvMonoid.Pow
- DivInvMonoid.measurableZPow
- Finsupp.instIntSMul
- Int.ModEq.instIsRefl
- Int.ModEq.instIsTrans
- Int.borelSpace
- Int.canLiftPNat
- Int.encodable
- Int.euclideanDomain
- Int.infinite
- Int.instAdd
- Int.instAddCommGroup
- Int.instAddCommMonoid
- Int.instAddCommSemigroup
- Int.instAddGroup
- Int.instAddLeftMono
- Int.instAddMonoid
- Int.instAddSemigroup
- Int.instCancelCommMonoidWithZero
- Int.instCharZero
- Int.instCommMonoid
- Int.instCommRing
- Int.instCommSemigroup
- Int.instCommSemiring
- Int.instComplement
- Int.instDist
- Int.instDistrib
- Int.instDiv
- Int.instDvd
- Int.instGCDMonoid
- Int.instHShiftRightNat
- Int.instInhabited
- Int.instIsPredArchimedean
- Int.instIsSuccArchimedean
- Int.instLEInt
- Int.instLTInt
- Int.instLawfulBEq
- Int.instLinearOrder
- Int.instLinearOrderedCommRing
- Int.instLocallyFiniteOrder
- Int.instMax
- Int.instMeasurableSingletonClass
- Int.instMeasurableSpace
- Int.instMetricSpace
- Int.instMin
- Int.instMod
- Int.instMonoid
- Int.instMul
- Int.instMulDivCancelClass
- Int.instNatPow
- Int.instNegInt
- Int.instNontrivial
- Int.instNormOneClass
- Int.instNormalizedGCDMonoid
- Int.instNormedAddCommGroup
- Int.instNormedCommRing
- Int.instOrderedCommRing
- Int.instOrderedRing
- Int.instPredOrder
- Int.instPredSubOrder
- Int.instProperSpace
- Int.instRing
- Int.instSemigroup
- Int.instSemiring
- Int.instShiftLeft_mathlib
- Int.instShiftRight_mathlib
- Int.instStarRing
- Int.instSub
- Int.instSuccAddOrder
- Int.instSuccOrder
- Int.instTrivialStar
- Int.normalizationMonoid
- Int.normedLatticeAddCommGroup
- Int.orderedSMul
- Lean.Json.instCoeInt
- Lean.JsonNumber.instCoeInt
- Lean.KVMap.instValueInt
- Lean.Omega.IntList.instHMulInt
- Lean.Omega.LinearCombo.instHMulInt
- Lean.Rat.instCoeInt
- Lean.instCoeIntDataValue
- Lean.instFromJsonInt
- Lean.instToExprInt
- Lean.instToJsonInt
- LinearMap.CompatibleSMul.intModule
- Mathlib.Tactic.Polyrith.instQuoteIntMkStr1_mathlib
- MeasureTheory.AEEqFun.instPowInt
- MeasureTheory.SimpleFunc.hasIntPow
- Module.Finite.addMonoidHom
- Module.Free.addMonoidHom
- NNRat.instZPow
- NoZeroSMulDivisors.CharZero.noZeroSMulDivisors_int
- NonUnitalNonAssocRing.int_isScalarTower
- NonUnitalNonAssocRing.int_smulCommClass
- Nonneg.zpow
- NormedAddGroupHom.zsmul
- NumberField.RingOfIntegers.instFreeInt
- NumberField.RingOfIntegers.instIsIntegralClosureInt
- NumberField.RingOfIntegers.instIsIntegralInt
- NumberField.RingOfIntegers.instIsNoetherianInt
- Plausible.Int.sampleableExt
- Plausible.Int.shrinkable
- Plausible.Random.instBoundedRandomInt
- Polynomial.instZSMul
- Rat.canLift
- Rat.isFractionRing
- RatModule.noZeroSMulDivisors
- Ring.toIntAlgebra
- RingCon.hasZSMul
- SeparationQuotient.instZPow
- SeparationQuotient.instZSMul
- StarAddMonoid.toStarModuleInt
- SubNegMonoid.SMulInt
- SubNegMonoid.measurableSMul_int₂
- Subfield.instPowSubtypeMemInt
- Subgroup.zpow
- SubgroupClass.zpow
- TensorProduct.CompatibleSMul.int
- TwoSidedIdeal.instSMulIntSubtypeMem
- WithZero.instPowInt
- divisibleByIntOfCharZero
- instArchimedeanInt
- instCanLiftIntNatCastLeOfNat
- instCoeHTCTIntOfIntCast
- instCoeTailIntOfIntCast
- instConditionallyCompleteLinearOrder
- instCountableInt
- instDiscreteTopologyInt
- instFloorRingInt
- instHashableInt
- instIntCastInt
- instIsAddCyclicInt
- instLatticeInt
- instNatCastInt
- instNoncompactSpaceInt
- instOfNat
- instOrdInt
- instReprAtomInt
- instReprInt
- instToStringInt
- instTopologicalSpaceInt
- instUniformSpaceInt
- selfAdjoint.instPowSubtypeMemAddSubgroupInt
Equations
- instNatCastInt = { natCast := fun (n : Nat) => Int.ofNat n }
Equations
- Int.instInhabited = { default := Int.ofNat 0 }
Coercions #
Negation of a natural number.
Equations
- Int.negOfNat 0 = 0
- Int.negOfNat m.succ = Int.negSucc m
Negation of an integer.
Implemented by efficient native code.
Equations
- (Int.ofNat n_2).neg = Int.negOfNat n_2
- (Int.negSucc n_2).neg = ↑n_2.succ
Equations
- Int.instNegInt = { neg := Int.neg }
Subtraction of two natural numbers.
Equations
- Int.subNatNat m n = match n - m with | 0 => Int.ofNat (m - n) | k.succ => Int.negSucc k
Addition of two integers.
#eval (7 : Int) + (6 : Int) -- 13
#eval (6 : Int) + (-6 : Int) -- 0
Implemented by efficient native code.
Equations
- (Int.ofNat m_2).add (Int.ofNat n_2) = Int.ofNat (m_2 + n_2)
- (Int.ofNat m_2).add (Int.negSucc n_2) = Int.subNatNat m_2 n_2.succ
- (Int.negSucc m_2).add (Int.ofNat n_2) = Int.subNatNat n_2 m_2.succ
- (Int.negSucc m_2).add (Int.negSucc n_2) = Int.negSucc (m_2 + n_2).succ
Multiplication of two integers.
#eval (63 : Int) * (6 : Int) -- 378
#eval (6 : Int) * (-6 : Int) -- -36
#eval (7 : Int) * (0 : Int) -- 0
Implemented by efficient native code.
Equations
- (Int.ofNat m_2).mul (Int.ofNat n_2) = Int.ofNat (m_2 * n_2)
- (Int.ofNat m_2).mul (Int.negSucc n_2) = Int.negOfNat (m_2 * n_2.succ)
- (Int.negSucc m_2).mul (Int.ofNat n_2) = Int.negOfNat (m_2.succ * n_2)
- (Int.negSucc m_2).mul (Int.negSucc n_2) = Int.ofNat (m_2.succ * n_2.succ)
Decides equality between two Int
s.
#eval (7 : Int) = (3 : Int) + (4 : Int) -- true
#eval (6 : Int) = (3 : Int) * (2 : Int) -- true
#eval ¬ (6 : Int) = (3 : Int) -- true
Implemented by efficient native code.
Equations
- (Int.ofNat m_1).decEq (Int.ofNat n_1) = match decEq m_1 n_1 with | isTrue h => isTrue ⋯ | isFalse h => isFalse ⋯
- (Int.ofNat m_1).decEq (Int.negSucc n_1) = isFalse ⋯
- (Int.negSucc m_1).decEq (Int.ofNat n_1) = isFalse ⋯
- (Int.negSucc m_1).decEq (Int.negSucc n_1) = match decEq m_1 n_1 with | isTrue h => isTrue ⋯ | isFalse h => isFalse ⋯
sign #
Conversion #
divisibility #
Divisibility of integers. a ∣ b
(typed as \|
) says that
there is some c
such that b = a * c
.
Powers #
The canonical homomorphism Int → R
.
In most use cases R
will have a ring structure and this will be a ring homomorphism.
Instances
- AddMonoid.End.instIntCast
- AddOpposite.instIntCast
- BitVec.instIntCast
- BoundedContinuousFunction.instIntCast
- BoundedContinuousFunction.instIntCast_1
- CauSeq.Completion.instIntCastCauchy
- CauSeq.instIntCast
- ContinuousMap.instIntCast
- Filter.Germ.instIntCast
- Lex.instIntCast
- Matrix.instIntCastOfZero
- MulOpposite.instIntCast
- OrderDual.instIntCast
- Pi.instIntCast
- Polynomial.instIntCast
- Rat.instIntCast
- Real.instIntCast
- RingCon.instIntCastQuotient
- SeparationQuotient.instIntCast
- SubringClass.toHasIntCast
- ULift.instIntCast
- instIntCastInt
- selfAdjoint.instIntCastSubtypeMemAddSubgroup
Equations
- instIntCastInt = { intCast := fun (n : Int) => n }