Пример #1
0
  public static void example13() {
    BigRational fac = new BigRational();
    UnivPowerSeriesRing<BigRational> pfac = new UnivPowerSeriesRing<BigRational>(fac, 11, "y");
    UnivPowerSeries<BigRational> exp = pfac.getEXP();
    System.out.println("exp = " + exp);
    System.out.println("exp(1) = " + exp.evaluate(fac.getONE()));
    System.out.println("exp(0) = " + exp.evaluate(fac.getZERO()));

    BigDecimal dfac = new BigDecimal();
    UnivPowerSeriesRing<BigDecimal> dpfac = new UnivPowerSeriesRing<BigDecimal>(dfac, 11, "z");
    UnivPowerSeries<BigDecimal> dexp = dpfac.getEXP();
    System.out.println("exp = " + dexp);
    System.out.println("exp(1) = " + dexp.evaluate(dfac.getONE()));
    System.out.println("exp(0) = " + dexp.evaluate(dfac.getZERO()));
  }
Пример #2
0
  /** Test rational coefficient reduction. */
  public void testRatReduction() {
    do {
      a = fac.random(kl, ll, el);
    } while (a.isZERO());
    do {
      b = fac.random(kl, ll, el);
    } while (b.isZERO());
    // System.out.println("a = " + a);
    // System.out.println("b = " + b);

    L = new ArrayList<GenWordPolynomial<BigRational>>();
    L.add(a);

    e = red.normalform(L, a);
    // System.out.println("e = " + e);
    assertTrue("isZERO( e )", e.isZERO());

    L.add(b);
    e = red.normalform(L, a);
    // System.out.println("e = " + e);
    assertTrue("isZERO( e ) some times", e.isZERO());

    L = new ArrayList<GenWordPolynomial<BigRational>>();
    L.add(a);
    assertTrue("isTopRed( a )", red.isTopReducible(L, a));
    assertTrue("isRed( a )", red.isReducible(L, a));
    L.add(b);
    assertTrue("isTopRed( b )", red.isTopReducible(L, b));
    assertTrue("isRed( b )", red.isReducible(L, b));

    c = fac.random(kl, ll, el);
    // System.out.println("c = " + c);
    e = red.normalform(L, c);
    // System.out.println("e = " + e);
    assertTrue("isNF( e )", red.isNormalform(L, e));

    Word u = new Word(wfac, "f");
    Word v = new Word(wfac, "abc");
    c = a.multiply(cfac.getONE(), u, v);
    // System.out.println("c = " + c);
    e = red.normalform(L, c);
    // System.out.println("e = " + e);
    assertTrue("isNF( e )", red.isNormalform(L, e));
    assertTrue("e == 0", e.isZERO());
  }
Пример #3
0
  public static void example7() {
    final BigRational fac = new BigRational();
    final UnivPowerSeriesRing<BigRational> pfac =
        new UnivPowerSeriesRing<BigRational>(fac, 11, "y");
    UnivPowerSeries<BigRational> exp =
        pfac.fixPoint(
            new UnivPowerSeriesMap<BigRational>() {

              public UnivPowerSeries<BigRational> map(UnivPowerSeries<BigRational> e) {
                return e.integrate(fac.getONE());
              }
            });
    System.out.println("exp = " + exp);
    UnivPowerSeries<BigRational> tan =
        pfac.fixPoint(
            new UnivPowerSeriesMap<BigRational>() {

              public UnivPowerSeries<BigRational> map(UnivPowerSeries<BigRational> t) {
                return t.multiply(t).sum(pfac.getONE()).integrate(fac.getZERO());
              }
            });
    System.out.println("tan = " + tan);
    UnivPowerSeries<BigRational> sin =
        new UnivPowerSeries<BigRational>(
            pfac,
            new Coefficients<BigRational>() {

              @Override
              public BigRational generate(int i) {
                BigRational c;
                if (i == 0) {
                  c = fac.getZERO();
                } else if (i == 1) {
                  c = fac.getONE();
                } else {
                  c = get(i - 2).negate();
                  c = c.divide(fac.fromInteger(i)).divide(fac.fromInteger(i - 1));
                }
                return c;
              }
            });
    System.out.println("sin = " + sin);
    UnivPowerSeries<BigRational> sin1 =
        pfac.fixPoint(
            new UnivPowerSeriesMap<BigRational>() {

              public UnivPowerSeries<BigRational> map(UnivPowerSeries<BigRational> e) {
                return e.negate().integrate(fac.getONE()).integrate(fac.getZERO());
              }
            });
    System.out.println("sin1 = " + sin1);

    UnivPowerSeries<BigRational> cos =
        new UnivPowerSeries<BigRational>(
            pfac,
            new Coefficients<BigRational>() {

              @Override
              public BigRational generate(int i) {
                BigRational c;
                if (i == 0) {
                  c = fac.getONE();
                } else if (i == 1) {
                  c = fac.getZERO();
                } else {
                  c = get(i - 2).negate();
                  c = c.divide(fac.fromInteger(i)).divide(fac.fromInteger(i - 1));
                }
                return c;
              }
            });
    System.out.println("cos = " + cos);
    UnivPowerSeries<BigRational> cos1 =
        pfac.fixPoint(
            new UnivPowerSeriesMap<BigRational>() {

              public UnivPowerSeries<BigRational> map(UnivPowerSeries<BigRational> e) {
                return e.negate().integrate(fac.getZERO()).integrate(fac.getONE());
              }
            });
    System.out.println("cos1 = " + cos1);

    UnivPowerSeries<BigRational> cos2 = pfac.solveODE(sin1.negate(), fac.getONE());
    System.out.println("cos2 = " + cos2);

    UnivPowerSeries<BigRational> sin2 = pfac.solveODE(cos1, fac.getZERO());
    System.out.println("sin2 = " + sin2);

    UnivPowerSeries<BigRational> sinh =
        new UnivPowerSeries<BigRational>(
            pfac,
            new Coefficients<BigRational>() {

              @Override
              public BigRational generate(int i) {
                BigRational c;
                if (i == 0) {
                  c = fac.getZERO();
                } else if (i == 1) {
                  c = fac.getONE();
                } else {
                  c = get(i - 2);
                  c = c.divide(fac.fromInteger(i)).divide(fac.fromInteger(i - 1));
                }
                return c;
              }
            });
    System.out.println("sinh = " + sinh);
    UnivPowerSeries<BigRational> cosh =
        new UnivPowerSeries<BigRational>(
            pfac,
            new Coefficients<BigRational>() {

              @Override
              public BigRational generate(int i) {
                BigRational c;
                if (i == 0) {
                  c = fac.getONE();
                } else if (i == 1) {
                  c = fac.getZERO();
                } else {
                  c = get(i - 2);
                  c = c.divide(fac.fromInteger(i)).divide(fac.fromInteger(i - 1));
                }
                return c;
              }
            } // , null
            );
    System.out.println("cosh = " + cosh);

    UnivPowerSeries<BigRational> sinhcosh = sinh.sum(cosh);
    System.out.println("sinh+cosh = " + sinhcosh);
    System.out.println("sinh+cosh == exp: " + sinhcosh.equals(exp));
  }
Пример #4
0
  /** Test scalar multiplication. */
  public void testMultiplication() {
    BigRational cfac = new BigRational(1);
    GenVectorModul<BigRational> mfac = new GenVectorModul<BigRational>(cfac, ll);
    BigRational r, s, t;
    GenVector<BigRational> a, b, c, d, e;

    r = cfac.random(kl);
    // System.out.println("r = " + r);
    s = r.inverse();
    // System.out.println("s = " + s);

    a = mfac.random(kl, q);
    // System.out.println("a = " + a);

    c = a.scalarMultiply(r);
    d = c.scalarMultiply(s);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a*b*(1/b) = a", a, d);

    b = mfac.random(kl, q);
    // System.out.println("b = " + b);

    t = cfac.getONE();
    // System.out.println("t = " + t);
    c = a.linearCombination(b, t);
    d = b.linearCombination(a, t);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b = b+1*a", c, d);

    c = a.linearCombination(b, t);
    d = a.sum(b);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b = b+1*a", c, d);

    s = t.negate();
    // System.out.println("s = " + s);
    c = a.linearCombination(b, t);
    d = c.linearCombination(b, s);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a+1*b+(-1)*b = a", a, d);

    c = a.linearCombination(t, b, t);
    d = c.linearCombination(t, b, s);
    // System.out.println("c = " + c);
    // System.out.println("d = " + d);
    assertEquals("a*1+b*1+b*(-1) = a", a, d);

    t = cfac.getZERO();
    // System.out.println("t = " + t);
    c = a.linearCombination(b, t);
    // System.out.println("c = " + c);
    assertEquals("a+0*b = a", a, c);

    d = a.linearCombination(t, b, t);
    // System.out.println("d = " + d);
    assertEquals("0*a+0*b = 0", mfac.getZERO(), d);

    r = a.scalarProduct(b);
    s = b.scalarProduct(a);
    // System.out.println("r = " + r);
    // System.out.println("s = " + s);
    assertEquals("a.b = b.a", r, s);
  }