pub fn optimize_by_cost(
expr: &TLExpr,
context: &CompilerContext,
) -> (TLExpr, CostBasedStats)Expand description
Optimize an expression using cost-based optimization.
This function explores equivalent rewrites and selects the lowest-cost alternative based on estimated execution cost.
ยงExample
use tensorlogic_compiler::optimize::optimize_by_cost;
use tensorlogic_compiler::CompilerContext;
use tensorlogic_ir::{TLExpr, Term};
let mut ctx = CompilerContext::new();
ctx.add_domain("Person", 1000);
let expr = TLExpr::and(
TLExpr::pred("expensive", vec![Term::var("x")]),
TLExpr::pred("cheap", vec![Term::var("x")]),
);
let (optimized, stats) = optimize_by_cost(&expr, &ctx);
assert!(stats.alternatives_explored > 0);