Hi, I attached a patch with my attempts to solve this problem. It is based on the latest version of pynac. I hope it applies cleanly to GiNaC as well. On Mon, 3 May 2010 17:50:44 +0200 Burcin Erocal <burcin@erocal.org> wrote:
On Fri, 30 Apr 2010 09:06:03 +0200 "Richard B. Kreckel" <kreckel@ginac.de> wrote:
Alas, I think that automatic evaluation of conjugation is too aggressive in GiNaC. It just keeps giving incorrect results on branch cuts. Here are some examples, using ginsh:
conjugate(sqrt(x)); sqrt(conjugate(x)) conjugate(sqrt(x))-sqrt(conjugate(x)); 0 conjugate(sqrt(-1))-sqrt(conjugate(-1)); -2*I conjugate(log(x)); log(conjugate(x)) conjugate(log(x))-log(conjugate(x)); 0 conjugate(log(-1))-log(conjugate(-1)); -(2*I)*Pi
I suggest to disable automatic evaluateion of conjugation where these kinds of problems can appear.
Opinions?
I agree that the automatic evaluation should be disabled for most cases. I don't immediately see a good definition for these cases though, but then I am not knowledgeable in this area at all.
For some time now, pynac doesn't automatically evaluate conjugates of function objects: http://pynac.sagemath.org/hg/rev/4c0f8441d460 This prevents the problems with log() above.
Maple seems to convert sqrt(-3) to sqrt(3)*I automatically:
sqrt(-3); 1/2 3 I
Perhaps adding this automatic evaluation rule for power objects would simplify the conditions we need to consider for automatic evaluation of conjugation.
Attached patch adds a rule to power::eval() to transform ^(-c1, c2) to *(^(-1, c2), (c1, c2)) when c1 and c2 are both rational. I got this idea from maxima. I also restrict the automatic conjugation unless the basis is real and the exponent is a rational, returning *this in this case. This seems to give an acceptable response to conjugate(sqrt(-3)): sage: conjugate(sqrt(-3)) -I*sqrt(3) Comments? Cheers, Burcin