Zulip Chat Archive

Stream: lean4

Topic: Why is this notation not printed


Nir Paz (Dec 24 2024 at 13:52):

I defined a notation and want it to show up in the infoview instead of its definition. Looking at the definitions of notations that do show up in the infoview, like , I don't see a difference from mine. What makes this happen?

import Mathlib

open Set

variable {α β : Type*} {f g : α  β} {X : Set α}

notation:50 f:50 "~"X:max g:50 => (EqOn f g X)

example : f ~X g := by
  sorry -- ⊢ EqOn f g X instead of ⊢ f ~X g

Daniel Weber (Dec 24 2024 at 13:54):

It is because of the parenthesis around EqOn f g X - if you remove them it works (almost, you should do notation:50 f:50 " ~"X:max g:50 => EqOn f g X)

Nir Paz (Dec 24 2024 at 13:55):

Huh, thanks. Do you know why this happens?

Daniel Weber (Dec 24 2024 at 13:56):

I'd guess whatever mechanism is responsible for creating a delaborator for the notation doesn't figure out the head function correctly, but I'm not sure why

Nir Paz (Dec 24 2024 at 13:57):

If the definition is slightly more complicated, like
notation:50 f:50 " ~"X:max g:50 => EqOn f g X ∧ False
then it breaks again.

Daniel Weber (Dec 24 2024 at 13:58):

notation3 works there, I don't know why notation doesn't

Nir Paz (Dec 24 2024 at 14:00):

Good enough for me! But if someone can explain the difference that's causing this.

Daniel Weber (Dec 24 2024 at 14:02):

notation:50 f:50 " ~"X:max g:50 => And (EqOn f g X) False also works

Daniel Weber (Dec 24 2024 at 14:03):

docs#Lean.Elab.Command.mkUnexpander says:

Try to derive an unexpander from a notation. The notation must be of the form notation ... => c body where c is a declaration in the current scope and body any syntax that contains each variable from the LHS at most once.

Nir Paz (Dec 24 2024 at 14:17):

That explains it, but it seems very finicky compared to lean3.

Eric Wieser (Dec 24 2024 at 14:31):

Hence the 3 in notation3

Mario Carneiro (Dec 27 2024 at 05:09):

the reason this is so finicky is because it doesn't have type information, so it can't properly elaborate the syntax and in many cases it has to make guesses about what constants you are talking about

Mario Carneiro (Dec 27 2024 at 05:10):

so the current limitation is that you basically have to write it out as just nested constant applications without notation


Last updated: May 02 2025 at 03:31 UTC