001/* 002 * $Id: RGroebnerBaseSeqTest.java 5866 2018-07-20 15:02:16Z 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 018 019import edu.jas.arith.BigInteger; 020import edu.jas.arith.BigRational; 021import edu.jas.arith.ModInteger; 022import edu.jas.arith.ModIntegerRing; 023import edu.jas.arith.Product; 024import edu.jas.arith.ProductRing; 025import edu.jas.gb.GroebnerBase; 026import edu.jas.poly.GenPolynomial; 027import edu.jas.poly.GenPolynomialRing; 028import edu.jas.poly.GenPolynomialTokenizer; 029import edu.jas.poly.PolyUtil; 030import edu.jas.poly.PolynomialList; 031import edu.jas.poly.TermOrder; 032import edu.jas.structure.RingFactory; 033 034 035/** 036 * R-Groebner base sequential tests with JUnit. 037 * @author Heinz Kredel 038 */ 039 040public class RGroebnerBaseSeqTest extends TestCase { 041 042 043 044 /** 045 * main 046 */ 047 public static void main(String[] args) { 048 junit.textui.TestRunner.run(suite()); 049 } 050 051 052 /** 053 * Constructs a <CODE>RGroebnerBaseSeqTest</CODE> object. 054 * @param name String. 055 */ 056 public RGroebnerBaseSeqTest(String name) { 057 super(name); 058 } 059 060 061 /** 062 * suite. 063 */ 064 public static Test suite() { 065 TestSuite suite = new TestSuite(RGroebnerBaseSeqTest.class); 066 return suite; 067 } 068 069 070 ProductRing<BigRational> pfac; 071 072 073 GenPolynomialRing<Product<BigRational>> fac; 074 075 076 List<GenPolynomial<Product<BigRational>>> L, G; 077 078 079 PolynomialList<Product<BigRational>> F; 080 081 082 GroebnerBase<Product<BigRational>> bb; 083 084 085 GenPolynomial<Product<BigRational>> a, b, c, d, e; 086 087 088 int rl = 3; //4; //3; 089 090 091 int kl = 10; 092 093 094 int ll = 7; 095 096 097 int el = 3; 098 099 100 float q = 0.2f; //0.4f 101 102 103 @Override 104 protected void setUp() { 105 BigRational coeff = new BigRational(9); 106 pfac = new ProductRing<BigRational>(coeff, 4); 107 fac = new GenPolynomialRing<Product<BigRational>>(pfac, rl); 108 a = b = c = d = e = null; 109 bb = new RGroebnerBaseSeq<Product<BigRational>>(); 110 } 111 112 113 @Override 114 protected void tearDown() { 115 a = b = c = d = e = null; 116 fac = null; 117 bb = null; 118 } 119 120 121 /** 122 * Test sequential GBase. 123 */ 124 public void testSequentialGBase() { 125 L = new ArrayList<GenPolynomial<Product<BigRational>>>(); 126 127 a = fac.random(kl, ll, el, q); 128 b = fac.random(kl, ll, el, q); 129 c = fac.random(kl, ll, el, q); 130 d = fac.random(kl, ll, el, q); 131 e = d; //fac.random(kl, ll, el, q ); 132 133 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 134 return; 135 } 136 137 assertTrue("not isZERO( a )", !a.isZERO()); 138 L.add(a); 139 140 L = bb.GB(L); 141 assertTrue("isGB( { a } )", bb.isGB(L)); 142 //System.out.println("L = " + L ); 143 144 assertTrue("not isZERO( b )", !b.isZERO()); 145 L.add(b); 146 //System.out.println("L = " + L.size() ); 147 148 L = bb.GB(L); 149 assertTrue("isGB( { a, b } )", bb.isGB(L)); 150 //System.out.println("L = " + L ); 151 152 assertTrue("not isZERO( c )", !c.isZERO()); 153 L.add(c); 154 155 L = bb.GB(L); 156 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 157 //System.out.println("L = " + L ); 158 159 assertTrue("not isZERO( d )", !d.isZERO()); 160 L.add(d); 161 162 L = bb.GB(L); 163 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 164 //System.out.println("L = " + L ); 165 166 assertTrue("not isZERO( e )", !e.isZERO()); 167 L.add(e); 168 169 L = bb.GB(L); 170 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 171 //System.out.println("L = " + L ); 172 } 173 174 175 /** 176 * Test Trinks7 GBase. 177 */ 178 @SuppressWarnings("unchecked") 179 public void testTrinks7() { 180 String exam = "Z(B,S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - 165 B - 36 ), " 181 + "( 35 P + 40 Z + 25 T - 27 S ), " + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 182 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 183 + "( 99 W - 11 B S + 3 B**2 ), " + "( 10000 B**2 + 6600 B + 2673 ) " + ") "; 184 Reader source = new StringReader(exam); 185 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 186 187 PolynomialList<BigInteger> F = null; 188 189 try { 190 F = (PolynomialList<BigInteger>) parser.nextPolynomialSet(); 191 } catch (ClassCastException e) { 192 fail("" + e); 193 } catch (IOException e) { 194 fail("" + e); 195 } 196 //System.out.println("F = " + F); 197 int rl = F.ring.nvar; 198 TermOrder to = F.ring.tord; 199 String[] vars = F.ring.getVars(); 200 PolynomialList<Product<ModInteger>> trinks; 201 202 List<RingFactory<ModInteger>> colist; 203 colist = new ArrayList<RingFactory<ModInteger>>(); 204 205 //colist.add( new ModIntegerRing(2) ); 206 //colist.add( new ModIntegerRing(3) ); 207 //colist.add( new ModIntegerRing(5) ); 208 //colist.add( new ModIntegerRing(30) ); // now ok, was not possible 209 colist.add(new ModIntegerRing(19)); 210 colist.add(new ModIntegerRing(23)); 211 //colist.add( new ModIntegerRing((2<<30)-19) ); 212 //System.out.println("colist = " + colist); 213 214 ProductRing<ModInteger> pfac; 215 pfac = new ProductRing<ModInteger>(colist); 216 //System.out.println("pfac = " + pfac); 217 218 GenPolynomialRing<Product<ModInteger>> fac; 219 fac = new GenPolynomialRing<Product<ModInteger>>(pfac, rl, to, vars); 220 //System.out.println("fac = " + fac); 221 222 List<GenPolynomial<Product<ModInteger>>> Fp; 223 Fp = PolyUtil.toProduct(fac, F.list); 224 225 List<GenPolynomial<Product<ModInteger>>> Fpp; 226 Fpp = new ArrayList<GenPolynomial<Product<ModInteger>>>(); 227 228 for (GenPolynomial<Product<ModInteger>> a : Fp) { 229 Fpp.add(a.multiply(pfac.getAtomic(0))); 230 Fpp.add(a.multiply(pfac.getAtomic(1))); 231 //Fpp.add( a ); 232 } 233 Fp = Fpp; 234 235 //trinks = new PolynomialList<Product<ModInteger>>(fac, Fp); 236 //System.out.println("Fp = " + trinks); 237 238 GroebnerBase<Product<ModInteger>> bbr = new RGroebnerBaseSeq<Product<ModInteger>>(); 239 240 List<GenPolynomial<Product<ModInteger>>> G; 241 G = bbr.GB(Fp); 242 //System.out.println("gb = " + G ); 243 244 //assertEquals("#GB(Trinks7) == 6", 6, G.size() ); 245 //System.out.println("Fp = " + trinks); 246 trinks = new PolynomialList<Product<ModInteger>>(fac, G); 247 assertFalse("trings != null", trinks == null); 248 //System.out.println("G = " + trinks); 249 250 assertTrue("isGB( GB(Trinks7) )", bbr.isGB(G)); 251 } 252 253 254}