Zulip Chat Archive
Stream: mathlib4
Topic: apply? failure
Nir Paz (Nov 12 2023 at 20:50):
Should apply?
get this?
import Mathlib
def re (n m : ℕ) : Prop := n = m
instance reSetoid : Setoid ℕ where
r := re
iseqv := ⟨Eq.refl, Eq.symm, Eq.trans⟩
example (a b : ℕ) (h : Quotient.mk' a = Quotient.mk' b) : re a b := by apply?
Quotient.exact h
works.
Eric Wieser (Nov 12 2023 at 23:43):
No, because apply?
isn't allowed to look at how you defined re
Eric Wieser (Nov 12 2023 at 23:43):
If you replace it with abbrev re
instead of def re
, which apply?
is allowed to look through, then it works
Nir Paz (Nov 16 2023 at 18:50):
What about this?
import Mathlib
example (P Q : Prop) (h : P → Q) (h' : ¬Q) : ¬P := by exact?
Patrick Massot (Nov 16 2023 at 18:59):
I think this is simply not stated in Mathlib.
Eric Rodriguez (Nov 16 2023 at 18:59):
docs#mt I thought
Eric Rodriguez (Nov 16 2023 at 18:59):
But I thought this may be the performance optimisation stuff
Patrick Massot (Nov 16 2023 at 19:00):
Eric is right and I was wrong.
Scott Morrison (Nov 17 2023 at 01:58):
Eric, Patrick, and I were all wrong. In fact it was a bug (one of the horsemen!) fixed now in std4#368 and #8458.
Nir Paz (Nov 17 2023 at 04:07):
Cool! Is there a rule of thumb for when it's ok for apply to not find a single-theorem-solution, like due to "optimization stuff"?
Nir Paz (Nov 17 2023 at 04:08):
Because I always think of that as a problem and I guess sometimes it's not
Nir Paz (Nov 17 2023 at 04:09):
(Excluding things like my first example with def
s)
Scott Morrison (Nov 17 2023 at 04:13):
As far as I know, after #8458 and #8459 land, I think the claim is:
if you can prove a goal via
apply X; solve_by_elim*
for someX
, thenexact?
should work
and
if you can prove a collection of goals via
apply X; apply Y; ...; apply Z
, where all theX Y Z
are hypotheses, thensolve_by_elim*
should work
These are probably wrong, but I'd be happy to see more examples where they are wrong!
Joachim Breitner (Nov 17 2023 at 06:54):
Great way to phrase the specification for these tactics. Maybe could be part of the docstring?
Nir Paz (Feb 05 2024 at 21:15):
import Mathlib.Tactic.LibrarySearch
import Mathlib.Order.RelIso.Basic
example {α} (r s t : α → α → Prop) (h : s ≃r r) (h' : r ≃r t) : α ↪ α := by
have := h.injective
have := h'.injective
use fun a ↦ h' (h a)
exact? --fails
fails, but works with use fun a ↦ (h' ∘ h) a
. (apply Function.Injective.comp; solve_by_elim*
works in both cases)
So does exact?
not try all theorems with results defeq to the goal? If that's how it works then there must be lots of cases where it can't close goals where a single apply
would work.
Patrick Massot (Feb 05 2024 at 21:51):
So this is not what it does. It used to do it in Lean 3 and it became unusable because Mathlib is now too large. So it uses some indexing now and this will not see through definitional equality.
Jireh Loreaux (Feb 06 2024 at 02:42):
Another way to say this: exact?
in Lean 4 now requires that matches satisfy a stricter equality constraint.
Nir Paz (Feb 07 2024 at 22:18):
Is there a tactic that does what the old exact
did? I often spend >2 minutes loogling and find a single theorem proof, and when it's obvious that what I want is somewhere in the library I'd rather just let that run for a minute.
Kevin Buzzard (Feb 07 2024 at 22:28):
You presumably mean exact?
in your message. Yes it would be nice sometimes to have an exact?!
or eexact?
which tried harder.
Last updated: May 02 2025 at 03:31 UTC