home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e031 / 3.ddi / MATHZIP2 / STARTUP / EXPAND.M < prev    next >
Encoding:
Text File  |  1991-09-23  |  1.7 KB  |  54 lines

  1.  
  2. (* ****************************************************************
  3. *
  4. *     Expand.m
  5. *
  6. **************************************************************** *)
  7.  
  8. Begin["System`"]
  9.  
  10. Unprotect[ExpandAll,ExpandDenominator,ExpandNumerator,PowerExpand]
  11.  
  12. ExpandAll::usage="ExpandAll[expr] expands out all products and integer powers
  13. in any part of expr. ExpandAll[expr, patt] avoids expanding parts of expr
  14. which do not contain terms matching the pattern patt."
  15.  
  16. ExpandDenominator::usage="ExpandDenominator[expr] expands out products
  17. and powers that appear as denominators in expr."
  18.  
  19. ExpandNumerator::usage="ExpandNumerator[expr] expands out products and
  20. powers that appear in the numerator of expr."
  21.  
  22. PowerExpand::usage="PowerExpand[expr] expands nested powers, powers of
  23. products, logarithms of powers, and logarithms of products.  Use PowerExpand
  24. with caution because PowerExpand does not pay attention to branch cuts."
  25.  
  26. Begin["System`Private`"]
  27.  
  28. ExpandAll[input_,options___]:=
  29.   MapAll[Expand[ExpandDenominator[#,options],options]&,input]
  30.  
  31. ExpandDenominator[input_,options___]:=
  32.   If[SameQ[Head[input],Plus],
  33.      Map[ExpandDenominator[#,options]&,input],
  34.      Numerator[input]/Expand[Denominator[input],options]]
  35.  
  36. ExpandNumerator[input_,options___]:=
  37.   If[SameQ[Head[input],Plus],
  38.      Map[ExpandNumerator[#,options]&,input],
  39.      Expand[Numerator[input],options]/Denominator[input]]
  40.      
  41. PowerExpand[expr_]:=
  42.   expr//.{(a_*b_)^c_:>a^c*b^c,
  43.           (a_^b_)^c_:>a^(b*c),
  44.       Log[a_^b_]:>b*Log[a],
  45.       Log[a_*b_]:>Log[a]+Log[b],
  46.       Log[Rational[a_,b_]]:>Log[a]-Log[b]}
  47.  
  48. End[]
  49.  
  50. Protect[ExpandAll,ExpandDenominator,ExpandNumerator,PowerExpand]
  51.  
  52. End[]
  53.  
  54.