01: package JSci.maths.polynomials;
02:
03: import JSci.maths.Complex;
04: import JSci.maths.MathDouble;
05: import JSci.maths.fields.Field;
06: import JSci.maths.fields.Ring;
07: import JSci.maths.groups.AbelianGroup;
08:
09: /**
10: *
11: * @author b.dietrich
12: */
13: public class ComplexPolynomialRing implements JSci.maths.fields.Ring {
14: private static final ComplexPolynomial ZERO = new ComplexPolynomial(
15: new Complex[] { Complex.ZERO });
16: private static final ComplexPolynomial ONE = new ComplexPolynomial(
17: new Complex[] { Complex.ONE });
18: private static final ComplexPolynomialRing _instance = new ComplexPolynomialRing();
19:
20: /** Creates a new instance of ComplexPolynomialRing */
21: protected ComplexPolynomialRing() {
22: }
23:
24: /**
25: * Singleton.
26: */
27: public static final ComplexPolynomialRing getInstance() {
28: return _instance;
29: }
30:
31: /** Returns true if one member is the negative of the other.
32: * @param a a group member
33: * @param b a group member
34: *
35: */
36: public boolean isNegative(AbelianGroup.Member a,
37: AbelianGroup.Member b) {
38: return a.add(b).equals(ZERO);
39: }
40:
41: /** Returns true if the member is the unit element.
42: *
43: */
44: public boolean isOne(Ring.Member r) {
45: return r.equals(ONE);
46: }
47:
48: /** Returns true if the member is the identity element of this group.
49: * @param g a group member
50: *
51: */
52: public boolean isZero(AbelianGroup.Member g) {
53: return g.equals(ZERO);
54: }
55:
56: /** Returns the unit element.
57: *
58: */
59: public Ring.Member one() {
60: return ONE;
61: }
62:
63: /** Returns the identity element.
64: *
65: */
66: public AbelianGroup.Member zero() {
67: return ZERO;
68: }
69:
70: /**
71: * Internal method for typesafe cast
72: *
73: */
74: protected static Complex[] toComplex(Field.Member[] f) {
75: Complex[] _c = null;
76: if (f == null) {
77: _c = new Complex[] { Complex.ZERO };
78: }
79: if (f.length == 0) {
80: _c = new Complex[] { Complex.ZERO };
81: } else {
82: _c = new Complex[f.length];
83: for (int k = 0; k < _c.length; k++) {
84: if (f[k] instanceof Complex) {
85: _c[k] = (Complex) f[k];
86: } else if (f[k] instanceof MathDouble) {
87: _c[k] = new Complex(((MathDouble) f[k]).value(), 0.);
88: } else {
89: throw new IllegalArgumentException(
90: "Different fields. Argument was " + f[k]);
91: }
92: }
93: }
94:
95: return _c;
96: }
97: }
|