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)
Dear Francois,
On Sun, 17 Oct 2010 16:31:20 +0200, Francois Maltey <fmaltey@nerim.fr> said: FM> After some computations, I offen get a result as sin(x)+sin(-x) FM> or cos(x)-cos(-x).
I am facing similar situations very often. If there is a predictable pattern in the answer I am employing a custom replacement (subs() method) with wildcards. This is rather effective and much safer than to put it into the core GiNaC. So far software is not smart enough to make all possible tricks, it may be reasonable to leave the final touch to humans. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
--- On Sun, 10/17/10, Vladimir V. Kisil <kisilv@maths.leeds.ac.uk> wrote:
From: Vladimir V. Kisil <kisilv@maths.leeds.ac.uk> Subject: Re: [GiNaC-devel] About a (poor) parity in expressions. To: "GiNaC development list" <ginac-devel@ginac.de>, "Francois Maltey" <fmaltey@nerim.fr> Cc: "Vladimir V. Kisil" <kisilv@maths.leeds.ac.uk> Date: Sunday, October 17, 2010, 10:28 AM Dear Francois,
On Sun, 17 Oct 2010 16:31:20 +0200, Francois Maltey <fmaltey@nerim.fr> said: FM> After some computations, I offen get a result as sin(x)+sin(-x) FM> or cos(x)-cos(-x).
I am facing similar situations very often. If there is a predictable pattern in the answer I am employing a custom replacement (subs() method) with wildcards. This is rather effective and much safer than to put it into the core GiNaC.
So far software is not smart enough to make all possible tricks, it may be reasonable to leave the final touch to humans.
Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/ _______________________________________________ GiNaC-devel mailing list GiNaC-devel@ginac.de https://www.cebix.net/mailman/listinfo/ginac-devel
To me it looks like two missing rewriting rules. Regards, Sergei.
Dear Sergei,
On Sun, 17 Oct 2010 13:40:19 -0700 (PDT), Sergei Steshenko <sergstesh@yahoo.com> said: SS> To me it looks like two missing rewriting rules.
Yes, it is so. But if they added to GiNaC core this can break something in a different place, see the example with my own suggestion to "add a rewriting rule": http://www.ginac.de/pipermail/ginac-devel/2009-October/001678.html A hundred of rewriting rules in the core GiNaC will make it slow and can cause other problems. A couple of rewriting rules added in the user's code to address a specific issue at the right place are much more manageable. This what I am doing in my own programmes right now. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
--- On Sun, 10/17/10, Vladimir V. Kisil <kisilv@maths.leeds.ac.uk> wrote:
From: Vladimir V. Kisil <kisilv@maths.leeds.ac.uk> Subject: Re: [GiNaC-devel] About a (poor) parity in expressions. To: "GiNaC development list" <ginac-devel@ginac.de>, "Sergei Steshenko" <sergstesh@yahoo.com> Date: Sunday, October 17, 2010, 2:59 PM Dear Sergei,
On Sun, 17 Oct 2010 13:40:19 -0700 (PDT), Sergei Steshenko <sergstesh@yahoo.com> said: SS> To me it looks like two missing rewriting rules.
Yes, it is so. But if they added to GiNaC core this can break something in a different place, see the example with my own suggestion to "add a rewriting rule":
http://www.ginac.de/pipermail/ginac-devel/2009-October/001678.html
A hundred of rewriting rules in the core GiNaC will make it slow and can cause other problems. A couple of rewriting rules added in the user's code to address a specific issue at the right place are much more manageable. This what I am doing in my own programmes right now.
Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
So what ? I.e. exp(x) * exp(-x) == exp(x - x) == exp(0) == 1. So, yet another rewriting rule is missing ? Thanks, Sergei.
On Sun, Oct 17, 2010 at 11:40 PM, Sergei Steshenko <sergstesh@yahoo.com> wrote:
To me it looks like two missing rewriting rules.
By design GiNaC does not apply any rewriting rules on its own. GiNaC is designed to process large expressions (~10^7 -- 10^9 terms), therefore implicit evaluation does only "simple" (that is, O(N^2)) transformations, everything else (normal(), evalm(), etc) is done only upon the user request.
participants (4)
-
Alexei Sheplyakov
-
Francois Maltey
-
Sergei Steshenko
-
Vladimir V. Kisil