Skip to content

Refactor LoopDefs and LimbSpec into modular subfiles#1

Closed
amit0365 wants to merge 1 commit into
mainfrom
claude/fix-evm-asm-312-HyeVq
Closed

Refactor LoopDefs and LimbSpec into modular subfiles#1
amit0365 wants to merge 1 commit into
mainfrom
claude/fix-evm-asm-312-HyeVq

Conversation

@amit0365
Copy link
Copy Markdown
Owner

Summary

This PR reorganizes the monolithic LoopDefs.lean and LimbSpec.lean files into modular subfiles, improving maintainability and reducing elaboration overhead. The original files are converted to backward-compatible re-export modules.

Key Changes

LoopDefs refactoring:

  • LoopDefs/Iter.lean: Iteration computation functions (mulsubN4, addbackN4, addbackN4_carry) and per-iteration unified postconditions (loopIterPost*)
  • LoopDefs/Post.lean: Loop-exit postcondition (loopExitPost), mulsub-skip/addback body posts, and per-n call-path postconditions
  • LoopDefs/Bundle.lean: Multi-iteration precondition/postcondition bundles (two-, three-, four-iteration pre/posts; unified posts)
  • LoopDefs.lean becomes a backward-compatible re-export of the above submodules

LimbSpec refactoring:

  • LimbSpec/PhaseA.lean: OR-reduce b[0..3] body and BEQ branch to zero path
  • LimbSpec/PhaseB.lean: Phase B initialization (zero q/u, load b[1..2]), tail, and cascade step
  • LimbSpec/PhaseC.lean: CopyAU, NormB, NormA, Phase C2, LoopSetup, CLZ (all stages)
  • LimbSpec/PerLimb.lean: Per-limb helpers (zero path, denorm body, epilogue copy)
  • LimbSpec/Div128.lean: div128 subroutine (Phase 1a/1b, Step 1, un21 computation, Step 2, End phase)
  • LimbSpec/MulSub.lean: Mul-sub building blocks (partA/partB, sub-carry, setup, save-j, composed spec)
  • LimbSpec/Addback.lean: Add-back correction building blocks (partA/partB, finalization, carry init, correction branch)
  • LimbSpec/Branch.lean: Branch/loop-control helpers (store q[j], loop-control j--/BGE, trial quotient loads)
  • LimbSpec.lean becomes a backward-compatible re-export of the above submodules

Implementation Details

  • All computation definitions and theorems are preserved with identical semantics
  • Downstream modules may continue to import EvmAsm.Evm64.DivMod.LoopDefs or EvmAsm.Evm64.DivMod.LimbSpec without changes
  • Individual subfiles can be imported directly for more granular dependency control
  • The refactoring reduces elaboration overhead by breaking large files into focused modules
  • All proofs remain kernel-checkable (no native_decide or bv_decide)

https://claude.ai/code/session_01VpAfgFgnGSL765pD2WbZYL

…M#312)

Break the two monolithic files into focused sub-modules so that editing
a single phase no longer recompiles the entire dependency cone.

LimbSpec.lean (3097 lines) -> LimbSpec/:
  - PerLimb : zero path, denorm per-limb, epilogue copy
  - PhaseA  : Phase A body + BEQ cpsBranch
  - PhaseB  : init, tail, cascade step
  - PhaseC  : CopyAU, NormB, NormA, Phase C2, LoopSetup, CLZ
  - MulSub  : partA/partB, sub-carry, setup, save-j, composed limb
  - Addback : partA/partB, finalization, carry init, correction branch,
              composed limb
  - Branch  : store q[j], loop control, trial quotient (u/vtop/MAX/composed)
  - Div128  : div128 subroutine (Phase 1, Step 1/2, End)

LoopDefs.lean (1377 lines) -> LoopDefs/:
  - Iter   : mulsubN4, addbackN4, div128 helpers, per-n iter{Max,Call,
             Bool-unified}, double-addback variants
  - Post   : loopExitPost, loopBody{Skip,Addback}Post, per-n call-path
             postconditions
  - Bundle : two-/three-/four-iteration pre- and postcondition bundles

The original .lean files become thin re-export shims so every downstream
import keeps working unchanged. Content is preserved verbatim - no proof
or definition changes.
@amit0365 amit0365 closed this May 16, 2026
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.

2 participants