1 core.expressions.Expression

core.expressions.Expression()

Abstract base class for all symbolic expressions.

Expressions form a tree structure that can be evaluated given variable values. All arithmetic operators are overloaded to build expression trees automatically.

1.1 Attributes

Name Type Description
_hash Cached hash value for the expression.
_degree Cached polynomial degree (None if not computed, -1 if non-polynomial).

1.2 Methods

Name Description
constraint_eq Create an == constraint: self == other.
eq Create an == constraint: self == other.
evaluate Evaluate the expression given variable values.
get_variables Return all variables this expression depends on.
is_linear Check if this expression is linear (degree <= 1).

1.2.1 constraint_eq

core.expressions.Expression.constraint_eq(other)

Create an == constraint: self == other.

Note: We use constraint_eq() instead of eq because eq is used for object identity comparison which is needed for sets/dicts.

.. deprecated:: Use :meth:eq instead. This method is kept for backwards compatibility.

1.2.2 eq

core.expressions.Expression.eq(other)

Create an == constraint: self == other.

Note: We use eq() instead of eq because eq is used for object identity comparison which is needed for sets/dicts.

1.2.3 evaluate

core.expressions.Expression.evaluate(values)

Evaluate the expression given variable values.

1.2.3.1 Parameters

Name Type Description Default
values Mapping[str, ArrayLike | float] Dictionary mapping variable names to their values. required

1.2.3.2 Returns

Name Type Description
NDArray[np.floating] | float The numerical result of evaluating the expression.

1.2.4 get_variables

core.expressions.Expression.get_variables()

Return all variables this expression depends on.

1.2.5 is_linear

core.expressions.Expression.is_linear()

Check if this expression is linear (degree <= 1).

1.2.5.1 Returns

Name Type Description
bool True if the expression is constant or linear in variables.

Uses cached degree computation for performance.