001/* 002 * $Id: SolvableGroebnerBaseSeqTest.java 4510 2013-07-25 09:05:27Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007import java.util.ArrayList; 008import java.util.List; 009 010import junit.framework.Test; 011import junit.framework.TestCase; 012import junit.framework.TestSuite; 013 014import org.apache.log4j.BasicConfigurator; 015//import org.apache.log4j.Logger; 016 017import edu.jas.arith.BigRational; 018import edu.jas.poly.GenSolvablePolynomial; 019import edu.jas.poly.GenSolvablePolynomialRing; 020import edu.jas.poly.PolynomialList; 021import edu.jas.poly.RelationTable; 022import edu.jas.poly.TermOrder; 023import edu.jas.poly.WeylRelations; 024import edu.jas.poly.RelationGenerator; 025 026/** 027 * Solvable Groebner base sequential tests with JUnit. 028 * @author Heinz Kredel. 029 */ 030 031public class SolvableGroebnerBaseSeqTest extends TestCase { 032 033 //private static final Logger logger = Logger.getLogger(SolvableGroebnerBaseSeqTest.class); 034 035 /** 036 * main. 037 */ 038 public static void main (String[] args) { 039 BasicConfigurator.configure(); 040 junit.textui.TestRunner.run( suite() ); 041 } 042 043 /** 044 * Constructs a <CODE>SolvableGroebnerBaseSeqTest</CODE> object. 045 * @param name String. 046 */ 047 public SolvableGroebnerBaseSeqTest(String name) { 048 super(name); 049 } 050 051 /** 052 * suite. 053 */ 054 public static Test suite() { 055 TestSuite suite= new TestSuite(SolvableGroebnerBaseSeqTest.class); 056 return suite; 057 } 058 059 int port = 4711; 060 String host = "localhost"; 061 062 GenSolvablePolynomial<BigRational> a; 063 GenSolvablePolynomial<BigRational> b; 064 GenSolvablePolynomial<BigRational> c; 065 GenSolvablePolynomial<BigRational> d; 066 GenSolvablePolynomial<BigRational> e; 067 068 List<GenSolvablePolynomial<BigRational>> L; 069 PolynomialList<BigRational> F; 070 PolynomialList<BigRational> G; 071 072 GenSolvablePolynomialRing<BigRational> ring; 073 074 SolvableGroebnerBase<BigRational> sbb; 075 076 BigRational cfac; 077 TermOrder tord; 078 RelationTable<BigRational> table; 079 080 int rl = 4; //4; //3; 081 int kl = 10; 082 int ll = 4; 083 int el = 2; 084 float q = 0.3f; //0.4f 085 086 protected void setUp() { 087 cfac = new BigRational(9); 088 tord = new TermOrder(); 089 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rl,tord); 090 table = ring.table; 091 a = b = c = d = e = null; 092 sbb = new SolvableGroebnerBaseSeq<BigRational>(); 093 094 a = ring.random(kl, ll, el, q ); 095 b = ring.random(kl, ll, el, q ); 096 c = ring.random(kl, ll, el, q ); 097 d = ring.random(kl, ll, el, q ); 098 e = d; //ring.random(kl, ll, el, q ); 099 } 100 101 protected void tearDown() { 102 a = b = c = d = e = null; 103 ring = null; 104 tord = null; 105 table = null; 106 cfac = null; 107 sbb = null; 108 } 109 110 111 /** 112 * Test sequential GBase. 113 */ 114 public void testSequentialGBase() { 115 116 if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 117 return; 118 } 119 120 assertTrue("not isZERO( a )", !a.isZERO() ); 121 122 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 123 L.add(a); 124 125 L = sbb.leftGB( L ); 126 assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L) ); 127 128 assertTrue("not isZERO( b )", !b.isZERO() ); 129 L.add(b); 130 //System.out.println("L = " + L.size() ); 131 132 L = sbb.leftGB( L ); 133 assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L) ); 134 135 assertTrue("not isZERO( c )", !c.isZERO() ); 136 L.add(c); 137 138 L = sbb.leftGB( L ); 139 assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L) ); 140 141 assertTrue("not isZERO( d )", !d.isZERO() ); 142 L.add(d); 143 144 L = sbb.leftGB( L ); 145 assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L) ); 146 147 assertTrue("not isZERO( e )", !e.isZERO() ); 148 L.add(e); 149 150 L = sbb.leftGB( L ); 151 assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L) ); 152 } 153 154 155 /** 156 * Test Weyl sequential GBase. 157 * 158 */ 159 public void testWeylSequentialGBase() { 160 161 int rloc = 4; 162 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rloc); 163 164 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 165 wl.generate(ring); 166 table = ring.table; 167 168 a = ring.random(kl, ll, el, q ); 169 b = ring.random(kl, ll, el, q ); 170 c = ring.random(kl, ll, el, q ); 171 d = ring.random(kl, ll, el, q ); 172 e = d; //ring.random(kl, ll, el, q ); 173 174 if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 175 return; 176 } 177 178 assertTrue("not isZERO( a )", !a.isZERO() ); 179 180 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 181 L.add(a); 182 183 L = sbb.leftGB( L ); 184 assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L) ); 185 186 assertTrue("not isZERO( b )", !b.isZERO() ); 187 L.add(b); 188 //System.out.println("L = " + L.size() ); 189 190 L = sbb.leftGB( L ); 191 assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L) ); 192 193 assertTrue("not isZERO( c )", !c.isZERO() ); 194 L.add(c); 195 196 L = sbb.leftGB( L ); 197 assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L) ); 198 199 assertTrue("not isZERO( d )", !d.isZERO() ); 200 L.add(d); 201 202 L = sbb.leftGB( L ); 203 assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L) ); 204 205 assertTrue("not isZERO( e )", !e.isZERO() ); 206 L.add(e); 207 208 L = sbb.leftGB( L ); 209 assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L) ); 210 } 211 212 213 /** 214 * Test sequential twosided GBase. 215 * 216 */ 217 public void testSequentialTSGBase() { 218 219 if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 220 return; 221 } 222 223 assertTrue("not isZERO( a )", !a.isZERO() ); 224 225 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 226 L.add(a); 227 228 L = sbb.twosidedGB( L ); 229 //System.out.println("L = " + L.size() ); 230 assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L) ); 231 232 assertTrue("not isZERO( b )", !b.isZERO() ); 233 L.add(b); 234 235 L = sbb.twosidedGB( L ); 236 //System.out.println("L = " + L.size() ); 237 assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L) ); 238 239 assertTrue("not isZERO( c )", !c.isZERO() ); 240 L.add(c); 241 242 L = sbb.twosidedGB( L ); 243 //System.out.println("L = " + L.size() ); 244 assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L) ); 245 246 assertTrue("not isZERO( d )", !d.isZERO() ); 247 L.add(d); 248 249 L = sbb.twosidedGB( L ); 250 //System.out.println("L = " + L.size() ); 251 assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L) ); 252 253 assertTrue("not isZERO( e )", !e.isZERO() ); 254 L.add(e); 255 256 L = sbb.twosidedGB( L ); 257 //System.out.println("L = " + L.size() ); 258 assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L) ); 259 } 260 261 262 263 /** 264 * Test Weyl sequential twosided GBase 265 * is always 1. 266 */ 267 public void testWeylSequentialTSGBase() { 268 269 int rloc = 4; 270 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rloc); 271 272 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 273 wl.generate(ring); 274 table = ring.table; 275 276 a = ring.random(kl, ll, el, q ); 277 b = ring.random(kl, ll, el, q ); 278 c = ring.random(kl, ll, el, q ); 279 d = ring.random(kl, ll, el, q ); 280 e = d; //ring.random(kl, ll, el, q ); 281 282 if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 283 return; 284 } 285 286 assertTrue("not isZERO( a )", !a.isZERO() ); 287 288 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 289 L.add(a); 290 291 //System.out.println("La = " + L ); 292 L = sbb.twosidedGB( L ); 293 //System.out.println("L = " + L ); 294 assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L) ); 295 296 assertTrue("not isZERO( b )", !b.isZERO() ); 297 L.add(b); 298 299 L = sbb.twosidedGB( L ); 300 //System.out.println("L = " + L ); 301 assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L) ); 302 303 assertTrue("not isZERO( c )", !c.isZERO() ); 304 L.add(c); 305 306 L = sbb.twosidedGB( L ); 307 //System.out.println("L = " + L ); 308 assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L) ); 309 310 assertTrue("not isZERO( d )", !d.isZERO() ); 311 L.add(d); 312 313 L = sbb.twosidedGB( L ); 314 //System.out.println("L = " + L ); 315 assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L) ); 316 317 assertTrue("not isZERO( e )", !e.isZERO() ); 318 L.add(e); 319 320 L = sbb.twosidedGB( L ); 321 //System.out.println("L = " + L ); 322 assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L) ); 323 } 324 325 326 /** 327 * Test sequential extended GBase. 328 * 329 */ 330 public void testSequentialExtendedGBase() { 331 332 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 333 334 SolvableExtendedGB<BigRational> exgb; 335 336 if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) { 337 return; 338 } 339 340 assertTrue("not isZERO( a )", !a.isZERO() ); 341 L.add(a); 342 //System.out.println("L = " + L ); 343 344 exgb = sbb.extLeftGB( L ); 345 //System.out.println("exgb = " + exgb ); 346 assertTrue("isLeftGB( { a } )", sbb.isLeftGB(exgb.G) ); 347 assertTrue("isLeftRmat( { a } )", sbb.isLeftReductionMatrix(exgb) ); 348 349 assertTrue("not isZERO( b )", !b.isZERO() ); 350 L.add(b); 351 //System.out.println("L = " + L ); 352 353 exgb = sbb.extLeftGB( L ); 354 //System.out.println("exgb = " + exgb ); 355 assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(exgb.G) ); 356 assertTrue("isLeftRmat( { a, b } )", sbb.isLeftReductionMatrix(exgb) ); 357 358 assertTrue("not isZERO( c )", !c.isZERO() ); 359 L.add(c); 360 361 exgb = sbb.extLeftGB( L ); 362 //System.out.println("exgb = " + exgb ); 363 assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(exgb.G) ); 364 assertTrue("isLeftRmat( { a, b, c } )", sbb.isLeftReductionMatrix(exgb) ); 365 366 assertTrue("not isZERO( d )", !d.isZERO() ); 367 L.add(d); 368 369 exgb = sbb.extLeftGB( L ); 370 //System.out.println("exgb = " + exgb ); 371 assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(exgb.G) ); 372 assertTrue("isLeftRmat( { a, b, c, d } )", sbb.isLeftReductionMatrix(exgb) ); 373 374 375 assertTrue("not isZERO( e )", !e.isZERO() ); 376 L.add(e); 377 378 exgb = sbb.extLeftGB( L ); 379 //System.out.println("exgb = " + exgb ); 380 assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(exgb.G) ); 381 assertTrue("isLeftRmat( { a, b, c, d, e } )", sbb.isLeftReductionMatrix(exgb) ); 382 } 383 384 385 /** 386 * Test Weyl sequential extended GBase. 387 * 388 */ 389 public void testWeylSequentialExtendedGBase() { 390 391 int rloc = 4; 392 ring = new GenSolvablePolynomialRing<BigRational>(cfac,rloc); 393 394 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 395 wl.generate(ring); 396 table = ring.table; 397 398 a = ring.random(kl, ll, el, q ); 399 b = ring.random(kl, ll, el, q ); 400 c = ring.random(kl, ll, el, q ); 401 d = ring.random(kl, ll, el, q ); 402 e = d; //ring.random(kl, ll, el, q ); 403 404 SolvableExtendedGB<BigRational> exgb; 405 406 assertTrue("not isZERO( a )", !a.isZERO() ); 407 408 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 409 L.add(a); 410 411 exgb = sbb.extLeftGB( L ); 412 // System.out.println("exgb = " + exgb ); 413 assertTrue("isLeftGB( { a } )", sbb.isLeftGB(exgb.G) ); 414 assertTrue("isRmat( { a } )", sbb.isLeftReductionMatrix(exgb) ); 415 416 assertTrue("not isZERO( b )", !b.isZERO() ); 417 L.add(b); 418 //System.out.println("L = " + L.size() ); 419 420 exgb = sbb.extLeftGB( L ); 421 //System.out.println("exgb = " + exgb ); 422 assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(exgb.G) ); 423 assertTrue("isRmat( { a, b } )", sbb.isLeftReductionMatrix(exgb) ); 424 425 assertTrue("not isZERO( c )", !c.isZERO() ); 426 L.add(c); 427 428 exgb = sbb.extLeftGB( L ); 429 //System.out.println("exgb = " + exgb ); 430 assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(exgb.G) ); 431 assertTrue("isRmat( { a, b, c } )", sbb.isLeftReductionMatrix(exgb) ); 432 433 assertTrue("not isZERO( d )", !d.isZERO() ); 434 L.add(d); 435 436 exgb = sbb.extLeftGB( L ); 437 //System.out.println("exgb = " + exgb ); 438 assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(exgb.G) ); 439 assertTrue("isRmat( { a, b, c, d } )", sbb.isLeftReductionMatrix(exgb) ); 440 441 assertTrue("not isZERO( e )", !e.isZERO() ); 442 L.add(e); 443 444 exgb = sbb.extLeftGB( L ); 445 //System.out.println("exgb = " + exgb ); 446 assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(exgb.G) ); 447 assertTrue("isRmat( { a, b, c, d, e } )", sbb.isLeftReductionMatrix(exgb) ); 448 } 449 450}