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 ⌀ |
|---|---|---|---|---|---|---|
BEq (α : Type u) where
/-- Boolean equality, notated as `a == b`. -/
beq : α → α → Bool
open BEq (beq) | class | Init.Prelude | [] | Init/Prelude.lean | BEq | `BEq α` is a typeclass for supplying a boolean-valued equality relation on
`α`, notated as `a == b`. Unlike `DecidableEq α` (which uses `a = b`), this
is `Bool` valued instead of `Prop` valued, and it also does not have any
axioms like being reflexive or agreeing with `=`. It is mainly intended for
programming applications. See `LawfulBEq` for a version that requires that
`==` and `=` coincide.
Typically we prefer to put the "more variable" term on the left,
and the "more constant" term on the right. |
@[macro_inline] dite {α : Sort u} (c : Prop) [h : Decidable c] (t : c → α) (e : Not c → α) : α :=
h.casesOn e t
/-! # if-then-else -/ | def | Init.Prelude | [] | Init/Prelude.lean | dite | "Dependent" if-then-else, normally written via the notation `if h : c then t(h) else e(h)`,
is sugar for `dite c (fun h => t(h)) (fun h => e(h))`, and it is the same as
`if c then t else e` except that `t` is allowed to depend on a proof `h : c`,
and `e` can depend on `h : ¬c`. (Both branches use the same name for the hypothesis,
even though it has different types in the two cases.)
We use this to be able to communicate the if-then-else condition to the branches.
For example, `Array.get arr i h` expects a proof `h : i < arr.size` in order to
avoid a bounds check, so you can write `if h : i < arr.size then arr.get i h else ...`
to avoid the bounds check inside the if branch. (Of course in this case we have only
lifted the check into an explicit `if`, but we could also use this proof multiple times
or derive `i < arr.size` from some other proposition that we are checking in the `if`.) |
@[macro_inline] ite {α : Sort u} (c : Prop) [h : Decidable c] (t e : α) : α :=
h.casesOn (fun _ => e) (fun _ => t)
@[macro_inline] instance {p q} [dp : Decidable p] [dq : Decidable q] : Decidable (And p q) :=
match dp with
| isTrue hp =>
match dq with
| isTrue hq => isTrue ⟨hp, hq⟩
| isFalse hq => isFalse (fun h => hq (And.right h))
| isFalse hp =>
isFalse (fun h => hp (And.left h))
@[macro_inline] instance [dp : Decidable p] [dq : Decidable q] : Decidable (Or p q) :=
match dp with
| isTrue hp => isTrue (Or.inl hp)
| isFalse hp =>
match dq with
| isTrue hq => isTrue (Or.inr hq)
| isFalse hq =>
isFalse fun h => match h with
| Or.inl h => hp h
| Or.inr h => hq h
@[inline] | def | Init.Prelude | [] | Init/Prelude.lean | ite | `if c then t else e` is notation for `ite c t e`, "if-then-else", which decides to
return `t` or `e` depending on whether `c` is true or false. The explicit argument
`c : Prop` does not have any actual computational content, but there is an additional
`[Decidable c]` argument synthesized by typeclass inference which actually
determines how to evaluate `c` to true or false. Write `if h : c then t else e`
instead for a "dependent if-then-else" `dite`, which allows `t`/`e` to use the fact
that `c` is true/false.
-/
/-
Because Lean uses a strict (call-by-value) evaluation strategy, the signature of this
function is problematic in that it would require `t` and `e` to be evaluated before
calling the `ite` function, which would cause both sides of the `if` to be evaluated.
Even if the result is discarded, this would be a big performance problem,
and is undesirable for users in any case. To resolve this, `ite` is marked as
`@[macro_inline]`, which means that it is unfolded during code generation, and
the definition of the function uses `fun _ => t` and `fun _ => e` so this recovers
the expected "lazy" behavior of `if`: the `t` and `e` arguments delay evaluation
until `c` is known. |
@[macro_inline] cond {α : Sort u} (c : Bool) (x y : α) : α :=
match c with
| true => x
| false => y | def | Init.Prelude | [] | Init/Prelude.lean | cond | The conditional function.
`cond c x y` is the same as `if c then x else y`, but optimized for a Boolean condition rather than
a decidable proposition. It can also be written using the notation `bif c then x else y`.
Just like `ite`, `cond` is declared `@[macro_inline]`, which causes applications of `cond` to be
unfolded. As a result, `x` and `y` are not evaluated at runtime until one of them is selected, and
only the selected branch is evaluated. |
@[macro_inline]
protected Bool.dcond {α : Sort u} (c : Bool) (x : Eq c true → α) (y : Eq c false → α) : α :=
match c with
| true => x rfl
| false => y rfl | def | Init.Prelude | [] | Init/Prelude.lean | Bool.dcond | The dependent conditional function, in which each branch is provided with a local assumption about
the condition's value. This allows the value to be used in proofs as well as for control flow.
`dcond c (fun h => x) (fun h => y)` is the same as `if h : c then x else y`, but optimized for a
Boolean condition rather than a decidable proposition. Unlike the non-dependent version `cond`,
there is no special notation for `dcond`.
Just like `ite`, `dite`, and `cond`, `dcond` is declared `@[macro_inline]`, which causes
applications of `dcond` to be unfolded. As a result, `x` and `y` are not evaluated at runtime until
one of them is selected, and only the selected branch is evaluated. `dcond` is intended for
metaprogramming use, rather than for use in verified programs, so behavioral lemmas are not
provided. |
@[macro_inline] Bool.or (x y : Bool) : Bool :=
match x with
| true => true
| false => y | def | Init.Prelude | [] | Init/Prelude.lean | Bool.or | Boolean “or”, also known as disjunction. `or x y` can be written `x || y`.
The corresponding propositional connective is `Or : Prop → Prop → Prop`, written with the `∨`
operator.
The Boolean `or` is a `@[macro_inline]` function in order to give it short-circuiting evaluation:
if `x` is `true` then `y` is not evaluated at runtime. |
@[macro_inline] Bool.and (x y : Bool) : Bool :=
match x with
| false => false
| true => y | def | Init.Prelude | [] | Init/Prelude.lean | Bool.and | Boolean “and”, also known as conjunction. `and x y` can be written `x && y`.
The corresponding propositional connective is `And : Prop → Prop → Prop`, written with the `∧`
operator.
The Boolean `and` is a `@[macro_inline]` function in order to give it short-circuiting evaluation:
if `x` is `false` then `y` is not evaluated at runtime. |
@[inline] Bool.not : Bool → Bool
| true => false
| false => true
export Bool (or and not)
set_option genCtorIdx false in | def | Init.Prelude | [] | Init/Prelude.lean | Bool.not | Boolean negation, also known as Boolean complement. `not x` can be written `!x`.
This is a function that maps the value `true` to `false` and the value `false` to `true`. The
propositional connective is `Not : Prop → Prop`. |
@[suggest_for ℕ]
Nat where
/--
Zero, the smallest natural number.
Using `Nat.zero` explicitly should usually be avoided in favor of the literal `0`, which is the
[simp normal form](lean-manual://section/simp-normal-forms).
-/
| zero : Nat
/--
The successor of a natural number `n`.
Using `Nat.succ n` should usually be avoided in favor of `n + 1`, which is the [simp normal
form](lean-manual://section/simp-normal-forms).
-/
| succ (n : Nat) : Nat | inductive | Init.Prelude | [] | Init/Prelude.lean | Nat | The natural numbers, starting at zero.
This type is special-cased by both the kernel and the compiler, and overridden with an efficient
implementation. Both use a fast arbitrary-precision arithmetic library (usually
[GMP](https://gmplib.org/)); at runtime, `Nat` values that are sufficiently small are unboxed. |
OfNat (α : Type u) (_ : Nat) where
/-- The `OfNat.ofNat` function is automatically inserted by the parser when
the user writes a numeric literal like `1 : α`. Implementations of this
typeclass can therefore customize the behavior of `n : α` based on `n` and
`α`. -/
ofNat : α
@[default_instance 100] /- low prio -/ | class | Init.Prelude | [] | Init/Prelude.lean | OfNat | The class `OfNat α n` powers the numeric literal parser. If you write
`37 : α`, Lean will attempt to synthesize `OfNat α 37`, and will generate
the term `(OfNat.ofNat 37 : α)`.
There is a bit of infinite regress here since the desugaring apparently
still contains a literal `37` in it. The type of expressions contains a
primitive constructor for "raw natural number literals", which you can directly
access using the macro `nat_lit 37`. Raw number literals are always of type `Nat`.
So it would be more correct to say that Lean looks for an instance of
`OfNat α (nat_lit 37)`, and it generates the term `(OfNat.ofNat (nat_lit 37) : α)`. |
instOfNatNat (n : Nat) : OfNat Nat n where
ofNat := n | instance | Init.Prelude | [] | Init/Prelude.lean | instOfNatNat | null |
LE (α : Type u) where
/-- The less-equal relation: `x ≤ y` -/
le : α → α → Prop | class | Init.Prelude | [] | Init/Prelude.lean | LE | `LE α` is the typeclass which supports the notation `x ≤ y` where `x y : α`. |
LT (α : Type u) where
/-- The less-than relation: `x < y` -/
lt : α → α → Prop | class | Init.Prelude | [] | Init/Prelude.lean | LT | `LT α` is the typeclass which supports the notation `x < y` where `x y : α`. |
@[reducible] GE.ge {α : Type u} [LE α] (a b : α) : Prop := LE.le b a | def | Init.Prelude | [] | Init/Prelude.lean | GE.ge | `a ≥ b` is an abbreviation for `b ≤ a`. |
@[reducible] GT.gt {α : Type u} [LT α] (a b : α) : Prop := LT.lt b a | def | Init.Prelude | [] | Init/Prelude.lean | GT.gt | `a > b` is an abbreviation for `b < a`. |
DecidableLT (α : Type u) [LT α] := DecidableRel (LT.lt : α → α → Prop) | abbrev | Init.Prelude | [] | Init/Prelude.lean | DecidableLT | Abbreviation for `DecidableRel (· < · : α → α → Prop)`. |
DecidableLE (α : Type u) [LE α] := DecidableRel (LE.le : α → α → Prop) | abbrev | Init.Prelude | [] | Init/Prelude.lean | DecidableLE | Abbreviation for `DecidableRel (· ≤ · : α → α → Prop)`. |
Max (α : Type u) where
/-- Returns the greater of its two arguments. -/
max : α → α → α
export Max (max) | class | Init.Prelude | [] | Init/Prelude.lean | Max | An overloaded operation to find the greater of two values of type `α`. |
Min (α : Type u) where
/-- Returns the lesser of its two arguments. -/
min : α → α → α
export Min (min) | class | Init.Prelude | [] | Init/Prelude.lean | Min | Constructs a `Max` instance from a decidable `≤` operation.
-/
-- Marked inline so that `min x y + max x y` can be optimized to a single branch.
@[inline]
def maxOfLe [LE α] [DecidableRel (@LE.le α _)] : Max α where
max x y := ite (LE.le x y) y x
/--
An overloaded operation to find the lesser of two values of type `α`. |
Trans (r : α → β → Sort u) (s : β → γ → Sort v) (t : outParam (α → γ → Sort w)) where
/-- Compose two proofs by transitivity, generalized over the relations involved. -/
trans : r a b → s b c → t a c
export Trans (trans) | class | Init.Prelude | [] | Init/Prelude.lean | Trans | Constructs a `Min` instance from a decidable `≤` operation.
-/
-- Marked inline so that `min x y + max x y` can be optimized to a single branch.
@[inline]
def minOfLe [LE α] [DecidableRel (@LE.le α _)] : Min α where
min x y := ite (LE.le x y) x y
/--
Transitive chaining of proofs, used e.g. by `calc`.
It takes two relations `r` and `s` as "input", and produces an "output"
relation `t`, with the property that `r a b` and `s b c` implies `t a c`.
The `calc` tactic uses this so that when it sees a chain with `a ≤ b` and `b < c`
it knows that this should be a proof of `a < c` because there is an instance
`Trans (·≤·) (·<·) (·<·)`. |
HAdd (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a + b` computes the sum of `a` and `b`.
The meaning of this notation is type-dependent. -/
hAdd : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HAdd | The notation typeclass for heterogeneous addition.
This enables the notation `a + b : γ` where `a : α`, `b : β`. |
HSub (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a - b` computes the difference of `a` and `b`.
The meaning of this notation is type-dependent.
* For natural numbers, this operator saturates at 0: `a - b = 0` when `a ≤ b`. -/
hSub : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HSub | The notation typeclass for heterogeneous subtraction.
This enables the notation `a - b : γ` where `a : α`, `b : β`. |
HMul (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a * b` computes the product of `a` and `b`.
The meaning of this notation is type-dependent. -/
hMul : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HMul | The notation typeclass for heterogeneous multiplication.
This enables the notation `a * b : γ` where `a : α`, `b : β`. |
HDiv (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a / b` computes the result of dividing `a` by `b`.
The meaning of this notation is type-dependent.
* For most types like `Nat`, `Int`, `Rat`, `Real`, `a / 0` is defined to be `0`.
* For `Nat`, `a / b` rounds downwards.
* For `Int`, `a / b` rounds downwards if `b` is positive or upwards if `b` is negative.
It is implemented as `Int.ediv`, the unique function satisfying
`a % b + b * (a / b) = a` and `0 ≤ a % b < natAbs b` for `b ≠ 0`.
Other rounding conventions are available using the functions
`Int.fdiv` (floor rounding) and `Int.tdiv` (truncation rounding).
* For `Float`, `a / 0` follows the IEEE 754 semantics for division,
usually resulting in `inf` or `nan`. -/
hDiv : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HDiv | The notation typeclass for heterogeneous division.
This enables the notation `a / b : γ` where `a : α`, `b : β`. |
HMod (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a % b` computes the remainder upon dividing `a` by `b`.
The meaning of this notation is type-dependent.
* For `Nat` and `Int` it satisfies `a % b + b * (a / b) = a`,
and `a % 0` is defined to be `a`. -/
hMod : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HMod | The notation typeclass for heterogeneous modulo / remainder.
This enables the notation `a % b : γ` where `a : α`, `b : β`. |
HPow (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a ^ b` computes `a` to the power of `b`.
The meaning of this notation is type-dependent. -/
hPow : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HPow | The notation typeclass for heterogeneous exponentiation.
This enables the notation `a ^ b : γ` where `a : α`, `b : β`. |
HSMul (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a • b` computes the product of `a` and `b`.
The meaning of this notation is type-dependent, but it is intended to be used for left actions. -/
hSMul : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HSMul | The notation typeclass for heterogeneous scalar multiplication.
This enables the notation `a • b : γ` where `a : α`, `b : β`.
It is assumed to represent a left action in some sense.
The notation `a • b` is augmented with a macro (below) to have it elaborate as a left action.
Only the `b` argument participates in the elaboration algorithm: the algorithm uses the type of `b`
when calculating the type of the surrounding arithmetic expression
and it tries to insert coercions into `b` to get some `b'`
such that `a • b'` has the same type as `b'`.
See the module documentation near the macro for more details. |
HAppend (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a ++ b` is the result of concatenation of `a` and `b`, usually read "append".
The meaning of this notation is type-dependent. -/
hAppend : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HAppend | The notation typeclass for heterogeneous append.
This enables the notation `a ++ b : γ` where `a : α`, `b : β`. |
HOrElse (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a <|> b` executes `a` and returns the result, unless it fails in which
case it executes and returns `b`. Because `b` is not always executed, it
is passed as a thunk so it can be forced only when needed.
The meaning of this notation is type-dependent. -/
hOrElse : α → (Unit → β) → γ | class | Init.Prelude | [] | Init/Prelude.lean | HOrElse | The typeclass behind the notation `a <|> b : γ` where `a : α`, `b : β`.
Because `b` is "lazy" in this notation, it is passed as `Unit → β` to the
implementation so it can decide when to evaluate it. |
HAndThen (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a >> b` executes `a`, ignores the result, and then executes `b`.
If `a` fails then `b` is not executed. Because `b` is not always executed, it
is passed as a thunk so it can be forced only when needed.
The meaning of this notation is type-dependent. -/
hAndThen : α → (Unit → β) → γ | class | Init.Prelude | [] | Init/Prelude.lean | HAndThen | The typeclass behind the notation `a >> b : γ` where `a : α`, `b : β`.
Because `b` is "lazy" in this notation, it is passed as `Unit → β` to the
implementation so it can decide when to evaluate it. |
HAnd (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a &&& b` computes the bitwise AND of `a` and `b`.
The meaning of this notation is type-dependent. -/
hAnd : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HAnd | The typeclass behind the notation `a &&& b : γ` where `a : α`, `b : β`. |
HXor (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a ^^^ b` computes the bitwise XOR of `a` and `b`.
The meaning of this notation is type-dependent. -/
hXor : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HXor | The typeclass behind the notation `a ^^^ b : γ` where `a : α`, `b : β`. |
HOr (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a ||| b` computes the bitwise OR of `a` and `b`.
The meaning of this notation is type-dependent. -/
hOr : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HOr | The typeclass behind the notation `a ||| b : γ` where `a : α`, `b : β`. |
HShiftLeft (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a <<< b` computes `a` shifted to the left by `b` places.
The meaning of this notation is type-dependent.
* On `Nat`, this is equivalent to `a * 2 ^ b`.
* On `UInt8` and other fixed width unsigned types, this is the same but
truncated to the bit width. -/
hShiftLeft : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HShiftLeft | The typeclass behind the notation `a <<< b : γ` where `a : α`, `b : β`. |
HShiftRight (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- `a >>> b` computes `a` shifted to the right by `b` places.
The meaning of this notation is type-dependent.
* On `Nat` and fixed width unsigned types like `UInt8`,
this is equivalent to `a / 2 ^ b`. -/
hShiftRight : α → β → γ | class | Init.Prelude | [] | Init/Prelude.lean | HShiftRight | The typeclass behind the notation `a >>> b : γ` where `a : α`, `b : β`. |
Zero (α : Type u) where
/-- The zero element of the type. -/
zero : α | class | Init.Prelude | [] | Init/Prelude.lean | Zero | A type with a zero element. |
One (α : Type u) where
/-- The "one" element of the type. -/
one : α | class | Init.Prelude | [] | Init/Prelude.lean | One | A type with a "one" element. |
Add (α : Type u) where
/-- `a + b` computes the sum of `a` and `b`. See `HAdd`. -/
add : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Add | The homogeneous version of `HAdd`: `a + b : α` where `a b : α`. |
Sub (α : Type u) where
/-- `a - b` computes the difference of `a` and `b`. See `HSub`. -/
sub : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Sub | The homogeneous version of `HSub`: `a - b : α` where `a b : α`. |
Mul (α : Type u) where
/-- `a * b` computes the product of `a` and `b`. See `HMul`. -/
mul : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Mul | The homogeneous version of `HMul`: `a * b : α` where `a b : α`. |
Neg (α : Type u) where
/-- `-a` computes the negative or opposite of `a`.
The meaning of this notation is type-dependent. -/
neg : α → α | class | Init.Prelude | [] | Init/Prelude.lean | Neg | The notation typeclass for negation.
This enables the notation `-a : α` where `a : α`. |
Div (α : Type u) where
/-- `a / b` computes the result of dividing `a` by `b`. See `HDiv`. -/
div : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Div | The homogeneous version of `HDiv`: `a / b : α` where `a b : α`. |
Inv (α : Type u) where
/-- `a⁻¹` computes the inverse of `a`.
The meaning of this notation is type-dependent. -/
inv : α → α | class | Init.Prelude | [] | Init/Prelude.lean | Inv | The notation typeclass for inverses.
This enables the notation `a⁻¹ : α` where `a : α`. |
Mod (α : Type u) where
/-- `a % b` computes the remainder upon dividing `a` by `b`. See `HMod`. -/
mod : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Mod | The homogeneous version of `HMod`: `a % b : α` where `a b : α`. |
Dvd (α : Type _) where
/-- Divisibility. `a ∣ b` (typed as `\|`) means that there is some `c` such that `b = a * c`. -/
dvd : α → α → Prop | class | Init.Prelude | [] | Init/Prelude.lean | Dvd | Notation typeclass for the `∣` operation (typed as `\|`), which represents divisibility. |
Pow (α : Type u) (β : Type v) where
/-- `a ^ b` computes `a` to the power of `b`. See `HPow`. -/
pow : α → β → α | class | Init.Prelude | [] | Init/Prelude.lean | Pow | The homogeneous version of `HPow`: `a ^ b : α` where `a : α`, `b : β`.
(The right argument is not the same as the left since we often want this even
in the homogeneous case.)
Types can choose to subscribe to particular defaulting behavior by providing
an instance to either `NatPow` or `HomogeneousPow`:
- `NatPow` is for types whose exponents is preferentially a `Nat`.
- `HomogeneousPow` is for types whose base and exponent are preferentially the same. |
NatPow (α : Type u) where
/-- `a ^ n` computes `a` to the power of `n` where `n : Nat`. See `Pow`. -/
protected pow : α → Nat → α | class | Init.Prelude | [] | Init/Prelude.lean | NatPow | The homogeneous version of `Pow` where the exponent is a `Nat`.
The purpose of this class is that it provides a default `Pow` instance,
which can be used to specialize the exponent to `Nat` during elaboration.
For example, if `x ^ 2` should preferentially elaborate with `2 : Nat` then `x`'s type should
provide an instance for this class. |
HomogeneousPow (α : Type u) where
/-- `a ^ b` computes `a` to the power of `b` where `a` and `b` both have the same type. -/
protected pow : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | HomogeneousPow | The completely homogeneous version of `Pow` where the exponent has the same type as the base.
The purpose of this class is that it provides a default `Pow` instance,
which can be used to specialize the exponent to have the same type as the base's type during elaboration.
This is to say, a type should provide an instance for this class in case `x ^ y` should be elaborated
with both `x` and `y` having the same type.
For example, the `Float` type provides an instance of this class, which causes expressions
such as `(2.2 ^ 2.2 : Float)` to elaborate. |
SMul (M : Type u) (α : Type v) where
/-- `m • a : α` denotes the product of `m : M` and `a : α`. The meaning of this notation is type-dependent,
but it is intended to be used for left actions. -/
smul : M → α → α | class | Init.Prelude | [] | Init/Prelude.lean | SMul | Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) |
Append (α : Type u) where
/-- `a ++ b` is the result of concatenation of `a` and `b`. See `HAppend`. -/
append : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | Append | The homogeneous version of `HAppend`: `a ++ b : α` where `a b : α`. |
OrElse (α : Type u) where
/-- The implementation of `a <|> b : α`. See `HOrElse`. -/
orElse : α → (Unit → α) → α | class | Init.Prelude | [] | Init/Prelude.lean | OrElse | The homogeneous version of `HOrElse`: `a <|> b : α` where `a b : α`.
Because `b` is "lazy" in this notation, it is passed as `Unit → α` to the
implementation so it can decide when to evaluate it. |
AndThen (α : Type u) where
/-- The implementation of `a >> b : α`. See `HAndThen`. -/
andThen : α → (Unit → α) → α | class | Init.Prelude | [] | Init/Prelude.lean | AndThen | The homogeneous version of `HAndThen`: `a >> b : α` where `a b : α`.
Because `b` is "lazy" in this notation, it is passed as `Unit → α` to the
implementation so it can decide when to evaluate it. |
AndOp (α : Type u) where
/-- The implementation of `a &&& b : α`. See `HAnd`. -/
and : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | AndOp | The homogeneous version of `HAnd`: `a &&& b : α` where `a b : α`.
(It is called `AndOp` because `And` is taken for the propositional connective.) |
XorOp (α : Type u) where
/-- The implementation of `a ^^^ b : α`. See `HXor`. -/
xor : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | XorOp | The homogeneous version of `HXor`: `a ^^^ b : α` where `a b : α`. |
OrOp (α : Type u) where
/-- The implementation of `a ||| b : α`. See `HOr`. -/
or : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | OrOp | The homogeneous version of `HOr`: `a ||| b : α` where `a b : α`.
(It is called `OrOp` because `Or` is taken for the propositional connective.) |
Complement (α : Type u) where
/-- The implementation of `~~~a : α`. -/
complement : α → α | class | Init.Prelude | [] | Init/Prelude.lean | Complement | The typeclass behind the notation `~~~a : α` where `a : α`. |
ShiftLeft (α : Type u) where
/-- The implementation of `a <<< b : α`. See `HShiftLeft`. -/
shiftLeft : α → α → α | class | Init.Prelude | [] | Init/Prelude.lean | ShiftLeft | The homogeneous version of `HShiftLeft`: `a <<< b : α` where `a b : α`. |
ShiftRight (α : Type u) where
/-- The implementation of `a >>> b : α`. See `HShiftRight`. -/
shiftRight : α → α → α
@[default_instance] | class | Init.Prelude | [] | Init/Prelude.lean | ShiftRight | The homogeneous version of `HShiftRight`: `a >>> b : α` where `a b : α`. |
instHAdd [Add α] : HAdd α α α where
hAdd a b := Add.add a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHAdd | null |
instHSub [Sub α] : HSub α α α where
hSub a b := Sub.sub a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHSub | null |
instHMul [Mul α] : HMul α α α where
hMul a b := Mul.mul a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHMul | null |
instHDiv [Div α] : HDiv α α α where
hDiv a b := Div.div a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHDiv | null |
instHMod [Mod α] : HMod α α α where
hMod a b := Mod.mod a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHMod | null |
instHPow [Pow α β] : HPow α β α where
hPow a b := Pow.pow a b
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instHPow | null |
instPowNat [NatPow α] : Pow α Nat where
pow a n := NatPow.pow a n
@[default_instance] | instance | Init.Prelude | [] | Init/Prelude.lean | instPowNat | null |
@[default_instance]
instHSMul {α β} [SMul α β] : HSMul α β β where
hSMul := SMul.smul | instance | Init.Prelude | [] | Init/Prelude.lean | instHSMul | null |
Membership (α : outParam (Type u)) (γ : Type v) where
/-- The membership relation `a ∈ s : Prop` where `a : α`, `s : γ`. -/
mem : γ → α → Prop
set_option bootstrap.genMatcherCode false in | class | Init.Prelude | [] | Init/Prelude.lean | Membership | The typeclass behind the notation `a ∈ s : Prop` where `a : α`, `s : γ`.
Because `α` is an `outParam`, the "container type" `γ` determines the type
of the elements of the container. |
@[extern "lean_nat_add"]
protected Nat.add : (@& Nat) → (@& Nat) → Nat
| a, Nat.zero => a
| a, Nat.succ b => Nat.succ (Nat.add a b) | def | Init.Prelude | [] | Init/Prelude.lean | Nat.add | Addition of natural numbers, typically used via the `+` operator.
This function 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. |
instAddNat : Add Nat where
add := Nat.add
/- We mark the following definitions as pattern to make sure they can be used in recursive equations,
and reduced by the equation Compiler. -/
attribute [match_pattern] Nat.add Add.add HAdd.hAdd Neg.neg Mul.mul HMul.hMul Inv.inv
set_option bootstrap.genMatcherCode false in | instance | Init.Prelude | [] | Init/Prelude.lean | instAddNat | null |
@[extern "lean_nat_mul"]
protected Nat.mul : (@& Nat) → (@& Nat) → Nat
| _, 0 => 0
| a, Nat.succ b => Nat.add (Nat.mul a b) a | def | Init.Prelude | [] | Init/Prelude.lean | Nat.mul | Multiplication of natural numbers, usually accessed via the `*` operator.
This function 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. |
instMulNat : Mul Nat where
mul := Nat.mul
set_option bootstrap.genMatcherCode false in | instance | Init.Prelude | [] | Init/Prelude.lean | instMulNat | null |
@[extern "lean_nat_pow"]
protected Nat.pow (m : @& Nat) : (@& Nat) → Nat
| 0 => 1
| succ n => Nat.mul (Nat.pow m n) m | def | Init.Prelude | [] | Init/Prelude.lean | Nat.pow | The power operation on natural numbers, usually accessed via the `^` operator.
This function 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. |
instNatPowNat : NatPow Nat := ⟨Nat.pow⟩
set_option bootstrap.genMatcherCode false in | instance | Init.Prelude | [] | Init/Prelude.lean | instNatPowNat | null |
@[extern "lean_nat_dec_eq"]
Nat.beq : (@& Nat) → (@& Nat) → Bool
| zero, zero => true
| zero, succ _ => false
| succ _, zero => false
| succ n, succ m => beq n m | def | Init.Prelude | [] | Init/Prelude.lean | Nat.beq | Boolean equality of natural numbers, usually accessed via the `==` operator.
This function 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. |
Nat.eq_of_beq_eq_true : {n m : Nat} → Eq (beq n m) true → Eq n m
| zero, zero, _ => rfl
| zero, succ _, h => Bool.noConfusion h
| succ _, zero, h => Bool.noConfusion h
| succ n, succ m, h =>
have : Eq (beq n m) true := h
have : Eq n m := eq_of_beq_eq_true this
this ▸ rfl | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.eq_of_beq_eq_true | null |
Nat.ne_of_beq_eq_false : {n m : Nat} → Eq (beq n m) false → Not (Eq n m)
| zero, zero, h₁, _ => Bool.noConfusion h₁
| zero, succ _, _, h₂ => Nat.noConfusion h₂
| succ _, zero, _, h₂ => Nat.noConfusion h₂
| succ n, succ m, h₁, h₂ =>
have : Eq (beq n m) false := h₁
Nat.noConfusion h₂ (fun h₂ => absurd h₂ (ne_of_beq_eq_false this)) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.ne_of_beq_eq_false | null |
private noConfusion_of_Nat.aux : (a : Nat) → (Nat.beq a a).rec False True
| Nat.zero => True.intro
| Nat.succ n => noConfusion_of_Nat.aux n | theorem | Init.Prelude | [] | Init/Prelude.lean | noConfusion_of_Nat.aux | null |
noConfusion_of_Nat {α : Sort u} (f : α → Nat) {a b : α} (h : Eq a b) :
(Nat.beq (f a) (f b)).rec False True :=
congrArg f h ▸ noConfusion_of_Nat.aux (f a) | theorem | Init.Prelude | [] | Init/Prelude.lean | noConfusion_of_Nat | A helper theorem to deduce `False` from `a = b` when `f a ≠ f b` for some function `f : α → Nat`
(typically `.ctorIdx`). Used as a simpler alternative to the no-confusion theorems. |
@[reducible, extern "lean_nat_dec_eq"]
protected Nat.decEq (n m : @& Nat) : Decidable (Eq n m) :=
match h:beq n m with
| true => isTrue (eq_of_beq_eq_true h)
| false => isFalse (ne_of_beq_eq_false h)
@[inline] instance : DecidableEq Nat := Nat.decEq
set_option bootstrap.genMatcherCode false in | def | Init.Prelude | [] | Init/Prelude.lean | Nat.decEq | A decision procedure for equality of natural numbers, usually accessed via the `DecidableEq Nat`
instance.
This function 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:
* `Nat.decEq 5 5 = isTrue rfl`
* `(if 3 = 4 then "yes" else "no") = "no"`
* `show 12 = 12 by decide` |
@[extern "lean_nat_dec_le"]
Nat.ble : @& Nat → @& Nat → Bool
| zero, _ => true
| succ _, zero => false
| succ n, succ m => ble n m
attribute [gen_constructor_elims] Bool | def | Init.Prelude | [] | Init/Prelude.lean | Nat.ble | The Boolean less-than-or-equal-to comparison on natural numbers.
This function 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:
* `Nat.ble 2 5 = true`
* `Nat.ble 5 2 = false`
* `Nat.ble 5 5 = true` |
protected Nat.le (n : Nat) : Nat → Prop
/-- Non-strict inequality is reflexive: `n ≤ n` -/
| refl : Nat.le n n
/-- If `n ≤ m`, then `n ≤ m + 1`. -/
| step {m} : Nat.le n m → Nat.le n (succ m) | inductive | Init.Prelude | [] | Init/Prelude.lean | Nat.le | Non-strict, or weak, inequality of natural numbers, usually accessed via the `≤` operator. |
instLENat : LE Nat where
le := Nat.le | instance | Init.Prelude | [] | Init/Prelude.lean | instLENat | null |
protected Nat.lt (n m : Nat) : Prop :=
Nat.le (succ n) m | def | Init.Prelude | [] | Init/Prelude.lean | Nat.lt | Strict inequality of natural numbers, usually accessed via the `<` operator.
It is defined as `n < m = n + 1 ≤ m`. |
instLTNat : LT Nat where
lt := Nat.lt | instance | Init.Prelude | [] | Init/Prelude.lean | instLTNat | null |
Nat.not_succ_le_zero (n : Nat) : LE.le (succ n) 0 → False :=
-- No injectivity tactic until `attribute [gen_constructor_elims] Nat`
have : ∀ m, Eq m 0 → LE.le (succ n) m → False := fun _ hm hle =>
Nat.le.casesOn (motive := fun m _ => Eq m 0 → False) hle
(fun h => Nat.noConfusion h)
(fun _ h => Nat.noConfusion h)
hm
this 0 rfl | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.not_succ_le_zero | null |
Nat.not_lt_zero (n : Nat) : Not (LT.lt n 0) :=
not_succ_le_zero n | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.not_lt_zero | null |
Nat.zero_le : (n : Nat) → LE.le 0 n
| zero => Nat.le.refl
| succ n => Nat.le.step (zero_le n) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.zero_le | null |
Nat.succ_le_succ : LE.le n m → LE.le (succ n) (succ m)
| Nat.le.refl => Nat.le.refl
| Nat.le.step h => Nat.le.step (succ_le_succ h) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.succ_le_succ | null |
Nat.zero_lt_succ (n : Nat) : LT.lt 0 (succ n) :=
succ_le_succ (zero_le n) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.zero_lt_succ | null |
Nat.le_succ_of_le (h : LE.le n m) : LE.le n (succ m) :=
Nat.le.step h | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_succ_of_le | null |
protected Nat.le_trans {n m k : Nat} : LE.le n m → LE.le m k → LE.le n k
| h, Nat.le.refl => h
| h₁, Nat.le.step h₂ => Nat.le.step (Nat.le_trans h₁ h₂) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_trans | null |
protected Nat.lt_of_lt_of_le {n m k : Nat} : LT.lt n m → LE.le m k → LT.lt n k :=
Nat.le_trans | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.lt_of_lt_of_le | null |
protected Nat.lt_trans {n m k : Nat} (h₁ : LT.lt n m) : LT.lt m k → LT.lt n k :=
Nat.le_trans (le_succ_of_le h₁) | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.lt_trans | null |
Nat.le_succ (n : Nat) : LE.le n (succ n) :=
Nat.le.step Nat.le.refl | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_succ | null |
protected Nat.le_refl (n : Nat) : LE.le n n :=
Nat.le.refl | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_refl | null |
Nat.succ_pos (n : Nat) : LT.lt 0 (succ n) :=
zero_lt_succ n
set_option bootstrap.genMatcherCode false in | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.succ_pos | null |
@[extern "lean_nat_pred"]
Nat.pred : (@& Nat) → Nat
| 0 => 0
| succ a => a | def | Init.Prelude | [] | Init/Prelude.lean | Nat.pred | The predecessor of a natural number is one less than it. The predecessor of `0` is defined to be
`0`.
This definition is overridden in the compiler with an efficient implementation. This definition is
the logical model. |
Nat.pred_le_pred : {n m : Nat} → LE.le n m → LE.le (pred n) (pred m)
| _, _, Nat.le.refl => Nat.le.refl
| 0, succ _, Nat.le.step h => h
| succ _, succ _, Nat.le.step h => Nat.le_trans (le_succ _) h | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.pred_le_pred | null |
Nat.le_of_succ_le_succ {n m : Nat} : LE.le (succ n) (succ m) → LE.le n m :=
pred_le_pred | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_of_succ_le_succ | null |
Nat.le_of_lt_succ {m n : Nat} : LT.lt m (succ n) → LE.le m n :=
le_of_succ_le_succ
set_option linter.missingDocs false in
-- single generic "theorem" used in `WellFounded` reduction in core | theorem | Init.Prelude | [] | Init/Prelude.lean | Nat.le_of_lt_succ | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.