Skip to main content

Module partial_eval

Module partial_eval 

Source
Expand description

Partial evaluation / expression specialization for TLExpr.

Given a set of concrete bindings for some variables while leaving others free/symbolic, this module reduces an expression as much as possible. This is strictly more powerful than plain constant propagation because it handles mixed symbolic-concrete environments and enables expression specialization across a range of inputs.

§Variable Convention

Following the established codebase convention, a scalar “variable” named "x" is represented as a zero-arity predicate: TLExpr::Pred { name: "x", args: [] }. Booleans are encoded as TLExpr::Constant(1.0) (true) and TLExpr::Constant(0.0) (false).

§Example

use tensorlogic_compiler::partial_eval::{PEEnv, PEConfig, partially_evaluate};
use tensorlogic_ir::TLExpr;

// Expression: x + y  (both are zero-arity predicates acting as variables)
let x = TLExpr::pred("x", vec![]);
let y = TLExpr::pred("y", vec![]);
let expr = TLExpr::add(x, y);

// Partially evaluate with x = 3.0; y stays symbolic
let env = PEEnv::new().with_f64("x", 3.0);
let config = PEConfig::default();
let result = partially_evaluate(&expr, &env, &config);

// Result should be: Add(Constant(3.0), Pred("y", []))
// (not fully concrete because y is still free)
assert!(result.residual_vars.contains(&"y".to_string()));

Structs§

PEConfig
Configuration governing which reductions are attempted during partial evaluation.
PEEnv
Partial-evaluation environment: a map from variable name to its known PEValue.
PEResult
The result of partially evaluating an expression.
PEStats
Statistics accumulated during a partial evaluation run.

Enums§

PEValue
A value in partial evaluation — either a concrete numeric scalar, a concrete boolean, or still symbolic (cannot be reduced further with current environment).

Functions§

partially_evaluate
Partially evaluate expr under env according to config.
specialize
Specialize expr by binding all provided (name, f64) pairs and returning the residual expression.
specialize_batch
Multi-point specialization: evaluate expr at multiple binding sets and return one PEResult per binding set, in the same order as binding_sets.