since there seems no permanent maintainer of Pynac I proposeto do the next release of Pynac. I have already transferred thesource/history as planned to github at:
Benjamin Hackl has also made a pull request there for the issuein #15846 and I'm planning to at least fix some infinity comparisonissues that look easy to fix.So this is not a hostile but a pragmatic takeover. 8P
Oh, and I'm posting this here because my earlier posting to pynac-develwas not even moderated.
One thing I would definitely make sure of is to try to update with the upstream Ginac source as possible.
One reason I never took Pynac over is because I knew I wouldn't have time to sync with (useful) changes upstream, but I think in general we want to do that (also to report there, of course).
sage: a,b = var('a b')
sage: abs(sqrt(x))
sqrt(abs(x))
sage: sqrt(abs(x)^2)
sqrt(x*conjugate(x))
sage: abs(x)^2
x*conjugate(x)
sage: A = abs((a+I*b))^2
sage: A
(a + I*b)*(conjugate(a) - I*conjugate(b))
sage: A.canonicalize_radical()
a^2 + b^2
sage: imag(A)
0
sage: imag(A.canonicalize_radical())
2*imag_part(a)*real_part(a) + 2*imag_part(b)*real_part(b)
sage: f = sqrt(abs(x)^2); f.canonicalize_radical()
x
The following changed behaviour leads to a few fails:
sage: a,b = var('a b')
sage: abs(sqrt(x))
sqrt(abs(x))
sage: sqrt(abs(x)^2)
sqrt(x*conjugate(x))
sage: abs(x)^2
x*conjugate(x)
sage: A = abs((a+I*b))^2
sage: A
(a + I*b)*(conjugate(a) - I*conjugate(b))
sage: A.canonicalize_radical()
a^2 + b^2
sage: imag(A)
0
sage: imag(A.canonicalize_radical())
2*imag_part(a)*real_part(a) + 2*imag_part(b)*real_part(b)
sage: f = sqrt(abs(x)^2); f.canonicalize_radical()
xReason is probably these commits:
https://github.com/pynac/pynac/commit/b645d3c200e74531f735d786259d043cbffe758a
The following changed behaviour leads to a few fails:
sage: a,b = var('a b')
sage: abs(sqrt(x))
sqrt(abs(x))
sage: sqrt(abs(x)^2)
sqrt(x*conjugate(x))
sage: abs(x)^2
x*conjugate(x)What does Maxima do with these? I know that there has been endless discussion of what to do with things involving abs, square, and sqrt.
(%i1) abs(sqrt(x));
(%o1) sqrt(x)
(%i2) sqrt(abs(x)^2);
(%o2) abs(x)
(%i3) abs(x)^2;
2
(%o3) x
sage: A = abs((a+I*b))^2
sage: A
(a + I*b)*(conjugate(a) - I*conjugate(b))
sage: A.canonicalize_radical()
a^2 + b^2Given the history of radcan I wouldn't necessarily worry about this, though what the previous behavior is would be worth looking at.
The following changed behaviour leads to a few fails:
sage: sqrt(abs(x)^2)
sqrt(x*conjugate(x))
So, do we want this?
sage: bool(sqrt(abs(x)**2) == abs(x))
False
sage: abs(x**2)
x*conjugate(x)
sage: (-1)^(2/3)
1
sage: sqrt(abs(x)^2)
sqrt(x*conjugate(x))So, do we want this?
I am a little bit worried to see this: whatever x (real positive, negative or complex), sqrt(abs(x)^2) should *always* return abs(x).
>>
>> (%i1) abs(sqrt(x));
>> (%o1) sqrt(x)
>> (%i2) sqrt(abs(x)^2);
>> (%o2) abs(x)
>> (%i3) abs(x)^2;
>> 2
>> (%o3) x
>
> That last one is only true if `x` is real. ginac’s answer doesn’t make this
> assumption and is more generic than maxima here.
The first one is true if `x` is real and non-negative... but
(%i4) abs(sqrt(-x));
(%o4) sqrt(- x)
is true if `x` is real and non-positive...
I would say to stick with GiNaC behavior within Pynac if we can deal with such behaviors at the Sage level.
That would ease maintenance of Pynac, don't you think?
sage: x=var('x', domain='real')
sage: abs(x**2)
x^2
sage: abs(x)**2
x^2
sage: abs(sqrt(x))
sqrt(abs(x))
sage: a,b = var('a b', domain='real')
sage: A = abs((a+I*b))^2
sage: A
(a + I*b)*(a - I*b)
sage: imag(A.canonicalize_radical())
0