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