8000 feat: binary recursive implementation of List.mapA by digama0 · Pull Request #3877 · leanprover/lean4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: binary recursive implementation of List.mapA #3877

New issue 8000

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 1 commit into
base: master
Choose a base branch
from

Conversation

digama0
Copy link
Collaborator
@digama0 digama0 commented Apr 11, 2024

Inspired by #3867 (comment) . After playing with this function a bit more, I was able to confirm that it's not really possible to implement it tail recursively in most monads (note that tail-recursiveness depends on the monad itself), because seq is not tail recursive in most monads and you have to stack up at least n-1 of them to reduce a list of length n. However, we can do the next best thing which is to use a balanced tree of seq applications. I have confirmed that this will evaluate

#eval List.mapA (m := StateT Nat Id) pure (List.range 10000) |>.run 1

without stack overflow, unlike the original implementation, but it still deserves a !bench because the binary reduction has overhead and it may be worthwhile to switch over to naive recursion below some threshold.

@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 Apr 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 11, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Apr 11, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator
leanprover-community-mathlib4-bot commented Apr 11, 2024

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 11, 2024
@david-christiansen
Copy link
Contributor

!bench

@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit f405eb4.
There were no significant changes against commit d988849.

@digama0
Copy link
Collaborator Author
digama0 commented Apr 12, 2024

(note: the benchmark is useless because List.mapA is unused in core)

@kim-em
Copy link
Collaborator
kim-em commented Apr 22, 2024

Could you add a doc-string explaining at least that the complicated implementation is for performance, and ideally explaining why tail-recursiveness is impossible and that this is "the next best thing"?

@kim-em kim-em added the awaiting-author Waiting for PR author to address issues label Apr 22, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 22, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 22, 2024
@github-actions github-actions bot added the stale label May 23, 2024
@kim-em kim-em self-requested a review as a code owner May 29, 2024 16:23
@github-actions github-actions bot removed the stale label May 30, 2024
@github-actions github-actions bot added stale and removed stale labels Jun 29, 2024
@github-actions github-actions bot added the stale label Aug 20, 2024
@github-actions github-actions bot removed the stale label Sep 6, 2024
@github-actions github-actions bot added the stale label Oct 30, 2024
@github-actions github-actions bot removed the stale label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author Waiting for PR author to address issues 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.

5 participants
0