Hi Paul,
This is a bug. I assume that the result is mathematically correct but
it is not a good transformation of the expression.
Can you open a GitHub issue for this and link back to this mailing
list thread (and send the link to the issue back here as well)?
The problem is with Pow.conjugate
In [1]: class CustomExpr(Expr): pass
In [2]: e = sqrt(1+2*CustomExpr(x))
In [3]: print(e)
sqrt(1 + 2*CustomExpr(x))
In [4]: print(e.conjugate())
-I*((2*re(CustomExpr(re(x) + I*im(x))) + 1)**2 + 4*im(CustomExpr(re(x)
+ I*im(x)))**2)**(1/4)*sin(atan2(2*im(CustomExpr(re(x) + I*im(x))),
2*re(CustomExpr(re(x) + I*im(x))) + 1)/2) + ((2*re(CustomExpr(re(x) +
I*im(x))) + 1)**2 + 4*im(CustomExpr(re(x) +
I*im(x)))**2)**(1/4)*cos(atan2(2*im(CustomExpr(re(x) + I*im(x))),
2*re(CustomExpr(re(x) + I*im(x))) + 1)/2)
This is because Pow.conjugate calls expand_complex which it should
not. Actually though the call to expand_complex is gated on the base
being not a positive number which exposes a bug here:
In [5]: (1 + 2*CustomExpr(x)).is_positive
Out[5]: False
That should return None rather than False so there is a bug in the
assumptions system.
The cause of this is that is_commutative is part of the assumptions
system (which it really shouldn't be) and CustomExpr has
is_commutative = None. A workaround is to define CustomExpr like this:
class CustomExpr(Expr):
is_commutative = True
--
Oscar
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
sympy+un...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/sympy/a93b9e4e-a9e5-4233-8417-c68121430c33n%40googlegroups.com.