Hello Bernard,
I suggest a new function dedicated specifically to trigonometric simplification, called trigsimplify. I attached the code below, it's a Makefile project which tests the function automatically. The function is very simple but effective, combining simplify, texpand, tcollect, tlin, trigtan, trigsin and trigcos in a certain order. The measure of complexity is the number of characters needed for textual representation of an expression (obtained by combining size and cat functions). If there's a better complexity measure within Giac, please let me know.
In many cases trigsimplify gives much more elegant results than the general simplify. I tested it on 25 expressions (see the enclosed PDF) with results in results.txt.
trigonometric simplification
Modérateur : xcasadmin
trigonometric simplification
- Pièces jointes
-
- trigsimp.zip
- (65.47 Kio) Téléchargé 175 fois
Re: trigonometric simplification
Perhaps you could use the taille function to measure complexity.
It will compute a number related to the number of nodes in the symbolic expression, and it will stop computing as soon as max is reached. That way you are sure it will not take too much time.
Code : Tout sélectionner
symbolic.h: unsigned taille(const gen & g,unsigned max);
Re: trigonometric simplification
Thanks for the suggestion, taille is indeed a time saver. The total of 44 candidate expressions need to be examined and no more than n nodes will be counted in each of them, where n is number of nodes in the original expression. Hence it's impossible for the new version of function (attached below) to hang.
- Pièces jointes
-
- trigsimp-fix1.zip
- (1.04 Kio) Téléchargé 181 fois
Re: trigonometric simplification
When I looked more closely to the result of tests, I noticed that one nonzero expression is simplifying to zero. When I traced the problem, I found that these commands give wrong result:The result is zero. It seems like there's a bug somewhere, I think the problem is with tcollect.
Code : Tout sélectionner
expr:=2*pi*sin(a*pi)/(1-cos(2*a*pi));
tcollect(simplify(expr))
Re: trigonometric simplification
Actually it was in simplify, more precisely in exp2pow transforming exp(i*pi*a) in (-1)^a