001/*
002 * $Id$
003 */
004
005package edu.jas.application;
006
007
008import java.io.Serializable;
009import java.util.List;
010import java.util.ArrayList;
011
012import edu.jas.poly.GenPolynomial;
013import edu.jas.structure.GcdRingElem;
014
015
016/**
017 * Container for Ideals together with univariate polynomials.
018 * @author Heinz Kredel
019 */
020public class IdealWithUniv<C extends GcdRingElem<C>> implements Serializable {
021
022
023    /**
024     * The ideal.
025     */
026    public final Ideal<C> ideal;
027
028
029    /**
030     * The list of univariate polynomials. Contains polynomials from several
031     * rings, depending on the stage of the decomposition. 1) polynomials in a
032     * ring of one variable, 2) polynomials depending on only one variable but
033     * in a ring with multiple variables, 3) after contraction to a non-zero
034     * dimensional ring multivariate polynomials depending on one significant
035     * variable and multiple variables from the quotient coefficients.
036     */
037    public final List<GenPolynomial<C>> upolys;
038
039
040    /**
041     * A list of other useful polynomials. 1) field extension polynomials, 2)
042     * generators for infinite quotients.
043     */
044    public final List<GenPolynomial<C>> others;
045
046
047    /**
048     * Constructor not for use.
049     */
050    protected IdealWithUniv() {
051        throw new IllegalArgumentException("do not use this constructor");
052    }
053
054
055    /**
056     * Constructor.
057     * @param id the ideal
058     * @param up the list of univariate polynomials
059     */
060    protected IdealWithUniv(Ideal<C> id, List<GenPolynomial<C>> up) {
061        this(id, up, null);
062    }
063
064
065    /**
066     * Constructor.
067     * @param id the ideal
068     * @param up the list of univariate polynomials
069     * @param og the list of other polynomials
070     */
071    protected IdealWithUniv(Ideal<C> id, List<GenPolynomial<C>> up, List<GenPolynomial<C>> og) {
072        ideal = id;
073        upolys = up;
074        others = og;
075    }
076
077
078    /**
079     * String representation of the ideal.
080     * @see java.lang.Object#toString()
081     */
082    @Override
083    public String toString() {
084        String s = ideal.toString();
085        if (upolys != null) {
086            s += "\nunivariate polynomials:\n" + upolys.toString();
087        }
088        if (others == null) {
089            return s;
090        }
091        return s + "\nother polynomials:\n" + others.toString();
092    }
093
094
095    /**
096     * Get a scripting compatible string representation.
097     * @return script compatible representation for this Element.
098     * @see edu.jas.structure.Element#toScript()
099     */
100    public String toScript() {
101        // Python case
102        String s = ideal.toScript();
103        if (upolys != null) {
104            s += ", upolys=" + upolys.toString();
105        }
106        if (others == null) {
107            return s;
108        }
109        return s + ", others=" + others.toString();
110    }
111
112
113    /**
114     * Get list of ideals from list of ideals with univariates.
115     * @param Bl list of ideals with univariate polynomials
116     * @return list of ideals
117     */
118    public static <C extends GcdRingElem<C>>
119           List<Ideal<C>> asListOfIdeals(List<IdealWithUniv<C>> Bl) {
120        List<Ideal<C>> L = new ArrayList<Ideal<C>>(Bl.size());
121        if (Bl.size() == 0) {
122            return L;
123        }
124        for (IdealWithUniv<C> B : Bl) {
125            if (B == null) {
126                continue;
127            }
128            Ideal<C> I = B.ideal;
129            L.add(I);
130        }
131        return L;
132    }
133
134}