Eq package:numeric-prelude
We need a Haskell 98 type class which provides equality test for
Vector type constructors.
The
Eq class defines equality (
==) and inequality
(
/=). All the basic datatypes exported by the
Prelude
are instances of
Eq, and
Eq may be derived for any
datatype whose constituents are also instances of
Eq.
The Haskell Report defines no laws for
Eq. However,
==
is customarily expected to implement an equivalence relationship where
two values comparing equal are indistinguishable by "public"
functions, with a "public" function being one not allowing to see
implementation details. For example, for a type representing
non-normalised natural numbers modulo 100, a "public" function doesn't
make the difference between 1 and 201. It is expected to have the
following properties:
- Reflexivity x == x = True
- Symmetry x == y = y == x
- Transitivity if x == y && y == z =
True, then x == z = True
- Substitutivity if x == y = True and
f is a "public" function whose return type is an instance of
Eq, then f x == f y = True
- Negation x /= y = not (x ==
y)
Minimal complete definition: either
== or
/=.
Two polynomials may be stored differently. This function checks
whether two values of type LaurentPolynomial actually
represent the same polynomial.
Lazy evaluation allows for the solution of differential equations in
terms of power series. Whenever you can express the highest derivative
of the solution as explicit expression of the lower derivatives where
each coefficient of the solution series depends only on lower
coefficients, the recursive algorithm will work.
Example for a linear equation: Setup a differential equation for
y with
y t = (exp (-t)) * (sin t)
y' t = -(exp (-t)) * (sin t) + (exp (-t)) * (cos t)
y'' t = -2 * (exp (-t)) * (cos t)
Thus the differential equation
y'' = -2 * (y' + y)
holds.
The following function generates a power series for
exp (-t) * sin
t by solving the differential equation.
We are not restricted to linear equations! Let the solution be y with
y t = (1-t)^-1 y' t = (1-t)^-2 y'' t = 2*(1-t)^-3 then it holds y'' =
2 * y' * y
Some common quantity classes.
The value of seq a b is bottom if a is bottom, and
otherwise equal to b. In other words, it evaluates the first
argument a to weak head normal form (WHNF). seq is
usually introduced to improve performance by avoiding unneeded
laziness.
A note on evaluation order: the expression seq a b does
not guarantee that a will be evaluated before
b. The only guarantee given by seq is that the both
a and b will be evaluated before seq
returns a value. In particular, this means that b may be
evaluated before a. If you need to guarantee a specific order
of evaluation, you must use the function pseq from the
"parallel" package.
Evaluate each monadic action in the structure from left to right, and
collect the results. For a version that ignores the results see
sequence_.
Evaluate each monadic action in the structure from left to right, and
ignore the results. For a version that doesn't ignore the results see
sequence.
As of base 4.8.0.0,
sequence_ is just
sequenceA_,
specialized to
Monad.