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

  1.  
  2. (* Copyright 1988 Wolfram Research Inc. *)
  3.  
  4. (*:Version: Mathematica 2.0 *)
  5.  
  6. (*:Name: Examples`IntegerRoots` *)
  7.  
  8. (*:Title: Integer Parts of Rational Roots of Integers *)
  9.  
  10. (*:Author:
  11.  
  12. *)
  13.  
  14. (*:Keywords:
  15.     integer, rational root, integer part
  16. *)
  17.  
  18. (*:Requirements: none. *)
  19.  
  20. (*:Warnings: none. *)
  21.  
  22. (*:Sources:
  23.  
  24. *)
  25.  
  26. (*:Summary:
  27.     For a given integer raised to a rational root, BreakRoots
  28.     extracts the integral part.  For example,
  29.     BreakRoots[ 8^(1/2) ] returns 2 Sqrt[2].
  30. *)
  31.  
  32.  
  33. BeginPackage["Examples`IntegerRoots`"]
  34.  
  35. BreakRoots::usage =
  36.     "BreakRoots[expr] extracts the integer parts of rational roots of
  37.     integers in expr."
  38.  
  39. Begin["`Private`"]
  40.  
  41. {`i};
  42.  
  43. BreakRoots[expr_] := expr /. (n_Integer)^(p_Rational) :> 
  44.                                 FactorRoot[n, Numerator[p], Denominator[p]]
  45.  
  46.  
  47. FactorRoot[n_Integer, p_Integer, q_Integer] :=
  48.         Block[ { nf = FactorInteger[n], ip = 1, rp = 1, t } ,
  49.                 Do[ 
  50.                         t = nf[[i]] ;
  51.                         ip = ip * t[[1]]^Quotient[p t[[2]], q] ; 
  52.                         rp = rp * t[[1]]^Mod[p t[[2]], q] , 
  53.                 {i, Length[nf]}  
  54.                 ] ; 
  55.  
  56.         ip rp^(1/q)
  57.         ] 
  58.  
  59. End[ ]  (* Examples`IntegerRoots`Private` *)
  60.  
  61. Protect[ BreakRoots ]
  62.  
  63. EndPackage[ ]   (* Examples`IntegerRoots` *)
  64.  
  65. (*:Limitations: none known. *)
  66.  
  67.  
  68. (*:Examples:
  69.  
  70. BreakRoots[ 2^(15/4)]
  71.  
  72. *)
  73.  
  74.