[GiNaC-devel] removing the evil
Richard B. Kreckel
kreckel at ginac.de
Tue Jul 15 22:24:41 CEST 2008
Dear Alexei,
I wrote:
> Alexei Sheplyakov wrote:
>> 2. (a consequence of 1) No bugs like this:
>>
>> ex e1, e2;
>> // do some calculation
>> if (e1 == e2) { // gotcha: this is always true.
>> // do something
>> }
>
> 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.
>
> What is your point?
I'm reading my batch of email backwards. I've now seen
<http://www.ginac.de/pipermail/ginac-devel/2008-July/001370.html>, but
when I try to complete these examples, they don't work as you describe:
$ cat relationaltest1.cc
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
unsigned n = 2;
symbol A("A");
symbol mu_sym("mu");
idx mu(mu_sym,4);
if (n == ex_to<idx>(mu).get_dim()) {
cout << "doing something" << endl;
} else {
cout << "doing nothing" << endl;
}
}
$ g++ -O relationaltest1.cc -lginac
$ ./a.out
doing nothing
$ cat relationaltest2.cc
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
matrix M(4,4);
for (unsigned r=0; r<4; ++r) {
for (unsigned c=0; c<4; ++c) {
M.set(r,c,numeric(1,r+c+1));
}
}
if (M(1,2) != M(2,1)) {
cout << "M(1,2) and M(2,1) appear to differ." << endl;
} else {
cout << "M(1,2) and M(2,1) appear to be equal." << endl;
}
if (M(1,3) != M(0,0)) {
cout << "M(1,3) and M(0,0) appear to differ." << endl;
} else {
cout << "M(1,3) and M(0,0) appear to be equal." << endl;
}
}
$ g++ -O relationaltest2.cc -lginac
$ ./a.out
M(1,2) and M(2,1) appear to be equal.
M(1,3) and M(0,0) appear to differ.
Cheers
-richy.
--
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>
More information about the GiNaC-devel
mailing list