Skip to main content

Module strength_reduction

Module strength_reduction 

Source
Expand description

Strength reduction optimization pass.

This module provides optimizations that replace expensive operations with cheaper equivalents. Examples include:

  • x^2x * x (avoid power function overhead)
  • x^01 (eliminate unnecessary computation)
  • x^1x (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§

StrengthReductionStats
Statistics from strength reduction optimization.

Functions§

reduce_strength
Apply strength reduction optimization to an expression.