1 2\subsection{Introduction} 3 4The \REDUCE{} package TRIGSIMP is a useful tool for all kinds of 5problems related to trigonometric and hyperbolic simplification and 6factorization. There are three operators included in TRIGSIMP: 7trigsimp, trigfactorize and triggcd. The first is for simplifying 8trigonometric or hyperbolic expressions and has many options, the 9second is for factorizing them and the third is for finding the 10greatest common divisor of two trigonometric or hyperbolic 11polynomials. This package is automatically loaded when one of these 12operators is used. 13 14 15\subsection{Simplifying trigonometric expressions} 16\ttindex{TRIGSIMP} 17 18As there is no normal form for trigonometric and hyperbolic 19expressions, the same function can convert in many different 20directions, e.g.\ $\sin(2x) \leftrightarrow 2\sin(x)\cos(x)$. The 21user has the possibility to give several parameters to the operator 22\texttt{trigsimp} in order to influence the transformations. It is 23possible to decide whether or not a rational expression involving 24trigonometric and hyperbolic functions vanishes. 25 26To simplify an expression \texttt{f}, one uses 27\texttt{trigsimp(f[,options])}. For example: 28\begin{verbatim} 29trigsimp(sin(x)^2+cos(x)^2); 30 311 32\end{verbatim} 33The possible options (where $^*$ denotes the default) are: 34\begin{enumerate} 35\item \texttt{sin}$^*$ or \texttt{cos}; 36\item \texttt{sinh}$^*$ or \texttt{cosh}; 37\item \texttt{expand}$^*$, \texttt{combine} or \texttt{compact}; 38\item \texttt{hyp}, \texttt{trig} or \texttt{expon}; 39\item \texttt{keepalltrig}; 40\item \texttt{tan} and/or \texttt{tanh}; 41\item target arguments of the form \textit{variable} / 42\textit{positive integer}. 43\end{enumerate} 44From each of the first four groups one can use at most one option, 45otherwise an error message will occur. Options can be given in any 46order. 47 48The first group fixes the preference used while transforming a 49trigonometric expression: 50\begin{verbatim} 51trigsimp(sin(x)^2); 52 53 2 54sin(x) 55 56trigsimp(sin(x)^2, cos); 57 58 2 59 - cos(x) + 1 60\end{verbatim} 61The second group is the equivalent for the hyperbolic functions. 62 63The third group determines the type of transformation. With the 64default, \texttt{expand}, an expression is transformed to use only 65simple variables as arguments: 66\begin{verbatim} 67trigsimp(sin(2x+y)); 68 69 2 702*cos(x)*cos(y)*sin(x) - 2*sin(x) *sin(y) + sin(y) 71\end{verbatim} 72With \texttt{combine}, products of trigonometric functions are 73transformed to trig\-onometric functions involving sums of variables: 74\begin{verbatim} 75trigsimp(sin(x)*cos(y), combine); 76 77 sin(x - y) + sin(x + y) 78------------------------- 79 2 80\end{verbatim} 81With \texttt{compact}, the \REDUCE{} operator \texttt{compact} 82\cite{Hearn:COMPACT} is applied to \texttt{f}. This often leads to a simple 83form, but in contrast to \texttt{expand} one does not get a normal 84form. For example: 85\begin{verbatim} 86trigsimp((1-sin(x)^2)^20*(1-cos(x)^2)^20, compact); 87 88 40 40 89cos(x) *sin(x) 90\end{verbatim} 91 92With an option from the fourth group, the input expression is 93transformed to trigonometric, hyperbolic or exponential form 94respectively: 95\begin{verbatim} 96trigsimp(sin(x), hyp); 97 98 - sinh(i*x)*i 99 100trigsimp(sinh(x), expon); 101 102 2*x 103 e - 1 104---------- 105 x 106 2*e 107 108trigsimp(e^x, trig); 109 110cos(i*x) - sin(i*x)*i 111\end{verbatim} 112 113Usually, \texttt{tan}, \texttt{cot}, \texttt{sec}, \texttt{csc} are 114expressed in terms of \texttt{sin} and \texttt{cos}. It can sometimes 115be useful to avoid this, which is handled by the option 116\texttt{keepalltrig}: 117\begin{verbatim} 118trigsimp(tan(x+y), keepalltrig); 119 120 - (tan(x) + tan(y)) 121---------------------- 122 tan(x)*tan(y) - 1 123\end{verbatim} 124Alternatively, the options \texttt{tan} and/or \texttt{tanh} can be 125given to convert the output to the specified form as far as possible: 126\begin{verbatim} 127trigsimp(tan(x+y), tan); 128 129 - (tan(x) + tan(y)) 130---------------------- 131 tan(x)*tan(y) - 1 132\end{verbatim} 133By default, the other functions used will be \texttt{cos} and/or 134\texttt{cosh}, unless the other desired functions are also specified 135in which case this choice will be respected. 136 137The final possibility is to specify additional target arguments for 138the trigonometric or hyperbolic functions, each of which should have 139the form of a variable divided by a positive integer. These 140additional arguments are treated as if they had occurred within the 141expression to be simplified, and their denominators are used in 142determining the overall denominator to use for each variable in the 143simplified form: 144\begin{verbatim} 145trigsimp(csc x - cot x + csc y - cot y, x/2, y/2, tan); 146 147 x y 148tan(---) + tan(---) 149 2 2 150\end{verbatim} 151 152It is possible to use the options of different groups simultaneously: 153\begin{verbatim} 154trigsimp(sin(x)^4, cos, combine); 155 156 cos(4*x) - 4*cos(2*x) + 3 157--------------------------- 158 8 159\end{verbatim} 160 161Sometimes, it is necessary to handle an expression in separate steps: 162\begin{verbatim} 163trigsimp((sinh(x)+cosh(x))^n+(cosh(x)-sinh(x))^n, expon); 164 165 1 n n*x 166(----) + e 167 x 168 e 169 170trigsimp(ws, hyp); 171 1722*cosh(n*x) 173 174trigsimp((cosh(a*n)*sinh(a)*sinh(p)+cosh(a)*sinh(a*n)*sinh(p)+ 175 sinh(a - p)*sinh(a*n))/sinh(a)); 176 177cosh(a*n)*sinh(p) + cosh(p)*sinh(a*n) 178 179trigsimp(ws, combine); 180 181sinh(a*n + p) 182\end{verbatim} 183 184The \texttt{trigsimp} operator can be applied to equations, lists and 185matrices (and compositions thereof) as well as scalar expressions, and 186automatically maps itself recursively over such non-scalar data 187structures: 188\begin{verbatim} 189trigsimp( { sin(2x) = cos(2x) } ); 190 191 2 192{2*cos(x)*sin(x)= - 2*sin(x) + 1} 193\end{verbatim} 194 195 196\subsection{Factorizing trigonometric expressions} 197 198With \texttt{trigfactorize(p,x)} one can factorize the trigonometric 199or hyperbolic polynomial \texttt{p} in terms of trigonometric 200functions of the argument \texttt{x}. The output has the same format 201as that from the standard \REDUCE{} operator \texttt{factorize}. For 202example: 203\begin{verbatim} 204trigfactorize(sin(x), x/2); 205 206 x x 207{{2,1},{sin(---),1},{cos(---),1}} 208 2 2 209\end{verbatim} 210If the polynomial is not coordinated or balanced \cite{Roach:Talk}, the 211output will equal the input. In this case, changing the value for 212\texttt{x} can help to find a factorization, e.g. 213\begin{verbatim} 214trigfactorize(1+cos(x), x); 215 216{{cos(x) + 1,1}} 217 218trigfactorize(1+cos(x), x/2); 219 220 x 221{{2,1},{cos(---),2}} 222 2 223\end{verbatim} 224The polynomial can consist of both trigonometric and hyperbolic functions: 225\begin{verbatim} 226trigfactorize(sin(2x)*sinh(2x), x); 227 228{{4,1}, {sinh(x),1}, {cosh(x),1}, {sin(x),1}, {cos(x),1}} 229\end{verbatim} 230 231The \texttt{trigfactorize} operator respects the standard \REDUCE{} 232\texttt{factorize} switch \texttt{nopowers} -- see the \REDUCE{} 233manual for details. Turning it on gives the behaviour that was 234standard before \REDUCE~3.7: 235\begin{verbatim} 236on nopowers; 237 238trigfactorize(1+cos(x), x/2); 239 240 x x 241{2,cos(---),cos(---)} 242 2 2 243\end{verbatim} 244 245 246\subsection{GCDs of trigonometric expressions} 247 248The operator \texttt{triggcd} is essentially an application of the 249algorithm behind \texttt{trigfactorize}. With its help the user can 250find the greatest common divisor of two trigonometric or hyperbolic 251polynomials. It uses the method described in \cite{Roach:Talk}. The syntax 252is \texttt{triggcd(p,q,x)}, where \texttt{p} and \texttt{q} are the 253trigonometric polynomials and \texttt{x} is the argument to use. For 254example: 255\begin{verbatim} 256triggcd(sin(x), 1+cos(x), x/2); 257 258 x 259cos(---) 260 2 261 262triggcd(sin(x), 1+cos(x), x); 263 2641 265\end{verbatim} 266The polynomials $p$ and $q$ can consist of both trigonometric and 267hyperbolic functions: 268\begin{verbatim} 269triggcd(sin(2x)*sinh(2x), (1-cos(2x))*(1+cosh(2x)), x); 270 271cosh(x)*sin(x) 272\end{verbatim} 273 274 275\subsection{Further Examples} 276 277With the help of this package the user can create identities: 278\begin{verbatim} 279trigsimp(tan(x)*tan(y)); 280 281 sin(x)*sin(y) 282--------------- 283 cos(x)*cos(y) 284 285trigsimp(ws, combine); 286\end{verbatim} 287 288{\samepage 289\begin{verbatim} 290 cos(x - y) - cos(x + y) 291------------------------- 292 cos(x - y) + cos(x + y) 293\end{verbatim}} 294 295\begin{verbatim} 296trigsimp((sin(x-a)+sin(x+a))/(cos(x-a)+cos(x+a))); 297 298 sin(x) 299-------- 300 cos(x) 301 302trigsimp(cosh(n*acosh(x))-cos(n*acos(x)), trig); 303 3040 305 306trigsimp(sec(a-b), keepalltrig); 307 308 csc(a)*csc(b)*sec(a)*sec(b) 309------------------------------- 310 csc(a)*csc(b) + sec(a)*sec(b) 311 312trigsimp(tan(a+b), keepalltrig); 313 314 - (tan(a) + tan(b)) 315---------------------- 316 tan(a)*tan(b) - 1 317 318trigsimp(ws, keepalltrig, combine); 319 320tan(a + b) 321\end{verbatim} 322 323Some difficult expressions can be simplified: 324\begin{verbatim} 325df(sqrt(1+cos(x)), x, 4); 326 327 5 4 3 2 3 328( - 4*cos(x) - 4*cos(x) - 20*cos(x) *sin(x) + 12*cos(x) 329 330 2 2 2 4 331 - 24*cos(x) *sin(x) + 20*cos(x) - 15*cos(x)*sin(x) 332 333 2 4 2 334 + 12*cos(x)*sin(x) + 8*cos(x) - 15*sin(x) + 16*sin(x) )/ 335 336(16*sqrt(cos(x) + 1) 337 338 4 3 2 339 *(cos(x) + 4*cos(x) + 6*cos(x) + 4*cos(x) + 1)) 340 341on rationalize; 342trigsimp(ws); 343 344 sqrt(cos(x) + 1) 345------------------ 346 16 347 348off rationalize; 349load_package taylor; 350 351taylor(sin(x+a)*cos(x+b), x, 0, 4); 352 353cos(b)*sin(a) + (cos(a)*cos(b) - sin(a)*sin(b))*x 354 355 2 356 - (cos(a)*sin(b) + cos(b)*sin(a))*x 357 358 2*( - cos(a)*cos(b) + sin(a)*sin(b)) 3 359 + --------------------------------------*x 360 3 361 362 cos(a)*sin(b) + cos(b)*sin(a) 4 5 363 + -------------------------------*x + O(x ) 364 3 365 366trigsimp(ws, combine); 367 368 sin(a - b) + sin(a + b) 2 369------------------------- + cos(a + b)*x - sin(a + b)*x 370 2 371 372 2*cos(a + b) 3 sin(a + b) 4 5 373 - --------------*x + ------------*x + O(x ) 374 3 3 375\end{verbatim} 376 377Certain integrals whose evaluation was not possible in \REDUCE{} 378(without preprocessing) are now computable: 379\begin{verbatim} 380int(trigsimp(sin(x+y)*cos(x-y)*tan(x)), x); 381 382 2 383(cos(x) *x - cos(x)*sin(x) - 2*cos(y)*log(cos(x))*sin(y) 384 385 2 386 + sin(x) *x)/2 387 388int(trigsimp(sin(x+y)*cos(x-y)/tan(x)), x); 389 390 x 2 391(cos(x)*sin(x) - 2*cos(y)*log(tan(---) + 1)*sin(y) 392 2 393 394 x 395 + 2*cos(y)*log(tan(---))*sin(y) + x)/2 396 2 397\end{verbatim} 398Without the package, the integration fails, and in the second case one 399does not receive an answer for many hours. 400 401\begin{verbatim} 402trigfactorize(sin(2x)*cos(y)^2, y/2); 403 404{{2*cos(x)*sin(x),1}, 405 406 y y 407 {cos(---) - sin(---),2}, 408 2 2 409 410 y y 411 {cos(---) + sin(---),2}} 412 2 2 413\end{verbatim} 414\begin{verbatim} 415trigfactorize(sin(y)^4-x^2, y); 416 417 2 2 418{{sin(y) + x,1},{sin(y) - x,1}} 419 420trigfactorize(sin(x)*sinh(x), x/2); 421 422{{4,1}, 423 424 x 425 {sinh(---),1}, 426 2 427 428 x 429 {cosh(---),1}, 430 2 431 432 x 433 {sin(---),1}, 434 2 435 436 x 437 {cos(---),1}} 438 2 439 440triggcd(-5+cos(2x)-6sin(x), -7+cos(2x)-8sin(x), x/2); 441 442 x x 4432*cos(---)*sin(---) + 1 444 2 2 445 446triggcd(1-2cosh(x)+cosh(2x), 1+2cosh(x)+cosh(2x), x/2); 447 448 x 2 4492*sinh(---) + 1 450 2 451\end{verbatim} 452 453