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

feat: fine-grained equational lemmas for non-recursive functions #4154

Merged
merged 45 commits into from
Aug 22, 2024

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented May 13, 2024

This is part of #3983.

Fine-grained equational lemmas are useful even for non-recursive functions, so this adds them.

The new option eqns.nonrecursive can be set to false to have the old behavior.

Breaking channge

This is a breaking change: Previously, rw [Option.map] would rewrite Option.map f o to match o with … . Now this rewrite will fail because the equational lemmas require constructors here (like they do for, say, List.map).

Remedies:

  • Split on o before rewriting.
  • Use rw [Option.map.eq_def], which rewrites any (saturated) application of Option.map
  • Use set_option eqns.nonrecursive false when defining the function in question.

Interaction with simp

The simp tactic so far had a special provision for non-recursive functions so that simp [f] will try to use the equational lemmas, but will also unfold f else, so less breakage here (but maybe performance improvements with functions with many cases when applied to a constructor, as the simplifier will no longer unfold to a large match-statement and then collapse it right away).

For projection functions and functions marked [reducible], simp [f] won’t use the equational theorems, and will only use its internal unfolding machinery.

Implementation notes

It uses the same mkEqnTypes function as for recursive functions, so we are close to a consistency here. There is still the wrinkle that for recursive functions we don't split matches without an interesting recursive call inside. Unifying that is future work.

@nomeata nomeata force-pushed the joachim/nonrec-eqns2 branch from 142e1a2 to 5b1e503 Compare May 13, 2024 17:08
@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 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 13, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label May 13, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented May 13, 2024

Mathlib CI status (docs):

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc May 13, 2024 18:09 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 3, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jun 3, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the release-ci Enable all CI checks for a PR, like is done for releases label Jun 3, 2024
nomeata added a commit to nomeata/leansat that referenced this pull request Jun 3, 2024
@nomeata nomeata removed the release-ci Enable all CI checks for a PR, like is done for releases label Aug 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Aug 15, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 15, 2024
to avoid `id` checkpoints in the proof, which would make
the lemma ineligible for dsmip
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the release-ci Enable all CI checks for a PR, like is done for releases label Aug 15, 2024
@nomeata nomeata removed the release-ci Enable all CI checks for a PR, like is done for releases label Aug 15, 2024
@nomeata nomeata requested a review from TwoFX as a code owner August 22, 2024 09:29
@nomeata nomeata disabled auto-merge August 22, 2024 09:29
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc August 22, 2024 09:42 Inactive
nomeata added a commit that referenced this pull request Aug 22, 2024
This is part of #3983.

After #4154 introduced equational lemmas for non-recursive functions and #5055
unififed the lemmas for structural and wf recursive funcitons, this now
disables the special handling of recursive functions in
`findMatchToSplit?`, so that the equational lemmas should be the same no
matter how the function was defined.

The new option `eqns.deepRecursiveSplit` can be disabled to get the old
behavior.

This can break existing code, as there now can be extra equational
lemmas:

* Explicit uses of `f.eq_2` might have to be adjusted if the numbering
  changed.

* Uses of `rw [f]` or `simp [f]` may no longer apply if they previously
  matched (and introduced a `match` statement), when the equational
  lemmas got more fine-grained.

  In this case either case analysis on the parameters before rewriting
  helps, or setting the option `opt.deepRecursiveSplit false` while
  defining the function
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc August 22, 2024 10:34 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Aug 22, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 22, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan and removed builds-mathlib CI has verified that Mathlib builds against this PR labels Aug 22, 2024
@nomeata nomeata changed the title feat: fine-grained equational lemmas for non-recursive equations feat: fine-grained equational lemmas for non-recursive functions Aug 22, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added 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 Aug 22, 2024
@nomeata nomeata added this pull request to the merge queue Aug 22, 2024
Merged via the queue into master with commit d975e43 Aug 22, 2024
33 checks passed
nomeata added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 23, 2024
commit 6d957dc
Author: Joachim Breitner <[email protected]>
Date:   Thu Aug 22 15:10:57 2024 +0200

    Fix proof

commit 5b95381
Merge: 48bea5e bc78dd4
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 22 11:24:01 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 48bea5e
Author: Joachim Breitner <[email protected]>
Date:   Wed Aug 21 18:35:50 2024 +0200

    Switch to Mathlib.Init

commit 4d38bbd
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Wed Aug 21 18:25:08 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit f84b84d
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Wed Aug 21 09:58:00 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit f958309
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Wed Aug 21 09:39:13 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 4b976ec
Author: Joachim Breitner <[email protected]>
Date:   Wed Aug 21 10:54:32 2024 +0200

    Try to remove some nolints

commit 0cbb129
Author: Joachim Breitner <[email protected]>
Date:   Wed Aug 21 10:53:14 2024 +0200

    Reduce diff

commit a485ac8
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Tue Aug 20 08:02:41 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit b5cb54a
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Mon Aug 19 13:09:14 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 8b1ce21
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 12:56:07 2024 +0200

    Like this?

commit e6ce4b5
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 11:38:06 2024 +0200

    nolint attributes

commit e24f1c6
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 11:15:52 2024 +0200

    Another simp only gone

commit a9d54a8
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 11:11:30 2024 +0200

    aesop_cat broke :-(

commit b4edcec
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 11:03:43 2024 +0200

    Use dsimp only

commit 8e66ddd
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 10:28:04 2024 +0200

    Fixes in ComposableArrows

commit 471b000
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 10:18:56 2024 +0200

    Use cond_false

commit 8120390
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 10:14:41 2024 +0200

    No rfl after simp needed anymore

commit 0544693
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 10:13:00 2024 +0200

    Less dsimp only

commit 5cffe6e
Author: Joachim Breitner <[email protected]>
Date:   Mon Aug 19 10:10:21 2024 +0200

    More autoParam

commit 8e019f8
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 17:16:43 2024 +0200

    More fixes

commit 7b6f094
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 17:13:46 2024 +0200

    More fixes

commit 3151f57
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 17:10:35 2024 +0200

    More [autoParam]

commit 54a6616
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 17:07:19 2024 +0200

    Some fixes

commit 9c41f64
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 12:15:03 2024 +0200

    Check for cold cache

commit 66ff376
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 14:54:25 2024 +0200

    No longer needed dsimps?

commit 2298410
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Fri Aug 16 12:24:02 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 8bca337
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 12:17:43 2024 +0200

    Some reasonable fixes

commit 14247a2
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 12:16:08 2024 +0200

    Revert "work-around dsimp Function.eval"

    This reverts commit 8c36154.

commit 0c86721
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Fri Aug 16 10:35:28 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 4b2124e
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Fri Aug 16 09:45:57 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 125f713
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Fri Aug 16 08:51:57 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit af7ab6c
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 08:16:31 2024 +0200

    Style exception

commit f11401e
Author: Joachim Breitner <[email protected]>
Date:   Fri Aug 16 08:08:49 2024 +0200

    toAdditive: transport MatcherInfo

commit 8c36154
Author: Joachim Breitner <[email protected]>
Date:   Thu Aug 15 18:27:00 2024 +0200

    work-around dsimp Function.eval

commit 5fcef86
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 15 14:24:51 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit d4e2758
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 15 13:59:06 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit af1456c
Author: Joachim Breitner <[email protected]>
Date:   Thu Aug 15 15:49:23 2024 +0200

    Fix call to getEqnsFor?

commit c62ab2f
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 15 12:30:12 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit d9bc3e9
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 15 11:47:22 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 40bc4fe
Author: Joachim Breitner <[email protected]>
Date:   Thu Aug 15 10:50:26 2024 +0000

    chore: do not set release-ci label upon failed PR test (#15775)

    with leanprover/lean4#5022 the need for this
    should have disappeared

commit 2ff3b31
Merge: 33a583e b8ad879
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Thu Aug 15 10:32:05 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 33a583e
Merge: 1c951db 85647f2
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Mon Jun 3 15:24:02 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit 1c951db
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Mon May 13 18:13:38 2024 +0000

    Trigger CI for leanprover/lean4#4154

commit f05d463
Author: leanprover-community-mathlib4-bot <[email protected]>
Date:   Mon May 13 17:26:47 2024 +0000

    Update lean-toolchain for testing leanprover/lean4#4154
github-merge-queue bot pushed a commit that referenced this pull request Aug 25, 2024
#5129)

This is part of #3983.

After #4154 introduced equational lemmas for non-recursive functions and
#5055
unififed the lemmas for structural and wf recursive funcitons, this now
disables the special handling of recursive functions in
`findMatchToSplit?`, so that the equational lemmas should be the same no
matter how the function was defined.

The new option `eqns.deepRecursiveSplit` can be disabled to get the old
behavior.

### Breaking change

This can break existing code, as there now can be extra equational
lemmas:

* Explicit uses of `f.eq_2` might have to be adjusted if the numbering
  changed.

* Uses of `rw [f]` or `simp [f]` may no longer apply if they previously
  matched (and introduced a `match` statement), when the equational
  lemmas got more fine-grained.

  In this case either case analysis on the parameters before rewriting
  helps, or setting the option `opt.deepRecursiveSplit false` while
  defining the function
@nomeata nomeata deleted the joachim/nonrec-eqns2 branch August 25, 2024 15:14
tobiasgrosser pushed a commit to opencompl/lean4 that referenced this pull request Aug 26, 2024
leanprover#5129)

This is part of leanprover#3983.

After leanprover#4154 introduced equational lemmas for non-recursive functions and
leanprover#5055
unififed the lemmas for structural and wf recursive funcitons, this now
disables the special handling of recursive functions in
`findMatchToSplit?`, so that the equational lemmas should be the same no
matter how the function was defined.

The new option `eqns.deepRecursiveSplit` can be disabled to get the old
behavior.

### Breaking change

This can break existing code, as there now can be extra equational
lemmas:

* Explicit uses of `f.eq_2` might have to be adjusted if the numbering
  changed.

* Uses of `rw [f]` or `simp [f]` may no longer apply if they previously
  matched (and introduced a `match` statement), when the equational
  lemmas got more fine-grained.

  In this case either case analysis on the parameters before rewriting
  helps, or setting the option `opt.deepRecursiveSplit false` while
  defining the function
nomeata added a commit that referenced this pull request Aug 29, 2024
in #4154 and #5129 the rules for equational lemmas have changed, and new
options were introduced that can be used to revert to the pre-4.12
behavior. Hopefully nobody really needs these options besides for
backwards compatibility, therefore we put these options in the
`backward` option name space.

So the previous behavior can be achieved by setting
```lean
set_option backward.eqns.nonrecursive false
set_option backward.eqns.deepRecursiveSplit false
```
github-merge-queue bot pushed a commit that referenced this pull request Aug 29, 2024
in #4154 and #5129 the rules for equational lemmas have changed, and new
options were introduced that can be used to revert to the pre-4.12
behavior. Hopefully nobody really needs these options besides for
backwards compatibility, therefore we put these options in the
`backward` option name space.

So the previous behavior can be achieved by setting
```lean
set_option backward.eqns.nonrecursive false
set_option backward.eqns.deepRecursiveSplit false
```
bjoernkjoshanssen pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 9, 2024
and with leanprover/lean4#4154 it actually
complains, so let's remove them now.
bjoernkjoshanssen pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 9, 2024
and with leanprover/lean4#4154 it actually
complains, so let's remove them now.
bjoernkjoshanssen pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 12, 2024
and with leanprover/lean4#4154 it actually
complains, so let's remove them now.
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 release-ci Enable all CI checks for a PR, like is done for releases 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