Principle:1kbgz Tributary Symbolic Compilation
| Knowledge Sources | |
|---|---|
| Domains | Symbolic_Computation, Lazy_Evaluation, Streaming |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
A technique for converting symbolic mathematical expressions into executable computation graphs by using lambda compilation to bridge symbolic representation and runtime evaluation.
Description
Symbolic compilation transforms a mathematical expression (represented as a SymPy expression tree) into an executable computation graph. The process:
- Parse: A string is parsed into a SymPy expression using SymPy's parser with implicit multiplication transformation.
- Symbol extraction: Free symbols in the expression are identified as graph inputs.
- Lambda compilation: sympy.lambdify compiles the expression into a Python callable, using numpy/scipy as backend modules.
- Graph construction: A LazyGraph or StreamingGraph subclass is dynamically created with:
- One leaf node per symbol
- An evaluate method that calls the compiled lambda with all symbol nodes
- For streaming: all symbols must be provided as streaming source nodes
This bridges the gap between symbolic mathematics (where expressions are trees of operations) and dataflow programming (where expressions are graphs of nodes). The result is a graph that can be evaluated, modified, visualized, and composed like any Tributary graph.
Usage
Use this principle when you need to convert mathematical formulas into executable graphs:
- Financial models (Black-Scholes, Greeks) expressed as formulas
- Physics equations that need to be evaluated with varying parameters
- Any SymPy expression that benefits from lazy evaluation or streaming execution
Theoretical Basis
SymPy's lambdify function compiles a symbolic expression into a numerical function:
# Abstract symbolic compilation model (NOT real implementation)
import sympy
def compile_to_graph(expr):
symbols = list(expr.free_symbols)
# Compile expression to Python callable
func = sympy.lambdify(symbols, expr, modules=["numpy", "scipy"])
# Create graph class dynamically
class Graph(LazyGraph):
def __init__(self, **kwargs):
for sym in symbols:
self.node(name=sym.name, value=kwargs[sym.name])
self._func = func
super().__init__()
@node
def evaluate(self):
return self._func(*[getattr(self, s.name) for s in symbols])
return Graph
The key transformation is from expression tree to computation graph:
Where each symbol becomes a leaf node and the compiled lambda becomes the evaluation function.