Hello! On Thu, Nov 18, 2004 at 01:51:03PM +0100, Christian Bauer wrote:
symbol m1("m1"); symbol m2("m2"); symbol x("x"); ex e1 = pow(x,2)*pow(m1,2) - pow(x,2)*pow(m2,2); ex e2 = pow(pow(x,2)*pow(m1,2)-pow(x,2)*pow(m2,2),100); ex ca, cb, gc; gc = gcd(e1, e2, &ca, &cb, false); cout << c2 << endl; // this won't be just x^198*(m1^2-m2^2)^99. // (m1^2-m2^2)^99 gets expanded. cout << (e1/e2).normal() << endl; // won't print just x^(-198)*(m1^2-m2^2)^(-99), // (m1^2-m2^2)^99 gets expanded
I'm sorry, there is a small error in my previous post, e1 should be ex e1 = pow(x,2)*pow(m2,2) - pow(x,2)*pow(m1,2);
I'm getting ca = 1, cb = (-m2^2*x^2+m1^2*x^2)^99,
I'm getting the same with e1 = x^2*m1^2 - x^2*m2^2. But with e1 = x^2*m2^2 - x^2*m1^2 ca = -1 cb = x^198*[expanded (m1^2-m2^2)^99]
and e1/e2 gets simplified to (-m2^2*x^2+m1^2*x^2)^(-99) by power::eval() even before normal() is invoked.
In ginsh: $ test = (x^2*m2^2-x^2*m1^2)/(x^2*m1^2-x^2*m2^2)^100; (-x^2*m1^2+x^2*m2^2)*(x^2*m1^2-x^2*m2^2)^(-100) $ test2 = (x^2*m1^2-x^2*m2^2)/(x^2*m1^2-x^2*m2^2)^100; (x^2*m1^2-x^2*m2^2)^(-99)
Besides, gcd() already has heuristics for the cases b==a^n (or a==b^n).
Unfortunately, gcd() does not play well with a==e*something^n (e is something simple, n >> 1), as my example demonstrates.
Hm, which version of GiNaC are you using?
I use GiNaC 1.3.0 from CVS. Thanks, Alexei.