suggest
and library_search
#
suggest
and library_search
are a pair of tactics for applying lemmas from the library to the
current goal.
suggest
prints a list ofexact ...
orrefine ...
statements, which may produce new goalslibrary_search
prints a singleexact ...
which closes the goal, or fails
- ex : tactic.suggest.head_symbol_match
- mp : tactic.suggest.head_symbol_match
- mpr : tactic.suggest.head_symbol_match
- both : tactic.suggest.head_symbol_match
A declaration can match the head symbol of the current goal in four possible ways:
ex
: an exact matchmp
: the declaration returns aniff
, and the right hand side matches the goalmpr
: the declaration returns aniff
, and the left hand side matches the goalboth
: the declaration returns aniff
, and the both sides match the goal
Instances for tactic.suggest.head_symbol_match
- tactic.suggest.head_symbol_match.has_sizeof_inst
- tactic.suggest.head_symbol_match.inhabited
a textual representation of a head_symbol_match
, for trace debugging.
Equations
- tactic.suggest.head_symbol_match.both.to_string = "iff.mp and iff.mpr"
- tactic.suggest.head_symbol_match.mpr.to_string = "iff.mpr"
- tactic.suggest.head_symbol_match.mp.to_string = "iff.mp"
- tactic.suggest.head_symbol_match.ex.to_string = "exact"
suggest
lists possible usages of the refine
tactic and leaves the tactic state unchanged.
It is intended as a complement of the search function in your editor, the #find
tactic, and
library_search
.
suggest
takes an optional natural number num
as input and returns the first num
(or less, if
all possibilities are exhausted) possibilities ordered by length of lemma names.
The default for num
is 50
.
suggest using h₁ h₂
will only show solutions that make use of the local hypotheses h₁
and h₂
.
For performance reasons suggest
uses monadic lazy lists (mllist
). This means that suggest
might miss some results if num
is not large enough. However, because suggest
uses monadic
lazy lists, smaller values of num
run faster than larger values.
An example of suggest
in action,
example (n : nat) : n < n + 1 :=
begin suggest, sorry end
prints the list,
Try this: exact nat.lt.base n
Try this: exact nat.lt_succ_self n
Try this: refine not_le.mp _
Try this: refine gt_iff_lt.mp _
Try this: refine nat.lt.step _
Try this: refine lt_of_not_ge _
...
library_search
is a tactic to identify existing lemmas in the library. It tries to close the
current goal by applying a lemma from the library, then discharging any new goals using
solve_by_elim
.
If it succeeds, it prints a trace message exact ...
which can replace the invocation
of library_search
.
Typical usage is:
example (n m k : ℕ) : n * (m - k) = n * m - n * k :=
by library_search -- Try this: exact mul_tsub n m k
library_search using h₁ h₂
will only show solutions
that make use of the local hypotheses h₁
and h₂
.
By default library_search
only unfolds reducible
definitions
when attempting to match lemmas against the goal.
Previously, it would unfold most definitions, sometimes giving surprising answers, or slow answers.
The old behaviour is still available via library_search!
.
You can add additional lemmas to be used along with local hypotheses
after the application of a library lemma,
using the same syntax as for solve_by_elim
, e.g.
example {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) :=
begin
library_search [add_lt_add], -- Says: `Try this: exact max_eq_left_of_lt (add_lt_add h₁ h₂)`
end
You can also use library_search with attr
to include all lemmas with the attribute attr
.
Invoking the hole command library_search
("Use library_search
to complete the goal") calls
the tactic library_search
to produce a proof term with the type of the hole.
Running it on
example : 0 < 1 :=
{!!}
produces
example : 0 < 1 :=
nat.one_pos