pub struct Expression { /* private fields */ }Expand description
A symbolic mathematical expression.
This type wraps egg’s RecExpr and provides a user-friendly API
for symbolic computation.
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn float(value: f64) -> SymEngineResult<Self>
pub fn float(value: f64) -> SymEngineResult<Self>
Sourcepub fn float_unchecked(value: f64) -> Self
pub fn float_unchecked(value: f64) -> Self
Create a floating-point constant, using 0 for NaN
Sourcepub fn from_complex64(c: Complex64) -> Self
pub fn from_complex64(c: Complex64) -> Self
Create from a complex number
If imaginary part is negligible, returns just the real part.
Sourcepub fn parse(input: &str) -> SymEngineResult<Self>
pub fn parse(input: &str) -> SymEngineResult<Self>
Sourcepub fn new(input: impl AsRef<str>) -> Self
pub fn new(input: impl AsRef<str>) -> Self
Create an expression from a string (alias for parse)
Sourcepub fn is_symbol(&self) -> bool
pub fn is_symbol(&self) -> bool
Check if this expression is a symbol (variable or number literal)
Sourcepub fn as_mul(&self) -> Option<Vec<Self>>
pub fn as_mul(&self) -> Option<Vec<Self>>
Get the operands if this is a multiplication operation
Sourcepub fn as_pow(&self) -> Option<(Self, Self)>
pub fn as_pow(&self) -> Option<(Self, Self)>
Get the base and exponent if this is a power operation
Sourcepub fn gradient(&self, vars: &[Self]) -> Vec<Self>
pub fn gradient(&self, vars: &[Self]) -> Vec<Self>
Compute the gradient with respect to multiple variables
Sourcepub fn hessian(&self, vars: &[Self]) -> Vec<Vec<Self>>
pub fn hessian(&self, vars: &[Self]) -> Vec<Vec<Self>>
Compute the Hessian matrix (second derivatives)
Sourcepub fn eval(&self, values: &HashMap<String, f64>) -> SymEngineResult<f64>
pub fn eval(&self, values: &HashMap<String, f64>) -> SymEngineResult<f64>
Evaluate the expression with given variable values
§Errors
Returns an error if a variable is not found in the values map
Sourcepub fn eval_complex(
&self,
values: &HashMap<String, f64>,
) -> SymEngineResult<Complex64>
pub fn eval_complex( &self, values: &HashMap<String, f64>, ) -> SymEngineResult<Complex64>
Evaluate the expression to a complex number.
This can handle expressions containing the imaginary unit I,
which is essential for quantum computing applications.
§Arguments
values- Map of variable names to real values
§Returns
The complex result of the evaluation.
§Errors
Returns an error if a variable is not found in the values map
Sourcepub fn substitute(&self, var: &Self, value: &Self) -> Self
pub fn substitute(&self, var: &Self, value: &Self) -> Self
Substitute a variable with an expression
Sourcepub fn substitute_many(&self, values: &HashMap<Self, Self>) -> Self
pub fn substitute_many(&self, values: &HashMap<Self, Self>) -> Self
Substitute multiple variables
Trait Implementations§
Source§impl Add for Expression
impl Add for Expression
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Display for Expression
impl Display for Expression
Source§impl Div for Expression
impl Div for Expression
Source§impl From<f64> for Expression
impl From<f64> for Expression
Source§impl From<i32> for Expression
impl From<i32> for Expression
Source§impl From<i64> for Expression
impl From<i64> for Expression
Source§impl Hash for Expression
impl Hash for Expression
Source§impl Mul for Expression
impl Mul for Expression
Source§impl Neg for Expression
impl Neg for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl Sub for Expression
impl Sub for Expression
impl Eq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more