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