001/* 002 * $Id: ModSolvableGroebnerBaseTest.java 5268 2015-07-27 18:05:58Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007 008// import edu.jas.poly.GroebnerBase; 009 010import java.util.ArrayList; 011import java.util.List; 012 013import junit.framework.Test; 014import junit.framework.TestCase; 015import junit.framework.TestSuite; 016 017import org.apache.log4j.BasicConfigurator; 018import org.apache.log4j.Logger; 019 020import edu.jas.arith.BigRational; 021import edu.jas.kern.ComputerThreads; 022import edu.jas.poly.GenSolvablePolynomial; 023import edu.jas.poly.GenSolvablePolynomialRing; 024import edu.jas.poly.ModuleList; 025import edu.jas.poly.PolynomialList; 026import edu.jas.poly.RelationGenerator; 027import edu.jas.poly.RelationTable; 028import edu.jas.poly.TermOrder; 029import edu.jas.poly.WeylRelations; 030 031 032/** 033 * ModSolvableGroebnerBase sequential and parallel tests with JUnit. 034 * @author Heinz Kredel. 035 */ 036 037public class ModSolvableGroebnerBaseTest extends TestCase { 038 039 040 private static final Logger logger = Logger.getLogger(ModSolvableGroebnerBaseTest.class); 041 042 043 /** 044 * main. 045 */ 046 public static void main(String[] args) { 047 BasicConfigurator.configure(); 048 junit.textui.TestRunner.run(suite()); 049 ComputerThreads.terminate(); 050 } 051 052 053 /** 054 * Constructs a <CODE>ModSolvableGroebnerBaseTest</CODE> object. 055 * @param name String. 056 */ 057 public ModSolvableGroebnerBaseTest(String name) { 058 super(name); 059 } 060 061 062 /** 063 * suite. 064 */ 065 public static Test suite() { 066 TestSuite suite = new TestSuite(ModSolvableGroebnerBaseTest.class); 067 return suite; 068 } 069 070 071 int port = 4711; 072 073 074 String host = "localhost"; 075 076 077 BigRational cfac; 078 079 080 GenSolvablePolynomialRing<BigRational> pfac; 081 082 083 GenSolvablePolynomial<BigRational> a, b, c, d, e; 084 085 086 TermOrder tord; 087 088 089 GenSolvablePolynomial<BigRational> one, zero; 090 091 092 RelationTable<BigRational> table; 093 094 095 List<List<GenSolvablePolynomial<BigRational>>> L; 096 097 098 List<GenSolvablePolynomial<BigRational>> V; 099 100 101 PolynomialList<BigRational> F, G; 102 103 104 ModuleList<BigRational> M, N; 105 106 107 SolvableGroebnerBaseAbstract<BigRational> msbb; 108 109 110 int rl = 3; //4; //3; 111 112 113 int kl = 4; 114 115 116 int ll = 3; 117 118 119 int el = 2; 120 121 122 float q = 0.2f; //0.4f 123 124 125 @Override 126 protected void setUp() { 127 cfac = new BigRational(1); 128 tord = new TermOrder(); 129 pfac = new GenSolvablePolynomialRing<BigRational>(cfac, rl, tord); 130 if (Math.random() > 0.5) { 131 msbb = new SolvableGroebnerBaseSeq<BigRational>(); //cfac); 132 } else { 133 msbb = new SolvableGroebnerBaseParallel<BigRational>(); //cfac); 134 } 135 logger.info("test with " + msbb.getClass().getSimpleName()); 136 137 a = b = c = d = e = null; 138 do { 139 a = pfac.random(kl, ll, el, q); 140 b = pfac.random(kl, ll, el, q); 141 c = pfac.random(kl, ll, el, q); 142 d = pfac.random(kl, ll, el, q); 143 } while (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()); 144 e = d; // = pfac.random(kl, ll, el, q ); 145 one = pfac.getONE(); 146 zero = pfac.getZERO(); 147 } 148 149 150 @Override 151 protected void tearDown() { 152 a = b = c = d = e = null; 153 one = null; 154 zero = null; 155 msbb.terminate(); 156 msbb = null; 157 } 158 159 160 /** 161 * Test sequential left GBase. 162 */ 163 public void testSequentialLeftModSolvableGB() { 164 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 165 166 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 167 V.add(a); 168 V.add(zero); 169 V.add(one); 170 L.add(V); 171 M = new ModuleList<BigRational>(pfac, L); 172 assertTrue("isLeftGB( { (a,0,1) } )", msbb.isLeftGB(M)); 173 //System.out.println("M = " + M ); 174 175 N = msbb.leftGB(M); 176 //System.out.println("N = " + N ); 177 assertTrue("isLeftGB( { (a,0,1) } )", msbb.isLeftGB(N)); 178 179 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 180 V.add(b); 181 V.add(one); 182 V.add(zero); 183 L.add(V); 184 M = new ModuleList<BigRational>(pfac, L); 185 //System.out.println("L = " + L.size() ); 186 187 N = msbb.leftGB(M); 188 assertTrue("isLeftGB( { (a,0,1),(b,1,0) } )", msbb.isLeftGB(N)); 189 //System.out.println("N = " + N ); 190 191 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 192 V.add(c); 193 V.add(zero); 194 V.add(zero); 195 L.add(V); 196 M = new ModuleList<BigRational>(pfac, L); 197 //System.out.println("M = " + M ); 198 //System.out.println("L = " + L.size() ); 199 200 N = msbb.leftGB(M); 201 assertTrue("isLeftGB( { (a,),(b,),(c,) } )", msbb.isLeftGB(N)); 202 //System.out.println("N = " + N ); 203 204 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 205 V.add(d); 206 V.add(zero); 207 V.add(zero); 208 L.add(V); 209 M = new ModuleList<BigRational>(pfac, L); 210 //System.out.println("M = " + M ); 211 //System.out.println("L = " + L.size() ); 212 213 N = msbb.leftGB(M); 214 assertTrue("isLeftGB( { (a,b,c,d) } )", msbb.isLeftGB(N)); 215 //System.out.println("N = " + N ); 216 217 } 218 219 220 /** 221 * Test sequential left Weyl GBase. 222 */ 223 public void testSequentialLeftModSolvableWeylGB() { 224 int rloc = 4; 225 pfac = new GenSolvablePolynomialRing<BigRational>(cfac, rloc, tord); 226 //System.out.println("pfac = " + pfac); 227 //System.out.println("pfac end"); 228 229 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 230 //System.out.println("wl = "); 231 wl.generate(pfac); 232 //System.out.println("generate = "); 233 table = pfac.table; 234 //System.out.println("table = "); 235 //System.out.println("table = " + table.size()); 236 237 do { 238 a = pfac.random(kl, ll, el, q); 239 b = pfac.random(kl, ll, el, q); 240 c = pfac.random(kl, ll, el, q); 241 d = pfac.random(kl, ll, el, q); 242 } while (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()); 243 e = d; // = pfac.random(kl, ll, el, q ); 244 one = pfac.getONE(); 245 zero = pfac.getZERO(); 246 //System.out.println("a = " + a ); 247 //System.out.println("b = " + b ); 248 //System.out.println("c = " + c ); 249 //System.out.println("d = " + d ); 250 //System.out.println("e = " + e ); 251 252 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 253 254 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 255 V.add(a); 256 V.add(zero); 257 V.add(one); 258 L.add(V); 259 M = new ModuleList<BigRational>(pfac, L); 260 assertTrue("isLeftGB( { (a,0,1) } )", msbb.isLeftGB(M)); 261 262 N = msbb.leftGB(M); 263 assertTrue("isLeftGB( { (a,0,1) } )", msbb.isLeftGB(N)); 264 265 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 266 V.add(b); 267 V.add(one); 268 V.add(zero); 269 L.add(V); 270 M = new ModuleList<BigRational>(pfac, L); 271 //System.out.println("L = " + L.size() ); 272 273 N = msbb.leftGB(M); 274 assertTrue("isLeftGB( { (a,0,1),(b,1,0) } )", msbb.isLeftGB(N)); 275 //System.out.println("N = " + N ); 276 277 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 278 V.add(c); 279 V.add(zero); 280 V.add(zero); 281 L.add(V); 282 M = new ModuleList<BigRational>(pfac, L); 283 //System.out.println("M = " + M ); 284 //System.out.println("L = " + L.size() ); 285 286 N = msbb.leftGB(M); 287 assertTrue("isLeftGB( { (a,),(b,),(c,) } )", msbb.isLeftGB(N)); 288 //System.out.println("N = " + N ); 289 290 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 291 V.add(d); 292 V.add(zero); 293 V.add(zero); 294 L.add(V); 295 M = new ModuleList<BigRational>(pfac, L); 296 //System.out.println("M = " + M ); 297 //System.out.println("L = " + L.size() ); 298 299 N = msbb.leftGB(M); 300 assertTrue("isLeftGB( { (a,b,c,d) } )", msbb.isLeftGB(N)); 301 //System.out.println("N = " + N ); 302 } 303 304 305 /** 306 * Test sequential twosided GBase. 307 */ 308 public void testSequentialTSModSolvableGB() { 309 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 310 311 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 312 V.add(a); 313 V.add(zero); 314 V.add(one); 315 L.add(V); 316 M = new ModuleList<BigRational>(pfac, L); 317 assertTrue("isTwosidedGB( { (a,0,1) } )", msbb.isTwosidedGB(M)); 318 319 N = msbb.twosidedGB(M); 320 assertTrue("isTwosidedGB( { (a,0,1) } )", msbb.isTwosidedGB(N)); 321 322 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 323 V.add(b); 324 V.add(one); 325 V.add(zero); 326 L.add(V); 327 M = new ModuleList<BigRational>(pfac, L); 328 //System.out.println("L = " + L.size() ); 329 330 N = msbb.twosidedGB(M); 331 assertTrue("isTwosidedGB( { (a,0,1),(b,1,0) } )", msbb.isTwosidedGB(N)); 332 //System.out.println("N = " + N ); 333 334 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 335 V.add(c); 336 V.add(zero); 337 V.add(zero); 338 L.add(V); 339 M = new ModuleList<BigRational>(pfac, L); 340 //System.out.println("L = " + L.size() ); 341 342 N = msbb.twosidedGB(M); 343 assertTrue("isTwosidedGB( { (a,),(b,),(c,) } )", msbb.isTwosidedGB(N)); 344 //System.out.println("N = " + N ); 345 346 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 347 V.add(d); 348 V.add(zero); 349 V.add(zero); 350 L.add(V); 351 M = new ModuleList<BigRational>(pfac, L); 352 //System.out.println("L = " + L.size() ); 353 354 N = msbb.twosidedGB(M); 355 assertTrue("isTwosidedGB( { (a,b,c,d) } )", msbb.isTwosidedGB(N)); 356 //System.out.println("N = " + N ); 357 } 358 359 360 /** 361 * Test sequential twosided Weyl GBase. 362 */ 363 public void testSequentialTSModSolvableWeylGB() { 364 int rloc = 4; 365 pfac = new GenSolvablePolynomialRing<BigRational>(cfac, rloc, tord); 366 //System.out.println("pfac = " + pfac); 367 //System.out.println("pfac end"); 368 369 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 370 //System.out.println("wl = "); 371 wl.generate(pfac); 372 //System.out.println("generate = "); 373 table = pfac.table; 374 //System.out.println("table = "); 375 //System.out.println("table = " + table.size()); 376 377 do { 378 a = pfac.random(kl, ll, el, q); 379 b = pfac.random(kl, ll, el, q); 380 c = pfac.random(kl, ll, el, q); 381 d = pfac.random(kl, ll, el, q); 382 } while (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()); 383 e = d; // = pfac.random(kl, ll, el, q ); 384 one = pfac.getONE(); 385 zero = pfac.getZERO(); 386 //System.out.println("a = " + a ); 387 //System.out.println("b = " + b ); 388 //System.out.println("c = " + c ); 389 //System.out.println("d = " + d ); 390 //System.out.println("e = " + e ); 391 392 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 393 394 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 395 V.add(a); 396 V.add(zero); 397 V.add(one); 398 L.add(V); 399 M = new ModuleList<BigRational>(pfac, L); 400 // not true in general 401 assertTrue("isTwosidedGB( { (a,0,1) } )", msbb.isTwosidedGB(M) || !pfac.isCommutative()); 402 403 N = msbb.twosidedGB(M); 404 assertTrue("isTwosidedGB( { (a,0,1) } )", msbb.isTwosidedGB(N)); 405 406 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 407 V.add(b); 408 V.add(one); 409 V.add(zero); 410 L.add(V); 411 M = new ModuleList<BigRational>(pfac, L); 412 //System.out.println("L = " + L.size() ); 413 414 N = msbb.twosidedGB(M); 415 assertTrue("isTwosidedGB( { (a,0,1),(b,1,0) } )", msbb.isTwosidedGB(N)); 416 //System.out.println("N = " + N ); 417 418 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 419 V.add(c); 420 V.add(zero); 421 V.add(zero); 422 L.add(V); 423 M = new ModuleList<BigRational>(pfac, L); 424 //System.out.println("M = " + M ); 425 //System.out.println("L = " + L.size() ); 426 427 N = msbb.twosidedGB(M); 428 assertTrue("isTwosidedGB( { (a,),(b,),(c,) } )", msbb.isTwosidedGB(N)); 429 //System.out.println("N = " + N ); 430 431 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 432 V.add(d); 433 V.add(zero); 434 V.add(zero); 435 L.add(V); 436 M = new ModuleList<BigRational>(pfac, L); 437 //System.out.println("M = " + M ); 438 //System.out.println("L = " + L.size() ); 439 440 N = msbb.twosidedGB(M); 441 assertTrue("isTwosidedGB( { (a,b,c,d) } )", msbb.isTwosidedGB(N)); 442 //System.out.println("N = " + N ); 443 } 444 445 446 /** 447 * Test sequential right GBase. 448 */ 449 public void testSequentialRightModSolvableGB() { 450 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 451 452 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 453 V.add(a); 454 V.add(zero); 455 V.add(one); 456 L.add(V); 457 M = new ModuleList<BigRational>(pfac, L); 458 assertTrue("isRightGB( { (a,0,1) } )", msbb.isRightGB(M)); 459 //System.out.println("M = " + M ); 460 461 N = msbb.rightGB(M); 462 //System.out.println("N = " + N ); 463 assertTrue("isRightGB( { (a,0,1) } )", msbb.isRightGB(N)); 464 465 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 466 V.add(b); 467 V.add(one); 468 V.add(zero); 469 L.add(V); 470 M = new ModuleList<BigRational>(pfac, L); 471 //System.out.println("L = " + L.size() ); 472 473 //System.out.println("M = " + M ); 474 N = msbb.rightGB(M); 475 //System.out.println("N = " + N ); 476 assertTrue("isRightGB( { (a,0,1),(b,1,0) } )", msbb.isRightGB(N)); 477 478 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 479 V.add(c); 480 V.add(zero); 481 V.add(zero); 482 L.add(V); 483 M = new ModuleList<BigRational>(pfac, L); 484 //System.out.println("M = " + M ); 485 //System.out.println("L = " + L.size() ); 486 487 N = msbb.rightGB(M); 488 assertTrue("isRightGB( { (a,),(b,),(c,) } )", msbb.isRightGB(N)); 489 //System.out.println("N = " + N ); 490 491 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 492 V.add(d); 493 V.add(zero); 494 V.add(zero); 495 L.add(V); 496 M = new ModuleList<BigRational>(pfac, L); 497 //System.out.println("M = " + M ); 498 //System.out.println("L = " + L.size() ); 499 500 N = msbb.rightGB(M); 501 assertTrue("isRightGB( { (a,b,c,d) } )", msbb.isRightGB(N)); 502 //System.out.println("N = " + N ); 503 } 504 505 506 /** 507 * Test sequential right Weyl GBase. 508 */ 509 public void testSequentialRightModSolvableWeylGB() { 510 int rloc = 4; 511 pfac = new GenSolvablePolynomialRing<BigRational>(cfac, rloc, tord); 512 //System.out.println("pfac = " + pfac); 513 //System.out.println("pfac end"); 514 515 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 516 //System.out.println("wl = "); 517 wl.generate(pfac); 518 //System.out.println("generate = "); 519 table = pfac.table; 520 //System.out.println("table = "); 521 //System.out.println("table = " + table.size()); 522 523 do { 524 a = pfac.random(kl, ll, el, q); 525 b = pfac.random(kl, ll, el, q); 526 c = pfac.random(kl, ll, el, q); 527 d = pfac.random(kl, ll, el, q); 528 } while (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()); 529 e = d; // = pfac.random(kl, ll, el, q ); 530 one = pfac.getONE(); 531 zero = pfac.getZERO(); 532 //System.out.println("a = " + a ); 533 //System.out.println("b = " + b ); 534 //System.out.println("c = " + c ); 535 //System.out.println("d = " + d ); 536 //System.out.println("e = " + e ); 537 538 L = new ArrayList<List<GenSolvablePolynomial<BigRational>>>(); 539 540 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 541 V.add(a); 542 V.add(zero); 543 V.add(one); 544 L.add(V); 545 M = new ModuleList<BigRational>(pfac, L); 546 assertTrue("isRightGB( { (a,0,1) } )", msbb.isRightGB(M)); 547 548 N = msbb.rightGB(M); 549 assertTrue("isRightGB( { (a,0,1) } )", msbb.isRightGB(N)); 550 551 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 552 V.add(b); 553 V.add(one); 554 V.add(zero); 555 L.add(V); 556 M = new ModuleList<BigRational>(pfac, L); 557 //System.out.println("L = " + L.size() ); 558 559 //System.out.println("M = " + M ); 560 N = msbb.rightGB(M); 561 //System.out.println("N = " + N ); 562 assertTrue("isRightGB( { (a,0,1),(b,1,0) } )", msbb.isRightGB(N)); 563 564 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 565 V.add(c); 566 V.add(zero); 567 V.add(zero); 568 L.add(V); 569 M = new ModuleList<BigRational>(pfac, L); 570 //System.out.println("M = " + M ); 571 //System.out.println("L = " + L.size() ); 572 573 N = msbb.rightGB(M); 574 assertTrue("isRightGB( { (a,),(b,),(c,) } )", msbb.isRightGB(N)); 575 //System.out.println("N = " + N ); 576 577 V = new ArrayList<GenSolvablePolynomial<BigRational>>(); 578 V.add(d); 579 V.add(zero); 580 V.add(zero); 581 L.add(V); 582 M = new ModuleList<BigRational>(pfac, L); 583 //System.out.println("M = " + M ); 584 //System.out.println("L = " + L.size() ); 585 586 N = msbb.rightGB(M); 587 assertTrue("isRightGB( { (a,b,c,d) } )", msbb.isRightGB(N)); 588 //System.out.println("N = " + N ); 589 } 590 591}