001/* 002 * $Id$ 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, G; 068 069 070 PolynomialList<BigInteger> F; 071 072 073 GroebnerBase<BigInteger> bb; 074 075 076 GenPolynomial<BigInteger> a, b, c, d, e; 077 078 079 int rl = 3; //4; //3; 080 081 082 int kl = 4; //4; 10 083 084 085 int ll = 4; 086 087 088 int el = 3; 089 090 091 float q = 0.2f; //0.4f 092 093 094 @Override 095 protected void setUp() { 096 BigInteger coeff = new BigInteger(9); 097 fac = new GenPolynomialRing<BigInteger>(coeff, rl); 098 a = b = c = d = e = null; 099 bb = new EGroebnerBaseSeq<BigInteger>(); 100 } 101 102 103 @Override 104 protected void tearDown() { 105 a = b = c = d = e = null; 106 fac = null; 107 bb = null; 108 } 109 110 111 /** 112 * Test sequential GBase. 113 */ 114 public void testSequentialGBase() { 115 116 L = new ArrayList<GenPolynomial<BigInteger>>(); 117 118 a = fac.random(kl, ll, el, q).abs(); 119 b = fac.random(kl, ll, el, q).abs(); 120 c = fac.random(kl, ll / 2, el, q).abs(); 121 d = fac.random(kl, ll / 2, el, q).abs(); 122 e = d; //fac.random(kl, ll, el, q ); 123 124 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 125 return; 126 } 127 128 L.add(a); 129 //System.out.println(" L = " + L ); 130 L = bb.GB(L); 131 //System.out.println("eGB(L) = " + L ); 132 assertTrue("isGB( { a } )", bb.isGB(L)); 133 134 L.add(b); 135 //System.out.println(" L = " + L ); 136 L = bb.GB(L); 137 //System.out.println("eGB(L) = " + L ); 138 assertTrue("isGB( { a, b } )", bb.isGB(L)); 139 140 L.add(c); 141 //System.out.println(" L = " + L ); 142 L = bb.GB(L); 143 //System.out.println("eGB(L) = " + L ); 144 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 145 146 L.add(d); 147 //System.out.println(" L = " + L ); 148 L = bb.GB(L); 149 //System.out.println("eGB(L) = " + L ); 150 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 151 152 L.add(e); 153 //System.out.println(" L = " + L ); 154 L = bb.GB(L); 155 //System.out.println("eGB(L) = " + L ); 156 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 157 } 158 159 160 /** 161 * Test Trinks7 GBase over Z. 162 */ 163 @SuppressWarnings("unchecked") 164 public void xtestTrinks7GBaseZ() { // needs 20 sec 165 String exam = "Z(B,S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - 165 B - 36 ), " 166 + "( 35 P + 40 Z + 25 T - 27 S ), " + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), " 167 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - 11 B**3 ), " 168 + "( 99 W - 11 B S + 3 B**2 ), " + "( 10000 B**2 + 6600 B + 2673 ) " + ") "; 169 Reader source = new StringReader(exam); 170 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 171 try { 172 F = (PolynomialList<BigInteger>) 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 PolynomialList<BigInteger> trinks = new PolynomialList<BigInteger>(F.ring, G); 182 System.out.println("G = " + trinks); 183 System.out.println("G.size() = " + G.size()); 184 assertTrue("isGB( eGB(Trinks7) )", bb.isGB(G)); 185 //assertEquals("#GB(Trinks7) == 44", 44, G.size() ); 186 } 187 188 189 /** 190 * Test Trinks7 GBase over Z(B). 191 */ 192 @SuppressWarnings("unchecked") 193 public void xtestTrinks7GBaseZ_B() { 194 String exam = "IntFunc{ B } (S,T,Z,P,W) G " + "( " + "( { 45 } P + { 35 } S - { 165 B } - { 36 } ), " 195 + "( { 35 } P + { 40 } Z + { 25 } T - { 27 } S ), " 196 + "( { 15 } W + { 25 } S P + { 30 } Z - { 18 } T - { 165 B**2 } ), " 197 + "( { - 9 } W + { 15 } T P + { 20 } S Z ), " + "( P W + { 2 } T Z - { 11 B**3 } ), " 198 + "( { 99 } W - { 11 B } S + { 3 B**2 } ), " + "( { 10000 B**2 + 6600 B + 2673 } ) " 199 + ") "; 200 Reader source = new StringReader(exam); 201 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 202 EGroebnerBaseSeq<GenPolynomial<BigRational>> bb = new EGroebnerBaseSeq<GenPolynomial<BigRational>>(); 203 PolynomialList<GenPolynomial<BigRational>> F = null; 204 List<GenPolynomial<GenPolynomial<BigRational>>> G = null; 205 try { 206 F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet(); 207 } catch (ClassCastException e) { 208 fail("" + e); 209 } catch (IOException e) { 210 fail("" + e); 211 } 212 System.out.println("F = " + F); 213 214 List<GenPolynomial<GenPolynomial<BigRational>>> Fp = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>( 215 F.list.size()); 216 for (GenPolynomial<GenPolynomial<BigRational>> p : F.list) { 217 p = PolyUtil.<BigRational> monic(p); 218 Fp.add(p); 219 } 220 //System.out.println("Fp = " + Fp); 221 G = bb.GB(Fp); 222 //System.out.println("G = " + G); 223 224 List<GenPolynomial<GenPolynomial<BigRational>>> Gp = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>( 225 F.list.size()); 226 for (GenPolynomial<GenPolynomial<BigRational>> p : G) { 227 p = PolyUtil.<BigRational> monic(p); 228 Gp.add(p); 229 } 230 PolynomialList<GenPolynomial<BigRational>> trinks = new PolynomialList<GenPolynomial<BigRational>>( 231 F.ring, Gp); 232 System.out.println("G = " + trinks); 233 System.out.println("G.size() = " + G.size()); 234 ComputerThreads.terminate(); 235 236 assertTrue("isGB( GB(Trinks7) )", bb.isGB(G)); 237 //assertEquals("#GB(Trinks7) == 1", 1, G.size() ); 238 } 239 240}