Skip to content

Latest commit

 

History

History
434 lines (324 loc) · 15.2 KB

File metadata and controls

434 lines (324 loc) · 15.2 KB

Build Fix Strategy for RustMath

Generated: 2025-11-23 Purpose: Comprehensive analysis and remediation plan for all build errors and warnings in build.log


Executive Summary

The build log reveals 23 compilation errors and 21 warnings across two main areas:

  1. rustmath-benchmarks: Missing benchmark files (3) + API incompatibility issues (20)
  2. rustmath-symbolic & rustmath-matrix: Various unused code warnings (21)

Critical Path: Fix rustmath-benchmarks errors first (blocking compilation), then address warnings for code cleanliness.


Part 1: CRITICAL ERRORS (23 total - Blocks Compilation)

Category A: Missing Benchmark Files (3 errors)

Problem: Cargo.toml declares 4 benchmark binaries but only 1 file exists.

Missing Files:

  • rustmath-benchmarks/src/bench_integers.rs
  • rustmath-benchmarks/src/bench_matrix.rs
  • rustmath-benchmarks/src/bench_polynomials.rs
  • rustmath-benchmarks/src/bench_symbolic.rs ✓ (exists but has API errors)

Root Cause: Incomplete implementation of benchmarking infrastructure from recent PR #562.

Solution Strategy:

  1. Create placeholder benchmark files following the pattern established in bench_symbolic.rs
  2. Each file should include:
    • Similar CLI argument structure (clap::Parser)
    • JSON output support
    • Multiple benchmark functions covering common operations
    • Consistent timing methodology

Implementation Complexity: Medium (need to design meaningful benchmarks for each domain)


Category B: API Incompatibility in bench_symbolic.rs (20 errors)

Problem: Code uses deprecated/non-existent API patterns from rustmath-symbolic.

Error Patterns:

Pattern 1: Symbol.pow() doesn't exist (2 occurrences)

// WRONG (lines 26-27)
let expr = Expr::from(5) * x.clone().pow(Expr::from(5))

// Error: no method named `pow` found for struct `Symbol`

Fix: Convert Symbol to Expr first

// CORRECT
let expr = Expr::from(5) * Expr::Symbol(x.clone()).pow(Expr::from(5))

Affected Lines: 26, 27


Pattern 2: Expr::Var() doesn't exist (18 occurrences)

// WRONG
Expr::Var(x.clone())

// Error: no variant or associated item named `Var` found for enum `Expr`

Context: The rustmath-symbolic API changed:

  • Old API: Expr::Var(symbol)
  • New API: Expr::Symbol(symbol) or Expr::symbol(name)

Fix Options:

  1. Direct enum variant: Expr::Symbol(x.clone())
  2. Constructor function: Expr::symbol(x.name()) (requires name accessor)

Affected Lines: 28, 43, 44, 59, 75, 76, 77, 92, 109, 110, 126 (x2), 140, 141, 156, 157, 158

Recommended Fix: Use Expr::Symbol(x.clone()) for consistency with existing Symbol instances.


Part 2: WARNINGS (21 total - Non-blocking)

Category C: Unused Imports (6 warnings)

File Line Import Status
diffeq.rs 323 BinaryOp Remove
pattern/matcher.rs 4 UnaryOp Remove
pattern/matcher.rs 5 crate::symbol::Symbol Remove
pattern/rules.rs 3 Substitution Remove
printing/unicode.rs 6 std::fmt Remove

Fix: Delete unused imports from use statements.

Automated Fix Available: cargo fix --lib -p rustmath-symbolic (suggested by compiler)


Category D: Unused Variables (10 warnings)

File Line Variable Suggested Fix
diffeq.rs 367 dm_dy Prefix with _dm_dy
diffeq.rs 368 dn_dx Prefix with _dn_dx
diffeq.rs 580 mut dx Remove mut
factor.rs 177 degree Prefix with _degree
function.rs 23 args Prefix with _args
function.rs 23 arg_index Prefix with _arg_index
pde.rs 257 initial_velocity Prefix with _initial_velocity
series.rs 764 var Prefix with _var
specialfunctions/airy.rs 269 c2 Prefix with _c2

Context: Variables computed but never used, often in incomplete implementations.

Fix Options:

  1. Prefix with underscore if intentionally unused (silences warning)
  2. Delete the binding if truly unnecessary
  3. Implement the missing logic if variable was meant to be used

Recommended: Review each case individually - some may indicate incomplete implementations.


Category E: Dead Code (5 warnings)

File Line Item Type Action
polynomial_matrix.rs 350 scalar_mul trait method Keep (may be used via trait) OR mark #[allow(dead_code)]
printing/unicode.rs 31 to_subscript function Keep for future use OR mark #[allow(dead_code)]
solve.rs 1687 expr_to_rational function Keep for future use OR mark #[allow(dead_code)]
solve.rs 1714 expr_to_integer function Keep for future use OR mark #[allow(dead_code)]
specialfunctions/other.rs 40 try_expr_to_f64 function Keep for future use OR mark #[allow(dead_code)]

Analysis: These appear to be helper functions/methods that may be used in future implementations.

Recommended: Add #[allow(dead_code)] attribute rather than deleting, since this is active development.


Category F: Naming Convention Violations (2 warnings)

File Line Variable Issue Fix
specialfunctions/orthogonal_polys.rs 505 N Should be snake_case Rename to n_param or total_n
specialfunctions/orthogonal_polys.rs 553 N Should be snake_case Rename to n_param or total_n

Context: Parameter N conflicts with parameter n in same function signature (Hahn and Krawtchouk polynomials).

Mathematical Context: In orthogonal polynomial theory, N often represents a domain size parameter distinct from degree n.

Recommended Fix: Rename to n_max or domain_size to preserve mathematical meaning while following Rust conventions.


Part 3: IMPLEMENTATION PLAN

Phase 1: Fix Critical Errors (Priority: HIGHEST)

Objective: Make the project compile successfully.

Task 1.1: Fix bench_symbolic.rs API Usage

  • Time Estimate: 10 minutes
  • Complexity: Low (mechanical find-replace)
  • Steps:
    1. Replace all Expr::Var(x)Expr::Symbol(x)
    2. Replace x.clone().pow(...)Expr::Symbol(x.clone()).pow(...)
    3. Verify all 20 error locations addressed
  • Validation: cargo build -p rustmath-benchmarks --bin bench_symbolic

Task 1.2: Create bench_integers.rs

  • Time Estimate: 30 minutes
  • Complexity: Medium
  • Steps:
    1. Copy structure from bench_symbolic.rs
    2. Design benchmarks for:
      • Prime factorization (Pollard's Rho algorithm)
      • Primality testing (Miller-Rabin)
      • GCD computation (Euclidean algorithm)
      • Modular exponentiation
      • Large integer arithmetic (add/mul/div)
    3. Implement CLI argument parsing
  • Validation: cargo build -p rustmath-benchmarks --bin bench_integers

Task 1.3: Create bench_matrix.rs

  • Time Estimate: 30 minutes
  • Complexity: Medium
  • Steps:
    1. Copy structure from bench_symbolic.rs
    2. Design benchmarks for:
      • Matrix multiplication (various sizes)
      • Determinant computation (PLU decomposition)
      • Matrix inversion
      • LU decomposition
      • Gaussian elimination
    3. Test with Integer, Rational, and Rational matrices
  • Validation: cargo build -p rustmath-benchmarks --bin bench_matrix

Task 1.4: Create bench_polynomials.rs

  • Time Estimate: 30 minutes
  • Complexity: Medium
  • Steps:
    1. Copy structure from bench_symbolic.rs
    2. Design benchmarks for:
      • Polynomial multiplication
      • Polynomial division
      • GCD computation
      • Factorization
      • Evaluation
    3. Test univariate and multivariate cases
  • Validation: cargo build -p rustmath-benchmarks --bin bench_polynomials

Phase 1 Total Time: ~2 hours


Phase 2: Address Warnings (Priority: MEDIUM)

Objective: Clean up codebase to warning-free state.

Task 2.1: Remove Unused Imports (Automated)

  • Command: cargo fix --lib -p rustmath-symbolic --allow-dirty
  • Fallback: Manual removal from 5 files
  • Time: 5 minutes

Task 2.2: Fix Unused Variable Warnings

  • Approach: Review each variable for intended use
  • Files to modify: 6 files in rustmath-symbolic
  • Time: 20 minutes

Task 2.3: Mark Dead Code Appropriately

  • Action: Add #[allow(dead_code)] to 5 functions/methods
  • Rationale: Preserve for future use
  • Time: 10 minutes

Task 2.4: Fix Naming Conventions

  • Files: specialfunctions/orthogonal_polys.rs
  • Action: Rename Nn_max in 2 functions
  • Impact: API change (may affect other code)
  • Time: 15 minutes

Phase 2 Total Time: ~50 minutes


Part 4: PARALLEL EXECUTION STRATEGY

To maximize efficiency, errors can be fixed in parallel by different developers/agents:

Parallel Track A: bench_symbolic.rs API fixes

Dependencies: None Files: 1 Time: 10 minutes

Parallel Track B: Create bench_integers.rs

Dependencies: None Files: 1 (new) Time: 30 minutes

Parallel Track C: Create bench_matrix.rs

Dependencies: None Files: 1 (new) Time: 30 minutes

Parallel Track D: Create bench_polynomials.rs

Dependencies: None Files: 1 (new) Time: 30 minutes

Parallel Track E: Fix all warnings

Dependencies: None Files: 7 Time: 50 minutes

Maximum Parallelization: All 5 tracks can run simultaneously. Wall-clock time: ~50 minutes (limited by Track E) Sequential time: ~3 hours


Part 5: ONE-LINER FIX PROMPTS (For Parallel Execution)

Prompt 1: Fix bench_symbolic.rs API incompatibility

Replace all occurrences of `Expr::Var(x)` with `Expr::Symbol(x)` and `x.clone().pow(...)` with `Expr::Symbol(x.clone()).pow(...)` in rustmath-benchmarks/src/bench_symbolic.rs to fix the 20 API compatibility errors.

Prompt 2: Create bench_integers.rs

Create rustmath-benchmarks/src/bench_integers.rs following the pattern of bench_symbolic.rs with benchmarks for: prime factorization (Pollard's Rho), primality testing (Miller-Rabin), GCD, modular exponentiation, and large integer arithmetic operations (add/mul/div).

Prompt 3: Create bench_matrix.rs

Create rustmath-benchmarks/src/bench_matrix.rs following the pattern of bench_symbolic.rs with benchmarks for: matrix multiplication (various sizes), determinant (PLU decomposition), inversion, LU decomposition, and Gaussian elimination over Integer and Rational types.

Prompt 4: Create bench_polynomials.rs

Create rustmath-benchmarks/src/bench_polynomials.rs following the pattern of bench_symbolic.rs with benchmarks for: polynomial multiplication, division, GCD, factorization, and evaluation for both univariate and multivariate cases.

Prompt 5: Fix all unused import warnings

Remove all unused imports from rustmath-symbolic: remove BinaryOp from diffeq.rs:323, UnaryOp from pattern/matcher.rs:4, Symbol from pattern/matcher.rs:5, Substitution from pattern/rules.rs:3, and std::fmt from printing/unicode.rs:6.

Prompt 6: Fix all unused variable warnings

Fix unused variable warnings in rustmath-symbolic by prefixing with underscore: _dm_dy (diffeq.rs:367), _dn_dx (diffeq.rs:368), remove mut from dx (diffeq.rs:580), _degree (factor.rs:177), _args and _arg_index (function.rs:23), _initial_velocity (pde.rs:257), _var (series.rs:764), _c2 (specialfunctions/airy.rs:269).

Prompt 7: Suppress dead code warnings

Add #[allow(dead_code)] attribute to: scalar_mul method (polynomial_matrix.rs:350), to_subscript function (printing/unicode.rs:31), expr_to_rational (solve.rs:1687), expr_to_integer (solve.rs:1714), and try_expr_to_f64 (specialfunctions/other.rs:40).

Prompt 8: Fix naming convention violations

Rename parameter `N` to `n_max` in hahn_polynomial (specialfunctions/orthogonal_polys.rs:505) and krawtchouk_polynomial (specialfunctions/orthogonal_polys.rs:553) to follow snake_case naming conventions.

Part 6: VALIDATION PLAN

Success Criteria

  1. cargo build completes without errors
  2. cargo build produces zero warnings
  3. ✅ All 4 benchmark binaries compile successfully
  4. cargo test continues to pass (no regressions)

Validation Commands

# Full build
cargo build 2>&1 | tee build_after_fix.log

# Build each benchmark
cargo build -p rustmath-benchmarks --bin bench_symbolic
cargo build -p rustmath-benchmarks --bin bench_integers
cargo build -p rustmath-benchmarks --bin bench_matrix
cargo build -p rustmath-benchmarks --bin bench_polynomials

# Run test suite
cargo test

# Count remaining warnings
cargo build 2>&1 | grep "warning:" | wc -l  # Should be 0

Part 7: RISK ASSESSMENT

Low Risk

  • bench_symbolic.rs API fixes: Mechanical replacement, well-understood API
  • Unused import removal: No behavioral changes
  • Dead code suppression: Only silences warnings

Medium Risk

  • Creating new benchmark files: May contain logic errors in benchmarks
  • Unused variable fixes: Could hide intentional but incomplete implementations

High Risk

  • Naming convention fixes (N → n_max): API change that may affect external code or tests

Mitigation

  • Run full test suite after each phase
  • Review git diff before committing
  • Test each benchmark binary manually
  • Search codebase for references to renamed parameters

Part 8: ESTIMATED IMPACT

Before Fixes

  • Compilation: ❌ FAILS
  • Errors: 23
  • Warnings: 21
  • Usable benchmarks: 0/4

After Fixes

  • Compilation: ✅ SUCCESS
  • Errors: 0
  • Warnings: 0
  • Usable benchmarks: 4/4

Developer Experience Impact

  • Removes all build noise
  • Enables benchmarking infrastructure for performance tracking
  • Establishes pattern for future benchmark development
  • Clean build encourages further contributions

APPENDIX: Error Location Reference

bench_symbolic.rs Error Map

Line 26:  x.clone().pow()          → Symbol doesn't have pow()
Line 27:  x.clone().pow()          → Symbol doesn't have pow()
Line 28:  Expr::Var()              → Var variant doesn't exist
Line 43:  Expr::Var()              → Var variant doesn't exist
Line 44:  Expr::Var()              → Var variant doesn't exist
Line 59:  Expr::Var()              → Var variant doesn't exist
Line 75:  Expr::Var()              → Var variant doesn't exist
Line 76:  Expr::Var()              → Var variant doesn't exist
Line 77:  Expr::Var()              → Var variant doesn't exist
Line 92:  Expr::Var()              → Var variant doesn't exist
Line 109: Expr::Var()              → Var variant doesn't exist
Line 110: Expr::Var()              → Var variant doesn't exist
Line 126: Expr::Var(x)             → Var variant doesn't exist
Line 126: Expr::Var(y)             → Var variant doesn't exist
Line 140: Expr::Var()              → Var variant doesn't exist
Line 141: Expr::Var()              → Var variant doesn't exist
Line 156: Expr::Var()              → Var variant doesn't exist
Line 157: Expr::Var()              → Var variant doesn't exist
Line 158: Expr::Var()              → Var variant doesn't exist

Document Status: ✅ Ready for Implementation Next Step: Execute parallel fix prompts Expected Completion: 50 minutes (parallel) | 3 hours (sequential)