REDUCE

16.72 TRIGSIMP: Simplification and factorization of trigonometric and hyperbolic functions

Author: Wolfram Koepf.

16.72.1 Introduction

The REDUCE package TRIGSIMP is a useful tool for all kinds of problems related to trigonometric and hyperbolic simplification and factorization. There are three operators included in TRIGSIMP: trigsimp, trigfactorize and triggcd. The first is for simplifying trigonometric or hyperbolic expressions and has many options, the second is for factorizing them and the third is for finding the greatest common divisor of two trigonometric or hyperbolic polynomials. This package is automatically loaded when one of these operators is used.

16.72.2 Simplifying trigonometric expressions

As there is no normal form for trigonometric and hyperbolic expressions, the same function can convert in many different directions, e.g. sin(2x) 2 sin(x) cos(x). The user has the possibility to give several parameters to the operator trigsimp in order to influence the transformations. It is possible to decide whether or not a rational expression involving trigonometric and hyperbolic functions vanishes.

To simplify an expression f, one uses trigsimp(f[,options]). For example:

trigsimp(sin(x)^2+cos(x)^2);  
 
1

The possible options (where * denotes the default) are:

  1. sin* or cos;
  2. sinh* or cosh;
  3. expand*, combine or compact;
  4. hyp, trig or expon;
  5. keepalltrig;
  6. tan and/or tanh;
  7. target arguments of the form variable / positive integer.

From each of the first four groups one can use at most one option, otherwise an error message will occur. Options can be given in any order.

The first group fixes the preference used while transforming a trigonometric expression:

trigsimp(sin(x)^2);  
 
      2  
sin(x)  
 
trigsimp(sin(x)^2, cos);  
 
         2  
 - cos(x)  + 1

The second group is the equivalent for the hyperbolic functions.

The third group determines the type of transformation. With the default, expand, an expression is transformed to use only simple variables as arguments:

trigsimp(sin(2x+y));  
 
                                 2  
2*cos(x)*cos(y)*sin(x) - 2*sin(x) *sin(y) + sin(y)

With combine, products of trigonometric functions are transformed to trigonometric functions involving sums of variables:

trigsimp(sin(x)*cos(y), combine);  
 
 sin(x - y) + sin(x + y)  
-------------------------  
            2

With compact, the REDUCE operator compact[?] is applied to f. This often leads to a simple form, but in contrast to expand one does not get a normal form. For example:

trigsimp((1-sin(x)^2)^20*(1-cos(x)^2)^20, compact);  
 
      40       40  
cos(x)  *sin(x)

With an option from the fourth group, the input expression is transformed to trigonometric, hyperbolic or exponential form respectively:

trigsimp(sin(x), hyp);  
 
 - sinh(i*x)*i  
 
trigsimp(sinh(x), expon);  
 
  2*x  
 e    - 1  
----------  
      x  
   2*e  
 
trigsimp(e^x, trig);  
 
cos(i*x) - sin(i*x)*i

Usually, tan, cot, sec, csc are expressed in terms of sin and cos. It can sometimes be useful to avoid this, which is handled by the option keepalltrig:

trigsimp(tan(x+y), keepalltrig);  
 
  - (tan(x) + tan(y))  
----------------------  
  tan(x)*tan(y) - 1

Alternatively, the options tan and/or tanh can be given to convert the output to the specified form as far as possible:

trigsimp(tan(x+y), tan);  
 
  - (tan(x) + tan(y))  
----------------------  
  tan(x)*tan(y) - 1

By default, the other functions used will be cos and/or cosh, unless the other desired functions are also specified in which case this choice will be respected.

The final possibility is to specify additional target arguments for the trigonometric or hyperbolic functions, each of which should have the form of a variable divided by a positive integer. These additional arguments are treated as if they had occurred within the expression to be simplified, and their denominators are used in determining the overall denominator to use for each variable in the simplified form:

trigsimp(csc x - cot x + csc y - cot y, x/2, y/2, tan);  
 
     x          y  
tan(---) + tan(---)  
     2          2

It is possible to use the options of different groups simultaneously:

trigsimp(sin(x)^4, cos, combine);  
 
 cos(4*x) - 4*cos(2*x) + 3  
---------------------------  
             8

Sometimes, it is necessary to handle an expression in separate steps:

trigsimp((sinh(x)+cosh(x))^n+(cosh(x)-sinh(x))^n, expon);  
 
  1   n    n*x  
(----)  + e  
   x  
  e  
 
trigsimp(ws, hyp);  
 
2*cosh(n*x)  
 
trigsimp((cosh(a*n)*sinh(a)*sinh(p)+cosh(a)*sinh(a*n)*sinh(p)+  
    sinh(a - p)*sinh(a*n))/sinh(a));  
 
cosh(a*n)*sinh(p) + cosh(p)*sinh(a*n)  
 
trigsimp(ws, combine);  
 
sinh(a*n + p)

The trigsimp operator can be applied to equations, lists and matrices (and compositions thereof) as well as scalar expressions, and automatically maps itself recursively over such non-scalar data structures:

trigsimp( { sin(2x) = cos(2x) } );  
 
                            2  
{2*cos(x)*sin(x)= - 2*sin(x)  + 1}

16.72.3 Factorizing trigonometric expressions

With trigfactorize(p,x) one can factorize the trigonometric or hyperbolic polynomial p in terms of trigonometric functions of the argument x. The output has the same format as that from the standard REDUCE operator factorize. For example:

trigfactorize(sin(x), x/2);  
 
             x            x  
{{2,1},{sin(---),1},{cos(---),1}}  
             2            2

If the polynomial is not coordinated or balanced [?], the output will equal the input. In this case, changing the value for x can help to find a factorization, e.g.

trigfactorize(1+cos(x), x);  
 
{{cos(x) + 1,1}}  
 
trigfactorize(1+cos(x), x/2);  
 
             x  
{{2,1},{cos(---),2}}  
             2

The polynomial can consist of both trigonometric and hyperbolic functions:

trigfactorize(sin(2x)*sinh(2x), x);  
 
{{4,1}, {sinh(x),1}, {cosh(x),1}, {sin(x),1}, {cos(x),1}}

The trigfactorize operator respects the standard REDUCE factorize switch nopowers – see the REDUCE manual for details. Turning it on gives the behaviour that was standard before REDUCE 3.7:

on nopowers;  
 
trigfactorize(1+cos(x), x/2);  
 
        x        x  
{2,cos(---),cos(---)}  
        2        2

16.72.4 GCDs of trigonometric expressions

The operator triggcd is essentially an application of the algorithm behind trigfactorize. With its help the user can find the greatest common divisor of two trigonometric or hyperbolic polynomials. It uses the method described in [?]. The syntax is triggcd(p,q,x), where p and q are the trigonometric polynomials and x is the argument to use. For example:

triggcd(sin(x), 1+cos(x), x/2);  
 
     x  
cos(---)  
     2  
 
triggcd(sin(x), 1+cos(x), x);  
 
1

The polynomials p and q can consist of both trigonometric and hyperbolic functions:

triggcd(sin(2x)*sinh(2x), (1-cos(2x))*(1+cosh(2x)), x);  
 
cosh(x)*sin(x)

16.72.5 Further Examples

With the help of this package the user can create identities:

trigsimp(tan(x)*tan(y));  
 
 sin(x)*sin(y)  
---------------  
 cos(x)*cos(y)  
 
trigsimp(ws, combine);

 cos(x - y) - cos(x + y)  
-------------------------  
 cos(x - y) + cos(x + y)

trigsimp((sin(x-a)+sin(x+a))/(cos(x-a)+cos(x+a)));  
 
 sin(x)  
--------  
 cos(x)  
 
trigsimp(cosh(n*acosh(x))-cos(n*acos(x)), trig);  
 
0  
 
trigsimp(sec(a-b), keepalltrig);  
 
  csc(a)*csc(b)*sec(a)*sec(b)  
-------------------------------  
 csc(a)*csc(b) + sec(a)*sec(b)  
 
trigsimp(tan(a+b), keepalltrig);  
 
  - (tan(a) + tan(b))  
----------------------  
  tan(a)*tan(b) - 1  
 
trigsimp(ws, keepalltrig, combine);  
 
tan(a + b)

Some difficult expressions can be simplified:

df(sqrt(1+cos(x)), x, 4);  
 
            5           4            3       2            3  
( - 4*cos(x)  - 4*cos(x)  - 20*cos(x) *sin(x)  + 12*cos(x)  
 
             2       2            2                   4  
  - 24*cos(x) *sin(x)  + 20*cos(x)  - 15*cos(x)*sin(x)  
 
                    2                       4            2  
  + 12*cos(x)*sin(x)  + 8*cos(x) - 15*sin(x)  + 16*sin(x) )/  
 
(16*sqrt(cos(x) + 1)  
 
         4           3           2  
 *(cos(x)  + 4*cos(x)  + 6*cos(x)  + 4*cos(x) + 1))  
 
on rationalize;  
trigsimp(ws);  
 
 sqrt(cos(x) + 1)  
------------------  
        16  
 
off rationalize;  
load_package taylor;  
 
taylor(sin(x+a)*cos(x+b), x, 0, 4);  
 
cos(b)*sin(a) + (cos(a)*cos(b) - sin(a)*sin(b))*x  
 
                                    2  
 - (cos(a)*sin(b) + cos(b)*sin(a))*x  
 
    2*( - cos(a)*cos(b) + sin(a)*sin(b))   3  
 + --------------------------------------*x  
                     3  
 
    cos(a)*sin(b) + cos(b)*sin(a)   4      5  
 + -------------------------------*x  + O(x )  
                  3  
 
trigsimp(ws, combine);  
 
 sin(a - b) + sin(a + b)                               2  
------------------------- + cos(a + b)*x - sin(a + b)*x  
            2  
 
    2*cos(a + b)   3    sin(a + b)   4      5  
 - --------------*x  + ------------*x  + O(x )  
         3                  3

Certain integrals whose evaluation was not possible in REDUCE (without preprocessing) are now computable:

int(trigsimp(sin(x+y)*cos(x-y)*tan(x)), x);  
 
       2  
(cos(x) *x - cos(x)*sin(x) - 2*cos(y)*log(cos(x))*sin(y)  
 
          2  
  + sin(x) *x)/2  
 
int(trigsimp(sin(x+y)*cos(x-y)/tan(x)), x);  
 
                                   x  2  
(cos(x)*sin(x) - 2*cos(y)*log(tan(---)  + 1)*sin(y)  
                                   2  
 
                      x  
  + 2*cos(y)*log(tan(---))*sin(y) + x)/2  
                      2

Without the package, the integration fails, and in the second case one does not receive an answer for many hours.

trigfactorize(sin(2x)*cos(y)^2, y/2);  
 
{{2*cos(x)*sin(x),1},  
 
       y          y  
 {cos(---) - sin(---),2},  
       2          2  
 
       y          y  
 {cos(---) + sin(---),2}}  
       2          2

trigfactorize(sin(y)^4-x^2, y);  
 
        2               2  
{{sin(y)  + x,1},{sin(y)  - x,1}}  
 
trigfactorize(sin(x)*sinh(x), x/2);  
 
{{4,1},  
 
        x  
 {sinh(---),1},  
        2  
 
        x  
 {cosh(---),1},  
        2  
 
       x  
 {sin(---),1},  
       2  
 
       x  
 {cos(---),1}}  
       2  
 
triggcd(-5+cos(2x)-6sin(x), -7+cos(2x)-8sin(x), x/2);  
 
       x        x  
2*cos(---)*sin(---) + 1  
       2        2  
 
triggcd(1-2cosh(x)+cosh(2x), 1+2cosh(x)+cosh(2x), x/2);  
 
        x  2  
2*sinh(---)  + 1  
        2

Bibliography

[1]   Roach, Kelly: Difficulties with Trigonometrics. Notes of a talk.

[2]   Hearn, A.C.: COMPACT User Manual.