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