Zulip Chat Archive

Stream: lean4

Topic: exact? failure with broad pattern


Floris van Doorn (Oct 22 2024 at 16:44):

I think the following failure of exact? happens because it doesn't index lemmas which have too broad DiscrTree-patterns. Is that correct? I think I lobbied for this before, to get speed over completeness. That said, these failures are unfortunate.

I'm still confused why the last example works, where the lemma is an implication instead of a bi-implication. Does it use a different pattern in that case?

import Mathlib.Data.Real.Basic

example (a b : ) (h : a - b = 0) : a = b := by
  exact? -- fails
  -- exact sub_eq_zero.mp h

example {G} [AddGroup G] (a b : G) (h : a - b = 0) : a = b := by
  exact? -- fails
  -- exact sub_eq_zero.mp h

example (a b : ) (h : a - b = 0) : a = b := by
  exact? -- exact Int.eq_of_sub_eq_zero h

Michael Stoll (Feb 20 2025 at 16:52):

This seems to be a general phenomenon with bi-implications:

import Mathlib

example {X : Type} {S : Set (Set X)} {B : Set X} (H : B  S  B  S) (hB : B  S) :
    B  S := by
  /- `exact?` could not close the goal. Try `apply?` to see partial suggestions. -/
  exact?
  -- exact H.mp hB -- works

example {X : Type} {S : Set (Set X)} {B : Set X} (H : B  S  B  S) (hB : B  S) :
    B  S := by
  /- Try this: exact H hB -/
  exact?

It would be nice if that could be made to work. (The #discr_tree_key of H above seems to be
Iff (Not (@Membership.mem (Set _) (Set (Set _)) _ _ _)) (@Membership.mem (Set _) (Set (Set _)) _ _ (@compl (Set _) _ _)),
which looks sufficiently specific to my eyes.)

Michael Stoll (Feb 22 2025 at 09:01):

I imagine one solution could be to include the two implications separately in the discrimination tree when indexing a statement whose conclusion is a bi-implication. Would this be reasonable?

Jovan Gerbscheid (Feb 23 2025 at 12:49):

These are two separate problems: exact? only deals with bi-implications of global statements, not local hypotheses. This does work:

import Mathlib

axiom X : Type
axiom S : Set (Set X)
axiom B : Set X
axiom H : B  S  B  S

example (H : B  S  B  S) (hB : B  S) :
    B  S := by
  /- Try this: exact _root_.H.mp hB -/
  exact?

Jovan Gerbscheid (Feb 23 2025 at 12:51):

The other problem is that exact? purposefully doesn't index any theorem with the discrimination tree pattern Eq * * *. That explains why it finds Int.eq_of_sub_eq_zero (pattern Eq Int * *). But there apparently isn't such a lemma specialized to real numbers.

Jovan Gerbscheid (Feb 23 2025 at 12:52):

Similarly, this example works for Nat and Int, but not in general:

import Mathlib

example (x y : Rat) (h : x  y) (h' : y  x) : x = y := by
  exact?

Last updated: May 02 2025 at 03:31 UTC