Zulip Chat Archive

Stream: lean4

Topic: apply motive failure


James Gallicchio (May 07 2024 at 08:48):

mwe:

theorem natAbs_elim {motive : Nat  Prop} (i : Int)
  (hpos :  (n : Nat), i = n  motive n)
  (hneg :  (n : Nat), i = -↑n  motive n)
  : motive (Int.natAbs i)
  := by sorry

example (x : Int) (y : Nat) : x.natAbs < y := by
  apply natAbs_elim x
  sorry

Is there an easy way to get apply to find the correct motive here? I'm a bit disappointed that it doesn't just work, but ofc I have low expectations for an undecidable problem

Mario Carneiro (May 07 2024 at 08:54):

The way it's supposed to "just work" is to put @[elab_as_elim] on the theorem, but it doesn't work:

unexpected eliminator resulting type
  motive i.natAbs

Mario Carneiro (May 07 2024 at 08:55):

(I believe this is a regression relative to lean 3)

James Gallicchio (May 07 2024 at 08:56):

do you know if there's a gh issue for it? otherwise i'll go digging

Mario Carneiro (May 07 2024 at 08:56):

I don't think so

James Gallicchio (May 07 2024 at 09:06):

https://github.com/leanprover/lean4/issues/4086

James Gallicchio (May 07 2024 at 09:10):

Temporary workaround:

@[elab_as_elim]
theorem natAbs_elim {motive : Nat  Prop} {i : Int} (x : Nat)
  (hi : Int.natAbs i = x)
  (hpos :  (n : Nat), i = n  motive n)
  (hneg :  (n : Nat), i = -↑n  motive n)
  : motive x := by
  sorry

example (x : Int) (y : Nat) : x.natAbs < y := by
  generalize hn : x.natAbs = n
  refine natAbs_elim n hn ?_ ?_
  sorry

which I can wrap into a tactic easily enough. Maybe this is not an unreasonable request for elab_as_elim to support!

James Gallicchio (May 07 2024 at 09:16):

macro "elim_int_natabs" : tactic => do
  `(tactic| (
    generalize h : Int.natAbs _ = n at *
    refine Int.natAbs_elim n h ?_ ?_ <;> cases h
  ) )

example (x : Int) (y : Nat) : x.natAbs < y := by
  elim_int_natabs
  sorry

daily love for lean macros


Last updated: May 02 2025 at 03:31 UTC