Skip to content

test: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen#12893

Merged
sgraf812 merged 8 commits intomasterfrom
mvcgen-with-grind
Mar 24, 2026
Merged

test: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen#12893
sgraf812 merged 8 commits intomasterfrom
mvcgen-with-grind

Conversation

@sgraf812
Copy link
Copy Markdown
Contributor

@sgraf812 sgraf812 commented Mar 11, 2026

This PR extends the sym-based mvcgen' tactic with two new modes:

  1. mvcgen' with <tac>: run VCGen, then apply <tac> to each remaining VC.
  2. mvcgen' with grind: integrate grind into the VCGen loop for incremental context internalization. Each VC inherits the parent's E-graph state, so hypothesis processing is shared across sibling VCs, avoiding O(n) re-internalization per VC.

The grind mode accepts the full grind configuration syntax (mvcgen' with grind (config := { ... }) [params]).

A persistent Sym.Simp cache with a reassocNatAdd simproc normalizes hypothesis types (e.g., s + 1 + 1 + 1s + 3) before grind internalization, achieving O(1) amortized simplification per VC.

Benchmark results for GetThrowSet (mvcgen' with grind):

  • n=100: 400ms total, 180ms kernel
  • n=250: 855ms total, 1.8s kernel
  • n=500: 1.9s total, 11.8s kernel

Kernel checking time grows superlinearly and is the dominant cost at larger sizes. This is a separate issue from VCGen performance.

…VCGen

This PR extends the sym-based `mvcgen'` tactic with two new modes:

1. `mvcgen' with <tac>`: run VCGen, then apply `<tac>` to each VC.
2. `mvcgen' with grind`: integrate grind into the VCGen loop for
   incremental context internalization. Each VC inherits the parent's
   E-graph state, so hypothesis processing is shared across sibling
   VCs. This avoids O(n) re-internalization per VC.

The grind mode accepts the full grind configuration syntax
(`mvcgen' with grind (config := { ... }) [params]`).

Key implementation details:
- `WorkItem` carries `MVarId × Option Grind.Goal` through the worklist
- `VCGenM` wraps `GrindM` (which wraps `SymM`), so all existing
  operations lift automatically
- `emitVC` uses `withNewMCtxDepth` + `resolveDelayedAssignments` to
  isolate grind's internal mvars and produce clean proofs
- `internalizePending` shares hypothesis internalization before forking,
  with rollback on inconsistency so children can construct their own
  proofs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 11, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing bot commented Mar 11, 2026

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4450ff89958bd479af79da62fa1949931b81351b --onto e8048291010c815d0d30926924e7ad7afc18b1c0. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-11 20:02:57)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-03-13 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-14 07:31:57)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 7ef25b8fe3a9b845e976a65032b2edb458e62471 --onto e6df474dd9c3ad0e21771eaa808c53f66222216d. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-24 11:53:40)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented Mar 11, 2026

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 4450ff89958bd479af79da62fa1949931b81351b --onto ff6816a854ef5cf2966519452d03933785f2fdeb. You can force reference manual CI using the force-manual-ci label. (2026-03-11 20:02:59)
  • ✅ Reference manual branch lean-pr-testing-12893 has successfully built against this PR. (2026-03-14 07:37:59) View Log
  • 🟡 Reference manual branch lean-pr-testing-12893 build against this PR didn't complete normally. (2026-03-14 07:39:08) View Log
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 7ef25b8fe3a9b845e976a65032b2edb458e62471 --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-24 11:53:41)

sgraf812 and others added 3 commits March 13, 2026 07:11
This removes the reimplemented `resolveDelayedAssignments` and the manual
`withNewMCtxDepth` + `mkFreshExprSyntheticOpaqueMVar` pattern in `emitVC`,
replacing them with a call to `Grind.withProtectedMCtx`. On exception,
`withProtectedMCtx` admits the goal, so we save/restore the `MetavarContext`
to undo the admit and fall back to emitting an unsolved VC.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts:
#	tests/bench/mvcgen/sym/lakefile.lean
#	tests/bench/mvcgen/sym/lib/VCGen.lean
…gen' with grind`

This PR adds a persistent `Sym.Simp.State` cache to VCGen and a
`reassocNatAdd` simproc that rewrites `(a + m) + n → a + (m + n)` for
Nat literals. Hypotheses and targets are simplified via `replaceLocalDeclDefEq`
and `replaceTargetDefEq` (O(1)) before grind internalization, avoiding
O(n) re-internalization of unsimplified `s + 1 + 1 + ...` chains.

The persistent cache gives O(1) amortized simplification per VC since
pointer-based cache hits on shared subexpressions avoid redundant work.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Mar 14, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Mar 14, 2026
sgraf812 and others added 4 commits March 24, 2026 09:56
…impTarget` from sym VCGen

This PR refactors `mvcgen' with grind` for clarity and correctness:
- Replace `grindMode : Bool` with `Option GrindContext` in `VCGen.Context`,
  storing `hypSimpMethods` for configurable hypothesis simplification
- Remove `normalizeLevelsExpr` in `work` (superseded by #12923)
- Remove `simpTarget` — let grind simplify targets as it sees fit
- Remove `tryCatchRuntimeEx` around `withProtectedMCtx` — let exceptions propagate
- Extract `mkGrindParamsFromSyntax` helper
- Revert unrelated `AddSubCancel` spec change from 8fc4ea8
- Use `fail` instead of `sorry` in `mvcgen' with grind` test cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`getOptional?` requires exactly 1 child but `(&" with " tactic)?`
produces 2 (keyword + tactic), so use `getNumArgs` instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sgraf812 sgraf812 changed the title test: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen feat: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen Mar 24, 2026
@sgraf812 sgraf812 marked this pull request as ready for review March 24, 2026 11:00
@sgraf812 sgraf812 changed the title feat: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen test: add mvcgen' with <tac> and mvcgen' with grind to sym-based VCGen Mar 24, 2026
@sgraf812 sgraf812 added this pull request to the merge queue Mar 24, 2026
Merged via the queue into master with commit 83c6f6e Mar 24, 2026
21 of 22 checks passed
@sgraf812 sgraf812 deleted the mvcgen-with-grind branch March 24, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR 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