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