The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Choose
27 declarations and 1 deprecated aliases. Mathlib docs · Source
choose tactic
Performs Skolemization, that is, given h : ∀ a:α, ∃ b:β, p a b |- G produces
f : α → β, hf: ∀ a, p a (f a) |- G.
TODO: switch to rcases syntax: choose ⟨i, j, h₁ -⟩ := expr.
theorem Mathlib.Tactic.Choose.ChooseArg.mk.inj E1 #
∀ {ref : Lean.Syntax} {name : Lean.Name} {expectedType? : Option Lean.Term} {ref_1 : Lean.Syntax} {name_1 : Lean.Name}
{expectedType?_1 : Option Lean.Term},
{ ref := ref, name := name, expectedType? := expectedType? } =
{ ref := ref_1, name := name_1, expectedType? := expectedType?_1 } →
ref = ref_1 ∧ name = name_1 ∧ expectedType? = expectedType?_1
theorem Mathlib.Tactic.Choose.ElimStatus.failure.inj E1 #
∀ {ts ts_1 : List Lean.Expr},
Mathlib.Tactic.Choose.ElimStatus.failure ts = Mathlib.Tactic.Choose.ElimStatus.failure ts_1 → ts = ts_1
def Mathlib.Tactic.Choose.ElimStatus.ctorIdx E1 #
Mathlib.Tactic.Choose.ElimStatus → ℕ
def Mathlib.Tactic.Choose.instInhabitedChooseArg.default E1 #
Mathlib.Tactic.Choose.ChooseArg
def Mathlib.Tactic.Choose.ChooseArg.ctorIdx E1 #
Mathlib.Tactic.Choose.ChooseArg → ℕ
theorem Mathlib.Tactic.Choose.ElimStatus.failure.injEq E0 #
∀ (ts ts_1 : List Lean.Expr),
(Mathlib.Tactic.Choose.ElimStatus.failure ts = Mathlib.Tactic.Choose.ElimStatus.failure ts_1) = (ts = ts_1)
abbrev Mathlib.Tactic.Choose.ElimStatus.ctorElimType E1 #
{motive : Mathlib.Tactic.Choose.ElimStatus → Sort u} → ℕ → Sort (max 1 u)
theorem Mathlib.Tactic.Choose.ChooseArg.mk.injEq E0 #
∀ (ref : Lean.Syntax) (name : Lean.Name) (expectedType? : Option Lean.Term) (ref_1 : Lean.Syntax) (name_1 : Lean.Name)
(expectedType?_1 : Option Lean.Term),
({ ref := ref, name := name, expectedType? := expectedType? } =
{ ref := ref_1, name := name_1, expectedType? := expectedType?_1 }) =
(ref = ref_1 ∧ name = name_1 ∧ expectedType? = expectedType?_1)
def Mathlib.Tactic.Choose.mkSometimes E1 #
Lean.Level →
Lean.Expr → Lean.Expr → Lean.Expr → List Lean.Expr → Lean.Expr × Lean.Expr → Lean.MetaM (Lean.Expr × Lean.Expr)
Given α : Sort u, nonemp : Nonempty α, p : α → Prop, a context of free variables
ctx, and a pair of an element val : α and spec : p val,
mkSometimes u α nonemp p ctx (val, spec) produces another pair val', spec'
such that val' does not have any free variables from elements of ctx whose types are
propositions. This is done by applying Function.sometimes to abstract over all the propositional
arguments.
inductive Mathlib.Tactic.Choose.ElimStatus E1 #
Type
Results of searching for nonempty instances,
to eliminate dependencies on propositions (choose!).
success means we found at least one instance;
failure ts means we didn't find instances for any t ∈ ts.
(failure [] means we didn't look for instances at all.)
Rationale:
choose! means we are expected to succeed at least once
in eliminating dependencies on propositions.
ctor Mathlib.Tactic.Choose.ElimStatus.success E0 #
Mathlib.Tactic.Choose.ElimStatus
ctor Mathlib.Tactic.Choose.ElimStatus.failure E0 #
List Lean.Expr → Mathlib.Tactic.Choose.ElimStatus
def Mathlib.Tactic.Choose.ElimStatus.merge E1 #
Mathlib.Tactic.Choose.ElimStatus → Mathlib.Tactic.Choose.ElimStatus → Mathlib.Tactic.Choose.ElimStatus
Combine two statuses, keeping a success from either side or merging the failures.
def Mathlib.Tactic.Choose.mkFreshNameFrom E1 #
Lean.Name → Lean.Name → Lean.CoreM Lean.Name
mkFreshNameFrom orig base returns mkFreshUserName base if orig = `_
and orig otherwise.
structure Mathlib.Tactic.Choose.ChooseArg E1 #
Type
Parsed information from a choose argument, which may include a type annotation.
ctor Mathlib.Tactic.Choose.ChooseArg.mk E0 #
Lean.Syntax → Lean.Name → Option Lean.Term → Mathlib.Tactic.Choose.ChooseArg
abbrev Mathlib.Tactic.Choose.ChooseArg.ref E1 #
Mathlib.Tactic.Choose.ChooseArg → Lean.Syntax
The syntax reference for the identifier (for hover info)
abbrev Mathlib.Tactic.Choose.ChooseArg.name E1 #
Mathlib.Tactic.Choose.ChooseArg → Lean.Name
The name to use for the introduced variable
abbrev Mathlib.Tactic.Choose.ChooseArg.expectedType? E1 #
Mathlib.Tactic.Choose.ChooseArg → Option Lean.Term
Optional expected type annotation
instance Mathlib.Tactic.Choose.instInhabitedChooseArg E0 #
Inhabited Mathlib.Tactic.Choose.ChooseArg
def Mathlib.Tactic.Choose.chooseBinder E1 #
Lean.ParserDescr
A choose argument is either a bare identifier or a parenthesized extended binder
def Mathlib.Tactic.Choose.parseChooseArg E1 #
Lean.TSyntax `Mathlib.Tactic.Choose.chooseBinder → Lean.MetaM Mathlib.Tactic.Choose.ChooseArg
Parse a choose argument from chooseBinder syntax. Accepts:
x- plain identifier_- anonymous(x : T)- identifier with type annotation(_ : T)- anonymous with type annotation
def Mathlib.Tactic.Choose.choose1 E1 #
Lean.MVarId →
Bool → Option Lean.Expr → Lean.Name → Lean.MetaM (Mathlib.Tactic.Choose.ElimStatus × Lean.Expr × Lean.MVarId)
Changes (h : ∀ xs, ∃ a:α, p a) ⊢ g to (d : ∀ xs, a) ⊢ (s : ∀ xs, p (d xs)) → g and
(h : ∀ xs, p xs ∧ q xs) ⊢ g to (d : ∀ xs, p xs) ⊢ (s : ∀ xs, q xs) → g.
choose1 returns a tuple of
- the error result (see
ElimStatus) - the data new free variable that was "chosen"
- the new goal (which contains the spec of the data as domain of an arrow type)
If nondep is true and α is inhabited, then it will remove the dependency of d on
all propositional assumptions in xs. For example if ys are propositions then
(h : ∀ xs ys, ∃ a:α, p a) ⊢ g becomes (d : ∀ xs, a) (s : ∀ xs ys, p (d xs)) ⊢ g.
def Mathlib.Tactic.Choose.choose1WithInfo E1 #
Lean.MVarId →
Bool →
Option Lean.Expr →
Mathlib.Tactic.Choose.ChooseArg → Lean.Elab.TermElabM (Mathlib.Tactic.Choose.ElimStatus × Lean.MVarId)
A wrapper around choose1 that parses identifiers, adds variable info to new variables,
and optionally checks the type annotation.
def Mathlib.Tactic.Choose.elabChoose E1 #
Bool →
Option Lean.Expr →
List Mathlib.Tactic.Choose.ChooseArg →
Mathlib.Tactic.Choose.ElimStatus → Lean.MVarId → Lean.Elab.TermElabM Lean.MVarId
A loop around choose1. The main entry point for the choose tactic.
def Mathlib.Tactic.Choose.choose E1 #
Lean.ParserDescr
-
choose a b h h' using hyptakes a hypothesishypof the form∀ (x : X) (y : Y), ∃ (a : A) (b : B), P x y a b ∧ Q x y a bfor someP Q : X → Y → A → B → Propand outputs into context a functiona : X → Y → A,b : X → Y → Band two assumptions:h : ∀ (x : X) (y : Y), P x y (a x y) (b x y)andh' : ∀ (x : X) (y : Y), Q x y (a x y) (b x y). It also works with dependent versions. -
choose! a b h h' using hypdoes the same, except that it will remove dependency of the functions on propositional arguments if possible. For example ifYis a proposition andAandBare nonempty in the above example then we will instead geta : X → A,b : X → B, and the assumptionsh : ∀ (x : X) (y : Y), P x y (a x) (b x)andh' : ∀ (x : X) (y : Y), Q x y (a x) (b x).
The using hyp part can be omitted,
which will effectively cause choose to start with an intro hyp.
Like intro, the choose tactic supports type annotations to specify the expected type
of the introduced variables. This is useful for documentation and for catching mistakes early:
example (h : ∃ n : ℕ, n > 0) : True := by
choose (n : ℕ) (hn : n > 0) using h
trivial
If the provided type does not match the actual type, an error is raised.
Examples:
example (h : ∀ n m : ℕ, ∃ i j, m = n + i ∨ m + j = n) : True := by
choose i j h using h
guard_hyp i : ℕ → ℕ → ℕ
guard_hyp j : ℕ → ℕ → ℕ
guard_hyp h : ∀ (n m : ℕ), m = n + i n m ∨ m + j n m = n
trivial
example (h : ∀ i : ℕ, i < 7 → ∃ j, i < j ∧ j < i+i) : True := by
choose! f h h' using h
guard_hyp f : ℕ → ℕ
guard_hyp h : ∀ (i : ℕ), i < 7 → i < f i
guard_hyp h' : ∀ (i : ℕ), i < 7 → f i < i + i
trivial
def Mathlib.Tactic.Choose.tacticChoose!___Using_ E1 #
Lean.ParserDescr
-
choose a b h h' using hyptakes a hypothesishypof the form∀ (x : X) (y : Y), ∃ (a : A) (b : B), P x y a b ∧ Q x y a bfor someP Q : X → Y → A → B → Propand outputs into context a functiona : X → Y → A,b : X → Y → Band two assumptions:h : ∀ (x : X) (y : Y), P x y (a x y) (b x y)andh' : ∀ (x : X) (y : Y), Q x y (a x y) (b x y). It also works with dependent versions. -
choose! a b h h' using hypdoes the same, except that it will remove dependency of the functions on propositional arguments if possible. For example ifYis a proposition andAandBare nonempty in the above example then we will instead geta : X → A,b : X → B, and the assumptionsh : ∀ (x : X) (y : Y), P x y (a x) (b x)andh' : ∀ (x : X) (y : Y), Q x y (a x) (b x).
The using hyp part can be omitted,
which will effectively cause choose to start with an intro hyp.
Like intro, the choose tactic supports type annotations to specify the expected type
of the introduced variables. This is useful for documentation and for catching mistakes early:
example (h : ∃ n : ℕ, n > 0) : True := by
choose (n : ℕ) (hn : n > 0) using h
trivial
If the provided type does not match the actual type, an error is raised.
Examples:
example (h : ∀ n m : ℕ, ∃ i j, m = n + i ∨ m + j = n) : True := by
choose i j h using h
guard_hyp i : ℕ → ℕ → ℕ
guard_hyp j : ℕ → ℕ → ℕ
guard_hyp h : ∀ (n m : ℕ), m = n + i n m ∨ m + j n m = n
trivial
example (h : ∀ i : ℕ, i < 7 → ∃ j, i < j ∧ j < i+i) : True := by
choose! f h h' using h
guard_hyp f : ℕ → ℕ
guard_hyp h : ∀ (i : ℕ), i < 7 → i < f i
guard_hyp h' : ∀ (i : ℕ), i < 7 → f i < i + i
trivial
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Mathlib.Tactic.Choose.mk_sometimes | Mathlib.Tactic.Choose.mkSometimes | 2026-05-27 |