示例#1
0
 /**
  * Sign changes on interval bounds.
  *
  * @param iv root isolating interval with f(left) * f(right) != 0.
  * @param f univariate polynomial.
  * @return true if f(left) * f(right) < 0, else false
  */
 public boolean signChange(Interval<C> iv, GenPolynomial<C> f) {
   if (f == null) {
     return false;
   }
   RingFactory<C> cfac = f.ring.coFac;
   C l = PolyUtil.<C>evaluateMain(cfac, f, iv.left);
   C r = PolyUtil.<C>evaluateMain(cfac, f, iv.right);
   return l.signum() * r.signum() < 0;
 }
示例#2
0
文件: Quotient.java 项目: rjolly/jas
 // JAVA6only: @Override
 public int compareTo(Quotient<C> b) {
   if (b == null || b.isZERO()) {
     return this.signum();
   }
   C r = num.multiply(b.den);
   C s = den.multiply(b.num);
   C x = r.subtract(s);
   return x.signum();
 }
示例#3
0
 /**
  * Count changes in sign.
  *
  * @param <C> coefficient type.
  * @param L list of coefficients.
  * @return number of sign changes in L.
  */
 public static <C extends RingElem<C>> long signVar(List<C> L) {
   long v = 0;
   if (L == null || L.isEmpty()) {
     return v;
   }
   C A = L.get(0);
   for (int i = 1; i < L.size(); i++) {
     C B = L.get(i);
     while (B == null || B.signum() == 0) {
       i++;
       if (i >= L.size()) {
         return v;
       }
       B = L.get(i);
     }
     if (A.signum() * B.signum() < 0) {
       v++;
     }
     A = B;
   }
   return v;
 }
示例#4
0
 /**
  * Real algebraic number sign.
  *
  * @param iv root isolating interval for f, with f(left) * f(right) &lt; 0, with iv such that
  *     g(iv) != 0.
  * @param f univariate polynomial, non-zero.
  * @param g univariate polynomial, gcd(f,g) == 1.
  * @return sign(g(iv)) .
  */
 public int realIntervalSign(Interval<C> iv, GenPolynomial<C> f, GenPolynomial<C> g) {
   if (g == null || g.isZERO()) {
     return 0;
   }
   if (f == null || f.isZERO() || f.isConstant()) {
     return g.signum();
   }
   if (g.isConstant()) {
     return g.signum();
   }
   RingFactory<C> cfac = f.ring.coFac;
   C c = iv.left.sum(iv.right);
   c = c.divide(cfac.fromInteger(2));
   C ev = PolyUtil.<C>evaluateMain(cfac, g, c);
   // System.out.println("ev = " + ev);
   return ev.signum();
 }
示例#5
0
文件: Quotient.java 项目: rjolly/jas
 /**
  * The constructor creates a Quotient object from a ring factory and a numerator and denominator
  * element.
  *
  * @param r ring factory.
  * @param n numerator.
  * @param d denominator.
  * @param isred true if gcd(n,d) == 1, else false.
  */
 @SuppressWarnings("unchecked")
 protected Quotient(QuotientRing<C> r, C n, C d, boolean isred) {
   if (d == null || d.isZERO()) {
     throw new IllegalArgumentException("denominator may not be zero");
   }
   ring = r;
   if (d.signum() < 0) {
     n = n.negate();
     d = d.negate();
   }
   if (isred) {
     num = n;
     den = d;
     return;
   }
   // must reduce to lowest terms
   if (n instanceof GcdRingElem && d instanceof GcdRingElem) {
     GcdRingElem ng = (GcdRingElem) n;
     GcdRingElem dg = (GcdRingElem) d;
     C gcd = (C) ng.gcd(dg);
     if (debug) {
       logger.info("gcd = " + gcd);
     }
     // RingElem<C> gcd = ring.ring.getONE();
     if (gcd.isONE()) {
       num = n;
       den = d;
     } else {
       num = n.divide(gcd);
       den = d.divide(gcd);
     }
     // } else { // univariate polynomial?
   } else {
     logger.warn("gcd = ????");
     num = n;
     den = d;
   }
 }
示例#6
0
文件: Quotient.java 项目: rjolly/jas
 /**
  * Quotient signum.
  *
  * @see edu.jas.structure.RingElem#signum()
  * @return signum(this).
  */
 public int signum() {
   return num.signum();
 }