KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
12 import org.nfunk.jep.type.*;
13 import java.util.*;
14 /**
15  * A free group generated by a symbol t.
16  *
17  * @author Rich Morris
18  * Created on 09-Mar-2004
19  */

20 public class FreeGroup extends Group implements RingI {
21
22     protected RingI baseRing;
23     protected FreeGroupElement zeroPoly;
24     protected FreeGroupElement unitPoly;
25     protected FreeGroupElement tPoly; // t
26
protected String symbol;
27     protected Complex rootVal=new Complex(Double.NaN);
28
29     /**
30      * Create the ring K(t) where t is a solution of the monic polynomial p.
31      *
32      * @param baseRing the Ring this is an extension of.
33      * @param poly A monic polynomial whose solution gives an algebraic number which is used to generate this group.
34      * @throws IllegalArgumentException if the base ring of the poly is not the same.
35      * @throws IllegalArgumentException if the polynomial is not monic.
36      */

37     public FreeGroup(RingI K,String symbol) {
38         super();
39         this.symbol = symbol;
40         this.baseRing=K;
41         
42         // construct the zero poly
43
zeroPoly = new FreeGroupElement(this,new Number[]{
44                 baseRing.getZERO()});
45         // construct the unit poly
46
unitPoly = new FreeGroupElement(this,new Number[]{
47                     baseRing.getONE()});
48         // construct the polynomial t
49
tPoly = new FreeGroupElement(this,new Number[]{
50                 baseRing.getZERO(),
51                 baseRing.getONE()});
52     }
53     
54     public Number add(Number a,Number b)
55     {
56         return ((FreeGroupElement) a).add((FreeGroupElement) b);
57     }
58     public Number sub(Number a,Number b)
59     {
60         return ((FreeGroupElement) a).sub((FreeGroupElement) b);
61     }
62     public Number mul(Number a,Number b)
63     {
64         return ((FreeGroupElement) a).mul((FreeGroupElement) b);
65     }
66     public boolean equals(Number a,Number b)
67     {
68         return ((FreeGroupElement) a).equals((FreeGroupElement) b);
69     }
70
71     public Number valueOf(String s) {
72         Number coeffs[] = new Number[]{baseRing.valueOf(s)};
73         return valueOf(coeffs);
74     }
75
76     public Number valueOf(Number coeffs[]) {
77         return new FreeGroupElement(this, coeffs);
78     }
79
80     public Number getZERO() { return zeroPoly; }
81     public Number getONE() { return unitPoly; }
82     public Number getInverse(Number a) {
83         return sub(zeroPoly,(FreeGroupElement) a);
84     }
85
86     public void addStandardConstants(JEP j)
87     {
88         baseRing.addStandardConstants(j);
89         SymbolTable st = j.getSymbolTable();
90         for(Enumeration enum=st.elements();enum.hasMoreElements();)
91         {
92             Variable val = (Variable) enum.nextElement();
93             st.remove(val.getName());
94             Number num = (Number) val.getValue();
95             Number p = this.valueOf(new Number[]{
96                     num});
97             j.addConstant(val.getName(),p);
98         }
99         j.addConstant(symbol,tPoly);
100     }
101     
102     public String toString()
103     {
104         return baseRing.toString() +"["+symbol+"]";
105     }
106     
107     /** Returns the base ring of this extension. */
108     public RingI getBaseRing() {
109         return baseRing;
110     }
111
112
113     /** Sets the value used to aproximate the root as a complex number. */
114     public void setRootVal(Complex complex) {
115         rootVal = complex;
116     }
117
118     /** Returns an aproximation to the value of the root as a complex number. */
119     public Complex getRootVal() {
120         return rootVal;
121     }
122
123     /** Returns the symbol used to denote the generator. */
124     public String getSymbol() {
125         return symbol;
126     }
127
128     
129
130 }
131
Popular Tags