001/*
002 * $Id$
003 */
004
005package edu.jas.ufd;
006
007
008import org.apache.logging.log4j.Logger;
009import org.apache.logging.log4j.LogManager; 
010
011import edu.jas.poly.GenPolynomial;
012import edu.jas.structure.GcdRingElem;
013
014
015/**
016 * Greatest common divisor algorithms with gcd always 1. The computation is
017 * faked as the gcd is always 1.
018 * @author Heinz Kredel
019 */
020
021public class GreatestCommonDivisorFake<C extends GcdRingElem<C>> extends GreatestCommonDivisorAbstract<C> {
022
023
024    private static final Logger logger = LogManager.getLogger(GreatestCommonDivisorFake.class);
025
026
027    //private static final boolean debug = logger.isDebugEnabled();
028
029
030    /**
031     * GenPolynomial base coefficient content. Always returns 1.
032     * @param P GenPolynomial.
033     * @return cont(P).
034     */
035    @Override
036    public C baseContent(GenPolynomial<C> P) {
037        if (P == null) {
038            throw new IllegalArgumentException(this.getClass().getName() + " P != null");
039        }
040        if (P.isZERO()) {
041            return P.ring.getZEROCoefficient();
042        }
043        return P.ring.getONECoefficient();
044    }
045
046
047    /**
048     * GenPolynomial base coefficient primitive part. Always returns P.
049     * @param P GenPolynomial.
050     * @return pp(P).
051     */
052    @Override
053    public GenPolynomial<C> basePrimitivePart(GenPolynomial<C> P) {
054        if (P == null) {
055            throw new IllegalArgumentException(this.getClass().getName() + " P != null");
056        }
057        if (P.isZERO()) {
058            return P;
059        }
060        if (P.isConstant()) {
061            return P.ring.getONE();
062        }
063        if (P.length() == 1) { // one term
064            //System.out.println("P = " + P);
065            return P.ring.valueOf(P.leadingExpVector());
066        }
067        return P;
068    }
069
070
071    /**
072     * Univariate GenPolynomial greatest common divisor. Always returns 1.
073     * @param P univariate GenPolynomial.
074     * @param S univariate GenPolynomial.
075     * @return gcd(P,S).
076     */
077    @Override
078    public GenPolynomial<C> baseGcd(GenPolynomial<C> P, GenPolynomial<C> S) {
079        if (S == null || S.isZERO()) {
080            return P;
081        }
082        if (P == null || P.isZERO()) {
083            return S;
084        }
085        if (P.ring.nvar > 1) {
086            throw new IllegalArgumentException(this.getClass().getName() + " no univariate polynomial");
087        }
088        return P.ring.getONE();
089    }
090
091
092    /**
093     * GenPolynomial recursive content. Always returns 1.
094     * @param P recursive GenPolynomial.
095     * @return cont(P).
096     */
097    @Override
098    public GenPolynomial<C> recursiveContent(GenPolynomial<GenPolynomial<C>> P) {
099        if (P == null) {
100            throw new IllegalArgumentException(this.getClass().getName() + " P != null");
101        }
102        if (P.isZERO()) {
103            return P.ring.getZEROCoefficient();
104        }
105        return P.ring.getONECoefficient();
106    }
107
108
109    /**
110     * GenPolynomial recursive primitive part. Always returns P.
111     * @param P recursive GenPolynomial.
112     * @return pp(P).
113     */
114    @Override
115    public GenPolynomial<GenPolynomial<C>> recursivePrimitivePart(GenPolynomial<GenPolynomial<C>> P) {
116        if (P == null) {
117            throw new IllegalArgumentException(this.getClass().getName() + " P != null");
118        }
119        if (P.isZERO()) {
120            return P;
121        }
122        if (P.isConstant()) {
123            return P.ring.getONE();
124        }
125        if (P.length() == 1) { // one term
126            //System.out.println("P = " + P);
127            return P.ring.valueOf(P.leadingExpVector());
128        }
129        return P;
130    }
131
132
133    /**
134     * Univariate GenPolynomial recursive greatest common divisor. Always returns
135     * 1.
136     * @param P univariate recursive GenPolynomial.
137     * @param S univariate recursive GenPolynomial.
138     * @return gcd(P,S).
139     */
140    @Override
141    public GenPolynomial<GenPolynomial<C>> recursiveUnivariateGcd(GenPolynomial<GenPolynomial<C>> P,
142                    GenPolynomial<GenPolynomial<C>> S) {
143        if (S == null || S.isZERO()) {
144            return P;
145        }
146        if (P == null || P.isZERO()) {
147            return S;
148        }
149        if (P.ring.nvar > 1) {
150            throw new IllegalArgumentException(this.getClass().getName() + " no univariate polynomial");
151        }
152        logger.debug("returning 1");
153        return P.ring.getONE();
154    }
155
156}