Skip to content

feat: add short-circuit evaluation for Or and And in cbv#12763

Merged
wkrozowski merged 1 commit intoleanprover:masterfrom
wkrozowski:wojciech/cbv_and_or
Mar 2, 2026
Merged

feat: add short-circuit evaluation for Or and And in cbv#12763
wkrozowski merged 1 commit intoleanprover:masterfrom
wkrozowski:wojciech/cbv_and_or

Conversation

@wkrozowski
Copy link
Copy Markdown
Contributor

@wkrozowski wkrozowski commented Mar 2, 2026

This PR adds pre-pass simprocs simpOr and simpAnd to the cbv tactic that evaluate only the left argument of Or/And first, short-circuiting when the result is determined without evaluating the right side. Previously, cbv processed Or/And via congruence, which always evaluated both arguments. For expressions like decide (m < n ∨ expensive), when m < n is true, the expensive right side is now skipped entirely.

🤖 Generated with Claude Code

This PR adds pre-pass simprocs `simpOr` and `simpAnd` to the `cbv` tactic
that evaluate only the left argument of `Or`/`And` first, short-circuiting
when the result is determined without evaluating the right side. Previously,
`cbv` processed `Or`/`And` via congruence, which always evaluated both
arguments. For expressions like `decide (m < n ∨ expensive)`, when `m < n`
is true, the expensive right side is now skipped entirely. This avoids
exponential blowup in proof term size for examples like Collatz conjecture
verification.

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

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Mar 2, 2026

Benchmark results for f41a502 against 292b423 are in! @wkrozowski

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

Large changes (1✅)

  • elab/cbv_decide//instructions: -10.9G (-12.49%)

Small changes (2🟥)

  • 🟥 build/module/Init.Sym.Lemmas//instructions: +31.9M (+1.67%)
  • 🟥 build/module/Lean.Meta.Tactic.Cbv.ControlFlow//instructions: +955.3M (+16.36%) (reduced significance based on *//lines)

@wkrozowski wkrozowski changed the title feat: add short-circuit evaluation for Or and And in cbv feat: add short-circuit evaluation for Or and And in cbv Mar 2, 2026
@wkrozowski wkrozowski added this pull request to the merge queue Mar 2, 2026
@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 2, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 292b423a17f95489d5d508b9c2b5818b2f430ba7 --onto 87ec768a509c45987a7d73258da0cc1ef047925c. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-02 13:53:47)

@leanprover-bot
Copy link
Copy Markdown
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 292b423a17f95489d5d508b9c2b5818b2f430ba7 --onto 8038a8b8904f89ad9542c8eda11379f8f006eab1. You can force reference manual CI using the force-manual-ci label. (2026-03-02 13:53:49)

Merged via the queue into leanprover:master with commit 6bebf9c Mar 2, 2026
27 checks passed
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