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