/** 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); }
/** Test rational coefficient reduction with recording. */ public void testRatReductionRecording() { List<GenWordPolynomial<BigRational>> lrow, rrow = null; do { a = fac.random(kl, ll, el); } while (a.isZERO()); do { b = fac.random(kl, ll, el); } while (b.isZERO()); c = fac.random(kl, ll, el); d = fac.random(kl, ll, el); // System.out.println("a = " + a); // System.out.println("b = " + b); // System.out.println("c = " + c); // System.out.println("d = " + d); L = new ArrayList<GenWordPolynomial<BigRational>>(); L.add(a); lrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); rrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); e = fac.getZERO(); for (int m = 0; m < L.size(); m++) { lrow.add(e); rrow.add(e); } e = red.normalform(lrow, rrow, L, a); // System.out.println("e = " + e); // System.out.println("lrow = " + lrow); // System.out.println("rrow = " + rrow); assertTrue("isZERO( e )", e.isZERO()); assertTrue("is Reduction ", red.isReductionNF(lrow, rrow, L, a, e)); L.add(b); lrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); rrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); e = fac.getZERO(); for (int m = 0; m < L.size(); m++) { lrow.add(e); rrow.add(e); } e = red.normalform(lrow, rrow, L, b); // System.out.println("e = " + e); // System.out.println("lrow = " + lrow); // System.out.println("rrow = " + rrow); assertTrue("is Reduction ", red.isReductionNF(lrow, rrow, L, b, e)); L.add(c); lrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); rrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); e = fac.getZERO(); for (int m = 0; m < L.size(); m++) { lrow.add(e); rrow.add(e); } e = red.normalform(lrow, rrow, L, c); // System.out.println("e = " + e); // System.out.println("lrow = " + lrow); // System.out.println("rrow = " + rrow); assertTrue("is Reduction ", red.isReductionNF(lrow, rrow, L, c, e)); L.add(d); lrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); rrow = new ArrayList<GenWordPolynomial<BigRational>>(L.size()); e = fac.getZERO(); for (int m = 0; m < L.size(); m++) { lrow.add(e); rrow.add(e); } Word u = new Word(wfac, "f"); Word v = new Word(wfac, "abc"); d = a.multiply(cfac.random(3), u, v); // System.out.println("d = " + d); e = red.normalform(lrow, rrow, L, d); // System.out.println("e = " + e); // System.out.println("lrow = " + lrow); // System.out.println("rrow = " + rrow); assertTrue("is Reduction ", red.isReductionNF(lrow, rrow, L, d, e)); }