KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > groupJep > groups > AlgebraicExtension


1 /* @author rich
2  * Created on 09-Mar-2004
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.groupJep.groups;
9 import org.lsmp.djep.groupJep.interfaces.*;
10 import org.lsmp.djep.groupJep.values.*;
11 import org.nfunk.jep.type.*;
12
13 /**
14  * An Algebraic Extension of a Ring.
15  * The ring generated by {1,t,...,t^n-1} where t is an algebraic number
16  * i.e t is be a root of a monic polynomial equation.
17  *
18  * @see AlgebraicExtensionElement
19  * @author Rich Morris
20  * Created on 09-Mar-2004
21  */

22 public class AlgebraicExtension extends FreeGroup implements RingI {
23
24     private Polynomial poly;
25     private Polynomial poly2;
26
27     /**
28      * Create the ring K(t) where t is a solution of the monic polynomial p.
29      *
30      * @param baseRing the Ring this is an extension of.
31      * @param poly A monic polynomial whose solution gives an algebraic number which is used to generate this group.
32      * @throws IllegalArgumentException if the base ring of the poly is not the same.
33      * @throws IllegalArgumentException if the polynomial is not monic.
34      */

35     public AlgebraicExtension(RingI K, Polynomial poly) {
36         super(K,poly.getSymbol());
37         this.poly = poly;
38         if(baseRing != poly.getBaseRing())
39             throw new IllegalArgumentException JavaDoc("The polynomial should be specified over the same base ring");
40         // test for monic
41
if(!baseRing.equals(
42             poly.getCoeffs()[poly.getDegree()],
43             baseRing.getONE()))
44             throw new IllegalArgumentException JavaDoc("poly "+poly.toString()+" should be monic");
45         
46         // construct q = t^n - poly (deg n-1)
47
Number JavaDoc coeffs[] = new Number JavaDoc[poly.getDegree()];
48         for(int i=0;i<poly.getDegree();++i)
49             coeffs[i]= baseRing.getInverse(poly.getCoeffs()[i]);
50         poly2 = new Polynomial(baseRing,poly.getSymbol(),coeffs);
51         
52         if(poly.getDegree()==2)
53         {
54             double b = poly.getCoeffs()[1].doubleValue();
55             double c = poly.getCoeffs()[0].doubleValue();
56             double det = b*b-4*c;
57             if(det<0)
58                 rootVal = new Complex(-b/2,Math.sqrt(-det)/2);
59             else
60                 rootVal = new Complex(-b/2+Math.sqrt(det)/2);
61         }
62         else
63         {
64             boolean flag = true;
65             for(int i=1;i<poly.getDegree();++i)
66                 if(!baseRing.equals(poly.getCoeffs()[i],baseRing.getZERO()))
67                 { flag = false; break; }
68             if(flag)
69             {
70                 double a0 = poly.getCoeffs()[0].doubleValue();
71                 Complex z = new Complex(-a0);
72                 rootVal = z.power(1.0/poly.getDegree());
73             }
74         }
75
76         // construct the zero poly
77
zeroPoly = new AlgebraicExtensionElement(this,new Number JavaDoc[]{
78                     baseRing.getZERO()});
79         // construct the unit poly
80
unitPoly = new AlgebraicExtensionElement(this,new Number JavaDoc[]{
81                     baseRing.getONE()});
82         // construct the polynomial t
83
tPoly = new AlgebraicExtensionElement(this,new Number JavaDoc[]{
84                     baseRing.getZERO(),
85                     baseRing.getONE()});
86     }
87     
88     public Number JavaDoc valueOf(Number JavaDoc coeffs[]) {
89         return new AlgebraicExtensionElement(this, coeffs);
90     }
91     
92     public String JavaDoc toString()
93     {
94         return baseRing.toString() +poly.toString();
95     }
96     
97     /** Returns the polynomial defining the algebraic number. */
98     public Polynomial getPoly() {
99         return poly;
100     }
101
102     /** Returns the polynomial -a_(n-1) t^(n-1) + ... + a_0.
103      * This polynomial is used in reducing the equation t^n
104      */

105     public Polynomial getSubsPoly() {
106         return poly2;
107     }
108 }
109
Popular Tags