Example #1
0
 /**
  * Real root bound. With f(M) * f(-M) != 0.
  *
  * @param f univariate polynomial.
  * @return M such that -M < root(f) < M.
  */
 public C realRootBound(GenPolynomial<C> f) {
   if (f == null) {
     return null;
   }
   RingFactory<C> cfac = f.ring.coFac;
   C M = cfac.getONE();
   if (f.isZERO() || f.isConstant()) {
     return M;
   }
   C a = f.leadingBaseCoefficient().abs();
   for (C c : f.getMap().values()) {
     C d = c.abs().divide(a);
     if (M.compareTo(d) < 0) {
       M = d;
     }
   }
   // works also without this case, only for optimization
   // to use rational number interval end points
   // can fail if real root is in interval [r,r+1]
   // for too low precision or too big r, since r is approximation
   if ((Object) M instanceof RealAlgebraicNumber) {
     RealAlgebraicNumber Mr = (RealAlgebraicNumber) M;
     BigRational r = Mr.magnitude();
     M = cfac.fromInteger(r.numerator()).divide(cfac.fromInteger(r.denominator()));
   }
   M = M.sum(f.ring.coFac.getONE());
   // System.out.println("M = " + M);
   return M;
 }
Example #2
0
 /**
  * Quotient summation.
  *
  * @param S Quotient.
  * @return this+S.
  */
 public Quotient<C> sum(Quotient<C> S) {
   if (S == null || S.isZERO()) {
     return this;
   }
   C n = num.multiply(S.den);
   n = n.sum(den.multiply(S.num));
   C d = den.multiply(S.den);
   return new Quotient<C>(ring, n, d, false);
 }
Example #3
0
  public static void main(String args[]) {
    System.out.println("Inheritance Main");

    A a = new A();
    A b = new B();
    A c = new C();

    // B a1 = new A();
    B b1 = new B();
    B c1 = new C();

    // C a2 = new A();
    // C b2 = new B();
    C c2 = new C();

    System.out.println(a.hashCode());
    a.sum();
    a.sub();

    System.out.println(b.hashCode());
    b.sum();
    b.sub();

    System.out.println(c.hashCode());
    c.sum();
    c.sub();

    System.out.println(b1.hashCode());
    b1.sum();
    b1.sub();

    System.out.println(c1.hashCode());
    c1.sum();
    c1.sub();

    System.out.println(c2.hashCode());
    c2.sum();
    c2.sub();
  }
Example #4
0
 public C eval(C c1, C c2) {
   return c1.sum(c2);
 }