fact
stringlengths
10
4.79k
type
stringclasses
9 values
library
stringclasses
44 values
imports
listlengths
0
13
filename
stringclasses
718 values
symbolic_name
stringlengths
1
76
docstring
stringlengths
10
64.6k
protected Nat.eq_or_lt_of_le : {n m: Nat} → LE.le n m → Or (Eq n m) (LT.lt n m) | zero, zero, _ => Or.inl rfl | zero, succ _, _ => Or.inr (Nat.succ_le_succ (Nat.zero_le _)) | succ _, zero, h => absurd h (not_succ_le_zero _) | succ n, succ m, h => have : LE.le n m := Nat.le_of_succ_le_succ h match Nat.eq_or_lt_of_le this with | Or.inl h => Or.inl (h ▸ rfl) | Or.inr h => Or.inr (succ_le_succ h)
def
Init.Prelude
[]
Init/Prelude.lean
Nat.eq_or_lt_of_le
null
protected Nat.lt_or_ge (n m : Nat) : Or (LT.lt n m) (GE.ge n m) := match m with | zero => Or.inr (zero_le n) | succ m => match Nat.lt_or_ge n m with | Or.inl h => Or.inl (le_succ_of_le h) | Or.inr h => match Nat.eq_or_lt_of_le h with | Or.inl h1 => Or.inl (h1 ▸ Nat.le_refl _) | Or.inr h1 => Or.inr h1
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_or_ge
null
Nat.not_succ_le_self : (n : Nat) → Not (LE.le (succ n) n) | 0 => not_succ_le_zero _ | succ n => fun h => absurd (le_of_succ_le_succ h) (not_succ_le_self n)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.not_succ_le_self
null
protected Nat.lt_irrefl (n : Nat) : Not (LT.lt n n) := Nat.not_succ_le_self n
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_irrefl
null
protected Nat.lt_of_le_of_lt {n m k : Nat} (h₁ : LE.le n m) (h₂ : LT.lt m k) : LT.lt n k := Nat.le_trans (Nat.succ_le_succ h₁) h₂
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_of_le_of_lt
null
protected Nat.le_antisymm {n m : Nat} (h₁ : LE.le n m) (h₂ : LE.le m n) : Eq n m := match h₁ with | Nat.le.refl => rfl | Nat.le.step h => absurd (Nat.lt_of_le_of_lt h h₂) (Nat.lt_irrefl n)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.le_antisymm
null
protected Nat.lt_of_le_of_ne {n m : Nat} (h₁ : LE.le n m) (h₂ : Not (Eq n m)) : LT.lt n m := match Nat.lt_or_ge n m with | Or.inl h₃ => h₃ | Or.inr h₃ => absurd (Nat.le_antisymm h₁ h₃) h₂
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_of_le_of_ne
null
Nat.le_of_ble_eq_true (h : Eq (Nat.ble n m) true) : LE.le n m := match n, m with | 0, _ => Nat.zero_le _ | succ _, succ _ => Nat.succ_le_succ (le_of_ble_eq_true h)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.le_of_ble_eq_true
null
Nat.ble_self_eq_true : (n : Nat) → Eq (Nat.ble n n) true | 0 => rfl | succ n => ble_self_eq_true n
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.ble_self_eq_true
null
Nat.ble_succ_eq_true : {n m : Nat} → Eq (Nat.ble n m) true → Eq (Nat.ble n (succ m)) true | 0, _, _ => rfl | succ n, succ _, h => ble_succ_eq_true (n := n) h
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.ble_succ_eq_true
null
Nat.ble_eq_true_of_le (h : LE.le n m) : Eq (Nat.ble n m) true := match h with | Nat.le.refl => Nat.ble_self_eq_true n | Nat.le.step h => Nat.ble_succ_eq_true (ble_eq_true_of_le h)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.ble_eq_true_of_le
null
Nat.not_le_of_not_ble_eq_true (h : Not (Eq (Nat.ble n m) true)) : Not (LE.le n m) := fun h' => absurd (Nat.ble_eq_true_of_le h') h
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.not_le_of_not_ble_eq_true
null
Nat.lt_succ_of_le {n m : Nat} : LE.le n m → LT.lt n (succ m) := succ_le_succ
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_succ_of_le
null
protected Nat.lt_add_one (n : Nat) : LT.lt n (HAdd.hAdd n 1) := Nat.le_refl (succ n)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_add_one
null
Nat.lt_succ_self (n : Nat) : LT.lt n (succ n) := Nat.lt_add_one _
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_succ_self
null
protected Nat.lt_of_not_le {a b : Nat} (h : Not (LE.le a b)) : LT.lt b a := (Nat.lt_or_ge b a).resolve_right h
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.lt_of_not_le
null
protected Nat.add_pos_right : {b : Nat} → (a : Nat) → (hb : LT.lt 0 b) → LT.lt 0 (HAdd.hAdd a b) | zero, _, h => (Nat.not_succ_le_zero _ h).elim | succ _, _, _ => Nat.zero_lt_succ _
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.add_pos_right
null
protected Nat.mul_pos : {n m : Nat} → (hn : LT.lt 0 n) → (hm : LT.lt 0 m) → LT.lt 0 (HMul.hMul n m) | _, zero, _, hb => (Nat.not_succ_le_zero _ hb).elim | _, succ _, ha, _ => Nat.add_pos_right _ ha
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.mul_pos
null
protected Nat.pow_pos {a : Nat} : {n : Nat} → (h : LT.lt 0 a) → LT.lt 0 (HPow.hPow a n) | zero, _ => Nat.zero_lt_succ _ | succ _, h => Nat.mul_pos (Nat.pow_pos h) h
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.pow_pos
null
@[extern "lean_nat_dec_le"] Nat.decLe (n m : @& Nat) : Decidable (LE.le n m) := dite (Eq (Nat.ble n m) true) (fun h => isTrue (Nat.le_of_ble_eq_true h)) (fun h => isFalse (Nat.not_le_of_not_ble_eq_true h))
instance
Init.Prelude
[]
Init/Prelude.lean
Nat.decLe
A decision procedure for non-strict inequality of natural numbers, usually accessed via the `DecidableLE Nat` instance. Examples: * `(if 3 ≤ 4 then "yes" else "no") = "yes"` * `(if 6 ≤ 4 then "yes" else "no") = "no"` * `show 12 ≤ 12 by decide` * `show 5 ≤ 12 by decide`
@[extern "lean_nat_dec_lt"] Nat.decLt (n m : @& Nat) : Decidable (LT.lt n m) := decLe (succ n) m
instance
Init.Prelude
[]
Init/Prelude.lean
Nat.decLt
A decision procedure for strict inequality of natural numbers, usually accessed via the `DecidableLT Nat` instance. Examples: * `(if 3 < 4 then "yes" else "no") = "yes"` * `(if 4 < 4 then "yes" else "no") = "no"` * `(if 6 < 4 then "yes" else "no") = "no"` * `show 5 < 12 by decide`
@[extern "lean_nat_sub"] protected Nat.sub : (@& Nat) → (@& Nat) → Nat | a, 0 => a | a, succ b => pred (Nat.sub a b) attribute [gen_constructor_elims] Nat -- Grind setup for Nat.ctorIdx, the built-in propagator for `.ctorIdx` does not kick in -- due to the special representation of Nat constructors.
def
Init.Prelude
[]
Init/Prelude.lean
Nat.sub
Subtraction of natural numbers, truncated at `0`. Usually used via the `-` operator. If a result would be less than zero, then the result is zero. This definition is overridden in both the kernel and the compiler to efficiently evaluate using the arbitrary-precision arithmetic library. The definition provided here is the logical model. Examples: * `5 - 3 = 2` * `8 - 2 = 6` * `8 - 8 = 0` * `8 - 20 = 0`
protected Nat.ctorIdx_zero : Eq (Nat.ctorIdx 0) 0 := rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.ctorIdx_zero
null
protected Nat.ctorIdx_succ : Eq (Nat.ctorIdx (succ n)) 1 := rfl grind_pattern Nat.ctorIdx_zero => Nat.ctorIdx 0 grind_pattern Nat.ctorIdx_succ => Nat.ctorIdx (.succ n)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.ctorIdx_succ
null
instSubNat : Sub Nat where sub := Nat.sub
instance
Init.Prelude
[]
Init/Prelude.lean
instSubNat
null
Nat.succ_sub_succ_eq_sub (n m : Nat) : Eq (HSub.hSub (succ n) (succ m)) (HSub.hSub n m) := m.rec rfl (fun _ ih => congrArg pred ih)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.succ_sub_succ_eq_sub
null
Nat.pred_le : ∀ (n : Nat), LE.le (Nat.pred n) n | zero => Nat.le.refl | succ _ => le_succ _
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.pred_le
null
Nat.sub_le (n m : Nat) : LE.le (HSub.hSub n m) n := m.rec (Nat.le_refl _) (fun _ ih => Nat.le_trans (pred_le _) ih)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.sub_le
null
Nat.sub_lt : ∀ {n m : Nat}, LT.lt 0 n → LT.lt 0 m → LT.lt (HSub.hSub n m) n | 0, _, h1, _ => absurd h1 (Nat.lt_irrefl 0) | Nat.succ _, 0, _, h2 => absurd h2 (Nat.lt_irrefl 0) | Nat.succ n, Nat.succ m, _, _ => Eq.symm (succ_sub_succ_eq_sub n m) ▸ show LT.lt (HSub.hSub n m) (succ n) from lt_succ_of_le (sub_le n m)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.sub_lt
null
Nat.div_rec_lemma {x y : Nat} : (And (LT.lt 0 y) (LE.le y x)) → LT.lt (HSub.hSub x y) x := fun ⟨ypos, ylex⟩ => sub_lt (Nat.lt_of_lt_of_le ypos ylex) ypos
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.div_rec_lemma
null
Nat.div_rec_fuel_lemma {x y fuel : Nat} (hy : LT.lt 0 y) (hle : LE.le y x) (hfuel : LT.lt x (HAdd.hAdd fuel 1)) : LT.lt (HSub.hSub x y) fuel := Nat.lt_of_lt_of_le (div_rec_lemma ⟨hy, hle⟩) (Nat.le_of_lt_succ hfuel) set_option bootstrap.genMatcherCode false in
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.div_rec_fuel_lemma
null
@[extern "lean_nat_div", irreducible] protected Nat.div (x y : @& Nat) : Nat := dite (LT.lt 0 y) (fun hy => let rec go (fuel : Nat) (x : Nat) (hfuel : LT.lt x fuel) : Nat := match fuel with | succ fuel => dite (LE.le y x) (fun h => HAdd.hAdd (go fuel (HSub.hSub x y) (div_rec_fuel_lemma hy h hfuel)) 1) (fun _ => 0) termination_by structural fuel go (succ x) x (Nat.lt_succ_self _)) (fun _ => 0)
def
Init.Prelude
[]
Init/Prelude.lean
Nat.div
Division of natural numbers, discarding the remainder. Division by `0` returns `0`. Usually accessed via the `/` operator. This operation is sometimes called “floor division.” This function is overridden at runtime with an efficient implementation. This definition is the logical model. Examples: * `21 / 3 = 7` * `21 / 5 = 4` * `0 / 22 = 0` * `5 / 0 = 0`
Nat.instDiv : Div Nat := ⟨Nat.div⟩ set_option bootstrap.genMatcherCode false in
instance
Init.Prelude
[]
Init/Prelude.lean
Nat.instDiv
null
@[extern "lean_nat_mod"] protected noncomputable Nat.modCore (x y : Nat) : Nat := dite (LT.lt 0 y) (fun hy => let rec go (fuel : Nat) (x : Nat) (hfuel : LT.lt x fuel) : Nat := match fuel with | succ fuel => dite (LE.le y x) (fun h => go fuel (HSub.hSub x y) (div_rec_fuel_lemma hy h hfuel)) (fun _ => x) termination_by structural fuel go (succ x) x (Nat.lt_succ_self _)) (fun _ => x)
def
Init.Prelude
[]
Init/Prelude.lean
Nat.modCore
The modulo operator, which computes the remainder when dividing one natural number by another. Usually accessed via the `%` operator. When the divisor is `0`, the result is the dividend rather than an error. This is the core implementation of `Nat.mod`. It computes the correct result for any two closed natural numbers, but it does not have some convenient [definitional reductions](lean-manual://section/type-system) when the `Nat`s contain free variables. The wrapper `Nat.mod` handles those cases specially and then calls `Nat.modCore`. This function is overridden at runtime with an efficient implementation. This definition is the logical model.
Nat.modCoreGo_lt {fuel y : Nat} (hy : LT.lt 0 y) : (x : Nat) → (hfuel : LT.lt x fuel) → LT.lt (Nat.modCore.go y hy fuel x hfuel) y := fuel.rec (fun _ h => absurd h (Nat.not_lt_zero _)) (fun _ ih x _ => show LT.lt (dite _ _ _) _ from match Nat.decLe y x with | .isTrue _ => ih _ _ | .isFalse h => Nat.lt_of_not_le h)
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.modCoreGo_lt
null
Nat.modCore_lt {x y : Nat} (hy : LT.lt 0 y) : LT.lt (Nat.modCore x y) y := show LT.lt (dite _ _ _) y from match Nat.decLt 0 y with | .isTrue _ => Nat.modCoreGo_lt hy x (Nat.lt_succ_self _) | .isFalse h => absurd hy h attribute [irreducible] Nat.modCore set_option bootstrap.genMatcherCode false in
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.modCore_lt
null
@[extern "lean_nat_mod"] protected Nat.mod : @& Nat → @& Nat → Nat /- Nat.modCore is defined with fuel and thus does not reduce with open terms very well. Nevertheless it is desirable for trivial `Nat.mod` calculations, namely * `Nat.mod 0 m` for all `m` * `Nat.mod n (m + n + 1)` for concrete literals `n`, to reduce definitionally. This property is desirable for `Fin n` literals, as it means `(ofNat 0 : Fin n).val = 0` by definition. -/ | 0, _ => 0 | n@(succ _), m => ite (LE.le m n) (Nat.modCore n m) n
def
Init.Prelude
[]
Init/Prelude.lean
Nat.mod
The modulo operator, which computes the remainder when dividing one natural number by another. Usually accessed via the `%` operator. When the divisor is `0`, the result is the dividend rather than an error. `Nat.mod` is a wrapper around `Nat.modCore` that special-cases two situations, giving better definitional reductions: * `Nat.mod 0 m` should reduce to `m`, for all terms `m : Nat`. * `Nat.mod n (m + n + 1)` should reduce to `n` for concrete `Nat` literals `n`. These reductions help `Fin n` literals work well, because the `OfNat` instance for `Fin` uses `Nat.mod`. In particular, `(0 : Fin (n + 1)).val` should reduce definitionally to `0`. `Nat.modCore` can handle all numbers, but its definitional reductions are not as convenient. This function is overridden at runtime with an efficient implementation. This definition is the logical model. Examples: * `7 % 2 = 1` * `9 % 3 = 0` * `5 % 7 = 5` * `5 % 0 = 5` * `show ∀ (n : Nat), 0 % n = 0 from fun _ => rfl` * `show ∀ (m : Nat), 5 % (m + 6) = 5 from fun _ => rfl`
Nat.instMod : Mod Nat := ⟨Nat.mod⟩
instance
Init.Prelude
[]
Init/Prelude.lean
Nat.instMod
null
Nat.mod_lt : (x : Nat) → {y : Nat} → (hy : LT.lt 0 y) → LT.lt (HMod.hMod x y) y | 0, succ _, _ => Nat.zero_lt_succ _ | succ n, m, hm => show LT.lt (ite (LE.le m (succ n)) (Nat.modCore (succ n) m) (succ n)) _ from match Nat.decLe m (succ n) with | .isTrue _ => Nat.modCore_lt hm | .isFalse h => Nat.lt_of_not_le h
theorem
Init.Prelude
[]
Init/Prelude.lean
Nat.mod_lt
null
@[extern "lean_system_platform_nbits"] System.Platform.getNumBits : Unit → Subtype fun (n : Nat) => Or (Eq n 32) (Eq n 64) := fun _ => ⟨64, Or.inr rfl⟩ -- inhabitant
opaque
Init.Prelude
[]
Init/Prelude.lean
System.Platform.getNumBits
Gets the word size of the current platform. The word size may be 64 or 32 bits. This function is opaque because there is no guarantee at compile time that the target will have the same word size as the host. It also helps avoid having type checking be architecture-dependent. Lean only works on 64 and 32 bit systems. This fact is visible in the return type.
System.Platform.numBits : Nat := (getNumBits ()).val
def
Init.Prelude
[]
Init/Prelude.lean
System.Platform.numBits
The word size of the current platform, which may be 64 or 32 bits.
System.Platform.numBits_eq : Or (Eq numBits 32) (Eq numBits 64) := (getNumBits ()).property
theorem
Init.Prelude
[]
Init/Prelude.lean
System.Platform.numBits_eq
The word size of the current platform may be 64 or 32 bits.
@[pp_using_anonymous_constructor] Fin (n : Nat) where /-- Creates a `Fin n` from `i : Nat` and a proof that `i < n`. -/ mk :: /-- The number that is strictly less than `n`. `Fin.val` is a coercion, so any `Fin n` can be used in a position where a `Nat` is expected. -/ val : Nat /-- The number `val` is strictly less than the bound `n`. -/ isLt : LT.lt val n attribute [coe] Fin.val grind_pattern Fin.isLt => self.val
structure
Init.Prelude
[]
Init/Prelude.lean
Fin
Natural numbers less than some upper bound. In particular, a `Fin n` is a natural number `i` with the constraint that `i < n`. It is the canonical type with `n` elements.
Fin.eq_of_val_eq {n} : ∀ {i j : Fin n}, Eq i.val j.val → Eq i j | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
Fin.eq_of_val_eq
null
Fin.val_eq_of_eq {n} {i j : Fin n} (h : Eq i j) : Eq i.val j.val := h ▸ rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
Fin.val_eq_of_eq
null
Fin.decLt {n} (a b : Fin n) : Decidable (LT.lt a b) := Nat.decLt ..
instance
Init.Prelude
[]
Init/Prelude.lean
Fin.decLt
null
Fin.decLe {n} (a b : Fin n) : Decidable (LE.le a b) := Nat.decLe ..
instance
Init.Prelude
[]
Init/Prelude.lean
Fin.decLe
null
@[expose] protected Fin.Internal.ofNat (n : Nat) (hn : LT.lt 0 n) (a : Nat) : Fin n := ⟨HMod.hMod a n, Nat.mod_lt _ hn⟩
def
Init.Prelude
[]
Init/Prelude.lean
Fin.Internal.ofNat
Returns `a` modulo `n` as a `Fin n`. This function exists for bootstrapping purposes. Use `Fin.ofNat` instead.
BitVec (w : Nat) where /-- Construct a `BitVec w` from a number less than `2^w`. O(1), because we use `Fin` as the internal representation of a bitvector. -/ ofFin :: /-- Interpret a bitvector as a number less than `2^w`. O(1), because we use `Fin` as the internal representation of a bitvector. -/ toFin : Fin (hPow 2 w)
structure
Init.Prelude
[]
Init/Prelude.lean
BitVec
A bitvector of the specified width. This is represented as the underlying `Nat` number in both the runtime and the kernel, inheriting all the special support for `Nat`.
@[match_pattern] protected BitVec.ofNatLT {w : Nat} (i : Nat) (p : LT.lt i (hPow 2 w)) : BitVec w where toFin := ⟨i, p⟩
def
Init.Prelude
[]
Init/Prelude.lean
BitVec.ofNatLT
Bitvectors have decidable equality. This should be used via the instance `DecidableEq (BitVec w)`. -/ -- We manually derive the `DecidableEq` instances for `BitVec` because -- we want to have builtin support for bit-vector literals, and we -- need a name for this function to implement `canUnfoldAtMatcher` at `WHNF.lean`. def BitVec.decEq (x y : BitVec w) : Decidable (Eq x y) := match x, y with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => BitVec.noConfusion rfl (heq_of_eq h') (fun h' => absurd (eq_of_heq h') h))) instance : DecidableEq (BitVec w) := BitVec.decEq /-- The `BitVec` with value `i`, given a proof that `i < 2^w`.
@[expose, match_pattern] protected BitVec.ofNat (n : Nat) (i : Nat) : BitVec n where toFin := Fin.Internal.ofNat (HPow.hPow 2 n) (Nat.pow_pos (Nat.zero_lt_succ _)) i
def
Init.Prelude
[]
Init/Prelude.lean
BitVec.ofNat
The bitvector with value `i mod 2^n`.
@[expose] protected BitVec.toNat (x : BitVec w) : Nat := x.toFin.val
def
Init.Prelude
[]
Init/Prelude.lean
BitVec.toNat
Return the underlying `Nat` that represents a bitvector. This is O(1) because `BitVec` is a (zero-cost) wrapper around a `Nat`.
UInt8.size : Nat := 256
abbrev
Init.Prelude
[]
Init/Prelude.lean
UInt8.size
The number of distinct values representable by `UInt8`, that is, `2^8 = 256`.
UInt8 where /-- Creates a `UInt8` from a `BitVec 8`. This function is overridden with a native implementation. -/ ofBitVec :: /-- Unpacks a `UInt8` into a `BitVec 8`. This function is overridden with a native implementation. -/ toBitVec : BitVec 8 attribute [extern "lean_uint8_of_nat_mk"] UInt8.ofBitVec attribute [extern "lean_uint8_to_nat"] UInt8.toBitVec
structure
Init.Prelude
[]
Init/Prelude.lean
UInt8
Unsigned 8-bit integers. This type has special support in the compiler so it can be represented by an unboxed 8-bit value rather than wrapping a `BitVec 8`.
@[extern "lean_uint8_of_nat"] UInt8.ofNatLT (n : @& Nat) (h : LT.lt n UInt8.size) : UInt8 where toBitVec := BitVec.ofNatLT n h
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.ofNatLT
Converts a natural number to an 8-bit unsigned integer. Requires a proof that the number is small enough to be representable without overflow; it must be smaller than `2^8`. This function is overridden at runtime with an efficient implementation.
@[extern "lean_uint8_of_nat"] UInt8.ofNat (n : @& Nat) : UInt8 := ⟨BitVec.ofNat 8 n⟩ set_option bootstrap.genMatcherCode false in
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.ofNat
Converts a natural number to an 8-bit unsigned integer, wrapping on overflow. This function is overridden at runtime with an efficient implementation. Examples: * `UInt8.ofNat 5 = 5` * `UInt8.ofNat 255 = 255` * `UInt8.ofNat 256 = 0` * `UInt8.ofNat 259 = 3` * `UInt8.ofNat 32770 = 2`
@[extern "lean_uint8_dec_eq"] UInt8.decEq (a b : UInt8) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt8.noConfusion h' (fun h' => absurd h' h)))
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.decEq
Decides whether two 8-bit unsigned integers are equal. Usually accessed via the `DecidableEq UInt8` instance. This function is overridden at runtime with an efficient implementation. Examples: * `UInt8.decEq 123 123 = .isTrue rfl` * `(if (6 : UInt8) = 7 then "yes" else "no") = "no"` * `show (7 : UInt8) = 7 by decide`
protected UInt8.lt (a b : UInt8) : Prop := LT.lt a.toBitVec b.toBitVec
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.lt
Strict inequality of 8-bit unsigned integers, defined as inequality of the corresponding natural numbers. Usually accessed via the `<` operator.
protected UInt8.le (a b : UInt8) : Prop := LE.le a.toBitVec b.toBitVec
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.le
Non-strict inequality of 8-bit unsigned integers, defined as inequality of the corresponding natural numbers. Usually accessed via the `≤` operator.
@[extern "lean_uint8_dec_lt"] UInt8.decLt (a b : UInt8) : Decidable (LT.lt a b) := inferInstanceAs (Decidable (LT.lt a.toBitVec b.toBitVec))
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.decLt
Decides whether one 8-bit unsigned integer is strictly less than another. Usually accessed via the `DecidableLT UInt8` instance. This function is overridden at runtime with an efficient implementation. Examples: * `(if (6 : UInt8) < 7 then "yes" else "no") = "yes"` * `(if (5 : UInt8) < 5 then "yes" else "no") = "no"` * `show ¬((7 : UInt8) < 7) by decide`
@[extern "lean_uint8_dec_le"] UInt8.decLe (a b : UInt8) : Decidable (LE.le a b) := inferInstanceAs (Decidable (LE.le a.toBitVec b.toBitVec)) attribute [instance] UInt8.decLt UInt8.decLe
def
Init.Prelude
[]
Init/Prelude.lean
UInt8.decLe
Decides whether one 8-bit unsigned integer is less than or equal to another. Usually accessed via the `DecidableLE UInt8` instance. This function is overridden at runtime with an efficient implementation. Examples: * `(if (15 : UInt8) ≤ 15 then "yes" else "no") = "yes"` * `(if (15 : UInt8) ≤ 5 then "yes" else "no") = "no"` * `(if (5 : UInt8) ≤ 15 then "yes" else "no") = "yes"` * `show (7 : UInt8) ≤ 7 by decide`
UInt16.size : Nat := 65536
abbrev
Init.Prelude
[]
Init/Prelude.lean
UInt16.size
The number of distinct values representable by `UInt16`, that is, `2^16 = 65536`.
UInt16 where /-- Creates a `UInt16` from a `BitVec 16`. This function is overridden with a native implementation. -/ ofBitVec :: /-- Unpacks a `UInt16` into a `BitVec 16`. This function is overridden with a native implementation. -/ toBitVec : BitVec 16 attribute [extern "lean_uint16_of_nat_mk"] UInt16.ofBitVec attribute [extern "lean_uint16_to_nat"] UInt16.toBitVec
structure
Init.Prelude
[]
Init/Prelude.lean
UInt16
Unsigned 16-bit integers. This type has special support in the compiler so it can be represented by an unboxed 16-bit value rather than wrapping a `BitVec 16`.
@[extern "lean_uint16_of_nat"] UInt16.ofNatLT (n : @& Nat) (h : LT.lt n UInt16.size) : UInt16 where toBitVec := BitVec.ofNatLT n h set_option bootstrap.genMatcherCode false in
def
Init.Prelude
[]
Init/Prelude.lean
UInt16.ofNatLT
Converts a natural number to a 16-bit unsigned integer. Requires a proof that the number is small enough to be representable without overflow; it must be smaller than `2^16`. This function is overridden at runtime with an efficient implementation.
@[extern "lean_uint16_dec_eq"] UInt16.decEq (a b : UInt16) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt16.noConfusion h' (fun h' => absurd h' h)))
def
Init.Prelude
[]
Init/Prelude.lean
UInt16.decEq
Decides whether two 16-bit unsigned integers are equal. Usually accessed via the `DecidableEq UInt16` instance. This function is overridden at runtime with an efficient implementation. Examples: * `UInt16.decEq 123 123 = .isTrue rfl` * `(if (6 : UInt16) = 7 then "yes" else "no") = "no"` * `show (7 : UInt16) = 7 by decide`
UInt32.size : Nat := 4294967296
abbrev
Init.Prelude
[]
Init/Prelude.lean
UInt32.size
The number of distinct values representable by `UInt32`, that is, `2^32 = 4294967296`.
UInt32 where /-- Creates a `UInt32` from a `BitVec 32`. This function is overridden with a native implementation. -/ ofBitVec :: /-- Unpacks a `UInt32` into a `BitVec 32`. This function is overridden with a native implementation. -/ toBitVec : BitVec 32 attribute [extern "lean_uint32_of_nat_mk"] UInt32.ofBitVec attribute [extern "lean_uint32_to_nat"] UInt32.toBitVec
structure
Init.Prelude
[]
Init/Prelude.lean
UInt32
Unsigned 32-bit integers. This type has special support in the compiler so it can be represented by an unboxed 32-bit value rather than wrapping a `BitVec 32`.
@[extern "lean_uint32_of_nat"] UInt32.ofNatLT (n : @& Nat) (h : LT.lt n UInt32.size) : UInt32 where toBitVec := BitVec.ofNatLT n h
def
Init.Prelude
[]
Init/Prelude.lean
UInt32.ofNatLT
Converts a natural number to a 32-bit unsigned integer. Requires a proof that the number is small enough to be representable without overflow; it must be smaller than `2^32`. This function is overridden at runtime with an efficient implementation.
@[extern "lean_uint32_to_nat"] UInt32.toNat (n : UInt32) : Nat := n.toBitVec.toNat set_option bootstrap.genMatcherCode false in
def
Init.Prelude
[]
Init/Prelude.lean
UInt32.toNat
Converts a 32-bit unsigned integer to an arbitrary-precision natural number. This function is overridden at runtime with an efficient implementation.
@[extern "lean_uint32_dec_eq"] UInt32.decEq (a b : UInt32) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt32.noConfusion h' (fun h' => absurd h' h)))
def
Init.Prelude
[]
Init/Prelude.lean
UInt32.decEq
Decides whether two 32-bit unsigned integers are equal. Usually accessed via the `DecidableEq UInt32` instance. This function is overridden at runtime with an efficient implementation. Examples: * `UInt32.decEq 123 123 = .isTrue rfl` * `(if (6 : UInt32) = 7 then "yes" else "no") = "no"` * `show (7 : UInt32) = 7 by decide`
@[extern "lean_uint32_dec_lt"] UInt32.decLt (a b : UInt32) : Decidable (LT.lt a b) := inferInstanceAs (Decidable (LT.lt a.toBitVec b.toBitVec))
def
Init.Prelude
[]
Init/Prelude.lean
UInt32.decLt
Decides whether one 8-bit unsigned integer is strictly less than another. Usually accessed via the `DecidableLT UInt32` instance. This function is overridden at runtime with an efficient implementation. Examples: * `(if (6 : UInt32) < 7 then "yes" else "no") = "yes"` * `(if (5 : UInt32) < 5 then "yes" else "no") = "no"` * `show ¬((7 : UInt32) < 7) by decide`
@[extern "lean_uint32_dec_le"] UInt32.decLe (a b : UInt32) : Decidable (LE.le a b) := inferInstanceAs (Decidable (LE.le a.toBitVec b.toBitVec)) attribute [instance] UInt32.decLt UInt32.decLe
def
Init.Prelude
[]
Init/Prelude.lean
UInt32.decLe
Decides whether one 32-bit signed integer is less than or equal to another. Usually accessed via the `DecidableLE UInt32` instance. This function is overridden at runtime with an efficient implementation. Examples: * `(if (15 : UInt32) ≤ 15 then "yes" else "no") = "yes"` * `(if (15 : UInt32) ≤ 5 then "yes" else "no") = "no"` * `(if (5 : UInt32) ≤ 15 then "yes" else "no") = "yes"` * `show (7 : UInt32) ≤ 7 by decide`
UInt64.size : Nat := 18446744073709551616
abbrev
Init.Prelude
[]
Init/Prelude.lean
UInt64.size
The number of distinct values representable by `UInt64`, that is, `2^64 = 18446744073709551616`.
UInt64 where /-- Creates a `UInt64` from a `BitVec 64`. This function is overridden with a native implementation. -/ ofBitVec :: /-- Unpacks a `UInt64` into a `BitVec 64`. This function is overridden with a native implementation. -/ toBitVec : BitVec 64 attribute [extern "lean_uint64_of_nat_mk"] UInt64.ofBitVec attribute [extern "lean_uint64_to_nat"] UInt64.toBitVec
structure
Init.Prelude
[]
Init/Prelude.lean
UInt64
Unsigned 64-bit integers. This type has special support in the compiler so it can be represented by an unboxed 64-bit value rather than wrapping a `BitVec 64`.
@[extern "lean_uint64_of_nat"] UInt64.ofNatLT (n : @& Nat) (h : LT.lt n UInt64.size) : UInt64 where toBitVec := BitVec.ofNatLT n h set_option bootstrap.genMatcherCode false in
def
Init.Prelude
[]
Init/Prelude.lean
UInt64.ofNatLT
Converts a natural number to a 64-bit unsigned integer. Requires a proof that the number is small enough to be representable without overflow; it must be smaller than `2^64`. This function is overridden at runtime with an efficient implementation.
@[extern "lean_uint64_dec_eq"] UInt64.decEq (a b : UInt64) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt64.noConfusion h' (fun h' => absurd h' h)))
def
Init.Prelude
[]
Init/Prelude.lean
UInt64.decEq
Decides whether two 64-bit unsigned integers are equal. Usually accessed via the `DecidableEq UInt64` instance. This function is overridden at runtime with an efficient implementation. Examples: * `UInt64.decEq 123 123 = .isTrue rfl` * `(if (6 : UInt64) = 7 then "yes" else "no") = "no"` * `show (7 : UInt64) = 7 by decide`
USize.size : Nat := (hPow 2 System.Platform.numBits)
abbrev
Init.Prelude
[]
Init/Prelude.lean
USize.size
The number of distinct values representable by `USize`, that is, `2^System.Platform.numBits`.
USize.size_eq : Or (Eq USize.size 4294967296) (Eq USize.size 18446744073709551616) := show Or (Eq (hPow 2 System.Platform.numBits) 4294967296) (Eq (hPow 2 System.Platform.numBits) 18446744073709551616) from match System.Platform.numBits, System.Platform.numBits_eq with | _, Or.inl rfl => Or.inl (of_decide_eq_true rfl) | _, Or.inr rfl => Or.inr (of_decide_eq_true rfl)
theorem
Init.Prelude
[]
Init/Prelude.lean
USize.size_eq
null
USize.size_pos : LT.lt 0 USize.size := match USize.size, USize.size_eq with | _, Or.inl rfl => of_decide_eq_true rfl | _, Or.inr rfl => of_decide_eq_true rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
USize.size_pos
null
USize where /-- Creates a `USize` from a `BitVec System.Platform.numBits`. This function is overridden with a native implementation. -/ ofBitVec :: /-- Unpacks a `USize` into a `BitVec System.Platform.numBits`. This function is overridden with a native implementation. -/ toBitVec : BitVec System.Platform.numBits attribute [extern "lean_usize_of_nat_mk"] USize.ofBitVec attribute [extern "lean_usize_to_nat"] USize.toBitVec
structure
Init.Prelude
[]
Init/Prelude.lean
USize
Unsigned integers that are the size of a word on the platform's architecture. On a 32-bit architecture, `USize` is equivalent to `UInt32`. On a 64-bit machine, it is equivalent to `UInt64`.
@[extern "lean_usize_of_nat"] USize.ofNatLT (n : @& Nat) (h : LT.lt n USize.size) : USize where toBitVec := BitVec.ofNatLT n h set_option bootstrap.genMatcherCode false in
def
Init.Prelude
[]
Init/Prelude.lean
USize.ofNatLT
Converts a natural number to a `USize`. Requires a proof that the number is small enough to be representable without overflow. This function is overridden at runtime with an efficient implementation.
@[extern "lean_usize_dec_eq"] USize.decEq (a b : USize) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => USize.noConfusion h' (fun h' => absurd h' h)))
def
Init.Prelude
[]
Init/Prelude.lean
USize.decEq
Decides whether two word-sized unsigned integers are equal. Usually accessed via the `DecidableEq USize` instance. This function is overridden at runtime with an efficient implementation. Examples: * `USize.decEq 123 123 = .isTrue rfl` * `(if (6 : USize) = 7 then "yes" else "no") = "no"` * `show (7 : USize) = 7 by decide`
Nat.isValidChar (n : Nat) : Prop := Or (LT.lt n 0xd800) (And (LT.lt 0xdfff n) (LT.lt n 0x110000))
abbrev
Init.Prelude
[]
Init/Prelude.lean
Nat.isValidChar
A `Nat` denotes a valid Unicode code point if it is less than `0x110000` and it is also not a surrogate code point (the range `0xd800` to `0xdfff` inclusive).
UInt32.isValidChar (n : UInt32) : Prop := n.toNat.isValidChar
abbrev
Init.Prelude
[]
Init/Prelude.lean
UInt32.isValidChar
A `UInt32` denotes a valid Unicode code point if it is less than `0x110000` and it is also not a surrogate code point (the range `0xd800` to `0xdfff` inclusive).
Char where /-- The underlying Unicode scalar value as a `UInt32`. -/ val : UInt32 /-- The value must be a legal scalar value. -/ valid : val.isValidChar
structure
Init.Prelude
[]
Init/Prelude.lean
Char
Characters are Unicode [scalar values](http://www.unicode.org/glossary/#unicode_scalar_value).
private isValidChar_UInt32 {n : Nat} (h : n.isValidChar) : LT.lt n UInt32.size := match h with | Or.inl h => Nat.lt_trans h (of_decide_eq_true rfl) | Or.inr ⟨_, h⟩ => Nat.lt_trans h (of_decide_eq_true rfl)
theorem
Init.Prelude
[]
Init/Prelude.lean
isValidChar_UInt32
null
@[extern "lean_uint32_of_nat"] Char.ofNatAux (n : @& Nat) (h : n.isValidChar) : Char where val := ⟨BitVec.ofNatLT n -- We would conventionally use `by exact` here to enter a private context, but `exact` does not -- exist here yet. (private_decl% isValidChar_UInt32 h)⟩ valid := h
def
Init.Prelude
[]
Init/Prelude.lean
Char.ofNatAux
Pack a `Nat` encoding a valid codepoint into a `Char`. This function is overridden with a native implementation.
@[noinline, match_pattern] Char.ofNat (n : Nat) : Char := dite (n.isValidChar) (fun h => Char.ofNatAux n h) (fun _ => { val := ⟨BitVec.ofNatLT 0 (of_decide_eq_true rfl)⟩, valid := Or.inl (of_decide_eq_true rfl) })
def
Init.Prelude
[]
Init/Prelude.lean
Char.ofNat
Converts a `Nat` into a `Char`. If the `Nat` does not encode a valid Unicode scalar value, `'\0'` is returned instead.
Char.ext : ∀ {c d : Char}, Eq c.val d.val → Eq c d | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
Char.ext
null
Char.val_eq_of_eq : ∀ {c d : Char}, Eq c d → Eq c.val d.val | _, _, rfl => rfl
theorem
Init.Prelude
[]
Init/Prelude.lean
Char.val_eq_of_eq
null
Char.ne_of_val_ne {c d : Char} (h : Not (Eq c.val d.val)) : Not (Eq c d) := fun h' => absurd (val_eq_of_eq h') h
theorem
Init.Prelude
[]
Init/Prelude.lean
Char.ne_of_val_ne
null
Char.val_ne_of_ne {c d : Char} (h : Not (Eq c d)) : Not (Eq c.val d.val) := fun h' => absurd (ext h') h
theorem
Init.Prelude
[]
Init/Prelude.lean
Char.val_ne_of_ne
null
Char.utf8Size (c : Char) : Nat := let v := c.val ite (LE.le v (UInt32.ofNatLT 0x7F (of_decide_eq_true rfl))) 1 (ite (LE.le v (UInt32.ofNatLT 0x7FF (of_decide_eq_true rfl))) 2 (ite (LE.le v (UInt32.ofNatLT 0xFFFF (of_decide_eq_true rfl))) 3 4))
def
Init.Prelude
[]
Init/Prelude.lean
Char.utf8Size
Returns the number of bytes required to encode this `Char` in UTF-8.
@[suggest_for Maybe, suggest_for Optional, suggest_for Nullable] Option (α : Type u) where /-- No value. -/ | none : Option α /-- Some value of type `α`. -/ | some (val : α) : Option α attribute [unbox] Option export Option (none some)
inductive
Init.Prelude
[]
Init/Prelude.lean
Option
Optional values, which are either `some` around a value from the underlying type or `none`. `Option` can represent nullable types or computations that might fail. In the codomain of a function type, it can also represent partiality.
@[macro_inline, expose] Option.getD (opt : Option α) (dflt : α) : α := match opt with | some x => x | none => dflt
def
Init.Prelude
[]
Init/Prelude.lean
Option.getD
Gets an optional value, returning a given default on `none`. This function is `@[macro_inline]`, so `dflt` will not be evaluated unless `opt` turns out to be `none`. Examples: * `(some "hello").getD "goodbye" = "hello"` * `none.getD "goodbye" = "goodbye"`
@[inline] protected Option.map (f : α → β) : Option α → Option β | some x => some (f x) | none => none
def
Init.Prelude
[]
Init/Prelude.lean
Option.map
Apply a function to an optional value, if present. From the perspective of `Option` as a container with at most one value, this is analogous to `List.map`. It can also be accessed via the `Functor Option` instance. Examples: * `(none : Option Nat).map (· + 1) = none` * `(some 3).map (· + 1) = some 4`
List (α : Type u) where /-- The empty list, usually written `[]`. -/ | nil : List α /-- The list whose first element is `head`, where `tail` is the rest of the list. Usually written `head :: tail`. -/ | cons (head : α) (tail : List α) : List α
inductive
Init.Prelude
[]
Init/Prelude.lean
List
Linked lists: ordered lists, in which each element has a reference to the next element. Most operations on linked lists take time proportional to the length of the list, because each element must be traversed to find the next element. `List α` is isomorphic to `Array α`, but they are useful for different things: * `List α` is easier for reasoning, and `Array α` is modeled as a wrapper around `List α`. * `List α` works well as a persistent data structure, when many copies of the tail are shared. When the value is not shared, `Array α` will have better performance because it can do destructive updates.
protected List.hasDecEq {α : Type u} [DecidableEq α] : (a b : List α) → Decidable (Eq a b) | nil, nil => isTrue rfl | cons _ _, nil => isFalse (fun h => List.noConfusion rfl (heq_of_eq h)) | nil, cons _ _ => isFalse (fun h => List.noConfusion rfl (heq_of_eq h)) | cons a as, cons b bs => match decEq a b with | isTrue hab => match List.hasDecEq as bs with | isTrue habs => isTrue (hab ▸ habs ▸ rfl) | isFalse nabs => isFalse (fun h => List.noConfusion rfl (heq_of_eq h) (fun _ habs => absurd (eq_of_heq habs) nabs)) | isFalse nab => isFalse (fun h => List.noConfusion rfl (heq_of_eq h) (fun hab _ => absurd (eq_of_heq hab) nab))
def
Init.Prelude
[]
Init/Prelude.lean
List.hasDecEq
Implements decidable equality for `List α`, assuming `α` has decidable equality.
List.instDecidableNilEq (a : List α) : Decidable (Eq List.nil a) := match a with | .nil => isTrue rfl | .cons _ _ => isFalse (fun h => List.noConfusion rfl (heq_of_eq h))
instance
Init.Prelude
[]
Init/Prelude.lean
List.instDecidableNilEq
Equality with `List.nil` is decidable even if the underlying type does not have decidable equality.
List.instDecidableEqNil (a : List α) : Decidable (Eq a List.nil) := match a with | .nil => isTrue rfl | .cons _ _ => isFalse (fun h => List.noConfusion rfl (heq_of_eq h))
instance
Init.Prelude
[]
Init/Prelude.lean
List.instDecidableEqNil
Equality with `List.nil` is decidable even if the underlying type does not have decidable equality.