Expand description
Distributivity optimization pass.
This module provides optimizations based on distributive laws to either expand or factor expressions based on computational cost analysis.
§Operations
- Expansion:
a * (b + c)→a*b + a*c(when beneficial) - Factoring:
a*b + a*c→a * (b + c)(when beneficial) - Distribution over logic:
a AND (b OR c)→(a AND b) OR (a AND c)
§Cost Model
The optimization uses a simple cost model where:
- Addition/Subtraction: cost 1
- Multiplication: cost 2
- Division: cost 4
- Power: cost 8
Factoring is preferred when it reduces total operation count.
Structs§
- Distributivity
Stats - Statistics from distributivity optimization.
Functions§
- optimize_
distributivity - Apply distributivity optimization to an expression.