mixle.engines.symbolic_engine module¶
A small dependency-free symbolic compute engine.
The symbolic engine is for expression tracing, generated-kernel inspection, and lightweight algebraic experiments. Numeric execution remains the job of NumPy/Torch engines; arrays here are NumPy object arrays of scalar expression nodes so generated kernels can be inspected without a separate runtime.
- class SymbolicExpression(op, args=())[source]
Bases:
objectA tiny immutable symbolic expression tree.
- op: str
- static symbol(name)[source]
Create a named symbolic variable node.
- Parameters:
name (str)
- Return type:
SymbolicExpression
- static constant(value)[source]
Create a symbolic constant node.
- Parameters:
value (Any)
- Return type:
SymbolicExpression
- static call(op, *args)[source]
Create an operation node with symbolic arguments.
- evaluate(values)[source]
Evaluate the expression with a mapping from symbol names to values.
- symbols()[source]
Return sorted symbolic variable names referenced by this expression.
- class SymbolicEngine[source]
Bases:
ComputeEngineSmall symbolic expression engine over scalar nodes and object arrays.
- name = 'symbolic'
- supports_autograd = False
- pi = pi
- e = e
- euler_gamma = euler_gamma
- inf = inf
- zero = 0
- one = 1
- two = 2
- half = (1 / 2)
- with_precision(precision)[source]
Return this engine unchanged: symbolic expressions carry no float precision policy.
The numeric engines swap their float dtype here, but symbolic nodes are exact expression trees with no reduced-precision representation, so precision adjustment is a no-op rather than an error – this lets backend-neutral code call
with_precisionuniformly across engines.- Parameters:
precision (Any)
- Return type:
SymbolicEngine
- constant(value)[source]
Return
valueas a symbolic constant node.- Parameters:
value (Any)
- Return type:
SymbolicExpression
- symbol(name)[source]
Return a named symbolic expression variable.
- Parameters:
name (str)
- Return type:
SymbolicExpression
- asarray(x, dtype=None)[source]
Convert scalars/arrays/strings into symbolic expression objects.
- zeros(shape, dtype=None)[source]
Return an object array filled with symbolic zero constants.
- empty(shape, dtype=None)[source]
Return an uninitialized object array for symbolic expressions.
- arange(*args, **kwargs)[source]
Return symbolic constants corresponding to
np.arangevalues.
- to_numpy(x)[source]
Return
xas a NumPy object array without numeric evaluation.
- evaluate(x, values)[source]
Evaluate a scalar expression or object-array expression tree.
- symbols(x)[source]
Return sorted symbolic variable names referenced by
x.
- op_counts(x)[source]
Return aggregate operation counts over a scalar or array expression.
- diagnostics(x)[source]
Return a compact diagnostic summary for generated-kernel inspection.
- stack(arrays, axis=0)[source]
Stack symbolic arrays with NumPy object-array semantics.
- static log(x)
- static exp(x)
- static sqrt(x)
- static abs(x)
- static floor(x)
- static gammaln(x)
- static digamma(x)
- static erf(x)
- static sum(x, axis=None, *args, **kwargs)[source]
Return a symbolic sum reduction over
axis.
- static logsumexp(x, axis=None, *args, **kwargs)[source]
Return a symbolic log-sum-exp reduction over
axis.
- static where(cond, x, y)[source]
Return a symbolic elementwise conditional expression.
- static maximum(x, y)[source]
Return a symbolic elementwise maximum expression.
- static less(x, y)[source]
Return a symbolic less-than comparison.
- static less_equal(x, y)[source]
Return a symbolic less-than-or-equal comparison.
- static greater(x, y)[source]
Return a symbolic greater-than comparison.
- static greater_equal(x, y)[source]
Return a symbolic greater-than-or-equal comparison.
- static equal(x, y)[source]
Return a symbolic equality comparison.
- static not_equal(x, y)[source]
Return a symbolic inequality comparison.
- static logical_and(x, y)[source]
Return a symbolic elementwise logical-and expression.
- static logical_or(x, y)[source]
Return a symbolic elementwise logical-or expression.
- static logical_not(x)[source]
Return a symbolic elementwise logical-not expression.
- static clip(x, a_min=None, a_max=None)[source]
Return a symbolic clipped expression.
- static isnan(x)
- static isinf(x)
- static max(x, axis=None, *args, **kwargs)
- static dot(x, y)
- static matmul(x, y)
- static cumsum(x, axis=None, *args, **kwargs)
- static bincount(x, *args, **kwargs)
- static unique(x, *args, **kwargs)
- static searchsorted(x, y, *args, **kwargs)
- static betaln(x, y)
- index_add(out, index, values)[source]
Return a symbolic index-add operation node.
- static to_sympy(x)[source]
Lower a symbolic expression (or object array) to a sympy expression.
- static to_sage(x)[source]
Lower a symbolic expression (or object array) to a sage expression.
- SYMBOLIC_ENGINE = <mixle.engines.symbolic_engine.SymbolicEngine object>
Shared symbolic engine; arithmetic on symbolic nodes/object arrays dispatches here.