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 | ErrorExpressions 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§
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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