/** Test object multiplication. */ public void testMultiplication() { a = fac.random(ll); assertTrue("not isZERO( a )", !a.isZERO()); b = fac.random(ll); assertTrue("not isZERO( b )", !b.isZERO()); c = b.multiply(a); d = a.multiply(b); assertTrue("not isZERO( c )", !c.isZERO()); assertTrue("not isZERO( d )", !d.isZERO()); // System.out.println("a = " + a); // System.out.println("b = " + b); e = d.subtract(c); assertTrue("!isZERO( a*b-b*a ) " + e, !e.isZERO()); assertTrue("a*b = b*a", !c.equals(d)); // assertEquals("a*b = b*a",c,d); c = fac.random(ll); // System.out.println("c = " + c); d = a.multiply(b.multiply(c)); e = (a.multiply(b)).multiply(c); // System.out.println("d = " + d); // System.out.println("e = " + e); // System.out.println("d-e = " + d.subtract(c) ); assertEquals("a(bc) = (ab)c", d, e); assertTrue("a(bc) = (ab)c", d.equals(e)); BigQuaternion x = a.leadingBaseCoefficient().inverse(); c = a.monic(); d = a.multiply(x); assertEquals("a.monic() = a(1/ldcf(a))", c, d); BigQuaternion y = b.leadingBaseCoefficient().inverse(); c = b.monic(); d = b.multiply(y); assertEquals("b.monic() = b(1/ldcf(b))", c, d); e = new GenPolynomial<BigQuaternion>(fac, y); d = b.multiply(e); assertEquals("b.monic() = b(1/ldcf(b))", c, d); // d = e.multiply(b); // assertEquals("b.monic() = (1/ldcf(b) (0))*b",c,d); }
/** Test constructors and factory. */ public void testConstructors() { // rational numbers BigRational rf = new BigRational(); // System.out.println("rf = " + rf); // BigRational r = rf.fromInteger( 99 ); // System.out.println("r = " + r); // r = rf.random( 9 ).sum(r); // System.out.println("r = " + r); // assertFalse("r.isZERO() = ", r.isZERO()); // RingElem<BigRational> re = new BigRational( 3 ); // System.out.println("re = " + re); // rf = (BigRational) re; // RingFactory<BigRational> ref = new BigRational( 3 ); // System.out.println("re = " + re); // rf = (BigRational) ref; // polynomials over rational numbers GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(rf, 2); // System.out.println("pf = " + pf); GenPolynomial<BigRational> p = pf.getONE(); // System.out.println("p = " + p); p = pf.random(9); // System.out.println("p = " + p); p = pf.getZERO(); // System.out.println("p = " + p); RingElem<GenPolynomial<BigRational>> pe = new GenPolynomial<BigRational>(pf); // System.out.println("pe = " + pe); // System.out.println("p.equals(pe) = " + p.equals(pe) ); // System.out.println("p.equals(p) = " + p.equals(p) ); assertTrue("p.equals(pe) = ", p.equals(pe)); assertTrue("p.equals(p) = ", p.equals(p)); pe = pe.sum(p); // why not p = p.add(pe) ? // System.out.println("pe = " + pe); assertTrue("pe.isZERO() = ", pe.isZERO()); p = pf.random(9); p = p.subtract(p); // System.out.println("p = " + p); // System.out.println("p.isZERO() = " + p.isZERO()); assertTrue("p.isZERO() = ", p.isZERO()); // polynomials over (polynomials over rational numbers) GenPolynomialRing<GenPolynomial<BigRational>> ppf = new GenPolynomialRing<GenPolynomial<BigRational>>(pf, 3); // System.out.println("ppf = " + ppf); GenPolynomial<GenPolynomial<BigRational>> pp = ppf.getONE(); // System.out.println("pp = " + pp); pp = ppf.random(2); // System.out.println("pp = " + pp); pp = ppf.getZERO(); // System.out.println("pp = " + pp); RingElem<GenPolynomial<GenPolynomial<BigRational>>> ppe = new GenPolynomial<GenPolynomial<BigRational>>(ppf); // System.out.println("ppe = " + ppe); // System.out.println("pp.equals(ppe) = " + pp.equals(ppe) ); // System.out.println("pp.equals(pp) = " + pp.equals(pp) ); assertTrue("pp.equals(ppe) = ", pp.equals(ppe)); assertTrue("pp.equals(pp) = ", pp.equals(pp)); ppe = ppe.sum(pp); // why not pp = pp.add(ppe) ? // System.out.println("ppe = " + ppe); assertTrue("ppe.isZERO() = ", ppe.isZERO()); pp = ppf.random(2); pp = pp.subtract(pp); // System.out.println("pp = " + pp); // System.out.println("pp.isZERO() = " + pp.isZERO()); assertTrue("pp.isZERO() = ", pp.isZERO()); // polynomials over (polynomials over (polynomials over rational numbers)) GenPolynomialRing<GenPolynomial<GenPolynomial<BigRational>>> pppf = new GenPolynomialRing<GenPolynomial<GenPolynomial<BigRational>>>(ppf, 4); // System.out.println("pppf = " + pppf); GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>> ppp = pppf.getONE(); // System.out.println("ppp = " + ppp); ppp = pppf.random(2); // System.out.println("ppp = " + ppp); ppp = pppf.getZERO(); // System.out.println("ppp = " + ppp); RingElem<GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>>> pppe = new GenPolynomial<GenPolynomial<GenPolynomial<BigRational>>>(pppf); // System.out.println("pppe = " + pppe); // System.out.println("ppp.equals(pppe) = " + ppp.equals(pppe) ); // System.out.println("ppp.equals(ppp) = " + ppp.equals(ppp) ); assertTrue("ppp.equals(pppe) = ", ppp.equals(pppe)); assertTrue("ppp.equals(ppp) = ", ppp.equals(ppp)); pppe = pppe.sum(ppp); // why not ppp = ppp.add(pppe) ? // System.out.println("pppe = " + pppe); assertTrue("pppe.isZERO() = ", pppe.isZERO()); ppp = pppf.random(2); ppp = ppp.subtract(ppp); // System.out.println("ppp = " + ppp); // System.out.println("ppp.isZERO() = " + ppp.isZERO()); assertTrue("ppp.isZERO() = ", ppp.isZERO()); // some tests // GenPolynomial<BigRational> pfx = new GenPolynomial<BigRational>(); // System.out.println("pfx = " + pfx); }