Skip to main content

split_linear

Function split_linear 

Source
pub fn split_linear(
    arena: &ExprArena,
    id: ExprId,
) -> (LinearTerms, Vec<SignedExpr>)
Expand description

Split an expression into its linear part and a nonlinear residual. The returned (LinearTerms, Vec<SignedExpr>) satisfies

value(id) == sum_i coef_i * var_i + constant + sum_j (-1)^neg_j value(id_j)

where the residual is empty when the whole expression is linear and otherwise lists the remaining nonlinear summands (each a pre-existing arena node, optionally negated). LinearTerms may have empty coeffs and constant == 0.0 when the whole expression is purely nonlinear.