1 package JSci.maths.polynomials; 2 3 import JSci.maths.Complex; 4 import JSci.maths.MathDouble; 5 import JSci.maths.fields.Field; 6 import JSci.maths.fields.Ring; 7 import JSci.maths.groups.AbelianGroup; 8 9 10 14 public class ComplexPolynomialRing implements JSci.maths.fields.Ring { 15 private static final ComplexPolynomial ZERO = 16 new ComplexPolynomial( new Complex[] { Complex.ZERO } ); 17 private static final ComplexPolynomial ONE = 18 new ComplexPolynomial( new Complex[] { Complex.ONE } ); 19 private static final ComplexPolynomialRing _instance = new ComplexPolynomialRing(); 20 21 22 protected ComplexPolynomialRing() { 23 } 24 25 28 public static final ComplexPolynomialRing getInstance() { 29 return _instance; 30 } 31 32 37 public boolean isNegative( AbelianGroup.Member a, AbelianGroup.Member b ) { 38 return a.add( b ).equals( ZERO ); 39 } 40 41 44 public boolean isOne( Ring.Member r ) { 45 return r.equals( ONE ); 46 } 47 48 52 public boolean isZero( AbelianGroup.Member g ) { 53 return g.equals( ZERO ); 54 } 55 56 59 public Ring.Member one() { 60 return ONE; 61 } 62 63 66 public AbelianGroup.Member zero() { 67 return ZERO; 68 } 69 70 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 ( "Different fields. Argument was " + f[k] ); 90 } 91 } 92 } 93 94 return _c; 95 } 96 } 97 | Popular Tags |