1 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 22 public class AlgebraicExtension extends FreeGroup implements RingI { 23 24 private Polynomial poly; 25 private Polynomial poly2; 26 27 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 ("The polynomial should be specified over the same base ring"); 40 if(!baseRing.equals( 42 poly.getCoeffs()[poly.getDegree()], 43 baseRing.getONE())) 44 throw new IllegalArgumentException ("poly "+poly.toString()+" should be monic"); 45 46 Number coeffs[] = new Number [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 zeroPoly = new AlgebraicExtensionElement(this,new Number []{ 78 baseRing.getZERO()}); 79 unitPoly = new AlgebraicExtensionElement(this,new Number []{ 81 baseRing.getONE()}); 82 tPoly = new AlgebraicExtensionElement(this,new Number []{ 84 baseRing.getZERO(), 85 baseRing.getONE()}); 86 } 87 88 public Number valueOf(Number coeffs[]) { 89 return new AlgebraicExtensionElement(this, coeffs); 90 } 91 92 public String toString() 93 { 94 return baseRing.toString() +poly.toString(); 95 } 96 97 98 public Polynomial getPoly() { 99 return poly; 100 } 101 102 105 public Polynomial getSubsPoly() { 106 return poly2; 107 } 108 } 109 | Popular Tags |