/** Test compare sequential with parallel GBase. */ public void testSequentialParallelGBase() { List<GenPolynomial<BigRational>> Gs, Gp; L = new ArrayList<GenPolynomial<BigRational>>(); a = fac.random(kl, ll, el, q); b = fac.random(kl, ll, el, q); c = fac.random(kl, ll, el, q); d = fac.random(kl, ll, el, q); e = d; // fac.random(kl, ll, el, q ); if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { return; } L.add(a); Gs = bbseq.GB(L); Gp = bbpar.GB(L); assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp)); assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs)); L = Gs; L.add(b); Gs = bbseq.GB(L); Gp = bbpar.GB(L); assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp)); assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs)); L = Gs; L.add(c); Gs = bbseq.GB(L); Gp = bbpar.GB(L); assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp)); assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs)); L = Gs; L.add(d); Gs = bbseq.GB(L); Gp = bbpar.GB(L); assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp)); assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs)); L = Gs; L.add(e); Gs = bbseq.GB(L); Gp = bbpar.GB(L); assertTrue("Gs.containsAll(Gp)", Gs.containsAll(Gp)); assertTrue("Gp.containsAll(Gs)", Gp.containsAll(Gs)); }
/** Test parallel GBase. */ public void testParallelGBase() { L = new ArrayList<GenPolynomial<BigRational>>(); a = fac.random(kl, ll, el, q); b = fac.random(kl, ll, el, q); c = fac.random(kl, ll, el, q); d = fac.random(kl, ll, el, q); e = d; // fac.random(kl, ll, el, q ); if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { return; } assertTrue("not isZERO( a )", !a.isZERO()); L.add(a); L = bbpar.GB(L); assertTrue("isGB( { a } )", bbpar.isGB(L)); assertTrue("not isZERO( b )", !b.isZERO()); L.add(b); // System.out.println("L = " + L.size() ); L = bbpar.GB(L); assertTrue("isGB( { a, b } )", bbpar.isGB(L)); assertTrue("not isZERO( c )", !c.isZERO()); L.add(c); L = bbpar.GB(L); assertTrue("isGB( { a, b, c } )", bbpar.isGB(L)); assertTrue("not isZERO( d )", !d.isZERO()); L.add(d); L = bbpar.GB(L); assertTrue("isGB( { a, b, c, d } )", bbpar.isGB(L)); assertTrue("not isZERO( e )", !e.isZERO()); L.add(e); L = bbpar.GB(L); assertTrue("isGB( { a, b, c, d, e } )", bbpar.isGB(L)); }
/** Test modular evaluation gcd. */ public void testModEvalGcd() { GreatestCommonDivisorAbstract<ModInteger> ufd_me = new GreatestCommonDivisorModEval(); for (int i = 0; i < 1; i++) { a = dfac.random(kl * (i + 2), ll + 2 * i, el + 0 * i, q); b = dfac.random(kl * (i + 2), ll + 2 * i, el + 0 * i, q); c = dfac.random(kl * (i + 2), ll + 2 * i, el + 0 * i, q); c = c.multiply(dfac.univariate(0)); // a = ufd.basePrimitivePart(a); // b = ufd.basePrimitivePart(b); if (a.isZERO() || b.isZERO() || c.isZERO()) { // skip for this turn continue; } assertTrue("length( c" + i + " ) <> 0", c.length() > 0); // assertTrue(" not isZERO( c"+i+" )", !c.isZERO() ); // assertTrue(" not isONE( c"+i+" )", !c.isONE() ); a = a.multiply(c); b = b.multiply(c); // System.out.println("a = " + a); // System.out.println("b = " + b); d = ufd_me.gcd(a, b); c = ufd.basePrimitivePart(c).abs(); e = PolyUtil.<ModInteger>basePseudoRemainder(d, c); // System.out.println("c = " + c); // System.out.println("d = " + d); assertTrue("c | gcd(ac,bc) " + e, e.isZERO()); e = PolyUtil.<ModInteger>basePseudoRemainder(a, d); // System.out.println("e = " + e); assertTrue("gcd(a,b) | a" + e, e.isZERO()); e = PolyUtil.<ModInteger>basePseudoRemainder(b, d); // System.out.println("e = " + e); assertTrue("gcd(a,b) | b" + e, e.isZERO()); } }
/** Test scalar multiplication. */ public void testPolynomialMultiplication() { BigRational cfac = new BigRational(1); GenPolynomialRing<BigRational> pfac = new GenPolynomialRing<BigRational>(cfac, rl); GenVectorModul<GenPolynomial<BigRational>> mfac = new GenVectorModul<GenPolynomial<BigRational>>(pfac, ll); GenPolynomial<BigRational> r, s, t; GenVector<GenPolynomial<BigRational>> a, b, c, d, e; r = pfac.random(kl); // System.out.println("r = " + r); s = r.negate(); // System.out.println("s = " + s); a = mfac.random(kl, q); // System.out.println("a = " + a); c = a.scalarMultiply(r); d = a.scalarMultiply(s); e = c.sum(d); // System.out.println("c = " + c); // System.out.println("d = " + d); // System.out.println("e = " + e); assertEquals("a*b + a*(-b) = 0", e, mfac.getZERO()); b = mfac.random(kl, q); // System.out.println("b = " + b); t = pfac.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 = a", a, d); t = pfac.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); }