/*
* $Id$
*/
package edu.jas.gbufd;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import edu.jas.gb.GroebnerBaseAbstract;
import edu.jas.poly.GenPolynomial;
import edu.jas.poly.GenPolynomialRing;
import edu.jas.poly.PolyUtil;
import edu.jas.structure.GcdRingElem;
import edu.jas.ufd.PolyUfdUtil;
import edu.jas.ufd.Quotient;
import edu.jas.ufd.QuotientRing;
/**
* Groebner Base sequential algorithm for rational function coefficients,
* fraction free computation. Implements Groebner bases.
* @param Quotient coefficient type
* @author Heinz Kredel
*/
public class GroebnerBaseSeqQuotient> extends GroebnerBaseAbstract> {
private static final Logger logger = Logger.getLogger(GroebnerBaseSeqQuotient.class);
private final boolean debug = logger.isDebugEnabled();
public final GroebnerBaseAbstract> bba;
/**
* Constructor.
* @param rf quotient coefficient ring factory.
*/
public GroebnerBaseSeqQuotient(QuotientRing rf) {
super();
bba = new GroebnerBasePseudoRecSeq(rf.ring);
}
/**
* Get the String representation with GB engines.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.getClass().getSimpleName() + "(" + bba.toString() + ")";
}
/**
* Groebner base using fraction free computation.
* @param modv module variable number.
* @param F polynomial list.
* @return GB(F) a Groebner base of F.
*/
@Override
public List>> GB(int modv, List>> F) {
List>> G = F;
if (F == null || F.isEmpty()) {
return G;
}
GenPolynomialRing> rring = F.get(0).ring;
QuotientRing cf = (QuotientRing) rring.coFac;
GenPolynomialRing> iring = new GenPolynomialRing>(cf.ring, rring);
List>> Fi = PolyUfdUtil. integralFromQuotientCoefficients(iring, F);
//System.out.println("Fi = " + Fi);
logger.info("#Fi = " + Fi.size());
List>> Gi = bba.GB(modv, Fi);
//System.out.println("Gi = " + Gi);
logger.info("#Gi = " + Gi.size());
G = PolyUfdUtil. quotientFromIntegralCoefficients(rring, Gi);
G = PolyUtil.> monic(G);
return G;
}
/**
* Minimal ordered Groebner basis.
* @param Gp a Groebner base.
* @return a reduced Groebner base of Gp.
*/
@Override
public List>> minimalGB(List>> Gp) {
if (Gp == null || Gp.size() <= 1) {
return Gp;
}
// remove zero polynomials
List>> G = new ArrayList>>(Gp.size());
for (GenPolynomial> a : Gp) {
if (a != null && !a.isZERO()) { // always true in GB()
// already positive a = a.abs();
G.add(a);
}
}
if (G.size() <= 1) {
return G;
}
// remove top reducible polynomials
GenPolynomial> a;
List>> F;
F = new ArrayList>>(G.size());
while (G.size() > 0) {
a = G.remove(0);
if (red.isTopReducible(G, a) || red.isTopReducible(F, a)) {
// drop polynomial
if (debug) {
System.out.println("dropped " + a);
List>> ff;
ff = new ArrayList>>(G);
ff.addAll(F);
a = red.normalform(ff, a);
if (!a.isZERO()) {
System.out.println("error, nf(a) " + a);
}
}
} else {
F.add(a);
}
}
G = F;
if (G.size() <= 1) {
return G;
}
// reduce remaining polynomials
GenPolynomialRing> rring = G.get(0).ring;
QuotientRing cf = (QuotientRing) rring.coFac;
GenPolynomialRing> iring = new GenPolynomialRing>(cf.ring, rring);
List>> Fi = PolyUfdUtil.integralFromQuotientCoefficients(iring, F);
logger.info("#Fi = " + Fi.size());
List>> Gi = bba.minimalGB(Fi);
logger.info("#Gi = " + Gi.size());
G = PolyUfdUtil. quotientFromIntegralCoefficients(rring, Gi);
G = PolyUtil.> monic(G);
return G;
}
/**
* Cleanup and terminate ThreadPool.
*/
@Override
public void terminate() {
bba.terminate();
}
/**
* Cancel ThreadPool.
*/
@Override
public int cancel() {
return bba.cancel();
}
}
Ads help maintain this website.