01: package JSci.maths.fields;
02:
03: import JSci.maths.Complex;
04: import JSci.maths.groups.AbelianGroup;
05:
06: /**
07: * The ComplexField class encapsulates the field of complex numbers.
08: * @version 1.0
09: * @author Mark Hale
10: */
11: public final class ComplexField extends Object implements Field {
12: public static final Complex ZERO = new Complex(0.0, 0.0);
13: public static final Complex I = new Complex(0.0, 1.0);
14: public static final Complex ONE = new Complex(1.0, 0.0);
15: public static final Complex MINUS_ONE = new Complex(-1.0, 0.0);
16: public static final Complex MINUS_I = new Complex(0.0, -1.0);
17: public static final Complex HALF = new Complex(0.5, 0.0);
18: public static final Complex MINUS_HALF = new Complex(-0.5, 0.0);
19: public static final Complex HALF_I = new Complex(0.0, 0.5);
20: public static final Complex MINUS_HALF_I = new Complex(0.0, -0.5);
21: public static final Complex TWO = new Complex(2.0, 0.0);
22: public static final Complex MINUS_TWO = new Complex(-2.0, 0.0);
23: public static final Complex SQRT_HALF = new Complex(Math.sqrt(0.5),
24: 0.0);
25: public static final Complex SQRT_HALF_I = new Complex(0.0, Math
26: .sqrt(0.5));
27: public static final Complex MINUS_SQRT_HALF_I = new Complex(0.0,
28: -Math.sqrt(0.5));
29: public static final Complex PI = new Complex(Math.PI, 0.0);
30: public static final Complex PI_I = new Complex(0.0, Math.PI);
31: public static final Complex PI_2 = new Complex(Math.PI / 2.0, 0.0);
32: public static final Complex MINUS_PI_2 = new Complex(
33: -Math.PI / 2.0, 0.0);
34: public static final Complex PI_2_I = new Complex(0.0, Math.PI / 2.0);
35: public static final Complex MINUS_PI_2_I = new Complex(0.0,
36: -Math.PI / 2.0);
37:
38: private final static ComplexField _instance = new ComplexField();
39:
40: /**
41: * Constructs a field of complex numbers.
42: */
43: private ComplexField() {
44: }
45:
46: /**
47: * Constructs a field of complex numbers.
48: * Singleton.
49: */
50: public static final ComplexField getInstance() {
51: return _instance;
52: }
53:
54: /**
55: * Returns the complex number zero.
56: */
57: public AbelianGroup.Member zero() {
58: return ZERO;
59: }
60:
61: /**
62: * Returns true if the complex number is equal to zero.
63: */
64: public boolean isZero(AbelianGroup.Member g) {
65: return ZERO.equals(g);
66: }
67:
68: /**
69: * Returns true if one complex number is the negative of the other.
70: */
71: public boolean isNegative(AbelianGroup.Member a,
72: AbelianGroup.Member b) {
73: return ZERO.equals(a.add(b));
74: }
75:
76: /**
77: * Returns the complex number one.
78: */
79: public Ring.Member one() {
80: return ONE;
81: }
82:
83: /**
84: * Returns true if the complex number is equal to one.
85: */
86: public boolean isOne(Ring.Member r) {
87: return ONE.equals(r);
88: }
89:
90: /**
91: * Returns true if one complex number is the inverse of the other.
92: */
93: public boolean isInverse(Field.Member a, Field.Member b) {
94: return ONE.equals(a.multiply(b));
95: }
96: }
|