This is a hard coded extra case. It is not an instance of has_coe.
Even if we change has_coe to accomodate this case, it will not be a
satisfactory solution because this coercion depends on the element and
not the type, and the element usually contains metavariables.
We should eventually write a tactic for synthesizing coercions.
I kept a few core methods (e.g., exact_core and apply_core). Reason:
if we use default parameters
meta constant exact (e : expr) (md := semireducible) : tactic unit
then, we will not be able to write
to_expr p >>= exact
The workaround is
do t <- to_expr p, exact t
or
to_expr p >>= (fun x, exact x)
One alternative is to change how we handle default parameters, and
eta-expand applications that involve default parameters.
We may also have an attribute [eta_expand]. Then
attribute [eta_expand] foo
instructs the elaborator to automatically eta-expand foo-applications.
The attribute would give users more control, and avoid potential
performance problems. Without the attribute, then for every function
application the elaborator has to check the type and decide whether it
must be eta-expanded or not.
@gebner @kha What do you think?
The idea is to make sure lean doesn't timeout (at reflexivity) when we apply simp or
rewrite in goals such as
(x y : nat) |- x + y + 10000000000 = x + y + 200000000000000
This commit also addresses an issue raised at #1218
They were at src/library because we hoped we would be able to use them
in the type_context unifier. However, the plan did not work for several
reasons. We saved the partial implementation in the branch: https://github.com/leodemoura/lean/tree/type_context_with_refl_lemmas
Here are the problems:
1) We have to be able to rewrite even when the type context is already in tmp-mode.
This is an issue because the tmp metavariables in the refl lemma clash with the ones created in the type context.
Solution: implemented lift operation for idx metavariables, and custom
match. This solution is not perfect since the lifting is extra overhead.
2) The term being "unfolded" may be stuck. Example:
nat.add n (@one nat ?m)
will not match the pattern
nat.add ?x_0 (nat.succ ?x_1)
because ?m is not assigned yet.
We can assign it during the matching process because it is a regular metavariable and the matching is performed in
tmp_mode.
Possible workaround a) try to instanciate type class instances before we try the refl lemmas.
This is a potential performance problem because the term can be arbitrarily big.
The current heuristics we use to speed up the process do not work for the example above.
Possible workaround b) allow regular metavariables be assigned by type class resolution even
when we are in tmp-mode.
We have not tried to implement any of these workarounds.
3) There are many more lazy-delta steps. Before this feature, when we unfold `nat.add a (succ ... (succ b) ...)`,
we are done with delta-reduction. It is just iota and beta after that.
However, with refl-lemmas, the term `nat.add a (succ ... (succ b) ...)` produces one lazy-delta step per succ.
This produces nasty side-effects because of the
The heuristic (f t =?= f s) ==> (t =?= s).
Examples such as
(fib 8) =?= 34
will take a very long time because of this heuristic.
Possible workaround: cache failures like we did in Lean2.
However, failure are only easy to cache if there are no meta-variables.
4) The type context trace gets very confusing since we use is_def_eq for matching lhs while we are computing is_def_eq.
Possible workaround: disable trace when trying refl_lemmas.
5) We must be able to temporarily disable the feature.
Example: when proving a refl_lemma for a definition `f`, we may have
to expand the nested definitions
(e.g., for match-end blocks)
6) refl/simp lemmas were designed to rewrite elaborated terms.
Using them during unification may produce a series of unexpected
behaviors since terms usually contain many regular and universe meta-variables.
7) We need to define a notion of "refl stuck application".
Right now, a metavar is stuck, a projection is stuck if the structure
is stuck, a recursor is stuck is the major premise is stuck.
An application (f ...) is refl-lemma stuck if f has refl-lemmas
associated with it, AND metavariables occurring in arguments are
preventing a refl-lemma from being applied.