
edu.jas.gbufd.GroebnerBasePseudoRecSeq Maven / Gradle / Ivy
The newest version!
/*
* $Id: GroebnerBasePseudoRecSeq.java 4179 2012-09-09 10:45:58Z kredel $
*/
package edu.jas.gbufd;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.apache.log4j.Logger;
import edu.jas.gb.GroebnerBaseAbstract;
import edu.jas.gb.OrderedPairlist;
import edu.jas.gb.Pair;
import edu.jas.poly.GenPolynomial;
import edu.jas.poly.GenPolynomialRing;
import edu.jas.structure.GcdRingElem;
import edu.jas.structure.RingFactory;
import edu.jas.ufd.GCDFactory;
import edu.jas.ufd.GreatestCommonDivisorAbstract;
/**
* Groebner Base with pseudo reduction sequential algorithm for integral
* function coefficients. Implements polynomial fraction free coefficients
* Groebner bases.
* @param base coefficient type
* @author Heinz Kredel
*
* @see edu.jas.application.GBAlgorithmBuilder
* @see edu.jas.gbufd.GBFactory
*/
public class GroebnerBasePseudoRecSeq> extends
GroebnerBaseAbstract> {
private static final Logger logger = Logger.getLogger(GroebnerBasePseudoRecSeq.class);
private final boolean debug = logger.isDebugEnabled();
/**
* Greatest common divisor engine for coefficient content and primitive
* parts.
*/
protected final GreatestCommonDivisorAbstract engine;
/**
* Pseudo reduction engine.
*/
protected final PseudoReduction> red;
/**
* Coefficient ring factory.
*/
protected final RingFactory> cofac;
/**
* Base coefficient ring factory.
*/
protected final RingFactory baseCofac;
/**
* Constructor.
* @param rf coefficient ring factory.
*/
public GroebnerBasePseudoRecSeq(RingFactory> rf) {
this(new PseudoReductionSeq>(), rf);
}
/**
* Constructor.
* @param red pseudo reduction engine.
* @param rf coefficient ring factory. Note: red must be an instance
* of PseudoReductionSeq.
*/
public GroebnerBasePseudoRecSeq(PseudoReduction> red, RingFactory> rf) {
super(red);
this.red = red;
cofac = rf;
GenPolynomialRing rp = (GenPolynomialRing) cofac;
baseCofac = rp.coFac;
//engine = (GreatestCommonDivisorAbstract)GCDFactory.getImplementation( baseCofac );
//not used:
engine = GCDFactory. getProxy(baseCofac);
}
/**
* Groebner base using pairlist class.
* @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) {
GenPolynomial> p;
List>> G = new ArrayList>>();
OrderedPairlist> pairlist = null;
int l = F.size();
ListIterator>> it = F.listIterator();
while (it.hasNext()) {
p = it.next();
if (p.length() > 0) {
p = engine.recursivePrimitivePart(p); //p.monic();
p = p.abs();
if (p.isConstant()) {
G.clear();
G.add(p);
return G; // since no threads are activated
}
G.add(p);
if (pairlist == null) {
pairlist = new OrderedPairlist>(modv, p.ring);
}
// putOne not required
pairlist.put(p);
} else {
l--;
}
}
if (l <= 1) {
return G; // since no threads are activated
}
Pair> pair;
GenPolynomial> pi;
GenPolynomial> pj;
GenPolynomial> S;
GenPolynomial> H;
while (pairlist.hasNext()) {
pair = pairlist.removeNext();
if (pair == null)
continue;
pi = pair.pi;
pj = pair.pj;
if (debug) {
logger.debug("pi = " + pi);
logger.debug("pj = " + pj);
}
S = red.SPolynomial(pi, pj);
if (S.isZERO()) {
pair.setZero();
continue;
}
if (debug) {
logger.debug("ht(S) = " + S.leadingExpVector());
}
H = red.normalform(G, S);
if (H.isZERO()) {
pair.setZero();
continue;
}
if (debug) {
logger.debug("ht(H) = " + H.leadingExpVector());
}
H = engine.recursivePrimitivePart(H); //H.monic();
H = H.abs();
if (H.isConstant()) {
G.clear();
G.add(H);
return G; // since no threads are activated
}
if (debug) {
logger.debug("H = " + H);
}
if (H.length() > 0) {
l++;
G.add(H);
pairlist.put(H);
}
}
logger.debug("#sequential list = " + G.size());
G = minimalGB(G);
logger.info("" + pairlist);
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;
}
Collections.reverse(G); // important for lex GB
// reduce remaining polynomials
int len = G.size();
int i = 0;
while (i < len) {
a = G.remove(0);
//System.out.println("doing " + a.length());
a = red.normalform(G, a);
a = engine.recursivePrimitivePart(a); //a.monic(); was not required
a = a.abs();
//a = red.normalform( F, a );
G.add(a); // adds as last
i++;
}
return G;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy