001/* 002 * $Id: IdealTest.java 4125 2012-08-19 19:05:22Z kredel $ 003 */ 004 005package edu.jas.application; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import junit.framework.Test; 012import junit.framework.TestCase; 013import junit.framework.TestSuite; 014 015import org.apache.log4j.BasicConfigurator; 016import org.apache.log4j.Logger; 017 018import edu.jas.arith.BigDecimal; 019import edu.jas.arith.BigRational; 020import edu.jas.gb.GroebnerBase; 021import edu.jas.gbufd.GBFactory; 022import edu.jas.kern.ComputerThreads; 023import edu.jas.poly.Complex; 024import edu.jas.poly.ComplexRing; 025import edu.jas.poly.GenPolynomial; 026import edu.jas.poly.GenPolynomialRing; 027import edu.jas.poly.PolyUtil; 028import edu.jas.poly.PolynomialList; 029import edu.jas.poly.TermOrder; 030import edu.jas.ufd.Quotient; 031import edu.jas.util.KsubSet; 032 033 034/** 035 * Ideal tests with JUnit. 036 * @author Heinz Kredel. 037 */ 038public class IdealTest extends TestCase { 039 040 041 private static final Logger logger = Logger.getLogger(IdealTest.class); 042 043 044 /** 045 * main 046 */ 047 public static void main(String[] args) { 048 BasicConfigurator.configure(); 049 junit.textui.TestRunner.run(suite()); 050 } 051 052 053 /** 054 * Constructs a <CODE>IdealTest</CODE> object. 055 * @param name String. 056 */ 057 public IdealTest(String name) { 058 super(name); 059 } 060 061 062 /** 063 * suite. 064 */ 065 public static Test suite() { 066 TestSuite suite = new TestSuite(IdealTest.class); 067 return suite; 068 } 069 070 071 TermOrder to; 072 073 074 GenPolynomialRing<BigRational> fac; 075 076 077 List<GenPolynomial<BigRational>> L; 078 079 080 PolynomialList<BigRational> F; 081 082 083 List<GenPolynomial<BigRational>> G; 084 085 086 List<? extends GenPolynomial<BigRational>> M; 087 088 089 GroebnerBase<BigRational> bb; 090 091 092 GenPolynomial<BigRational> a; 093 094 095 GenPolynomial<BigRational> b; 096 097 098 GenPolynomial<BigRational> c; 099 100 101 GenPolynomial<BigRational> d; 102 103 104 GenPolynomial<BigRational> e; 105 106 107 int rl = 3; //4; //3; 108 109 110 int kl = 4; //10 111 112 113 int ll = 5; //7 114 115 116 int el = 3; 117 118 119 float q = 0.2f; //0.4f 120 121 122 @Override 123 protected void setUp() { 124 BigRational coeff = new BigRational(17, 1); 125 to = new TermOrder( /*TermOrder.INVLEX*/); 126 String[] vars = new String[] { "x", "y", "z" }; 127 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 128 //bb = new GroebnerBaseSeq<BigRational>(); 129 bb = GBFactory.getImplementation(coeff); 130 a = b = c = d = e = null; 131 } 132 133 134 @Override 135 protected void tearDown() { 136 a = b = c = d = e = null; 137 fac = null; 138 bb = null; 139 ComputerThreads.terminate(); 140 } 141 142 143 /** 144 * Test Ideal sum. 145 */ 146 public void testIdealSum() { 147 148 Ideal<BigRational> I; 149 Ideal<BigRational> J; 150 Ideal<BigRational> K; 151 152 L = new ArrayList<GenPolynomial<BigRational>>(); 153 154 a = fac.random(kl, ll, el, q); 155 b = fac.random(kl, ll, el, q); 156 c = fac.random(kl, ll, el, q); 157 d = fac.random(kl, ll, el, q); 158 e = d; //fac.random(kl, ll, el, q ); 159 160 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 161 return; 162 } 163 164 assertTrue("not isZERO( a )", !a.isZERO()); 165 L.add(a); 166 167 I = new Ideal<BigRational>(fac, L, true); 168 assertTrue("not isZERO( I )", !I.isZERO()); 169 assertTrue("not isONE( I )", !I.isONE()); 170 assertTrue("isGB( I )", I.isGB()); 171 172 I = new Ideal<BigRational>(fac, L, false); 173 assertTrue("not isZERO( I )", !I.isZERO()); 174 assertTrue("not isONE( I )", !I.isONE()); 175 assertTrue("isGB( I )", I.isGB()); 176 177 178 L = bb.GB(L); 179 assertTrue("isGB( { a } )", bb.isGB(L)); 180 181 I = new Ideal<BigRational>(fac, L, true); 182 assertTrue("not isZERO( I )", !I.isZERO()); 183 //assertTrue("not isONE( I )", !I.isONE() ); 184 assertTrue("isGB( I )", I.isGB()); 185 186 I = new Ideal<BigRational>(fac, L, false); 187 assertTrue("not isZERO( I )", !I.isZERO()); 188 //assertTrue("not isONE( I )", !I.isONE() ); 189 assertTrue("isGB( I )", I.isGB()); 190 191 192 assertTrue("not isZERO( b )", !b.isZERO()); 193 L.add(b); 194 //System.out.println("L = " + L.size() ); 195 196 I = new Ideal<BigRational>(fac, L, false); 197 assertTrue("not isZERO( I )", !I.isZERO()); 198 //assertTrue("not isONE( I )", !I.isONE() ); 199 //assertTrue("not isGB( I )", !I.isGB() ); 200 201 202 L = bb.GB(L); 203 assertTrue("isGB( { a, b } )", bb.isGB(L)); 204 205 I = new Ideal<BigRational>(fac, L, true); 206 assertTrue("not isZERO( I )", !I.isZERO()); 207 // assertTrue("not isONE( I )", !I.isONE() ); 208 assertTrue("isGB( I )", I.isGB()); 209 210 211 J = I; 212 K = J.sum(I); 213 assertTrue("not isZERO( K )", !K.isZERO()); 214 assertTrue("isGB( K )", K.isGB()); 215 assertTrue("equals( K, I )", K.equals(I)); 216 217 218 L = new ArrayList<GenPolynomial<BigRational>>(); 219 assertTrue("not isZERO( c )", !c.isZERO()); 220 L.add(c); 221 assertTrue("isGB( { c } )", bb.isGB(L)); 222 223 J = new Ideal<BigRational>(fac, L, true); 224 K = J.sum(I); 225 assertTrue("not isZERO( K )", !K.isZERO()); 226 assertTrue("isGB( K )", K.isGB()); 227 assertTrue("K contains(I)", K.contains(I)); 228 assertTrue("K contains(J)", K.contains(J)); 229 230 L = new ArrayList<GenPolynomial<BigRational>>(); 231 assertTrue("not isZERO( d )", !d.isZERO()); 232 L.add(d); 233 234 assertTrue("isGB( { d } )", bb.isGB(L)); 235 J = new Ideal<BigRational>(fac, L, true); 236 I = K; 237 K = J.sum(I); 238 assertTrue("not isZERO( K )", !K.isZERO()); 239 assertTrue("isGB( K )", K.isGB()); 240 assertTrue("K contains(I)", K.contains(I)); 241 assertTrue("K contains(J)", K.contains(J)); 242 243 244 L = new ArrayList<GenPolynomial<BigRational>>(); 245 assertTrue("not isZERO( e )", !e.isZERO()); 246 L.add(e); 247 248 assertTrue("isGB( { e } )", bb.isGB(L)); 249 J = new Ideal<BigRational>(fac, L, true); 250 I = K; 251 K = J.sum(I); 252 assertTrue("not isZERO( K )", !K.isZERO()); 253 assertTrue("isGB( K )", K.isGB()); 254 assertTrue("equals( K, I )", K.equals(I)); 255 assertTrue("K contains(J)", K.contains(I)); 256 assertTrue("I contains(K)", I.contains(K)); 257 } 258 259 260 /** 261 * Test Ideal product. 262 */ 263 public void testIdealProduct() { 264 265 Ideal<BigRational> I; 266 Ideal<BigRational> J; 267 Ideal<BigRational> K; 268 Ideal<BigRational> H; 269 270 a = fac.random(kl, ll, el, q); 271 b = fac.random(kl, ll, el, q); 272 c = fac.random(kl, ll, el, q); 273 d = fac.random(kl, ll, el, q); 274 e = d; //fac.random(kl, ll, el, q ); 275 276 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 277 return; 278 } 279 280 L = new ArrayList<GenPolynomial<BigRational>>(); 281 assertTrue("not isZERO( a )", !a.isZERO()); 282 L.add(a); 283 284 I = new Ideal<BigRational>(fac, L, true); 285 assertTrue("not isZERO( I )", !I.isZERO()); 286 assertTrue("not isONE( I )", !I.isONE()); 287 assertTrue("isGB( I )", I.isGB()); 288 289 L = new ArrayList<GenPolynomial<BigRational>>(); 290 assertTrue("not isZERO( b )", !a.isZERO()); 291 L.add(b); 292 293 J = new Ideal<BigRational>(fac, L, true); 294 assertTrue("not isZERO( J )", !J.isZERO()); 295 assertTrue("not isONE( J )", !J.isONE()); 296 assertTrue("isGB( J )", J.isGB()); 297 298 K = I.product(J); 299 assertTrue("not isZERO( K )", !K.isZERO()); 300 assertTrue("isGB( K )", K.isGB()); 301 assertTrue("I contains(K)", I.contains(K)); 302 assertTrue("J contains(K)", J.contains(K)); 303 304 H = I.intersect(J); 305 assertTrue("not isZERO( H )", !H.isZERO()); 306 assertTrue("isGB( H )", H.isGB()); 307 assertTrue("I contains(H)", I.contains(H)); 308 assertTrue("J contains(H)", J.contains(H)); 309 assertTrue("H contains(K)", H.contains(K)); 310 //if (false /*! H.equals(K)*/) { 311 // System.out.println("I = " + I); 312 // System.out.println("J = " + J); 313 // System.out.println("K = " + K); 314 // System.out.println("H = " + H); 315 //} 316 317 318 L = new ArrayList<GenPolynomial<BigRational>>(); 319 assertTrue("not isZERO( a )", !a.isZERO()); 320 L.add(a); 321 assertTrue("not isZERO( c )", !c.isZERO()); 322 L.add(c); 323 L = bb.GB(L); 324 325 I = new Ideal<BigRational>(fac, L, true); 326 assertTrue("not isZERO( I )", !I.isZERO()); 327 //assertTrue("not isONE( I )", !I.isONE() ); 328 assertTrue("isGB( I )", I.isGB()); 329 330 K = I.product(J); 331 assertTrue("not isZERO( K )", !K.isZERO()); 332 assertTrue("isGB( K )", K.isGB()); 333 assertTrue("I contains(K)", I.contains(K)); 334 assertTrue("J contains(K)", J.contains(K)); 335 336 H = I.intersect(J); 337 assertTrue("not isZERO( H )", !H.isZERO()); 338 assertTrue("isGB( H )", H.isGB()); 339 assertTrue("I contains(H)", I.contains(H)); 340 assertTrue("J contains(H)", J.contains(H)); 341 assertTrue("H contains(K)", H.contains(K)); 342 //if (false /*! H.equals(K)*/) { 343 // System.out.println("I = " + I); 344 // System.out.println("J = " + J); 345 // System.out.println("K = " + K); 346 // System.out.println("H = " + H); 347 //} 348 349 350 L = new ArrayList<GenPolynomial<BigRational>>(); 351 assertTrue("not isZERO( b )", !b.isZERO()); 352 L.add(b); 353 assertTrue("not isZERO( d )", !d.isZERO()); 354 L.add(d); 355 L = bb.GB(L); 356 357 J = new Ideal<BigRational>(fac, L, true); 358 assertTrue("not isZERO( J )", !J.isZERO()); 359 //assertTrue("not isONE( J )", !J.isONE() ); 360 assertTrue("isGB( J )", J.isGB()); 361 362 K = I.product(J); 363 assertTrue("not isZERO( K )", !K.isZERO()); 364 assertTrue("isGB( K )", K.isGB()); 365 assertTrue("I contains(K)", I.contains(K)); 366 assertTrue("J contains(K)", J.contains(K)); 367 368 H = I.intersect(J); 369 assertTrue("not isZERO( H )", !H.isZERO()); 370 assertTrue("isGB( H )", H.isGB()); 371 assertTrue("I contains(H)", I.contains(H)); 372 assertTrue("J contains(H)", J.contains(H)); 373 assertTrue("H contains(K)", H.contains(K)); 374 //if (false /*! H.equals(K)*/) { 375 // System.out.println("I = " + I); 376 // System.out.println("J = " + J); 377 // System.out.println("K = " + K); 378 // System.out.println("H = " + H); 379 //} 380 } 381 382 383 /** 384 * Test Ideal quotient. 385 */ 386 public void testIdealQuotient() { 387 388 Ideal<BigRational> I; 389 Ideal<BigRational> J; 390 Ideal<BigRational> K; 391 Ideal<BigRational> H; 392 393 a = fac.random(kl, ll, el, q); 394 b = fac.random(kl, ll, el, q); 395 c = fac.random(kl, ll, el, q); 396 d = fac.random(kl, ll, el, q); 397 e = d; //fac.random(kl, ll, el, q ); 398 399 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 400 return; 401 } 402 403 L = new ArrayList<GenPolynomial<BigRational>>(); 404 assertTrue("not isZERO( a )", !a.isZERO()); 405 L.add(a); 406 L = bb.GB(L); 407 408 I = new Ideal<BigRational>(fac, L, true); 409 assertTrue("not isZERO( I )", !I.isZERO()); 410 //assertTrue("not isONE( I )", !I.isONE() ); 411 assertTrue("isGB( I )", I.isGB()); 412 413 414 L = new ArrayList<GenPolynomial<BigRational>>(); 415 assertTrue("not isZERO( b )", !a.isZERO()); 416 L.add(b); 417 L = bb.GB(L); 418 419 J = new Ideal<BigRational>(fac, L, true); 420 assertTrue("not isZERO( J )", !J.isZERO()); 421 //assertTrue("not isONE( J )", !J.isONE() ); 422 assertTrue("isGB( J )", J.isGB()); 423 424 K = I.product(J); 425 assertTrue("not isZERO( K )", !K.isZERO()); 426 assertTrue("isGB( K )", K.isGB()); 427 assertTrue("I contains(K)", I.contains(K)); 428 assertTrue("J contains(K)", J.contains(K)); 429 430 H = K.quotient(J.getList().get(0)); 431 assertTrue("not isZERO( H )", !H.isZERO()); 432 assertTrue("isGB( H )", H.isGB()); 433 assertTrue("equals(H,I)", H.equals(I)); // GBs only 434 435 H = K.quotient(J); 436 assertTrue("not isZERO( H )", !H.isZERO()); 437 assertTrue("isGB( H )", H.isGB()); 438 assertTrue("equals(H,I)", H.equals(I)); // GBs only 439 440 441 L = new ArrayList<GenPolynomial<BigRational>>(); 442 assertTrue("not isZERO( b )", !b.isZERO()); 443 L.add(b); 444 assertTrue("not isZERO( c )", !c.isZERO()); 445 L.add(c); 446 L = bb.GB(L); 447 448 J = new Ideal<BigRational>(fac, L, true); 449 assertTrue("not isZERO( J )", !J.isZERO()); 450 //assertTrue("not isONE( J )", !J.isONE() ); 451 assertTrue("isGB( J )", J.isGB()); 452 453 K = I.product(J); 454 assertTrue("not isZERO( K )", !K.isZERO()); 455 assertTrue("isGB( K )", K.isGB()); 456 assertTrue("I contains(K)", I.contains(K)); 457 assertTrue("J contains(K)", J.contains(K)); 458 459 H = K.quotient(J); 460 assertTrue("not isZERO( H )", !H.isZERO()); 461 assertTrue("isGB( H )", H.isGB()); 462 assertTrue("equals(H,I)", H.equals(I)); // GBs only 463 464 465 L = new ArrayList<GenPolynomial<BigRational>>(); 466 assertTrue("not isZERO( a )", !a.isZERO()); 467 L.add(a); 468 assertTrue("not isZERO( d )", !d.isZERO()); 469 L.add(d); 470 L = bb.GB(L); 471 472 I = new Ideal<BigRational>(fac, L, true); 473 assertTrue("not isZERO( I )", !I.isZERO()); 474 //assertTrue("not isONE( J )", !J.isONE() ); 475 assertTrue("isGB( I )", I.isGB()); 476 477 K = I.product(J); 478 assertTrue("not isZERO( K )", !K.isZERO()); 479 assertTrue("isGB( K )", K.isGB()); 480 assertTrue("I contains(K)", I.contains(K)); 481 assertTrue("J contains(K)", J.contains(K)); 482 483 H = K.quotient(J); 484 assertTrue("not isZERO( H )", !H.isZERO()); 485 assertTrue("isGB( H )", H.isGB()); 486 assertTrue("equals(H,I)", H.equals(I)); // GBs only 487 } 488 489 490 /** 491 * Test Ideal infinite quotient. 492 */ 493 public void testIdealInfiniteQuotient() { 494 495 Ideal<BigRational> I; 496 Ideal<BigRational> J; 497 Ideal<BigRational> K; 498 499 a = fac.random(kl, ll, el, q); 500 b = fac.random(kl, ll, el, q); 501 c = fac.random(kl, ll, el, q); 502 d = fac.random(kl, ll, el, q); 503 e = d; //fac.random(kl, ll, el, q ); 504 505 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 506 return; 507 } 508 509 L = new ArrayList<GenPolynomial<BigRational>>(); 510 assertTrue("not isZERO( b )", !b.isZERO()); 511 L.add(b); 512 L = bb.GB(L); 513 I = new Ideal<BigRational>(fac, L, true); 514 assertTrue("not isZERO( I )", !I.isZERO()); 515 //assertTrue("not isONE( I )", !I.isONE() ); 516 assertTrue("isGB( I )", I.isGB()); 517 518 J = I.infiniteQuotient(a); 519 520 assertTrue("not isZERO( c )", !c.isZERO()); 521 L.add(c); 522 L = bb.GB(L); 523 I = new Ideal<BigRational>(fac, L, true); 524 assertTrue("not isZERO( I )", !I.isZERO()); 525 //assertTrue("not isONE( I )", !I.isONE() ); 526 assertTrue("isGB( I )", I.isGB()); 527 528 J = I.infiniteQuotient(a); 529 assertTrue("equals(J,I)", J.equals(I)); // GBs only 530 531 assertTrue("not isZERO( d )", !d.isZERO()); 532 L.add(d); 533 L = bb.GB(L); 534 I = new Ideal<BigRational>(fac, L, true); 535 assertTrue("not isZERO( I )", !I.isZERO()); 536 //assertTrue("not isONE( I )", !I.isONE() ); 537 assertTrue("isGB( I )", I.isGB()); 538 539 J = I.infiniteQuotient(a); 540 assertTrue("isGB( J )", J.isGB()); 541 assertTrue("equals(J,I)", J.equals(I)); // GBs only 542 543 544 G = new ArrayList<GenPolynomial<BigRational>>(); 545 assertTrue("not isZERO( a )", !a.isZERO()); 546 G.add(a); 547 G = bb.GB(G); 548 K = new Ideal<BigRational>(fac, G, true); 549 assertTrue("not isZERO( K )", !K.isZERO()); 550 //assertTrue("not isONE( I )", !I.isONE() ); 551 assertTrue("isGB( K )", K.isGB()); 552 553 J = I.infiniteQuotient(K); 554 assertTrue("equals(J,I)", J.equals(I)); // GBs only 555 556 557 assertTrue("not isZERO( e )", !e.isZERO()); 558 G.add(e); 559 G = bb.GB(G); 560 K = new Ideal<BigRational>(fac, G, true); 561 assertTrue("not isZERO( K )", !K.isZERO()); 562 //assertTrue("not isONE( I )", !I.isONE() ); 563 assertTrue("isGB( K )", K.isGB()); 564 565 J = I.infiniteQuotient(K); 566 assertTrue("equals(J,I)", J.equals(I)); // GBs only 567 } 568 569 570 /** 571 * Test Ideal infinite quotient with Rabinowich trick. 572 */ 573 public void testIdealInfiniteQuotientRabi() { 574 575 Ideal<BigRational> I; 576 Ideal<BigRational> J; 577 Ideal<BigRational> K; 578 Ideal<BigRational> JJ; 579 580 a = fac.random(kl - 1, ll - 1, el - 1, q / 2); 581 b = fac.random(kl - 1, ll - 1, el, q / 2); 582 c = fac.random(kl - 1, ll - 1, el, q / 2); 583 d = fac.random(kl - 1, ll - 1, el, q / 2); 584 e = a; //fac.random(kl, ll-1, el, q ); 585 586 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 587 return; 588 } 589 590 L = new ArrayList<GenPolynomial<BigRational>>(); 591 assertTrue("not isZERO( b )", !b.isZERO()); 592 L.add(b); 593 L = bb.GB(L); 594 I = new Ideal<BigRational>(fac, L, true); 595 assertTrue("not isZERO( I )", !I.isZERO()); 596 //assertTrue("not isONE( I )", !I.isONE() ); 597 assertTrue("isGB( I )", I.isGB()); 598 599 J = I.infiniteQuotientRab(a); 600 JJ = I.infiniteQuotient(a); 601 assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only 602 603 assertTrue("not isZERO( c )", !c.isZERO()); 604 L.add(c); 605 L = bb.GB(L); 606 I = new Ideal<BigRational>(fac, L, true); 607 assertTrue("not isZERO( I )", !I.isZERO()); 608 //assertTrue("not isONE( I )", !I.isONE() ); 609 assertTrue("isGB( I )", I.isGB()); 610 611 J = I.infiniteQuotientRab(a); 612 assertTrue("equals(J,I)", J.equals(I)); // GBs only 613 JJ = I.infiniteQuotient(a); 614 assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only 615 616 assertTrue("not isZERO( d )", !d.isZERO()); 617 L.add(d); 618 L = bb.GB(L); 619 I = new Ideal<BigRational>(fac, L, true); 620 assertTrue("not isZERO( I )", !I.isZERO()); 621 //assertTrue("not isONE( I )", !I.isONE() ); 622 assertTrue("isGB( I )", I.isGB()); 623 624 J = I.infiniteQuotientRab(a); 625 assertTrue("isGB( J )", J.isGB()); 626 assertTrue("equals(J,I)", J.equals(I)); // GBs only 627 JJ = I.infiniteQuotient(a); 628 assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only 629 630 631 G = new ArrayList<GenPolynomial<BigRational>>(); 632 assertTrue("not isZERO( a )", !a.isZERO()); 633 G.add(a); 634 G = bb.GB(G); 635 K = new Ideal<BigRational>(fac, G, true); 636 assertTrue("not isZERO( K )", !K.isZERO()); 637 //assertTrue("not isONE( I )", !I.isONE() ); 638 assertTrue("isGB( K )", K.isGB()); 639 640 J = I.infiniteQuotientRab(K); 641 assertTrue("equals(J,I)", J.equals(I)); // GBs only 642 JJ = I.infiniteQuotient(a); 643 assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only 644 645 646 assertTrue("not isZERO( e )", !e.isZERO()); 647 G.add(e); 648 G = bb.GB(G); 649 K = new Ideal<BigRational>(fac, G, true); 650 assertTrue("not isZERO( K )", !K.isZERO()); 651 //assertTrue("not isONE( I )", !I.isONE() ); 652 assertTrue("isGB( K )", K.isGB()); 653 654 J = I.infiniteQuotientRab(K); 655 assertTrue("equals(J,I)", J.equals(I)); // GBs only 656 JJ = I.infiniteQuotient(a); 657 assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only 658 } 659 660 661 /** 662 * Test Ideal radical membership. 663 */ 664 public void testIdealRadicalMember() { 665 666 Ideal<BigRational> I; 667 //Ideal<BigRational> J; 668 //Ideal<BigRational> K; 669 //Ideal<BigRational> JJ; 670 671 a = fac.random(kl - 1, ll, el - 1, q); 672 b = fac.random(kl - 1, ll, el, q); 673 c = fac.random(kl - 1, ll - 1, el, q / 2); 674 d = fac.random(kl - 1, ll - 1, el, q / 2); 675 e = a; //fac.random(kl, ll-1, el, q ); 676 677 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 678 return; 679 } 680 681 L = new ArrayList<GenPolynomial<BigRational>>(); 682 L.add(b); 683 L = bb.GB(L); 684 I = new Ideal<BigRational>(fac, L, true); 685 assertTrue("not isZERO( I )", !I.isZERO()); 686 //assertTrue("not isONE( I )", !I.isONE() ); 687 assertTrue("isGB( I )", I.isGB()); 688 689 //System.out.println("a = " + a); 690 //System.out.println("b = " + b); 691 //System.out.println("I = " + I); 692 693 if (!I.isONE()) { 694 assertFalse("a in radical(b)", I.isRadicalMember(a)); 695 assertTrue("b in radical(b)", I.isRadicalMember(b)); 696 } 697 698 L = new ArrayList<GenPolynomial<BigRational>>(); 699 L.add(b.multiply(b)); 700 L = bb.GB(L); 701 I = new Ideal<BigRational>(fac, L, true); 702 assertTrue("not isZERO( I )", !I.isZERO()); 703 //assertTrue("not isONE( I )", !I.isONE() ); 704 assertTrue("isGB( I )", I.isGB()); 705 706 //System.out.println("I = " + I); 707 708 if (!I.isONE()) { 709 assertFalse("a in radical(b*b)", I.isRadicalMember(a)); 710 assertTrue("b in radical(b*b)", I.isRadicalMember(b)); 711 } 712 713 //System.out.println("c = " + c); 714 L.add(c); 715 L = bb.GB(L); 716 I = new Ideal<BigRational>(fac, L, true); 717 assertTrue("not isZERO( I )", !I.isZERO()); 718 //assertTrue("not isONE( I )", !I.isONE() ); 719 assertTrue("isGB( I )", I.isGB()); 720 721 //System.out.println("I = " + I); 722 723 if (!I.isONE()) { 724 assertFalse("a in radical(b*b)", I.isRadicalMember(a)); 725 assertTrue("b in radical(b*b)", I.isRadicalMember(b)); 726 } 727 } 728 729 730 /** 731 * Test Ideal common zeros. 732 */ 733 public void testIdealCommonZeros() { 734 735 Ideal<BigRational> I; 736 L = new ArrayList<GenPolynomial<BigRational>>(); 737 738 I = new Ideal<BigRational>(fac, L, true); 739 assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1); 740 741 a = fac.getZERO(); 742 L.add(a); 743 I = new Ideal<BigRational>(fac, L, true); 744 assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1); 745 746 b = fac.getONE(); 747 L.add(b); 748 I = new Ideal<BigRational>(fac, L, true); 749 assertEquals("commonZeroTest( I )", I.commonZeroTest(), -1); 750 751 L = new ArrayList<GenPolynomial<BigRational>>(); 752 a = fac.random(kl, ll, el, q); 753 if (!a.isZERO() && !a.isConstant()) { 754 L.add(a); 755 I = new Ideal<BigRational>(fac, L, true); 756 assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1); 757 } 758 759 L = (List<GenPolynomial<BigRational>>) fac.univariateList(); 760 I = new Ideal<BigRational>(fac, L, true); 761 assertEquals("commonZeroTest( I )", I.commonZeroTest(), 0); 762 763 L.remove(0); 764 I = new Ideal<BigRational>(fac, L, true); 765 assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1); 766 } 767 768 769 /** 770 * Test Ideal dimension. 771 */ 772 public void testIdealDimension() { 773 774 Ideal<BigRational> I; 775 L = new ArrayList<GenPolynomial<BigRational>>(); 776 Dimension dim; 777 778 I = new Ideal<BigRational>(fac, L, true); 779 assertEquals("dimension( I )", rl, I.dimension().d); 780 781 a = fac.getZERO(); 782 L.add(a); 783 I = new Ideal<BigRational>(fac, L, true); 784 assertEquals("dimension( I )", rl, I.dimension().d); 785 786 b = fac.getONE(); 787 L.add(b); 788 I = new Ideal<BigRational>(fac, L, true); 789 assertEquals("dimension( I )", -1, I.dimension().d); 790 791 L = new ArrayList<GenPolynomial<BigRational>>(); 792 a = fac.random(kl, ll, el, q); 793 if (!a.isZERO() && !a.isConstant()) { 794 L.add(a); 795 I = new Ideal<BigRational>(fac, L, true); 796 //System.out.println("a = " + a); 797 dim = I.dimension(); 798 //System.out.println("dim(I) = " + dim); 799 assertTrue("dimension( I )", dim.d >= 1); 800 } 801 802 L = (List<GenPolynomial<BigRational>>) fac.univariateList(); 803 I = new Ideal<BigRational>(fac, L, true); 804 dim = I.dimension(); 805 assertEquals("dimension( I )", 0, dim.d); 806 807 while (L.size() > 0) { 808 L.remove(0); 809 I = new Ideal<BigRational>(fac, L, true); 810 //System.out.println("I = " + I); 811 dim = I.dimension(); 812 //System.out.println("dim(I) = " + dim); 813 assertEquals("dimension( I )", rl - L.size(), dim.d); 814 } 815 816 L = (List<GenPolynomial<BigRational>>) fac.univariateList(); 817 I = new Ideal<BigRational>(fac, L, true); 818 I = I.product(I); 819 //System.out.println("I = " + I); 820 dim = I.dimension(); 821 //System.out.println("dim(I) = " + dim); 822 assertEquals("dimension( I )", 0, dim.d); 823 824 L = I.getList(); 825 while (L.size() > 0) { 826 L.remove(0); 827 I = new Ideal<BigRational>(fac, L, true); 828 //System.out.println("I = " + I); 829 dim = I.dimension(); 830 //System.out.println("dim(I) = " + dim); 831 assertTrue("dimension( I )", dim.d > 0); 832 } 833 } 834 835 836 /** 837 * Test Ideal term order optimization. 838 */ 839 public void testIdealTopt() { 840 841 Ideal<BigRational> I; 842 Ideal<BigRational> J; 843 Ideal<BigRational> K; 844 845 L = new ArrayList<GenPolynomial<BigRational>>(); 846 847 a = fac.random(kl, ll, el, q); 848 b = fac.random(kl, ll, el, q); 849 c = fac.random(kl, ll, el, q); 850 d = fac.random(kl, ll, el, q); 851 e = d; //fac.random(kl, ll, el, q ); 852 853 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 854 return; 855 } 856 857 assertTrue("not isZERO( a )", !a.isZERO()); 858 L.add(a); 859 860 I = new Ideal<BigRational>(fac, L); 861 I.doGB(); 862 assertTrue("not isZERO( I )", !I.isZERO()); 863 assertTrue("isGB( I )", I.isGB()); 864 //System.out.println("I = " + I); 865 866 J = I.copy(); //new Ideal<BigRational>(fac,L); 867 J.doToptimize(); 868 assertTrue("not isZERO( J )", !J.isZERO()); 869 assertTrue("isGB( J )", J.isGB()); 870 //System.out.println("J = " + J); 871 872 if (I.isONE()) { 873 return; 874 } 875 876 assertTrue("not isZERO( b )", !b.isZERO()); 877 L.add(b); 878 879 I = new Ideal<BigRational>(fac, L); 880 K = I.copy(); 881 I.doGB(); 882 assertTrue("not isZERO( I )", !I.isZERO()); 883 assertTrue("isGB( I )", I.isGB()); 884 //System.out.println("GB(I) = " + I); 885 886 K.doToptimize(); 887 K.doGB(); 888 assertTrue("not isZERO( K )", !K.isZERO()); 889 assertTrue("isGB( K )", K.isGB()); 890 //System.out.println("GB(opt(K)) = " + K); 891 892 J = I.copy(); 893 J.doToptimize(); 894 assertTrue("not isZERO( J )", !J.isZERO()); 895 assertTrue("isGB( J )", J.isGB()); 896 //System.out.println("opt(GB(J)) = " + J); 897 898 if (I.isONE()) { 899 return; 900 } 901 902 assertTrue("not isZERO( c )", !c.isZERO()); 903 L.add(c); 904 905 I = new Ideal<BigRational>(fac, L); 906 K = I.copy(); 907 I.doGB(); 908 assertTrue("not isZERO( I )", !I.isZERO()); 909 assertTrue("isGB( I )", I.isGB()); 910 //System.out.println("GB(I) = " + I); 911 912 K.doToptimize(); 913 K.doGB(); 914 assertTrue("not isZERO( K )", !K.isZERO()); 915 assertTrue("isGB( K )", K.isGB()); 916 //System.out.println("GB(opt(K)) = " + K); 917 918 J = I.copy(); 919 J.doToptimize(); 920 assertTrue("not isZERO( J )", !J.isZERO()); 921 assertTrue("isGB( J )", J.isGB()); 922 //System.out.println("opt(GB(J)) = " + J); 923 } 924 925 926 /** 927 * Test elimination Ideals. 928 */ 929 public void testElimIdeal() { 930 931 String[] vars = fac.getVars(); 932 //System.out.println("vars = " + Arrays.toString(vars)); 933 //System.out.println("fac = " + fac); 934 935 Ideal<BigRational> I; 936 Ideal<BigRational> J; 937 938 L = new ArrayList<GenPolynomial<BigRational>>(); 939 940 a = fac.univariate(2, 3L); //fac.random(kl, ll, el, q ); 941 b = fac.univariate(1, 2L); //fac.random(kl, ll, el, q ); 942 c = fac.univariate(0, 1L); //fac.random(kl, ll, el, q ); 943 944 if (a.isZERO() || b.isZERO() || c.isZERO()) { 945 return; 946 } 947 948 L.add(a); 949 L.add(b); 950 L.add(c); 951 952 I = new Ideal<BigRational>(fac, L); 953 //I.doGB(); 954 assertTrue("not isZERO( I )", !I.isZERO()); 955 assertTrue("isGB( I )", I.isGB()); 956 //System.out.println("I = " + I); 957 958 List<String> sv = new ArrayList<String>(vars.length); 959 for (int i = 0; i < vars.length; i++) { 960 sv.add(vars[i]); 961 } 962 //System.out.println("sv = " + sv); 963 964 for (int i = 0; i <= vars.length; i++) { 965 KsubSet<String> ps = new KsubSet<String>(sv, i); 966 //System.out.println("========================== ps : " + i); 967 for (List<String> ev : ps) { 968 //System.out.println("ev = " + ev); 969 970 String[] evars = new String[ev.size()]; 971 for (int j = 0; j < ev.size(); j++) { 972 evars[j] = ev.get(j); 973 } 974 GenPolynomialRing<BigRational> efac; 975 efac = new GenPolynomialRing<BigRational>(fac.coFac, evars.length, fac.tord, evars); 976 //System.out.println("efac = " + efac); 977 978 J = I.eliminate(efac); 979 assertTrue("isGB( J )", J.isGB()); 980 assertTrue("size( J ) <= |ev|", J.getList().size() <= ev.size()); 981 //System.out.println("J = " + J); 982 } 983 } 984 } 985 986 987 /** 988 * Test univariate polynomials in ideal. 989 */ 990 public void testUnivPoly() { 991 String[] vars; 992 993 BigRational coeff = new BigRational(17, 1); 994 to = new TermOrder(TermOrder.INVLEX); 995 vars = new String[] { "x", "y", "z" }; 996 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 997 998 vars = fac.getVars(); 999 //System.out.println("vars = " + Arrays.toString(vars)); 1000 //System.out.println("fac = " + fac); 1001 assertTrue("vars.length == 3 ", vars.length == 3); 1002 1003 Ideal<BigRational> I; 1004 L = new ArrayList<GenPolynomial<BigRational>>(); 1005 1006 a = fac.parse("( x^3 + 34/55 x^2 + 1/9 x + 99 )"); 1007 b = fac.parse("( y^4 - x )"); 1008 c = fac.parse("( z^3 - x y )"); 1009 1010 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1011 return; 1012 } 1013 1014 L.add(a); 1015 L.add(b); 1016 L.add(c); 1017 I = new Ideal<BigRational>(fac, L); 1018 //I.doGB(); 1019 assertTrue("not isZERO( I )", !I.isZERO()); 1020 assertTrue("isGB( I )", I.isGB()); 1021 //System.out.println("I = " + I); 1022 1023 for (int i = 0; i < rl; i++) { // rl 1024 GenPolynomial<BigRational> u = I.constructUnivariate(rl - 1 - i); 1025 //System.out.println("u = " + u); 1026 GenPolynomial<BigRational> U = fac.parse(u.toString()); 1027 //System.out.println("U = " + U + "\n"); 1028 assertTrue("I.contains(U) ", I.contains(U)); 1029 } 1030 1031 List<GenPolynomial<BigRational>> Us = I.constructUnivariate(); 1032 for (GenPolynomial<BigRational> u : Us) { 1033 //System.out.println("u = " + u); 1034 GenPolynomial<BigRational> U = fac.parse(u.toString()); 1035 //System.out.println("U = " + U + "\n"); 1036 assertTrue("I.contains(U) ", I.contains(U)); 1037 } 1038 } 1039 1040 1041 /** 1042 * Test complex roots univariate polynomials in zero dim ideal. 1043 */ 1044 public void testComplexRoot() { 1045 String[] vars; 1046 1047 BigRational coeff = new BigRational(17, 1); 1048 to = new TermOrder(TermOrder.INVLEX); 1049 vars = new String[] { "x", "y", "z" }; 1050 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1051 1052 vars = fac.getVars(); 1053 //System.out.println("vars = " + Arrays.toString(vars)); 1054 //System.out.println("fac = " + fac); 1055 assertTrue("vars.length == 3 ", vars.length == 3); 1056 1057 Ideal<BigRational> I; 1058 L = new ArrayList<GenPolynomial<BigRational>>(); 1059 1060 a = fac.parse("( x^3 - 27 )"); 1061 b = fac.parse("( y^2 - 9 )"); 1062 c = fac.parse("( z - 7 )"); 1063 1064 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1065 return; 1066 } 1067 1068 L.add(a); 1069 L.add(b); 1070 L.add(c); 1071 I = new Ideal<BigRational>(fac, L); 1072 //I.doGB(); 1073 assertTrue("not isZERO( I )", !I.isZERO()); 1074 assertTrue("isGB( I )", I.isGB()); 1075 //System.out.println("I = " + I); 1076 1077 BigRational eps = new BigRational(1, 1000000); 1078 eps = eps.multiply(eps); 1079 eps = eps.multiply(eps).multiply(eps); 1080 BigDecimal e = new BigDecimal(eps.getRational()); 1081 e = e.abs(); //.multiply(e); 1082 1083 BigDecimal dc = BigDecimal.ONE; 1084 GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, fac); 1085 //System.out.println("dfac = " + dfac); 1086 ComplexRing<BigDecimal> dcc = new ComplexRing<BigDecimal>(dc); 1087 GenPolynomialRing<Complex<BigDecimal>> dcfac = new GenPolynomialRing<Complex<BigDecimal>>(dcc, dfac); 1088 //System.out.println("dcfac = " + dcfac); 1089 1090 List<List<Complex<BigDecimal>>> roots = PolyUtilApp.<BigRational> complexRootTuples(I, eps); 1091 //System.out.println("roots = " + roots + "\n"); 1092 for (GenPolynomial<BigRational> p : I.getList()) { 1093 GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p); 1094 GenPolynomial<Complex<BigDecimal>> dpc = PolyUtil.<BigDecimal> toComplex(dcfac, dp); 1095 //System.out.println("dpc = " + dpc); 1096 for (List<Complex<BigDecimal>> r : roots) { 1097 //System.out.println("r = " + r); 1098 Complex<BigDecimal> ev = PolyUtil.<Complex<BigDecimal>> evaluateAll(dcc, dcfac, dpc, r); 1099 if (ev.norm().getRe().compareTo(e) > 0) { 1100 //System.out.println("ev = " + ev); 1101 fail("ev > eps : " + ev + " > " + e); 1102 } 1103 } 1104 } 1105 //System.out.println(); 1106 } 1107 1108 1109 /** 1110 * Test real roots univariate polynomials in zero dim ideal. 1111 */ 1112 public void testRealRoot() { 1113 String[] vars; 1114 1115 BigRational coeff = new BigRational(17, 1); 1116 to = new TermOrder(TermOrder.INVLEX); 1117 vars = new String[] { "x", "y", "z" }; 1118 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1119 1120 vars = fac.getVars(); 1121 //System.out.println("vars = " + Arrays.toString(vars)); 1122 //System.out.println("fac = " + fac); 1123 assertTrue("vars.length == 3 ", vars.length == 3); 1124 1125 Ideal<BigRational> I; 1126 L = new ArrayList<GenPolynomial<BigRational>>(); 1127 1128 a = fac.parse("( x^3 - 27 )"); 1129 b = fac.parse("( y^4 - x )"); 1130 c = fac.parse("( z^2 - x^2 )"); 1131 1132 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1133 return; 1134 } 1135 1136 L.add(a); 1137 L.add(b); 1138 L.add(c); 1139 I = new Ideal<BigRational>(fac, L); 1140 //I.doGB(); 1141 assertTrue("not isZERO( I )", !I.isZERO()); 1142 assertTrue("isGB( I )", I.isGB()); 1143 //System.out.println("I = " + I); 1144 1145 BigRational eps = new BigRational(1, 1000000); 1146 eps = eps.multiply(eps); 1147 eps = eps.multiply(eps).multiply(eps); 1148 BigDecimal e = new BigDecimal(eps.getRational()); 1149 e = e.abs(); //.multiply(e); 1150 eps = eps.multiply(new BigRational(1, 2)); 1151 1152 List<List<BigDecimal>> roots = PolyUtilApp.<BigRational> realRootTuples(I, eps); 1153 //System.out.println("roots = " + roots + "\n"); 1154 // polynomials with decimal coefficients 1155 BigDecimal dc = BigDecimal.ONE; 1156 GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, fac); 1157 //System.out.println("dfac = " + dfac); 1158 for (GenPolynomial<BigRational> p : I.getList()) { 1159 GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p); 1160 //System.out.println("dp = " + dp); 1161 for (List<BigDecimal> r : roots) { 1162 //System.out.println("r = " + r); 1163 BigDecimal ev = PolyUtil.<BigDecimal> evaluateAll(dc, dfac, dp, r); 1164 if (ev.abs().compareTo(e) > 0) { 1165 //System.out.println("ev = " + ev); 1166 fail("ev > e : " + ev + " > " + e + ", eps = " + new BigDecimal(eps)); 1167 } 1168 } 1169 } 1170 //System.out.println(); 1171 } 1172 1173 1174 /** 1175 * Test zero dimensional decomposition. 1176 */ 1177 public void testZeroDimDecomp() { 1178 String[] vars; 1179 1180 BigRational coeff = new BigRational(17, 1); 1181 to = new TermOrder(TermOrder.INVLEX); 1182 vars = new String[] { "x", "y", "z" }; 1183 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1184 1185 vars = fac.getVars(); 1186 //System.out.println("vars = " + Arrays.toString(vars)); 1187 //System.out.println("fac = " + fac); 1188 assertTrue("vars.length == 3 ", vars.length == 3); 1189 1190 Ideal<BigRational> I; 1191 L = new ArrayList<GenPolynomial<BigRational>>(); 1192 1193 a = fac.parse("( x^3 - 27 )"); 1194 b = fac.parse("( y^4 - x )"); 1195 c = fac.parse("( z^2 - x^2 )"); 1196 1197 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1198 return; 1199 } 1200 1201 L.add(a); 1202 L.add(b); 1203 L.add(c); 1204 I = new Ideal<BigRational>(fac, L); 1205 //I.doGB(); 1206 assertTrue("not isZERO( I )", !I.isZERO()); 1207 assertTrue("isGB( I )", I.isGB()); 1208 //System.out.println("I = " + I); 1209 1210 List<IdealWithUniv<BigRational>> zd = I.zeroDimDecomposition(); 1211 //System.out.println("I = " + I); 1212 //System.out.println("zd = " + zd); 1213 1214 boolean t = I.isZeroDimDecomposition(zd); 1215 //System.out.println("t = " + t); 1216 assertTrue("is decomposition ", t); 1217 } 1218 1219 1220 /** 1221 * Test real roots univariate polynomials in zero dim ideal. 1222 */ 1223 public void testIdealRealRoot() { 1224 String[] vars; 1225 1226 BigRational coeff = new BigRational(17, 1); 1227 to = new TermOrder(TermOrder.INVLEX); 1228 vars = new String[] { "x", "y", "z" }; 1229 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1230 1231 vars = fac.getVars(); 1232 //System.out.println("vars = " + Arrays.toString(vars)); 1233 //System.out.println("fac = " + fac); 1234 assertTrue("vars.length == 3 ", vars.length == 3); 1235 1236 Ideal<BigRational> I; 1237 L = new ArrayList<GenPolynomial<BigRational>>(); 1238 1239 a = fac.parse("( x^3 - 27 )"); 1240 b = fac.parse("( y^4 - x )"); 1241 c = fac.parse("( z^2 - x^2 )"); 1242 1243 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1244 return; 1245 } 1246 1247 L.add(a); 1248 L.add(b); 1249 L.add(c); 1250 I = new Ideal<BigRational>(fac, L); 1251 //I.doGB(); 1252 assertTrue("not isZERO( I )", !I.isZERO()); 1253 assertTrue("isGB( I )", I.isGB()); 1254 //System.out.println("I = " + I); 1255 1256 List<IdealWithUniv<BigRational>> zd = I.zeroDimDecomposition(); 1257 //System.out.println("zd = " + zd); 1258 assertTrue("is decomposition ", I.isZeroDimDecomposition(zd)); 1259 1260 BigRational eps = new BigRational(1, 1000000); 1261 eps = eps.multiply(eps); 1262 eps = eps.multiply(eps).multiply(eps); 1263 BigDecimal e = new BigDecimal(eps.getRational()); 1264 e = e.abs(); //.multiply(e); 1265 eps = eps.multiply(new BigRational(1, 2)); 1266 BigDecimal dc = BigDecimal.ONE; 1267 1268 List<IdealWithRealRoots<BigRational>> roots = PolyUtilApp.<BigRational> realRoots(zd, eps); 1269 //System.out.println("roots = " + roots + "\n"); 1270 1271 for (IdealWithRealRoots<BigRational> Ir : roots) { 1272 List<GenPolynomial<BigRational>> L = Ir.ideal.getList(); 1273 List<GenPolynomial<BigDecimal>> Ld = new ArrayList<GenPolynomial<BigDecimal>>(L.size()); 1274 1275 GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, Ir.ideal.list.ring); 1276 //System.out.println("dfac = " + dfac); 1277 1278 for (GenPolynomial<BigRational> p : L) { 1279 GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p); 1280 //System.out.println("dp = " + dp); 1281 Ld.add(dp); 1282 } 1283 boolean t = PolyUtilApp.isRealRoots(Ld, Ir.rroots, e); 1284 assertTrue("isRealRoots ", t); // this example only 1285 } 1286 } 1287 1288 1289 /** 1290 * Test complex roots univariate polynomials in zero dim ideal. 1291 */ 1292 public void testIdealComplexRoot() { 1293 String[] vars; 1294 1295 BigRational coeff = new BigRational(1, 1); 1296 to = new TermOrder(TermOrder.INVLEX); 1297 //vars = new String[] { "x", "y" }; 1298 vars = new String[] { "x", "y", "z" }; 1299 fac = new GenPolynomialRing<BigRational>(coeff, vars.length, to, vars); 1300 1301 vars = fac.getVars(); 1302 //System.out.println("vars = " + Arrays.toString(vars)); 1303 //System.out.println("fac = " + fac); 1304 assertTrue("vars.length == 3 ", vars.length == 3); 1305 1306 Ideal<BigRational> I; 1307 L = new ArrayList<GenPolynomial<BigRational>>(); 1308 1309 a = fac.parse("( x^3 + 3 )"); 1310 //a = fac.parse("( x^3 - 3 )"); 1311 //a = fac.parse("( x^2 + 3 )"); 1312 b = fac.parse("( y^2 - x )"); 1313 //b = fac.parse("( y^2 + x )"); 1314 //b = fac.parse("( y^2 + 4 )"); 1315 c = fac.parse("( z^2 - x y )"); 1316 1317 if (a.isZERO() || b.isZERO()) { 1318 return; 1319 } 1320 1321 L.add(a); 1322 L.add(b); 1323 L.add(c); 1324 I = new Ideal<BigRational>(fac, L); 1325 //I.doGB(); 1326 assertTrue("not isZERO( I )", !I.isZERO()); 1327 assertTrue("isGB( I )", I.isGB()); 1328 //System.out.println("I = " + I); 1329 1330 List<IdealWithUniv<BigRational>> zd = I.zeroDimRootDecomposition(); 1331 //System.out.println("zd = " + zd); 1332 assertTrue("is decomposition ", I.isZeroDimDecomposition(zd)); 1333 1334 BigRational eps = new BigRational(1, 1000000); 1335 //eps = eps.multiply(eps); 1336 eps = eps.multiply(eps).multiply(eps); 1337 BigDecimal e = new BigDecimal(eps.getRational()); 1338 e = e.abs(); //.multiply(e); 1339 1340 List<IdealWithComplexAlgebraicRoots<BigRational>> roots = PolyUtilApp 1341 .<BigRational> complexAlgebraicRoots(zd); //, eps); 1342 //System.out.println("roots = " + roots + "\n"); 1343 1344 ComplexRing<BigDecimal> dcc = new ComplexRing<BigDecimal>(e); 1345 1346 int d = 0; 1347 int s = 0; 1348 for (IdealWithComplexAlgebraicRoots<BigRational> Ic : roots) { 1349 List<GenPolynomial<BigRational>> L = Ic.ideal.getList(); 1350 List<GenPolynomial<Complex<BigDecimal>>> Ld = new ArrayList<GenPolynomial<Complex<BigDecimal>>>( 1351 L.size()); 1352 s += Ic.can.size(); 1353 1354 GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(e, Ic.ideal.list.ring); 1355 //System.out.println("dfac = " + dfac); 1356 GenPolynomialRing<Complex<BigDecimal>> dcfac; 1357 dcfac = new GenPolynomialRing<Complex<BigDecimal>>(dcc, dfac); 1358 //System.out.println("dcfac = " + dcfac); 1359 int ds = 1; 1360 for (GenPolynomial<BigRational> p : L) { 1361 long dl = p.leadingExpVector().totalDeg(); 1362 ds *= dl; 1363 GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p); 1364 GenPolynomial<Complex<BigDecimal>> dpc = PolyUtil.<BigDecimal> toComplex(dcfac, dp); 1365 //System.out.println("p = " + p); 1366 //System.out.println("dpc = " + dpc); 1367 Ld.add(dpc); 1368 } 1369 d += ds; 1370 List<List<Complex<BigDecimal>>> droot = Ic.decimalApproximation(); 1371 for (List<Complex<BigDecimal>> dr : droot) { 1372 //System.out.println("dr = " + dr); // TODO 1373 } 1374 } 1375 logger.info("#roots = " + s + ", #vr-dim = " + d); 1376 assertTrue("#roots(" + s + ") == degree(" + d + "): ", s == d); 1377 } 1378 1379 1380 /** 1381 * Test normal position. 1382 */ 1383 public void testNormalPosition() { 1384 String[] vars; 1385 1386 BigRational coeff = new BigRational(17, 1); 1387 to = new TermOrder(TermOrder.INVLEX); 1388 vars = new String[] { "x", "y", "z" }; 1389 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1390 1391 vars = fac.getVars(); 1392 //System.out.println("vars = " + Arrays.toString(vars)); 1393 //System.out.println("fac = " + fac); 1394 assertTrue("vars.length == 3 ", vars.length == 3); 1395 1396 Ideal<BigRational> I; 1397 L = new ArrayList<GenPolynomial<BigRational>>(); 1398 1399 a = fac.parse("( x^3 - 27 )"); 1400 b = fac.parse("( y^3 - x )"); 1401 c = fac.parse("( z^2 - x^2 )"); 1402 1403 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1404 return; 1405 } 1406 1407 L.add(a); 1408 L.add(b); 1409 L.add(c); 1410 I = new Ideal<BigRational>(fac, L); 1411 I.doGB(); 1412 assertTrue("not isZERO( I )", !I.isZERO()); 1413 assertTrue("isGB( I )", I.isGB()); 1414 //System.out.println("I = " + I); 1415 1416 int[] np = I.normalPositionIndex2Vars(); 1417 //System.out.println("np = " + np); 1418 if (np == null) { 1419 np = I.normalPositionIndexUnivars(); 1420 //System.out.println("np = " + np); 1421 } 1422 if (np == null) { 1423 return; 1424 } 1425 int i = np[0]; 1426 int j = np[1]; 1427 IdealWithUniv<BigRational> Ip = I.normalPositionFor(i, j, null); 1428 //System.out.println("Ip = " + Ip); 1429 1430 boolean t = Ip.ideal.isNormalPositionFor(i + 1, j + 1); // sic 1431 //System.out.println("t = " + t); 1432 assertTrue("is normal position ", t); 1433 1434 np = Ip.ideal.normalPositionIndex2Vars(); 1435 //System.out.println("np = " + np); 1436 if (np == null) { 1437 np = Ip.ideal.normalPositionIndexUnivars(); 1438 //System.out.println("np = " + Arrays.toString(np)); 1439 } 1440 if (np == null) { 1441 return; 1442 } 1443 i = np[0]; 1444 j = np[1]; 1445 assertTrue("i == 0: " + i, i == 0); 1446 assertTrue("j == 2: " + j, j == 2); // fixed, was 3 1447 } 1448 1449 1450 /** 1451 * Test 0-dim root decomposition. 1452 */ 1453 public void testRootDecomposition() { 1454 String[] vars; 1455 1456 BigRational coeff = new BigRational(17, 1); 1457 to = new TermOrder(TermOrder.INVLEX); 1458 vars = new String[] { "x", "y", "z" }; 1459 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1460 1461 vars = fac.getVars(); 1462 //System.out.println("vars = " + Arrays.toString(vars)); 1463 //System.out.println("fac = " + fac); 1464 assertTrue("vars.length == 3 ", vars.length == 3); 1465 1466 Ideal<BigRational> I; 1467 L = new ArrayList<GenPolynomial<BigRational>>(); 1468 1469 a = fac.parse("( x^2 - 7 )"); 1470 b = fac.parse("( y^2 - 5 )"); 1471 c = fac.parse("( z^3 - x * y )"); 1472 1473 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1474 return; 1475 } 1476 1477 L.add(a); 1478 L.add(b); 1479 L.add(c); 1480 I = new Ideal<BigRational>(fac, L); 1481 I.doGB(); 1482 assertTrue("not isZERO( I )", !I.isZERO()); 1483 assertTrue("isGB( I )", I.isGB()); 1484 //System.out.println("I = " + I); 1485 1486 List<IdealWithUniv<BigRational>> rzd = I.zeroDimRootDecomposition(); 1487 //System.out.println("rzd = " + rzd); 1488 1489 assertTrue("is contained in intersection ", I.isZeroDimDecomposition(rzd)); 1490 } 1491 1492 1493 /** 1494 * Test 0-dim prime decomposition. 1495 */ 1496 public void testPrimeDecomposition() { 1497 String[] vars; 1498 1499 BigRational coeff = new BigRational(17, 1); 1500 to = new TermOrder(TermOrder.INVLEX); 1501 vars = new String[] { "x", "y", "z" }; 1502 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1503 1504 vars = fac.getVars(); 1505 //System.out.println("vars = " + Arrays.toString(vars)); 1506 //System.out.println("fac = " + fac); 1507 assertTrue("vars.length == 3 ", vars.length == 3); 1508 1509 Ideal<BigRational> I; 1510 L = new ArrayList<GenPolynomial<BigRational>>(); 1511 1512 a = fac.parse("( x^2 - 5 )^2 "); 1513 b = fac.parse("( y^2 - 5 )"); 1514 c = fac.parse("( z^3 - x )"); 1515 1516 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1517 return; 1518 } 1519 1520 L.add(a); 1521 L.add(b); 1522 L.add(c); 1523 I = new Ideal<BigRational>(fac, L); 1524 I.doGB(); 1525 assertTrue("not isZERO( I )", !I.isZERO()); 1526 assertTrue("isGB( I )", I.isGB()); 1527 //System.out.println("I = " + I); 1528 1529 List<IdealWithUniv<BigRational>> pzd = I.zeroDimPrimeDecomposition(); 1530 //System.out.println("pzd = " + pzd); 1531 //System.out.println("I = " + I); 1532 1533 assertTrue("is contained in intersection ", I.isZeroDimDecomposition(pzd)); 1534 } 1535 1536 1537 /** 1538 * Test 0-dim primary decomposition. 1539 */ 1540 public void testPrimaryDecomposition() { 1541 String[] vars; 1542 1543 BigRational coeff = new BigRational(17, 1); 1544 to = new TermOrder(TermOrder.INVLEX); 1545 vars = new String[] { "x", "y", "z" }; 1546 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1547 1548 vars = fac.getVars(); 1549 //System.out.println("vars = " + Arrays.toString(vars)); 1550 //System.out.println("fac = " + fac); 1551 assertTrue("vars.length == 3 ", vars.length == 3); 1552 1553 Ideal<BigRational> I; 1554 L = new ArrayList<GenPolynomial<BigRational>>(); 1555 1556 a = fac.parse("( x^2 - 5 )^2 "); 1557 b = fac.parse("( y^2 - 5 )"); 1558 c = fac.parse("( z^3 - x )"); 1559 1560 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1561 return; 1562 } 1563 1564 L.add(a); 1565 L.add(b); 1566 L.add(c); 1567 I = new Ideal<BigRational>(fac, L); 1568 I.doGB(); 1569 assertTrue("not isZERO( I )", !I.isZERO()); 1570 assertTrue("isGB( I )", I.isGB()); 1571 //System.out.println("I = " + I); 1572 1573 List<PrimaryComponent<BigRational>> qzd = I.zeroDimPrimaryDecomposition(); 1574 //System.out.println("qzd = " + qzd); 1575 //System.out.println("I = " + I); 1576 1577 assertTrue("is intersection ", I.isPrimaryDecomposition(qzd)); 1578 } 1579 1580 1581 /** 1582 * Test 0-dim root decomposition and real roots. 1583 */ 1584 public void testRootDecompositionReal() { 1585 String[] vars; 1586 1587 BigRational coeff = new BigRational(17, 1); 1588 to = new TermOrder(TermOrder.INVLEX); 1589 vars = new String[] { "x", "y", "z" }; 1590 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1591 1592 vars = fac.getVars(); 1593 //System.out.println("vars = " + Arrays.toString(vars)); 1594 //System.out.println("fac = " + fac); 1595 assertTrue("vars.length == 3 ", vars.length == 3); 1596 1597 Ideal<BigRational> I; 1598 L = new ArrayList<GenPolynomial<BigRational>>(); 1599 1600 a = fac.parse("( x^2 - 5 )"); 1601 b = fac.parse("( y^2 - 7 )"); 1602 c = fac.parse("( z^3 - x * y )"); 1603 1604 if (a.isZERO() || b.isZERO() || c.isZERO()) { 1605 return; 1606 } 1607 1608 L.add(a); 1609 L.add(b); 1610 L.add(c); 1611 I = new Ideal<BigRational>(fac, L); 1612 I.doGB(); 1613 assertTrue("not isZERO( I )", !I.isZERO()); 1614 assertTrue("isGB( I )", I.isGB()); 1615 //System.out.println("I = " + I); 1616 1617 List<IdealWithRealAlgebraicRoots<BigRational>> iur; 1618 iur = PolyUtilApp.<BigRational> realAlgebraicRoots(I); 1619 1620 List<IdealWithUniv<BigRational>> iul = new ArrayList<IdealWithUniv<BigRational>>(); 1621 for (IdealWithRealAlgebraicRoots<BigRational> iu : iur) { 1622 iul.add(iu); 1623 } 1624 assertTrue("is contained in intersection ", I.isZeroDimDecomposition(iul)); 1625 1626 for (IdealWithRealAlgebraicRoots<BigRational> iu : iur) { 1627 //System.out.println("iu = " + iu); 1628 //System.out.println(""); 1629 List<List<BigDecimal>> rd = iu.decimalApproximation(); // TODO 1630 //System.out.println("iu = " + iu); 1631 //System.out.println(""); 1632 } 1633 } 1634 1635 1636 /** 1637 * Test extension-contraction. 1638 */ 1639 public void testExtCont() { 1640 String[] vars; 1641 1642 BigRational coeff = new BigRational(17, 1); 1643 to = new TermOrder(); //TermOrder.INVLEX); 1644 vars = new String[] { "x", "y", "z" }; 1645 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1646 1647 vars = fac.getVars(); 1648 //System.out.println("vars = " + Arrays.toString(vars)); 1649 //System.out.println("fac = " + fac); 1650 assertTrue("vars.length == 3 ", vars.length == 3); 1651 1652 Ideal<BigRational> I; 1653 L = new ArrayList<GenPolynomial<BigRational>>(); 1654 1655 //a = fac.parse("( y^2 - 5 ) x "); 1656 //b = fac.parse("( y^2 - 5 ) x "); 1657 //c = fac.parse("( x z^3 - 3 )"); 1658 1659 //a = fac.parse("( x^2 + 2 x y z + z^4 ) "); 1660 //b = fac.parse("( y z - z^2 ) "); 1661 //c = fac.parse("0"); 1662 1663 a = fac.parse("( y + x y^2 ) "); 1664 b = fac.parse("( x z + x^2 y ) "); 1665 //c = fac.parse("0"); 1666 1667 if (a.isZERO() || b.isZERO()) { 1668 return; 1669 } 1670 1671 L.add(a); 1672 L.add(b); 1673 //L.add(c); 1674 I = new Ideal<BigRational>(fac, L); 1675 I.doGB(); 1676 assertTrue("not isZERO( I )", !I.isZERO()); 1677 assertTrue("isGB( I )", I.isGB()); 1678 //System.out.println("I = " + I); 1679 1680 IdealWithUniv<Quotient<BigRational>> Ext = I.extension(new String[] { "x" }); 1681 //Ideal<Quotient<BigRational>> Ext = I.extension( new String[] { "y", "z" } ); 1682 //System.out.println("Ext = " + Ext); 1683 //System.out.println("I = " + I); 1684 1685 IdealWithUniv<BigRational> Con = I.permContraction(Ext); 1686 //System.out.println("Con = " + Con); 1687 //System.out.println("I = " + I); 1688 1689 assertTrue("I subseteq Con(Ext(I)) ", Con.ideal.contains(I)); 1690 } 1691 1692 1693 /** 1694 * Test prime ideal decomposition. 1695 */ 1696 public void testPrimeDecomp() { 1697 String[] vars; 1698 1699 BigRational coeff = new BigRational(17, 1); 1700 to = new TermOrder(TermOrder.INVLEX); 1701 vars = new String[] { "x", "y", "z" }; 1702 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1703 1704 vars = fac.getVars(); 1705 //System.out.println("vars = " + Arrays.toString(vars)); 1706 //System.out.println("fac = " + fac); 1707 assertTrue("vars.length == 3 ", vars.length == 3); 1708 1709 Ideal<BigRational> I; 1710 L = new ArrayList<GenPolynomial<BigRational>>(); 1711 1712 //a = fac.parse("( y^2 - 5 ) x "); 1713 //b = fac.parse("( y^2 - 5 ) x "); 1714 //c = fac.parse("( x z^3 - 3 )"); 1715 1716 //a = fac.parse("( x^2 + 2 x y z + z^4 ) "); 1717 //b = fac.parse("( y z - z^2 ) "); 1718 1719 //a = fac.parse("( y + x y^2 ) "); 1720 //b = fac.parse("( x z + x^2 y ) "); 1721 1722 a = fac.parse("( z^2 - x ) "); 1723 b = fac.parse("( y^2 - x ) "); 1724 1725 //a = fac.parse("( x y ) "); 1726 //b = fac.parse("( x z ) "); 1727 1728 if (a.isZERO() || b.isZERO()) { 1729 return; 1730 } 1731 1732 L.add(a); 1733 L.add(b); 1734 //L.add(c); 1735 I = new Ideal<BigRational>(fac, L); 1736 I.doGB(); 1737 assertTrue("not isZERO( I )", !I.isZERO()); 1738 assertTrue("isGB( I )", I.isGB()); 1739 //System.out.println("I = " + I); 1740 1741 List<IdealWithUniv<BigRational>> pdec = I.primeDecomposition(); 1742 //System.out.println("pdec = " + pdec); 1743 //System.out.println("I = " + I); 1744 1745 assertTrue("I subseteq cup G_i ", I.isDecomposition(pdec)); 1746 1747 List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(pdec.size()); 1748 for (IdealWithUniv<BigRational> pu : pdec) { 1749 dec.add(pu.ideal); 1750 } 1751 Ideal<BigRational> Ii = I.intersect(dec); 1752 //System.out.println("Ii = " + Ii); 1753 //System.out.println("I = " + I); 1754 1755 // not always: 1756 assertTrue("I == Ii ", I.equals(Ii)); 1757 } 1758 1759 1760 /** 1761 * Test radical ideal decomposition. 1762 */ 1763 public void testRadicalDecomp() { 1764 String[] vars; 1765 1766 BigRational coeff = new BigRational(17, 1); 1767 to = new TermOrder(TermOrder.INVLEX); 1768 vars = new String[] { "x", "y", "z" }; 1769 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1770 1771 vars = fac.getVars(); 1772 //System.out.println("vars = " + Arrays.toString(vars)); 1773 //System.out.println("fac = " + fac); 1774 assertTrue("vars.length == 3 ", vars.length == 3); 1775 1776 Ideal<BigRational> I; 1777 L = new ArrayList<GenPolynomial<BigRational>>(); 1778 1779 //a = fac.parse("( y^2 - 5 ) x "); 1780 //b = fac.parse("( y^2 - 5 ) x "); 1781 //c = fac.parse("( x z^3 - 3 )"); 1782 1783 a = fac.parse("( x^2 + 2 x y z + z^4 ) "); 1784 b = fac.parse("( y z - z^2 ) "); 1785 1786 //a = fac.parse("( y + x y^2 ) "); 1787 //b = fac.parse("( x z + x^2 y ) "); 1788 1789 //a = fac.parse("( z^2 - x )^2 "); 1790 //b = fac.parse("( y^2 - x ) "); 1791 1792 //a = fac.parse("( x^2 y^3 ) "); 1793 //b = fac.parse("( x^2 z^5 ) "); 1794 1795 if (a.isZERO() || b.isZERO()) { 1796 return; 1797 } 1798 1799 L.add(a); 1800 L.add(b); 1801 //L.add(c); 1802 I = new Ideal<BigRational>(fac, L); 1803 I.doGB(); 1804 assertTrue("not isZERO( I )", !I.isZERO()); 1805 assertTrue("isGB( I )", I.isGB()); 1806 //System.out.println("I = " + I); 1807 1808 List<IdealWithUniv<BigRational>> rdec = I.radicalDecomposition(); 1809 //System.out.println("rdec = " + rdec); 1810 //System.out.println("I = " + I); 1811 1812 assertTrue("I subseteq cup G_i ", I.isDecomposition(rdec)); 1813 1814 List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(rdec.size()); 1815 for (IdealWithUniv<BigRational> ru : rdec) { 1816 dec.add(ru.ideal); 1817 } 1818 Ideal<BigRational> Ii = I.intersect(dec); 1819 //System.out.println("Ii = " + Ii); 1820 //System.out.println("I = " + I); 1821 1822 assertTrue("Ii.contains(I) ", Ii.contains(I)); 1823 1824 //Ii = I.radical(); 1825 //System.out.println("Ii = " + Ii); 1826 //System.out.println("I = " + I); 1827 //assertTrue("Ii.contains(I) ", Ii.contains(I)); 1828 } 1829 1830 1831 /** 1832 * Test ideal decomposition. 1833 */ 1834 public void testIrredDecomp() { 1835 String[] vars; 1836 1837 BigRational coeff = new BigRational(17, 1); 1838 to = new TermOrder(TermOrder.INVLEX); 1839 vars = new String[] { "x", "y", "z" }; 1840 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1841 1842 vars = fac.getVars(); 1843 //System.out.println("vars = " + Arrays.toString(vars)); 1844 //System.out.println("fac = " + fac); 1845 assertTrue("vars.length == 3 ", vars.length == 3); 1846 1847 Ideal<BigRational> I; 1848 L = new ArrayList<GenPolynomial<BigRational>>(); 1849 1850 //a = fac.parse("( y^2 - 5 ) x "); 1851 //b = fac.parse("( y^2 - 5 ) x "); 1852 //c = fac.parse("( x z^3 - 3 )"); 1853 1854 a = fac.parse("( x^2 + 2 x y z + z^4 ) "); 1855 b = fac.parse("( y z - z^2 ) "); 1856 1857 //a = fac.parse("( y + x y^2 ) "); 1858 //b = fac.parse("( x z + x^2 y ) "); 1859 1860 //a = fac.parse("( z^2 - x )^2 "); 1861 //b = fac.parse("( y^2 - x ) "); 1862 1863 //a = fac.parse("( x^2 y^3 ) "); 1864 //b = fac.parse("( x^2 z^5 ) "); 1865 1866 if (a.isZERO() || b.isZERO()) { 1867 return; 1868 } 1869 1870 L.add(a); 1871 L.add(b); 1872 //L.add(c); 1873 I = new Ideal<BigRational>(fac, L); 1874 I.doGB(); 1875 assertTrue("not isZERO( I )", !I.isZERO()); 1876 assertTrue("isGB( I )", I.isGB()); 1877 //System.out.println("I = " + I); 1878 1879 List<IdealWithUniv<BigRational>> rdec = I.decomposition(); 1880 //System.out.println("rdec = " + rdec); 1881 //System.out.println("I = " + I); 1882 1883 assertTrue("I subseteq cup G_i ", I.isDecomposition(rdec)); 1884 1885 List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(rdec.size()); 1886 for (IdealWithUniv<BigRational> ru : rdec) { 1887 dec.add(ru.ideal); 1888 } 1889 Ideal<BigRational> Ii = I.intersect(dec); 1890 //System.out.println("Ii = " + Ii); 1891 //System.out.println("I = " + I); 1892 1893 assertTrue("Ii.contains(I) ", Ii.contains(I)); 1894 1895 //Ii = I.radical(); 1896 //System.out.println("Ii = " + Ii); 1897 //System.out.println("I = " + I); 1898 //assertTrue("Ii.contains(I) ", Ii.contains(I)); 1899 } 1900 1901 1902 /** 1903 * Test primary ideal decomposition. 1904 */ 1905 public void testPrimaryDecomp() { 1906 String[] vars; 1907 1908 BigRational coeff = new BigRational(17, 1); 1909 to = new TermOrder(TermOrder.INVLEX); 1910 vars = new String[] { "x", "y", "z" }; 1911 fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars); 1912 1913 vars = fac.getVars(); 1914 //System.out.println("vars = " + Arrays.toString(vars)); 1915 //System.out.println("fac = " + fac); 1916 assertTrue("vars.length == 3 ", vars.length == 3); 1917 1918 Ideal<BigRational> I; 1919 L = new ArrayList<GenPolynomial<BigRational>>(); 1920 1921 //a = fac.parse("( y^2 - 5 ) x "); 1922 //b = fac.parse("( y^2 - 5 ) x "); 1923 //c = fac.parse("( x z^3 - 3 )"); 1924 1925 //a = fac.parse("( x^2 + 2 x y z + z^4 ) "); 1926 //b = fac.parse("( y z - z^2 ) "); 1927 1928 //a = fac.parse("( y + x y^2 ) "); 1929 //b = fac.parse("( x z + x^2 y ) "); 1930 1931 a = fac.parse("( x z^2 - 1 )^2 "); 1932 b = fac.parse("( y^2 - x ) "); 1933 1934 //a = fac.parse("( x^2 y ) "); 1935 //b = fac.parse("( x z^3 ) "); 1936 1937 if (a.isZERO() || b.isZERO()) { 1938 return; 1939 } 1940 1941 L.add(a); 1942 L.add(b); 1943 //L.add(c); 1944 I = new Ideal<BigRational>(fac, L); 1945 I.doGB(); 1946 assertTrue("not isZERO( I )", !I.isZERO()); 1947 assertTrue("isGB( I )", I.isGB()); 1948 //System.out.println("I = " + I); 1949 1950 List<PrimaryComponent<BigRational>> qdec = I.primaryDecomposition(); 1951 //System.out.println("qdec = " + qdec); 1952 //System.out.println("I = " + I); 1953 1954 List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(qdec.size()); 1955 for (PrimaryComponent<BigRational> ru : qdec) { 1956 dec.add(ru.primary); 1957 } 1958 assertTrue("I eq cup G_i ", I.isPrimaryDecomposition(qdec)); 1959 } 1960 1961}