pub struct Expr {
pub(crate) atom: Rc<Atom>,
}
Fields§
§atom: Rc<Atom>
Implementations§
source§impl Expr
impl Expr
pub fn add(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn sub(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn mul(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn div(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn add_raw(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn mul_raw(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn div_raw(lhs: impl Borrow<Expr>, rhs: impl Borrow<Expr>) -> Expr
pub fn pow_raw(base: impl Borrow<Expr>, exponent: impl Borrow<Expr>) -> Expr
pub fn pow(base: impl Borrow<Expr>, exponent: impl Borrow<Expr>) -> Expr
pub fn derivative<T: Borrow<Self>>(&self, x: T) -> Self
source§impl Expr
impl Expr
pub fn simplify(&self) -> Vec<Self>
pub fn expand(&self) -> Self
pub fn expand_main_op(&self) -> Self
sourcepub fn expand_exponential(&self) -> Self
pub fn expand_exponential(&self) -> Self
exponential expansion
exp(u+v) = exp(u) * exp(v) exp(w*u) = exp(u)^w
pub fn simplify_trig(&self) -> Self
pub fn substitute_trig(&self) -> Self
pub fn expand_trig(&self) -> Self
pub fn contract_trig(&self) -> Self
pub fn expand_ln(&self) -> Self
pub fn distribute(&self) -> Self
pub fn rationalize(&self) -> Expr
sourcefn rationalize_add(lhs: &Self, rhs: &Self) -> Expr
fn rationalize_add(lhs: &Self, rhs: &Self) -> Expr
a/b + c/d -> (ad + cb) / (bd)
sourcepub fn factorize_common_terms(lhs: &Expr, rhs: &Self) -> (Expr, (Expr, Expr))
pub fn factorize_common_terms(lhs: &Expr, rhs: &Self) -> (Expr, (Expr, Expr))
divide lhs and rhs by their common factor and return them in the form (fac, (lhs/fac, rhs/fac)
pub fn common_factors(lhs: &Self, rhs: &Self) -> Expr
pub fn factor_out(&self) -> Expr
pub fn separate_factors(&self, x: &Self) -> (Expr, Expr)
pub fn cancel(&self) -> Expr
pub fn substitude(&self, from: &Expr, to: &Expr) -> Self
pub fn seq_substitude<'a, T>(&self, subs: T) -> Self
pub fn concurr_substitude<'a, T>(&self, subs: T) -> Self
pub fn sort_args(&self) -> Self
pub fn try_for_each_compl_sub_expr<F>(&mut self, func: F)
pub fn for_each_compl_sub_expr<F>(&mut self, func: F)
source§impl Expr
impl Expr
const _UNDEF: LocalKey<Expr> = _
const _MINUS_TWO: LocalKey<Expr> = _
const _MINUS_ONE: LocalKey<Expr> = _
const _ZERO: LocalKey<Expr> = _
const _ONE: LocalKey<Expr> = _
const _TWO: LocalKey<Expr> = _
const _PI: LocalKey<Expr> = _
const _E: LocalKey<Expr> = _
fn from_atom(a: Atom) -> Expr
pub fn undef() -> Expr
pub fn min_two() -> Expr
pub fn min_one() -> Expr
pub fn zero() -> Expr
pub fn one() -> Expr
pub fn two() -> Expr
pub fn pi() -> Expr
pub fn e() -> Expr
pub fn var(str: &str) -> Expr
pub fn atom(&self) -> &Atom
pub fn atom_mut(&mut self) -> &mut Atom
pub fn rational<T: Into<Rational>>(r: T) -> Expr
pub fn cos(e: impl Borrow<Expr>) -> Expr
pub fn arc_cos(e: impl Borrow<Expr>) -> Expr
pub fn sin(e: impl Borrow<Expr>) -> Expr
pub fn arc_sin(e: impl Borrow<Expr>) -> Expr
pub fn tan(e: impl Borrow<Expr>) -> Expr
pub fn arc_tan(e: impl Borrow<Expr>) -> Expr
pub fn sec(e: impl Borrow<Expr>) -> Expr
pub fn arc_sec(e: impl Borrow<Expr>) -> Expr
pub fn cot(e: impl Borrow<Expr>) -> Expr
pub fn arc_cot(e: impl Borrow<Expr>) -> Expr
pub fn csc(e: impl Borrow<Expr>) -> Expr
pub fn arc_csc(e: impl Borrow<Expr>) -> Expr
pub fn exp(e: impl Borrow<Expr>) -> Expr
pub fn log(base: impl Into<Real>, e: impl Borrow<Expr>) -> Expr
pub fn ln(e: impl Borrow<Expr>) -> Expr
pub fn log10(e: impl Borrow<Expr>) -> Expr
pub fn sqrt(v: impl Borrow<Expr>) -> Expr
pub fn as_monomial_view<'a>(&'a self, vars: &'a VarSet) -> MonomialView<'a>
pub fn as_polynomial_view<'a>(&'a self, vars: &'a VarSet) -> PolynomialView<'a>
pub fn numerator(&self) -> Expr
pub fn denominator(&self) -> Expr
pub fn base(&self) -> Expr
pub fn exponent(&self) -> Expr
pub fn is_exponential(&self) -> bool
pub fn is_trig(&self) -> bool
pub fn try_as_div(&self) -> Option<(Expr, Expr)>
pub fn rational_coeff(&self) -> Option<Rational>
pub fn non_rational_term(&self) -> Option<Expr>
pub fn variables(&self) -> HashSet<Expr, FxBuildHasher>
fn variables_impl(&self, vars: &mut HashSet<Expr, FxBuildHasher>)
pub fn free_of(&self, expr: &Expr) -> bool
pub fn free_of_set<'a, I: IntoIterator<Item = &'a Self>>( &'a self, exprs: I, ) -> bool
pub fn iter_compl_sub_exprs(&self) -> ExprIterator<'_> ⓘ
pub fn flatten(&self) -> &Expr
fn cmp_slices(lhs: &[Self], rhs: &[Self]) -> Ordering
fn cost(&self) -> usize
Methods from Deref<Target = Atom>§
sourcepub fn is_undef(&self) -> bool
pub fn is_undef(&self) -> bool
Returns true
if this value is of type Undef
. Returns false
otherwise
sourcepub fn is_rational(&self) -> bool
pub fn is_rational(&self) -> bool
Returns true
if this value is of type Rational
. Returns false
otherwise
sourcepub fn is_irrational(&self) -> bool
pub fn is_irrational(&self) -> bool
Returns true
if this value is of type Irrational
. Returns false
otherwise
sourcepub fn is_var(&self) -> bool
pub fn is_var(&self) -> bool
Returns true
if this value is of type Var
. Returns false
otherwise
sourcepub fn is_sum(&self) -> bool
pub fn is_sum(&self) -> bool
Returns true
if this value is of type Sum
. Returns false
otherwise
sourcepub fn is_prod(&self) -> bool
pub fn is_prod(&self) -> bool
Returns true
if this value is of type Prod
. Returns false
otherwise
sourcepub fn is_pow(&self) -> bool
pub fn is_pow(&self) -> bool
Returns true
if this value is of type Pow
. Returns false
otherwise
sourcepub fn is_func(&self) -> bool
pub fn is_func(&self) -> bool
Returns true
if this value is of type Func
. Returns false
otherwise
sourcepub fn unwrap_undef_ref(&self)
pub fn unwrap_undef_ref(&self)
Unwraps this reference to the Atom::Undef
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_rational_ref(&self) -> &Rational
pub fn unwrap_rational_ref(&self) -> &Rational
Unwraps this reference to the Atom::Rational
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_irrational_ref(&self) -> &Irrational
pub fn unwrap_irrational_ref(&self) -> &Irrational
Unwraps this reference to the Atom::Irrational
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_var_ref(&self) -> &Var
pub fn unwrap_var_ref(&self) -> &Var
Unwraps this reference to the Atom::Var
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_sum_ref(&self) -> &Sum
pub fn unwrap_sum_ref(&self) -> &Sum
Unwraps this reference to the Atom::Sum
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_prod_ref(&self) -> &Prod
pub fn unwrap_prod_ref(&self) -> &Prod
Unwraps this reference to the Atom::Prod
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_pow_ref(&self) -> &Pow
pub fn unwrap_pow_ref(&self) -> &Pow
Unwraps this reference to the Atom::Pow
variant.
Panics if this value is of any other type.
sourcepub fn unwrap_func_ref(&self) -> &Func
pub fn unwrap_func_ref(&self) -> &Func
Unwraps this reference to the Atom::Func
variant.
Panics if this value is of any other type.
sourcepub fn try_unwrap_undef_ref(&self) -> Result<(), TryUnwrapError<&Self>>
pub fn try_unwrap_undef_ref(&self) -> Result<(), TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Undef
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_rational_ref(
&self,
) -> Result<&Rational, TryUnwrapError<&Self>>
pub fn try_unwrap_rational_ref( &self, ) -> Result<&Rational, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Rational
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_irrational_ref(
&self,
) -> Result<&Irrational, TryUnwrapError<&Self>>
pub fn try_unwrap_irrational_ref( &self, ) -> Result<&Irrational, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Irrational
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_var_ref(&self) -> Result<&Var, TryUnwrapError<&Self>>
pub fn try_unwrap_var_ref(&self) -> Result<&Var, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Var
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_sum_ref(&self) -> Result<&Sum, TryUnwrapError<&Self>>
pub fn try_unwrap_sum_ref(&self) -> Result<&Sum, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Sum
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_prod_ref(&self) -> Result<&Prod, TryUnwrapError<&Self>>
pub fn try_unwrap_prod_ref(&self) -> Result<&Prod, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Prod
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_pow_ref(&self) -> Result<&Pow, TryUnwrapError<&Self>>
pub fn try_unwrap_pow_ref(&self) -> Result<&Pow, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Pow
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
sourcepub fn try_unwrap_func_ref(&self) -> Result<&Func, TryUnwrapError<&Self>>
pub fn try_unwrap_func_ref(&self) -> Result<&Func, TryUnwrapError<&Self>>
Attempts to unwrap this reference to the Atom::Func
variant.
Returns a [TryUnwrapError] with the original value if this value is of any other type.
pub const UNDEF: Atom = Atom::Undef
pub const MINUS_TWO: Atom = _
pub const MINUS_ONE: Atom = _
pub const ZERO: Atom = _
pub const ONE: Atom = _
pub const TWO: Atom = _
pub const PI: Atom = _
pub const E: Atom = _
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
pub fn is_min_one(&self) -> bool
pub fn is_pi(&self) -> bool
pub fn is_e(&self) -> bool
pub fn is_neg(&self) -> bool
pub fn is_pos(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_even(&self) -> bool
pub fn is_odd(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_real(&self) -> bool
pub fn is_irreducible(&self) -> bool
pub fn is_rational_and(&self, cond: impl Fn(&Rational) -> bool) -> bool
pub fn is_const(&self) -> bool
pub fn is_sin(&self) -> bool
pub fn is_cos(&self) -> bool
pub fn try_unwrap_int(&self) -> Option<i128>
pub fn unwrap_int(&self) -> i128
pub fn try_as_real(&self) -> Option<Real>
pub fn for_each_arg<'a>(&'a self, func: impl FnMut(&'a Expr))
pub fn fmt_ast(&self) -> FmtAtom
Trait Implementations§
source§impl<T: Borrow<Expr>> AddAssign<T> for Expr
impl<T: Borrow<Expr>> AddAssign<T> for Expr
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresource§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>,
source§impl<T: Borrow<Expr>> DivAssign<T> for Expr
impl<T: Borrow<Expr>> DivAssign<T> for Expr
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresource§impl<T: Borrow<Expr>> MulAssign<T> for Expr
impl<T: Borrow<Expr>> MulAssign<T> for Expr
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresource§impl Ord for Expr
impl Ord for Expr
source§impl PartialOrd for Expr
impl PartialOrd for Expr
source§impl<T: Borrow<Expr>> SubAssign<T> for Expr
impl<T: Borrow<Expr>> SubAssign<T> for Expr
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moresource§impl SymbolicExpr for Expr
impl SymbolicExpr for Expr
source§fn reduce(&self) -> Self
fn reduce(&self) -> Self
fn args(&self) -> &[Expr]
fn args_mut(&mut self) -> &mut [Expr]
fn is_atom(&self) -> bool
fn n_args(&self) -> usize
fn iter_args(&self) -> impl Iterator<Item = &Expr>
fn map_args(self, map_fn: impl Fn(&mut Expr)) -> Self
impl Eq 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 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)