home *** CD-ROM | disk | FTP | other *** search
-
- (* Copyright 1988 Wolfram Research Inc. *)
-
- (*:Version: Mathematica 2.0 *)
-
- (*:Name: Examples`IntegerRoots` *)
-
- (*:Title: Integer Parts of Rational Roots of Integers *)
-
- (*:Author:
-
- *)
-
- (*:Keywords:
- integer, rational root, integer part
- *)
-
- (*:Requirements: none. *)
-
- (*:Warnings: none. *)
-
- (*:Sources:
-
- *)
-
- (*:Summary:
- For a given integer raised to a rational root, BreakRoots
- extracts the integral part. For example,
- BreakRoots[ 8^(1/2) ] returns 2 Sqrt[2].
- *)
-
-
- BeginPackage["Examples`IntegerRoots`"]
-
- BreakRoots::usage =
- "BreakRoots[expr] extracts the integer parts of rational roots of
- integers in expr."
-
- Begin["`Private`"]
-
- {`i};
-
- BreakRoots[expr_] := expr /. (n_Integer)^(p_Rational) :>
- FactorRoot[n, Numerator[p], Denominator[p]]
-
-
- FactorRoot[n_Integer, p_Integer, q_Integer] :=
- Block[ { nf = FactorInteger[n], ip = 1, rp = 1, t } ,
- Do[
- t = nf[[i]] ;
- ip = ip * t[[1]]^Quotient[p t[[2]], q] ;
- rp = rp * t[[1]]^Mod[p t[[2]], q] ,
- {i, Length[nf]}
- ] ;
-
- ip rp^(1/q)
- ]
-
- End[ ] (* Examples`IntegerRoots`Private` *)
-
- Protect[ BreakRoots ]
-
- EndPackage[ ] (* Examples`IntegerRoots` *)
-
- (*:Limitations: none known. *)
-
-
- (*:Examples:
-
- BreakRoots[ 2^(15/4)]
-
- *)
-
-