Skip to content

fix: type mismatches in cbv proof terms about ite/dite/Decide#12811

Closed
wkrozowski wants to merge 3 commits intoleanprover:masterfrom
wkrozowski:fix-cbv-decidable-congr
Closed

fix: type mismatches in cbv proof terms about ite/dite/Decide#12811
wkrozowski wants to merge 3 commits intoleanprover:masterfrom
wkrozowski:fix-cbv-decidable-congr

Conversation

@wkrozowski
Copy link
Contributor

@wkrozowski wkrozowski commented Mar 5, 2026

This PR fixes two issues in cbv's proof term construction for ite/dite/decide.

First, when the condition/proposition is unchanged but the Decidable instance is simplified (e.g. via @[cbv_eval] rules), the proof terms were built using the simplified instance rather than the original, causing kernel type mismatches. Now matchIteDecidable, matchDIteDecidable, and matchDecideInst pattern-match on the simplified instance to determine isTrue/isFalse but use the original instance in the proof term.

Second, when the condition c simplifies to a new c', the tactic previously could not reduce the resulting Decidable instance. Now it derives a Decidable c' instance via decidable_of_decidable_of_eq, simplifies it, and uses new *_congr lemmas (ite_true_congr, dite_true_congr, decide_isTrue_congr, etc.) to produce the correct proof terms.

This PR fixes `cbv`'s handling of `ite`/`dite`/`decide` when the condition is
simplified via congruence. Previously, in the congruence case (where condition
`c` simplifies to `c'`), the tactic would try to simplify the original decidable
instance and fall back to a generic congruence result if it couldn't match
`isTrue`/`isFalse`. Now it constructs a decidable instance for the simplified
condition `c'` via `decidable_of_decidable_of_eq` and tries to match that,
allowing full reduction. New `*_congr` lemmas in `Init.Sym.Lemmas` produce the
correct proof terms for this case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wkrozowski wkrozowski requested a review from leodemoura as a code owner March 5, 2026 13:14
@wkrozowski wkrozowski added the changelog-tactics User facing tactics label Mar 5, 2026
@wkrozowski
Copy link
Contributor Author

!bench

@leanprover-radar
Copy link

leanprover-radar commented Mar 5, 2026

Benchmark results for fb24c80 against fe1ad52 are in! @wkrozowski

  • 🟥 build//instructions: +1.3G (+0.01%)

Large changes (1🟥)

  • 🟥 elab/cbv_merge_sort//instructions: +5.9G (+27.50%)

Small changes (1✅, 2🟥)

  • 🟥 build/module/Init.Sym.Lemmas//instructions: +53.5M (+2.63%)
  • 🟥 build/module/Lean.Meta.Tactic.Cbv.ControlFlow//instructions: +673.9M (+10.24%) (reduced significance based on *//lines)
  • elab/bv_decide_large_aig//instructions: -230.0M (-0.56%)

@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 Mar 5, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fe1ad52f88a2b72913f9cb5f218146cb5a0c584f --onto 333ab1c6f0ce11f33551d6a736054cb72812cad9. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-05 14:01:58)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase fe1ad52f88a2b72913f9cb5f218146cb5a0c584f --onto cda84702e9b31165f1f83c657b532f36f34e0bd0. You can force reference manual CI using the force-manual-ci label. (2026-03-05 14:02:00)

…dite`/`decide`

When `simpAndMatch{Ite,DIte}Decidable` simplified the decidable instance,
the simplified instance was passed to `match{Ite,DIte}Decidable` which used
it in the proof term. This produced a proof about `@decide p simplified_inst`
instead of `@decide p original_inst`, causing a kernel type mismatch.

Now `match{Ite,DIte}Decidable` and `matchDecideInst` take an optional
`inst'` parameter for pattern matching while using the original `inst`
in proof construction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wkrozowski wkrozowski changed the title fix: handle cbv decidable instance resolution in congruence case fix: type mismatches in cbv handling of decide,ite and dite Mar 5, 2026
@wkrozowski
Copy link
Contributor Author

!bench

@leanprover-radar
Copy link

Benchmark results for fb24c80 against fe1ad52 are in! @wkrozowski

  • 🟥 build//instructions: +1.3G (+0.01%)

Large changes (2🟥)

  • 🟥 elab/cbv_arm_ldst//instructions: +4.2G (+5.36%)
  • 🟥 elab/cbv_merge_sort//instructions: +5.9G (+27.50%)

Small changes (1✅, 2🟥)

  • 🟥 build/module/Init.Sym.Lemmas//instructions: +53.5M (+2.63%)
  • 🟥 build/module/Lean.Meta.Tactic.Cbv.ControlFlow//instructions: +673.9M (+10.24%) (reduced significance based on *//lines)
  • elab/bv_decide_large_aig//instructions: -230.0M (-0.56%)

@wkrozowski wkrozowski changed the title fix: type mismatches in cbv handling of decide,ite and dite fix: use original decidable instance in cbv proof terms Mar 5, 2026
@wkrozowski wkrozowski changed the title fix: use original decidable instance in cbv proof terms fix: type mismatches in cbv proof terms about ite/dite/Decide Mar 5, 2026
@wkrozowski wkrozowski added this pull request to the merge queue Mar 5, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 5, 2026
@wkrozowski
Copy link
Contributor Author

Continuing work in #12816

@wkrozowski wkrozowski closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-tactics User facing tactics 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.

3 participants