001 /* 002 * $Id: RGroebnerBasePseudoSeqTest.java 3423 2010-12-24 10:56:50Z kredel $ 003 */ 004 005 package edu.jas.gbufd; 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.BigInteger; 021 import edu.jas.arith.Product; 022 import edu.jas.arith.ProductRing; 023 import edu.jas.gb.GroebnerBase; 024 import edu.jas.poly.GenPolynomial; 025 import edu.jas.poly.GenPolynomialRing; 026 import edu.jas.poly.GenPolynomialTokenizer; 027 import edu.jas.poly.PolyUtil; 028 import edu.jas.poly.PolynomialList; 029 import edu.jas.structure.RingFactory; 030 031 032 /** 033 * R-Groebner base sequential tests with JUnit. 034 * @author Heinz Kredel. 035 */ 036 037 public class RGroebnerBasePseudoSeqTest extends TestCase { 038 039 040 // private static final Logger logger = 041 // Logger.getLogger(RGroebnerBasePseudoSeqTest.class); 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>RGroebnerBasePseudoSeqTest</CODE> object. 055 * @param name String. 056 */ 057 public RGroebnerBasePseudoSeqTest(String name) { 058 super(name); 059 } 060 061 062 /** 063 * suite. 064 */ 065 public static Test suite() { 066 TestSuite suite = new TestSuite(RGroebnerBasePseudoSeqTest.class); 067 return suite; 068 } 069 070 071 ProductRing<BigInteger> pfac; 072 073 074 GenPolynomialRing<Product<BigInteger>> fac; 075 076 077 List<GenPolynomial<Product<BigInteger>>> L; 078 079 080 PolynomialList<Product<BigInteger>> F; 081 082 083 List<GenPolynomial<Product<BigInteger>>> G; 084 085 086 GroebnerBase<Product<BigInteger>> bb; 087 088 089 GenPolynomial<Product<BigInteger>> a; 090 091 092 GenPolynomial<Product<BigInteger>> b; 093 094 095 GenPolynomial<Product<BigInteger>> c; 096 097 098 GenPolynomial<Product<BigInteger>> d; 099 100 101 GenPolynomial<Product<BigInteger>> e; 102 103 104 int pl = 3; 105 106 107 int rl = 3; // 4; //3; 108 109 110 int kl = 7; // 10; 111 112 113 int ll = 7; 114 115 116 int el = 3; 117 118 119 float q = 0.3f; // 0.4f 120 121 122 @Override 123 protected void setUp() { 124 BigInteger coeff = new BigInteger(9); 125 pfac = new ProductRing<BigInteger>(coeff, pl); 126 fac = new GenPolynomialRing<Product<BigInteger>>(pfac, rl); 127 a = b = c = d = e = null; 128 bb = new RGroebnerBasePseudoSeq<Product<BigInteger>>(pfac); 129 } 130 131 132 @Override 133 protected void tearDown() { 134 a = b = c = d = e = null; 135 fac = null; 136 bb = null; 137 } 138 139 140 /** 141 * Test sequential GBase. 142 * 143 */ 144 public void testSequentialGBase() { 145 146 L = new ArrayList<GenPolynomial<Product<BigInteger>>>(); 147 148 a = fac.random(kl, ll, el, q); 149 b = fac.random(kl, ll, el, q); 150 c = fac.random(kl, ll, el, q); 151 d = fac.random(kl, ll, el, q); 152 e = d; // fac.random(kl, ll, el, q ); 153 154 if (a.isZERO() || b.isZERO() /* || c.isZERO() || d.isZERO() */) { 155 return; 156 } 157 158 assertTrue("not isZERO( a )", !a.isZERO()); 159 L.add(a); 160 // System.out.println("L = " + L ); 161 162 L = bb.GB(L); 163 // System.out.println("L = " + L ); 164 assertTrue("isGB( { a } )", bb.isGB(L)); 165 166 assertTrue("not isZERO( b )", !b.isZERO()); 167 L.add(b); 168 // System.out.println("L = " + L ); 169 170 L = bb.GB(L); 171 // System.out.println("L = " + L ); 172 assertTrue("isGB( { a, b } )", bb.isGB(L)); 173 174 // assertTrue("not isZERO( c )", !c.isZERO() ); 175 L.add(c); 176 // System.out.println("L = " + L ); 177 178 L = bb.GB(L); 179 // System.out.println("L = " + L ); 180 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 181 182 // assertTrue("not isZERO( d )", !d.isZERO() ); 183 L.add(d); 184 // System.out.println("L = " + L ); 185 186 L = bb.GB(L); 187 // System.out.println("L = " + L ); 188 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 189 190 // assertTrue("not isZERO( e )", !e.isZERO() ); 191 L.add(e); 192 // System.out.println("L = " + L ); 193 194 L = bb.GB(L); 195 // System.out.println("L = " + L ); 196 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 197 } 198 199 200 /** 201 * Test Trinks7 GBase. 202 * 203 */ 204 @SuppressWarnings("unchecked") 205 public void testTrinks7() { 206 String exam = "Z(B,S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - 165 B - 36 ), " 207 + "( 35 P + 40 Z + 25 T - 27 S ), " 208 + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 209 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 210 + "( 99 W - 11 B S + 3 B**2 ), " + "( 10000 B**2 + 6600 B + 2673 ) " 211 + ") "; 212 Reader source = new StringReader(exam); 213 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 214 215 PolynomialList<BigInteger> F = null; 216 217 try { 218 F = (PolynomialList<BigInteger>) parser.nextPolynomialSet(); 219 } catch (ClassCastException e) { 220 fail("" + e); 221 } catch (IOException e) { 222 fail("" + e); 223 } 224 // System.out.println("F = " + F); 225 PolynomialList<Product<BigInteger>> trinks; 226 227 List<RingFactory<BigInteger>> colist; 228 colist = new ArrayList<RingFactory<BigInteger>>(); 229 230 // colist.add( new BigInteger() ); 231 // colist.add( new BigInteger() ); 232 // colist.add( new BigInteger() ); 233 // colist.add( new BigInteger() ); 234 colist.add(new BigInteger()); 235 colist.add(new BigInteger()); 236 // colist.add( new BigInteger() ); 237 // System.out.println("colist = " + colist); 238 239 ProductRing<BigInteger> pfac; 240 pfac = new ProductRing<BigInteger>(colist); 241 // System.out.println("pfac = " + pfac); 242 243 GenPolynomialRing<Product<BigInteger>> fac; 244 fac = new GenPolynomialRing<Product<BigInteger>>(pfac, F.ring); 245 // System.out.println("fac = " + fac); 246 247 List<GenPolynomial<Product<BigInteger>>> Fp = null; 248 Fp = PolyUtil.<BigInteger> toProductGen(fac, F.list); 249 250 251 List<GenPolynomial<Product<BigInteger>>> Fpp; 252 Fpp = new ArrayList<GenPolynomial<Product<BigInteger>>>(); 253 for (GenPolynomial<Product<BigInteger>> a : Fp) { 254 Fpp.add(a.multiply(pfac.getAtomic(0))); 255 Fpp.add(a.multiply(pfac.getAtomic(1))); 256 // Fpp.add( a ); 257 } 258 Fp = Fpp; 259 260 trinks = new PolynomialList<Product<BigInteger>>(fac, Fp); 261 // System.out.println("Fp = " + trinks); 262 GroebnerBase<Product<BigInteger>> bbri = new RGroebnerBasePseudoSeq<Product<BigInteger>>( 263 pfac); 264 265 List<GenPolynomial<Product<BigInteger>>> G; 266 G = bbri.GB(Fp); 267 // System.out.println("gb = " + G ); 268 269 // assertEquals("#GB(Trinks7) == 6", 6, G.size() ); 270 // System.out.println("Fp = " + trinks); 271 trinks = new PolynomialList<Product<BigInteger>>(fac, G); 272 // System.out.println("G = " + trinks); 273 274 assertTrue("isGB( GB(Trinks7) )", bbri.isGB(G)); 275 } 276 277 278 }