Skip to content

perf: stop two proofs from unfolding executable code - #411

Merged
alexanderlhicks merged 3 commits into
Verified-zkEVM:mainfrom
parithosh:roots-repeated-congr
Nov 18, 2026
Merged

alexanderlhicks merged 3 commits into
Verified-zkEVM:mainfrom
parithosh:roots-repeated-congr

Conversation

@parithosh

Copy link
Copy Markdown
Contributor

Two proofs spent most of their elaboration time in definitional unification that unfolded executable code. Both fixes are local; no statement or axiom set changes anywhere in the library.

Module Before After
Univariate/Roots/LasVegas/Probability/Repeated.lean 37.9 s, 35.8 s 3.4 s, 3.4 s
Bivariate/Deriv.lean 9.2 s, 9.2 s 4.6 s, 5.1 s

Each file run alone with lake env lean on one 4-core machine, alternating old and new.

tryOddSplitAttemptsWith_uniformTable_none_le_geometric (39 s in the profile). Two congr 1 calls tried to close their new goals by rfl, and that failed attempt evaluated tryOddSplitAttemptsWith and cantorZassenhausOddAttemptWith (11.1 s and 18.5 s); they are now refine congrArg _ ?_. exact hhalf (9.1 s) unified oddSplitTrialPMF's trial function with a restated copy of its match, which compiles to a different matcher constant; the failure event is now read off oddSplitTrialPMF directly, and the restated hfailset is gone. The theorem no longer needs set_option maxHeartbeats 1600000: it now passes even under a 25,000 limit (the default is 200,000).

partialDerivX_add (8.6 s). erw [coeff_add, coeff_add] tried the pattern at default transparency against every coefficient in the goal, unfolding Array.getD on each failed match. Plain rw finds the same instances.

Repeated.lean was the last module on the longest import chain. Modelled from recorded per-module times (not measured), that chain drops from about 153 s to about 121 s; on a 4-core machine, where total work dominates, the two changes save about 3% of build CPU.

Tradeoffs.

  • Robustness to refactors: congr 1 and erw adapt to a changed goal shape; refine congrArg _ ?_ relies on Lean inferring the function, and rw needs a syntactic match. If the goal or the definition of CBivariate.coeff changes, these steps may need an explicit function or erw again. They would fail loudly, not admit anything.
  • One private, compiler-generated case splitter moves: tryOddSplitAttemptsWith_uniformTable_none_le_geometric.match_1_1.splitter is replaced by oddSplitTrialPMF.match_1.splitter. Nothing refers to either.

Checks. lake build --wfail, lake build --wfail CompPolyTests, and lake exe axiomsweep --check pass. A per-declaration statement and axiom diff over all 11,711 CompPoly/CompPolyTests declarations is empty except for that splitter.

ampagent and others added 2 commits November 5, 2026 11:35
tryOddSplitAttemptsWith_uniformTable_none_le_geometric spent 39 s in
three tactic calls whose definitional unification evaluated
cantorZassenhausOddAttemptWith and tryOddSplitAttemptsWith:

- two `congr 1` calls tried to close the new goal by `rfl`; they
  are now `refine congrArg _ ?_`.
- `exact hhalf` unified the trial function of oddSplitTrialPMF
  with a restated copy of its `match`, a different matcher constant.
  The failure event is now read off oddSplitTrialPMF directly.

Repeated.lean goes from 37.9 s and 35.8 s to 3.4 s and 3.4 s (alternating
runs, same orb), and the theorem no longer needs maxHeartbeats 1600000.
No statement or axiom set changed across the library.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a66d-72db-7532-b204-db0dff8754a6
Co-authored-by: Parithosh Jayanthi <parithosh@forkchoice.ai>
…_add

`erw` unified the pattern (?p + ?q).coeff ?i ?j at default transparency
against every coefficient in the goal, and each failed match unfolded
into Array.getD (about 8.6 s). Plain `rw` finds the same instances.
Bivariate/Deriv.lean goes from 9.2 s and 9.2 s to 4.6 s and 5.1 s
(alternating runs, same orb). No statement or axiom set changed.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1a66d-72db-7532-b204-db0dff8754a6
Co-authored-by: Parithosh Jayanthi <parithosh@forkchoice.ai>
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Summary

Performance Improvements in Two Proofs

This PR contains two localized performance fixes in separate modules. Neither changes any statement, axiom set, definition signature, or theorem type; the sole effect is a reduction in elaboration time. The changes are independent and are summarized by file below.

Mathematical Formalization / Proof Structure

Both proofs spent the majority of their elaboration time in definitional unification that unfolded executable code:

  • CompPoly/Univariate/Roots/LasVegas/Probability/Repeated.lean – tryOddSplitAttemptsWith_uniformTable_none_le_geometric

    • Two congr 1 calls were replaced with refine congrArg _ ?_. The failed try branches trying to close by rfl were responsible for unfolding tryOddSplitAttemptsWith and cantorZassenhausOddAttemptWith (11.1 s and 18.5 s respectively), accounting for the bulk of the 39 s profile.
    • The auxiliary lemma hfailset (which rewrote a preimage as a set of polynomials) was removed. Instead, the inequality hfail now directly uses PMF.toOuterMeasure_map_apply after rewriting eventProbability and oddSplitTrialPMF.
    • A congrArg-based equality replaces the earlier proof that went through hfailset. The unification failure is now read off oddSplitTrialPMF directly rather than working through a restated copy.
    • The set_option maxHeartbeats 1600000 directive was deleted; the theorem now passes under the default 200,000 heartbeat limit (and even under 25,000).
    • Elapsed time dropped from ~37.9 s / 35.8 s to ~3.4 s / 3.4 s.
  • CompPoly/Bivariate/Deriv.lean – partialDerivX_add

    • erw [coeff_add, coeff_add] was replaced with rw [coeff_add, coeff_add]. The erw tried the rewrite at default transparency against every coefficient in the goal, unfolding Array.getD on each failed match. Plain rw finds the same instances without that overhead.
    • Elapsed time dropped from ~9.2 s / 9.2 s to ~4.6 s / 5.1 s.

Infrastructure / Build Impact

Repeated.lean was the last module on the longest import chain. Modelled per-module times (not directly measured) estimate that the chain drops from about 153 s to about 121 s; on a 4-core machine this projects to roughly a 3% saving in total build CPU.

Tradeoffs / Robustness

  • congr 1 and erw adapt to a changed goal shape; their replacements (refine congrArg _ ?_ and rw) rely on Lean inferring a function or on a syntactic match, respectively. If the goal or the definition of CBivariate.coeff changes, these steps may need an explicit function argument or a return to erw. Both would fail loudly (not silently admit anything).
  • One private, compiler-generated case splitter symbol moves: tryOddSplitAttemptsWith_uniformTable_none_le_geometric.match_1_1.splitter is replaced by oddSplitTrialPMF.match_1.splitter. No other declaration refers to either symbol.

Documentation / PR Body Discrepancy

The PR body omits mention of the removal of hfailset and the maxHeartbeats directive, but the per-file summary for Repeated.lean correctly captures both. No sorry or admit placeholders were introduced.

No sorry / admit Placeholders

Neither file introduces any sorry or admit placeholders.


Statistics

Metric Count
📝 Files Changed 2
✅ Lines Added 12
❌ Lines Removed 19

Lean Declarations

  • No declarations were added, removed, or affected.

sorry Tracking

  • No sorrys were added, removed, or affected.

📋 **Additional Analysis**
  • Style and Naming Guidelines: The diff follows the project's style (2‑space indentation, line length ≤ 100 characters, snake_case for theorem names, lowerCamelCase for functions). Proof changes use rw instead of erw and replace rw chains with refine and congrArg, consistent with the recommendation to write proofs that survive refactoring. No violations.

  • Performance / New Types / Codec: Not relevant to this diff; the changes are a minor proof cleanup and do not affect performance or introduce new types.

  • Pull Request Guidelines: The code changes are small and focused (one topical change per file), matching the “one change per PR” principle. The PR title and description are not part of the diff; therefore compliance with the required title format cannot be assessed from the code alone.

  • Validation: The diff does not show evidence of lake build, lake test, or other validation commands. This information belongs in the PR description, not the code diff.

No violations of the supplied guidelines are present in the code changes themselves.


📄 **Per-File Summaries**
  • CompPoly/Bivariate/Deriv.lean: In CompPoly/Bivariate/Deriv.lean, the proof of partialDerivX_add was modified by replacing erw [coeff_add, coeff_add] with rw [coeff_add, coeff_add], which simplifies the rewriting step without changing the theorem's statement or its semantic content.
  • CompPoly/Univariate/Roots/LasVegas/Probability/Repeated.lean: The proof of tryOddSplitAttemptsWith_uniformTable_none_le_geometric was refactored: the auxiliary lemma hfailset (which rewrote a preimage as a set of polynomials) was removed; the inequality hfail now directly uses PMF.toOuterMeasure_map_apply after rewriting eventProbability and oddSplitTrialPMF, and a congrArg-based equality replaces the earlier rewriting through hfailset. The set_option maxHeartbeats 1600000 line was also deleted. A few congr 1 calls were replaced with more explicit refine congrArg _ ?_ expressions. No definitions, signatures, or theorem statements changed; no sorry or admit were introduced.

Last updated: 2026-11-18 05:00 UTC.

@parithosh parithosh changed the title Roots repeated congr perf: stop two proofs from unfolding executable code Nov 5, 2026
@alexanderlhicks
alexanderlhicks enabled auto-merge (squash) November 18, 2026 05:00
@alexanderlhicks
alexanderlhicks merged commit f98c437 into Verified-zkEVM:main Nov 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants