Hi, Thank you for your suggestion! It is almost what I want to do. However, in my case also the symbols a0 and a1 are different objects with the same text: int main(){ ex A = symbolic_matrix(1,2, "a"); ex B = symbolic_matrix(1,2, "a"); symbol x("x"); ex a, b; int n=0; for (const_iterator i = A.begin(); i != A.end(); ++i) { a += (*i)*pow(x,n); n++; } n=0; for (const_iterator i = B.begin(); i != B.end(); ++i) { b += (*i)*pow(x,n); n++; } cout << "a-b=" << (a-b).expand() << endl; return 0; } Any suggestions when the expressions "a0+a1*x" are produced this way? Maybe string comparison of the texts in the coefficient objects is a way to do it? -- Vera Louise Hauge On Thu, 18 Aug 2005, Markus Knodel wrote:
Hi,
#include <ginac/ginac.h> #include <iostream>
using namespace std; using namespace GiNaC;
int main() {
symbol a0("a0"), x("x"), a1("a1");
ex a = a0 + x*a1; ex b = a0 + a1*x;
ex diff = a - b;
ex diff_expd = diff.expand();
cout << "a-b = " << diff_expd << endl;
// should give: a-b = 0
return 0; }
I want to compare (or test the equality of) two ex objects which contain symbols. a = a0 + x*a1; b = a0 + a1*x;
If the ex objects are evaluated (symbolically), such that a-b becomes 0, then the test would be finished.
However, how do I evaluate such a expression as a-b symbolically?
is this what you wanted?
Cheers Markus
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list