Liking cljdoc? Tell your friends :D

PatternHelpers.v Split Implementation Log

Date: 2025-11-20 Status: Implementation Complete, Testing In Progress


Problem Summary

PatternHelpers.v (591 lines, 21KB) was killed by OOM during compilation despite 126GB RAM limit (50% of system memory).

Root Cause:

  • Nested induction (depth 3) with 42 lia tactic calls
  • Each lia generates large proof terms (50-100 lines)
  • Module dependency chain loads ~65GB of .vo files
  • Proof term size grows as O(C³) where C is context size
  • Total memory: ~65GB dependencies + ~80-100GB proof terms = >150GB

Paradox: 17.5% file size (compared to monolithic) requires >3× memory


Solution Implemented: Split into 3 Files

File 1: PatternHelpers_Basic.v (~241 lines)

Memory Estimate: ~10GB Contents:

  • Prefix preservation lemmas
  • Context preservation lemmas (Initial, BeforeVowel, AfterVowel, etc.)
  • Region structure lemma
  • All proofs use simple tactics (destruct, rewrite, lia)

Compilation: ✅ SUCCESSFUL (verified)

File 2: PatternHelpers_Mismatch.v (~206 lines)

Memory Estimate: ~50GB Contents:

  • Pattern mismatch helper lemmas
  • nth_error_none_implies_no_pattern_match
  • phone_mismatch_implies_no_pattern_match (Admitted - needs Phone_eqb symmetry)
  • pattern_matches_at_has_mismatch (96-line proof with nested induction)

Compilation: 🔄 IN PROGRESS

File 3: PatternHelpers_Leftmost.v (~144 lines)

Memory Estimate: ~80GB Contents:

  • pattern_has_leftmost_mismatch (136-line proof)
  • Deep nested induction with complex leftmost mismatch analysis
  • Most memory-intensive proof in the module

Compilation: ⏳ PENDING


Implementation Details

Files Created

  1. theories/Patterns/PatternHelpers_Basic.v - Basic infrastructure
  2. theories/Patterns/PatternHelpers_Mismatch.v - Mismatch characterization
  3. theories/Patterns/PatternHelpers_Leftmost.v - Leftmost mismatch analysis

Files Modified

  1. _CoqProject - Updated to include 3 new files, removed old PatternHelpers.v
  2. theories/Patterns/PatternOverlap.v - Updated imports:
    From Liblevenshtein.Phonetic.Verification Require Import Patterns.PatternHelpers_Basic.
    From Liblevenshtein.Phonetic.Verification Require Import Patterns.PatternHelpers_Mismatch.
    From Liblevenshtein.Phonetic.Verification Require Import Patterns.PatternHelpers_Leftmost.
    

Original File

  • theories/Patterns/PatternHelpers.v - Kept for reference (not in _CoqProject)

Compilation Configuration

Command:

systemd-run --user --scope \
  -p MemoryMax=126G \
  -p CPUQuota=1800% \
  -p IOWeight=30 \
  -p TasksMax=200 \
  make -j1 2>&1 | tee /tmp/compile_split_files.log

Parameters:

  • Memory limit: 126GB (50% of 252GB system RAM)
  • CPU quota: 1800% (18 cores at 100%)
  • Build parallelism: Serial (-j1) to minimize memory contention
  • I/O priority: 30 (low to avoid disk thrashing)
  • Task limit: 200 (prevent fork bombs)

Expected Outcome

Memory Usage Prediction

  • PatternHelpers_Basic.v: ~10GB ✅ (verified)
  • PatternHelpers_Mismatch.v: ~50GB (peak during pattern_matches_at_has_mismatch)
  • PatternHelpers_Leftmost.v: ~80GB (peak during pattern_has_leftmost_mismatch)

Peak Memory: 80GB < 126GB limit ✅

Success Criteria

  1. All 3 PatternHelpers files compile without OOM
  2. PatternOverlap.v compiles successfully with new imports
  3. Full proof build completes (9 modules total)
  4. Peak memory stays below 126GB

Compilation Progress

Completed (Verified)

  • ✅ theories/Auxiliary/Types.v
  • ✅ theories/Auxiliary/Lib.v
  • ✅ theories/Core/Rules.v
  • ✅ theories/Patterns/Preservation.v
  • ✅ theories/Invariants/InvariantProperties.v
  • ✅ theories/Invariants/AlgoState.v
  • ✅ theories/Patterns/PatternHelpers_Basic.v

In Progress

  • 🔄 theories/Patterns/PatternHelpers_Mismatch.v

Pending

  • ⏳ theories/Patterns/PatternHelpers_Leftmost.v
  • ⏳ theories/Patterns/PatternOverlap.v
  • ⏳ theories/Position_Skipping_Proof.v

Comparison with Previous Attempts

Attempt 1: Parallel Build (-j4) with 150GB

Result: ❌ OOM killed Reason: Multiple files competing for memory

Attempt 2: Serial Build (-j1) with 126GB (Monolithic)

Result: ❌ OOM killed Reason: PatternHelpers.v alone exceeded 126GB

Attempt 3: Serial Build (-j1) with 126GB (Split Files)

Result: ✅ IN PROGRESS Status: PatternHelpers_Basic.v compiled successfully, PatternHelpers_Mismatch.v compiling


Technical Debt / Future Work

  1. Phone_eqb Symmetry Lemma

    • phone_mismatch_implies_no_pattern_match currently Admitted
    • Needs standalone Phone_eqb_sym proof
    • Already proven in PatternOverlap.v (can be extracted)
  2. Deprecation Warnings

    • firstn_length notation deprecated since Coq 8.20
    • Should migrate to length_firstn
    • Affects 3 files: PatternHelpers_Basic.v, Preservation.v
  3. Logical Path Warnings

    • . and theories/ overlap in -R/-Q mappings
    • Should consolidate under single namespace
    • Low priority (warnings only, not errors)

References

  • Problem Analysis: COQ_MEMORY_ANALYSIS.md
  • Monolithic Source: theories/Patterns/PatternHelpers.v (original)
  • Split Implementation: This document
  • Compilation Log: /tmp/compile_split_files.log

Lessons Learned

  1. Modular decomposition paradox: Smaller files can require MORE memory

    • Module loading overhead (~65GB for .vo files)
    • Cannot discard intermediate proof terms at boundaries
    • Proof term explosion amplified by context size
  2. Tactic choice matters: lia generates large proof terms

    • 42 lia calls × ~50-100 lines each = 2,100-4,200 line proof term
    • Manual arithmetic proofs would be smaller but harder to maintain
  3. File splitting strategy:

    • Split by proof complexity, not just LOC count
    • Isolate memory-intensive proofs into separate files
    • Target peak memory < 60-70% of limit for safety margin
  4. Serial vs parallel compilation:

    • Parallel (-j4) faster but less memory efficient
    • Serial (-j1) slower but predictable memory usage
    • For memory-constrained proofs, serial is safer

Last Updated: 2025-11-20 22:30 UTC Next Update: After compilation completes (success or failure)

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close