Zulip Chat Archive
Stream: mathlib4
Topic: Factorial notation parse error
Floris van Doorn (May 08 2023 at 14:18):
In some cases the Nat.factorial notation parses incorrectly.
import Mathlib.Data.Nat.Factorial.Basic
open Nat
example (n : ℕ) (hn : 0 < n) : n ∣ n ! := by -- fine
have : n ∣ n ! := -- fine
dvd_factorial hn le_rfl
have : n ∣ n ! -- parsed incorrectly
· exact dvd_factorial hn le_rfl
exact dvd_factorial hn le_rfl
Floris van Doorn (May 08 2023 at 14:21):
My guess is that the · is parsed as the anonymous variable, because we're still resolving the overloaded notation ! (either not or Nat.factorial)
Mario Carneiro (May 08 2023 at 18:31):
Removing the whitespace works, since it prevents it from being treated as an application of n to ! ·. Of course the lexer issues with n! still apply, but you can write (n)! instead
Kyle Miller (May 08 2023 at 19:47):
There's also using an explicit semicolon (have : n ∣ n !;) or using parentheses around other parts of the expression (like have : n ∣ (n !)).
Mario Carneiro (May 08 2023 at 19:50):
or even (have : n ∣ n !)
Kyle Miller (May 08 2023 at 19:50):
(Javascript also has optional semicolons, and the risk of unexpected parses like this pushed me towards always using semicolons there.)
Kyle Miller (May 08 2023 at 19:51):
It's too bad that · for focusing is also a valid notation in expressions; if focusing used a unique symbol this could be less of an issue.
Ruben Van de Velde (May 08 2023 at 19:51):
Does it work if you use . (period) instead of ·?
Mario Carneiro (May 08 2023 at 19:52):
nope, . works as an ascii replacement for · in both cases
Reid Barton (May 09 2023 at 05:50):
This also wouldn't be an issue if indentation-based syntax worked like in Haskell (as discussed elsewhere)
Johan Commelin (Jun 19 2023 at 17:00):
Sorry for necrobumping this... I think @Kyle Miller had a parser "hack" that made factorial notation work nicely. Maybe we actually want to have that in mathlib
Kyle Miller (Jun 19 2023 at 17:02):
https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/New.20.60propose.60.20tactic/near/351149815
(it's in a propose thread since Johan came across n! not being n ! when creating a propose demo)
Last updated: May 02 2025 at 03:31 UTC