001/* 002 * $Id$ 003 */ 004 005package edu.jas.poly; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import edu.jas.arith.BigComplex; 012import edu.jas.arith.BigInteger; 013import edu.jas.arith.BigRational; 014import edu.jas.arith.ModInteger; 015import edu.jas.arith.ModIntegerRing; 016import edu.jas.arith.Product; 017import edu.jas.arith.ProductRing; 018 019import junit.framework.Test; 020import junit.framework.TestCase; 021import junit.framework.TestSuite; 022 023 024/** 025 * PolyUtil tests with JUnit. 026 * @author Heinz Kredel 027 */ 028 029public class PolyUtilTest extends TestCase { 030 031 032 /** 033 * main. 034 */ 035 public static void main(String[] args) { 036 junit.textui.TestRunner.run(suite()); 037 } 038 039 040 /** 041 * Constructs a <CODE>PolyUtilTest</CODE> object. 042 * @param name String. 043 */ 044 public PolyUtilTest(String name) { 045 super(name); 046 } 047 048 049 /** 050 */ 051 public static Test suite() { 052 TestSuite suite = new TestSuite(PolyUtilTest.class); 053 return suite; 054 } 055 056 057 //private final static int bitlen = 100; 058 059 TermOrder to = new TermOrder(TermOrder.INVLEX); 060 061 062 GenPolynomialRing<BigInteger> dfac; 063 064 065 GenPolynomialRing<BigInteger> cfac; 066 067 068 GenPolynomialRing<GenPolynomial<BigInteger>> rfac; 069 070 071 BigInteger ai, bi, ci, di, ei; 072 073 074 GenPolynomial<BigInteger> a, b, c, d, e; 075 076 077 GenPolynomial<GenPolynomial<BigInteger>> ar, br, cr, dr, er; 078 079 080 int rl = 5; 081 082 083 int kl = 5; 084 085 086 int ll = 5; 087 088 089 int el = 3; 090 091 092 float q = 0.3f; 093 094 095 @Override 096 protected void setUp() { 097 a = b = c = d = e = null; 098 ai = bi = ci = di = ei = null; 099 ar = br = cr = dr = er = null; 100 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, to); 101 cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, to); 102 rfac = new GenPolynomialRing<GenPolynomial<BigInteger>>(cfac, 1, to); 103 } 104 105 106 @Override 107 protected void tearDown() { 108 a = b = c = d = e = null; 109 ai = bi = ci = di = ei = null; 110 ar = br = cr = dr = er = null; 111 dfac = null; 112 cfac = null; 113 rfac = null; 114 } 115 116 117 protected static java.math.BigInteger getPrime1() { 118 long prime = 2; //2^60-93; // 2^30-35; //19; knuth (2,390) 119 for (int i = 1; i < 60; i++) { 120 prime *= 2; 121 } 122 prime -= 93; 123 //prime = 37; 124 //System.out.println("p1 = " + prime); 125 return new java.math.BigInteger("" + prime); 126 } 127 128 129 protected static java.math.BigInteger getPrime2() { 130 long prime = 2; //2^60-93; // 2^30-35; //19; knuth (2,390) 131 for (int i = 1; i < 30; i++) { 132 prime *= 2; 133 } 134 prime -= 35; 135 //prime = 19; 136 //System.out.println("p1 = " + prime); 137 return new java.math.BigInteger("" + prime); 138 } 139 140 141 /** 142 * Test recursive -- distributive conversion. 143 */ 144 public void testConversion() { 145 c = dfac.getONE(); 146 assertTrue("length( c ) = 1", c.length() == 1); 147 assertTrue("isZERO( c )", !c.isZERO()); 148 assertTrue("isONE( c )", c.isONE()); 149 150 cr = PolyUtil.recursive(rfac, c); 151 a = PolyUtil.distribute(dfac, cr); 152 assertEquals("c == dist(rec(c))", c, a); 153 154 d = dfac.getZERO(); 155 assertTrue("length( d ) = 0", d.length() == 0); 156 assertTrue("isZERO( d )", d.isZERO()); 157 assertTrue("isONE( d )", !d.isONE()); 158 159 dr = PolyUtil.recursive(rfac, d); 160 b = PolyUtil.distribute(dfac, dr); 161 assertEquals("d == dist(rec(d))", d, b); 162 } 163 164 165 /** 166 * Test recursive -- distributive ring conversion. 167 */ 168 public void testConversionRing() { 169 GenPolynomialRing<GenPolynomial<BigInteger>> rf = dfac.recursive(1); 170 GenPolynomialRing<BigInteger> cf = (GenPolynomialRing<BigInteger>) rf.coFac; 171 assertEquals("rfac#var == rf#var ", rfac.nvar, rf.nvar); 172 assertEquals("rfac.coFac#var == rf.coFac#var ", cfac.nvar, cf.nvar); 173 assertEquals("rfac.coFac.coFac == rf.coFac.coFac ", cfac.coFac, cf.coFac); 174 // variable names not same in this test 175 } 176 177 178 /** 179 * Test random recursive -- distributive conversion. 180 */ 181 public void testRandomConversion() { 182 for (int i = 0; i < 7; i++) { 183 c = dfac.random(kl * (i + 2), ll + 2 * i, el + i, q); 184 185 assertTrue("length( c" + i + " ) <> 0", c.length() >= 0); 186 assertTrue(" not isZERO( c" + i + " )", !c.isZERO()); 187 assertTrue(" not isONE( c" + i + " )", !c.isONE()); 188 189 cr = PolyUtil.recursive(rfac, c); 190 a = PolyUtil.distribute(dfac, cr); 191 //System.out.println("c = " + c); 192 //System.out.println("cr = " + cr); 193 //System.out.println("crd = " + a); 194 195 assertEquals("c == dist(rec(c))", c, a); 196 } 197 } 198 199 200 /** 201 * Test random rational -- integer conversion. 202 */ 203 public void testRationalConversion() { 204 GenPolynomialRing<BigRational> rfac = new GenPolynomialRing<BigRational>(new BigRational(1), rl, to); 205 206 GenPolynomial<BigRational> ar; 207 GenPolynomial<BigRational> br; 208 209 for (int i = 0; i < 3; i++) { 210 c = dfac.random(kl * (i + 9), ll * (i + 3), el + i, q).abs(); 211 //c = c.multiply( new BigInteger(99) ); // fails, since not primitive 212 //c = GreatestCommonDivisor.primitivePart(c); 213 214 assertTrue("length( c" + i + " ) <> 0", c.length() >= 0); 215 assertTrue(" not isZERO( c" + i + " )", !c.isZERO()); 216 assertTrue(" not isONE( c" + i + " )", !c.isONE()); 217 218 ar = PolyUtil.<BigRational> fromIntegerCoefficients(rfac, c); 219 br = ar.monic(); 220 a = PolyUtil.integerFromRationalCoefficients(dfac, br); 221 //System.out.println("c = " + c); 222 //System.out.println("ar = " + ar); 223 //System.out.println("br = " + br); 224 //System.out.println("crd = " + a); 225 226 assertEquals("c == integer(rational(c))", c, a); 227 } 228 } 229 230 231 /** 232 * Test random modular -- integer conversion. 233 */ 234 public void testModularConversion() { 235 ModIntegerRing pm = new ModIntegerRing(getPrime1()); 236 GenPolynomialRing<ModInteger> mfac = new GenPolynomialRing<ModInteger>(pm, rl, to); 237 238 GenPolynomial<ModInteger> ar; 239 240 for (int i = 0; i < 3; i++) { 241 c = dfac.random(kl * (i + 2), ll * (i + 1), el + i, q).abs(); 242 //c = c.multiply( new BigInteger(99) ); // fails, since not primitive 243 //c = GreatestCommonDivisor.primitivePart(c); 244 245 assertTrue("length( c" + i + " ) <> 0", c.length() >= 0); 246 assertTrue(" not isZERO( c" + i + " )", !c.isZERO()); 247 assertTrue(" not isONE( c" + i + " )", !c.isONE()); 248 249 ar = PolyUtil.<ModInteger> fromIntegerCoefficients(mfac, c); 250 a = PolyUtil.integerFromModularCoefficients(dfac, ar); 251 //System.out.println("c = " + c); 252 //System.out.println("ar = " + ar); 253 //System.out.println("crd = " + a); 254 255 assertEquals("c == integer(modular(c))", c, a); 256 } 257 } 258 259 260 /** 261 * Test chinese remainder. 262 */ 263 public void testChineseRemainder() { 264 java.math.BigInteger p1 = getPrime1(); 265 java.math.BigInteger p2 = getPrime2(); 266 java.math.BigInteger p12 = p1.multiply(p2); 267 268 ModIntegerRing pm1 = new ModIntegerRing(p1); 269 GenPolynomialRing<ModInteger> mfac1 = new GenPolynomialRing<ModInteger>(pm1, rl, to); 270 271 ModIntegerRing pm2 = new ModIntegerRing(p2); 272 GenPolynomialRing<ModInteger> mfac2 = new GenPolynomialRing<ModInteger>(pm2, rl, to); 273 274 ModIntegerRing pm12 = new ModIntegerRing(p12); 275 GenPolynomialRing<ModInteger> mfac = new GenPolynomialRing<ModInteger>(pm12, rl, to); 276 277 ModInteger di = pm2.create(p1); 278 di = di.inverse(); 279 //System.out.println("di = " + di); 280 281 GenPolynomial<ModInteger> am; 282 GenPolynomial<ModInteger> bm; 283 GenPolynomial<ModInteger> cm; 284 285 ExpVector degv, qdegv; 286 287 for (int i = 0; i < 3; i++) { 288 c = dfac.random((59 + 29) / 2, ll * (i + 1), el + i, q); 289 //c = c.multiply( new BigInteger(99) ); // fails, since not primitive 290 //c = GreatestCommonDivisor.primitivePart(c); 291 degv = c.degreeVector(); 292 //System.out.println("degv = " + degv); 293 294 assertTrue("length( c" + i + " ) <> 0", c.length() >= 0); 295 assertTrue(" not isZERO( c" + i + " )", !c.isZERO()); 296 assertTrue(" not isONE( c" + i + " )", !c.isONE()); 297 298 am = PolyUtil.<ModInteger> fromIntegerCoefficients(mfac1, c); 299 qdegv = am.degreeVector(); 300 //System.out.println("qdegv = " + qdegv); 301 if (!degv.equals(qdegv)) { 302 continue; 303 } 304 bm = PolyUtil.<ModInteger> fromIntegerCoefficients(mfac2, c); 305 qdegv = bm.degreeVector(); 306 //System.out.println("qdegv = " + qdegv); 307 if (!degv.equals(qdegv)) { 308 continue; 309 } 310 311 cm = PolyUtil.chineseRemainder(mfac, am, di, bm); 312 a = PolyUtil.integerFromModularCoefficients(dfac, cm); 313 314 //System.out.println("c = " + c); 315 //System.out.println("am = " + am); 316 //System.out.println("bm = " + bm); 317 //System.out.println("cm = " + cm); 318 //System.out.println("a = " + a); 319 320 assertEquals("cra(c mod p1,c mod p2) = c", c, a); 321 } 322 } 323 324 325 /** 326 * Test complex conversion. 327 */ 328 public void testComplexConversion() { 329 BigRational rf = new BigRational(1); 330 GenPolynomialRing<BigRational> rfac = new GenPolynomialRing<BigRational>(rf, rl, to); 331 332 BigComplex cf = new BigComplex(1); 333 GenPolynomialRing<BigComplex> cfac = new GenPolynomialRing<BigComplex>(cf, rl, to); 334 335 BigComplex imag = BigComplex.I; 336 337 GenPolynomial<BigRational> rp; 338 GenPolynomial<BigRational> ip; 339 GenPolynomial<BigComplex> crp; 340 GenPolynomial<BigComplex> cip; 341 GenPolynomial<BigComplex> cp; 342 GenPolynomial<BigComplex> ap; 343 344 for (int i = 0; i < 3; i++) { 345 cp = cfac.random(kl + 2 * i, ll * (i + 1), el + i, q); 346 347 assertTrue("length( c" + i + " ) <> 0", cp.length() >= 0); 348 assertTrue(" not isZERO( c" + i + " )", !cp.isZERO()); 349 assertTrue(" not isONE( c" + i + " )", !cp.isONE()); 350 351 rp = PolyUtil.realPart(rfac, cp); 352 ip = PolyUtil.imaginaryPart(rfac, cp); 353 354 crp = PolyUtil.complexFromRational(cfac, rp); 355 cip = PolyUtil.complexFromRational(cfac, ip); 356 357 ap = crp.sum(cip.multiply(imag)); 358 359 //System.out.println("cp = " + cp); 360 //System.out.println("rp = " + rp); 361 //System.out.println("ip = " + ip); 362 //System.out.println("crp = " + crp); 363 //System.out.println("cip = " + cip); 364 //System.out.println("ap = " + ap); 365 366 assertEquals("re(c)+i*im(c) = c", cp, ap); 367 } 368 } 369 370 371 /** 372 * Test base pseudo division. 373 */ 374 public void testBasePseudoDivision() { 375 String[] names = new String[] { "x" }; 376 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), to, names); 377 GenPolynomialRing<BigRational> rdfac = new GenPolynomialRing<BigRational>(new BigRational(1), dfac); 378 //System.out.println("\ndfac = " + dfac); 379 //System.out.println("rdfac = " + rdfac); 380 381 a = dfac.random(kl, 2 * ll, el + 17, q); 382 //a = dfac.parse(" 3 x^5 + 44 "); 383 //b = a; 384 b = dfac.random(kl, 2 * ll, el + 3, q); 385 //a = a.multiply(b); 386 //a = a.sum(b); 387 //b = dfac.parse(" 2 x^2 + 40 "); 388 //System.out.println("a = " + a); 389 //System.out.println("b = " + b); 390 391 GenPolynomial<BigInteger>[] QR = PolyUtil.<BigInteger> basePseudoQuotientRemainder(a, b); 392 c = QR[1]; 393 d = QR[0]; 394 //System.out.println("q = " + d); 395 //System.out.println("r = " + c); 396 397 boolean t = PolyUtil.<BigInteger> isBasePseudoQuotientRemainder(a, b, d, c); 398 assertTrue("lc^n a = q b + r: " + c, t); 399 400 GenPolynomial<BigRational> ap = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, a); 401 GenPolynomial<BigRational> bp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, b); 402 GenPolynomial<BigRational> cp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, c); 403 GenPolynomial<BigRational> dp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, d); 404 //System.out.println("ap = " + ap); 405 //System.out.println("bp = " + bp); 406 //System.out.println("cp = " + cp); 407 ////System.out.println("dp = " + dp); 408 //System.out.println("dp = " + dp.monic()); 409 410 GenPolynomial<BigRational> qp = ap.divide(bp); 411 GenPolynomial<BigRational> rp = ap.remainder(bp); 412 //System.out.println("qp = " + qp); 413 //System.out.println("qp = " + qp.monic()); 414 //System.out.println("rp = " + rp); 415 GenPolynomial<BigRational> rhs = qp.multiply(bp).sum(rp); 416 //System.out.println("qp bp + rp = " + rhs); 417 418 assertEquals("ap = qp bp + rp: ", ap, rhs); 419 420 assertEquals("cp = rp: ", rp.monic(), cp.monic()); 421 assertEquals("dp = qp: ", qp.monic(), dp.monic()); // ?? 422 //System.out.println("dp = qp: " + qp.monic().equals(dp.monic()) ); 423 } 424 425 426 /** 427 * Test base sparse pseudo division. 428 */ 429 public void testBasePseudoDivisionSparse() { 430 String[] names = new String[] { "x" }; 431 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), to, names); 432 GenPolynomialRing<BigRational> rdfac = new GenPolynomialRing<BigRational>(new BigRational(1), dfac); 433 //System.out.println("\ndfac = " + dfac); 434 //System.out.println("rdfac = " + rdfac); 435 436 a = dfac.random(kl, 2 * ll, el + 17, q); 437 //a = dfac.parse(" 3 x^5 + 44 "); 438 //b = a; 439 b = dfac.random(kl, 2 * ll, el + 3, q); 440 //a = a.multiply(b); 441 //a = a.sum(b); 442 //b = dfac.parse(" 2 x^2 + 40 "); 443 //System.out.println("a = " + a); 444 //System.out.println("b = " + b); 445 446 d = PolyUtil.<BigInteger> basePseudoDivide(a, b); 447 //System.out.println("q = " + d); 448 c = PolyUtil.<BigInteger> baseSparsePseudoRemainder(a, b); 449 //System.out.println("r = " + c); 450 451 boolean t = PolyUtil.<BigInteger> isBasePseudoQuotientRemainder(a, b, d, c); 452 assertTrue("lc^n a = q b + r: " + c, t); 453 454 GenPolynomial<BigRational> ap = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, a); 455 GenPolynomial<BigRational> bp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, b); 456 GenPolynomial<BigRational> cp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, c); 457 GenPolynomial<BigRational> dp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, d); 458 //System.out.println("ap = " + ap); 459 //System.out.println("bp = " + bp); 460 //System.out.println("cp = " + cp); 461 ////System.out.println("dp = " + dp); 462 //System.out.println("dp = " + dp.monic()); 463 464 GenPolynomial<BigRational> qp = ap.divide(bp); 465 GenPolynomial<BigRational> rp = ap.remainder(bp); 466 //System.out.println("qp = " + qp); 467 //System.out.println("qp = " + qp.monic()); 468 //System.out.println("rp = " + rp); 469 GenPolynomial<BigRational> rhs = qp.multiply(bp).sum(rp); 470 //System.out.println("qp bp + rp = " + rhs); 471 472 assertEquals("ap = qp bp + rp: ", ap, rhs); 473 474 assertEquals("cp = rp: ", rp.monic(), cp.monic()); 475 assertEquals("dp = qp: ", qp.monic(), dp.monic()); // ?? 476 //System.out.println("dp = qp: " + qp.monic().equals(dp.monic()) ); 477 } 478 479 480 /** 481 * Test base dense pseudo division. 482 */ 483 public void testBasePseudoDivisionDense() { 484 String[] names = new String[] { "x" }; 485 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), to, names); 486 GenPolynomialRing<BigRational> rdfac = new GenPolynomialRing<BigRational>(new BigRational(1), dfac); 487 //System.out.println("\ndfac = " + dfac); 488 //System.out.println("rdfac = " + rdfac); 489 490 a = dfac.random(kl, 2 * ll, el + 17, q); 491 //a = dfac.parse(" 3 x^5 + 44 "); 492 //b = a; 493 b = dfac.random(kl, 2 * ll, el + 3, q); 494 //a = a.multiply(b); 495 //a = a.sum(b); 496 //b = dfac.parse(" 2 x^2 + 40 "); 497 //System.out.println("a = " + a); 498 //System.out.println("b = " + b); 499 500 d = PolyUtil.<BigInteger> baseDensePseudoQuotient(a, b); 501 //System.out.println("q = " + d); 502 c = PolyUtil.<BigInteger> baseDensePseudoRemainder(a, b); 503 //System.out.println("r = " + c); 504 505 boolean t = PolyUtil.<BigInteger> isBasePseudoQuotientRemainder(a, b, d, c); 506 assertTrue("lc^n a = q b + r: " + c, t); 507 508 GenPolynomial<BigRational> ap = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, a); 509 GenPolynomial<BigRational> bp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, b); 510 GenPolynomial<BigRational> cp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, c); 511 GenPolynomial<BigRational> dp = PolyUtil.<BigRational> fromIntegerCoefficients(rdfac, d); 512 //System.out.println("ap = " + ap); 513 //System.out.println("bp = " + bp); 514 //System.out.println("cp = " + cp); 515 ////System.out.println("dp = " + dp); 516 //System.out.println("dp = " + dp.monic()); 517 518 GenPolynomial<BigRational> qp = ap.divide(bp); 519 GenPolynomial<BigRational> rp = ap.remainder(bp); 520 //System.out.println("qp = " + qp); 521 //System.out.println("qp = " + qp.monic()); 522 //System.out.println("rp = " + rp); 523 GenPolynomial<BigRational> rhs = qp.multiply(bp).sum(rp); 524 //System.out.println("qp bp + rp = " + rhs); 525 526 assertEquals("ap = qp bp + rp: ", ap, rhs); 527 528 assertEquals("cp = rp: ", rp.monic(), cp.monic()); 529 assertEquals("dp = qp: ", qp.monic(), dp.monic()); // ?? 530 //System.out.println("dp = qp: " + qp.monic().equals(dp.monic()) ); 531 } 532 533 534 /** 535 * Test recursive pseudo division. 536 * @see edu.jas.ufd.PolyUfdUtilTest#testRecursivePseudoDivisionSparse 537 */ 538 public void testRecursivePseudoDivision() { 539 } 540 541 542 /** 543 * Test evaluate main recursive. 544 */ 545 public void testEvalMainRecursive() { 546 ai = (new BigInteger()).random(kl); 547 //System.out.println("ai = " + ai); 548 549 ar = rfac.getZERO(); 550 //System.out.println("ar = " + ar); 551 552 a = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, ar, ai); 553 //System.out.println("a = " + a); 554 555 assertTrue("isZERO( a )", a.isZERO()); 556 557 ar = rfac.getONE(); 558 //System.out.println("ar = " + ar); 559 560 a = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, ar, ai); 561 //System.out.println("a = " + a); 562 563 assertTrue("isONE( a )", a.isONE()); 564 565 566 //ar = rfac.getONE(); 567 ar = rfac.random(kl, ll, el, q); 568 //System.out.println("ar = " + ar); 569 //br = rfac.getONE(); 570 br = rfac.random(kl, ll, el, q); 571 //System.out.println("br = " + br); 572 573 cr = br.sum(ar); 574 //System.out.println("cr = " + cr); 575 576 a = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, ar, ai); 577 b = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, br, ai); 578 c = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, cr, ai); 579 //System.out.println("a = " + a); 580 //System.out.println("b = " + b); 581 //System.out.println("c = " + c); 582 583 d = a.sum(b); 584 //System.out.println("d = " + d); 585 586 assertEquals("eval(a+b) == eval(a) + eval(b)", c, d); 587 588 589 cr = br.multiply(ar); 590 //System.out.println("cr = " + cr); 591 592 a = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, ar, ai); 593 b = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, br, ai); 594 c = PolyUtil.<BigInteger> evaluateMainRecursive(cfac, cr, ai); 595 //System.out.println("a = " + a); 596 //System.out.println("b = " + b); 597 //System.out.println("c = " + c); 598 599 d = a.multiply(b); 600 //System.out.println("d = " + d); 601 602 assertEquals("eval(a*b) == eval(a) * eval(b)", c, d); 603 } 604 605 606 /** 607 * Test evaluate main. 608 */ 609 public void testEvalMain() { 610 ei = (new BigInteger()).random(kl); 611 //System.out.println("ei = " + ei); 612 613 cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 1, to); 614 //System.out.println("cfac = " + cfac); 615 616 a = cfac.getZERO(); 617 //System.out.println("a = " + a); 618 619 ai = PolyUtil.<BigInteger> evaluateMain(ei, a, ei); 620 //System.out.println("ai = " + ai); 621 622 assertTrue("isZERO( ai )", ai.isZERO()); 623 624 a = cfac.getONE(); 625 //System.out.println("a = " + a); 626 627 ai = PolyUtil.<BigInteger> evaluateMain(ei, a, ei); 628 //System.out.println("ai = " + ai); 629 630 assertTrue("isONE( ai )", ai.isONE()); 631 632 //a = cfac.getONE(); 633 a = cfac.random(kl, ll, el, q); 634 //System.out.println("a = " + a); 635 //b = cfac.getONE(); 636 b = cfac.random(kl, ll, el, q); 637 //System.out.println("b = " + b); 638 639 c = b.sum(a); 640 //System.out.println("c = " + c); 641 642 ai = PolyUtil.<BigInteger> evaluateMain(ei, a, ei); 643 bi = PolyUtil.<BigInteger> evaluateMain(ei, b, ei); 644 ci = PolyUtil.<BigInteger> evaluateMain(ei, c, ei); 645 //System.out.println("ai = " + ai); 646 //System.out.println("bi = " + bi); 647 //System.out.println("ci = " + ci); 648 649 di = bi.sum(ai); 650 //System.out.println("di = " + di); 651 652 assertEquals("eval(a+b) == eval(a) + eval(b)", ci, di); 653 654 c = b.multiply(a); 655 //System.out.println("c = " + c); 656 657 ai = PolyUtil.<BigInteger> evaluateMain(ei, a, ei); 658 bi = PolyUtil.<BigInteger> evaluateMain(ei, b, ei); 659 ci = PolyUtil.<BigInteger> evaluateMain(ei, c, ei); 660 //System.out.println("ai = " + ai); 661 //System.out.println("bi = " + bi); 662 //System.out.println("ci = " + ci); 663 664 di = bi.multiply(ai); 665 //System.out.println("di = " + di); 666 667 assertEquals("eval(a*b) == eval(a) * eval(b)", ci, di); 668 } 669 670 671 /** 672 * Test evaluate first. 673 */ 674 public void testEvalFirst() { 675 ei = (new BigInteger()).random(kl); 676 //System.out.println("ei = " + ei); 677 678 GenPolynomial<BigInteger> ae, be, ce, de; 679 680 GenPolynomialRing<BigInteger> fac; 681 fac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, to); 682 //System.out.println("fac = " + fac); 683 684 cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 1, to); 685 //System.out.println("cfac = " + cfac); 686 687 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, to); 688 //System.out.println("dfac = " + dfac); 689 690 a = fac.getZERO(); 691 //System.out.println("a = " + a); 692 693 ae = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, a, ei); 694 //System.out.println("ae = " + ae); 695 696 assertTrue("isZERO( ae )", ae.isZERO()); 697 698 a = fac.getONE(); 699 //System.out.println("a = " + a); 700 701 ae = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, a, ei); 702 //System.out.println("ae = " + ae); 703 704 assertTrue("isONE( ae )", ae.isONE()); 705 706 //a = fac.getONE(); 707 a = fac.random(kl, ll, el, q); 708 //System.out.println("a = " + a); 709 //b = fac.getONE(); 710 b = fac.random(kl, ll, el, q); 711 //System.out.println("b = " + b); 712 713 c = b.sum(a); 714 //System.out.println("c = " + c); 715 716 ae = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, a, ei); 717 be = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, b, ei); 718 ce = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, c, ei); 719 //System.out.println("ae = " + ae); 720 //System.out.println("be = " + be); 721 //System.out.println("ce = " + ce); 722 723 de = be.sum(ae); 724 //System.out.println("de = " + de); 725 726 assertEquals("eval(a+b) == eval(a) + eval(b)", ce, de); 727 728 c = b.multiply(a); 729 //System.out.println("c = " + c); 730 731 ae = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, a, ei); 732 be = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, b, ei); 733 ce = PolyUtil.<BigInteger> evaluateFirst(cfac, dfac, c, ei); 734 //System.out.println("ae = " + ae); 735 //System.out.println("be = " + be); 736 //System.out.println("ce = " + ce); 737 738 de = be.multiply(ae); 739 //System.out.println("de = " + de); 740 741 assertEquals("eval(a*b) == eval(a) * eval(b)", ce, de); 742 } 743 744 745 /** 746 * Test evaluate all. 747 */ 748 public void testEvalAll() { 749 BigInteger cfac = new BigInteger(); 750 751 List<BigInteger> Ev = new ArrayList<BigInteger>(); 752 for (int i = 0; i < rl; i++) { 753 ei = cfac.random(kl); 754 Ev.add(ei); 755 } 756 //System.out.println("Ev = " + Ev); 757 758 BigInteger ae, be, ce, de; 759 760 GenPolynomialRing<BigInteger> fac; 761 fac = new GenPolynomialRing<BigInteger>(cfac, rl, to); 762 //System.out.println("fac = " + fac); 763 764 a = fac.getZERO(); 765 //System.out.println("a = " + a); 766 767 ae = PolyUtil.<BigInteger> evaluateAll(cfac, a, Ev); 768 //System.out.println("ae = " + ae); 769 770 assertTrue("isZERO( ae )", ae.isZERO()); 771 772 a = fac.getONE(); 773 //System.out.println("a = " + a); 774 775 ae = PolyUtil.<BigInteger> evaluateAll(cfac, a, Ev); 776 //System.out.println("ae = " + ae); 777 778 assertTrue("isONE( ae )", ae.isONE()); 779 780 //a = fac.getONE(); 781 a = fac.random(kl, ll, el, q); 782 //System.out.println("a = " + a); 783 //b = fac.getONE(); 784 b = fac.random(kl, ll, el, q); 785 //System.out.println("b = " + b); 786 787 c = b.sum(a); 788 //System.out.println("c = " + c); 789 790 ae = PolyUtil.<BigInteger> evaluateAll(cfac, a, Ev); 791 be = PolyUtil.<BigInteger> evaluateAll(cfac, b, Ev); 792 ce = PolyUtil.<BigInteger> evaluateAll(cfac, c, Ev); 793 //System.out.println("ae = " + ae); 794 //System.out.println("be = " + be); 795 //System.out.println("ce = " + ce); 796 797 de = be.sum(ae); 798 //System.out.println("de = " + de); 799 800 assertEquals("eval(a+b) == eval(a) + eval(b)", ce, de); 801 802 c = b.multiply(a); 803 //System.out.println("c = " + c); 804 805 ce = PolyUtil.<BigInteger> evaluateAll(cfac, c, Ev); 806 //System.out.println("ae = " + ae); 807 //System.out.println("be = " + be); 808 //System.out.println("ce = " + ce); 809 810 de = be.multiply(ae); 811 //System.out.println("de = " + de); 812 813 assertEquals("eval(a*b) == eval(a) * eval(b)", ce, de); 814 } 815 816 817 /** 818 * Test interpolate univariate 1 polynomial. 819 */ 820 public void testInterpolateUnivariateOne() { 821 ModInteger ai, bi, ci, di, ei, fi, gi, hi; 822 GenPolynomial<ModInteger> a; 823 GenPolynomialRing<ModInteger> cfac; 824 ModIntegerRing fac; 825 GenPolynomial<ModInteger> r; 826 GenPolynomial<ModInteger> Q; 827 GenPolynomial<ModInteger> Qp; 828 829 fac = new ModIntegerRing(19); 830 //System.out.println("fac.modul = " + fac.getModul()); 831 cfac = new GenPolynomialRing<ModInteger>(fac, 1, to); 832 //System.out.println("cfac = " + cfac); 833 834 a = cfac.getONE(); 835 //System.out.println("a = " + a); 836 837 ei = fac.fromInteger(11); 838 //System.out.println("ei = " + ei); 839 // a(ei) 840 ai = PolyUtil.<ModInteger> evaluateMain(fac, a, ei); 841 //System.out.println("ai = " + ai); 842 assertTrue("isONE( ai )", ai.isONE()); 843 844 di = fac.fromInteger(13); 845 //System.out.println("di = " + di); 846 // a(di) 847 bi = PolyUtil.<ModInteger> evaluateMain(fac, a, di); 848 //System.out.println("bi = " + bi); 849 assertTrue("isONE( bi )", bi.isONE()); 850 851 // interpolation result 852 r = cfac.getZERO(); 853 //System.out.println("r = " + r); 854 855 // interpolation polynomials product 856 Q = cfac.getONE(); 857 //System.out.println("Q = " + Q); 858 859 ci = PolyUtil.<ModInteger> evaluateMain(fac, Q, ei); 860 //System.out.println("ci = " + ci); 861 // Q(ei)^-1 862 fi = ci.inverse(); 863 //System.out.println("fi = " + fi); 864 r = PolyUtil.<ModInteger> interpolate(cfac, r, Q, fi, ai, ei); 865 //System.out.println("r = " + r); 866 867 // next evaluation polynomial 868 Qp = cfac.univariate(0); 869 Qp = Qp.subtract(cfac.getONE().multiply(ei)); 870 //System.out.println("Qp = " + Qp); 871 Q = Q.multiply(Qp); 872 //System.out.println("Q = " + Q); 873 874 ci = PolyUtil.<ModInteger> evaluateMain(fac, Q, di); 875 //System.out.println("ci = " + ci); 876 // Q(di)^-1 877 fi = ci.inverse(); 878 //System.out.println("fi = " + fi); 879 r = PolyUtil.<ModInteger> interpolate(cfac, r, Q, fi, bi, di); 880 //System.out.println("r = " + r); 881 882 // check evaluation 883 gi = PolyUtil.<ModInteger> evaluateMain(fac, r, ei); 884 //System.out.println("gi = " + gi); 885 hi = PolyUtil.<ModInteger> evaluateMain(fac, r, di); 886 //System.out.println("hi = " + hi); 887 assertTrue("gi == 1 ", gi.isONE()); 888 assertTrue("hi == 1 ", hi.isONE()); 889 890 // interpolate( a(ei), a(di) ) = a (mod 19) 891 assertEquals("interpolate(a mod (x-ei),a mod (x-di)) = a (mod 19)", a, r); 892 } 893 894 895 /** 896 * Test interpolate univariate deg > 0 polynomial. 897 */ 898 public void testInterpolateUnivariate() { 899 ModInteger ai, ci, ei, fi; 900 GenPolynomial<ModInteger> a; 901 GenPolynomialRing<ModInteger> cfac; 902 ModIntegerRing fac; 903 GenPolynomial<ModInteger> r; 904 GenPolynomial<ModInteger> Q; 905 GenPolynomial<ModInteger> Qp; 906 907 //long prime = 19; 908 long prime = getPrime1().longValue(); 909 fac = new ModIntegerRing(prime); 910 //System.out.println("fac.modul = " + fac.getModul()); 911 cfac = new GenPolynomialRing<ModInteger>(fac, 1, to); 912 //System.out.println("cfac = " + cfac); 913 int maxdeg = 19; 914 915 // polynomial to interpolate 916 long deg = 0; 917 do { 918 a = cfac.random(kl, ll, maxdeg, q); 919 if (!a.isZERO()) { 920 deg = a.degree(0); 921 } 922 } while (deg <= 0); 923 //System.out.println("a = " + a); 924 //System.out.println("deg = " + deg); 925 926 // interpolation result 927 r = cfac.getZERO(); 928 //System.out.println("r = " + r); 929 930 // interpolation polynomials product 931 Q = cfac.getONE(); 932 //System.out.println("Q = " + Q); 933 934 long i = -1; 935 long qdeg; 936 do { 937 i++; 938 if (i >= prime) { 939 assertTrue("elements of Z_prime exhausted", i < prime); 940 } 941 qdeg = Q.degree(0); 942 ei = fac.fromInteger(i); 943 //System.out.println("ei = " + ei); 944 // a(ei) 945 ai = PolyUtil.<ModInteger> evaluateMain(fac, a, ei); 946 //System.out.println("ai = " + ai); 947 948 ci = PolyUtil.<ModInteger> evaluateMain(fac, Q, ei); 949 //System.out.println("ci = " + ci); 950 // Q(ei)^-1 951 fi = ci.inverse(); 952 //System.out.println("fi = " + fi); 953 r = PolyUtil.<ModInteger> interpolate(cfac, r, Q, fi, ai, ei); 954 //System.out.println("r = " + r); 955 956 // next evaluation polynomial 957 Qp = cfac.univariate(0); 958 Qp = Qp.subtract(cfac.getONE().multiply(ei)); 959 //System.out.println("Qp = " + Qp); 960 Q = Q.multiply(Qp); 961 //System.out.println("Q = " + Q); 962 } while (qdeg < deg); 963 964 //System.out.println("a = " + a); 965 //System.out.println("r = " + r); 966 967 // interpolate( a(e1), ..., a(ei) ) = a (mod 19) 968 assertEquals("interpolate(a mod (x-e1),...,a mod (x-ei)) = a (mod 19)", a, r); 969 } 970 971 972 /** 973 * Test interpolate multivariate deg > 0 polynomial. 974 */ 975 public void testInterpolateMultivariate() { 976 ModInteger ci, ei, fi; 977 GenPolynomial<ModInteger> ap, bp; 978 GenPolynomial<GenPolynomial<ModInteger>> a; 979 GenPolynomialRing<GenPolynomial<ModInteger>> cfac; 980 GenPolynomialRing<ModInteger> ufac; 981 GenPolynomialRing<ModInteger> dfac; 982 ModIntegerRing fac; 983 GenPolynomial<GenPolynomial<ModInteger>> r; 984 GenPolynomial<ModInteger> Q; 985 GenPolynomial<ModInteger> Qp; 986 987 //long prime = 19; 988 long prime = getPrime1().longValue(); 989 fac = new ModIntegerRing(prime); 990 //System.out.println("fac.modul = " + fac.getModul()); 991 ufac = new GenPolynomialRing<ModInteger>(fac, 1, to); 992 //System.out.println("ufac = " + ufac); 993 cfac = new GenPolynomialRing<GenPolynomial<ModInteger>>(ufac, rl, to); 994 //System.out.println("cfac = " + cfac); 995 dfac = new GenPolynomialRing<ModInteger>(fac, rl, to); 996 //System.out.println("dfac = " + dfac); 997 int maxdeg = 19; 998 999 // polynomial to interpolate 1000 long deg = 0; 1001 do { 1002 a = cfac.random(kl, ll + 9, maxdeg, q); 1003 if (!a.isZERO()) { 1004 deg = PolyUtil.<ModInteger> coeffMaxDegree(a); 1005 } 1006 } while (deg <= 0); 1007 //System.out.println("a = " + a); 1008 //System.out.println("deg = " + deg); 1009 ExpVector degv = a.degreeVector(); 1010 //System.out.println("degv = " + degv); 1011 1012 // interpolation result 1013 r = cfac.getZERO(); 1014 //System.out.println("r = " + r); 1015 1016 // interpolation polynomials product 1017 Q = ufac.getONE(); 1018 //System.out.println("Q = " + Q); 1019 1020 long i = -1; 1021 long qdeg; 1022 ExpVector qdegv; 1023 do { 1024 i++; 1025 if (i >= prime) { 1026 assertTrue("elements of Z_prime exhausted", i < prime); 1027 } 1028 qdeg = Q.degree(0); 1029 ei = fac.fromInteger(i); 1030 //System.out.println("ei = " + ei); 1031 // a(ei) 1032 ap = PolyUtil.<ModInteger> evaluateFirstRec(ufac, dfac, a, ei); 1033 //System.out.println("ap = " + ap); 1034 qdegv = ap.degreeVector(); 1035 //System.out.println("qdegv = " + qdegv); 1036 if (!degv.equals(qdegv)) { 1037 continue; 1038 } 1039 ci = PolyUtil.<ModInteger> evaluateMain(fac, Q, ei); 1040 //System.out.println("ci = " + ci); 1041 // Q(ei)^-1 1042 fi = ci.inverse(); 1043 //System.out.println("fi = " + fi); 1044 r = PolyUtil.<ModInteger> interpolate(cfac, r, Q, fi, ap, ei); 1045 //System.out.println("r = " + r); 1046 1047 // check 1048 bp = PolyUtil.<ModInteger> evaluateFirstRec(ufac, dfac, r, ei); 1049 //System.out.println("bp = " + bp); 1050 assertEquals("interpolate(a)(ei) == a ", bp, ap); 1051 1052 1053 // next evaluation polynomial 1054 Qp = ufac.univariate(0); 1055 Qp = Qp.subtract(ufac.getONE().multiply(ei)); 1056 //System.out.println("Qp = " + Qp); 1057 Q = Q.multiply(Qp); 1058 //System.out.println("Q = " + Q); 1059 } while (qdeg <= deg); 1060 1061 //System.out.println("a = " + a); 1062 //System.out.println("r = " + r); 1063 1064 // interpolate( a(e1), ..., a(ei) ) = a (mod 19) 1065 assertEquals("interpolate(a mod (x-e1),...,a mod (x-ei)) = a (mod 19)", a, r); 1066 } 1067 1068 1069 /** 1070 * Test interpolate rational multivariate deg > 0 polynomial. 1071 */ 1072 public void testInterpolateRationalMultivariate() { 1073 BigRational ci, ei, fi; 1074 GenPolynomial<BigRational> ap, bp; 1075 GenPolynomial<GenPolynomial<BigRational>> a; 1076 GenPolynomialRing<GenPolynomial<BigRational>> cfac; 1077 GenPolynomialRing<BigRational> ufac; 1078 GenPolynomialRing<BigRational> dfac; 1079 BigRational fac; 1080 GenPolynomial<GenPolynomial<BigRational>> r; 1081 GenPolynomial<BigRational> Q; 1082 GenPolynomial<BigRational> Qp; 1083 1084 fac = new BigRational(); 1085 //System.out.println("fac.modul = " + fac.getModul()); 1086 ufac = new GenPolynomialRing<BigRational>(fac, 1, to); 1087 //System.out.println("ufac = " + ufac); 1088 cfac = new GenPolynomialRing<GenPolynomial<BigRational>>(ufac, rl, to); 1089 //System.out.println("cfac = " + cfac); 1090 dfac = new GenPolynomialRing<BigRational>(fac, rl, to); 1091 //System.out.println("dfac = " + dfac); 1092 int maxdeg = 19; 1093 1094 // polynomial to interpolate 1095 long deg = 0; 1096 do { 1097 a = cfac.random(kl, ll + 9, maxdeg, q); 1098 if (!a.isZERO()) { 1099 deg = PolyUtil.<BigRational> coeffMaxDegree(a); 1100 } 1101 } while (deg <= 0); 1102 //System.out.println("a = " + a); 1103 //System.out.println("deg = " + deg); 1104 ExpVector degv = a.degreeVector(); 1105 //System.out.println("degv = " + degv); 1106 1107 // interpolation result 1108 r = cfac.getZERO(); 1109 //System.out.println("r = " + r); 1110 1111 // interpolation polynomials product 1112 Q = ufac.getONE(); 1113 //System.out.println("Q = " + Q); 1114 1115 long i = -1; 1116 long qdeg; 1117 ExpVector qdegv; 1118 do { 1119 i++; 1120 qdeg = Q.degree(0); 1121 ei = fac.fromInteger(i); 1122 //System.out.println("ei = " + ei); 1123 // a(ei) 1124 ap = PolyUtil.<BigRational> evaluateFirstRec(ufac, dfac, a, ei); 1125 //System.out.println("ap = " + ap); 1126 qdegv = ap.degreeVector(); 1127 //System.out.println("qdegv = " + qdegv); 1128 if (!degv.equals(qdegv)) { 1129 continue; 1130 } 1131 ci = PolyUtil.<BigRational> evaluateMain(fac, Q, ei); 1132 //System.out.println("ci = " + ci); 1133 // Q(ei)^-1 1134 fi = ci.inverse(); 1135 //System.out.println("fi = " + fi); 1136 r = PolyUtil.<BigRational> interpolate(cfac, r, Q, fi, ap, ei); 1137 //System.out.println("r = " + r); 1138 1139 // check 1140 bp = PolyUtil.<BigRational> evaluateFirstRec(ufac, dfac, r, ei); 1141 //System.out.println("bp = " + bp); 1142 assertEquals("interpolate(a)(ei) == a ", bp, ap); 1143 1144 1145 // next evaluation polynomial 1146 Qp = ufac.univariate(0); 1147 Qp = Qp.subtract(ufac.getONE().multiply(ei)); 1148 //System.out.println("Qp = " + Qp); 1149 Q = Q.multiply(Qp); 1150 //System.out.println("Q = " + Q); 1151 } while (qdeg <= deg); 1152 1153 //System.out.println("a = " + a); 1154 //System.out.println("r = " + r); 1155 1156 // interpolate( a(e1), ..., a(ei) ) = a (mod 19) 1157 assertEquals("interpolate(a mod (x-e1),...,a mod (x-ei)) = a (mod 19)", a, r); 1158 } 1159 1160 1161 /** 1162 * Test coefficient map function. 1163 */ 1164 public void testMap() { 1165 // integers 1166 BigInteger fi = new BigInteger(); 1167 //System.out.println("fi = " + fi); 1168 1169 // rational numbers 1170 BigRational fr = new BigRational(); 1171 //System.out.println("fr = " + fr); 1172 1173 // modular integers 1174 ModIntegerRing fm = new ModIntegerRing(17); 1175 //System.out.println("fm = " + fm); 1176 1177 // polynomials over integral numbers 1178 GenPolynomialRing<BigInteger> pfi = new GenPolynomialRing<BigInteger>(fi, rl); 1179 //System.out.println("pfi = " + pfi); 1180 1181 // polynomials over rational numbers 1182 GenPolynomialRing<BigRational> pfr = new GenPolynomialRing<BigRational>(fr, rl); 1183 //System.out.println("pfr = " + pfr); 1184 1185 // polynomials over modular integers 1186 GenPolynomialRing<ModInteger> pfm = new GenPolynomialRing<ModInteger>(fm, rl); 1187 //System.out.println("pfm = " + pfm); 1188 1189 1190 // random polynomial 1191 GenPolynomial<BigInteger> pi = pfi.random(kl, 2 * ll, el, q); 1192 //System.out.println("pi = " + pi); 1193 1194 // random polynomial 1195 GenPolynomial<BigRational> pr = pfr.random(kl, 2 * ll, el, q).monic(); 1196 //System.out.println("pr = " + pr); 1197 1198 // random polynomial 1199 GenPolynomial<ModInteger> pm = pfm.random(kl, 2 * ll, el, q); 1200 //System.out.println("pm = " + pm); 1201 1202 // test integer to rational and back 1203 GenPolynomial<BigRational> qr; 1204 GenPolynomial<BigInteger> qi; 1205 qr = PolyUtil.<BigInteger, BigRational> map(pfr, pi, new FromInteger<BigRational>(fr)); 1206 qi = PolyUtil.<BigRational, BigInteger> map(pfi, qr, new RatNumer()); 1207 //System.out.println("qr = " + qr); 1208 //System.out.println("qi = " + qi); 1209 assertEquals("pi == qi ", pi, qi); 1210 1211 // test rational to integer and back 1212 qi = PolyUtil.integerFromRationalCoefficients(pfi, pr); 1213 qr = PolyUtil.<BigInteger, BigRational> map(pfr, qi, new FromInteger<BigRational>(fr)); 1214 qr = qr.monic(); 1215 //System.out.println("pr = " + pr); 1216 //System.out.println("qr = " + qr); 1217 //System.out.println("qi = " + qi); 1218 assertEquals("pr == qr ", pr, qr); 1219 1220 // test symmetric modular integer to integer and back 1221 GenPolynomial<ModInteger> qm; 1222 qi = PolyUtil.<ModInteger, BigInteger> map(pfi, pm, new ModSymToInt<ModInteger>()); 1223 qm = PolyUtil.<BigInteger, ModInteger> map(pfm, qi, new FromInteger<ModInteger>(fm)); 1224 //System.out.println("qi = " + qi); 1225 //System.out.println("qm = " + qm); 1226 assertEquals("pm == qm ", pm, qm); 1227 1228 // test modular integer to integer and back 1229 qi = PolyUtil.<ModInteger, BigInteger> map(pfi, pm, new ModToInt<ModInteger>()); 1230 qm = PolyUtil.<BigInteger, ModInteger> map(pfm, qi, new FromInteger<ModInteger>(fm)); 1231 //System.out.println("qi = " + qi); 1232 //System.out.println("qm = " + qm); 1233 assertEquals("pm == qm ", pm, qm); 1234 1235 // test symmetric modular integer to integer to rational and back 1236 qi = PolyUtil.<ModInteger, BigInteger> map(pfi, pm, new ModSymToInt<ModInteger>()); 1237 qr = PolyUtil.<BigInteger, BigRational> map(pfr, qi, new FromInteger<BigRational>(fr)); 1238 qi = PolyUtil.<BigRational, BigInteger> map(pfi, qr, new RatNumer()); 1239 qm = PolyUtil.<BigInteger, ModInteger> map(pfm, qi, new FromInteger<ModInteger>(fm)); 1240 //System.out.println("qi = " + qi); 1241 //System.out.println("qm = " + qm); 1242 assertEquals("pm == qm ", pm, qm); 1243 } 1244 1245 1246 /** 1247 * Test substitution. 1248 */ 1249 public void testSubstitution() { 1250 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 1, to); 1251 1252 // subs = x - 7 1253 GenPolynomial<BigInteger> s = dfac.univariate(0).subtract(dfac.fromInteger(7)); 1254 GenPolynomial<BigInteger> s1 = dfac.univariate(0).sum(dfac.fromInteger(7)); 1255 //System.out.println("s = " + s); 1256 //System.out.println("s1 = " + s1); 1257 1258 for (int i = 0; i < 5; i++) { 1259 a = dfac.random(kl, ll, el, q); 1260 //System.out.println("a = " + a); 1261 b = PolyUtil.<BigInteger> substituteMain(a, s); 1262 c = PolyUtil.<BigInteger> substituteMain(b, s1); 1263 //System.out.println("b = " + b); 1264 //System.out.println("c = " + c); 1265 //System.out.println("a == c " + a.equals(c)); 1266 assertEquals("a == c ", a, c); 1267 } 1268 } 1269 1270 1271 /** 1272 * Test algebraic substitution. 1273 */ 1274 public void testAlgebraicSubstitution() { 1275 1276 BigRational cfac = new BigRational(1); 1277 String[] alpha = new String[] { "alpha" }; 1278 String[] vars = new String[] { "z" }; 1279 GenPolynomialRing<BigRational> pfac = new GenPolynomialRing<BigRational>(cfac, 1, to, alpha); 1280 GenPolynomial<BigRational> agen = pfac.univariate(0, 2); 1281 agen = agen.sum(pfac.getONE()); // x^2 + 1 1282 AlgebraicNumberRing<BigRational> afac = new AlgebraicNumberRing<BigRational>(agen, true); 1283 GenPolynomialRing<AlgebraicNumber<BigRational>> apfac = new GenPolynomialRing<AlgebraicNumber<BigRational>>( 1284 afac, 1, to, vars); // univariate 1285 1286 //System.out.println("agen = " + agen); 1287 //System.out.println("afac = " + afac); 1288 //System.out.println("apfac = " + apfac); 1289 1290 // subs = x - 7 1291 GenPolynomial<AlgebraicNumber<BigRational>> s = apfac.univariate(0) 1292 .subtract(apfac.fromInteger(7).multiply(afac.getGenerator())); 1293 GenPolynomial<AlgebraicNumber<BigRational>> s1 = apfac.univariate(0) 1294 .sum(apfac.fromInteger(7).multiply(afac.getGenerator())); 1295 //System.out.println("s = " + s); 1296 //System.out.println("s1 = " + s1); 1297 1298 GenPolynomial<AlgebraicNumber<BigRational>> a, b, c; 1299 for (int i = 0; i < 5; i++) { 1300 a = apfac.random(kl, ll, el, q); 1301 //System.out.println("a = " + a); 1302 b = PolyUtil.<AlgebraicNumber<BigRational>> substituteMain(a, s); 1303 c = PolyUtil.<AlgebraicNumber<BigRational>> substituteMain(b, s1); 1304 //System.out.println("b = " + b); 1305 //System.out.println("c = " + c); 1306 //System.out.println("a == c " + a.equals(c)); 1307 assertEquals("a == c ", a, c); 1308 } 1309 } 1310 1311 1312 /** 1313 * Test multivariate substitution. 1314 */ 1315 public void testMultivarSubstitution() { 1316 dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 2, to); 1317 // subs = x - 7 1318 GenPolynomial<BigInteger> s = dfac.univariate(0).subtract(dfac.fromInteger(7)); 1319 GenPolynomial<BigInteger> s1 = dfac.univariate(0).sum(dfac.fromInteger(7)); 1320 //System.out.println("s = " + s); 1321 //System.out.println("s1 = " + s1); 1322 1323 for (int i = 0; i < 5; i++) { 1324 a = dfac.random(kl, ll, el, q); 1325 //System.out.println("a = " + a); 1326 b = PolyUtil.<BigInteger> substituteUnivariateMult(a, s); 1327 c = PolyUtil.<BigInteger> substituteUnivariateMult(b, s1); 1328 //System.out.println("b = " + b); 1329 //System.out.println("c = " + c); 1330 //System.out.println("a == c " + a.equals(c)); 1331 assertEquals("a == c ", a, c); 1332 } 1333 } 1334 1335 1336 /** 1337 * Test switch variables. 1338 */ 1339 public void testSwitchVariables() { 1340 BigRational cfac = new BigRational(1); 1341 GenPolynomialRing<BigRational> pfac = new GenPolynomialRing<BigRational>(cfac, rl, to); 1342 GenPolynomialRing<GenPolynomial<BigRational>> rfac = new GenPolynomialRing<GenPolynomial<BigRational>>( 1343 pfac, rl, to); 1344 1345 //System.out.println("pfac = " + pfac); 1346 //System.out.println("rfac = " + rfac); 1347 1348 GenPolynomial<GenPolynomial<BigRational>> a, c; 1349 GenPolynomial<GenPolynomial<BigRational>> b; 1350 for (int i = 0; i < 5; i++) { 1351 a = rfac.random(kl, ll, el, q); 1352 //System.out.println("a = " + a); 1353 b = PolyUtil.<BigRational> switchVariables(a); 1354 c = PolyUtil.<BigRational> switchVariables(b); 1355 //System.out.println("b = " + b); 1356 //System.out.println("c = " + c); 1357 //System.out.println("a == c " + a.equals(c)); 1358 assertEquals("a == c ", a, c); 1359 } 1360 } 1361 1362 1363 /** 1364 * Test algebraic conversions. 1365 */ 1366 public void testAlgebraicConversions() { 1367 1368 BigRational cfac = new BigRational(1); 1369 String[] alpha = new String[] { "alpha" }; 1370 //String[] vars = new String[] { "z" }; 1371 GenPolynomialRing<BigRational> pfac = new GenPolynomialRing<BigRational>(cfac, 1, to, alpha); 1372 GenPolynomial<BigRational> agen = pfac.univariate(0, 2); 1373 agen = agen.sum(pfac.getONE()); // x^2 + 1 1374 AlgebraicNumberRing<BigRational> afac = new AlgebraicNumberRing<BigRational>(agen, true); 1375 GenPolynomialRing<AlgebraicNumber<BigRational>> apfac = new GenPolynomialRing<AlgebraicNumber<BigRational>>( 1376 afac, rl, to); 1377 GenPolynomialRing<GenPolynomial<BigRational>> rfac = new GenPolynomialRing<GenPolynomial<BigRational>>( 1378 pfac, rl, to); 1379 1380 //System.out.println("agen = " + agen); 1381 //System.out.println("afac = " + afac); 1382 //System.out.println("apfac = " + apfac); 1383 //System.out.println("pfac = " + pfac); 1384 //System.out.println("rfac = " + rfac); 1385 1386 GenPolynomial<AlgebraicNumber<BigRational>> a, c; 1387 GenPolynomial<GenPolynomial<BigRational>> b; 1388 for (int i = 0; i < 5; i++) { 1389 a = apfac.random(kl, ll, el, q); 1390 //System.out.println("a = " + a); 1391 b = PolyUtil.<BigRational> fromAlgebraicCoefficients(rfac, a); 1392 c = PolyUtil.<BigRational> convertRecursiveToAlgebraicCoefficients(apfac, b); 1393 //System.out.println("b = " + b); 1394 //System.out.println("c = " + c); 1395 //System.out.println("a == c " + a.equals(c)); 1396 assertEquals("a == c ", a, c); 1397 } 1398 } 1399 1400 1401 /** 1402 * Test Taylor series. 1403 */ 1404 public void testTaylorSeries() { 1405 GenPolynomial<BigRational> a; 1406 GenPolynomial<BigRational> b; 1407 GenPolynomial<BigRational> c; 1408 GenPolynomialRing<BigRational> dfac; 1409 BigRational cfac; 1410 1411 cfac = new BigRational(1); 1412 String[] vars = new String[] { "x" }; 1413 dfac = new GenPolynomialRing<BigRational>(cfac, 1, to, vars); 1414 1415 a = dfac.random(kl, ll, el, q); 1416 //System.out.println("a = " + a); 1417 1418 BigRational v = cfac.getZERO(); 1419 //System.out.println("v = " + v); 1420 1421 b = PolyUtil.<BigRational> seriesOfTaylor(a, v); 1422 //System.out.println("taylor(a,0) = " + b); 1423 assertTrue("taylor(a,0) == a ", a.equals(b)); 1424 1425 v = cfac.random(kl); 1426 //System.out.println("v = " + v); 1427 1428 b = PolyUtil.<BigRational> seriesOfTaylor(a, v); 1429 //System.out.println("taylor(a,v) = " + b); 1430 1431 c = PolyUtil.<BigRational> seriesOfTaylor(b, v.negate()); 1432 //System.out.println("tailor(taylor(a,v),-v) = " + c); 1433 assertTrue("tailor(taylor(a,v),-v) == a ", a.equals(c)); 1434 } 1435 1436 1437 /** 1438 * Test Complex real and imaginary part. 1439 */ 1440 public void testComplexParts() { 1441 BigRational rf = new BigRational(1); 1442 GenPolynomialRing<BigRational> rfac = new GenPolynomialRing<BigRational>(rf, rl, to); 1443 1444 ComplexRing<BigRational> cf = new ComplexRing<BigRational>(new BigRational(1)); 1445 GenPolynomialRing<Complex<BigRational>> cfac = new GenPolynomialRing<Complex<BigRational>>(cf, rl, 1446 to); 1447 1448 Complex<BigRational> imag = cf.getIMAG(); 1449 1450 GenPolynomial<BigRational> rp; 1451 GenPolynomial<BigRational> ip; 1452 GenPolynomial<Complex<BigRational>> crp; 1453 GenPolynomial<Complex<BigRational>> cip; 1454 GenPolynomial<Complex<BigRational>> cp; 1455 GenPolynomial<Complex<BigRational>> ap; 1456 1457 for (int i = 0; i < 3; i++) { 1458 cp = cfac.random(kl + 2 * i, ll * (i + 1), el + i, q); 1459 1460 assertTrue("length( c" + i + " ) <> 0", cp.length() >= 0); 1461 assertTrue(" not isZERO( c" + i + " )", !cp.isZERO()); 1462 assertTrue(" not isONE( c" + i + " )", !cp.isONE()); 1463 1464 rp = PolyUtil.<BigRational> realPartFromComplex(rfac, cp); 1465 ip = PolyUtil.<BigRational> imaginaryPartFromComplex(rfac, cp); 1466 1467 crp = PolyUtil.<BigRational> toComplex(cfac, rp); 1468 cip = PolyUtil.<BigRational> toComplex(cfac, ip); 1469 1470 ap = crp.sum(cip.multiply(imag)); 1471 1472 //System.out.println("cp = " + cp); 1473 //System.out.println("rp = " + rp); 1474 //System.out.println("ip = " + ip); 1475 //System.out.println("crp = " + crp); 1476 //System.out.println("cip = " + cip); 1477 //System.out.println("ap = " + ap); 1478 1479 assertEquals("re(c)+i*im(c) = c", cp, ap); 1480 } 1481 } 1482 1483 1484 /** 1485 * Test product represenation conversion, rational numbers. 1486 */ 1487 public void testProductConversionRN() { 1488 GenPolynomialRing<BigRational> ufac; 1489 ufac = new GenPolynomialRing<BigRational>(new BigRational(1), 1); 1490 1491 ProductRing<GenPolynomial<BigRational>> pfac; 1492 pfac = new ProductRing<GenPolynomial<BigRational>>(ufac, rl); 1493 1494 GenPolynomialRing<BigRational> dfac = new GenPolynomialRing<BigRational>(new BigRational(1), rl, to); 1495 1496 GenPolynomial<BigRational> c; 1497 Product<GenPolynomial<BigRational>> cp; 1498 1499 c = dfac.getONE(); 1500 //System.out.println("c = " + c); 1501 1502 cp = PolyUtil.<BigRational> toProduct(pfac, c); 1503 //System.out.println("cp = " + cp); 1504 assertTrue("isONE( cp )", cp.isONE()); 1505 1506 c = dfac.random(kl, ll, el, q); 1507 //System.out.println("c = " + c); 1508 1509 cp = PolyUtil.<BigRational> toProduct(pfac, c); 1510 //System.out.println("cp = " + cp); 1511 assertTrue("!isONE( cp )", !cp.isONE()); 1512 } 1513 1514 1515 /** 1516 * Test polynomal over product represenation conversion, algebraic numbers. 1517 */ 1518 public void testPolyProductConversionAN() { 1519 GenPolynomialRing<BigRational> ufac; 1520 ufac = new GenPolynomialRing<BigRational>(new BigRational(1), 1); 1521 1522 GenPolynomial<BigRational> m; 1523 m = ufac.univariate(0, 2); 1524 m = m.subtract(ufac.univariate(0, 1)); 1525 //System.out.println("m = " + m); 1526 1527 AlgebraicNumberRing<BigRational> afac; 1528 afac = new AlgebraicNumberRing<BigRational>(m); 1529 //System.out.println("afac = " + afac); 1530 1531 ProductRing<AlgebraicNumber<BigRational>> pfac; 1532 pfac = new ProductRing<AlgebraicNumber<BigRational>>(afac, rl); 1533 1534 GenPolynomialRing<Product<AlgebraicNumber<BigRational>>> dpfac; 1535 dpfac = new GenPolynomialRing<Product<AlgebraicNumber<BigRational>>>(pfac, 2); 1536 1537 GenPolynomialRing<AlgebraicNumber<BigRational>> dfac; 1538 dfac = new GenPolynomialRing<AlgebraicNumber<BigRational>>(afac, 2, to); 1539 1540 1541 GenPolynomial<AlgebraicNumber<BigRational>> c; 1542 GenPolynomial<Product<AlgebraicNumber<BigRational>>> cp; 1543 1544 c = dfac.getONE(); 1545 //System.out.println("c = " + c); 1546 1547 cp = PolyUtil.<AlgebraicNumber<BigRational>> toProductGen(dpfac, c); 1548 //System.out.println("cp = " + cp); 1549 assertTrue("isZERO( cp )", cp.isONE()); 1550 1551 c = dfac.random(kl, ll, el, q); 1552 //System.out.println("c = " + c); 1553 1554 cp = PolyUtil.<AlgebraicNumber<BigRational>> toProductGen(dpfac, c); 1555 //System.out.println("cp = " + cp); 1556 assertTrue("!isONE( cp )", !cp.isONE()); 1557 } 1558 1559 1560 /** 1561 * Test remove unused upper varaibles. 1562 */ 1563 public void testRemoveUnusedUpper() { 1564 //System.out.println("dfac = " + dfac); 1565 a = dfac.univariate(3, 2); 1566 b = a.subtract(dfac.univariate(1, 1)); 1567 //System.out.println("a = " + a); 1568 //System.out.println("b = " + b); 1569 1570 c = PolyUtil.<BigInteger> removeUnusedUpperVariables(b); 1571 //System.out.println("c = " + c + ", fac = " + c.ring); 1572 assertTrue("#var == 4: " + c.ring.nvar, c.ring.nvar == 4); 1573 1574 a = dfac.univariate(3, 2); 1575 //System.out.println("a = " + a); 1576 1577 c = PolyUtil.<BigInteger> removeUnusedUpperVariables(a); 1578 //System.out.println("c = " + c + ", fac = " + c.ring); 1579 assertTrue("#var == 2: " + c.ring.nvar, c.ring.nvar == 2); 1580 1581 a = dfac.univariate(1, 2); 1582 //System.out.println("a = " + a); 1583 1584 c = PolyUtil.<BigInteger> removeUnusedUpperVariables(a); 1585 //System.out.println("c = " + c + ", fac = " + c.ring); 1586 assertTrue("#var == 4: " + c.ring.nvar, c.ring.nvar == 4); 1587 } 1588 1589 1590 /** 1591 * Test remove unused lower varaibles. 1592 */ 1593 public void testRemoveUnusedLower() { 1594 //System.out.println("dfac = " + dfac); 1595 a = dfac.univariate(3, 2); 1596 b = a.subtract(dfac.univariate(1, 1)); 1597 //System.out.println("a = " + a); 1598 //System.out.println("b = " + b); 1599 1600 c = PolyUtil.<BigInteger> removeUnusedLowerVariables(b); 1601 //System.out.println("c = " + c + ", fac = " + c.ring); 1602 assertTrue("#var == 4: " + c.ring.nvar, c.ring.nvar == 4); 1603 1604 a = dfac.univariate(3, 2); 1605 //System.out.println("a = " + a); 1606 1607 c = PolyUtil.<BigInteger> removeUnusedLowerVariables(a); 1608 //System.out.println("c = " + c + ", fac = " + c.ring); 1609 assertTrue("#var == 4: " + c.ring.nvar, c.ring.nvar == 4); 1610 1611 a = dfac.univariate(1, 2); 1612 //System.out.println("a = " + a); 1613 1614 c = PolyUtil.<BigInteger> removeUnusedLowerVariables(a); 1615 //System.out.println("c = " + c + ", fac = " + c.ring); 1616 assertTrue("#var == 2: " + c.ring.nvar, c.ring.nvar == 2); 1617 } 1618 1619 1620 /** 1621 * Test remove unused middle varaibles. 1622 */ 1623 public void testRemoveUnusedMiddle() { 1624 //System.out.println("dfac = " + dfac); 1625 a = dfac.univariate(4, 2); 1626 b = a.subtract(dfac.univariate(0, 1)); 1627 //System.out.println("a = " + a); 1628 //System.out.println("b = " + b); 1629 1630 c = PolyUtil.<BigInteger> removeUnusedLowerVariables(b); 1631 //System.out.println("c = " + c + ", fac = " + c.ring); 1632 assertTrue("#var == 5: " + c.ring.nvar, c.ring.nvar == 5); 1633 c = PolyUtil.<BigInteger> removeUnusedUpperVariables(c); 1634 //System.out.println("c = " + c + ", fac = " + c.ring); 1635 assertTrue("#var == 5: " + c.ring.nvar, c.ring.nvar == 5); 1636 1637 c = PolyUtil.<BigInteger> removeUnusedMiddleVariables(c); 1638 //System.out.println("c = " + c + ", fac = " + c.ring); 1639 assertTrue("#var == 2: " + c.ring.nvar, c.ring.nvar == 2); 1640 1641 a = dfac.univariate(3, 2); 1642 b = a.subtract(dfac.univariate(1, 1)); 1643 //System.out.println("a = " + a); 1644 //System.out.println("b = " + b); 1645 1646 try { 1647 c = PolyUtil.<BigInteger> removeUnusedMiddleVariables(b); 1648 fail("c = " + c + ", fac = " + c.ring); 1649 } catch (RuntimeException e) { 1650 // success 1651 } 1652 1653 c = PolyUtil.<BigInteger> removeUnusedLowerVariables(b); 1654 //System.out.println("c = " + c + ", fac = " + c.ring); 1655 assertTrue("#var == 4: " + c.ring.nvar, c.ring.nvar == 4); 1656 c = PolyUtil.<BigInteger> removeUnusedUpperVariables(c); 1657 //System.out.println("c = " + c + ", fac = " + c.ring); 1658 assertTrue("#var == 3: " + c.ring.nvar, c.ring.nvar == 3); 1659 1660 c = PolyUtil.<BigInteger> removeUnusedMiddleVariables(c); 1661 //System.out.println("c = " + c + ", fac = " + c.ring); 1662 assertTrue("#var == 2: " + c.ring.nvar, c.ring.nvar == 2); 1663 } 1664 1665 1666 /** 1667 * Test transformation. 1668 */ 1669 public void testTransformation() { 1670 //dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 1, to); 1671 //System.out.println("ring = " + dfac.toScript()); 1672 c = dfac.getONE(); 1673 //System.out.println("c = " + c); 1674 a = PolyUtil.reciprocalTransformation(c); 1675 //System.out.println("a = " + a); 1676 1677 d = dfac.getZERO(); 1678 //System.out.println("d = " + d); 1679 b = PolyUtil.reciprocalTransformation(d); 1680 //System.out.println("b = " + b); 1681 1682 c = dfac.random(kl * 2, ll + 2, el * 2, q+q); 1683 //System.out.println("c = " + c); 1684 a = PolyUtil.reciprocalTransformation(c); 1685 //System.out.println("a = " + a); 1686 b = PolyUtil.reciprocalTransformation(a); 1687 //System.out.println("b = " + b); 1688 assertEquals("recip(recip(c)) == c: ", c, b); 1689 1690 for (int i = 0; i < rl; i++) { 1691 //System.out.println("i = " + i + ", deg(c,i) = " + c.degree(i)); 1692 a = PolyUtil.reciprocalTransformation(c,i); 1693 //System.out.println("a = " + a); 1694 b = PolyUtil.reciprocalTransformation(a,i); 1695 //System.out.println("b = " + b); 1696 assertEquals("recip(recip(c)) == c: ", c, b); 1697 //break; 1698 } 1699 } 1700 1701 1702 /** 1703 * Test translation. 1704 */ 1705 public void testTranslation() { 1706 //dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), 1, to); 1707 //System.out.println("ring = " + rfac.toScript()); 1708 ai = new BigInteger(5); 1709 //System.out.println("ai = " + ai); 1710 1711 cr = rfac.getONE(); 1712 //System.out.println("cr = " + cr); 1713 ar = PolyUtil.translationMainRecursive(cr, ai); 1714 //System.out.println("ar = " + ar); 1715 br = PolyUtil.translationMainRecursive(ar, ai.negate()); 1716 //System.out.println("br = " + br); 1717 assertEquals("translat(translat(cr)) == cr: ", cr, br); 1718 1719 dr = rfac.getZERO(); 1720 //System.out.println("dr = " + dr); 1721 ar = PolyUtil.translationMainRecursive(dr, ai); 1722 //System.out.println("ar = " + ar); 1723 br = PolyUtil.translationMainRecursive(ar, ai.negate()); 1724 //System.out.println("br = " + br); 1725 assertEquals("translat(translat(dr)) == dr: ", dr, br); 1726 1727 cr = rfac.univariate(0).power(3); 1728 cr = cr.sum(cr.power(5)); 1729 //System.out.println("cr = " + cr); 1730 ar = PolyUtil.translationMainRecursive(cr, ai); 1731 //System.out.println("ar = " + ar); 1732 br = PolyUtil.translationMainRecursive(ar, ai.negate()); 1733 //System.out.println("br = " + br); 1734 assertEquals("translat(translat(cr)) == cr: ", cr, br); 1735 1736 1737 //System.out.println("ring = " + dfac.toScript()); 1738 c = dfac.getONE(); 1739 //System.out.println("c = " + c); 1740 a = PolyUtil.translationMain(c, ai); 1741 //System.out.println("a = " + a); 1742 b = PolyUtil.translationMain(a, ai.negate()); 1743 //System.out.println("b = " + b); 1744 assertEquals("translat(translat(c)) == c: ", c, b); 1745 1746 c = dfac.univariate(0).power(2); 1747 c = c.sum(c.power(6)); 1748 //System.out.println("c = " + c); 1749 a = PolyUtil.translationMain(c, ai); 1750 //System.out.println("a = " + a); 1751 b = PolyUtil.translationMain(a, ai.negate()); 1752 //System.out.println("b = " + b); 1753 assertEquals("translat(translat(c)) == c: ", c, b); 1754 1755 List<BigInteger> H = new ArrayList<BigInteger>(rl); 1756 List<BigInteger> Hm = new ArrayList<BigInteger>(rl); 1757 for (int i = 1; i <= rl; i++) { 1758 H.add(new BigInteger(i)); 1759 Hm.add(new BigInteger(-i)); 1760 } 1761 //System.out.println("H = " + H + ", Hm = " + Hm); 1762 1763 c = dfac.univariate(0).power(2); 1764 c = c.sum(c.power(5)); 1765 c = c.multiply( dfac.univariate(1).power(3) ); 1766 c = c.multiply( dfac.univariate(2).power(4) ); 1767 c = c.sum( dfac.univariate(3).power(7) ); 1768 c = c.sum( dfac.univariate(4).power(11) ); 1769 //System.out.println("c = " + c); 1770 a = PolyUtil.translation(c, H); 1771 //System.out.println("a = " + a); 1772 b = PolyUtil.translation(a, Hm); 1773 //System.out.println("b = " + b); 1774 assertEquals("translat(translat(c)) == c: ", c, b); 1775 1776 c = dfac.random(kl * 2, ll + 2, el * 2, q+q); 1777 //System.out.println("c = " + c); 1778 a = PolyUtil.translation(c, H); 1779 //System.out.println("a = " + a); 1780 b = PolyUtil.translation(a, Hm); 1781 //System.out.println("b = " + b); 1782 assertEquals("translat(translat(c)) == c: ", c, b); 1783 } 1784 1785}