feat(library/type_context): unfold lemmas in major premise of acc.rec #1680
Conversation
Note that we don't get any Regarding using
nat.add n (@one nat ?m) will not match the pattern nat.add ?x_0 (nat.succ ?x_1) because Possible workaround a) try to instanciate type class instances before we try the refl lemmas. Possible workaround b) allow regular metavariables be assigned by type class resolution even when we are in tmp-mode.
will take a very long time because of this heuristic.
|
@gebner Regarding this PR, I'm concerned about using computation for proving lemmas about functions defined by well founded recursion. It is super expensive to compute with them in the kernel. Example: example : gcd 1000 10 = 10 :=
rfl That being said, we have a related problem in the current system: we don't have a nice way to unfold functions such as gcd.equations._eqn_1 : ∀ (y : ℕ), gcd y = λ (x : ℕ), ite (y = 0) x (gcd (x % y) y) There is no constructor on the equation lhs. Thus, rw [gcd.equations._eqn_1] This is bad, but we can use it to prove lemma gcd_zero_right (x : nat) : gcd 0 x = x :=
by rw [gcd.equations._eqn_1]; simp I see the following possibilities for addressing the I think option 2 is the most natural. |
The following commit implements workaround 3 |
…rewrite using the equational lemmas for `f` The tactic succeeds if the expression can be rewritten using one of the equational lemmas associated with `f`. See discussion at leanprover#1680
@gebner I'll merge this PR.
|
I'm going to create an issue for the |
See discussion at the bitwise operations issue.
Basically the issue is once again that even though terms such as
4 % 2
definitionally reduce to0
in the kernel, we can't make use of that fact anywhere else, since the type_context doesn't reduce lemmas.The
type_context.unfold_lemmas
option that I added a while back is also problematic, since it is local: consider a definition where the type depends on the definitional equality4 % 2 = 0
. Then whenever you want to use this definition, you have to enable the unfold lemmas option at the use site.This PR introduces a seemingly cheap workaround for this issue. In the type_context, we iota-reduce
acc.rec
applications with transparency_mode::All. This makes some well-founded definitions reduce definitionally (and should solve the @digama0's issue). I originally wanted to treateq.rec
andheq.rec
in the same way, but this breaks the equation compiler.@leodemoura Another way to solve this issue is to unfold definitions in the type_context using the equational (rfl-)lemmas. You mentioned a while back that this approach has some issues. Could you elaborate on that, or point to me to previous discussions?