Zulip Chat Archive

Stream: Is there code for X?

Topic: Coq-like notation with inductive


Zhuanhao Wu (Jul 31 2024 at 13:51):

I'm wondering if I can use coq like inductive notation as follows for aevalR. I'm trying to find a way that allows me to use ==> within the definition of aevalR inductive

import Mathlib

namespace AExp

inductive aexp where
| ANum   (n: )
deriving Repr

-- set_option quotPrecheck false in
-- notation:90 e:90 "==>" n:89 => aevalR e n

inductive aevalR: aexp ->  -> Prop where
| E_Anum (n: ): (ANum n) ==> n
where e "==>" n := aevalR e n  -- this won't work of course


end AExp

Shreyas Srinivas (Jul 31 2024 at 15:08):

Maybe this helps: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Does.20.60set_option.20hygiene.20false.60.20not.20work.20with.20.60notation3.60.3F/near/455228084

Zhuanhao Wu (Jul 31 2024 at 15:35):

Thank you, I think it is the one I'm looking for, and the following works for me

import Mathlib

namespace AExp

inductive aexp where
| ANum   (n: )

deriving Repr

set_option hygiene false

-- set_option quotPrecheck false in
notation:90 e:90 "==>" n:89 => aevalR e n


inductive aevalR: aexp ->  -> Prop where
| E_Anum (n: ): (.ANum n) ==> n
-- where e "==>" n := aevalR e n


end AExp

Shreyas Srinivas (Jul 31 2024 at 15:40):

import Mathlib

namespace AExp

inductive aexp where
| ANum   (n: )

deriving Repr

section Temp

set_option hygiene false

-- set_option quotPrecheck false in
local notation:90 e:90 "==>" n:89 => aevalR e n


inductive aevalR: aexp ->  -> Prop where
| E_Anum (n: ): (.ANum n) ==> n
-- where e "==>" n := aevalR e n
end Temp

notation:90 e:90 "==>" n:89 => aevalR e n

end AExp

Shreyas Srinivas (Jul 31 2024 at 15:40):

This way you also get unexpanders for your notation

Zhuanhao Wu (Jul 31 2024 at 16:17):

Nice, thanks for the info

Kyle Miller (Jul 31 2024 at 19:33):

It's also how you can make sure ==> will always refer to the correct aevalR, even if another aevalR is in scope. This is what hygiene is for.


Last updated: May 02 2025 at 03:31 UTC