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