home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / ALGEBRA.PAK / TRIGONOM.M < prev   
Encoding:
Text File  |  1992-07-29  |  5.3 KB  |  176 lines

  1.  
  2. (* Copyright 1988 Wolfram Research Inc. *)
  3.  
  4. (*:Version: Mathematica 2.0 *)
  5.  
  6. (*:Title: Trigonometric Simplifications *)
  7.  
  8. (*:Author: Roman Maeder *)
  9.  
  10. (*:Keywords:
  11.     trigonometry, simplification, reduction, expansion
  12. *)
  13.  
  14. (*:Requirements: none. *)
  15.  
  16. (*:Warnings: none. *)
  17.  
  18. (*:Summary:
  19.     This package provides all kinds of trigonometric simplifications.
  20. *)
  21.  
  22. (* import Global`, as we anticipate these routines to be called
  23.    frequently by mistake before reading the file. *)
  24.  
  25. BeginPackage["Algebra`Trigonometry`", "Global`"]
  26.  
  27. TrigCanonical::usage = "TrigCanonical[expr] is obsolete.
  28.     Its functionality is now built-in."
  29.  
  30. TrigExpand::usage = "TrigExpand[expr] is obsolete.
  31.     Its functionality is provided by Expand[expr, Trig->True]."
  32.  
  33. TrigFactor::usage = "TrigFactor[expr] tries to write sums of trigonometric
  34.     functions as products."
  35.  
  36. TrigReduce::usage = "TrigReduce[expr] writes trigonometric functions of
  37.     multiple angles as sums of products of trigonometric functions of
  38.     that angle."
  39.  
  40. TrigReduce::notes = "TrigReduce simplifies the arguments of trigonometric
  41.     functions. It is, in a way, the inverse of TrigExpand."
  42.  
  43. TrigToComplex::usage = "TrigToComplex[expr] writes trigonometric functions
  44.     in terms of complex exponentials."
  45.  
  46. ComplexToTrig::usage = "ComplexToTrig[expr] writes complex exponentials
  47.     as trigonometric functions of a real angle."
  48.  
  49.  
  50. Begin["`Private`"]
  51.  
  52. (* explicitly create all local variables to avoid name clashes,
  53.    since Global` is on the search path. *)
  54.  
  55. {`x, `y, `r, `n, `m, `a, `b, `c, `i, `e};
  56.  
  57. TrigCanonical[e_] := e
  58.  
  59. TrigExpand[___] := $Failed /;
  60.     Message[TrigExpand::obsfn, TrigExpand, Expand]
  61.  
  62. TrigExpand[e_]:=Expand[e,Trig->True]
  63.  
  64. `TrigFactorRel = {
  65.     a_. Sin[x_] + a_. Sin[y_] :> 2 a Sin[x/2+y/2] Cos[x/2-y/2],
  66.     a_. Sin[x_] + b_. Sin[y_] :> 2 a Sin[x/2-y/2] Cos[x/2+y/2] /; a+b == 0,
  67.     a_. Cos[x_] + a_. Cos[y_] :> 2 a Cos[x/2+y/2] Cos[x/2-y/2],
  68.     a_. Cos[x_] + b_. Cos[y_] :> 2 a Sin[x/2+y/2] Sin[y/2-x/2] /; a+b == 0,
  69.     a_. Tan[x_] + a_. Tan[y_] :> a Sin[x+y]/(Cos[x] Cos[y]),
  70.     a_. Tan[x_] + b_. Tan[y_] :> a Sin[x-y]/(Cos[x] Cos[y]) /; a+b == 0,
  71.  
  72.     a_. Sin[x_] Cos[y_] + a_. Sin[y_] Cos[x_] :> a Sin[x + y],
  73.     a_. Sin[x_] Cos[y_] + b_. Sin[y_] Cos[x_] :> a Sin[x - y] /; a+b == 0,
  74.     a_. Cos[x_] Cos[y_] + b_. Sin[x_] Sin[y_] :> a Cos[x + y] /; a+b == 0,
  75.     a_. Cos[x_] Cos[y_] + a_. Sin[x_] Sin[y_] :> a Cos[x - y]
  76.  
  77. }
  78. TrigFactorRel = Dispatch[TrigFactorRel]
  79. Protect[TrigFactorRel]
  80.  
  81. TrigFactor[e_] := FixedPoint[(# /. TrigFactorRel)&, e]
  82.  
  83. `TrigReduceRel = {
  84.  
  85.     (* the following two formulas are chosen to allow easy
  86.        reconstruction of TrigExpand[Sin[x]^n] or TrigExpand[Cos[x]^n].
  87.        In these cases, Sin[n x] with even n does not occur.
  88.        There we use another formula. *)
  89.  
  90.     Cos[n_Integer x_] :> 2^(n-1) Cos[x]^n +
  91.     Sum[ Binomial[n-i-1, i-1] (-1)^i n/i 2^(n-2i-1) Cos[x]^(n-2i),
  92.        {i, 1, n/2} ]        /; n > 0,
  93.  
  94.     Sin[m_Integer?OddQ x_] :>
  95.         Block[{`p = -(m^2-1)/6, `s = Sin[x], `k},
  96.           Do[s += p Sin[x]^k;
  97.                  p *= -(m^2 - k^2)/(k+2)/(k+1),
  98.                 {k, 3, m, 2}];
  99.           m s]                /; m > 0,
  100.  
  101.     Sin[n_Integer?EvenQ x_] :> 
  102.     Sum[ Binomial[n, i] (-1)^((i-1)/2) Sin[x]^i Cos[x]^(n-i),
  103.          {i, 1, n, 2} ]        /; n > 0,
  104.  
  105.     Tan[n_Integer x_] :> Sin[n x]/Cos[n x],
  106.  
  107.     Sin[x_ + y_] :> Sin[x] Cos[y] + Sin[y] Cos[x],
  108.     Cos[x_ + y_] :> Cos[x] Cos[y] - Sin[x] Sin[y],
  109.     Tan[x_ + y_] :> (Tan[x] + Tan[y])/(1 - Tan[x] Tan[y]),
  110.  
  111.     (* rational factors, "symb" does not have a value *)
  112.     Sin[r_Rational x_] :> (Sin[Numerator[r] `symb] /. TrigReduceRel /.
  113.         `symb -> x/Denominator[r])        /; Numerator[r] != 1,
  114.     Cos[r_Rational x_] :> (Cos[Numerator[r] `symb] /. TrigReduceRel /.
  115.         `symb -> x/Denominator[r])        /; Numerator[r] != 1,
  116.  
  117.     (* half angle args *)
  118.     Tan[x_/2] :> (1 - Cos[x])/Sin[x],
  119.     Cos[x_/2]^(n_Integer?EvenQ) :>
  120.                 ((1 + Cos[x])/2)^(n/2),
  121.     Sin[x_/2]^(n_Integer?EvenQ) :>
  122.                 ((1 - Cos[x])/2)^(n/2),
  123.     Sin[x_/2]^n_. Cos[x_/2]^m_. :> Tan[x/2]^n        /; m == -n,
  124.     Sin[r_ x_.] Cos[r_ x_.]    :> Sin[2 r x]/2    /; IntegerQ[2r]
  125.  
  126. }
  127. TrigReduceRel = Dispatch[TrigReduceRel]
  128.  
  129. TrigReduce[e_] := e //. TrigReduceRel
  130.  
  131. `TrigToComplexRel = {
  132.     Sin[x_] :> -I/2*(-E^(-I*x) + E^(I*x)),
  133.     Cos[x_] :>  (E^(-I*x) + E^(I*x))/2,
  134.     Tan[x_] :> (-I*(-E^(-I*x) + E^(I*x)))/(E^(-I*x) + E^(I*x)),
  135.     Csc[x_] :> (2*I)/(-E^(-I*x) + E^(I*x)),
  136.     Sec[x_] :> 2/(E^(-I*x) + E^(I*x)),
  137.     Cot[x_] :> (I*(E^(-I*x) + E^(I*x)))/(-E^(-I*x) + E^(I*x)),
  138.     Si[x_]  :> -I/2(ExpIntegralE[1, I x] - ExpIntegralE[1, -I x]) + Pi/2,
  139.     Ci[x_]  :> -1/2(ExpIntegralE[1, I x] + ExpIntegralE[1, -I x])
  140. }
  141. TrigToComplexRel = Dispatch[TrigToComplexRel]
  142.  
  143. TrigToComplex[e_] := e //. TrigToComplexRel
  144.  
  145. `ComplexToTrigRel = {
  146.     Exp[a_ b_Plus] :> Exp[Expand[a b]],
  147.     Exp[c_Complex x_. + y_.] :> Exp[Re[c] x + y] (Cos[Im[c] x] + I Sin[Im[c] x])
  148. }
  149. ComplexToTrigRel = Dispatch[ComplexToTrigRel]
  150.  
  151. ComplexToTrig[e_] := Cancel[e //. ComplexToTrigRel]
  152.  
  153. End[]   (* Algebra`Trigonometry`Private` *)
  154.  
  155. Protect[ TrigCanonical, TrigExpand, TrigFactor, TrigReduce,
  156.      TrigToComplex, ComplexToTrig ]
  157.  
  158. EndPackage[]   (* Algebra`Trigonometry` *)
  159.  
  160. (*:Limitations: none known. *)
  161.  
  162.  
  163. (*:Examples:
  164.  
  165. TrigExpand[ Sin[x]^2 ]
  166.  
  167. TrigFactor[ Sin[x] + Sin[y] ]
  168.  
  169. TrigReduce[ Sin[5 x] ]
  170.  
  171. TrigToComplex[ Cos[x] ]
  172.  
  173. ComplexToTrig[ Exp[I] ]
  174.  
  175. *)
  176.