Zulip Chat Archive
Stream: mathlib4
Topic: Clash with factorial and EuclideanSpace notation
Eric Wieser (May 09 2025 at 18:38):
What's the fix to this clash between docs#PiLp.vecNotation and docs#Nat.term_! ?
import Mathlib
#check Eq ![1, 2, 3] ![1, 2, 3] -- ok
#check Eq !₂[1, 2, 3] !₂[1, 2, 3] -- ok
open scoped Nat
#check Eq ![1, 2, 3] ![1, 2, 3] -- ok
#check Eq !₂[1, 2, 3] !₂[1, 2, 3] -- fails
(using Eq just as it's a two-argument function)
Andrew Yang (May 09 2025 at 18:39):
Does this actually happen in practice?
Andrew Yang (May 09 2025 at 18:41):
Ah probably it does and my question should be "Does this still happen in practice if the EuclideanSpace notation is scoped?"
Eric Wieser (May 09 2025 at 18:41):
I'd prefer it be possible to use both these notations without any ambiguity
Eric Wieser (May 09 2025 at 18:42):
There's no scenario in which we want n !m to parse as Nat.factorial n m
Andrew Yang (May 09 2025 at 18:49):
docs#Lean.Parser.lookahead should be useful?
Eric Wieser (May 09 2025 at 19:04):
I'm not sure how
Eric Wieser (May 09 2025 at 19:06):
Here's a mwe that includes the conflicting notations
import Mathlib.Analysis.Normed.Lp.PiLp
import Mathlib.Util.Superscript
open Lean Meta Elab Term Macro TSyntax PrettyPrinter.Delaborator SubExpr
open Mathlib.Tactic (subscriptTerm)
/-- Notation for vectors in Lp space. `!₂[x, y, ...]` is a shorthand for
`(WithLp.equiv 2 _ _).symm ![x, y, ...]`, of type `EuclideanSpace _ (Fin _)`.
This also works for other subscripts. -/
syntax (name := PiLp.vecNotation) "!" noWs subscriptTerm noWs "[" term,* "]" : term
macro_rules | `(!$p:subscript[$e:term,*]) => do
-- override the `Fin n.succ` to a literal
let n := e.getElems.size
`((WithLp.equiv $p <| ∀ _ : Fin $(quote n), _).symm ![$e,*])
notation:10000 n "!" => Nat.factorial n
#check Eq ![1, 2, 3] ![1, 2, 3]
#check Eq !₂[1, 2, 3] (!₂[1, 2, 3])
#check Eq !₂[1, 2, 3] !₂[1, 2, 3]
Andrew Yang (May 09 2025 at 19:55):
e.g. changing the notation to this works
syntax:10000 term atomic("!" notFollowedBy("₂")) : term
macro_rules | `($n:term !) => do `(Nat.factorial $n)
Aaron Liu (May 09 2025 at 20:15):
But then of course it breaks again on !₁[1, 2, 3]
Andrew Yang (May 09 2025 at 20:24):
Yeah. Hence the e.g.. I'm just saying that this method works but someone needs to decide what is allowed after n! and put it there.
Last updated: Dec 20 2025 at 21:32 UTC