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