[GiNaC-devel] About a (poor) parity in expressions.
Francois Maltey
fmaltey at nerim.fr
Sun Oct 17 16:31:20 CEST 2010
Hello,
I'm a ginac user because I use Sage, and I work around expressions.
I discover that ginac remains function arguments (more than the other
computer algebra system).
So sin(x)+sin(-x) remains sin(x)+sin(-x), and I don't get 0.
The only automatic rewrite rules I discover around signs and integers are :
1 / exp(x) ==> exp(-x)
exp(x)^2 ==> exp(2*x)
I don't speak about exp(log(x)) ==> x, sin(atan(x)) ==> x/sqrt(x^2+1), ...
Are there other rewrite rules ?
After some computations, I offen get a result as sin(x)+sin(-x) or
cos(x)-cos(-x).
I know it's almost impossible to choose between cos(a-b) and cos(b-a).
But it's possible to choose only one expression between a-b and b-a :
1/ Look at the only numeric constant in a product, and test if it's a
positive one.
2/ Look at the first term in a sum, and test this first term.
Can I find it in ginac or must I use this sage function :
def pseudoPositive (expr) :
if expr._is_real() : return bool (RR(expr) >= 0)
if expr._is_numeric () :
return bool ((expr.real() > 0) or (expr.real() == 0 and expr.imag()
> 0))
if expr._is_symbol() : return True
opor = expr.operator()
opands = expr.operands()
if opor == operator.mul :
return pseudoPositive (opands[-1])
if opor == operator.add :
return pseudoPositive (opands[0])
return True
Then I redefine the usual functions as sin by :
def rewSin (expr) :
if pseudoPositive (expr) : return sin (expr)
else : return -sin(-expr)
By this way I get all the easy simplifications.
Where do ginac developpers see these rules ? inside-ginac or outside-ginac ?
It's not a good idea to (re-)code these rules inside sage if I can get
them by ginac.
Many thanks for your advices.
Francois (in France)
More information about the GiNaC-devel
mailing list