Skip to content

feat: in app elaborator, beta reduce when substituting arguments #7991

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Apr 17, 2025

This PR modifies the app elaborator so that as arguments are elaborated, they are substituted into the remaining function type with beta reduction. This is useful for eliminator-like applications. In an eliminator, if a user provides an explicit motive, it used to be that that the expression was substituted without beta reduction, even though the @[elab_as_elim] procedure would beta reduce the substituted motive. Now a user-provided motive is similarly beta reduced:

example (xs : List α) : xs ++ [] = xs :=
  List.recOn xs
    (motive := fun xs' => xs' ++ [] = xs')
    (nil := rfl)
    (cons := fun x xs' ih => by rw [List.cons_append, ih])
/-           ^
Before:
⊢ ∀ (head : α) (tail : List α),
  (fun xs' ↦ xs' ++ [] = xs') tail → (fun xs' ↦ xs' ++ [] = xs') (head :: tail)
After (and before when `motive` is deleted):
⊢ ∀ (head : α) (tail : List α),
  tail ++ [] = tail → head :: tail ++ [] = head :: tail
-/

@kmill kmill added the changelog-language Language features, tactics, and metaprograms label Apr 17, 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 Apr 17, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 17, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 17, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Apr 17, 2025

Mathlib CI status (docs):

@leanprover-community-bot leanprover-community-bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Apr 17, 2025
… type

This PR modifies the app elaborator so that as arguments are elaborated, they are substituted into the remaining function type with beta reduction. This is useful for eliminator-like applications. In an eliminator, if a user provides an explicit motive, it was the case that the expression would be beta reduced, but now it is beta reduced like in the `@[elab_as_elim]` procedure:
```lean4
example (xs : List α) : xs ++ [] = xs :=
  List.recOn xs
    (motive := fun xs' => xs' ++ [] = xs')
    (nil := rfl)
    (cons := fun x xs' ih => by rw [List.cons_append, ih])
/-           ^
Before:
⊢ ∀ (head : α) (tail : List α),
  (fun xs' ↦ xs' ++ [] = xs') tail → (fun xs' ↦ xs' ++ [] = xs') (head :: tail)
After (and before when `motive` is deleted):
⊢ ∀ (head : α) (tail : List α),
  tail ++ [] = tail → head :: tail ++ [] = head :: tail
-/
```
@kmill kmill force-pushed the kmill_beta_app_arg branch from a7cd662 to 80c60a0 Compare April 19, 2025 22:35
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Apr 19, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Apr 19, 2025
kmill pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 20, 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-language Language features, tactics, and metaprograms 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