001/* 002 * $Id: RGroebnerBasePseudoSeqTest.java 4071 2012-07-27 19:59:38Z kredel $ 003 */ 004 005package edu.jas.gbufd; 006 007 008import java.io.IOException; 009import java.io.Reader; 010import java.io.StringReader; 011import java.util.ArrayList; 012import java.util.List; 013 014import junit.framework.Test; 015import junit.framework.TestCase; 016import junit.framework.TestSuite; 017 018import org.apache.log4j.BasicConfigurator; 019 020import edu.jas.arith.BigInteger; 021import edu.jas.arith.Product; 022import edu.jas.arith.ProductRing; 023import edu.jas.gb.GroebnerBase; 024import edu.jas.poly.GenPolynomial; 025import edu.jas.poly.GenPolynomialRing; 026import edu.jas.poly.GenPolynomialTokenizer; 027import edu.jas.poly.PolyUtil; 028import edu.jas.poly.PolynomialList; 029import edu.jas.structure.RingFactory; 030 031 032/** 033 * R-Groebner base sequential tests with JUnit. 034 * @author Heinz Kredel. 035 */ 036 037public 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 ), " + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 208 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 209 + "( 99 W - 11 B S + 3 B**2 ), " + "( 10000 B**2 + 6600 B + 2673 ) " + ") "; 210 Reader source = new StringReader(exam); 211 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 212 213 PolynomialList<BigInteger> F = null; 214 215 try { 216 F = (PolynomialList<BigInteger>) parser.nextPolynomialSet(); 217 } catch (ClassCastException e) { 218 fail("" + e); 219 } catch (IOException e) { 220 fail("" + e); 221 } 222 // System.out.println("F = " + F); 223 PolynomialList<Product<BigInteger>> trinks; 224 225 List<RingFactory<BigInteger>> colist; 226 colist = new ArrayList<RingFactory<BigInteger>>(); 227 228 // colist.add( new BigInteger() ); 229 // colist.add( new BigInteger() ); 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 // System.out.println("colist = " + colist); 236 237 ProductRing<BigInteger> pfac; 238 pfac = new ProductRing<BigInteger>(colist); 239 // System.out.println("pfac = " + pfac); 240 241 GenPolynomialRing<Product<BigInteger>> fac; 242 fac = new GenPolynomialRing<Product<BigInteger>>(pfac, F.ring); 243 // System.out.println("fac = " + fac); 244 245 List<GenPolynomial<Product<BigInteger>>> Fp = null; 246 Fp = PolyUtil.<BigInteger> toProductGen(fac, F.list); 247 248 249 List<GenPolynomial<Product<BigInteger>>> Fpp; 250 Fpp = new ArrayList<GenPolynomial<Product<BigInteger>>>(); 251 for (GenPolynomial<Product<BigInteger>> a : Fp) { 252 Fpp.add(a.multiply(pfac.getAtomic(0))); 253 Fpp.add(a.multiply(pfac.getAtomic(1))); 254 // Fpp.add( a ); 255 } 256 Fp = Fpp; 257 258 //trinks = new PolynomialList<Product<BigInteger>>(fac, Fp); 259 // System.out.println("Fp = " + trinks); 260 GroebnerBase<Product<BigInteger>> bbri = new RGroebnerBasePseudoSeq<Product<BigInteger>>(pfac); 261 262 List<GenPolynomial<Product<BigInteger>>> G; 263 G = bbri.GB(Fp); 264 // System.out.println("gb = " + G ); 265 266 // assertEquals("#GB(Trinks7) == 6", 6, G.size() ); 267 // System.out.println("Fp = " + trinks); 268 trinks = new PolynomialList<Product<BigInteger>>(fac, G); 269 // System.out.println("G = " + trinks); 270 assertFalse("trinks != null", trinks == null); 271 272 assertTrue("isGB( GB(Trinks7) )", bbri.isGB(G)); 273 } 274 275 276}