statement stringlengths 1 8.65k | proof stringlengths 0 19.6k | type stringclasses 12
values | symbolic_name stringlengths 1 110 | library stringclasses 165
values | filename stringclasses 822
values | imports listlengths 0 19 | deps listlengths 0 64 | docstring stringlengths 0 3.64k | source_url stringclasses 1
value | commit stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|
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 | Nat.not_le_of_not_ble_eq_true | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Nat.ble",
"Nat.ble_eq_true_of_le",
"Not",
"absurd"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Nat.lt_succ_of_le {n m : Nat} : LE.le n m → LT.lt n (succ m) | succ_le_succ | theorem | Nat.lt_succ_of_le | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Nat.lt_add_one (n : Nat) : LT.lt n (HAdd.hAdd n 1) | Nat.le_refl (succ n) | theorem | Nat.lt_add_one | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.le_refl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Nat.lt_succ_self (n : Nat) : LT.lt n (succ n) | Nat.lt_add_one _ | theorem | Nat.lt_succ_self | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.lt_add_one"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.lt_of_not_le | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.lt_or_ge",
"Not"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.add_pos_right | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.not_succ_le_zero",
"Nat.zero_lt_succ"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.mul_pos | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.add_pos_right",
"Nat.not_succ_le_zero"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.pow_pos | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.mul_pos",
"Nat.zero_lt_succ"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.decLe | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"Nat",
"Nat.ble",
"Nat.le_of_ble_eq_true",
"Nat.not_le_of_not_ble_eq_true",
"dite"
] | 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` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.decLt (n m : @& Nat) : Decidable (LT.lt n m) | decLe (succ n) m | instance | Nat.decLt | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Nat"
] | 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` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.sub : (@& Nat) → (@& Nat) → Nat | | a, 0 => a
| a, succ b => pred (Nat.sub a b) | def | Nat.sub | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.ctorIdx_zero : Eq (Nat.ctorIdx 0) 0 | rfl | theorem | Nat.ctorIdx_zero | Init | src/Init/Prelude.lean | [] | [
"Eq",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.ctorIdx_succ | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Nat.ctorIdx_zero",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
instSubNat : Sub Nat | where
sub := Nat.sub | instance | instSubNat | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.sub",
"Sub"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.succ_sub_succ_eq_sub | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Nat",
"congrArg",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Nat.pred_le : ∀ (n : Nat), LE.le (Nat.pred n) n | | zero => Nat.le.refl
| succ _ => le_succ _ | theorem | Nat.pred_le | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.pred"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.sub_le | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.le_refl",
"Nat.le_trans"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.sub_lt | Init | src/Init/Prelude.lean | [] | [
"Eq.symm",
"Nat",
"Nat.lt_irrefl",
"absurd"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.div_rec_lemma | Init | src/Init/Prelude.lean | [] | [
"And",
"Nat",
"Nat.lt_of_lt_of_le"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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) | theorem | Nat.div_rec_fuel_lemma | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.le_of_lt_succ",
"Nat.lt_of_lt_of_le"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 fu... | def | Nat.div | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.lt_succ_self",
"dite"
] | 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`
* `... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.instDiv : Div Nat | ⟨Nat.div⟩ | instance | Nat.instDiv | Init | src/Init/Prelude.lean | [] | [
"Div",
"Nat"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 structu... | def | Nat.modCore | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.lt_succ_self",
"dite"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | Nat.modCoreGo_lt | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.decLe",
"Nat.lt_of_not_le",
"Nat.not_lt_zero",
"absurd",
"dite"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | theorem | Nat.modCore_lt | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.decLt",
"Nat.lt_succ_self",
"Nat.modCore",
"Nat.modCoreGo_lt",
"absurd",
"dite"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 pr... | | 0, _ => 0
| n@(succ _), m => ite (LE.le m n) (Nat.modCore n m) n | def | Nat.mod | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.modCore",
"ite"
] | 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 reduc... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.instMod : Mod Nat | ⟨Nat.mod⟩ | instance | Nat.instMod | Init | src/Init/Prelude.lean | [] | [
"Mod",
"Nat"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Nat.mod_lt | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.decLe",
"Nat.lt_of_not_le",
"Nat.modCore",
"Nat.modCore_lt",
"Nat.zero_lt_succ",
"ite"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
System.Platform.getNumBits : Unit → Subtype fun (n : Nat) => Or (Eq n 32) (Eq n 64) | fun _ => ⟨64, Or.inr rfl⟩ | opaque | System.Platform.getNumBits | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Nat",
"Or",
"Subtype",
"Unit"
] | 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. ... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
System.Platform.numBits : Nat | (getNumBits ()).val | def | System.Platform.numBits | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | The word size of the current platform, which may be 64 or 32 bits. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
System.Platform.numBits_eq : Or (Eq numBits 32) (Eq numBits 64) | (getNumBits ()).property | theorem | System.Platform.numBits_eq | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Or"
] | The word size of the current platform may be 64 or 32 bits. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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... | structure | Fin | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Fin.eq_of_val_eq {n} : ∀ {i j : Fin n}, Eq i.val j.val → Eq i j | | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl | theorem | Fin.eq_of_val_eq | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Fin",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Fin.val_eq_of_eq {n} {i j : Fin n} (h : Eq i j) : Eq i.val j.val | h ▸ rfl | theorem | Fin.val_eq_of_eq | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Fin",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Fin.decLt {n} (a b : Fin n) : Decidable (LT.lt a b) | Nat.decLt .. | instance | Fin.decLt | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Fin",
"Nat.decLt"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Fin.decLe {n} (a b : Fin n) : Decidable (LE.le a b) | Nat.decLe .. | instance | Fin.decLe | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Fin",
"Nat.decLe"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Fin.Internal.ofNat (n : Nat) (hn : LT.lt 0 n) (a : Nat) : Fin n | ⟨HMod.hMod a n, Nat.mod_lt _ hn⟩ | def | Fin.Internal.ofNat | Init | src/Init/Prelude.lean | [] | [
"Fin",
"Nat",
"Nat.mod_lt"
] | Returns `a` modulo `n` as a `Fin n`.
This function exists for bootstrapping purposes. Use `Fin.ofNat` instead. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 : F... | structure | BitVec | Init | src/Init/Prelude.lean | [] | [
"Fin",
"Nat"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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))) | def | BitVec.decEq | Init | src/Init/Prelude.lean | [] | [
"BitVec",
"Decidable",
"Eq",
"absurd",
"dite",
"eq_of_heq",
"heq_of_eq",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
BitVec.ofNatLT {w : Nat} (i : Nat) (p : LT.lt i (hPow 2 w)) : BitVec w | where
toFin := ⟨i, p⟩ | def | BitVec.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec",
"Nat"
] | The `BitVec` with value `i`, given a proof that `i < 2^w`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | BitVec.ofNat | Init | src/Init/Prelude.lean | [] | [
"BitVec",
"Fin.Internal.ofNat",
"Nat",
"Nat.pow_pos",
"Nat.zero_lt_succ"
] | The bitvector with value `i mod 2^n`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
BitVec.toNat (x : BitVec w) : Nat | x.toFin.val | def | BitVec.toNat | Init | src/Init/Prelude.lean | [] | [
"BitVec",
"Nat"
] | Return the underlying `Nat` that represents a bitvector.
This is O(1) because `BitVec` is a (zero-cost) wrapper around a `Nat`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.size : Nat | 256 | abbrev | UInt8.size | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | The number of distinct values representable by `UInt8`, that is, `2^8 = 256`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | structure | UInt8 | Init | src/Init/Prelude.lean | [] | [
"BitVec"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
UInt8.ofNatLT (n : @& Nat) (h : LT.lt n UInt8.size) : UInt8 | where
toBitVec := BitVec.ofNatLT n h | def | UInt8.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec.ofNatLT",
"Nat",
"UInt8",
"UInt8.size"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.ofNat (n : @& Nat) : UInt8 | ⟨BitVec.ofNat 8 n⟩ | def | UInt8.ofNat | Init | src/Init/Prelude.lean | [] | [
"Nat",
"UInt8"
] | 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` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | UInt8.decEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"UInt8",
"absurd",
"dite",
"rfl"
] | 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 deci... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.lt (a b : UInt8) : Prop | LT.lt a.toBitVec b.toBitVec | def | UInt8.lt | Init | src/Init/Prelude.lean | [] | [
"UInt8"
] | Strict inequality of 8-bit unsigned integers, defined as inequality of the corresponding
natural numbers. Usually accessed via the `<` operator. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.le (a b : UInt8) : Prop | LE.le a.toBitVec b.toBitVec | def | UInt8.le | Init | src/Init/Prelude.lean | [] | [
"UInt8"
] | Non-strict inequality of 8-bit unsigned integers, defined as inequality of the corresponding
natural numbers. Usually accessed via the `≤` operator. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.decLt (a b : UInt8) : Decidable (LT.lt a b) | inferInstanceAs (Decidable (LT.lt a.toBitVec b.toBitVec)) | def | UInt8.decLt | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"UInt8"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt8.decLe (a b : UInt8) : Decidable (LE.le a b) | inferInstanceAs (Decidable (LE.le a.toBitVec b.toBitVec)) | def | UInt8.decLe | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"UInt8"
] | 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")... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt16.size : Nat | 65536 | abbrev | UInt16.size | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | The number of distinct values representable by `UInt16`, that is, `2^16 = 65536`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | structure | UInt16 | Init | src/Init/Prelude.lean | [] | [
"BitVec"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
UInt16.ofNatLT (n : @& Nat) (h : LT.lt n UInt16.size) : UInt16 | where
toBitVec := BitVec.ofNatLT n h | def | UInt16.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec.ofNatLT",
"Nat",
"UInt16",
"UInt16.size"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | UInt16.decEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"UInt16",
"absurd",
"dite",
"rfl"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt32.size : Nat | 4294967296 | abbrev | UInt32.size | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | The number of distinct values representable by `UInt32`, that is, `2^32 = 4294967296`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | structure | UInt32 | Init | src/Init/Prelude.lean | [] | [
"BitVec"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
UInt32.ofNatLT (n : @& Nat) (h : LT.lt n UInt32.size) : UInt32 | where
toBitVec := BitVec.ofNatLT n h | def | UInt32.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec.ofNatLT",
"Nat",
"UInt32",
"UInt32.size"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt32.toNat (n : UInt32) : Nat | n.toBitVec.toNat | def | UInt32.toNat | Init | src/Init/Prelude.lean | [] | [
"Nat",
"UInt32"
] | Converts a 32-bit unsigned integer to an arbitrary-precision natural number.
This function is overridden at runtime with an efficient implementation. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | UInt32.decEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"UInt32",
"absurd",
"dite",
"rfl"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt32.decLt (a b : UInt32) : Decidable (LT.lt a b) | inferInstanceAs (Decidable (LT.lt a.toBitVec b.toBitVec)) | def | UInt32.decLt | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"UInt32"
] | 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") = ... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt32.decLe (a b : UInt32) : Decidable (LE.le a b) | inferInstanceAs (Decidable (LE.le a.toBitVec b.toBitVec)) | def | UInt32.decLe | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"UInt32"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt64.size : Nat | 18446744073709551616 | abbrev | UInt64.size | Init | src/Init/Prelude.lean | [] | [
"Nat"
] | The number of distinct values representable by `UInt64`, that is, `2^64 = 18446744073709551616`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | structure | UInt64 | Init | src/Init/Prelude.lean | [] | [
"BitVec"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
UInt64.ofNatLT (n : @& Nat) (h : LT.lt n UInt64.size) : UInt64 | where
toBitVec := BitVec.ofNatLT n h | def | UInt64.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec.ofNatLT",
"Nat",
"UInt64",
"UInt64.size"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | UInt64.decEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"UInt64",
"absurd",
"dite",
"rfl"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
USize.size : Nat | (hPow 2 System.Platform.numBits) | abbrev | USize.size | Init | src/Init/Prelude.lean | [] | [
"Nat",
"System.Platform.numBits"
] | The number of distinct values representable by `USize`, that is, `2^System.Platform.numBits`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | USize.size_eq | Init | src/Init/Prelude.lean | [] | [
"Eq",
"Or",
"System.Platform.numBits",
"System.Platform.numBits_eq",
"USize.size",
"of_decide_eq_true",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | USize.size_pos | Init | src/Init/Prelude.lean | [] | [
"USize.size",
"USize.size_eq",
"of_decide_eq_true",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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.Pla... | structure | USize | Init | src/Init/Prelude.lean | [] | [
"BitVec",
"System.Platform.numBits"
] | 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`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
USize.ofNatLT (n : @& Nat) (h : LT.lt n USize.size) : USize | where
toBitVec := BitVec.ofNatLT n h | def | USize.ofNatLT | Init | src/Init/Prelude.lean | [] | [
"BitVec.ofNatLT",
"Nat",
"USize",
"USize.size"
] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | USize.decEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"USize",
"absurd",
"dite",
"rfl"
] | 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... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Nat.isValidChar (n : Nat) : Prop | Or (LT.lt n 0xd800) (And (LT.lt 0xdfff n) (LT.lt n 0x110000)) | abbrev | Nat.isValidChar | Init | src/Init/Prelude.lean | [] | [
"And",
"Nat",
"Or"
] | 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). | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
UInt32.isValidChar (n : UInt32) : Prop | n.toNat.isValidChar | abbrev | UInt32.isValidChar | Init | src/Init/Prelude.lean | [] | [
"UInt32"
] | 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). | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Char where
/-- The underlying Unicode scalar value as a `UInt32`. -/
val : UInt32
/-- The value must be a legal scalar value. -/
valid : val.isValidChar
grind_pattern Char.valid => self.val | structure | Char | Init | src/Init/Prelude.lean | [] | [
"UInt32"
] | Characters are Unicode [scalar values](http://www.unicode.org/glossary/#unicode_scalar_value). | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | isValidChar_UInt32 | Init | src/Init/Prelude.lean | [] | [
"Nat",
"Nat.lt_trans",
"UInt32.size",
"of_decide_eq_true",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Char.ofNatAux | Init | src/Init/Prelude.lean | [] | [
"Char",
"Nat",
"isValidChar_UInt32"
] | Pack a `Nat` encoding a valid codepoint into a `Char`.
This function is overridden with a native implementation. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | Char.ofNat | Init | src/Init/Prelude.lean | [] | [
"Char",
"Char.ofNatAux",
"Nat",
"dite",
"of_decide_eq_true",
"rfl"
] | Converts a `Nat` into a `Char`. If the `Nat` does not encode a valid Unicode scalar value, `'\0'` is
returned instead. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Char.ext : ∀ {c d : Char}, Eq c.val d.val → Eq c d | | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl | theorem | Char.ext | Init | src/Init/Prelude.lean | [] | [
"Char",
"Eq",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Char.val_eq_of_eq : ∀ {c d : Char}, Eq c d → Eq c.val d.val | | _, _, rfl => rfl | theorem | Char.val_eq_of_eq | Init | src/Init/Prelude.lean | [] | [
"Char",
"Eq",
"rfl"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Char.ne_of_val_ne | Init | src/Init/Prelude.lean | [] | [
"Char",
"Eq",
"Not",
"absurd"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Char.val_ne_of_ne | Init | src/Init/Prelude.lean | [] | [
"Char",
"Eq",
"Not",
"absurd"
] | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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 | Char.utf8Size | Init | src/Init/Prelude.lean | [] | [
"Char",
"Nat",
"UInt32.ofNatLT",
"ite",
"of_decide_eq_true",
"rfl"
] | Returns the number of bytes required to encode this `Char` in UTF-8. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Option (α : Type u) where
/-- No value. -/
| none : Option α
/-- Some value of type `α`. -/
| some (val : α) : Option α | inductive | Option | Init | src/Init/Prelude.lean | [] | [] | 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. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
Option.getD (opt : Option α) (dflt : α) : α | match opt with
| some x => x
| none => dflt | def | Option.getD | Init | src/Init/Prelude.lean | [] | [
"Option"
] | 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"` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Option.map (f : α → β) : Option α → Option β | | some x => some (f x)
| none => none | def | Option.map | Init | src/Init/Prelude.lean | [] | [
"Option"
] | 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` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | List | Init | src/Init/Prelude.lean | [] | [] | 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:
* `L... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 | |
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
| ... | def | List.hasDecEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"DecidableEq",
"Eq",
"List",
"absurd",
"decEq",
"eq_of_heq",
"heq_of_eq",
"rfl"
] | Implements decidable equality for `List α`, assuming `α` has decidable equality. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | List.instDecidableNilEq | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"List",
"heq_of_eq",
"rfl"
] | Equality with `List.nil` is decidable even if the underlying type does not have decidable equality. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
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 | List.instDecidableEqNil | Init | src/Init/Prelude.lean | [] | [
"Decidable",
"Eq",
"List",
"heq_of_eq",
"rfl"
] | Equality with `List.nil` is decidable even if the underlying type does not have decidable equality. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.length : List α → Nat | | nil => 0
| cons _ as => HAdd.hAdd (length as) 1 | def | List.length | Init | src/Init/Prelude.lean | [] | [
"List",
"Nat"
] | The length of a list.
This function is overridden in the compiler to `lengthTR`, which uses constant stack space.
Examples:
* `([] : List String).length = 0`
* `["green", "brown"].length = 2` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.lengthTRAux : List α → Nat → Nat | | nil, n => n
| cons _ as, n => lengthTRAux as (Nat.succ n) | def | List.lengthTRAux | Init | src/Init/Prelude.lean | [] | [
"List",
"Nat"
] | Auxiliary function for `List.lengthTR`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.lengthTR (as : List α) : Nat | lengthTRAux as 0 | def | List.lengthTR | Init | src/Init/Prelude.lean | [] | [
"List",
"Nat"
] | The length of a list.
This is a tail-recursive version of `List.length`, used to implement `List.length` without running
out of stack space.
Examples:
* `([] : List String).lengthTR = 0`
* `["green", "brown"].lengthTR = 2` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.get {α : Type u} : (as : List α) → Fin as.length → α | | cons a _, ⟨0, _⟩ => a
| cons _ as, ⟨Nat.succ i, h⟩ => get as ⟨i, Nat.le_of_succ_le_succ h⟩ | def | List.get | Init | src/Init/Prelude.lean | [] | [
"Fin",
"List",
"Nat.le_of_succ_le_succ"
] | Returns the element at the provided index, counting from `0`.
In other words, for `i : Fin as.length`, `as.get i` returns the `i`'th element of the list `as`.
Because the index is a `Fin` bounded by the list's length, the index will never be out of bounds.
Examples:
* `["spring", "summer", "fall", "winter"].get (2 :... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.set : (l : List α) → (n : Nat) → (a : α) → List α | | cons _ as, 0, b => cons b as
| cons a as, Nat.succ n, b => cons a (set as n b)
| nil, _, _ => nil | def | List.set | Init | src/Init/Prelude.lean | [] | [
"List",
"Nat"
] | Replaces the value at (zero-based) index `n` in `l` with `a`. If the index is out of bounds, then
the list is returned unmodified.
Examples:
* `["water", "coffee", "soda", "juice"].set 1 "tea" = ["water", "tea", "soda", "juice"]`
* `["water", "coffee", "soda", "juice"].set 4 "tea" = ["water", "coffee", "soda", "juice"... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.foldl {α : Type u} {β : Type v} (f : α → β → α) : (init : α) → List β → α | | a, nil => a
| a, cons b l => foldl f (f a b) l | def | List.foldl | Init | src/Init/Prelude.lean | [] | [
"List",
"foldl"
] | Folds a function over a list from the left, accumulating a value starting with `init`. The
accumulated value is combined with the each element of the list in order, using `f`.
Examples:
* `[a, b, c].foldl f z = f (f (f z a) b) c`
* `[1, 2, 3].foldl (· ++ toString ·) "" = "123"`
* `[1, 2, 3].foldl (s!"({·} {·})") "... | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.concat {α : Type u} : List α → α → List α | | nil, b => cons b nil
| cons a as, b => cons a (concat as b) | def | List.concat | Init | src/Init/Prelude.lean | [] | [
"List"
] | Adds an element to the *end* of a list.
The added element is the last element of the resulting list.
Examples:
* `List.concat ["red", "yellow"] "green" = ["red", "yellow", "green"]`
* `List.concat [1, 2, 3] 4 = [1, 2, 3, 4]`
* `List.concat [] () = [()]` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.append : (xs ys : List α) → List α | | nil, bs => bs
| cons a as, bs => cons a (List.append as bs) | def | List.append | Init | src/Init/Prelude.lean | [] | [
"List"
] | Appends two lists. Normally used via the `++` operator.
Appending lists takes time proportional to the length of the first list: `O(|xs|)`.
Examples:
* `[1, 2, 3] ++ [4, 5] = [1, 2, 3, 4, 5]`.
* `[] ++ [4, 5] = [4, 5]`.
* `[1, 2, 3] ++ [] = [1, 2, 3]`. | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.flatten : List (List α) → List α | | nil => nil
| cons l L => List.append l (flatten L) | def | List.flatten | Init | src/Init/Prelude.lean | [] | [
"List",
"List.append"
] | Concatenates a list of lists into a single list, preserving the order of the elements.
`O(|flatten L|)`.
Examples:
* `[["a"], ["b", "c"]].flatten = ["a", "b", "c"]`
* `[["a"], [], ["b", "c"], ["d", "e", "f"]].flatten = ["a", "b", "c", "d", "e", "f"]` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
List.map (f : α → β) : (l : List α) → List β | | nil => nil
| cons a as => cons (f a) (map f as) | def | List.map | Init | src/Init/Prelude.lean | [] | [
"List"
] | Applies a function to each element of the list, returning the resulting list of values.
`O(|l|)`.
Examples:
* `[a, b, c].map f = [f a, f b, f c]`
* `[].map Nat.succ = []`
* `["one", "two", "three"].map (·.length) = [3, 3, 5]`
* `["one", "two", "three"].map (·.reverse) = ["eno", "owt", "eerht"]` | https://github.com/leanprover/lean4 | d265d1ca745e7741a7e7f7366c22ce9c9dda57b6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.