boundlab.expr.Expr#
- class boundlab.expr.Expr[source]#
Bases:
objectAbstract base class for all symbolic expressions in BoundLab.
Each expression represents a node in a directed acyclic graph (DAG) of computations. Expressions are immutable after construction, and each instance is assigned a unique time-ordered UUID to enable deterministic topological ordering during bound propagation.
Subclasses must implement
shape,children, andbackward()to define the expression’s semantics.Methods
Perform backward-mode bound propagation through this expression.
Compute the width of the bounds for this expression.
Compute the center of the bounds for this expression.
Return the concrete tensor if self is a pure constant expression, else None.
Recursively compute Jacobian ops for affine expressions.
Compute a lower bound for this expression.
Return string representation with child strings substituted.
Compute an upper bound for this expression.
Compute both an upper bound and a lower bound for this expression.
Return a new expression with the same type and flags but new children.
- with_children(*new_children)[source]#
Return a new expression with the same type and flags but new children.
- property shape: torch.Size#
The shape of the output(s) produced by this expression.
- backward(weights, direction='==')[source]#
Perform backward-mode bound propagation through this expression.
Given an accumulated weight
weights(usually aEinsumOp) from the output back to this node, backward propagation derives child weights and a bias:\[\mathbf{w}^\top f(x_1, \ldots, x_n) \;\square\; b + \sum_i \mathbf{w}_i^\top x_i\]- Parameters:
- Returns:
A tuple
(bias, child_weights)wherebiasis atorch.Tensoror0, andchild_weightsis a list ofEinsumOp(one per child). ReturnsNoneif this expression cannot contribute to the bound in the given direction.- Return type:
tuple[torch.Tensor, list[LinearOp]] | None