home *** CD-ROM | disk | FTP | other *** search
-
-
- (*:Version: Mathematica 2.0 *)
-
- (*:Name: NumberTheory`Recognize` *)
-
- (*:Title: Recognition of Polynomials *)
-
- (*:Author: Daniel R. Grayson *)
-
- (*:Keywords:
- Polynomial, Degree
- *)
-
- (*:Requirements: none. *)
-
- (*:Warnings:
- Trouble with bignum:
-
- In[5]:= Recognize[ 902589045298.90329599084,10,t]
-
- Out[5]= 1
-
- In[6]:= Recognize[ 902589045298.90329599084,15,t]
-
- Out[6]= 1
-
- *)
-
- (*:Sources:
-
- *)
-
- (*:Summary: This package allows you to find the minimal polynomial of
- which a given approximate number is a root.
- *)
-
- BeginPackage["NumberTheory`Recognize`"]
-
- Recognize::usage = "Recognize[x,n,t] finds a polynomial of degree at
- most n in the variable t which is satisfied by the number x.
- Recognize[x,n,t,k] also finds a polynomial of degree at most n
- in the variable t, but with a penalty of weight k against
- higher degree polynomials. k must be a nonnegative integer."
- Begin["`Private`"]
-
- Recognize[x_, n_Integer?Positive, t_Symbol, k_Integer:0] :=
- Block[{data, i, scale},
- If[IntegerQ[x] || ! NumberQ[x], Message[Recognize::nodec],
- data = Table[x^i, {i, 0, n}];
- data = Round[data 10^Max[Accuracy /@ Rest[data]]];
- scale = Table[(k+1)^i, {i, 0, n}];
- data = Transpose[ Append[ DiagonalMatrix[scale], data ]];
- data = Drop[LatticeReduce[data][[1]], -1];
- Table[t^i, {i, 0, n}] . (data/scale)
- ]
- ]
-
-
- Recognize::nodec = "Not a decimal number."
-
- End[ ] (* NumberTheory`Recognize`Private` *)
-
- Protect[ Recognize ]
-
- EndPackage[ ] (* NumberTheory`Recognize` *)
-
- (*:Limitations: none known. *)
-
-
- (*:Examples:
-
- Recognize[1.17,3,t]
-
- Recognize[984.945,10,t,3]
-
-
- *)
-
-
-
-