GiNaCRA
0.6.4
|
A class for an open interval providing interval arithmetic operations. More...
#include <OpenInterval.h>
Public Member Functions | |
OpenInterval (const numeric &n) | |
Constructs an open interval ]n-1, n+1[. | |
OpenInterval (const numeric &l, const numeric &r) throw ( std::invalid_argument ) | |
Constructs an open interval ]l, r[. | |
OpenInterval (const OpenInterval &i) | |
Constructs an open interval from another. | |
~OpenInterval () | |
void | setLeft (const numeric &l) throw ( std::invalid_argument ) |
Set new left bound for the interval. | |
void | setRight (const numeric &r) throw ( std::invalid_argument ) |
Set new right bound for the interval. | |
const numeric | left () const |
Selects the left bound. | |
const numeric | right () const |
Selects the right bound. | |
const bool | isZero () const |
const bool | isNormalized () const |
const bool | contains (const numeric &n) const |
const bool | contains (const OpenInterval &o) const |
const bool | meets (const numeric &n) const |
const OpenInterval | intersection (const OpenInterval &o) const |
const numeric | midpoint () const |
const numeric | sample () const |
Chooses a numeric value out of the interval with the smallest numeric representation. | |
const numeric | sampleFast () const |
Returns sample() if the bounds are small enough for machine computations and midpoint otherwise. | |
const OpenInterval | abs () const |
Computes the absolute value of this interval, i.e. | |
const OpenInterval | add (const OpenInterval &o) const |
Adds two intervals and returns their sum. | |
const OpenInterval | minus () const |
Returns the negative value. | |
const OpenInterval | mul (const OpenInterval &o) const |
Multiplies two intervals and returns their product. | |
const OpenInterval | div (const OpenInterval &o) const throw ( std::invalid_argument ) |
Divides two intervals. | |
const OpenInterval | pow (unsigned e) const |
Computes the power to e of this interval. | |
const bool | isEqual (const OpenInterval &o) const |
const bool | isLess (const OpenInterval &o) const |
Compares only the left bounds of the involved intervals. | |
const bool | isGreater (const OpenInterval &o) const |
Compares only the right bounds of the involved intervals. | |
Static Public Member Functions | |
static OpenInterval | evaluate (const ex &p, evalintervalmap m) throw ( std::invalid_argument ) |
Protected Member Functions | |
bool | is_equal_same_type (const basic &) const |
void | do_print (const print_context &, unsigned level=0) const |
ex | evalf (int level=0) const |
unsigned | calchash () const |
Static Private Member Functions | |
static const numeric | findSample (cln::cl_I numeratorL, cln::cl_I denominatorL, cln::cl_I numeratorR, cln::cl_I denominatorR) |
Finds a number t between l:=numeratorL/denominatorL and r:=numeratorR/denominatorR so that t has a minimal number of digits. | |
static const numeric | findSample (long numeratorL, long denominatorL, long numeratorR, long denominatorR) |
Finds a number t between l:=numeratorL/denominatorL and r:=numeratorR/denominatorR so that t has a minimal number of digits. | |
Private Attributes | |
numeric | mLeft |
numeric | mRight |
A class for an open interval providing interval arithmetic operations.
All operations are performed in constant time.
Definition at line 55 of file OpenInterval.h.
GiNaCRA::OpenInterval::OpenInterval | ( | const numeric & | n | ) |
Constructs an open interval ]n-1, n+1[.
n | middle |
Definition at line 71 of file OpenInterval.cpp.
Referenced by abs(), add(), intersection(), minus(), mul(), and pow().
GiNaCRA::OpenInterval::OpenInterval | ( | const numeric & | l, |
const numeric & | r | ||
) | throw ( std::invalid_argument ) |
Constructs an open interval ]l, r[.
l | left bound of the open interval ]l, r[ |
r | right bound of the open interval ]l, r[ |
Definition at line 78 of file OpenInterval.cpp.
GiNaCRA::OpenInterval::OpenInterval | ( | const OpenInterval & | i | ) |
Constructs an open interval from another.
i | other open interval |
Definition at line 90 of file OpenInterval.cpp.
Definition at line 97 of file OpenInterval.cpp.
const OpenInterval GiNaCRA::OpenInterval::abs | ( | ) | const |
Computes the absolute value of this interval, i.e.
the maximum of the absolute values of its bounds.
Definition at line 270 of file OpenInterval.cpp.
References mLeft, mRight, OpenInterval(), and GiNaC::sgn().
const OpenInterval GiNaCRA::OpenInterval::add | ( | const OpenInterval & | o | ) | const |
Adds two intervals and returns their sum.
o |
Definition at line 283 of file OpenInterval.cpp.
References mLeft, mRight, and OpenInterval().
Referenced by GiNaCRA::operator+(), and GiNaCRA::operator-().
unsigned GiNaCRA::OpenInterval::calchash | ( | ) | const [protected] |
Definition at line 146 of file OpenInterval.cpp.
const bool GiNaCRA::OpenInterval::contains | ( | const numeric & | n | ) | const |
n |
Definition at line 179 of file OpenInterval.cpp.
Referenced by GiNaCRA::RationalUnivariatePolynomial::approximateRealRoot(), GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::RealAlgebraicNumberIR::operator=(), and GiNaCRA::RealAlgebraicNumberIR::refineAvoiding().
const bool GiNaCRA::OpenInterval::contains | ( | const OpenInterval & | o | ) | const |
o |
Definition at line 184 of file OpenInterval.cpp.
const OpenInterval GiNaCRA::OpenInterval::div | ( | const OpenInterval & | o | ) | const throw ( std::invalid_argument ) |
Divides two intervals.
o |
invalid_argument | in case the argument interval contains zero |
Definition at line 315 of file OpenInterval.cpp.
References mLeft.
void GiNaCRA::OpenInterval::do_print | ( | const print_context & | c, |
unsigned | level = 0 |
||
) | const [protected] |
Definition at line 154 of file OpenInterval.cpp.
ex GiNaCRA::OpenInterval::evalf | ( | int | level = 0 | ) | const [protected] |
Definition at line 159 of file OpenInterval.cpp.
OpenInterval GiNaCRA::OpenInterval::evaluate | ( | const ex & | p, |
evalintervalmap | m | ||
) | throw ( std::invalid_argument ) [static] |
p | |
m |
Use Horner's method to perform the interval-arithmetic operations according to the polynomial p in the variable s.
Definition at line 348 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberFactory::evaluateIR(), and GiNaCRA::RealAlgebraicNumberFactory::realRootsEval().
const numeric GiNaCRA::OpenInterval::findSample | ( | cln::cl_I | numeratorL, |
cln::cl_I | denominatorL, | ||
cln::cl_I | numeratorR, | ||
cln::cl_I | denominatorR | ||
) | [inline, static, private] |
Finds a number t between l:=numeratorL/denominatorL and r:=numeratorR/denominatorR so that t has a minimal number of digits.
The algorithm uses cln arithmetic operations only.
numeratorL | |
denominatorL | |
numeratorR | |
denominatorR |
Definition at line 412 of file OpenInterval.cpp.
References GiNaC::denominator(), GiNaC::gcd(), GiNaC::lcm(), and GiNaC::numerator().
Referenced by sample().
const numeric GiNaCRA::OpenInterval::findSample | ( | long | numeratorL, |
long | denominatorL, | ||
long | numeratorR, | ||
long | denominatorR | ||
) | [inline, static, private] |
Finds a number t between l:=numeratorL/denominatorL and r:=numeratorR/denominatorR so that t has a minimal number of digits.
The algorithm uses machine integer arithmetic only.
numeratorL | |
denominatorL | |
numeratorR | |
denominatorR |
Definition at line 447 of file OpenInterval.cpp.
References GiNaC::denominator(), GiNaC::gcd(), GiNaC::lcm(), and GiNaC::numerator().
const OpenInterval GiNaCRA::OpenInterval::intersection | ( | const OpenInterval & | o | ) | const |
o |
Definition at line 194 of file OpenInterval.cpp.
References mLeft, mRight, and OpenInterval().
bool GiNaCRA::OpenInterval::is_equal_same_type | ( | const basic & | o | ) | const [protected] |
Definition at line 140 of file OpenInterval.cpp.
References isEqual().
const bool GiNaCRA::OpenInterval::isEqual | ( | const OpenInterval & | o | ) | const |
o |
Definition at line 381 of file OpenInterval.cpp.
Referenced by is_equal_same_type(), GiNaCRA::operator!=(), and GiNaCRA::operator==().
const bool GiNaCRA::OpenInterval::isGreater | ( | const OpenInterval & | o | ) | const |
Compares only the right bounds of the involved intervals.
o |
----------]------------[------- >= -----]------------[------------ or ----------]------------[------- >= -------------]----[------------ holds.
Definition at line 397 of file OpenInterval.cpp.
References mRight.
Referenced by GiNaCRA::operator>=().
const bool GiNaCRA::OpenInterval::isLess | ( | const OpenInterval & | o | ) | const |
Compares only the left bounds of the involved intervals.
o |
-----]------------[------------ <= ----------]------------[------- or -----]------------[------------ <= ----------]-----[-------------- holds.
Definition at line 386 of file OpenInterval.cpp.
References mLeft.
Referenced by GiNaCRA::operator<=().
const bool GiNaCRA::OpenInterval::isNormalized | ( | ) | const |
Definition at line 174 of file OpenInterval.cpp.
const bool GiNaCRA::OpenInterval::isZero | ( | ) | const |
Definition at line 169 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberIR::add(), GiNaCRA::RealAlgebraicNumberIR::is_equal_same_type(), GiNaCRA::RealAlgebraicNumberIR::isEqual(), GiNaCRA::RealAlgebraicNumberIR::minus(), GiNaCRA::RealAlgebraicNumberIR::mul(), GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::RealAlgebraicNumberFactory::realRootsEval(), and GiNaCRA::RealAlgebraicNumberIR::sgn().
const numeric GiNaCRA::OpenInterval::left | ( | ) | const |
Selects the left bound.
Definition at line 115 of file OpenInterval.cpp.
References mLeft.
Referenced by GiNaCRA::RationalUnivariatePolynomial::countRealRoots(), GiNaCRA::RealAlgebraicNumberIR::inverse(), GiNaCRA::RealAlgebraicNumberIR::is_equal_same_type(), GiNaCRA::RealAlgebraicNumberIR::isEqual(), GiNaCRA::RealAlgebraicNumberIR::isLessWhileUnequal(), GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::operator*(), GiNaCRA::operator+(), GiNaCRA::RealAlgebraicNumberIR::refine(), GiNaCRA::RealAlgebraicNumberIR::refineAvoiding(), GiNaCRA::RealAlgebraicNumberFactory::searchRealRoots(), and GiNaCRA::RealAlgebraicNumberIR::sgn().
const bool GiNaCRA::OpenInterval::meets | ( | const numeric & | n | ) | const |
n |
Definition at line 189 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberIR::refineAvoiding().
const numeric GiNaCRA::OpenInterval::midpoint | ( | ) | const |
Definition at line 212 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberIR::approximateValue(), GiNaCRA::RealAlgebraicNumberIR::evalf(), GiNaCRA::RealAlgebraicNumberIR::refine(), sampleFast(), and GiNaCRA::RealAlgebraicNumberFactory::searchRealRoots().
const OpenInterval GiNaCRA::OpenInterval::minus | ( | ) | const |
Returns the negative value.
Definition at line 288 of file OpenInterval.cpp.
References mLeft, mRight, and OpenInterval().
Referenced by GiNaCRA::operator-().
const OpenInterval GiNaCRA::OpenInterval::mul | ( | const OpenInterval & | o | ) | const |
Multiplies two intervals and returns their product.
o |
Definition at line 293 of file OpenInterval.cpp.
References mLeft, mRight, and OpenInterval().
Referenced by GiNaCRA::operator*().
const OpenInterval GiNaCRA::OpenInterval::pow | ( | unsigned | e | ) | const |
Computes the power to e
of this interval.
e | exponent |
e
of this interval Definition at line 339 of file OpenInterval.cpp.
References mLeft, mRight, and OpenInterval().
const numeric GiNaCRA::OpenInterval::right | ( | ) | const |
Selects the right bound.
Definition at line 120 of file OpenInterval.cpp.
References mRight.
Referenced by GiNaCRA::RationalUnivariatePolynomial::countRealRoots(), GiNaCRA::RealAlgebraicNumberIR::inverse(), GiNaCRA::RealAlgebraicNumberIR::is_equal_same_type(), GiNaCRA::RealAlgebraicNumberIR::isEqual(), GiNaCRA::RealAlgebraicNumberIR::isLessWhileUnequal(), GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::operator*(), GiNaCRA::operator+(), GiNaCRA::RealAlgebraicNumberIR::refine(), GiNaCRA::RealAlgebraicNumberIR::refineAvoiding(), and GiNaCRA::RealAlgebraicNumberFactory::searchRealRoots().
const numeric GiNaCRA::OpenInterval::sample | ( | ) | const |
Chooses a numeric value out of the interval with the smallest numeric representation.
The core algorithm works with machine integer arithmetic whenever possible.
Goal: Compute a rational number within the isolating interval with the smallest number representation.
Definition at line 217 of file OpenInterval.cpp.
References GiNaC::denominator(), findSample(), mLeft, mRight, and GiNaC::numerator().
Referenced by GiNaCRA::RealAlgebraicNumberIR::refine(), sampleFast(), GiNaCRA::RealAlgebraicNumberIR::sampleValue(), and GiNaCRA::RealAlgebraicNumberFactory::searchRealRoots().
const numeric GiNaCRA::OpenInterval::sampleFast | ( | ) | const [inline] |
Returns sample() if the bounds are small enough for machine computations and midpoint otherwise.
Definition at line 170 of file OpenInterval.h.
References GiNaCRA::RealAlgebraicNumberSettings::MAX_FASTSAMPLE_BOUND, midpoint(), mLeft, mRight, and sample().
Referenced by GiNaCRA::RealAlgebraicNumberIR::refineAvoiding().
void GiNaCRA::OpenInterval::setLeft | ( | const numeric & | l | ) | throw ( std::invalid_argument ) |
Set new left bound for the interval.
l | new left bound |
Definition at line 103 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::RealAlgebraicNumberIR::refine(), and GiNaCRA::RealAlgebraicNumberIR::refineAvoiding().
void GiNaCRA::OpenInterval::setRight | ( | const numeric & | r | ) | throw ( std::invalid_argument ) |
Set new right bound for the interval.
r | new right bound |
Definition at line 109 of file OpenInterval.cpp.
Referenced by GiNaCRA::RealAlgebraicNumberIR::normalizeInterval(), GiNaCRA::RealAlgebraicNumberIR::refine(), and GiNaCRA::RealAlgebraicNumberIR::refineAvoiding().
numeric GiNaCRA::OpenInterval::mLeft [private] |
Definition at line 266 of file OpenInterval.h.
Referenced by abs(), add(), calchash(), contains(), div(), do_print(), evalf(), intersection(), isEqual(), isLess(), isNormalized(), isZero(), left(), midpoint(), minus(), mul(), pow(), sample(), and sampleFast().
numeric GiNaCRA::OpenInterval::mRight [private] |
Definition at line 267 of file OpenInterval.h.
Referenced by abs(), add(), calchash(), contains(), do_print(), evalf(), intersection(), isEqual(), isGreater(), isNormalized(), isZero(), midpoint(), minus(), mul(), pow(), right(), sample(), and sampleFast().