001/*
002 * $Id: GreatestCommonDivisorFake.java 5682 2017-01-01 16:48:55Z kredel $
003 */
004
005package edu.jas.fd;
006
007
008import org.apache.log4j.Logger;
009
010import edu.jas.poly.GenPolynomial;
011import edu.jas.poly.GenSolvablePolynomial;
012import edu.jas.structure.GcdRingElem;
013import edu.jas.structure.RingFactory;
014
015
016/**
017 * (Non-unique) factorization domain greatest common divisor common algorithms
018 * with monic polynomial remainder sequence. Fake implementation always returns
019 * 1 for any gcds.
020 * @param <C> coefficient type
021 * @author Heinz Kredel
022 */
023
024public class GreatestCommonDivisorFake<C extends GcdRingElem<C>> extends GreatestCommonDivisorAbstract<C> {
025
026
027    private static final Logger logger = Logger.getLogger(GreatestCommonDivisorFake.class);
028
029
030    //private static final boolean debug = true; //logger.isDebugEnabled();
031
032
033    /**
034     * Constructor.
035     * @param cf coefficient ring.
036     */
037    public GreatestCommonDivisorFake(RingFactory<C> cf) {
038        super(cf);
039    }
040
041
042    /**
043     * Univariate GenSolvablePolynomial greatest common divisor. Uses
044     * pseudoRemainder for remainder.
045     * @param P univariate GenSolvablePolynomial.
046     * @param S univariate GenSolvablePolynomial.
047     * @return 1 = gcd(P,S) with P = P'*gcd(P,S) and S = S'*gcd(P,S).
048     */
049    @Override
050    public GenSolvablePolynomial<C> leftBaseGcd(GenSolvablePolynomial<C> P, GenSolvablePolynomial<C> S) {
051        if (S == null || S.isZERO()) {
052            return P;
053        }
054        if (P == null || P.isZERO()) {
055            return S;
056        }
057        if (P.ring.nvar > 1) {
058            throw new IllegalArgumentException(this.getClass().getName() + " no univariate polynomial");
059        }
060        logger.warn("fake gcd always returns 1");
061        return P.ring.getONE();
062    }
063
064
065    /**
066     * Univariate GenSolvablePolynomial right greatest common divisor. Uses
067     * pseudoRemainder for remainder.
068     * @param P univariate GenSolvablePolynomial.
069     * @param S univariate GenSolvablePolynomial.
070     * @return 1 = gcd(P,S) with P = gcd(P,S)*P' and S = gcd(P,S)*S'.
071     */
072    @Override
073    public GenSolvablePolynomial<C> rightBaseGcd(GenSolvablePolynomial<C> P, GenSolvablePolynomial<C> S) {
074        if (S == null || S.isZERO()) {
075            return P;
076        }
077        if (P == null || P.isZERO()) {
078            return S;
079        }
080        if (P.ring.nvar > 1) {
081            throw new IllegalArgumentException(this.getClass().getName() + " no univariate polynomial");
082        }
083        logger.warn("fake gcd always returns 1");
084        return P.ring.getONE();
085    }
086
087
088    /**
089     * Univariate GenSolvablePolynomial left recursive greatest common divisor.
090     * Uses pseudoRemainder for remainder.
091     * @param P univariate recursive GenSolvablePolynomial.
092     * @param S univariate recursive GenSolvablePolynomial.
093     * @return 1 = gcd(P,S) with P = P'*gcd(P,S)*p and S = S'*gcd(P,S)*s, where
094     *         deg_main(p) = deg_main(s) == 0.
095     */
096    @Override
097    public GenSolvablePolynomial<GenPolynomial<C>> leftRecursiveUnivariateGcd(
098                    GenSolvablePolynomial<GenPolynomial<C>> P, GenSolvablePolynomial<GenPolynomial<C>> S) {
099        if (S == null || S.isZERO()) {
100            return P;
101        }
102        if (P == null || P.isZERO()) {
103            return S;
104        }
105        if (P.ring.nvar > 1) {
106            throw new IllegalArgumentException("no univariate polynomial");
107        }
108        return P.ring.getONE();
109    }
110
111
112    /**
113     * Univariate GenSolvablePolynomial right recursive greatest common divisor.
114     * Uses pseudoRemainder for remainder.
115     * @param P univariate recursive GenSolvablePolynomial.
116     * @param S univariate recursive GenSolvablePolynomial.
117     * @return 1 = gcd(P,S) with P = p*gcd(P,S)*P' and S = s*gcd(P,S)*S', where
118     *         deg_main(p) = deg_main(s) == 0.
119     */
120    @Override
121    public GenSolvablePolynomial<GenPolynomial<C>> rightRecursiveUnivariateGcd(
122                    GenSolvablePolynomial<GenPolynomial<C>> P, GenSolvablePolynomial<GenPolynomial<C>> S) {
123        if (S == null || S.isZERO()) {
124            return P;
125        }
126        if (P == null || P.isZERO()) {
127            return S;
128        }
129        if (P.ring.nvar > 1) {
130            throw new IllegalArgumentException("no univariate polynomial");
131        }
132        return P.ring.getONE();
133    }
134
135}