New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(widget): pretty printing restricted quantifiers #5440
Conversation
Eg converts `∀ (x : ℕ), x > 3 → ∃ (N : set ℕ), ∀ y, y ∈ N → x > 2` to `∀ (x > 3), ∃ (N : set ℕ), ∀ (y ∈ N), x > 2` in the widget view. Things to do: - testing - include support for other binders, not just ∀ - docstrings
I probably won't have time to work on this for a while so if anyone wants to pick it up; go nuts. |
I'm unsure about this for two reasons. One, it suppresses information (the type of |
Yeah @robertylewis I think these are valid concerns. The context of this is that @PatrickMassot noted that beginners find the non-compacted notation that the pretty printer generates to be confusing and its a sticking point for learning Lean. Perhaps you can weigh in Patrick? In terms of not knowing the type, you can still inspect the expression in the widget view and see the type, although it is not immediate from a glance. I agree that this should really belong in Lean's pretty printer C++ code. But this was just way simpler to implement in Lean as a post-processing step. There are already a few pretty-printer post-processing steps in use in the file: eg the lines above 303 in interactive_expr.lean. We can add an option to disable. |
Yes, I think this would be a huge improvement for teaching, especially when existentials quantifiers will be handled, getting rid of the infamous |
I think there might be a bug in the pretty printer.
Any news here? @EdAyers |
meta def sf.replace {m} [monad m] [alternative m] (f : sf → m sf) : sf → m sf | ||
| x := (f x >>= sf.traverse sf.replace) <|> pure x | ||
|
||
/-- The test for whether the proposition is a valid target for restricted quantifier collapsing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the valid targets "everything with infix notation"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a programmatic way to test whether a given relation has an infix notation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I'm aware of. You could build a dummy application and see if it pretty prints differently than you expect, which is very hackish.
For @PatrickMassot 👁‿👁 I do this by refactoring the sf handling code in to its own method that returns the sf tree with the new look.
Ed, could you update the TODO list in the PR description? |
The pretty printer was getting the addresses for a special notation binder wrong because of a bug in pp_binders. See also leanprover-community/mathlib#5440
Ready for review |
I'm still not really thrilled about this change. My first worry is debatable, I know, but I feel like bundling this in the goal view really does obscure things in the logic and type theory. Maybe it helps for exists, but: example : ∀ x : ℤ, x > 0 → true :=
begin
-- ∀ (x > 0), true
end In this example I don't see the type of Worse, because this is implemented as widget post-processing, it doesn't interact well with pp options. This is ugly and doesn't round-trip: set_option pp.notation false
example : ∀ x : ℤ, x > 0 → true :=
begin
-- ∀ (gt x 0), true
end and pp.all makes it worse. At a bare minimum, I think this feature needs an option to disable it. I'd prefer it disabled by default. Even better, I'd prefer it implemented as part of the pretty-printer so it interacted right with pp options. |
I still think this is a great contribution, but of course it would be better to have an option controlling this. I think the Note that in my course I ship everything with this PR included (not in mathlib, in my project). |
To address some of Rob's concerns; There are other existing cases where the pp system makes the types of expressions ambiguous. I agree that this one is particularly bad because the information it is hiding is something that the user could really do with knowing. There is not going to be a non-clunky way to reveal this information without being worse than the original uncollapsed notation. The community are going to have to make an aesthetic judgement call. I agree that turning off pp.notation makes this ugly, hopefully it is possible for the tactic state to know whether I agree it needs a disabling option. In the small amount of Lean teaching that I have done I can concur with Patrick that students stumble on these non-collapsed quantifiers. So I do think that this addition has some merit for teaching purposes even at the expense of being bloat for the power users. Perhaps the tradeoff is not worth it, I am genuinely not sure. |
This PR/issue depends on:
|
Lean 4 handles nested binders completely differently, so this will have to be redone mostly from scratch. To be revisited after the port. |
Eg converts
∀ (x : ℕ), x > 3 → ∃ (N : set ℕ), ∀ y, y ∈ N → x > 2
to
∀ (x > 3), ∃ (N : set ℕ), ∀ (y ∈ N), x > 2
in the widget view.
pp.notation
is off