home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PROGRAMM.PAK / TRIGDEFI.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.2 KB  |  70 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["TrigDefine`"]
  12.  
  13. TrigDefine::usage = "TrigDefine.m defines global rules for putting
  14.     products of trigonometric functions into normal form."
  15.  
  16. Begin["`Private`"]    (* set the private context *)
  17.  
  18. (* unprotect any system functions for which rules will be defined *)
  19.  
  20. protected = Unprotect[Sin, Cos, Tan]
  21.  
  22. (* linearization *)
  23.  
  24. Sin/: Sin[x_] Cos[y_] := Sin[x+y]/2 + Sin[x-y]/2
  25. Sin/: Sin[x_] Sin[y_] := Cos[x-y]/2 - Cos[x+y]/2
  26. Cos/: Cos[x_] Cos[y_] := Cos[x+y]/2 + Cos[x-y]/2
  27.  
  28. Sin/: Sin[x_]^n_Integer?Positive := Expand[(1/2 - Cos[2x]/2) Sin[x]^(n-2)]
  29. Cos/: Cos[x_]^n_Integer?Positive := Expand[(1/2 + Cos[2x]/2) Cos[x]^(n-2)]
  30.  
  31. Protect[ Evaluate[protected] ]      (* restore protection of system symbols *)
  32.  
  33. End[]         (* end the private context *)
  34.  
  35. EndPackage[]  (* end the package context *)
  36. (*********************************************************************
  37.  
  38.         Adapted from
  39.         Roman E. Maeder: Programming in Mathematica,
  40.         Second Edition, Addison-Wesley, 1991.
  41.  
  42.  *********************************************************************)
  43.  
  44.  
  45. BeginPackage["TrigDefine`"]
  46.  
  47. TrigDefine::usage = "TrigDefine.m defines global rules for putting
  48.     products of trigonometric functions into normal form."
  49.  
  50. Begin["`Private`"]    (* set the private context *)
  51.  
  52. (* unprotect any system functions for which rules will be defined *)
  53.  
  54. protected = Unprotect[Sin, Cos, Tan]
  55.  
  56. (* linearization *)
  57.  
  58. Sin/: Sin[x_] Cos[y_] := Sin[x+y]/2 + Sin[x-y]/2
  59. Sin/: Sin[x_] Sin[y_] := Cos[x-y]/2 - Cos[x+y]/2
  60. Cos/: Cos[x_] Cos[y_] := Cos[x+y]/2 + Cos[x-y]/2
  61.  
  62. Sin/: Sin[x_]^n_Integer?Positive := Expand[(1/2 - Cos[2x]/2) Sin[x]^(n-2)]
  63. Cos/: Cos[x_]^n_Integer?Positive := Expand[(1/2 + Cos[2x]/2) Cos[x]^(n-2)]
  64.  
  65. Protect[ Evaluate[protected] ]      (* restore protection of system symbols *)
  66.  
  67. End[]         (* end the private context *)
  68.  
  69. EndPackage[]  (* end the package context *)
  70.