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