001    /*
002     * $Id: HenselApprox.java 3355 2010-10-23 16:01:52Z kredel $
003     */
004    
005    package edu.jas.ufd;
006    
007    
008    import java.io.Serializable;
009    
010    import edu.jas.arith.BigInteger;
011    import edu.jas.arith.Modular;
012    import edu.jas.arith.ModularRingFactory;
013    import edu.jas.poly.GenPolynomial;
014    import edu.jas.structure.GcdRingElem;
015    
016    
017    /**
018     * Container for the approximation result from a Hensel algorithm.
019     * @author Heinz Kredel
020     * @param <MOD> coefficient type
021     */
022    
023    public class HenselApprox<MOD extends GcdRingElem<MOD> & Modular> implements Serializable {
024    
025    
026        /**
027         * Approximated polynomial with integer coefficients.
028         */
029        public final GenPolynomial<BigInteger> A;
030    
031    
032        /**
033         * Approximated polynomial with integer coefficients.
034         */
035        public final GenPolynomial<BigInteger> B;
036    
037    
038        /**
039         * Modular approximated polynomial with modular coefficients.
040         */
041        public final GenPolynomial<MOD> Am;
042    
043    
044        /**
045         * Modular approximated polynomial with modular coefficients.
046         */
047        public final GenPolynomial<MOD> Bm;
048    
049    
050        /**
051         * Constructor.
052         * @param A approximated polynomial.
053         * @param B approximated polynomial.
054         * @param Am approximated modular polynomial.
055         * @param Bm approximated modular polynomial.
056         */
057        public HenselApprox(GenPolynomial<BigInteger> A, GenPolynomial<BigInteger> B, GenPolynomial<MOD> Am,
058                GenPolynomial<MOD> Bm) {
059            this.A = A;
060            this.B = B;
061            this.Am = Am;
062            this.Bm = Bm;
063        }
064    
065    
066        /**
067         * Get the String representation.
068         * @see java.lang.Object#toString()
069         */
070        @Override
071        public String toString() {
072            StringBuffer sb = new StringBuffer();
073            sb.append(A.toString());
074            sb.append(",");
075            sb.append(B.toString());
076            sb.append(",");
077            sb.append(Am.toString());
078            sb.append(",");
079            sb.append(Bm.toString());
080            return sb.toString();
081        }
082    
083    
084        /**
085         * Get a scripting compatible string representation.
086         * @return script compatible representation for this container.
087         * @see edu.jas.structure.ElemFactory#toScript()
088         */
089        public String toScript() {
090            // Python case
091            StringBuffer sb = new StringBuffer();
092            sb.append(A.toScript());
093            sb.append(",");
094            sb.append(B.toScript());
095            sb.append(",");
096            sb.append(Am.toScript());
097            sb.append(",");
098            sb.append(Bm.toScript());
099            return sb.toString();
100        }
101    
102    
103        /**
104         * Hash code for this Factors.
105         * @see java.lang.Object#hashCode()
106         */
107        @Override
108        public int hashCode() {
109            int h = A.hashCode();
110            h = 37 * h + B.hashCode();
111            h = 37 * h + Am.hashCode();
112            h = 37 * h + Bm.hashCode();
113            return h;
114        }
115    
116    
117        /**
118         * Comparison with any other object.
119         * @see java.lang.Object#equals(java.lang.Object)
120         */
121        @Override
122        @SuppressWarnings("unchecked")
123        public boolean equals(Object B) {
124            if (!(B instanceof HenselApprox)) {
125                return false;
126            }
127            HenselApprox<MOD> a = null;
128            try {
129                a = (HenselApprox<MOD>) B;
130            } catch (ClassCastException ignored) {
131            }
132            if (a == null) {
133                return false;
134            }
135            return A.equals(a.A) && B.equals(a.B) && Am.equals(a.Am) && Bm.equals(a.Bm);
136        }
137    
138    
139        /**
140         * Get modul of modular polynomial.
141         * @return coefficient modul of polynomial mpol.
142         */
143        public BigInteger approximationSize() {
144            ModularRingFactory fac = (ModularRingFactory) Am.ring.coFac;
145            return fac.getIntegerModul();
146        }
147    
148    }