Zulip Chat Archive

Stream: lean4

Topic: Nat.succ of a nat literal


Heather Macbeth (Jun 26 2023 at 04:08):

Is it possible to write a theorem foo such that foo 37 a is syntactically 38 ≤ a ∨ a ≤ 37? (For all values of 37.). I tried

theorem foo (a b : Nat) : OfNat.ofNat a.succ  b  b  OfNat.ofNat a := Nat.lt_or_ge a b

but although this is the result I wanted up to defeq, it isn't actually the result I wanted.

example (a : Nat) : True := by
  have := foo 37 a -- infoview shows `OfNat.ofNat (Nat.succ 37) ≤ a ∨ a ≤ OfNat.ofNat 37`
  have := foo (nat_lit 37) a -- infoview shows `OfNat.ofNat (Nat.succ 37) ≤ a ∨ a ≤ 37`
  sorry

Heather Macbeth (Jun 26 2023 at 04:15):

Also, same question but for (a : Nat) (b : Int),

James Gallicchio (Jun 26 2023 at 04:18):

is it allowed to be a custom macro that just looks like a theorem? :joy:

Heather Macbeth (Jun 26 2023 at 04:20):

Sure, do tell! :)

Mario Carneiro (Jun 26 2023 at 04:23):

import Lean

macro "foo" n:num a:term:arg : term =>
  `(show $(Lean.quote (n.getNat+1))  $a  $a  $n from Nat.lt_or_ge ..)

example (a : Nat) : True := by
  have := foo 37 a -- infoview shows `this: 38 ≤ a ∨ a ≤ 37`
  sorry

Heather Macbeth (Jun 26 2023 at 04:24):

That's pretty cool. Thanks!


Last updated: Dec 20 2023 at 11:08 UTC