trigonometric simplification

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

trigonometric simplification

Message par lukamar » ven. sept. 29, 2017 10:48 am

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.
Pièces jointes
trigsimp.zip
(65.47 Kio) Téléchargé 103 fois

parisse
Messages : 5084
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: trigonometric simplification

Message par parisse » ven. sept. 29, 2017 5:27 pm

Perhaps you could use the taille function to measure complexity.

Code : Tout sélectionner

symbolic.h:  unsigned taille(const gen & g,unsigned max);
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.

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: trigonometric simplification

Message par lukamar » ven. sept. 29, 2017 7:11 pm

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é 106 fois

lukamar
Messages : 294
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: trigonometric simplification

Message par lukamar » sam. sept. 30, 2017 10:40 am

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:

Code : Tout sélectionner

expr:=2*pi*sin(a*pi)/(1-cos(2*a*pi));
tcollect(simplify(expr))
The result is zero. It seems like there's a bug somewhere, I think the problem is with tcollect.

parisse
Messages : 5084
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: trigonometric simplification

Message par parisse » sam. sept. 30, 2017 2:23 pm

Actually it was in simplify, more precisely in exp2pow transforming exp(i*pi*a) in (-1)^a

Répondre