home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PROGRAMM.PAK / TRIGSIMP.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.5 KB  |  83 lines

  1.  
  2. (*********************************************************************
  3.  
  4.         Adapted from
  5.         Roman E. Maeder: Programming in Mathematica,
  6.         Second Edition, Addison-Wesley, 1991.
  7.  
  8.  *********************************************************************)
  9.  
  10.  
  11. BeginPackage["TrigSimplification`"]
  12.  
  13. TrigNormal::usage = "TrigNormal[e] puts expressions with trigonometric
  14.     functions into normal form."
  15.  
  16. TrigLinear::usage = "TrigLinear[e] expands products and powers of trigonometric
  17.     functions."
  18.  
  19. TrigArgument::usage = "TrigArgument[e] writes trigonometric functions of multiple
  20.     angles as products of functions of that angle."
  21.  
  22. Begin["`Private`"]
  23.  
  24. TrigCanonicalRules = {
  25.     Sin[n_?Negative x_.] :> -Sin[-n x],
  26.     Cos[n_?Negative x_.] :>  Cos[-n x],
  27.     Tan[n_?Negative x_.] :> -Tan[-n x],
  28.     Sin[n_?Negative x_ + y_] :> - Sin[-n x - y] /; OrderedQ[{x, y}],
  29.     Cos[n_?Negative x_ + y_] :>   Cos[-n x - y] /; OrderedQ[{x, y}],
  30.     Tan[n_?Negative x_ + y_] :> - Tan[-n x - y] /; OrderedQ[{x, y}]
  31. }
  32.  
  33. TrigLinearRules = {
  34.     Sin[x_] Cos[y_] :> Sin[x+y]/2 + Sin[x-y]/2,
  35.     Sin[x_] Sin[y_] :> Cos[x-y]/2 - Cos[x+y]/2,
  36.     Cos[x_] Cos[y_] :> Cos[x+y]/2 + Cos[x-y]/2,
  37.     Sin[x_]^(m1_Integer?EvenQ) :> Block[{m=Abs[m1]},
  38.      (2^(-m+1)
  39.       (Sum[(-1)^(m/2-k) Binomial[m,k] Cos[(m-2k)x], {k, 0, m/2-1}]+
  40.        Binomial[m,m/2]/2))^Sign[m1] ],
  41.  
  42.     Cos[x_]^(m1_Integer?EvenQ) :> Block[{m=Abs[m1]},
  43.      (2^(-m+1)
  44.       (Sum[Binomial[m,k] Cos[(m-2k)x], {k, 0, m/2-1}] +
  45.        Binomial[m,m/2]/2))^Sign[m1] ],
  46.  
  47.     Sin[x_]^(m1_Integer?OddQ) :> Block[{m=Abs[m1]},
  48.      (2^(-m+1)
  49.       Sum[(-1)^((m-1)/2-k)
  50.          Binomial[m,k] Sin[(m-2k)x], {k, 0, (m-1)/2}])^Sign[m1] ],
  51.  
  52.     Cos[x_]^(m1_Integer?OddQ) :> Block[{m=Abs[m1]},
  53.      (2^(-m+1)
  54.       Sum[Binomial[m,k] Cos[(m-2k)x], {k, 0, (m-1)/2}])^Sign[m1] ]
  55. }
  56.  
  57. TrigArgumentRules = {
  58.     Sin[x_ + y_] :> Sin[x] Cos[y] + Sin[y] Cos[x],
  59.     Cos[x_ + y_] :> Cos[x] Cos[y] - Sin[x] Sin[y],
  60.     Sin[n_Integer?Positive x_.] :>
  61.         Sum[ (-1)^((i-1)/2) Binomial[n, i] Cos[x]^(n-i) Sin[x]^i,
  62.             {i, 1, n, 2} ],
  63.     Cos[n_Integer?Positive x_.] :>
  64.         Sum[ (-1)^(i/2) Binomial[n, i] Cos[x]^(n-i) Sin[x]^i,
  65.             {i, 0, n, 2} ]
  66. }
  67.  
  68. SetAttributes[{TrigNormal, TrigLinear, TrigArgument}, Listable]
  69.  
  70. TrigNormal[e_] := e /. TrigCanonicalRules
  71.  
  72. TrigLinear[e_] :=
  73.     FixedPoint[ Expand[# //. TrigLinearRules /. TrigCanonicalRules]&, e ]
  74.  
  75. TrigArgument[e_] :=
  76.     Together[ FixedPoint[ (# //. TrigArgumentRules /. TrigCanonicalRules)&, e ] ]
  77.  
  78. End[]
  79.  
  80. Protect[TrigNormal, TrigLinear, TrigArgument]
  81.  
  82. EndPackage[]
  83.