Skip to content

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
Copy link
Member

@TwoFX TwoFX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@datokrat datokrat changed the base branch from paul/base/ranges/introduce-ranges to master June 26, 2025 08:17
@datokrat datokrat added this pull request to the merge queue Jun 26, 2025
Merged via the queue into master with commit 70b4b2b Jun 26, 2025
17 checks passed
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Aug 27, 2025
FormulaRabbit81 pushed a commit to YaelDillies/mathlib4 that referenced this pull request Aug 30, 2025
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.

4 participants