001/* 002 * $Id$ 003 */ 004 005package edu.jas.application; 006 007 008import java.io.IOException; 009import java.io.Reader; 010import java.io.StringReader; 011import java.util.ArrayList; 012import java.util.List; 013 014import edu.jas.arith.BigRational; 015import edu.jas.arith.Product; 016import edu.jas.gbufd.RGroebnerBasePseudoSeq; 017import edu.jas.gbufd.RReductionSeq; 018import edu.jas.kern.ComputerThreads; 019import edu.jas.poly.GenPolynomial; 020import edu.jas.poly.GenPolynomialRing; 021import edu.jas.poly.GenPolynomialTokenizer; 022import edu.jas.poly.PolynomialList; 023import edu.jas.structure.RingFactory; 024 025import junit.framework.Test; 026import junit.framework.TestCase; 027import junit.framework.TestSuite; 028 029 030/** 031 * Comprehenssive Groebner base sequential tests with JUnit. 032 * @author Heinz Kredel 033 */ 034 035public class CGBSeqTest extends TestCase { 036 037 038 /** 039 * main 040 */ 041 public static void main(String[] args) { 042 junit.textui.TestRunner.run(suite()); 043 ComputerThreads.terminate(); 044 } 045 046 047 /** 048 * Constructs a <CODE>CGBSeqTest</CODE> object. 049 * @param name String. 050 */ 051 public CGBSeqTest(String name) { 052 super(name); 053 } 054 055 056 /** 057 * suite. 058 */ 059 public static Test suite() { 060 TestSuite suite = new TestSuite(CGBSeqTest.class); 061 return suite; 062 } 063 064 065 GenPolynomialRing<BigRational> cfac; 066 067 068 GenPolynomialRing<GenPolynomial<BigRational>> fac; 069 070 071 List<GenPolynomial<GenPolynomial<BigRational>>> L; 072 073 074 ComprehensiveGroebnerBaseSeq<BigRational> bb; 075 076 077 GenPolynomial<GenPolynomial<BigRational>> a, b, c, d, e; 078 079 080 int rl = 2; //4; //3; 081 082 083 int kl = 2; 084 085 086 int ll = 3; 087 088 089 int el = 3 + 1; 090 091 092 float q = 0.3f; //0.4f 093 094 095 @Override 096 protected void setUp() { 097 BigRational coeff = new BigRational(kl); 098 String[] cv = { "a" }; //, "b" }; 099 cfac = new GenPolynomialRing<BigRational>(coeff, 1, cv); 100 String[] v = { "x" }; //, "y" }; 101 fac = new GenPolynomialRing<GenPolynomial<BigRational>>(cfac, 1, v); 102 a = b = c = d = e = null; 103 bb = new ComprehensiveGroebnerBaseSeq<BigRational>(coeff); 104 } 105 106 107 @Override 108 protected void tearDown() { 109 a = b = c = d = e = null; 110 fac = null; 111 cfac = null; 112 bb = null; 113 } 114 115 116 /* 117 * Dummy test method for jUnit. 118 * 119 public void testDummy() { 120 } 121 */ 122 123 124 /** 125 * Test sequential CGB. 126 */ 127 public void testSequentialCGB() { 128 L = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>(); 129 a = fac.random(kl, ll, el, q); 130 b = fac.random(kl, ll, el, q); 131 c = a; //fac.random(kl, ll, el, q ); 132 d = c; //fac.random(kl, ll, el, q ); 133 e = d; //fac.random(kl, ll, el, q ); 134 135 L = fac.generators(); 136 //System.out.println("generators: " + L); 137 int k = 2; 138 if (a.isZERO()) { 139 a = L.get(k); 140 } 141 if (b.isZERO()) { 142 b = L.get(k); 143 } 144 if (c.isZERO()) { 145 c = L.get(k); 146 } 147 if (d.isZERO()) { 148 d = L.get(k); 149 e = d; 150 } 151 152 L.clear(); 153 assertTrue("not isZERO( a )", !a.isZERO()); 154 L.add(a); 155 //System.out.println("L = " + L); 156 157 L = bb.GB(L); 158 //System.out.println("L = " + L); 159 assertTrue("isGB( { a } )", bb.isGB(L)); 160 //System.out.println("isGB: " + L); 161 if (L.contains(fac.getONE())) { 162 L.clear(); 163 } 164 assertTrue("not isZERO( b )", !b.isZERO()); 165 L.add(b); 166 //System.out.println("L = " + L); 167 168 L = bb.GB(L); 169 assertTrue("isGB( { a, b } )", bb.isGB(L)); 170 //System.out.println("L = " + L); 171 172 assertTrue("not isZERO( c )", !c.isZERO()); 173 L.add(c); 174 //System.out.println("L = " + L); 175 176 L = bb.GB(L); 177 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 178 //System.out.println("L = " + L); 179 } 180 181 182 /** 183 * Test Trinks CGB. 184 */ 185 @SuppressWarnings("unchecked") 186 public void testTrinks7GBase() { 187 PolynomialList<GenPolynomial<BigRational>> F = null; 188 List<GenPolynomial<GenPolynomial<BigRational>>> G = null; 189 String exam = "IntFunc(b) (S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - { 165 b + 36 } ), " 190 + "( 35 P + 40 Z + 25 T - 27 S ), " 191 + "( 15 W + 25 S P + 30 Z - 18 T - { 165 b**2 } ), " + "( - 9 W + 15 T P + 20 S Z ), " 192 + "( P W + 2 T Z - { 11 b**3 } ), " + "( 99 W - { 11 b } S + { 3 b**2 } ), " 193 + "( { b**2 + 33/50 b + 2673/10000 } ) " + ") "; 194 Reader source = new StringReader(exam); 195 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 196 try { 197 F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet(); 198 } catch (ClassCastException e) { 199 fail("" + e); 200 } catch (IOException e) { 201 fail("" + e); 202 } 203 //System.out.println("F = " + F); 204 205 G = bb.GB(F.list); 206 assertTrue("isGB( GB(Trinks7) )", bb.isGB(G)); 207 208 //PolynomialList<GenPolynomial<BigRational>> trinks 209 // = new PolynomialList<GenPolynomial<BigRational>>(F.ring,G); 210 //System.out.println("G = " + trinks); 211 //System.out.println("G = " + G); 212 } 213 214 215 /** 216 * Test Raksanyi & Walter example comprehensive GB and regular GB. 217 */ 218 @SuppressWarnings("unchecked") 219 public void testRaksanyiCGBase() { 220 PolynomialList<GenPolynomial<BigRational>> F = null; 221 String exam = "IntFunc(a1,a2,a3,a4) (x1,x2,x3,x4) L " + "( " + "( x4 - ( a4 - a2 ) ), " 222 + "( x1 + x2 + x3 + x4 - ( a1 + a3 + a4 ) ), " 223 + "( x1 * x3 + x1 * x4 + x2 * x3 + x3 * x4 - ( a1 * a4 + a1 * a3 + a3 * a4 ) ), " 224 + "( x1 * x3 * x4 - ( a1 * a3 * a4 ) ) " + ") "; 225 Reader source = new StringReader(exam); 226 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 227 try { 228 F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet(); 229 } catch (ClassCastException e) { 230 fail("" + e); 231 } catch (IOException e) { 232 fail("" + e); 233 } 234 //System.out.println("F = " + F.toScript()); 235 236 // as comprehensive Gröbner system 237 GroebnerSystem<BigRational> GS; 238 List<GenPolynomial<GenPolynomial<BigRational>>> G; 239 240 GS = bb.GBsys(F.list); 241 //System.out.println("GBsys(F) = GS = " + GS); 242 assertTrue("isGBsys( GBsys(Raksanyi) )", bb.isGB(GS)); 243 String s = GS.toString() + ", " + GS.toScript(); 244 //System.out.println("s = " + s + ", " + s.length()); 245 assertTrue("length( string(GS) ) >= 10500", s.length() >= 10500); 246 247 G = GS.getCGB(); 248 //System.out.println("cgb( GS ) = " + G); 249 assertTrue("isCGB( CGB(Raksanyi) )", bb.isGB(G)); 250 251 // as regular ring 252 RReductionSeq<Product<Residue<BigRational>>> res; 253 RGroebnerBasePseudoSeq<Product<Residue<BigRational>>> rbb; 254 List<GenPolynomial<Product<Residue<BigRational>>>> Gr, Grbc, GBr; 255 256 Gr = PolyUtilApp.<BigRational> toProductRes(GS.list); // list of colored systems 257 //System.out.println("Gr = " + Gr); 258 res = new RReductionSeq<Product<Residue<BigRational>>>(); 259 Grbc = res.booleanClosure(Gr); 260 //System.out.println("Grbc = " + Grbc); 261 262 RingFactory<Product<Residue<BigRational>>> cofac = Grbc.get(0).ring.coFac; 263 //System.out.println("cofac = " + cofac.toScript()); 264 rbb = new RGroebnerBasePseudoSeq<Product<Residue<BigRational>>>(cofac); 265 //System.out.println("isGB(Grbc) = " + rbb.isGB(Grbc)); 266 assertTrue("isGB(Grbc)", rbb.isGB(Grbc)); 267 268 GBr = rbb.GB(Grbc); 269 //System.out.println("GBr = " + GBr); 270 assertTrue("isRGB( RGB(Raksanyi) )", rbb.isGB(GBr)); 271 } 272 273}