Zulip Chat Archive

Stream: metaprogramming / tactics

Topic: Aesop safe apply not triggering


Geoffrey Irving (Jun 16 2024 at 15:16):

I'm confused why this aesop call doesn't work. Am I using ofNat and AtLeastTwo wrong?

import Mathlib.Data.Real.Basic

structure A where
  x : 

def approx (x : A) : Set  := sorry
def convert (x : ) : A := sorry

lemma mem_approx {a b : } [a.AtLeastTwo] [b.AtLeastTwo] :
    OfNat.ofNat a / OfNat.ofNat b  approx (convert (OfNat.ofNat a / OfNat.ofNat b)) := sorry

set_option trace.aesop true in
example : 2 / 3  approx (convert (2 / 3)) := by
  --exact mem_approx  -- Works
  aesop (add safe apply mem_approx)  -- Fails

(This is minimized from a more complicated aesop tactic.)

Geoffrey Irving (Jun 16 2024 at 15:17):

add norm apply mem_approx also doesn't work.

Geoffrey Irving (Jun 16 2024 at 15:19):

Note that the OfNat.ofNats on the left of mem_approx are converting to , and those on the right are converting to , which is why I can't generalize mem_approx further.

Jannis Limperg (Jun 16 2024 at 16:03):

Further minimised:

import Aesop

structure  : Type where
  r : Nat

instance : OfNat  n :=
  ⟨⟨n⟩⟩

axiom P :   Prop
axiom mem_approx (a : Nat) : P (OfNat.ofNat a)

set_option pp.all true

#check mem_approx

-- Works
example (a : Nat) : P (OfNat.ofNat a) := by
  -- exact mem_approx a
  aesop (add safe apply mem_approx)

example : P 2 := by
  -- exact mem_approx 2 -- works
  aesop (add safe apply mem_approx) -- fails

Aesop doesn't even try mem_approx, so most likely the discrimination tree still has issues with number literals. I'll investigate further.

Geoffrey Irving (Jun 16 2024 at 16:11):

Thank you!

Johan Commelin (Jun 17 2024 at 07:37):

See also lean4#2867

Geoffrey Irving (Jul 16 2024 at 21:19):

It looks like https://github.com/leanprover/lean4/pull/3684 which fixes that issue has been stalled since April 11.


Last updated: May 02 2025 at 03:31 UTC