/*
* $Id$
*/
package edu.jas.ps;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.apache.log4j.Logger;
import edu.jas.structure.RingElem;
import edu.jas.poly.ExpVector;
/**
* Standard Base sequential algorithm. Implements Standard bases and GB test.
* Note: Currently the term order is fixed to the order defined by the
* iterator over exponent vectors ExpVectorIterator.
* @param coefficient type
* @author Heinz Kredel
*/
public class StandardBaseSeq>
/*todo: extends StandardBaseAbstract*/{
private static final Logger logger = Logger.getLogger(StandardBaseSeq.class);
private final boolean debug = logger.isDebugEnabled();
/**
* Reduction engine.
*/
public final ReductionSeq red;
/**
* Constructor.
*/
public StandardBaseSeq() {
//super();
this(new ReductionSeq());
}
/**
* Constructor.
* @param red Reduction engine
*/
public StandardBaseSeq(ReductionSeq red) {
this.red = red; //super(red);
}
/**
* Standard base test.
* @param F power series list.
* @return true, if F is a Standard base, else false.
*/
public boolean isSTD(List> F) {
return isSTD(0, F);
}
/**
* Standard base test.
* @param modv module variable number.
* @param F power series list.
* @return true, if F is a Standard base, else false.
*/
public boolean isSTD(int modv, List> F) {
if (F == null) {
return true;
}
MultiVarPowerSeries pi, pj, s, h;
for (int i = 0; i < F.size(); i++) {
pi = F.get(i);
for (int j = i + 1; j < F.size(); j++) {
pj = F.get(j);
if (!red.moduleCriterion(modv, pi, pj)) {
continue;
}
// if ( ! red.criterion4( pi, pj ) ) {
// continue;
// }
s = red.SPolynomial(pi, pj);
if (s.isZERO()) {
continue;
}
h = red.normalform(F, s);
if (!h.isZERO()) {
System.out.println("pi = " + pi + ", pj = " + pj);
System.out.println("s = " + s + ", h = " + h);
return false;
}
}
}
return true;
}
/**
* Standard base using pairlist class.
* @param F power series list.
* @return STD(F) a Standard base of F.
*/
public List> STD(List> F) {
return STD(0, F);
}
/**
* Standard base using pairlist class.
* @param modv module variable number.
* @param F power series list.
* @return STD(F) a Standard base of F.
*/
public List> STD(int modv, List> F) {
MultiVarPowerSeries p = null;
List> G = new ArrayList>();
OrderedPairlist pairlist = null;
int l = F.size();
ListIterator> it = F.listIterator();
while (it.hasNext()) {
p = it.next();
if (!p.isZERO()) {
//p = p.monic();
if (p.isUnit()) {
G.clear();
G.add(p);
return G; // since no threads are activated
}
G.add(p);
if (pairlist == null) {
pairlist = new OrderedPairlist(modv, p.ring);
if (!p.ring.coFac.isField()) {
throw new IllegalArgumentException("coefficients not from a field");
}
}
// putOne not required
pairlist.put(p);
} else {
l--;
}
}
if (l <= 1) {
return G; // since no threads are activated
}
Pair pair;
MultiVarPowerSeries pi;
MultiVarPowerSeries pj;
MultiVarPowerSeries S;
MultiVarPowerSeries H;
while (pairlist.hasNext()) {
pair = pairlist.removeNext();
//logger.debug("pair = " + pair);
if (pair == null) {
continue;
}
pi = pair.pi;
pj = pair.pj;
if ( /*false &&*/debug) {
logger.debug("pi = " + pi);
logger.debug("pj = " + pj);
}
S = red.SPolynomial(pi, pj);
//S.setTruncate(p.ring.truncate()); // ??
if (S.isZERO()) {
pair.setZero();
continue;
}
if (logger.isInfoEnabled()) {
ExpVector es = S.orderExpVector();
logger.info("ht(S) = " + es.toString(S.ring.vars) + ", " + es); // + ", S = " + S);
}
//long t = System.currentTimeMillis();
H = red.normalform(G, S);
if (H.isZERO()) {
pair.setZero();
continue;
}
//t = System.currentTimeMillis() - t;
//System.out.println("time = " + t);
if (logger.isInfoEnabled()) {
ExpVector eh = H.orderExpVector();
logger.info("ht(H) = " + eh.toString(S.ring.vars) + ", " + eh); // + ", coeff(HT(H)) = " + H.coefficient(eh));
}
//H = H.monic();
if (H.isUnit()) {
G.clear();
G.add(H);
return G; // since no threads are activated
}
if (logger.isDebugEnabled()) {
logger.info("H = " + H);
}
//if (!H.isZERO()) {
l++;
G.add(H);
pairlist.put(H);
//}
}
logger.debug("#sequential list = " + G.size());
G = minimalSTD(G);
logger.info("" + pairlist);
return G;
}
/**
* Minimal ordered Standard basis.
* @param Gp a Standard base.
* @return a minimal Standard base of Gp, not auto reduced.
*/
public List> minimalSTD(List> Gp) {
if (Gp == null || Gp.size() <= 1) {
return Gp;
}
// remove zero power series
List> G = new ArrayList>(Gp.size());
for (MultiVarPowerSeries a : Gp) {
if (a != null && !a.isZERO()) { // always true in GB()
// make positive a = a.abs(); ?
a = a.monic();
G.add(a);
}
}
if (G.size() <= 1) {
return G;
}
// remove top reducible power series
MultiVarPowerSeries a;
List> F = new ArrayList>(G.size());
while (G.size() > 0) {
a = G.remove(0);
if (red.isTopReducible(G, a) || red.isTopReducible(F, a)) {
// drop power series
if (debug) {
System.out.println("dropped " + a);
List> 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;
// power series not reduced
return G;
}
}
Ads help maintain this website.