Skip to content
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: pp.numericTypes option for printing number literals with type ascriptions #2933

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Nov 21, 2023

Implements the pretty printer option pp.numericTypes for including a type ascription for numeric literals. For example, (2 : Nat), (-2 : Int), and (-2 / 3 : Rat). This is useful for debugging how arithmetic expressions have elaborated or have been otherwise transformed. For example, with exponentiation is is helpful knowing whether it is x ^ (2 : Nat) or x ^ (2 : Real). This is like the Lean 3 option pp.numeralTypes but it has a wider notion of a numeric literal.

Also implements the pretty printer option pp.natLit for including the nat_lit prefix for raw natural number literals.

Closes #3021

@kmill kmill requested a review from Kha as a code owner November 21, 2023 00:14
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 21, 2023
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Nov 21, 2023

  • ❗ Mathlib CI can not be attempted yet, as the 'nightly-testing-2023-11-20' branch does not exist there yet. We will retry when you push more commits. It may be necessary to rebase onto 'nightly' tomorrow. (2023-11-21 01:09:19)
  • ✅ Mathlib branch lean-pr-testing-2933 has successfully built against this PR. (2023-12-19 01:37:05) View Log
  • ✅ Mathlib branch lean-pr-testing-2933 has successfully built against this PR. (2023-12-19 02:14:19) View Log
  • ✅ Mathlib branch lean-pr-testing-2933 has successfully built against this PR. (2024-01-31 01:28:31) View Log

@tydeu
Copy link
Member

tydeu commented Nov 21, 2023

I am a bit concerned about the name numeralTypes and its discoverability because, as far as I know, numeric literals are not called "numerals" anywhere else in Lean. Thus, it would be hard to connect the dots between the option in an autocomplete list and its functionality. Maybe numLitTypes (or just numTypes) instead?

@kmill
Copy link
Collaborator Author

kmill commented Nov 21, 2023

Sebastian suggested that we go through the RFC process for this, so I'll put this back to draft and we can discuss these issues on Zulip.

@kmill kmill marked this pull request as draft November 21, 2023 21:38
@kmill kmill changed the title feat: pp.numeralTypes option for printing number literals with type ascriptions feat: pp.numericTypes option for printing number literals with type ascriptions Dec 18, 2023
@kmill kmill marked this pull request as ready for review December 19, 2023 00:03
@kmill kmill added the awaiting-review Waiting for someone to review the PR label Dec 19, 2023
@kmill
Copy link
Collaborator Author

kmill commented Dec 19, 2023

I'm re-opening this now that it's implementing an RFC.

Something I checked by hand is that the delaborators ensure that each subexpression is still hoverable in the infoview.

leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 19, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 19, 2023
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 19, 2023
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 31, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 31, 2024
@kmill kmill added full-ci and removed full-ci labels Jan 31, 2024
@kim-em
Copy link
Collaborator

kim-em commented Jan 31, 2024

This looks good.

  • Could you add a sentence to RELEASES.md for visibility?
  • You wrote such great text on the RFC (manual level explanation, reference level explanation). Should any of that text be copied into docs/? Happy either way.

@kmill kmill requested a review from kim-em as a code owner January 31, 2024 22:46
@kmill
Copy link
Collaborator Author

kmill commented Jan 31, 2024

@semorrison I added a RELEASES entry. Regarding the RFC, I'm planning on eventually going through the RFCs I've written and copying the explanations to relevant parts of the docs (in future PRs).

kmill added 2 commits February 1, 2024 17:18
… ascriptions

This was a pretty printer option in the Lean 3 community edition, and it was useful for debugging how arithmetic expressions elaborated or have been otherwise transformed. For example, the real numbers have two exponentiation operations (Real -> Real -> Real and Real -> Nat -> Real) and it is helpful knowing at a glance which of these is `x ^ 2`.

Closes leanprover#3021
@kim-em kim-em enabled auto-merge February 1, 2024 06:19
@kim-em kim-em disabled auto-merge February 1, 2024 06:23
@kim-em kim-em merged commit 1d8cf38 into leanprover:master Feb 1, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Pretty printer options to see types of numeric literals
5 participants