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