Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 66 variants Var(String), Literal(Float), Rational(Rational), Pi, E, Pow2(Box<Expr>), Fabs(Box<Expr>), Neg(Box<Expr>), Sqrt(Box<Expr>), Cbrt(Box<Expr>), Exp(Box<Expr>), Exp2(Box<Expr>), Expm1(Box<Expr>), Log(Box<Expr>), Log2(Box<Expr>), Log10(Box<Expr>), Log1p(Box<Expr>), Logb(Box<Expr>), Sin(Box<Expr>), Cos(Box<Expr>), Tan(Box<Expr>), Asin(Box<Expr>), Acos(Box<Expr>), Atan(Box<Expr>), Sinh(Box<Expr>), Cosh(Box<Expr>), Tanh(Box<Expr>), Asinh(Box<Expr>), Acosh(Box<Expr>), Atanh(Box<Expr>), Erf(Box<Expr>), Erfc(Box<Expr>), Rint(Box<Expr>), Round(Box<Expr>), Ceil(Box<Expr>), Floor(Box<Expr>), Trunc(Box<Expr>), Not(Box<Expr>), Error(Box<Expr>), Assert(Box<Expr>), Cosu(u64, Box<Expr>), Sinu(u64, Box<Expr>), Tanu(u64, Box<Expr>), Pow(Box<Expr>, Box<Expr>), Fdim(Box<Expr>, Box<Expr>), Hypot(Box<Expr>, Box<Expr>), Add(Box<Expr>, Box<Expr>), Sub(Box<Expr>, Box<Expr>), Mul(Box<Expr>, Box<Expr>), Div(Box<Expr>, Box<Expr>), And(Box<Expr>, Box<Expr>), Or(Box<Expr>, Box<Expr>), Eq(Box<Expr>, Box<Expr>), Ne(Box<Expr>, Box<Expr>), Lt(Box<Expr>, Box<Expr>), Le(Box<Expr>, Box<Expr>), Gt(Box<Expr>, Box<Expr>), Ge(Box<Expr>, Box<Expr>), Fmin(Box<Expr>, Box<Expr>), Fmax(Box<Expr>, Box<Expr>), Copysign(Box<Expr>, Box<Expr>), Atan2(Box<Expr>, Box<Expr>), Fmod(Box<Expr>, Box<Expr>), Remainder(Box<Expr>, Box<Expr>), Fma(Box<Expr>, Box<Expr>, Box<Expr>), If(Box<Expr>, Box<Expr>, Box<Expr>),
}
Expand description

High-level expression AST for real-number computation.

Rival supports a simple language of real-number expressions containing variables, rational literals, common mathematical functions, and common mathematical constants:

Expr = variable
     | literal
     | (constant)
     | (operator Expr ...)

constant = Pi | E

operator = Add | Sub | Mul | Div | Fma | Fabs
         | Sqrt | Cbrt | Hypot
         | Exp | Exp2 | Expm1 | Pow
         | Log | Log2 | Log10 | Log1p | Logb
         | Sin | Cos | Tan | Asin | Acos | Atan | Atan2
         | Sinh | Cosh | Tanh | Asinh | Acosh | Atanh
         | Erf | Erfc | Lgamma | Tgamma
         | Fmod | Remainder | Rint | Round | Ceil | Floor | Trunc
         | Fmin | Fmax | Copysign | Fdim
         | Lt | Le | Gt | Ge | Eq | Ne
         | If | And | Or | Not
         | Assert | Error

Expressions largely follow the semantics of math.h, not Racket, when it comes to, for example, the order of arguments to atan2 or the naming of the exponential function.

Some inputs are invalid to some operations, such as division by zero, square roots of negative numbers, and similar. For Pow, Rival considers pow(0, x) valid for non-negative x, and pow(x, y) invalid for negative x and non-integer y. In general these conventions again follow those in math.h. Colloquially we say that these expressions “throw” on invalid points, though note that internally Rival uses error intervals to soundly track whether an input is invalid or not.

Expressions that mix boolean and real-number operations must type-check in the expected way, and variables must have consistent types. Rival does not perform typechecking; that is a user responsibility, and Rival may return undefined results if passed ill-typed formulas.

The Assert and Error variants need additional explanation; these control the definition of a “valid” input to an expression. The Assert function takes in a boolean input and returns a boolean output. If the input is false, Assert throws. Its output is always true. Error has the opposite behavior. This function never throws, and instead returns true if its argument throws and false if it doesn’t. Assert and Error can be used to model constructs like preconditions, tests, try/catch blocks, and others.

Variants§

§

Var(String)

Variable reference by name.

§

Literal(Float)

Floating-point literal value.

§

Rational(Rational)

Exact rational value.

§

Pi

§

E

§

Pow2(Box<Expr>)

§

Fabs(Box<Expr>)

§

Neg(Box<Expr>)

§

Sqrt(Box<Expr>)

§

Cbrt(Box<Expr>)

§

Exp(Box<Expr>)

§

Exp2(Box<Expr>)

§

Expm1(Box<Expr>)

§

Log(Box<Expr>)

§

Log2(Box<Expr>)

§

Log10(Box<Expr>)

§

Log1p(Box<Expr>)

§

Logb(Box<Expr>)

§

Sin(Box<Expr>)

§

Cos(Box<Expr>)

§

Tan(Box<Expr>)

§

Asin(Box<Expr>)

§

Acos(Box<Expr>)

§

Atan(Box<Expr>)

§

Sinh(Box<Expr>)

§

Cosh(Box<Expr>)

§

Tanh(Box<Expr>)

§

Asinh(Box<Expr>)

§

Acosh(Box<Expr>)

§

Atanh(Box<Expr>)

§

Erf(Box<Expr>)

§

Erfc(Box<Expr>)

§

Rint(Box<Expr>)

§

Round(Box<Expr>)

§

Ceil(Box<Expr>)

§

Floor(Box<Expr>)

§

Trunc(Box<Expr>)

§

Not(Box<Expr>)

§

Error(Box<Expr>)

§

Assert(Box<Expr>)

§

Cosu(u64, Box<Expr>)

§

Sinu(u64, Box<Expr>)

§

Tanu(u64, Box<Expr>)

§

Pow(Box<Expr>, Box<Expr>)

§

Fdim(Box<Expr>, Box<Expr>)

§

Hypot(Box<Expr>, Box<Expr>)

§

Add(Box<Expr>, Box<Expr>)

§

Sub(Box<Expr>, Box<Expr>)

§

Mul(Box<Expr>, Box<Expr>)

§

Div(Box<Expr>, Box<Expr>)

§

And(Box<Expr>, Box<Expr>)

§

Or(Box<Expr>, Box<Expr>)

§

Eq(Box<Expr>, Box<Expr>)

§

Ne(Box<Expr>, Box<Expr>)

§

Lt(Box<Expr>, Box<Expr>)

§

Le(Box<Expr>, Box<Expr>)

§

Gt(Box<Expr>, Box<Expr>)

§

Ge(Box<Expr>, Box<Expr>)

§

Fmin(Box<Expr>, Box<Expr>)

§

Fmax(Box<Expr>, Box<Expr>)

§

Copysign(Box<Expr>, Box<Expr>)

§

Atan2(Box<Expr>, Box<Expr>)

§

Fmod(Box<Expr>, Box<Expr>)

§

Remainder(Box<Expr>, Box<Expr>)

§

Fma(Box<Expr>, Box<Expr>, Box<Expr>)

§

If(Box<Expr>, Box<Expr>, Box<Expr>)

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.