/*
* $Id$
*/
package edu.jas.gb;
import java.util.List;
import java.util.Map;
import edu.jas.poly.ExpVector;
import edu.jas.poly.GenPolynomial;
import edu.jas.structure.RingElem;
/**
* Polynomial Reduction sequential use algorithm. Implements normalform.
* @param coefficient type
* @author Heinz Kredel
*/
public class ReductionSeq> // should be FieldElem>
extends ReductionAbstract {
//private static final Logger logger = Logger.getLogger(ReductionSeq.class);
/**
* Constructor.
*/
public ReductionSeq() {
}
/**
* Normalform.
* @param Ap polynomial.
* @param Pp polynomial list.
* @return nf(Ap) with respect to Pp.
*/
@SuppressWarnings("unchecked")
public GenPolynomial normalform(List> Pp, GenPolynomial Ap) {
if (Pp == null || Pp.isEmpty()) {
return Ap;
}
if (Ap == null || Ap.isZERO()) {
return Ap;
}
if (!Ap.ring.coFac.isField()) {
throw new IllegalArgumentException("coefficients not from a field");
}
Map.Entry m;
int l;
GenPolynomial[] P;
synchronized (Pp) {
l = Pp.size();
P = new GenPolynomial[l];
//P = Pp.toArray();
for (int i = 0; i < Pp.size(); i++) {
P[i] = Pp.get(i);
}
}
ExpVector[] htl = new ExpVector[l];
Object[] lbc = new Object[l]; // want C[]
GenPolynomial[] p = new GenPolynomial[l];
int i;
int j = 0;
for (i = 0; i < l; i++) {
p[i] = P[i];
m = p[i].leadingMonomial();
if (m != null) {
p[j] = p[i];
htl[j] = m.getKey();
lbc[j] = m.getValue();
j++;
}
}
l = j;
ExpVector e;
C a;
boolean mt = false;
GenPolynomial R = Ap.ring.getZERO().copy();
//GenPolynomial T = null;
//GenPolynomial Q = null;
GenPolynomial S = Ap.copy();
while (S.length() > 0) {
m = S.leadingMonomial();
e = m.getKey();
a = m.getValue();
for (i = 0; i < l; i++) {
mt = e.multipleOf(htl[i]);
if (mt)
break;
}
if (!mt) {
//logger.debug("irred");
//R = R.sum( a, e );
//S = S.subtract( a, e );
R.doPutToMap(e, a);
S.doRemoveFromMap(e, a);
// System.out.println(" S = " + S);
} else {
e = e.subtract(htl[i]);
//logger.info("red div = " + e);
a = a.divide((C) lbc[i]);
//Q = p[i].multiply( a, e );
//S = S.subtract( Q );
S = S.subtractMultiple(a, e, p[i]);
}
}
return R;
}
/**
* Normalform with recording.
* @param row recording matrix, is modified.
* @param Pp a polynomial list for reduction.
* @param Ap a polynomial.
* @return nf(Pp,Ap), the normal form of Ap wrt. Pp.
*/
@SuppressWarnings("unchecked")
public GenPolynomial normalform(List> row, List> Pp,
GenPolynomial Ap) {
if (Pp == null || Pp.isEmpty()) {
return Ap;
}
if (Ap == null || Ap.isZERO()) {
return Ap;
}
if (!Ap.ring.coFac.isField()) {
throw new IllegalArgumentException("coefficients not from a field");
}
int l = Pp.size();
GenPolynomial[] P = new GenPolynomial[l];
synchronized (Pp) {
//P = Pp.toArray();
for (int i = 0; i < Pp.size(); i++) {
P[i] = Pp.get(i);
}
}
ExpVector[] htl = new ExpVector[l];
Object[] lbc = new Object[l]; // want C[]
GenPolynomial[] p = new GenPolynomial[l];
Map.Entry m;
int j = 0;
int i;
for (i = 0; i < l; i++) {
p[i] = P[i];
m = p[i].leadingMonomial();
if (m != null) {
p[j] = p[i];
htl[j] = m.getKey();
lbc[j] = m.getValue();
j++;
}
}
l = j;
ExpVector e;
C a;
boolean mt = false;
GenPolynomial zero = Ap.ring.getZERO();
GenPolynomial R = Ap.ring.getZERO().copy();
GenPolynomial fac = null;
// GenPolynomial T = null;
//GenPolynomial Q = null;
GenPolynomial S = Ap.copy();
while (S.length() > 0) {
m = S.leadingMonomial();
e = m.getKey();
a = m.getValue();
for (i = 0; i < l; i++) {
mt = e.multipleOf(htl[i]);
if (mt)
break;
}
if (!mt) {
//logger.debug("irred");
//R = R.sum( a, e );
//S = S.subtract( a, e );
R.doPutToMap(e, a);
S.doRemoveFromMap(e, a);
// System.out.println(" S = " + S);
//throw new RuntimeException("Syzygy no GB");
} else {
e = e.subtract(htl[i]);
//logger.info("red div = " + e);
C c = (C) lbc[i];
a = a.divide(c);
//Q = p[i].multiply( a, e );
//S = S.subtract( Q );
S = S.subtractMultiple(a, e, p[i]);
fac = row.get(i);
if (fac == null) {
fac = zero.sum(a, e);
} else {
fac = fac.sum(a, e);
}
row.set(i, fac);
}
}
return R;
}
}
Ads help maintain this website.