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