8000 feat: polymorphic ranges by datokrat · Pull Request #8784 · leanprover/lean4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: polymorphic ranges #8784

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

Open
wants to merge 45 commits into
base: paul/base/ranges/introduce-ranges
Choose a base branch
from

Conversation

datokrat
Copy link
Contributor
@datokrat datokrat commented Jun 14, 2025

This PR introduces ranges that are polymorphic, in contrast to the existing Std.Range which only supports natural numbers.

Breakdown of core changes:

  • Lean.Parser.Basic: Modified the number parser (Lean.Parser.Basic) so that it will only consider a single dot to be part of a decimal number. 1.. will no longer be parsed as 1. followed by ., but as 1 followed by ...
  • The test ellipsisProjIssue ensures that #check Nat.add ...succ produces a syntax error. After introducing the new range notation (see below), it returns a different (less nice) error message. I updated the test to reflect the new error message. (The error message will become nicer as soon as a delaborator for the ranges is implemented. This is out of scope for this PR.)

Breakdown of standard library changes:

Modified modules: Init.Data.Range.Polymorphic (added), Init.Data.Iterators, Std.Data.Iterators

  • Introduced the type Std.PRange that is parameterized over the type in which the range operates and the shapes of the lower and upper bound.
  • Introduced a new notation for ranges. Examples for this notation are: 1...*, 1...=3, 1...<3, 1<...=2, *...=3.
  • Defined lots of typeclasses for different capabilities of ranges, depending on their shape and underlying type.
  • Introduced Iter(M).size.
  • Introduced the Iter(M).stepSize n combinator, which iterates over an iterator with the given step size n. It will drop n - 1 values between every value it emits.
  • Replaced LawfulPureIterator with a new and better typeclass LawfulDeterministicIterator.
  • Simplified some lemma statements in the iterator library such as IterM.toList_eq_match, which unnecessarily matched over a Subtype, hindering rewrites due to type dependencies.

Reasons for the concrete choice of notation:

  • lean4-cli uses ...-based notation for the Cmd notation and it clashes with ...a range notation.
  • test 2461 fails when using two-dot-based notation because of the existing { a.. } notation.

@datokrat datokrat added the changelog-library Library label Jun 14, 2025
@datokrat datokrat changed the base branch from master to paul/base/ranges/introduce-ranges June 14, 2025 16:53
@datokrat datokrat force-pushed the paul/ranges/introduce-ranges branch 2 times, most recently from 17a7c4a to 23b9390 Compare June 17, 2025 21:16
@datokrat datokrat force-pushed the paul/base/ranges/introduce-ranges branch 2 times, most recently from b3e6ea4 to 6b335e6 Compare June 18, 2025 12:37
@datokrat datokrat force-pushed the paul/ranges/introduce-ranges branch from 23b9390 to 0c96c36 Compare June 18, 2025 12:37
@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 Jun 23, 2025
@leanprover-community-bot
Copy link
Collaborator
leanprover-community-bot commented Jun 23, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 86eded35db40fadcd718eed738e0860b942841b1 --onto db499e96aac8ad654c8ed5ab40c4e6885d38c9a1. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-23 08:44:03)
  • ✅ Mathlib branch lean-pr-testing-8784 has successfully built against this PR. (2025-06-23 10:02:06) View Log
  • ✅ Mathlib branch lean-pr-testing-8784 has successfully built against this PR. (2025-06-23 14:01:22) View Log
  • ✅ Mathlib branch lean-pr-testing-8784 has successfully built against this PR. (2025-06-23 22:30:02) View Log
  • ❗ Batteries CI can not be attempted yet, as the nightly-testing-2025-06-24 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Batteries CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2025-06-25 08:37:42)

@datokrat datokrat force-pushed the paul/base/ranges/introduce-ranges branch from 6b335e6 to db499e9 Compare June 23, 2025 08:48
@datokrat datokrat force-pushed the paul/ranges/introduce-ranges branch from 2ce1833 to 5fe9499 Compare June 23, 2025 08:48
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 23, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 23, 2025
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jun 23, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 23, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 23, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 23, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 23, 2025
@datokrat datokrat marked this pull request as ready for review June 24, 2025 05:42
@datokrat datokrat requested review from TwoFX and kim-em as code owners June 24, 2025 05:42
@datokrat datokrat force-pushed the paul/ranges/introduce-ranges branch from 15482bc to 7ee86a1 Compare June 25, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR changelog-library Library 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.

2 participants
0