[GiNaC-devel] removing the evil

Alexei Sheplyakov varg at theor.jinr.ru
Wed Jul 16 06:18:25 CEST 2008


Dear Richard,

On Tue, Jul 15, 2008 at 09:41:06PM +0200, Richard B. Kreckel wrote:

> Well, over here I get:
> 
> $ cat relationaltest.cc
> #include <iostream>
> #include <ginac/ginac.h>
> using namespace std;
> using namespace GiNaC;
> 
> int main()
> {
>      symbol x("x");
>      ex e1, e2;
>      // do some calculation
>      e1 = series(tgamma(x),x==0,3).op(3);
>      e2 = series(log(x),x==1,6).op(4);
>      cout << e1 << endl;
>      cout << e2 << endl;
>      if (e1 == e2) { // gotcha: what happens?
>          cout << "e1 and e2 appear to be equal." << endl;
>      } else {
>          cout << "e1 and e2 appear to differ." << endl;
>      }
> }
> $ g++ -O relationaltest.cc -lginac
> $ ./a.out
> -1/12*x^2*(2*Euler^3+Euler*Pi^2+4*zeta(3))
> 1/5*(-1+x)^5
> e1 and e2 appear to differ.

I'm a bit confused. The program fails to compile if I comment out
declarations of operator[=!<>][=]*, like this

diff --git a/ginac/operators.h b/ginac/operators.h
index c08713f..a821aed 100644
--- a/ginac/operators.h
+++ b/ginac/operators.h
@@ -74,12 +74,14 @@ const numeric operator++(numeric & lh, int);
 const numeric operator--(numeric & lh, int);
 
 // binary relational operators ex with ex
+/*
 const relational operator==(const ex & lh, const ex & rh);
 const relational operator!=(const ex & lh, const ex & rh);
 const relational operator<(const ex & lh, const ex & rh);
 const relational operator<=(const ex & lh, const ex & rh);
 const relational operator>(const ex & lh, const ex & rh);
 const relational operator>=(const ex & lh, const ex & rh);
+*/

 // input/output stream operators
 std::ostream & operator<<(std::ostream & os, const ex & e);


So, e1 == e2 definitely creates the `relational' object. But it seems
to give correct results anyway. I don't quite understand what's going
on.

> What is your point?

I've noticed that my program

1. *sometimes* gives incorrect result 
2. *always* consumes more memory

if I use operator== to compare expressions instead of .is_equal() method.
Unfortunately, I'm unable to provide a simple test case.

Also some (most?) templates libraries don't work with GiNaC::ex "out of box"
because comparision operators return `relational' instead of bool.


Best regards,
	Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-devel/attachments/20080716/278e22f0/attachment.sig 


More information about the GiNaC-devel mailing list