/*
 * $Id$
 */

package edu.jas.ufd;


import java.io.Serializable;
import java.util.List;

import edu.jas.poly.AlgebraicNumberRing;
import edu.jas.poly.GenPolynomial;
import edu.jas.structure.GcdRingElem;


/**
 * Container for the factors of a squarefree factorization.
 * @author Heinz Kredel
 * @param  coefficient type
 */

public class FactorsList> implements Serializable {


    /**
     * Original polynomial to be factored with coefficients from C.
     */
    public final GenPolynomial poly;


    /**
     * List of factors with coefficients from C.
     */
    public final List> factors;


    /**
     * List of factors with coefficients from AlgebraicNumberRings.
     */
    public final List> afactors;


    /**
     * Constructor.
     * @param p given GenPolynomial over C.
     * @param list irreducible factors of p with coefficients from C.
     */
    public FactorsList(GenPolynomial p, List> list) {
        this(p, list, null);
    }


    /**
     * Constructor.
     * @param p given GenPolynomial over C.
     * @param list irreducible factors of p with coefficients from C.
     * @param alist irreducible factors of p with coefficients from an algebraic
     *            number field.
     */
    public FactorsList(GenPolynomial p, List> list, List> alist) {
        poly = p;
        factors = list;
        afactors = alist;
    }


    /**
     * Get the String representation.
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        //sb.append(poly.toString());
        //sb.append(" =\n");
        boolean first = true;
        for (GenPolynomial p : factors) {
            if (first) {
                first = false;
            } else {
                sb.append(",\n ");
            }
            sb.append(p.toString());
        }
        if (afactors == null) {
            return sb.toString();
        }
        for (Factors f : afactors) {
            if (first) {
                first = false;
            } else {
                sb.append(",\n ");
            }
            sb.append(f.toString());
        }
        return sb.toString();
    }


    /**
     * Get a scripting compatible string representation.
     * @return script compatible representation for this container.
     * @see edu.jas.structure.ElemFactory#toScript()
     */
    public String toScript() {
        // Python case
        StringBuffer sb = new StringBuffer();
        sb.append(poly.toScript());
        sb.append(" =\n");
        boolean first = true;
        for (GenPolynomial p : factors) {
            if (first) {
                first = false;
            } else {
                sb.append("\n * ");
            }
            sb.append(p.toScript());
        }
        if (afactors == null) {
            return sb.toString();
        }
        for (Factors f : afactors) {
            if (first) {
                first = false;
            } else {
                sb.append("\n * ");
            }
            sb.append(f.toScript());
        }
        return sb.toString();
    }


    /**
     * Find largest extension field.
     * @return largest extension field or null if no extension field
     */
    public AlgebraicNumberRing findExtensionField() {
        if (afactors == null) {
            return null;
        }
        AlgebraicNumberRing ar = null;
        int depth = 0;
        for (Factors f : afactors) {
            AlgebraicNumberRing aring = f.findExtensionField();
            if (aring == null) {
                continue;
            }
            int d = aring.depth();
            if (d > depth) {
                depth = d;
                ar = aring;
            }
        }
        return ar;
    }

}

 

Ads help maintain this website.