Skip to content
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

fix: predefinition preprocessing: float .mdata out of non-unary applications #3204

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

nomeata
Copy link
Contributor

@nomeata nomeata commented Jan 22, 2024

Recursive predefinitions contains “rec app” markers as mdata in the predefinitions,
but sometimes these get in the way of termination checking, when you have

  [mdata (fun x => f)] arg

Therefore, the preprocess pass floats them out of applications (originally
only for structural recursion, since #2818 also for well-founded recursion).

But the code was incomplete: Because Meta.transform calls post on f x y only
once (and not also on f x) one has to float out of nested applications as well.

A consequence of this can be that in a recursive proof, rw [foo] does not work
although rw [foo _ _] does.

Also adding the testcase where @david-christiansen and I stumbled over this

(Maybe the two preprocess modules can be combined, now that #2973 is landed, will try that
in a follow-up).

both Structural and WF recursion have a preprocess module (since #2818
at least). Back then I found that betareducing in WF, like it happens
for structural, bytes because it would drop `let_fun` annotations, which
are of course worth preserving.

Now that #2973 is landed let's see if we can do it now.

I hope that this fixes an issue where code like
```
theorem size_rev {α} (arr : Array α) (i : Nat) : (rev arr i).size = arr.size := by
  unfold rev
  split
  · rw [size_rev]
    rw [Array.size_swap]
  · rfl
termination_by arr.size - i
decreasing_by simp_wf; omega
```
fails but works with `size_rev _ _`.

It fails due to some lambda-redexes that maybe go away.

(Maybe we can also/additinally/alternatively track down where that redex
is created and use `.beta` instead of `.app`.)
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 22, 2024 13:14 Inactive
@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 Jan 22, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 22, 2024
@nomeata nomeata changed the title feat: when preprocessing for WF, also beta-reduce fix: predefinition preprocessing: float .mdata out of non-unary applications Jan 22, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 22, 2024 13:49 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 22, 2024
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 22, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 22, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

@nomeata nomeata added the will-merge-soon …unless someone speaks up label Jan 22, 2024
@nomeata nomeata marked this pull request as ready for review January 22, 2024 16:20
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 22, 2024
@nomeata nomeata added this pull request to the merge queue Jan 24, 2024
Merged via the queue into master with commit 409c6ca Jan 24, 2024
20 of 24 checks passed
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 toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN will-merge-soon …unless someone speaks up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants