001/* 002 * $Id$ 003 */ 004 005package edu.jas.application; 006 007 008import java.util.List; 009 010import junit.framework.Test; 011import junit.framework.TestCase; 012import junit.framework.TestSuite; 013 014import edu.jas.arith.BigInteger; 015import edu.jas.arith.BigRational; 016import edu.jas.gb.DGroebnerBaseSeq; 017import edu.jas.gb.EGroebnerBaseSeq; 018import edu.jas.gb.GBOptimized; 019import edu.jas.gb.GBProxy; 020import edu.jas.gb.GroebnerBaseAbstract; 021import edu.jas.gb.GroebnerBaseParallel; 022import edu.jas.gb.GroebnerBaseSeq; 023import edu.jas.gb.GroebnerBaseSeqIter; 024import edu.jas.gb.GroebnerBaseSigSeqIter; 025import edu.jas.gb.GroebnerBaseF5zSigSeqIter; 026import edu.jas.gb.GroebnerBaseGGVSigSeqIter; 027import edu.jas.gb.GroebnerBaseArriSigSeqIter; 028import edu.jas.gb.GroebnerBaseParIter; 029import edu.jas.gbufd.GBFactory; 030import edu.jas.gbufd.GroebnerBaseFGLM; 031import edu.jas.gbufd.GroebnerBaseWalk; 032import edu.jas.gbufd.GroebnerBasePseudoSeq; 033import edu.jas.gbufd.GroebnerBaseRational; 034import edu.jas.gbufd.GroebnerBaseQuotient; 035import edu.jas.kern.ComputerThreads; 036import edu.jas.poly.GenPolynomial; 037import edu.jas.poly.GenPolynomialRing; 038import edu.jas.ufd.Quotient; 039import edu.jas.ufd.QuotientRing; 040 041 042/** 043 * GBAlgorithmBuilder tests with JUnit. 044 * @author Heinz Kredel 045 */ 046 047public class GBAlgorithmBuilderTest extends TestCase { 048 049 050 /** 051 * main. 052 */ 053 public static void main(String[] args) { 054 055 junit.textui.TestRunner.run(suite()); 056 } 057 058 059 /** 060 * Constructs a <CODE>GBAlgorithmBuilderTest</CODE> object. 061 * @param name String. 062 */ 063 public GBAlgorithmBuilderTest(String name) { 064 super(name); 065 } 066 067 068 /** 069 * suite. 070 */ 071 public static Test suite() { 072 TestSuite suite = new TestSuite(GBAlgorithmBuilderTest.class); 073 return suite; 074 } 075 076 077 GBAlgorithmBuilder builder; 078 079 080 @Override 081 protected void setUp() { 082 builder = null; 083 } 084 085 086 @Override 087 protected void tearDown() { 088 builder = null; 089 ComputerThreads.terminate(); 090 } 091 092 093 /** 094 * Test basic construction for BigRational. 095 */ 096 public void testConstructionRational() { 097 BigRational bf = new BigRational(1); 098 String[] vars = new String[] { "a", "b", "c" }; 099 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 100 101 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 102 //System.out.println("ab = " + ab); 103 String s = ab.toString() + " :: " + ab.toScript(); 104 //System.out.println("s = " + s + ", len(s) = " + s.length()); 105 assertTrue("len(s) >= 150 " + s, s.length() >= 150); 106 107 GroebnerBaseAbstract<BigRational> bb = ab.build(); 108 //System.out.println("bb = " + bb); 109 assertTrue("instance of " + bb, bb instanceof GroebnerBaseSeq); 110 } 111 112 113 /** 114 * Test construction for BigRational and FGLM. 115 */ 116 public void testConstructionRationalFGLM() { 117 BigRational bf = new BigRational(1); 118 String[] vars = new String[] { "a", "b", "c" }; 119 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 120 121 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 122 //System.out.println("ab = " + ab); 123 124 ab = ab.graded(); 125 //System.out.println("ab = " + ab); 126 127 GroebnerBaseAbstract<BigRational> bb = ab.build(); 128 //System.out.println("bb = " + bb); 129 assertTrue("instance of " + bb, bb instanceof GroebnerBaseFGLM); 130 } 131 132 133 /** 134 * Test construction for BigRational and Groebner walk. 135 */ 136 public void testConstructionRationalWalk() { 137 BigRational bf = new BigRational(1); 138 String[] vars = new String[] { "a", "b", "c" }; 139 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 140 141 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 142 //System.out.println("ab = " + ab); 143 144 ab = ab.walk(); 145 //System.out.println("ab = " + ab); 146 147 GroebnerBaseAbstract<BigRational> bb = ab.build(); 148 //System.out.println("bb = " + bb); 149 assertTrue("instance of " + bb, bb instanceof GroebnerBaseWalk); 150 } 151 152 153 /** 154 * Test construction for BigRational and parallel. 155 */ 156 public void testConstructionRationalParallel() { 157 BigRational bf = new BigRational(1); 158 String[] vars = new String[] { "a", "b", "c" }; 159 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 160 161 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 162 //System.out.println("ab = " + ab); 163 164 ab = ab.parallel(); 165 //System.out.println("ab = " + ab); 166 167 GroebnerBaseAbstract<BigRational> bb = ab.build(); 168 //System.out.println("bb = " + bb); 169 assertTrue("instance of " + bb, bb instanceof GBProxy); 170 171 GBProxy<BigRational> bbp = (GBProxy<BigRational>) bb; 172 assertTrue("instance of " + bbp.e1, bbp.e1 instanceof GroebnerBaseSeq); 173 assertTrue("instance of " + bbp.e2, bbp.e2 instanceof GroebnerBaseParallel); 174 } 175 176 177 /** 178 * Test construction for BigRational fraction free and parallel. 179 */ 180 public void testConstructionRationalFFParallel() { 181 BigRational bf = new BigRational(1); 182 String[] vars = new String[] { "a", "b", "c" }; 183 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 184 185 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 186 //System.out.println("ab = " + ab); 187 188 ab = ab.fractionFree(); 189 //System.out.println("ab = " + ab); 190 191 ab = ab.parallel(); 192 //System.out.println("ab = " + ab); 193 194 GroebnerBaseAbstract<BigRational> bb = ab.build(); 195 //System.out.println("bb = " + bb); 196 assertTrue("instance of " + bb, bb instanceof GBProxy); 197 198 GBProxy<BigRational> bbp = (GBProxy<BigRational>) bb; 199 assertTrue("instance of " + bbp.e1, bbp.e1 instanceof GroebnerBaseRational); 200 assertTrue("instance of " + bbp.e2, bbp.e2 instanceof GroebnerBaseRational); 201 } 202 203 204 /** 205 * Test construction for BigRational and optimize. 206 */ 207 public void testConstructionRationalOptimized() { 208 BigRational bf = new BigRational(1); 209 String[] vars = new String[] { "a", "b", "c" }; 210 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 211 212 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 213 //System.out.println("ab = " + ab); 214 215 ab = ab.optimize(); 216 //System.out.println("ab = " + ab); 217 218 GroebnerBaseAbstract<BigRational> bb = ab.build(); 219 //System.out.println("bb = " + bb); 220 assertTrue("instance of " + bb, bb instanceof GBOptimized); 221 } 222 223 224 /** 225 * Test construction for BigRational and fraction free. 226 */ 227 public void testConstructionRationalFF() { 228 BigRational bf = new BigRational(1); 229 String[] vars = new String[] { "a", "b", "c" }; 230 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 231 232 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 233 //System.out.println("ab = " + ab); 234 235 ab = ab.fractionFree(); 236 //System.out.println("ab = " + ab); 237 238 GroebnerBaseAbstract<BigRational> bb = ab.build(); 239 //System.out.println("bb = " + bb); 240 assertTrue("instance of " + bb, bb instanceof GroebnerBaseRational); 241 } 242 243 244 /** 245 * Test basic construction for BigInteger. 246 */ 247 public void testConstructionInteger() { 248 BigInteger bf = new BigInteger(1); 249 String[] vars = new String[] { "a", "b", "c" }; 250 GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(bf, vars); 251 252 GBAlgorithmBuilder<BigInteger> ab = GBAlgorithmBuilder.<BigInteger> polynomialRing(pf); 253 //System.out.println("ab = " + ab); 254 255 GroebnerBaseAbstract<BigInteger> bb = ab.build(); 256 //System.out.println("bb = " + bb); 257 assertTrue("instance of " + bb, bb instanceof GroebnerBasePseudoSeq); 258 } 259 260 261 /** 262 * Test construction for d-GB BigInteger. 263 */ 264 public void testConstructionIntegerDGB() { 265 BigInteger bf = new BigInteger(1); 266 String[] vars = new String[] { "a", "b", "c" }; 267 GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(bf, vars); 268 269 GBAlgorithmBuilder<BigInteger> ab = GBAlgorithmBuilder.<BigInteger> polynomialRing(pf); 270 //System.out.println("ab = " + ab); 271 272 ab = ab.domainAlgorithm(GBFactory.Algo.dgb); 273 //System.out.println("ab = " + ab); 274 275 GroebnerBaseAbstract<BigInteger> bb = ab.build(); 276 //System.out.println("bb = " + bb); 277 assertTrue("instance of " + bb, bb instanceof DGroebnerBaseSeq); 278 } 279 280 281 /** 282 * Test construction for e-GB BigInteger. 283 */ 284 public void testConstructionIntegerEGB() { 285 BigInteger bf = new BigInteger(1); 286 String[] vars = new String[] { "a", "b", "c" }; 287 GenPolynomialRing<BigInteger> pf = new GenPolynomialRing<BigInteger>(bf, vars); 288 289 GBAlgorithmBuilder<BigInteger> ab = GBAlgorithmBuilder.<BigInteger> polynomialRing(pf); 290 //System.out.println("ab = " + ab); 291 292 ab = ab.domainAlgorithm(GBFactory.Algo.egb); 293 //System.out.println("ab = " + ab); 294 295 GroebnerBaseAbstract<BigInteger> bb = ab.build(); 296 //System.out.println("bb = " + bb); 297 assertTrue("instance of " + bb, bb instanceof EGroebnerBaseSeq); 298 } 299 300 301 /** 302 * Test construction for BigRational and more. 303 */ 304 public void testConstructionRationalMore() { 305 BigRational bf = new BigRational(1); 306 String[] vars = new String[] { "a", "b", "c" }; 307 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 308 309 GroebnerBaseAbstract<BigRational> bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf) 310 .fractionFree().optimize().build(); 311 //System.out.println("bb = " + bb); 312 assertTrue("instance of " + bb, bb instanceof GBOptimized); 313 314 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().parallel().optimize().build(); 315 //System.out.println("bb = " + bb); 316 assertTrue("instance of " + bb, bb instanceof GBOptimized); 317 318 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().graded().parallel() 319 .optimize().build(); 320 //System.out.println("bb = " + bb); 321 assertTrue("instance of " + bb, bb instanceof GBOptimized); 322 } 323 324 325 /** 326 * Test construction for BigRational and more and compute. 327 */ 328 public void testConstructionRationalMoreCompute() { 329 List<GenPolynomial<BigRational>> cp = ExamplesGeoTheorems.getExample(); 330 GenPolynomialRing<BigRational> pf = cp.get(0).ring; 331 332 GroebnerBaseAbstract<BigRational> bb; 333 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().parallel().optimize().build(); 334 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).parallel().optimize().build(); 335 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).build(); 336 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).optimize().build(); 337 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().build(); 338 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).parallel().build(); 339 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().optimize().build(); 340 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).parallel().fractionFree().optimize().build(); 341 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).optimize().fractionFree().build(); 342 //bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).fractionFree().optimize().parallel().build(); 343 //System.out.println("bb = " + bb); 344 //assertTrue("instance of " + bb, bb instanceof GBOptimized); 345 346 List<GenPolynomial<BigRational>> gb; 347 long t; 348 t = System.currentTimeMillis(); 349 gb = bb.GB(cp); 350 t = System.currentTimeMillis() - t; 351 //System.out.println("time(gb) = " + t); 352 353 t = System.currentTimeMillis(); 354 gb = bb.GB(cp); 355 t = System.currentTimeMillis() - t; 356 //System.out.println("time(gb) = " + t); 357 358 t = System.currentTimeMillis(); 359 gb = bb.GB(cp); 360 t = System.currentTimeMillis() - t; 361 //System.out.println("time(gb) = " + t); 362 assertTrue("t >= 0: ", t >= 0L); // praise findbugs 363 364 assertTrue("isGB: ", bb.isGB(gb)); 365 bb.terminate(); 366 //System.out.println("gb = " + gb); 367 //System.out.println("bb = " + bb); 368 } 369 370 371 /** 372 * Test construction for BigRational and pairlists and compute. 373 */ 374 public void testConstructionRationalParilistCompute() { 375 List<GenPolynomial<BigRational>> cp = ExamplesGeoTheorems.getExample(); 376 GenPolynomialRing<BigRational> pf = cp.get(0).ring; 377 378 GroebnerBaseAbstract<BigRational> bb; 379 List<GenPolynomial<BigRational>> gb; 380 long t; 381 382 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).normalPairlist().build(); 383 t = System.currentTimeMillis(); 384 gb = bb.GB(cp); 385 t = System.currentTimeMillis() - t; 386 //System.out.println("time(gb) = " + t); 387 assertTrue("isGB: ", bb.isGB(gb)); 388 389 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).syzygyPairlist().build(); 390 t = System.currentTimeMillis(); 391 gb = bb.GB(cp); 392 t = System.currentTimeMillis() - t; 393 //System.out.println("time(gb) = " + t); 394 assertTrue("isGB: ", bb.isGB(gb)); 395 396 bb = GBAlgorithmBuilder.<BigRational> polynomialRing(pf).simplePairlist().build(); 397 t = System.currentTimeMillis(); 398 gb = bb.GB(cp); 399 t = System.currentTimeMillis() - t; 400 //System.out.println("time(gb) = " + t); 401 assertTrue("isGB: ", bb.isGB(gb)); 402 403 assertTrue("t >= 0: ", t >= 0L); // for findbugs 404 } 405 406 407 /** 408 * Test construction for BigRational and iterate. 409 */ 410 public void testConstructionRationalIterate() { 411 BigRational bf = new BigRational(1); 412 String[] vars = new String[] { "a", "b", "c" }; 413 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 414 415 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 416 //System.out.println("ab = " + ab); 417 418 ab = ab.iterated(); 419 //System.out.println("ab = " + ab); 420 421 GroebnerBaseAbstract<BigRational> bb = ab.build(); 422 //System.out.println("bb = " + bb); 423 assertTrue("instance of " + bb, bb instanceof GroebnerBaseSeqIter); 424 425 ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 426 ab = ab.iterated().parallel(); 427 //System.out.println("ab = " + ab); 428 429 bb = ab.build(); 430 //System.out.println("bb = " + bb); 431 assertTrue("instance of " + bb, bb instanceof GBProxy); 432 433 GBProxy<BigRational> bbp = (GBProxy<BigRational>) bb; 434 assertTrue("instance of " + bbp.e1, bbp.e1 instanceof GroebnerBaseSeqIter); 435 assertTrue("instance of " + bbp.e2, bbp.e2 instanceof GroebnerBaseParIter); 436 } 437 438 439 /** 440 * Test construction for BigRational and signature based GBs. 441 */ 442 public void testConstructionRationalSignatureBased() { 443 BigRational bf = new BigRational(1); 444 String[] vars = new String[] { "a", "b", "c" }; 445 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 446 447 GBAlgorithmBuilder<BigRational> ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 448 //System.out.println("ab = " + ab); 449 450 ab = ab.F5(); 451 //System.out.println("ab = " + ab); 452 453 GroebnerBaseAbstract<BigRational> bb = ab.build(); 454 //System.out.println("bb = " + bb); 455 assertTrue("instance of " + bb, bb instanceof GroebnerBaseSigSeqIter); 456 assertTrue("instance of " + bb, bb instanceof GroebnerBaseF5zSigSeqIter); 457 458 459 ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 460 ab = ab.GGV(); 461 //System.out.println("ab = " + ab); 462 463 bb = ab.build(); 464 //System.out.println("bb = " + bb); 465 assertTrue("instance of " + bb, bb instanceof GroebnerBaseSigSeqIter); 466 assertTrue("instance of " + bb, bb instanceof GroebnerBaseGGVSigSeqIter); 467 468 469 ab = GBAlgorithmBuilder.<BigRational> polynomialRing(pf); 470 ab = ab.Arri(); 471 //System.out.println("ab = " + ab); 472 473 bb = ab.build(); 474 //System.out.println("bb = " + bb); 475 assertTrue("instance of " + bb, bb instanceof GroebnerBaseSigSeqIter); 476 assertTrue("instance of " + bb, bb instanceof GroebnerBaseArriSigSeqIter); 477 } 478 479 480 /** 481 * Test construction for Quotient and parallel. 482 */ 483 public void testConstructionQuotient() { 484 BigRational bf = new BigRational(1); 485 String[] vars = new String[] { "a", "b", "c" }; 486 GenPolynomialRing<BigRational> pf = new GenPolynomialRing<BigRational>(bf, vars); 487 QuotientRing<BigRational> qr = new QuotientRing<BigRational>(pf); 488 String[] varq = new String[] { "x", "y", "z" }; 489 GenPolynomialRing<Quotient<BigRational>> qf = new GenPolynomialRing<Quotient<BigRational>>(qr, varq); 490 491 GroebnerBaseAbstract<Quotient<BigRational>> bb; 492 GBProxy<Quotient<BigRational>> bbp; 493 bb = GBAlgorithmBuilder.<Quotient<BigRational>> polynomialRing(qf).fractionFree().build(); 494 //System.out.println("bb = " + bb); 495 assertTrue("instance of " + bb, bb instanceof GroebnerBaseQuotient); 496 497 bb = GBAlgorithmBuilder.<Quotient<BigRational>> polynomialRing(qf).fractionFree().parallel(2).build(); 498 //System.out.println("bb = " + bb); 499 assertTrue("instance of " + bb, bb instanceof GBProxy); 500 bbp = (GBProxy<Quotient<BigRational>>) bb; 501 assertTrue("instance of " + bbp.e1, bbp.e1 instanceof GroebnerBaseQuotient); 502 assertTrue("instance of " + bbp.e2, bbp.e2 instanceof GroebnerBaseQuotient); 503 504 bb = GBAlgorithmBuilder.<Quotient<BigRational>> polynomialRing(qf).fractionFree().graded().parallel() 505 .build(); 506 //System.out.println("bb = " + bb); 507 assertTrue("instance of " + bb, bb instanceof GBProxy); 508 bbp = (GBProxy<Quotient<BigRational>>) bb; 509 assertTrue("instance of " + bbp.e1, bbp.e1 instanceof GroebnerBaseFGLM); 510 assertTrue("instance of " + bbp.e2, bbp.e2 instanceof GroebnerBaseParallel); 511 } 512 513}