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 ⌀ |
|---|---|---|---|---|---|---|
exists_rep {α : Sort u} {s : Setoid α} (q : Quotient s) : Exists (fun (a : α) => Quotient.mk s a = q) :=
Quot.exists_rep q | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | exists_rep | null |
@[inline, elab_as_elim]
protected rec
(f : (a : α) → motive (Quotient.mk s a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
(q : Quotient s)
: motive q :=
Quot.rec f h q | def | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | rec | A dependent recursion principle for `Quotient`. It is analogous to the
[recursor](lean-manual://section/recursors) for a structure, and can be used when the resulting type
is not necessarily a proposition.
While it is very general, this recursor can be tricky to use. The following simpler alternatives may
be easier to use:
* `Quotient.lift` is useful for defining non-dependent functions.
* `Quotient.ind` is useful for proving theorems about quotients.
* `Quotient.recOnSubsingleton` can be used whenever the target type is a `Subsingleton`.
* `Quotient.hrecOn` uses heterogeneous equality instead of rewriting with `Quotient.sound`.
`Quotient.recOn` is a version of this recursor that takes the quotient parameter first. |
@[elab_as_elim]
protected recOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
: motive q :=
Quot.recOn q f h | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | recOn | A dependent recursion principle for `Quotient`. It is analogous to the
[recursor](lean-manual://section/recursors) for a structure, and can be used when the resulting type
is not necessarily a proposition.
While it is very general, this recursor can be tricky to use. The following simpler alternatives may
be easier to use:
* `Quotient.lift` is useful for defining non-dependent functions.
* `Quotient.ind` is useful for proving theorems about quotients.
* `Quotient.recOnSubsingleton` can be used whenever the target type is a `Subsingleton`.
* `Quotient.hrecOn` uses heterogeneous equality instead of rewriting with `Quotient.sound`.
`Quotient.rec` is a version of this recursor that takes the quotient parameter last. |
@[elab_as_elim]
protected recOnSubsingleton
[h : (a : α) → Subsingleton (motive (Quotient.mk s a))]
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
: motive q :=
Quot.recOnSubsingleton (h := h) q f | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | recOnSubsingleton | An alternative recursion or induction principle for quotients that can be used when the target type
is a subsingleton, in which all elements are equal.
In these cases, the proof that the function respects the quotient's equivalence relation is trivial,
so any function can be lifted.
`Quotient.rec` does not assume that the target type is a subsingleton. |
@[elab_as_elim]
protected hrecOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
(c : (a b : α) → (p : a ≈ b) → f a ≍ f b)
: motive q :=
Quot.hrecOn q f c | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | hrecOn | A dependent recursion principle for `Quotient` that uses [heterogeneous
equality](lean-manual://section/HEq), analogous to a [recursor](lean-manual://section/recursors) for
a structure.
`Quotient.recOn` is a version of this recursor that uses `Eq` instead of `HEq`. |
protected lift₂
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
(q₁ : Quotient s₁) (q₂ : Quotient s₂)
: φ := by
apply Quotient.lift (fun (a₁ : α) => Quotient.lift (f a₁) (fun (a b : β) => c a₁ a a₁ b (Setoid.refl a₁)) q₂) _ q₁
intros
induction q₂ using Quotient.ind
apply c; assumption; apply Setoid.refl | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | lift₂ | Lifts a binary function from the underlying types to a binary function on quotients. The function
must respect both quotients' equivalence relations.
`Quotient.lift` is a version of this operation for unary functions. `Quotient.liftOn₂` is a version
that take the quotient parameters first. |
protected liftOn₂
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
: φ :=
Quotient.lift₂ f c q₁ q₂
@[elab_as_elim] | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | liftOn₂ | Lifts a binary function from the underlying types to a binary function on quotients. The function
must respect both quotients' equivalence relations.
`Quotient.liftOn` is a version of this operation for unary functions. `Quotient.lift₂` is a version
that take the quotient parameters last. |
protected ind₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(h : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
@[elab_as_elim] | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | ind₂ | null |
protected inductionOn₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(h : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
@[elab_as_elim] | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | inductionOn₂ | null |
protected inductionOn₃
{s₃ : Setoid φ}
{motive : Quotient s₁ → Quotient s₂ → Quotient s₃ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(q₃ : Quotient s₃)
(h : (a : α) → (b : β) → (c : φ) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b) (Quotient.mk s₃ c))
: motive q₁ q₂ q₃ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
induction q₃ using Quotient.ind
apply h | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | inductionOn₃ | null |
private rel {s : Setoid α} (q₁ q₂ : Quotient s) : Prop :=
Quotient.liftOn₂ q₁ q₂
(fun a₁ a₂ => a₁ ≈ a₂)
(fun _ _ _ _ a₁b₁ a₂b₂ =>
propext (Iff.intro
(fun a₁a₂ => Setoid.trans (Setoid.symm a₁b₁) (Setoid.trans a₁a₂ a₂b₂))
(fun b₁b₂ => Setoid.trans a₁b₁ (Setoid.trans b₁b₂ (Setoid.symm a₂b₂))))) | def | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | rel | null |
private rel.refl {s : Setoid α} (q : Quotient s) : rel q q :=
q.inductionOn Setoid.refl | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | rel.refl | null |
private rel_of_eq {s : Setoid α} {q₁ q₂ : Quotient s} : q₁ = q₂ → rel q₁ q₂ :=
fun h => Eq.ndrecOn h (rel.refl q₁) | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | rel_of_eq | null |
exact {s : Setoid α} {a b : α} : Quotient.mk s a = Quotient.mk s b → a ≈ b :=
fun h => rel_of_eq h | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | exact | If two values are equal in a quotient, then they are related by its equivalence relation. |
@[elab_as_elim]
protected recOnSubsingleton₂
{motive : Quotient s₁ → Quotient s₂ → Sort uC}
[s : (a : α) → (b : β) → Subsingleton (motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))]
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(g : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
: motive q₁ q₂ := by
induction q₁ using Quot.recOnSubsingleton
induction q₂ using Quot.recOnSubsingleton
apply g
intro a; apply s
induction q₂ using Quot.recOnSubsingleton
intro a; apply s
infer_instance | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | recOnSubsingleton₂ | An alternative induction or recursion operator for defining binary operations on quotients that can
be used when the target type is a subsingleton.
In these cases, the proof that the function respects the quotient's equivalence relation is trivial,
so any function can be lifted. |
Quotient.decidableEq {α : Sort u} {s : Setoid α} [d : ∀ (a b : α), Decidable (a ≈ b)]
: DecidableEq (Quotient s) :=
fun (q₁ q₂ : Quotient s) =>
Quotient.recOnSubsingleton₂ q₁ q₂
fun a₁ a₂ =>
match d a₁ a₂ with
| isTrue h₁ => isTrue (Quotient.sound h₁)
| isFalse h₂ => isFalse fun h => absurd (Quotient.exact h) h₂
/-! # Function extensionality -/ | instance | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Quotient.decidableEq | null |
funext {α : Sort u} {β : α → Sort v} {f g : (x : α) → β x}
(h : ∀ x, f x = g x) : f = g := by
let eqv (f g : (x : α) → β x) := ∀ x, f x = g x
let extfunApp (f : Quot eqv) (x : α) : β x :=
Quot.liftOn f
(fun (f : ∀ (x : α), β x) => f x)
(fun _ _ h => h x)
change extfunApp (Quot.mk eqv f) = extfunApp (Quot.mk eqv g)
exact congrArg extfunApp (Quot.sound h) | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | funext | **Function extensionality.** If two functions return equal results for all possible arguments, then
they are equal.
It is called “extensionality” because it provides a way to prove two objects equal based on the
properties of the underlying mathematical functions, rather than based on the syntax used to denote
them. Function extensionality is a theorem that can be [proved using quotient
types](lean-manual://section/quotient-funext). |
protected Quot.pliftOn {α : Sort u} {r : α → α → Prop}
(q : Quot r)
(f : (a : α) → q = Quot.mk r a → β)
(h : ∀ (a b : α) (h h'), r a b → f a h = f b h') : β :=
q.rec (motive := fun q' => q = q' → β) f
(fun a b p => funext fun h' =>
(apply_eqRec (motive := fun b _ => q = b)).trans
(@h a b (h'.trans (sound p).symm) h' p)) rfl | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Quot.pliftOn | Like `Quot.liftOn q f h` but allows `f a` to "know" that `q = Quot.mk r a`. |
protected Quotient.pliftOn {α : Sort u} {s : Setoid α}
(q : Quotient s)
(f : (a : α) → q = Quotient.mk s a → β)
(h : ∀ (a b : α) (h h'), a ≈ b → f a h = f b h') : β :=
Quot.pliftOn q f h | abbrev | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Quotient.pliftOn | Like `Quotient.liftOn q f h` but allows `f a` to "know" that `q = Quotient.mk s a`. |
Pi.instSubsingleton {α : Sort u} {β : α → Sort v} [∀ a, Subsingleton (β a)] :
Subsingleton (∀ a, β a) where
allEq f g := funext fun a => Subsingleton.elim (f a) (g a)
/-! # Squash -/ | instance | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Pi.instSubsingleton | null |
Squash (α : Sort u) := Quot (fun (_ _ : α) => True) | def | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Squash | The quotient of `α` by the universal relation. The elements of `Squash α` are those of `α`, but all
of them are equal and cannot be distinguished.
`Squash α` is a `Subsingleton`: it is empty if `α` is empty, otherwise it has just one element. It
is the “universal `Subsingleton`” mapped from `α`.
`Nonempty α` also has these properties. It is a proposition, which means that its elements (i.e.
proofs) are erased from compiled code and represented by a dummy value. `Squash α` is a `Type u`,
and its representation in compiled code is identical to that of `α`.
Consequently, `Squash.lift` may extract an `α` value into any subsingleton type `β`, while
`Nonempty.rec` can only do the same when `β` is a proposition. |
Squash.mk {α : Sort u} (x : α) : Squash α := Quot.mk _ x | def | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Squash.mk | Places a value into its squash type, in which it cannot be distinguished from any other. |
Squash.ind {α : Sort u} {motive : Squash α → Prop} (h : ∀ (a : α), motive (Squash.mk a)) : ∀ (q : Squash α), motive q :=
Quot.ind h | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Squash.ind | A reasoning principle that allows proofs about squashed types to assume that all values are
constructed with `Squash.mk`. |
@[inline] Squash.lift {α β} [Subsingleton β] (s : Squash α) (f : α → β) : β :=
Quot.lift f (fun _ _ _ => Subsingleton.elim _ _) s | def | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Squash.lift | Extracts a squashed value into any subsingleton type.
If `β` is a subsingleton, a function `α → β` cannot distinguish between elements of `α` and thus
automatically respects the universal relation that `Squash` quotients with. |
trustCompiler : True | axiom | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | trustCompiler | Depends on the correctness of the Lean compiler, interpreter, and all `[implemented_by ...]` and `[extern ...]` annotations. |
reduceBool (b : Bool) : Bool :=
-- This ensures that `#print axioms` will track use of `reduceBool`.
have := trustCompiler
b | opaque | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | reduceBool | When the kernel tries to reduce a term `Lean.reduceBool c`, it will invoke the Lean interpreter to evaluate `c`.
The kernel will not use the interpreter if `c` is not a constant.
This feature is useful for performing proofs by reflection.
Remark: the Lean frontend allows terms of the from `Lean.reduceBool t` where `t` is a term not containing
free variables. The frontend automatically declares a fresh auxiliary constant `c` and replaces the term with
`Lean.reduceBool c`. The main motivation is that the code for `t` will be pre-compiled.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your development using
external type checkers that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your development using external checkers.
Recall that the compiler trusts the correctness of all `[implemented_by ...]` and `[extern ...]` annotations.
If an extern function is executed, then the trusted code base will also include the implementation of the associated
foreign function. |
reduceNat (n : Nat) : Nat :=
-- This ensures that `#print axioms` will track use of `reduceNat`.
have := trustCompiler
n | opaque | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | reduceNat | Similar to `Lean.reduceBool` for closed `Nat` terms.
Remark: we do not have plans for supporting a generic `reduceValue {α} (a : α) : α := a`.
The main issue is that it is non-trivial to convert an arbitrary runtime object back into a Lean expression.
We believe `Lean.reduceBool` enables most interesting applications (e.g., proof by reflection). |
ofReduceBool (a b : Bool) (h : reduceBool a = b) : a = b | axiom | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | ofReduceBool | The axiom `ofReduceBool` is used to perform proofs by reflection. See `reduceBool`.
This axiom is usually not used directly, because it has some syntactic restrictions.
Instead, the `native_decide` tactic can be used to prove any proposition whose
decidability instance can be evaluated to `true` using the lean compiler / interpreter.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your development using
external type checkers that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your development using external checkers. |
ofReduceNat (a b : Nat) (h : reduceNat a = b) : a = b | axiom | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | ofReduceNat | The axiom `ofReduceNat` is used to perform proofs by reflection. See `reduceBool`.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your development using
external type checkers that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your development using external checkers. |
opaqueId {α : Sort u} (x : α) : α := x | opaque | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | opaqueId | The term `opaqueId x` will not be reduced by the kernel. |
@[simp] ge_iff_le [LE α] {x y : α} : x ≥ y ↔ y ≤ x := Iff.rfl
@[simp] theorem gt_iff_lt [LT α] {x y : α} : x > y ↔ y < x := Iff.rfl | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | ge_iff_le | null |
le_of_eq_of_le {a b c : α} [LE α] (h₁ : a = b) (h₂ : b ≤ c) : a ≤ c := h₁ ▸ h₂ | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | le_of_eq_of_le | null |
le_of_le_of_eq {a b c : α} [LE α] (h₁ : a ≤ b) (h₂ : b = c) : a ≤ c := h₂ ▸ h₁ | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | le_of_le_of_eq | null |
lt_of_eq_of_lt {a b c : α} [LT α] (h₁ : a = b) (h₂ : b < c) : a < c := h₁ ▸ h₂ | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | lt_of_eq_of_lt | null |
lt_of_lt_of_eq {a b c : α} [LT α] (h₁ : a < b) (h₂ : b = c) : a < c := h₂ ▸ h₁ | theorem | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | lt_of_lt_of_eq | null |
Associative (op : α → α → α) : Prop where
/-- An associative operation satisfies `(a ∘ b) ∘ c = a ∘ (b ∘ c)`. -/
assoc : (a b c : α) → op (op a b) c = op a (op b c) | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Associative | `Associative op` indicates `op` is an associative operation,
i.e. `(a ∘ b) ∘ c = a ∘ (b ∘ c)`. |
Commutative (op : α → α → α) : Prop where
/-- A commutative operation satisfies `a ∘ b = b ∘ a`. -/
comm : (a b : α) → op a b = op b a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Commutative | `Commutative op` says that `op` is a commutative operation,
i.e. `a ∘ b = b ∘ a`. |
IdempotentOp (op : α → α → α) : Prop where
/-- An idempotent operation satisfies `a ∘ a = a`. -/
idempotent : (x : α) → op x x = x | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | IdempotentOp | `IdempotentOp op` indicates `op` is an idempotent binary operation.
i.e. `a ∘ a = a`. |
LeftIdentity (op : α → β → β) (o : outParam α) : Prop | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | LeftIdentity | `LeftIdentify op o` indicates `o` is a left identity of `op`.
This class does not require a proof that `o` is an identity, and
is used primarily for inferring the identity using class resolution. |
LawfulLeftIdentity (op : α → β → β) (o : outParam α) : Prop extends LeftIdentity op o where
/-- Left identity `o` is an identity. -/
left_id : ∀ a, op o a = a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | LawfulLeftIdentity | `LawfulLeftIdentify op o` indicates `o` is a verified left identity of
`op`. |
RightIdentity (op : α → β → α) (o : outParam β) : Prop | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | RightIdentity | `RightIdentify op o` indicates `o` is a right identity `o` of `op`.
This class does not require a proof that `o` is an identity, and is used
primarily for inferring the identity using class resolution. |
LawfulRightIdentity (op : α → β → α) (o : outParam β) : Prop extends RightIdentity op o where
/-- Right identity `o` is an identity. -/
right_id : ∀ a, op a o = a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | LawfulRightIdentity | `LawfulRightIdentify op o` indicates `o` is a verified right identity of
`op`. |
Identity (op : α → α → α) (o : outParam α) : Prop extends LeftIdentity op o, RightIdentity op o | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Identity | `Identity op o` indicates `o` is a left and right identity of `op`.
This class does not require a proof that `o` is an identity, and is used
primarily for inferring the identity using class resolution. |
LawfulIdentity (op : α → α → α) (o : outParam α) : Prop extends Identity op o, LawfulLeftIdentity op o, LawfulRightIdentity op o | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | LawfulIdentity | `LawfulIdentity op o` indicates `o` is a verified left and right
identity of `op`. |
LawfulCommIdentity (op : α → α → α) (o : outParam α) [hc : Commutative op] : Prop extends LawfulIdentity op o where
left_id a := Eq.trans (hc.comm o a) (right_id a)
right_id a := Eq.trans (hc.comm a o) (left_id a) | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | LawfulCommIdentity | `LawfulCommIdentity` can simplify defining instances of `LawfulIdentity`
on commutative functions by requiring only a left or right identity
proof.
This class is intended for simplifying defining instances of
`LawfulIdentity` and functions needed commutative operations with
identity should just add a `LawfulIdentity` constraint. |
Refl (r : α → α → Prop) : Prop where
/-- A reflexive relation satisfies `r a a`. -/
refl : ∀ a, r a a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Refl | `Refl r` means the binary relation `r` is reflexive, that is, `r x x` always holds. |
Antisymm (r : α → α → Prop) : Prop where
/-- An antisymmetric relation `r` satisfies `r a b → r b a → a = b`. -/
antisymm (a b : α) : r a b → r b a → a = b | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Antisymm | `Antisymm r` says that `r` is antisymmetric, that is, `r a b → r b a → a = b`. |
Asymm (r : α → α → Prop) : Prop where
/-- An asymmetric relation satisfies `r a b → ¬ r b a`. -/
asymm : ∀ a b, r a b → ¬r b a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Asymm | `Asymm r` means that the binary relation `r` is asymmetric, that is, `r a b → ¬ r b a`. |
Symm (r : α → α → Prop) : Prop where
/-- A symmetric relation satisfies `r a b → r b a`. -/
symm : ∀ a b, r a b → r b a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Symm | `Symm r` means that the binary relation `r` is symmetric, that is, `r a b → r b a`. |
Total (r : α → α → Prop) : Prop where
/-- A total relation satisfies `r a b` or `r b a`. -/
total : ∀ a b, r a b ∨ r b a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Total | `Total X r` means that the binary relation `r` on `X` is total, that is, `r a b` or `r b a`. |
Irrefl (r : α → α → Prop) : Prop where
/-- An irreflexive relation satisfies `¬ r a a`. -/
irrefl : ∀ a, ¬r a a | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Irrefl | `Irrefl r` means the binary relation `r` is irreflexive, that is, `r x x` never holds. |
Trichotomous (r : α → α → Prop) : Prop where
/-- An trichotomous relation `r` satisfies `¬ r a b → ¬ r b a → a = b`. -/
trichotomous (a b : α) : ¬ r a b → ¬ r b a → a = b | class | Init.Core | [
"Init.SizeOf"
] | Init/Core.lean | Trichotomous | `Trichotomous r` says that `r` is trichotomous, that is, `¬ r a b → ¬ r b a → a = b`. |
TypeNameData (α : Type u) : NonemptyType.{0} :=
⟨Name, inferInstance⟩ | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | TypeNameData | null |
@[nospecialize]
TypeName (α : Type u) where private mk' ::
private data : (TypeNameData α).type | class | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | TypeName | Dynamic type name information.
Types with an instance of `TypeName` can be stored in an `Dynamic`.
The type class contains the declaration name of the type,
which must not have any universe parameters
and be of type `Sort ..` (i.e., monomorphic).
The preferred way to declare instances of this type is using the derive
handler, which will internally use the unsafe `TypeName.mk` function.
Morally, this is the same as:
```lean
class TypeName (α : Type) where unsafe mk ::
typeName : Name
``` |
unsafe TypeName.mk (α : Type u) (typeName : Name) : TypeName α :=
⟨unsafeCast typeName⟩
private unsafe def TypeName.typeNameImpl (α) [TypeName α] : Name :=
unsafeCast (@TypeName.data α _) | def | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | TypeName.mk | Creates a `TypeName` instance.
For safety, it is required that the constant `typeName` is definitionally equal
to `α`. |
@[implemented_by TypeName.typeNameImpl]
TypeName.typeName (α) [TypeName α] : Name | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | TypeName.typeName | Returns a declaration name of the type. |
private DynamicPointed : NonemptyType.{0} :=
⟨Name × NonScalar, inferInstance⟩ | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | DynamicPointed | null |
Dynamic : Type := DynamicPointed.type | def | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | Dynamic | A type-tagged union that can store any type with a `TypeName` instance.
This is roughly equivalent to `(α : Type) × TypeName α × α`, but without the universe bump. Use
`Dynamic.mk` to inject a value into `Dynamic` from another type, and `Dynamic.get?` to extract a
value from `Dynamic` if it has some expected type. |
private unsafe Dynamic.typeNameImpl (any : Dynamic) : Name :=
(unsafeCast any : Name × NonScalar).1 | def | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | Dynamic.typeNameImpl | null |
@[implemented_by Dynamic.typeNameImpl]
Dynamic.typeName (any : Dynamic) : Name
private unsafe def Dynamic.get?Impl (α) (any : Dynamic) [TypeName α] : Option α :=
let ((typeName, obj) : Name × NonScalar) := unsafeCast any
if typeName == TypeName.typeName α then
some (unsafeCast obj)
else
none | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | Dynamic.typeName | The name of the type of the value stored in the `Dynamic`. |
@[implemented_by Dynamic.get?Impl]
Dynamic.get? (α) (any : Dynamic) [TypeName α] : Option α
private unsafe def Dynamic.mkImpl [TypeName α] (obj : α) : Dynamic :=
unsafeCast (TypeName.typeName α, (unsafeCast obj : NonScalar)) | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | Dynamic.get | Retrieves the value stored in the `Dynamic`.
Returns `some a` if the value has the right type, and `none` otherwise. |
@[implemented_by Dynamic.mkImpl]
Dynamic.mk [TypeName α] (obj : α) : Dynamic | opaque | Init.Dynamic | [
"Init.Core"
] | Init/Dynamic.lean | Dynamic.mk | Stores the provided value in a `Dynamic`.
Use `Dynamic.get? α` to retrieve it. |
@[deprecated Subtype.ext_iff (since := "2025-10-26")]
protected Subtype.eq_iff := @Subtype.ext_iff
attribute [grind ext] funext Array.ext
attribute [ext] PUnit.ext | def | Init.Ext | [
"Init.Data.ToString.Macro",
"Init.TacticsExtra",
"Init.RCases"
] | Init/Ext.lean | Subtype.eq_iff | null |
protected Unit.ext (x y : Unit) : x = y := rfl
@[ext] protected theorem Thunk.ext : {a b : Thunk α} → a.get = b.get → a = b
| {..}, {..}, heq => congrArg _ <| funext fun _ => heq | theorem | Init.Ext | [
"Init.Data.ToString.Macro",
"Init.TacticsExtra",
"Init.RCases"
] | Init/Ext.lean | Unit.ext | null |
@[never_extract]
outOfBounds [Inhabited α] : α :=
panic! "index out of bounds" | def | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | outOfBounds | null |
outOfBounds_eq_default [Inhabited α] : (outOfBounds : α) = default := rfl | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | outOfBounds_eq_default | null |
GetElem (coll : Type u) (idx : Type v) (elem : outParam (Type w))
(valid : outParam (coll → idx → Prop)) where
/--
The syntax `arr[i]` gets the `i`'th element of the collection `arr`. If there
are proof side conditions to the application, they will be automatically
inferred by the `get_elem_tactic` tactic.
-/
getElem (xs : coll) (i : idx) (h : valid xs i) : elem
export GetElem (getElem)
@[inherit_doc getElem]
syntax:max term noWs "[" withoutPosition(term) "]" : term
macro_rules | `($x[$i]) => `(getElem $x $i (by get_elem_tactic))
@[inherit_doc getElem]
syntax term noWs "[" withoutPosition(term) "]'" term:max : term
macro_rules | `($x[$i]'$h) => `(getElem $x $i $h) | class | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | GetElem | The classes `GetElem` and `GetElem?` implement lookup notation,
specifically `xs[i]`, `xs[i]?`, `xs[i]!`, and `xs[i]'p`.
Both classes are indexed by types `coll`, `idx`, and `elem` which are
the collection, the index, and the element types.
A single collection may support lookups with multiple index
types. The relation `valid` determines when the index is guaranteed to be
valid; lookups of valid indices are guaranteed not to fail.
For example, an instance for arrays looks like
`GetElem (Array α) Nat α (fun xs i => i < xs.size)`. In other words, given an
array `xs` and a natural number `i`, `xs[i]` will return an `α` when `valid xs i`
holds, which is true when `i` is less than the size of the array. `Array`
additionally supports indexing with `USize` instead of `Nat`.
In either case, because the bounds are checked at compile time,
no runtime check is required.
Given `xs[i]` with `xs : coll` and `i : idx`, Lean looks for an instance of
`GetElem coll idx elem valid` and uses this to infer the type of the return
value `elem` and side condition `valid` required to ensure `xs[i]` yields
a valid value of type `elem`. The tactic `get_elem_tactic` is
invoked to prove validity automatically. The `xs[i]'p` notation uses the
proof `p` to satisfy the validity condition.
If the proof `p` is long, it is often easier to place the
proof in the context using `have`, because `get_elem_tactic` tries
`assumption`.
The proof side-condition `valid xs i` is automatically dispatched by the
`get_elem_tactic` tactic; this tactic can be extended by adding more clauses to
`get_elem_tactic_extensible` using `macro_rules`.
`xs[i]?` and `xs[i]!` do not impose a proof obligation; the former returns
an `Option elem`, with `none` signalling that the value isn't present, and
the latter returns `elem` but panics if the value isn't there, returning
`default : elem` based on the `Inhabited elem` instance.
These are provided by the `GetElem?` class, for which there is a default instance
generated from a `GetElem` class as long as `valid xs i` is always decidable.
Important instances include:
* `arr[i] : α` where `arr : Array α` and `i : Nat` or `i : USize`: does array
indexing with no runtime bounds check and a proof side goal `i < arr.size`.
* `l[i] : α` where `l : List α` and `i : Nat`: index into a list, with proof
side goal `i < l.length`. |
decidableGetElem? [GetElem coll idx elem valid] (xs : coll) (i : idx) [Decidable (valid xs i)] :
Option elem :=
if h : valid xs i then some xs[i] else none
@[inherit_doc GetElem] | abbrev | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | decidableGetElem | Helper function for implementation of `GetElem?.getElem?`. |
GetElem? (coll : Type u) (idx : Type v) (elem : outParam (Type w))
(valid : outParam (coll → idx → Prop)) extends GetElem coll idx elem valid where
/--
The syntax `arr[i]?` gets the `i`'th element of the collection `arr`,
if it is present (and wraps it in `some`), and otherwise returns `none`.
-/
getElem? : coll → idx → Option elem
/--
The syntax `arr[i]!` gets the `i`'th element of the collection `arr`,
if it is present, and otherwise panics at runtime and returns the `default` term
from `Inhabited elem`.
-/
getElem! [Inhabited elem] (xs : coll) (i : idx) : elem :=
match getElem? xs i with | some e => e | none => outOfBounds
export GetElem? (getElem? getElem!) | class | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | GetElem | null |
LawfulGetElem (cont : Type u) (idx : Type v) (elem : outParam (Type w))
(dom : outParam (cont → idx → Prop)) [ge : GetElem? cont idx elem dom] : Prop where
/-- `GetElem?.getElem?` succeeds when the validity predicate is satisfied and fails otherwise. -/
getElem?_def (c : cont) (i : idx) [Decidable (dom c i)] :
c[i]? = if h : dom c i then some (c[i]'h) else none := by
intros
try simp only [getElem?] <;> congr
/-- `GetElem?.getElem!` succeeds and fails when `GetElem.getElem?` succeeds and fails. -/
getElem!_def [Inhabited elem] (c : cont) (i : idx) :
c[i]! = match c[i]? with | some e => e | none => default := by
intros
simp only [getElem!, getElem?, outOfBounds_eq_default]
export LawfulGetElem (getElem?_def getElem!_def) | class | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | LawfulGetElem | The syntax `arr[i]?` gets the `i`'th element of the collection `arr` or
returns `none` if `i` is out of bounds.
-/
macro:max x:term noWs "[" i:term "]" noWs "?" : term => `(getElem? $x $i)
/--
The syntax `arr[i]!` gets the `i`'th element of the collection `arr` and
panics if `i` is out of bounds.
-/
macro:max x:term noWs "[" i:term "]" noWs "!" : term => `(getElem! $x $i)
recommended_spelling "getElem" for "xs[i]" in [GetElem.getElem, «term__[_]»]
recommended_spelling "getElem" for "xs[i]'h" in [GetElem.getElem, «term__[_]'_»]
recommended_spelling "getElem?" for "xs[i]?" in [GetElem?.getElem?, «term__[_]_?»]
recommended_spelling "getElem!" for "xs[i]!" in [GetElem?.getElem!, «term__[_]_!»]
instance (priority := low) [GetElem coll idx elem valid] [∀ xs i, Decidable (valid xs i)] :
GetElem? coll idx elem valid where
getElem? xs i := decidableGetElem? xs i
theorem getElem_congr [GetElem coll idx elem valid] {c d : coll} (h : c = d)
{i j : idx} (h' : i = j) (w : valid c i) : c[i] = d[j]'(h' ▸ h ▸ w) := by
cases h; cases h'; rfl
theorem getElem_congr_coll [GetElem coll idx elem valid] {c d : coll} {i : idx} {w : valid c i}
(h : c = d) : c[i] = d[i]'(h ▸ w) := by
cases h; rfl
theorem getElem_congr_idx [GetElem coll idx elem valid] {c : coll} {i j : idx} {w : valid c i}
(h' : i = j) : c[i] = c[j]'(h' ▸ w) := by
cases h'; rfl
/--
Lawful `GetElem?` instances (which extend `GetElem`) are those for which the potentially-failing
`GetElem?.getElem?` and `GetElem?.getElem!` operators succeed when the validity predicate is
satisfied, and fail when it is not. |
@[simp, grind =] getElem?_pos [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) (h : dom c i) : c[i]? = some (c[i]'h) := by
have : Decidable (dom c i) := .isTrue h
rw [getElem?_def]
exact dif_pos h
@[simp, grind =] theorem getElem?_neg [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) (h : ¬dom c i) : c[i]? = none := by
have : Decidable (dom c i) := .isFalse h
rw [getElem?_def]
exact dif_neg h
@[simp, grind =] theorem getElem!_pos [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
[Inhabited elem] (c : cont) (i : idx) (h : dom c i) :
c[i]! = c[i]'h := by
have : Decidable (dom c i) := .isTrue h
simp [getElem!_def, h]
@[simp, grind =] theorem getElem!_neg [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
[Inhabited elem] (c : cont) (i : idx) (h : ¬dom c i) : c[i]! = default := by
have : Decidable (dom c i) := .isFalse h
simp [getElem!_def, h]
@[simp, grind =] theorem get_getElem? [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) [Decidable (dom c i)] (h) :
c[i]?.get h = c[i]'(by simp only [getElem?_def] at h; split at h <;> simp_all) := by
simp only [getElem?_def] at h ⊢
split <;> simp_all
@[simp] theorem getElem?_eq_none_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) [Decidable (dom c i)] : c[i]? = none ↔ ¬dom c i := by
simp only [getElem?_def]
split <;> simp_all
@[simp] theorem none_eq_getElem?_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) [Decidable (dom c i)] : none = c[i]? ↔ ¬dom c i := by
simp only [getElem?_def]
split <;> simp_all | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem | null |
of_getElem?_eq_some [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] (h : c[i]? = some e) : dom c i := by
simp only [getElem?_def] at h
split at h <;> rename_i h'
case isTrue =>
exact h'
case isFalse =>
simp at h | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | of_getElem | null |
getElem?_eq_some_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] : c[i]? = some e ↔ Exists fun h : dom c i => c[i] = e := by
simp only [getElem?_def]
split <;> rename_i h
case isTrue =>
constructor
case mp =>
intro w
refine ⟨h, ?_⟩
simpa using w
case mpr =>
intro ⟨h, w⟩
simpa using w
case isFalse =>
simp only [reduceCtorEq, false_iff]
intro ⟨w, w'⟩
exact h w | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem | null |
some_eq_getElem?_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] : some e = c[i]? ↔ Exists fun h : dom c i => c[i] = e := by
rw [eq_comm, getElem?_eq_some_iff] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | some_eq_getElem | null |
getElem_of_getElem? [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] (h : c[i]? = some e) : Exists fun h : dom c i => c[i] = e :=
getElem?_eq_some_iff.mp h | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_of_getElem | null |
of_getElem_eq [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] {h} (_ : c[i] = e) : dom c i := h
@[simp] theorem some_getElem_eq_getElem?_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] (h : dom c i):
(some c[i] = c[i]?) ↔ True := by
simp [h]
@[simp] theorem getElem?_eq_some_getElem_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
{c : cont} {i : idx} [Decidable (dom c i)] (h : dom c i):
(c[i]? = some c[i]) ↔ True := by
simp [h]
@[simp, grind =] theorem isSome_getElem? [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom]
(c : cont) (i : idx) [Decidable (dom c i)] : c[i]?.isSome = dom c i := by
simp only [getElem?_def]
split <;> simp_all | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | of_getElem_eq | null |
instGetElemFinVal [GetElem cont Nat elem dom] : GetElem cont (Fin n) elem fun xs i => dom xs i where
getElem xs i h := getElem xs i.1 h | instance | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | instGetElemFinVal | null |
instGetElem?FinVal [GetElem? cont Nat elem dom] : GetElem? cont (Fin n) elem fun xs i => dom xs i where
getElem? xs i := getElem? xs i.val
getElem! xs i := getElem! xs i.val | instance | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | instGetElem | null |
@[simp, grind =] getElem_fin [GetElem Cont Nat Elem Dom] (a : Cont) (i : Fin n) (h : Dom a i) :
a[i] = a[i.1] := rfl
@[simp, grind =] theorem getElem?_fin [h : GetElem? Cont Nat Elem Dom] (a : Cont) (i : Fin n) : a[i]? = a[i.1]? := rfl
@[simp, grind =] theorem getElem!_fin [GetElem? Cont Nat Elem Dom] (a : Cont) (i : Fin n) [Inhabited Elem] : a[i]! = a[i.1]! := rfl
macro_rules
| `(tactic| get_elem_tactic_extensible) => `(tactic| (with_reducible apply Fin.val_lt_of_le); get_elem_tactic_extensible; done) | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_fin | null |
@[simp, grind =]
getElem_cons_zero (a : α) (as : List α) (h : 0 < (a :: as).length) :
getElem (a :: as) 0 h = a := rfl
@[simp, grind =] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_cons_zero | null |
getElem_cons_succ (a : α) (as : List α) (i : Nat) (h : i + 1 < (a :: as).length) : getElem (a :: as) (i+1) h = getElem as i (Nat.lt_of_succ_lt_succ h) :=
rfl
@[simp] theorem getElem_mem : ∀ {l : List α} {n} (h : n < l.length), l[n]'h ∈ l
| _ :: _, 0, _ => .head ..
| _ :: l, _+1, _ => .tail _ (getElem_mem (l := l) ..)
grind_pattern getElem_mem => l[n]'h ∈ l
@[simp] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_cons_succ | null |
getElem_cons_drop {as : List α} {i : Nat} (h : i < as.length) :
as[i] :: as.drop (i+1) = as.drop i :=
match as, i with
| _::_, 0 => rfl
| _::_, i+1 => getElem_cons_drop (i := i) (Nat.add_one_lt_add_one_iff.mp h)
@[deprecated getElem_cons_drop (since := "2025-10-26")] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_cons_drop | null |
getElem_cons_drop_succ_eq_drop {as : List α} {i : Nat} (h : i < as.length) :
as[i] :: as.drop (i+1) = as.drop i := getElem_cons_drop h
/-! ### getElem? -/ | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem_cons_drop_succ_eq_drop | null |
get?Internal : (as : List α) → (i : Nat) → Option α
| a::_, 0 => some a
| _::as, n+1 => get?Internal as n
| _, _ => none | def | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | get | null |
get!Internal [Inhabited α] : (as : List α) → (i : Nat) → α
| a::_, 0 => a
| _::as, n+1 => get!Internal as n
| _, _ => panic! "invalid index" | def | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | get | null |
@[simp] get?Internal_eq_getElem? {l : List α} {i : Nat} :
l.get?Internal i = l[i]? := rfl
@[simp] theorem get!Internal_eq_getElem! [Inhabited α] {l : List α} {i : Nat} :
l.get!Internal i = l[i]! := rfl
-- This is only needed locally; after the `LawfulGetElem` instance the general `getElem?_pos` lemma applies.
@[local simp] theorem getElem?_eq_getElem {l : List α} {i} (h : i < l.length) :
l[i]? = some l[i] := by
induction l generalizing i with
| nil => cases h
| cons a l ih =>
cases i with
| zero => rfl
| succ i => exact ih ..
-- This is only needed locally; after the `LawfulGetElem` instance the general `getElem?_eq_none_iff` lemma applies.
@[local simp] theorem getElem?_eq_none_iff : l[i]? = none ↔ length l ≤ i :=
match l with
| [] => by simp; rfl
| _ :: l => by
cases i with
| zero => simp
| succ i =>
simp only [length_cons, Nat.add_le_add_iff_right]
exact getElem?_eq_none_iff (l := l) (i := i) | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | get | null |
none_eq_getElem?_iff {l : List α} {i : Nat} : none = l[i]? ↔ length l ≤ i := by
simp [eq_comm (a := none)] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | none_eq_getElem | null |
getElem?_eq_none (h : length l ≤ i) : l[i]? = none := getElem?_eq_none_iff.mpr h
grind_pattern getElem?_eq_none => l.length, l[i]? where
guard l.length ≤ i | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getElem | null |
@[simp] getInternal_eq_getElem (a : Array α) (i : Nat) (h) :
a.getInternal i h = a[i] := rfl
@[simp] theorem get!Internal_eq_getElem! [Inhabited α] (a : Array α) (i : Nat) :
a.get!Internal i = a[i]! := by
simp only [get!Internal, getD, getInternal_eq_getElem, getElem!_def]
split <;> simp_all [getElem?_pos, getElem?_neg] | theorem | Init.GetElem | [
"Init.Util"
] | Init/GetElem.lean | getInternal_eq_getElem | null |
and_true_curry {a b : Bool} {P : Prop}
(h : a → b → P) : (a && b) → P := by
rw [Bool.and_eq_true_iff]
intro h'
apply h h'.1 h'.2 | theorem | Init.LawfulBEqTactics | [
"Init.Core",
"Init.Data.Bool",
"Init.ByCases"
] | Init/LawfulBEqTactics.lean | and_true_curry | null |
deriving_lawful_beq_helper_dep {x y : α} [BEq α] [ReflBEq α]
{t : (x == y) = true → Bool} {P : Prop}
(inst : (x == y) = true → x = y)
(k : (h : x = y) → t (h ▸ ReflBEq.rfl) = true → P) :
(if h : (x == y) then t h else false) = true → P := by
intro h
by_cases hxy : x = y
· subst hxy
apply k rfl
rw [dif_pos (BEq.refl x)] at h
exact h
· by_cases hxy' : x == y
· exact False.elim <| hxy (inst hxy')
· rw [dif_neg hxy'] at h
contradiction | theorem | Init.LawfulBEqTactics | [
"Init.Core",
"Init.Data.Bool",
"Init.ByCases"
] | Init/LawfulBEqTactics.lean | deriving_lawful_beq_helper_dep | null |
deriving_lawful_beq_helper_nd {x y : α} [BEq α] [ReflBEq α]
{P : Prop}
(inst : (x == y) = true → x = y)
(k : x = y → P) :
(x == y) = true → P := by
intro h
by_cases hxy : x = y
· subst hxy
apply k rfl
· exact False.elim <| hxy (inst h) | theorem | Init.LawfulBEqTactics | [
"Init.Core",
"Init.Data.Bool",
"Init.ByCases"
] | Init/LawfulBEqTactics.lean | deriving_lawful_beq_helper_nd | null |
NameGenerator where
namePrefix : Name := `_uniq
idx : Nat := 1
deriving Inhabited | structure | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | NameGenerator | null |
Module where
header : Syntax
commands : Array Syntax | structure | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | Module | Syntax objects for a Lean module. |
TransparencyMode where
/-- Unfolds all constants, even those tagged as `@[irreducible]`. -/
| all
/-- Unfolds all constants except those tagged as `@[irreducible]`. -/
| default
/-- Unfolds only constants tagged with the `@[reducible]` attribute. -/
| reducible
/-- Unfolds reducible constants and constants tagged with the `@[instance]` attribute. -/
| instances
/-- Do not unfold anything -/
| none
deriving Inhabited, BEq | inductive | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | TransparencyMode | Which constants should be unfolded? |
EtaStructMode where
/-- Enable eta for structure and classes. -/
| all
/-- Enable eta only for structures that are not classes. -/
| notClasses
/-- Disable eta for structures and classes. -/
| none
deriving Inhabited, BEq | inductive | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | EtaStructMode | Which structure types should eta be used with? |
Config where
/--
When `true` (default: `true`), performs zeta reduction of `let` and `have` expressions.
That is, `let x := v; e[x]` reduces to `e[v]`.
If `zetaHave` is `false` then `have` expressions are not zeta reduced.
See also `zetaDelta`.
-/
zeta : Bool := true
/--
When `true` (default: `true`), performs beta reduction of applications of `fun` expressions.
That is, `(fun x => e[x]) v` reduces to `e[v]`.
-/
beta : Bool := true
/--
TODO (currently unimplemented). When `true` (default: `true`), performs eta reduction for `fun` expressions.
That is, `(fun x => f x)` reduces to `f`.
-/
eta : Bool := true
/--
Configures how to determine definitional equality between two structure instances.
See documentation for `Lean.Meta.EtaStructMode`.
-/
etaStruct : EtaStructMode := .all
/--
When `true` (default: `true`), reduces `match` expressions applied to constructors.
-/
iota : Bool := true
/--
When `true` (default: `true`), reduces projections of structure constructors.
-/
proj : Bool := true
/--
When `true` (default: `false`), rewrites a proposition `p` to `True` or `False` by inferring
a `Decidable p` instance and reducing it.
-/
decide : Bool := false
/--
When `true` (default: `false`), unfolds applications of functions defined by pattern matching, when one of the patterns applies.
This can be enabled using the `simp!` syntax.
-/
autoUnfold : Bool := false
/--
If `failIfUnchanged` is `true` (default: `true`), then calls to `simp`, `dsimp`, or `simp_all`
will fail if they do not make progress.
-/
failIfUnchanged : Bool := true
/--
If `unfoldPartialApp` is `true` (default: `false`), then calls to `simp`, `dsimp`, or `simp_all`
will unfold even partial applications of `f` when we request `f` to be unfolded.
-/
... | structure | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | Config | The configuration for `dsimp`.
Passed to `dsimp` using, for example, the `dsimp (config := {zeta := false})` syntax.
Implementation note: this structure is only used for processing the `(config := ...)` syntax, and it is not used internally.
It is immediately converted to `Lean.Meta.Simp.Config` by `Lean.Elab.Tactic.elabSimpConfig`. |
defaultMaxSteps := 100000 | def | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | defaultMaxSteps | null |
Config where
/--
The maximum number of subexpressions to visit when performing simplification.
The default is 100000.
-/
maxSteps : Nat := defaultMaxSteps
/--
When simp discharges side conditions for conditional lemmas, it can recursively apply simplification.
The `maxDischargeDepth` (default: 2) is the maximum recursion depth when recursively applying simplification to side conditions.
-/
maxDischargeDepth : Nat := 2
/--
When `contextual` is true (default: `false`) and simplification encounters an implication `p → q`
it includes `p` as an additional simp lemma when simplifying `q`.
-/
contextual : Bool := false
/--
When true (default: `true`) then the simplifier caches the result of simplifying each sub-expression, if possible.
-/
memoize : Bool := true
/--
When `singlePass` is `true` (default: `false`), the simplifier runs through a single round of simplification,
which consists of running pre-methods, recursing using congruence lemmas, and then running post-methods.
Otherwise, when it is `false`, it iteratively applies this simplification procedure.
-/
singlePass : Bool := false
/--
When `true` (default: `true`), performs zeta reduction of `let` and `have` expressions.
That is, `let x := v; e[x]` reduces to `e[v]`.
If `zetaHave` is `false` then `have` expressions are not zeta reduced.
See also `zetaDelta`.
-/
zeta : Bool := true
/--
When `true` (default: `true`), performs beta reduction of applications of `fun` expressions.
That is, `(fun x => e[x]) v` reduces to `e[v]`.
-/
beta : Bool := true
/--
TODO (currently unimplemented). When `true` (default: `true`), performs eta reduction for `fun` expressions.
That is, `(fun x => f x)` reduces to `f`.
-/
eta : Bool := true
/--
Configures how to determine definitional equality between two structure instances.
See documentation for `Lean.Meta.EtaStructMode`.
-/
etaStruct : EtaStructMode := .all
/--
When `true` (default: `true`), reduces `match` expressions applied to constructors.
... | structure | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | Config | The configuration for `simp`.
Passed to `simp` using, for example, the `simp +contextual` or `simp (maxSteps := 100000)` syntax.
See also `Lean.Meta.Simp.neutralConfig` and `Lean.Meta.DSimp.Config`. |
ConfigCtx extends Config where
contextual := true | structure | Init.MetaTypes | [
"Init.Core"
] | Init/MetaTypes.lean | ConfigCtx | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.