Skip to content

feat: support for lambda expressions in discr trees #8395

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

Closed
wants to merge 19 commits into from

Conversation

Rob23oba
Copy link
Contributor

@Rob23oba Rob23oba commented May 18, 2025

This PR adds support for lambda expressions in discrimination trees (Lean.Meta.DiscrTree). This means that a lot more specialization can be applied in discrimination trees than before. Examples:

-- previously
#discr_tree_key fun x => x -- `<other>`
#discr_tree_simp_key bind_pure_comp -- @bind _ _ _ _ _ <other>
#discr_tree_simp_key List.foldlM_pure -- @List.foldlM _ _ _ _ <other> _ _
#discr_tree_simp_key List.foldr_cons_eq_append -- @List.foldr _ (List _) <other> _ _
-- now
#discr_tree_key fun x => x -- fun _
#discr_tree_simp_key bind_pure_comp -- @bind _ _ _ _ _ (fun @pure _ _ _ _)
#discr_tree_simp_key List.foldlM_pure -- @List.foldlM _ _ _ _ (fun fun @pure _ _ _ _) _ _
#discr_tree_simp_key List.foldr_cons_eq_append -- @List.foldr _ (List _) (fun @List.cons _ _) _ _

@github-actions github-actions bot added the changelog-language Language features, tactics, and metaprograms label May 18, 2025
@Rob23oba Rob23oba force-pushed the discr-tree-lambda branch from fc031be to 8c00fae Compare May 18, 2025 22:27
@Rob23oba Rob23oba marked this pull request as ready for review May 18, 2025 22:27
@Rob23oba Rob23oba force-pushed the discr-tree-lambda branch from c0ac632 to b9dc37b Compare May 19, 2025 08:03
@nomeata
Copy link
Collaborator

nomeata commented May 19, 2025

@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 May 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 19, 2025
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label May 19, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented May 19, 2025

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 19, 2025
@leodemoura
Copy link
Member

We have decided to not support lambda in the DiscrTree type in core. Please consider contributing this PR to RefinedDiscrTree in Mathlib.

@leodemoura leodemoura added the closing soon This issue will be closed soon (<1 month) as it is missing essential features. label May 20, 2025
@Rob23oba
Copy link
Contributor Author

What was the particular reason for this decision? The impact on downstream projects?

@leodemoura
Copy link
Member

What was the particular reason for this decision? The impact on downstream projects?

There are several reasons for my decision:

  • This is a performance-critical file that is used by multiple core modules in Lean.
  • I currently maintain this file, and I’m not satisfied with its performance. I plan to make further changes to it.
  • In my experience, files modified by many different authors tend to accumulate subtle bugs.
  • Discrimination trees are inherently syntactic, but Lean relies on dependent type theory and definitional equality. We've found a compromise that isn't perfect but works reasonably well. Supporting lambdas would introduce additional complexity and potential issues. I've had to debug similar changes in the past.
  • I'm currently overwhelmed with responsibilities and don’t have the bandwidth to context-switch when external contributors modify core components. I’m happy to support contributions that are self-contained or affect less critical parts of the system.
  • We don't yet have a strong benchmark suite. While Mathlib is an important use case, it's not the only one we need to support.
  • Finally, there's another module called LazyDiscrTree, and we aim to keep it in sync with this one.

I appreciate your interest and contributions to Lean. If you're looking for areas where help is especially welcome, I’d be happy to suggest something.

@leodemoura leodemoura closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan changelog-language Language features, tactics, and metaprograms closing soon This issue will be closed soon (<1 month) as it is missing essential features. 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