A mixin for the SeparationBound that implements the BMFSS bound.
A mixin that will move all divisions up to the top of the expression tree,
ensuring there is, at most, one division in a Real
.
A type class that indicates that the type A
has a structure that can be
modelled by an Expr[A]
.
A type class that indicates that the type A
has a structure that can be
modelled by an Expr[A]
. The type class let's us switch between the 2 types,
so that we can both traverse the type A
as an Expr
and also construct an
A
from an Expr[A]
.
If ce
is an instance of Coexpr[A]
, then ce.coexpr(ce.expr(a)) == a.
This folds all ring ops (+, -, *) on constants to constants.
This folds all ring ops (+, -, *) on constants to constants. This only works
on IntLit
s for now, as BigInt
s may be slow.
TODO: It may be worth it to fold BigIntLit
s for add/subtract, since the
space requirement would approximately half.
An Expr
describes a simple structure for algebraic expressions.
An Expr
describes a simple structure for algebraic expressions. Generally,
a type Expr[A]
indicates that A
has some structure that mirrors Expr
.
To get at this symmetry, you must use the type class Coexpr[A]
. This let's
us switch between types A
and Expr[A]
, giving us the ability to extract
structure from a type A
, traverse, and construct the expression tree of
A
, without having to deal with A
as a concrete type.
Using Coexpr
let's us provide further general constructors and pattern
matchers. These are defined as the same name as the case class, but without
the Expr
appended. So, we can, for example, pattern match on an instance
a
of the generic type A
. Suppose we wanted to map patterns like ab + ac
to a(b + c), then we could do the following:
a match { case Add(Mul(a, b), Mul(c, d)) if a == c => Mul(a, Add(b, d)) case _ => a }
A mix-in for RealLike
that adds an internal floating pointer filter.
A MaybeDouble
will hold a Double
approximation so long as the Double
's
sign can be computed exactly.
A MaybeDouble
will hold a Double
approximation so long as the Double
's
sign can be computed exactly. It is not a general number type, but is meant
to be used in tandem with a more accurate, but slow (computationally),
number type. When performing comparisons then, this can be checked first to
save on potentially slow computation.
For this type, if a method returns an Option
al value, then that indicates
that if None
is returned, the answer cannot be computed exactly, but if
Some(x)
is returned, then that is guaranteed to be correct. For example,
toLong
, toFloat
, sign
, isWhole
, etc. return these types of optional,
only-if-correct, type values.
Most likely you would not use this directly, but just wrap your number type
in a FPFilter
which maintains a MaybeDouble
and handles all the lazy
computation of the more accurate number type for you.
A mixin for a Real
that let's us transform the tree as its being built.
A mixin for a Real
that let's us transform the tree as its being built.
In your implementation of transform
, you'll likely want to play nice and
call super.transform(x)
first.
A SeparationBound
provides a way to bound a real number s.t.
A SeparationBound
provides a way to bound a real number s.t. if the number
is not 0, then its absolute value is >= 2^lowerBound
.
Provides absolute and relative approximations to RealLike
types that have
mixed in a SeparationBound
.
Provides absolute and relative approximations to RealLike
types that have
mixed in a SeparationBound
. The absolute approximations take
BigDecimal
for their context, returning a BigDecimal
that is equal to
the RealLike
+/- the context (error). The relative approximations take a
MathContext
specifying how many digits to determine the value of the
RealLike
to.
Note that a relative approximation of 0 is always 0.
Here, we mostly work with java.math.BigDecimal
as its operations let you
provide a MathContext
directly. However, I'm pretty sure that
a.add(b, mc)
is equivalent to (a + b).round(mc)
.
A mixin that will move all divisions up to the top of the expression tree, ensuring there is, at most, one division in a
Real
. This is needed for the BFMSS bound.