1 core.vectors.VectorExpression
core.vectors.VectorExpression(expressions)A vector of expressions (result of vector arithmetic).
VectorExpression represents element-wise operations on vectors, such as x + y or 2 * x.
1.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| expressions | Sequence[Expression] | List of scalar expressions, one per element. | required |
1.2 Example
x = VectorVariable(“x”, 3) y = VectorVariable(“y”, 3) z = x + y # VectorExpression with 3 elements z[0].evaluate({“x[0]”: 1, “y[0]”: 2}) 3.0
1.3 Methods
| Name | Description |
|---|---|
| between | Create element-wise range constraints: lb <= self <= ub. |
| dot | Compute dot product with another vector. |
| eq | Element-wise == constraint. |
| evaluate | Evaluate all expressions and return as list. |
| get_variables | Return all variables these expressions depend on. |
| sum | Sum of all elements. |
1.3.1 between
core.vectors.VectorExpression.between(lb, ub)Create element-wise range constraints: lb <= self <= ub.
1.3.1.1 Returns
| Name | Type | Description |
|---|---|---|
| list[Constraint] | List of constraints covering both bounds. |
1.3.2 dot
core.vectors.VectorExpression.dot(other)Compute dot product with another vector.
1.3.2.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| other | VectorExpression | VectorVariable | Vector to compute dot product with. | required |
1.3.2.2 Returns
| Name | Type | Description |
|---|---|---|
| DotProduct | DotProduct expression (scalar). |
1.3.2.3 Example
x = VectorVariable(“x”, 3) y = VectorVariable(“y”, 3) d = x.dot(y) d.evaluate({“x[0]”: 1, “x[1]”: 2, “x[2]”: 3, “y[0]”: 4, “y[1]”: 5, “y[2]”: 6}) 32.0
1.3.3 eq
core.vectors.VectorExpression.eq(other)Element-wise == constraint.
1.3.3.1 Example
x = VectorVariable(“x”, 3) y = VectorVariable(“y”, 3) constraints = x.eq(y) # 3 constraints: x[i] == y[i]
1.3.4 evaluate
core.vectors.VectorExpression.evaluate(values)Evaluate all expressions and return as list.
1.3.5 get_variables
core.vectors.VectorExpression.get_variables()Return all variables these expressions depend on.
1.3.6 sum
core.vectors.VectorExpression.sum()Sum of all elements.
1.3.6.1 Returns
| Name | Type | Description |
|---|---|---|
| VectorExpressionSum | VectorExpressionSum expression (scalar). |
1.3.6.2 Example
x = VectorVariable(“x”, 3) y = VectorVariable(“y”, 3) s = (x - y).sum() # VectorExpressionSum, not nested BinaryOps