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
52
53
54
55
//! Symbolic differentiation of TLExpr.
//!
//! This module implements formal symbolic differentiation of TensorLogic expressions
//! with respect to named variables. It supports:
//!
//! - Standard arithmetic differentiation rules (sum, product, quotient, power, chain)
//! - Unary transcendental functions (sin, cos, exp, log, sqrt, abs)
//! - Logical differentiation (AND, OR, NOT, implication)
//! - Quantifiers treated as scoped operators (bound variable treated as independent)
//! - Let-bindings via substitution
//! - Jacobian computation for multiple variables
//! - Post-differentiation algebraic simplification
//!
//! # Design Notes
//!
//! In TLExpr, a scalar variable named `"x"` is represented as a zero-arity predicate:
//! `TLExpr::Pred { name: "x".to_string(), args: vec![] }`.
//! This convention is used throughout the codebase and is the basis for variable
//! detection in this module.
//!
//! Arithmetic negation (unary minus) does **not** have its own `TLExpr` variant.
//! It is represented as `TLExpr::Sub(Constant(0.0), inner)` or
//! `TLExpr::Mul(Constant(-1.0), inner)`. The simplification pass recognises the
//! `Sub(0, e)` form and folds it to a negated constant where possible.
//!
//! # Example
//!
//! ```rust
//! use tensorlogic_compiler::symbolic_diff::{differentiate, DiffConfig};
//! use tensorlogic_ir::TLExpr;
//!
//! // d(x * x)/dx → x * 1 + x * 1 → (after simplification) x + x
//! let x = TLExpr::pred("x", vec![]);
//! let expr = TLExpr::mul(x.clone(), x.clone());
//! let config = DiffConfig::default();
//! let result = differentiate(&expr, "x", &config).expect("differentiate");
//! // result.derivative is the symbolic derivative (x + x)
//! ```
pub use ;
pub use simplify_derivative;
pub use ;