pub enum Expr {
Show 15 variants
Const(f64),
Var(VarId),
Add(Box<Expr>, Box<Expr>),
Sub(Box<Expr>, Box<Expr>),
Mul(Box<Expr>, Box<Expr>),
Div(Box<Expr>, Box<Expr>),
Neg(Box<Expr>),
Sin(Box<Expr>),
Cos(Box<Expr>),
Sqrt(Box<Expr>),
Abs(Box<Expr>),
Atan2(Box<Expr>, Box<Expr>),
Hypot(Box<Expr>, Box<Expr>),
Min(Box<Expr>, Box<Expr>),
Max(Box<Expr>, Box<Expr>),
}Expand description
A scalar expression.
Variants§
Const(f64)
Constant.
Var(VarId)
Variable.
Add(Box<Expr>, Box<Expr>)
a + b.
Sub(Box<Expr>, Box<Expr>)
a - b.
Mul(Box<Expr>, Box<Expr>)
a * b.
Div(Box<Expr>, Box<Expr>)
a / b.
Neg(Box<Expr>)
-a.
Sin(Box<Expr>)
sin a.
Cos(Box<Expr>)
cos a.
Sqrt(Box<Expr>)
sqrt a (domain a ≥ 0; negative inputs evaluate to NaN).
Abs(Box<Expr>)
|a|.
Atan2(Box<Expr>, Box<Expr>)
atan2(y, x).
Hypot(Box<Expr>, Box<Expr>)
hypot(x, y).
Min(Box<Expr>, Box<Expr>)
min(a, b).
Max(Box<Expr>, Box<Expr>)
max(a, b).
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn eval(&self, x: &[f64]) -> f64
pub fn eval(&self, x: &[f64]) -> f64
Evaluate with variable values x (missing variables evaluate to NaN).
Sourcepub fn eval_dual(&self, x: &[f64]) -> Dual
pub fn eval_dual(&self, x: &[f64]) -> Dual
Evaluate value and exact gradient.
Non-smooth points use a deterministic one-sided derivative: |0|' = 0,
sqrt'(0) = 0, hypot'(0, 0) = (1, 0), ties of min/max take the first argument.
Sourcepub fn linear_form(
&self,
x: &[f64],
fixed: &dyn Fn(VarId) -> bool,
) -> Option<LinearForm>
pub fn linear_form( &self, x: &[f64], fixed: &dyn Fn(VarId) -> bool, ) -> Option<LinearForm>
Affine form Σ cᵢ·xᵢ + k if the expression is exactly linear in the variables
whose fixed[i] is false (fixed variables are folded into the constant).
Sourcepub fn substitute(&self, f: &dyn Fn(VarId) -> Self) -> Self
pub fn substitute(&self, f: &dyn Fn(VarId) -> Self) -> Self
Replace every variable by the expression returned by f (constant folding is
applied by the simplifying constructors).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Expr
impl<'de> Deserialize<'de> for Expr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnsafeUnpin for Expr
impl UnwindSafe for Expr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.