This squashes all local history (768 commits) onto the scrubbed PR #90 baseline. Individual commits were lost during filter-repo corruption; the working tree content is preserved intact. Build: N/A (working tree state only)
3.9 KiB
Microstep Guide for Q16_16 Unification Migration
This guide provides precise steps for migrating any file from PhysicsScalar/ElectromagneticSpectrum to canonical FixedPoint Q16_16.
🔍 PRE-MIGRATION ASSESSMENT
-
Check file dependencies:
cd /home/allaun/Research Stack grep -n "PhysicsScalar\|ElectromagneticSpectrum" 0-Core-Formalism/lean/Semantics/Semantics/FILENAME.lean -
Identify usage patterns:
- Type-only usage:
tension : PhysicsScalar.Q16_16(simple migration) - Function usage:
PhysicsScalar.Q16_16.zero,mean3, etc. (requires bridge) - Mixed usage: Both type and function calls
- Type-only usage:
🔄 SIMPLE TYPE-ONLY MIGRATION
For files that only use Q16_16 as field types (like ManifoldStructures.lean):
Step 1: Update imports
-import Semantics.PhysicsScalar
+import Semantics.FixedPoint
Step 2: Update open statements
-open Semantics.PhysicsScalar
+open Semantics.FixedPoint
Step 3: Test build
cd 0-Core-Formalism/lean/Semantics
lake build Semantics.FILENAME
🌉 FUNCTION-USING MIGRATION
For files that call PhysicsScalar functions:
Step 1: Add bridge import
import Semantics.PhysicsScalarBridge
Step 2: Replace specific function calls
-let value := PhysicsScalar.Q16_16.zero
+let value := Semantics.FixedPoint.Q16_16.zero
-let avg := PhysicsScalar.Q16_16.mean3 a b c
+let avg := Semantics.PhysicsScalarBridge.add (Semantics.PhysicsScalarBridge.add a b) c
+let avg := Semantics.FixedPoint.Q16_16.ofRawInt ((avg_raw + 1) / 3) -- manual conversion
Step 3: Use bridge for arithmetic
-let result := PhysicsScalar.Q16_16.add a b
+let result := Semantics.PhysicsScalarBridge.add a b
⚠️ COMMON COMPILATION ERRORS & FIXES
Error: unknown identifier 'PhysicsScalar.Q16_16.zero'
Fix: Replace with Semantics.FixedPoint.Q16_16.zero or use bridge
Error: type mismatch PhysicsScalar.Q16_16 vs Q16_16
Fix: Ensure all references use the same Q16_16 variant throughout the file
Error: unknown field 'tension'
Fix: The field name is the same; check that the import/open statements are correct
🧪 VERIFICATION STEPS
-
Syntax check:
lake build Semantics.FILENAME --quiet -
Full build verification:
lake build --quiet -
If build fails, common fixes:
- Check that all Q16_16 references use the same variant
- Ensure PhysicsScalarBridge is imported when needed
- Verify field names match between variants (they should be identical)
📋 MIGRATION PRIORITY LIST
Phase 1 - Type-only files (easiest):
- ManifoldStructures.lean ✅ (completed)
- Errors.lean
- SensorField.lean (has complex dependencies - may need partial approach)
Phase 2 - Simple function usage: 4. BoundaryDynamics.lean 5. CausalGeometry.lean
Phase 3 - Complex function usage: 6. PhysicsEuclidean.lean (re-exports PhysicsScalar) 7. PhysicsLagrangian.lean (re-exports PhysicsScalar)
🛠️ BRIDGE FUNCTIONS AVAILABLE
In Semantics.PhysicsScalarBridge:
toFixedPoint : PhysicsScalar.Q16_16 → Semantics.FixedPoint.Q16_16fromFixedPoint : Semantics.FixedPoint.Q16_16 → PhysicsScalar.Q16_16add,mul,sub- bridged arithmetic operations
🚨 RISK MITIGATION
- Always backup:
git stashbefore starting - Small changes: Migrate one file at a time
- Test immediately: Run
lake buildafter each change - Use bridge: When in doubt, use PhysicsScalarBridge for compatibility
- Preserve semantics: Pay attention to signed vs unsigned behavior differences
✅ SUCCESS CRITERIA
- File compiles with
lake build Semantics.FILENAME - Full project builds with
lake build - No new type mismatch errors
- Functionality preserved (semantic equivalence maintained)
This microstep approach allows any LLM to systematically migrate files while maintaining build integrity and semantic correctness.