1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! 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
//!
//! ```rust
//! 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()));
//! ```
pub use ;
pub use ;