/** Test coefficient map function. */
  public void testMap() {
    // integers
    BigInteger rf = new BigInteger();
    // System.out.println("rf = " + rf);

    // polynomials over integral numbers
    GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf, rl);
    // System.out.println("pf = " + pf);

    // random polynomial
    GenPolynomial<BigInteger> p = pf.random(kl, 2 * ll, el, q);
    // System.out.println("p = " + p);

    // test times 1
    GenPolynomial<BigInteger> q;
    q = p.map(new Multiply<BigInteger>(rf.getONE()));
    assertEquals("p == q ", p, q);

    // test times 0
    q = p.map(new Multiply<BigInteger>(rf.getZERO()));
    assertTrue("q == 0 ", q.isZERO());

    // test times -1
    q = p.map(new Multiply<BigInteger>(rf.getONE().negate()));
    assertEquals("p == q ", p.negate(), q);
  }
Exemple #2
0
  public static void example2() {
    UnivPowerSeries<BigInteger> integers = integersFrom(0);

    System.out.print("integer coefficients = ");
    UnivPowerSeries<BigInteger> s = integers;
    for (int i = 0; i < 20; i++) {
      BigInteger c = s.leadingCoefficient();
      System.out.print(c.toString() + ", ");
      s = s.reductum();
    }
    System.out.println("...");
  }
  /** Test iterators. */
  public void testIterators() {
    // integers
    BigInteger rf = new BigInteger();
    // System.out.println("rf = " + rf);

    // polynomials over integral numbers
    GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(rf, rl);
    // System.out.println("pf = " + pf);

    // random polynomial
    GenPolynomial<BigInteger> p = pf.random(kl, 2 * ll, el, q);
    // System.out.println("p = " + p);

    // test monomials
    for (Monomial<BigInteger> m : p) {
      // System.out.println("m = " + m);
      assertFalse("m.c == 0 ", m.coefficient().isZERO());
      assertFalse("m.e < (0) ", m.exponent().signum() < 0);
    }

    // test exponents
    Iterator<ExpVector> et = p.exponentIterator();
    while (et.hasNext()) {
      ExpVector e = et.next();
      // System.out.println("e = " + e);
      assertFalse("e < (0) ", e.signum() < 0);
    }

    // test coefficents
    Iterator<BigInteger> ct = p.coefficientIterator();
    while (ct.hasNext()) {
      BigInteger i = ct.next();
      // System.out.println("i = " + i);
      assertFalse("i == 0 ", i.isZERO());
    }
  }