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 ⌀ |
|---|---|---|---|---|---|---|
MonadQuotation.getMainModule := @MonadQuotation.getContext | abbrev | Init.Prelude | [] | Init/Prelude.lean | MonadQuotation.getMainModule | null |
@[inline]
MonadRef.mkInfoFromRefPos [Monad m] [MonadRef m] : m SourceInfo :=
return SourceInfo.fromRef (← getRef) | def | Init.Prelude | [] | Init/Prelude.lean | MonadRef.mkInfoFromRefPos | Construct a synthetic `SourceInfo` from the `ref` in the monad state. |
@[expose] Name.hasMacroScopes : Name → Bool
| str _ s => beq s "_hyg"
| num p _ => hasMacroScopes p
| _ => false | def | Init.Prelude | [] | Init/Prelude.lean | Name.hasMacroScopes | Does this name have hygienic macro scopes? |
private eraseMacroScopesAux : Name → Name
| .str p s => match beq s "_@" with
| true => p
| false => eraseMacroScopesAux p
| .num p _ => eraseMacroScopesAux p
| .anonymous => Name.anonymous | def | Init.Prelude | [] | Init/Prelude.lean | eraseMacroScopesAux | null |
@[export lean_erase_macro_scopes]
Name.eraseMacroScopes (n : Name) : Name :=
match n.hasMacroScopes with
| true => eraseMacroScopesAux n
| false => n | def | Init.Prelude | [] | Init/Prelude.lean | Name.eraseMacroScopes | Remove the macro scopes from the name. |
private simpMacroScopesAux : Name → Name
| .num p i => Name.mkNum (simpMacroScopesAux p) i
| n => eraseMacroScopesAux n | def | Init.Prelude | [] | Init/Prelude.lean | simpMacroScopesAux | null |
@[export lean_simp_macro_scopes]
Name.simpMacroScopes (n : Name) : Name :=
match n.hasMacroScopes with
| true => simpMacroScopesAux n
| false => n | def | Init.Prelude | [] | Init/Prelude.lean | Name.simpMacroScopes | Helper function we use to create binder names that do not need to be unique. |
MacroScopesView where
/-- The original (unhygienic) name. -/
name : Name
/-- All the name components `(<module_name>.<scopes>)*` from the imports
concatenated together. -/
imported : Name
/-- The context name, a globally unique prefix. -/
ctx : Name
/-- The list of macro scopes. -/
scopes : List MacroScope | structure | Init.Prelude | [] | Init/Prelude.lean | MacroScopesView | A `MacroScopesView` represents a parsed hygienic name. `extractMacroScopes`
will decode it from a `Name`, and `.review` will re-encode it. The grammar of a
hygienic name is:
```
<name>._@.(<module_name>.<scopes>)*.<mainModule>._hyg.<scopes>
``` |
MacroScopesView.review (view : MacroScopesView) : Name :=
match view.scopes with
| List.nil => view.name
| List.cons _ _ =>
let base := (Name.mkStr (Name.appendCore (Name.appendCore (Name.mkStr view.name "_@") view.imported) view.ctx) "_hyg")
view.scopes.foldl Name.mkNum base | def | Init.Prelude | [] | Init/Prelude.lean | MacroScopesView.review | Encode a hygienic name from the parsed pieces. |
private assembleParts : List Name → Name → Name
| .nil, acc => acc
| .cons (.str _ s) ps, acc => assembleParts ps (Name.mkStr acc s)
| .cons (.num _ n) ps, acc => assembleParts ps (Name.mkNum acc n)
| _, _ => panic "Error: unreachable @ assembleParts" | def | Init.Prelude | [] | Init/Prelude.lean | assembleParts | null |
private extractImported (scps : List MacroScope) (mainModule : Name) : Name → List Name → MacroScopesView
| n@(Name.str p str), parts =>
match beq str "_@" with
| true => { name := p, ctx := mainModule, imported := assembleParts parts Name.anonymous, scopes := scps }
| false => extractImported scps mainModule p (List.cons n parts)
| n@(Name.num p _), parts => extractImported scps mainModule p (List.cons n parts)
| _, _ => panic "Error: unreachable @ extractImported" | def | Init.Prelude | [] | Init/Prelude.lean | extractImported | null |
private extractMainModule (scps : List MacroScope) : Name → List Name → MacroScopesView
| n@(Name.str p str), parts =>
match beq str "_@" with
| true => { name := p, ctx := assembleParts parts Name.anonymous, imported := Name.anonymous, scopes := scps }
| false => extractMainModule scps p (List.cons n parts)
| n@(Name.num _ _), acc => extractImported scps (assembleParts acc Name.anonymous) n List.nil
| _, _ => panic "Error: unreachable @ extractMainModule" | def | Init.Prelude | [] | Init/Prelude.lean | extractMainModule | null |
private extractMacroScopesAux : Name → List MacroScope → MacroScopesView
| Name.num p scp, acc => extractMacroScopesAux p (List.cons scp acc)
| Name.str p _ , acc => extractMainModule acc p List.nil -- str must be "_hyg"
| _, _ => panic "Error: unreachable @ extractMacroScopesAux" | def | Init.Prelude | [] | Init/Prelude.lean | extractMacroScopesAux | null |
extractMacroScopes (n : Name) : MacroScopesView :=
match n.hasMacroScopes with
| true => extractMacroScopesAux n List.nil
| false => { name := n, scopes := List.nil, imported := Name.anonymous, ctx := Name.anonymous } | def | Init.Prelude | [] | Init/Prelude.lean | extractMacroScopes | Revert all `addMacroScope` calls. `v = extractMacroScopes n → n = v.review`.
This operation is useful for analyzing/transforming the original identifiers, then adding back
the scopes (via `MacroScopesView.review`). |
addMacroScope (ctx : Name) (n : Name) (scp : MacroScope) : Name :=
match n.hasMacroScopes with
| true =>
let view := extractMacroScopes n
match beq view.ctx ctx with
| true => Name.mkNum n scp
| false =>
{ view with
imported := view.scopes.foldl Name.mkNum (Name.appendCore view.imported view.ctx)
ctx := ctx
scopes := List.cons scp List.nil
}.review
| false =>
Name.mkNum (Name.mkStr (Name.appendCore (Name.mkStr n "_@") ctx) "_hyg") scp | def | Init.Prelude | [] | Init/Prelude.lean | addMacroScope | Add a new macro scope onto the name `n`, in the given `ctx`. |
@[expose] Name.append (a b : Name) : Name :=
match a.hasMacroScopes, b.hasMacroScopes with
| true, true =>
panic "Error: invalid `Name.append`, both arguments have macro scopes, consider using `eraseMacroScopes`"
| true, false =>
let view := extractMacroScopes a
{ view with name := appendCore view.name b }.review
| false, true =>
let view := extractMacroScopes b
{ view with name := appendCore a view.name }.review
| false, false => appendCore a b | def | Init.Prelude | [] | Init/Prelude.lean | Name.append | Appends two names `a` and `b`, propagating macro scopes from `a` or `b`, if any, to the result.
Panics if both `a` and `b` have macro scopes.
This function is used for the `Append Name` instance.
See also `Lean.Name.appendCore`, which appends names without any consideration for macro scopes.
Also consider `Lean.Name.eraseMacroScopes` to erase macro scopes before appending, if appropriate. |
@[inline] MonadQuotation.addMacroScope {m : Type → Type} [MonadQuotation m] [Monad m] (n : Name) : m Name :=
bind MonadQuotation.getContext fun ctx =>
bind getCurrMacroScope fun scp =>
pure (Lean.addMacroScope ctx n scp) | def | Init.Prelude | [] | Init/Prelude.lean | MonadQuotation.addMacroScope | Add a new macro scope onto the name `n`, using the monad state to supply the
main module and current macro scope. |
matchesNull (stx : Syntax) (n : Nat) : Bool :=
stx.isNodeOf nullKind n | def | Init.Prelude | [] | Init/Prelude.lean | matchesNull | Is this syntax a null `node`? |
matchesIdent (stx : Syntax) (id : Name) : Bool :=
and stx.isIdent (beq stx.getId.eraseMacroScopes id.eraseMacroScopes) | def | Init.Prelude | [] | Init/Prelude.lean | matchesIdent | Function used for determining whether a syntax pattern `` `(id) `` is matched.
There are various conceivable notions of when two syntactic identifiers should be regarded as identical,
but semantic definitions like whether they refer to the same global name cannot be implemented without
context information (i.e. `MonadResolveName`). Thus in patterns we default to the structural solution
of comparing the identifiers' `Name` values, though we at least do so modulo macro scopes so that
identifiers that "look" the same match. This is particularly useful when dealing with identifiers that
do not actually refer to Lean bindings, e.g. in the `stx` pattern `` `(many($p)) ``. |
matchesLit (stx : Syntax) (k : SyntaxNodeKind) (val : String) : Bool :=
match stx with
| Syntax.node _ k' args => and (beq k k') (match args.getD 0 Syntax.missing with
| Syntax.atom _ val' => beq val val'
| _ => false)
| _ => false | def | Init.Prelude | [] | Init/Prelude.lean | matchesLit | Is this syntax a node kind `k` wrapping an `atom _ val`? |
Context where
/-- An opaque reference to the `Methods` object. This is done to break a
dependency cycle: the `Methods` involve `MacroM` which has not been defined yet. -/
methods : MethodsRef
/-- The quotation context name for `MonadQuotation.getContext`. -/
quotContext : Name
/-- The current macro scope. -/
currMacroScope : MacroScope
/-- The current recursion depth. -/
currRecDepth : Nat := 0
/-- The maximum recursion depth. -/
maxRecDepth : Nat := defaultMaxRecDepth
/-- The syntax which supplies the position of error messages. -/
ref : Syntax | structure | Init.Prelude | [] | Init/Prelude.lean | Context | References -/
-- TODO: make private again and make Nonempty instance no_expose instead after bootstrapping
opaque MethodsRefPointed : NonemptyType.{0}
set_option linter.missingDocs false in
@[expose] def MethodsRef : Type := MethodsRefPointed.type
instance : Nonempty MethodsRef := MethodsRefPointed.property
/-- The read-only context for the `MacroM` monad. |
Exception where
/-- A general error, given a message and a span (expressed as a `Syntax`). -/
| error : Syntax → String → Exception
/-- An unsupported syntax exception. We keep this separate because it is
used for control flow: if one macro does not support a syntax then we try
the next one. -/
| unsupportedSyntax : Exception | inductive | Init.Prelude | [] | Init/Prelude.lean | Exception | An exception in the `MacroM` monad. |
State where
/-- The global macro scope counter, used for producing fresh scope names. -/
macroScope : MacroScope
/-- The list of trace messages that have been produced, each with a trace
class and a message. -/
traceMsgs : List (Prod Name String) := List.nil
/-- Declaration names of expanded macros, for use with `shake`. -/
private expandedMacroDecls : List Name := List.nil
deriving Inhabited | structure | Init.Prelude | [] | Init/Prelude.lean | State | The mutable state for the `MacroM` monad. |
MacroM := ReaderT Macro.Context (EStateM Macro.Exception Macro.State) | abbrev | Init.Prelude | [] | Init/Prelude.lean | MacroM | The `MacroM` monad is the main monad for macro expansion. It has the
information needed to handle hygienic name generation, and is the monad that
`macro` definitions live in.
Notably, this is a (relatively) pure monad: there is no `IO` and no access to
the `Environment`. That means that things like declaration lookup are
impossible here, as well as `IO.Ref` or other side-effecting operations.
For more capabilities, macros can instead be written as `elab` using `adaptExpander`. |
Macro := Syntax → MacroM Syntax | abbrev | Init.Prelude | [] | Init/Prelude.lean | Macro | A `macro` has type `Macro`, which is a `Syntax → MacroM Syntax`: it
receives an input syntax and is supposed to "expand" it into another piece of
syntax. |
throwUnsupported {α} : MacroM α :=
throw Exception.unsupportedSyntax | def | Init.Prelude | [] | Init/Prelude.lean | throwUnsupported | Throw an `unsupportedSyntax` exception. |
throwError {α} (msg : String) : MacroM α :=
bind getRef fun ref =>
throw (Exception.error ref msg) | def | Init.Prelude | [] | Init/Prelude.lean | throwError | Throw an error with the given message,
using the `ref` for the location information. |
throwErrorAt {α} (ref : Syntax) (msg : String) : MacroM α :=
withRef ref (throwError msg) | def | Init.Prelude | [] | Init/Prelude.lean | throwErrorAt | Throw an error with the given message and location information. |
@[inline] protected withFreshMacroScope {α} (x : MacroM α) : MacroM α :=
bind (modifyGet (fun s => (s.macroScope, { s with macroScope := hAdd s.macroScope 1 }))) fun fresh =>
withReader (fun ctx => { ctx with currMacroScope := fresh }) x | def | Init.Prelude | [] | Init/Prelude.lean | withFreshMacroScope | Increments the macro scope counter so that inside the body of `x` the macro
scope is fresh. |
@[inline] withIncRecDepth {α} (ref : Syntax) (x : MacroM α) : MacroM α :=
bind read fun ctx =>
match beq ctx.currRecDepth ctx.maxRecDepth with
| true => throw (Exception.error ref maxRecDepthErrorMessage)
| false => withReader (fun ctx => { ctx with currRecDepth := hAdd ctx.currRecDepth 1 }) x | def | Init.Prelude | [] | Init/Prelude.lean | withIncRecDepth | Run `x` with an incremented recursion depth counter. |
addMacroScope (n : Name) : MacroM Name :=
MonadQuotation.addMacroScope n | def | Init.Prelude | [] | Init/Prelude.lean | addMacroScope | Add a new macro scope to the name `n`. |
Methods where
/-- Expands macros in the given syntax. A return value of `none` means there
was nothing to expand. -/
expandMacro? : Syntax → MacroM (Option Syntax)
/-- Get the current namespace in the file. -/
getCurrNamespace : MacroM Name
/-- Check if a given name refers to a declaration. -/
hasDecl : Name → MacroM Bool
/-- Resolves the given name to an overload list of namespaces. -/
resolveNamespace : Name → MacroM (List Name)
/-- Resolves the given name to an overload list of global definitions.
The `List String` in each alternative is the deduced list of projections
(which are ambiguous with name components). -/
resolveGlobalName : Name → MacroM (List (Prod Name (List String)))
deriving Inhabited | structure | Init.Prelude | [] | Init/Prelude.lean | Methods | The opaque methods that are available to `MacroM`. |
unsafe mkMethodsImp (methods : Methods) : MethodsRef :=
unsafeCast methods | def | Init.Prelude | [] | Init/Prelude.lean | mkMethodsImp | Implementation of `mkMethods`. |
@[implemented_by mkMethodsImp]
mkMethods (methods : Methods) : MethodsRef | opaque | Init.Prelude | [] | Init/Prelude.lean | mkMethods | Make an opaque reference to a `Methods`. |
unsafe getMethodsImp : MacroM Methods :=
bind read fun ctx => pure (unsafeCast (ctx.methods)) | def | Init.Prelude | [] | Init/Prelude.lean | getMethodsImp | Implementation of `getMethods`. |
@[implemented_by getMethodsImp] getMethods : MacroM Methods | opaque | Init.Prelude | [] | Init/Prelude.lean | getMethods | Extract the methods list from the `MacroM` state. |
expandMacro? (stx : Syntax) : MacroM (Option Syntax) := do
(← getMethods).expandMacro? stx | def | Init.Prelude | [] | Init/Prelude.lean | expandMacro | `expandMacro? stx` returns `some stxNew` if `stx` is a macro,
and `stxNew` is its expansion. |
hasDecl (declName : Name) : MacroM Bool := do
(← getMethods).hasDecl declName | def | Init.Prelude | [] | Init/Prelude.lean | hasDecl | Returns `true` if the environment contains a declaration with name `declName` |
getCurrNamespace : MacroM Name := do
(← getMethods).getCurrNamespace
/-- Resolves the given name to an overload list of namespaces. -/ | def | Init.Prelude | [] | Init/Prelude.lean | getCurrNamespace | Gets the current namespace given the position in the file. |
resolveNamespace (n : Name) : MacroM (List Name) := do
(← getMethods).resolveNamespace n | def | Init.Prelude | [] | Init/Prelude.lean | resolveNamespace | null |
resolveGlobalName (n : Name) : MacroM (List (Prod Name (List String))) := do
(← getMethods).resolveGlobalName n | def | Init.Prelude | [] | Init/Prelude.lean | resolveGlobalName | Resolves the given name to an overload list of global definitions.
The `List String` in each alternative is the deduced list of projections
(which are ambiguous with name components).
Remark: it will not trigger actions associated with reserved names. Recall that Lean
has reserved names. For example, a definition `foo` has a reserved name `foo.def` for theorem
containing stating that `foo` is equal to its definition. The action associated with `foo.def`
automatically proves the theorem. At the macro level, the name is resolved, but the action is not
executed. The actions are executed by the elaborator when converting `Syntax` into `Expr`. |
trace (clsName : Name) (msg : String) : MacroM Unit := do
modify fun s => { s with traceMsgs := List.cons (Prod.mk clsName msg) s.traceMsgs } | def | Init.Prelude | [] | Init/Prelude.lean | trace | Add a new trace message, with the given trace class and message. |
UnexpandM := ReaderT Syntax (EStateM Unit Unit) | abbrev | Init.Prelude | [] | Init/Prelude.lean | UnexpandM | The unexpander monad, essentially `Syntax → Option α`. The `Syntax` is the `ref`,
and it has the possibility of failure without an error message. |
Unexpander := Syntax → UnexpandM Syntax | abbrev | Init.Prelude | [] | Init/Prelude.lean | Unexpander | null |
@[simp] eq_mp_eq_cast (h : α = β) : Eq.mp h = cast h := rfl
@[simp] theorem eq_mpr_eq_cast (h : α = β) : Eq.mpr h = cast h.symm := rfl
@[simp] theorem cast_cast : ∀ (ha : α = β) (hb : β = γ) (a : α),
cast hb (cast ha a) = cast (ha.trans hb) a
| rfl, rfl, _ => rfl
@[simp] theorem eq_true_eq_id : Eq True = id := by
funext _; simp only [true_iff, id_def, eq_iff_iff] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | eq_mp_eq_cast | null |
proof_irrel_heq {p q : Prop} (hp : p) (hq : q) : hp ≍ hq := by
cases propext (iff_of_true hp hq); rfl
/-! ## not -/ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | proof_irrel_heq | null |
not_not_em (a : Prop) : ¬¬(a ∨ ¬a) := fun h => h (.inr (h ∘ .inl))
/-! ## and -/ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_not_em | null |
and_self_iff : a ∧ a ↔ a := Iff.of_eq (and_self a) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_self_iff | null |
and_not_self_iff (a : Prop) : a ∧ ¬a ↔ False := iff_false_intro and_not_self | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_not_self_iff | null |
not_and_self_iff (a : Prop) : ¬a ∧ a ↔ False := iff_false_intro not_and_self | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_and_self_iff | null |
And.imp (f : a → c) (g : b → d) (h : a ∧ b) : c ∧ d := And.intro (f h.left) (g h.right) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | And.imp | null |
And.imp_left (h : a → b) : a ∧ c → b ∧ c := .imp h id | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | And.imp_left | null |
And.imp_right (h : a → b) : c ∧ a → c ∧ b := .imp id h | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | And.imp_right | null |
and_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : a ∧ b ↔ c ∧ d :=
Iff.intro (And.imp h₁.mp h₂.mp) (And.imp h₁.mpr h₂.mpr) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_congr | null |
and_congr_left' (h : a ↔ b) : a ∧ c ↔ b ∧ c := and_congr h .rfl | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_congr_left' | null |
and_congr_right' (h : b ↔ c) : a ∧ b ↔ a ∧ c := and_congr .rfl h | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_congr_right' | null |
not_and_of_not_left (b : Prop) : ¬a → ¬(a ∧ b) := mt And.left | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_and_of_not_left | null |
not_and_of_not_right (a : Prop) {b : Prop} : ¬b → ¬(a ∧ b) := mt And.right | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_and_of_not_right | null |
and_congr_right_eq (h : a → b = c) : (a ∧ b) = (a ∧ c) :=
propext (and_congr_right (Iff.of_eq ∘ h)) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_congr_right_eq | null |
and_congr_left_eq (h : c → a = b) : (a ∧ c) = (b ∧ c) :=
propext (and_congr_left (Iff.of_eq ∘ h)) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_congr_left_eq | null |
and_left_comm : a ∧ b ∧ c ↔ b ∧ a ∧ c :=
Iff.intro (fun ⟨ha, hb, hc⟩ => ⟨hb, ha, hc⟩)
(fun ⟨hb, ha, hc⟩ => ⟨ha, hb, hc⟩) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_left_comm | null |
and_right_comm : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b :=
Iff.intro (fun ⟨⟨ha, hb⟩, hc⟩ => ⟨⟨ha, hc⟩, hb⟩)
(fun ⟨⟨ha, hc⟩, hb⟩ => ⟨⟨ha, hb⟩, hc⟩) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_right_comm | null |
and_rotate : a ∧ b ∧ c ↔ b ∧ c ∧ a := by rw [and_left_comm, @and_comm a c] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_rotate | null |
and_and_and_comm : (a ∧ b) ∧ c ∧ d ↔ (a ∧ c) ∧ b ∧ d := by rw [← and_assoc, @and_right_comm a, and_assoc] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_and_and_comm | null |
and_and_left : a ∧ (b ∧ c) ↔ (a ∧ b) ∧ a ∧ c := by rw [and_and_and_comm, and_self] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_and_left | null |
and_and_right : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b ∧ c := by rw [and_and_and_comm, and_self] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_and_right | null |
and_iff_left (hb : b) : a ∧ b ↔ a := Iff.intro And.left (And.intro · hb) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_iff_left | null |
and_iff_right (ha : a) : a ∧ b ↔ b := Iff.intro And.right (And.intro ha ·)
/-! ## or -/ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_iff_right | null |
or_self_iff : a ∨ a ↔ a := or_self _ ▸ .rfl | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_self_iff | null |
not_or_intro {a b : Prop} (ha : ¬a) (hb : ¬b) : ¬(a ∨ b) := (·.elim ha hb) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_or_intro | null |
or_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∨ b) ↔ (c ∨ d) := ⟨.imp h₁.mp h₂.mp, .imp h₁.mpr h₂.mpr⟩ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_congr | null |
or_congr_left (h : a ↔ b) : a ∨ c ↔ b ∨ c := or_congr h .rfl | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_congr_left | null |
or_congr_right (h : b ↔ c) : a ∨ b ↔ a ∨ c := or_congr .rfl h | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_congr_right | null |
or_left_comm : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) := by rw [← or_assoc, ← or_assoc, @or_comm a b] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_left_comm | null |
or_right_comm : (a ∨ b) ∨ c ↔ (a ∨ c) ∨ b := by rw [or_assoc, or_assoc, @or_comm b] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_right_comm | null |
or_or_or_comm : (a ∨ b) ∨ c ∨ d ↔ (a ∨ c) ∨ b ∨ d := by rw [← or_assoc, @or_right_comm a, or_assoc] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_or_or_comm | null |
or_or_distrib_left : a ∨ b ∨ c ↔ (a ∨ b) ∨ a ∨ c := by rw [or_or_or_comm, or_self] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_or_distrib_left | null |
or_or_distrib_right : (a ∨ b) ∨ c ↔ (a ∨ c) ∨ b ∨ c := by rw [or_or_or_comm, or_self] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_or_distrib_right | null |
or_rotate : a ∨ b ∨ c ↔ b ∨ c ∨ a := by simp only [or_left_comm, Or.comm] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_rotate | null |
or_iff_left (hb : ¬b) : a ∨ b ↔ a := or_iff_left_iff_imp.mpr hb.elim | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_iff_left | null |
or_iff_right (ha : ¬a) : a ∨ b ↔ b := or_iff_right_iff_imp.mpr ha.elim
/-! ## distributivity -/ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_iff_right | null |
not_imp_of_and_not : a ∧ ¬b → ¬(a → b)
| ⟨ha, hb⟩, h => hb <| h ha | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_imp_of_and_not | null |
imp_and {α} : (α → b ∧ c) ↔ (α → b) ∧ (α → c) :=
⟨fun h => ⟨fun ha => (h ha).1, fun ha => (h ha).2⟩, fun h ha => ⟨h.1 ha, h.2 ha⟩⟩ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | imp_and | null |
not_and' : ¬(a ∧ b) ↔ b → ¬a := Iff.trans not_and imp_not_comm | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_and' | null |
and_or_left : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) :=
Iff.intro (fun ⟨ha, hbc⟩ => hbc.imp (.intro ha) (.intro ha))
(Or.rec (.imp_right .inl) (.imp_right .inr)) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_or_left | `∧` distributes over `∨` (on the left). |
or_and_right : (a ∨ b) ∧ c ↔ (a ∧ c) ∨ (b ∧ c) := by rw [@and_comm (a ∨ b), and_or_left, @and_comm c, @and_comm c] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_and_right | `∧` distributes over `∨` (on the right). |
or_and_left : a ∨ (b ∧ c) ↔ (a ∨ b) ∧ (a ∨ c) :=
Iff.intro (Or.rec (fun ha => ⟨.inl ha, .inl ha⟩) (.imp .inr .inr))
(And.rec <| .rec (fun _ => .inl ·) (.imp_right ∘ .intro)) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_and_left | `∨` distributes over `∧` (on the left). |
and_or_right : (a ∧ b) ∨ c ↔ (a ∨ c) ∧ (b ∨ c) := by rw [@or_comm (a ∧ b), or_and_left, @or_comm c, @or_comm c] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | and_or_right | `∨` distributes over `∧` (on the right). |
or_imp : (a ∨ b → c) ↔ (a → c) ∧ (b → c) :=
Iff.intro (fun h => ⟨h ∘ .inl, h ∘ .inr⟩) (fun ⟨ha, hb⟩ => Or.rec ha hb)
/-
`not_or` is made simp for confluence with `¬((b || c) = true)`:
Critical pair:
1. `¬(b = true ∨ c = true)` via `Bool.or_eq_true`.
2. `(b || c = false)` via `Bool.not_eq_true` which then
reduces to `b = false ∧ c = false` via Mathlib simp lemma
`Bool.or_eq_false_eq_eq_false_and_eq_false`.
Both reduce to `b = false ∧ c = false` via `not_or`.
-/
@[simp] theorem not_or : ¬(p ∨ q) ↔ ¬p ∧ ¬q := or_imp | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | or_imp | null |
not_and_of_not_or_not (h : ¬a ∨ ¬b) : ¬(a ∧ b) := h.elim (mt (·.1)) (mt (·.2))
/-! ## not equal -/ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | not_and_of_not_or_not | null |
ne_of_apply_ne {α β : Sort _} (f : α → β) {x y : α} : f x ≠ f y → x ≠ y :=
mt <| congrArg _
/-! ## Ite -/
@[simp] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | ne_of_apply_ne | null |
if_false_left [h : Decidable p] :
ite p False q ↔ ¬p ∧ q := by cases h <;> (rename_i g; simp [g])
@[simp] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | if_false_left | null |
if_false_right [h : Decidable p] :
ite p q False ↔ p ∧ q := by cases h <;> (rename_i g; simp [g])
/-
`if_true_left` and `if_true_right` are lower priority because
they introduce disjunctions and we prefer `if_false_left` and
`if_false_right` if they overlap.
-/
@[simp low] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | if_false_right | null |
if_true_left [h : Decidable p] :
ite p True q ↔ ¬p → q := by cases h <;> (rename_i g; simp [g])
@[simp low] | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | if_true_left | null |
if_true_right [h : Decidable p] :
ite p q True ↔ p → q := by cases h <;> (rename_i g; simp [g]) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | if_true_right | null |
@[simp] dite_not [hn : Decidable (¬p)] [h : Decidable p] (x : ¬p → α) (y : ¬¬p → α) :
dite (¬p) x y = dite p (fun h => y (not_not_intro h)) x := by
cases h <;> (rename_i g; simp [g]) | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | dite_not | Negation of the condition `P : Prop` in a `dite` is the same as swapping the branches. |
@[simp] ite_not (p : Prop) [Decidable p] (x y : α) : ite (¬p) x y = ite p y x :=
dite_not (fun _ => x) (fun _ => y)
@[simp] theorem ite_then_self {p q : Prop} [h : Decidable p] : (if p then p else q) ↔ (¬p → q) := by
cases h <;> (rename_i g; simp [g])
@[simp] theorem ite_else_self {p q : Prop} [h : Decidable p] : (if p then q else p) ↔ (p ∧ q) := by
cases h <;> (rename_i g; simp [g])
@[simp] theorem ite_then_not_self {p : Prop} [Decidable p] {q : Prop} : (if p then ¬p else q) ↔ ¬p ∧ q := by
split <;> simp_all
@[simp] theorem ite_else_not_self {p : Prop} [Decidable p] {q : Prop} : (if p then q else ¬p) ↔ p → q := by
split <;> simp_all | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | ite_not | Negation of the condition `P : Prop` in a `ite` is the same as swapping the branches. |
@[simp] forall_exists_index {q : (∃ x, p x) → Prop} :
(∀ h, q h) ↔ ∀ x (h : p x), q ⟨x, h⟩ :=
⟨fun h x hpx => h ⟨x, hpx⟩, fun h ⟨x, hpx⟩ => h x hpx⟩ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | forall_exists_index | If two if-then-else statements only differ by the `Decidable` instances, they are equal. -/
-- This is useful for ensuring confluence, but rarely otherwise.
@[simp] theorem ite_eq_ite (p : Prop) {h h' : Decidable p} (x y : α) :
(@ite _ p h x y = @ite _ p h' x y) ↔ True := by
simp
congr
/-- If two if-then-else statements only differ by the `Decidable` instances, they are equal. -/
-- This is useful for ensuring confluence, but rarely otherwise.
@[simp] theorem ite_iff_ite (p : Prop) {h h' : Decidable p} (x y : Prop) :
(@ite _ p h x y ↔ @ite _ p h' x y) ↔ True := by
rw [iff_true]
suffices @ite _ p h x y = @ite _ p h' x y by simp [this]
congr
/-! ## exists and forall -/
section quantifiers
variable {p q : α → Prop} {b : Prop}
theorem forall_imp (h : ∀ a, p a → q a) : (∀ a, p a) → ∀ a, q a := fun h' a => h a (h' a)
/--
As `simp` does not index foralls, this `@[simp]` lemma is tried on every `forall` expression.
This is not ideal, and likely a performance issue, but it is difficult to remove this attribute at this time. |
Exists.imp (h : ∀ a, p a → q a) : (∃ a, p a) → ∃ a, q a
| ⟨a, hp⟩ => ⟨a, h a hp⟩ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | Exists.imp | null |
Exists.imp' {β} {q : β → Prop} (f : α → β) (hpq : ∀ a, p a → q (f a)) :
(∃ a, p a) → ∃ b, q b
| ⟨_, hp⟩ => ⟨_, hpq _ hp⟩ | theorem | Init.PropLemmas | [
"Init.NotationExtra"
] | Init/PropLemmas.lean | Exists.imp' | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.