001/* 002 * $Id: AlgebraicRootsPrimElem.java 5579 2016-08-14 17:48:18Z kredel $ 003 */ 004 005package edu.jas.application; 006 007 008import java.io.Serializable; 009import java.util.List; 010 011import edu.jas.arith.Rational; 012import edu.jas.poly.AlgebraicNumberRing; 013import edu.jas.poly.AlgebraicNumber; 014import edu.jas.poly.GenPolynomial; 015import edu.jas.poly.Complex; 016import edu.jas.root.AlgebraicRoots; 017import edu.jas.root.RealAlgebraicNumber; 018import edu.jas.root.ComplexAlgebraicNumber; 019import edu.jas.structure.GcdRingElem; 020 021 022/** 023 * Container for the real and complex algebraic roots of a univariate 024 * polynomial together with primitive element. 025 * @param <C> coefficient type. 026 * @author Heinz Kredel 027 */ 028public class AlgebraicRootsPrimElem<C extends GcdRingElem<C> & Rational> 029 extends AlgebraicRoots<C> implements Serializable { 030 031 032 /** 033 * Primitive Element algebraic roots. 034 */ 035 public final PrimitiveElement<C> pelem; 036 037 038 /** 039 * Roots of unity of primitive element origin representations. 040 */ 041 public final List<AlgebraicNumber<C>> runit; 042 043 044 /** 045 * Constructor not for use. 046 */ 047 protected AlgebraicRootsPrimElem() { 048 throw new IllegalArgumentException("do not use this constructor"); 049 } 050 051 052 /** 053 * Constructor. 054 * @param p univariate polynomial 055 * @param cp univariate polynomial with compelx coefficients 056 * @param r list of real algebraic roots 057 * @param c list of complex algebraic roots 058 * @param pe primitive element 059 * @param ru roots of unity of primitive element origin representations 060 */ 061 public AlgebraicRootsPrimElem(GenPolynomial<C> p, GenPolynomial<Complex<C>> cp, 062 List<RealAlgebraicNumber<C>> r, 063 List<ComplexAlgebraicNumber<C>> c, 064 PrimitiveElement<C> pe, List<AlgebraicNumber<C>> ru) { 065 super(p, cp, r, c); 066 this.pelem = pe; 067 this.runit = ru; 068 } 069 070 071 /** 072 * Constructor. 073 * @param ar algebraic roots container 074 * @param pe primitive element 075 */ 076 public AlgebraicRootsPrimElem(AlgebraicRoots<C> ar, PrimitiveElement<C> pe) { 077 this(ar.p, ar.cp, ar.real, ar.complex, pe, null); 078 } 079 080 081 /** 082 * Constructor. 083 * @param ar algebraic roots container 084 * @param pe primitive element 085 * @param ru roots of unity of primitive element origin representations 086 */ 087 public AlgebraicRootsPrimElem(AlgebraicRoots<C> ar, PrimitiveElement<C> pe, List<AlgebraicNumber<C>> ru) { 088 this(ar.p, ar.cp, ar.real, ar.complex, pe, ru); 089 } 090 091 092 /** 093 * String representation of AlgebraicRootsPrimElem. 094 * @see java.lang.Object#toString() 095 */ 096 @Override 097 public String toString() { 098 if (runit == null) { 099 return super.toString(); 100 } 101 return super.toString() + ", " + runit.toString(); 102 //return "[" + p + ", real=" + real + ", complex=" + complex + ", " + pelem + "]"; 103 } 104 105 106 /** 107 * Get a scripting compatible string representation. 108 * @return script compatible representation for this Interval. 109 */ 110 public String toScript() { 111 // any case 112 StringBuffer sb = new StringBuffer(super.toScript()); 113 if (runit == null) { 114 return sb.toString(); 115 } 116 sb.append(" ["); 117 boolean first = true; 118 for (AlgebraicNumber<C> a : runit) { 119 if (first) { 120 first = false; 121 } else { 122 sb.append(", "); 123 } 124 sb.append(a.toScript()); 125 } 126 sb.append("] "); 127 return sb.toString(); 128 } 129 130 131 /** 132 * Get a scripting compatible string representation. 133 * @return script compatible representation for this Interval. 134 */ 135 public String toDecimalScript() { 136 // any case 137 return super.toDecimalScript(); 138 } 139 140 141 /** 142 * Copy this. 143 * @return a copy of this. 144 */ 145 public AlgebraicRootsPrimElem<C> copy() { 146 return new AlgebraicRootsPrimElem<C>(p, cp, real, complex, pelem, runit); 147 } 148 149 150 /** 151 * Comparison with any other object. 152 * @see java.lang.Object#equals(java.lang.Object) 153 */ 154 @Override 155 @SuppressWarnings("unchecked") 156 public boolean equals(Object b) { 157 if (!(b instanceof AlgebraicRootsPrimElem)) { 158 return false; 159 } 160 AlgebraicRootsPrimElem<C> a = null; 161 try { 162 a = (AlgebraicRootsPrimElem<C>) b; 163 } catch (ClassCastException e) { 164 return false; 165 } 166 // && cp.equals(a.cp) 167 return super.equals(a); 168 } 169 170 171 /** 172 * Hash code for this AlgebraicRootsPrimElem. 173 * @see java.lang.Object#hashCode() 174 */ 175 @Override 176 public int hashCode() { 177 return super.hashCode(); //(161 * p.hashCode() + 37) * real.hashCode() + complex.hashCode(); 178 } 179 180}