Zulip Chat Archive
Stream: lean4
Topic: exact? can't find theorem
Alex Meiburg (Sep 02 2025 at 02:35):
theorem blah {α : Sort u} (h : Prop) [Decidable h] {x y : α} {p : α → Prop} (hx : h → p x) (hy : ¬h → p y) :
p (if h then x else y) := by
exact iteInduction hx hy
this (with no imports) works fine. But exact? does not close the goal, even though iteInduction is a ??totally normal?? theorem, and the only arguments are hx and hy, and everything is an exact expression equality afaict (no "merely" defeq fits going on). Can someone explain to me why?
Aaron Liu (Sep 02 2025 at 02:43):
iteInduction doesn't seem to be used a lot
Alex Meiburg (Sep 02 2025 at 02:44):
Yes, for good reason, it's kind of awkward (split or split_ifs is usually better). It's more a question of why exact? doesn't find it.
Aaron Liu (Sep 02 2025 at 02:44):
Probably the answer is that your conclusion is a free variable applied to stuff
Aaron Liu (Sep 02 2025 at 02:44):
so it's hard to unify
Alex Meiburg (Sep 02 2025 at 02:45):
ah! Like there's no key for the discrimination tree? Did I say that right? That would make sense.
Alex Meiburg (Sep 02 2025 at 02:45):
I guess it just finds p as the head, doesn't know what to do with that, and gives up. Hm.
Alex Meiburg (Sep 02 2025 at 02:46):
That's too bad. I like to think of exact? as "if there's one theorem in the library that will solve this, find it and use it!". But no.
Kevin Buzzard (Sep 02 2025 at 16:47):
It also often won't find theorems whose conclusion is A = B.
Jovan Gerbscheid (Sep 02 2025 at 20:08):
Yep, theorems whose conclusion is a free variable, or an equality of free variables where the type is a free variable, are not indexed by exact? for efficiency reasons.
Patrick Massot (Sep 03 2025 at 06:25):
This is really a huge trap for new users. It would be really nice if exact? could detect that the goal looks like this and print a warning message suggesting to try some new slow_exact? doing what the Lean 3 version was doing (simply try to apply all lemmas).
Kim Morrison (Sep 03 2025 at 07:14):
Yes please, I would merge that PR! :-)
Kim Morrison (Sep 03 2025 at 07:14):
Probably just a flag exact? +all would do. I like the warning idea, that hadn't occurred to me!
Alex Meiburg (Sep 03 2025 at 17:09):
There's actually a spot more than "try to apply all lemmas": you can do exfalso first and then trying applying all lemmas. :) (Or, by_contra first, which is slightly stronger.)
Example:
example (f : Filter ℕ) [f.NeBot] (x y z : Set ℕ) (hx : x ∈ f) (hy : y ∈ f) (hf : Disjoint x y) : x = z := by
solve_by_elim [Filter.NeBot.not_disjoint]
Here solve_by_elim is able to (with the help of one extra library lemma) prove False and close the goal. exact? and exfalso; exact? both don't work. If there was a slow_exact?, I would hope it could catch things like this too!
Alex Meiburg (Sep 03 2025 at 17:13):
Another example:
import Mathlib
example {m n : ℕ} (h1 : m ∣ n) (h2 : 1 ≠ m) (h3 : Nat.Prime n) : m = n := by
by_contra
solve_by_elim [Nat.not_prime_of_dvd_of_ne]
Kevin Buzzard (Sep 03 2025 at 20:10):
This feels like mission creep really.
Jovan Gerbscheid (Sep 03 2025 at 20:28):
Fundamentally apply?, and hence exact?, are backwards reasoning tactics. This means that they infer what to apply directly from the shape of the goal. If the goal is False, or a free variable, then this strategy is simply too inefficient. Though feel free to try and implement a better strategy :).
Alex Meiburg (Sep 03 2025 at 20:30):
That's fair to call it mission creep! I just like automation that helps people find relevant stuff. So maybe this isn't "exact?" any more, but it's functionality I would enjoy seeing exist... Maybe under a different name, like find_one_lemma or something
What is "simply too inefficient"? Like this would take five minutes, an hour?
Jovan Gerbscheid (Sep 03 2025 at 20:39):
Hmm, good question, I'm not sure how long such a thing would actually take. But another question is, even if the speed was there, how useful would it be to apply recursor-like theorems. Applying a recursor is hard, and will only work if the conclusion has exactly the right shape. This is the case in your original example, but if you replace p with a more complicated thing, it won't work at all.
Kim Morrison (Dec 04 2025 at 22:52):
@Alex Meiburg, @Patrick Massot, lean#11494 ensures that this lemma is found. In fact, hopefully we recover the old mathlib3 behaviour, as now all "unindexable" lemmas (i.e. DiscrTree keys [*] and [Eq.eq, *, *, *]) are tried in a second pass automatically. You can disable this with exact? -start.
Kim Morrison (Dec 04 2025 at 22:53):
I'm particularly interested if anyone has reports of exact? timing out or being very slow, as I have a PR ready to install parallelism in exact? at lean#11369, but I don't yet have convincing evidence it helps!
(In particular, making this useful probably requires not parallelising every task, but chunking to limit the task overhead, and I need some good slow examples to tune this on.)
Alex Meiburg (Dec 05 2025 at 04:25):
Exciting! I'll be curious to try this out. :)
Kim Morrison (Dec 06 2025 at 05:57):
@Alex Meiburg, I'm looking forward to you trying out the new exact? +grind. Sometimes it is too expensive (examples where it is slow very welcome!!) but it gives some lovely results. (It's the same first stage as exact?, but instead of solely relying on solve_by_elim to discharge the hypotheses, it can also use grind. So often slight mismatches get covered by grind, particularly small arithmetical differences.)
Julian Berman (Dec 06 2025 at 12:45):
Is the idea to evaluate possibly making grind the default discharger? Or just stay an alternate?
Alex Meiburg (Dec 06 2025 at 17:20):
What kind of terms does exact? +grind produce? Is it always grind [one_extra_library_thm]?
Robin Arnez (Dec 06 2025 at 21:16):
I think exact some_kind_of_theorem x y hxy (by grind) (by grind)
Kim Morrison (Dec 07 2025 at 22:37):
Julian Berman said:
Is the idea to evaluate possibly making grind the default discharger? Or just stay an alternate?
I would need many more user reports about its effectiveness / speed before considering this.
Kim Morrison (Dec 07 2025 at 22:38):
If you're looking for suggestions like grind [one_extra_library_thm], please try grind +suggestions (and, for those with in house AIs, please try out set_library_suggestions, and see if you can get your AI to make good suggestions!)
Alex Meiburg (Dec 07 2025 at 22:40):
I see, yeah it makes sense what Robin said, and I see why that falls much more naturally under exact? than what I was thinking. :)
Last updated: Dec 20 2025 at 21:32 UTC