[GiNaC-list] open interval class with GiNaC's term evaluation engine
Alexei Sheplyakov
alexei.sheplyakov at gmail.com
Thu Sep 30 21:16:45 CEST 2010
Hello,
On Mon, Sep 27, 2010 at 04:28:03PM +0200, Ulrich Loup wrote:
> I try to implement a class for open intervals with interval arithmetic. I
> followed the instructions written in the GiNaC tutorial (6.5)
> and also used the implementation of "numeric" etc. as example code in order to
> get a clue of implementing the operators for my interval class.
>
> My goal is to get the class working with GiNaC's term evaluation engine and in
> particular, allow for polynomials with interval coefficients, which are
> automatically simplified by the use of the arithmetic operations I
> implemented.
I'm afraid it's not going to work. GiNaC (specifically, GiNaC::add,
GiNaC::mul, and GiNaC::expairseq) handles numbers in a special way
for efficiency reasons. Therefore you'd need to modify that code to
work with your interval class. Such changes are going to make
the code (even) more complicated, and will certainly slow down GiNaC
(which IMHO is unacceptable, unfortunately add::eval() is already
slow enough).
A few comments regarding the code itself...
> /**
> * Set new bounds for the interval.
> *@param l new left bound
> *@param r new right bound
> */
> void setBounds(const numeric&, const numeric&) throw(invalid_argument);
Const methods only, please (GiNaC objects are essentially immutable,
there are only few exceptions, like ctors and let_op, and the latter
takes care to not modify a multiply referenced object).
> /** Adds two intervals and returns a reference to their sum, allocated on the heap.
> *@param o
> *@return sum allocated on the heap
> */
> const OpenInterval& add_dyn(const OpenInterval& o) const;
Are you sure *_dyn methods are necessary (or useful) here?
> private:
>
> ////////////////
> // Attributes //
> ////////////////
>
> numeric* const mpLeft; // pointer to the left bound of the interval (pointer is fixed, value not)
> numeric* const mpRight; // pointer to the right bound of the interval (pointer is fixed, value not)
I think pointers are not necessary here. Please use plain numeric instead:
numeric mpLeft;
numeric mpRight;
Best regards,
Alexei
More information about the GiNaC-list
mailing list