Expand description
Strength reduction optimization pass.
This module provides optimizations that replace expensive operations with cheaper equivalents. Examples include:
x^2→x * x(avoid power function overhead)x^0→1(eliminate unnecessary computation)x^1→x(eliminate identity operation)exp(0)→1(constant evaluation)log(1)→0(constant evaluation)sqrt(x*x)→abs(x)(eliminate redundant sqrt)
§Examples
use tensorlogic_compiler::optimize::reduce_strength;
use tensorlogic_ir::{TLExpr, Term};
// x^2 → x * x
let x = TLExpr::pred("x", vec![Term::var("i")]);
let expr = TLExpr::pow(x, TLExpr::Constant(2.0));
let (optimized, stats) = reduce_strength(&expr);
assert!(stats.power_reductions > 0);Structs§
- Strength
Reduction Stats - Statistics from strength reduction optimization.
Functions§
- reduce_
strength - Apply strength reduction optimization to an expression.