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