/*
* $Id$
*/
package edu.jas.gbufd;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import edu.jas.arith.BigInteger;
import edu.jas.arith.BigRational;
import edu.jas.gb.GroebnerBaseAbstract;
import edu.jas.poly.GenPolynomial;
import edu.jas.poly.GenPolynomialRing;
import edu.jas.poly.PolyUtil;
/**
* Groebner Base sequential algorithm for rational coefficients, fraction free
* computation. Implements Groebner bases.
* @param BigRational coefficient type
* @author Heinz Kredel
*/
public class GroebnerBaseRational extends GroebnerBaseAbstract {
private static final Logger logger = Logger.getLogger(GroebnerBaseRational.class);
private final boolean debug = logger.isDebugEnabled();
public final GroebnerBaseAbstract bba;
/**
* Constructor.
*/
public GroebnerBaseRational() {
super();
bba = new GroebnerBasePseudoSeq(new BigInteger());
}
/**
* Constructor.
*/
public GroebnerBaseRational(int threads) {
super();
bba = new GroebnerBasePseudoParallel(threads,new BigInteger());
}
/**
* 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;
BigInteger cf = new BigInteger();
GenPolynomialRing iring = new GenPolynomialRing(cf, rring);
List> Fi = PolyUtil.integerFromRationalCoefficients(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 = PolyUtil. fromIntegerCoefficients(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;
BigInteger cf = new BigInteger();
GenPolynomialRing iring = new GenPolynomialRing(cf, rring);
List> Fi = PolyUtil.integerFromRationalCoefficients(iring, F);
logger.info("#Fi = " + Fi.size());
List> Gi = bba.minimalGB(Fi);
logger.info("#Gi = " + Gi.size());
G = PolyUtil. fromIntegerCoefficients(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.