001/* 002 * $Id: CGBSeqTest.java 4071 2012-07-27 19:59:38Z kredel $ 003 */ 004 005package edu.jas.application; 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.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.PolynomialList; 026 027 028/** 029 * Comprehenssive Groebner base sequential tests with JUnit. 030 * @author Heinz Kredel. 031 */ 032 033public class CGBSeqTest extends TestCase { 034 035 036 //private static final Logger logger = Logger.getLogger(CGBSeqTest.class); 037 038 /** 039 * main 040 */ 041 public static void main(String[] args) { 042 BasicConfigurator.configure(); 043 junit.textui.TestRunner.run(suite()); 044 ComputerThreads.terminate(); 045 } 046 047 048 /** 049 * Constructs a <CODE>CGBSeqTest</CODE> object. 050 * @param name String. 051 */ 052 public CGBSeqTest(String name) { 053 super(name); 054 } 055 056 057 /** 058 * suite. 059 */ 060 public static Test suite() { 061 TestSuite suite = new TestSuite(CGBSeqTest.class); 062 return suite; 063 } 064 065 066 GenPolynomialRing<BigRational> cfac; 067 068 069 GenPolynomialRing<GenPolynomial<BigRational>> fac; 070 071 072 List<GenPolynomial<GenPolynomial<BigRational>>> L; 073 074 075 ComprehensiveGroebnerBaseSeq<BigRational> bb; 076 077 078 GenPolynomial<GenPolynomial<BigRational>> a; 079 080 081 GenPolynomial<GenPolynomial<BigRational>> b; 082 083 084 GenPolynomial<GenPolynomial<BigRational>> c; 085 086 087 GenPolynomial<GenPolynomial<BigRational>> d; 088 089 090 GenPolynomial<GenPolynomial<BigRational>> e; 091 092 093 int rl = 2; //4; //3; 094 095 096 int kl = 2; 097 098 099 int ll = 3; 100 101 102 int el = 3; 103 104 105 float q = 0.2f; //0.4f 106 107 108 @Override 109 protected void setUp() { 110 BigRational coeff = new BigRational(kl); 111 String[] cv = { "a" }; //, "b" }; 112 cfac = new GenPolynomialRing<BigRational>(coeff, 1, cv); 113 String[] v = { "x" }; //, "y" }; 114 fac = new GenPolynomialRing<GenPolynomial<BigRational>>(cfac, 1, v); 115 a = b = c = d = e = null; 116 bb = new ComprehensiveGroebnerBaseSeq<BigRational>(coeff); 117 } 118 119 120 @Override 121 protected void tearDown() { 122 a = b = c = d = e = null; 123 fac = null; 124 cfac = null; 125 bb = null; 126 } 127 128 129 /* 130 * Dummy test method for jUnit. 131 * 132 public void testDummy() { 133 } 134 */ 135 136 137 /** 138 * Test sequential CGB. 139 * 140 */ 141 public void testSequentialCGB() { 142 143 L = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>(); 144 145 a = fac.random(kl, ll, el, q); 146 b = fac.random(kl, ll, el, q); 147 c = a; //fac.random(kl, ll, el, q ); 148 d = c; //fac.random(kl, ll, el, q ); 149 e = d; //fac.random(kl, ll, el, q ); 150 151 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 152 return; 153 } 154 155 assertTrue("not isZERO( a )", !a.isZERO()); 156 L.add(a); 157 158 L = bb.GB(L); 159 assertTrue("isGB( { a } )", bb.isGB(L)); 160 161 assertTrue("not isZERO( b )", !b.isZERO()); 162 L.add(b); 163 //System.out.println("L = " + L.size() ); 164 165 L = bb.GB(L); 166 assertTrue("isGB( { a, b } )", bb.isGB(L)); 167 168 assertTrue("not isZERO( c )", !c.isZERO()); 169 L.add(c); 170 171 L = bb.GB(L); 172 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 173 } 174 175 176 /** 177 * Test Trinks CGB. 178 * 179 */ 180 @SuppressWarnings("unchecked") 181 public void testTrinks7GBase() { 182 PolynomialList<GenPolynomial<BigRational>> F = null; 183 List<GenPolynomial<GenPolynomial<BigRational>>> G = null; 184 String exam = "IntFunc(b) (S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - { 165 b + 36 } ), " 185 + "( 35 P + 40 Z + 25 T - 27 S ), " 186 + "( 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 } ), " + "( { b**2 + 33/50 b + 2673/10000 } ) " 189 + ") "; 190 Reader source = new StringReader(exam); 191 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 192 try { 193 F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet(); 194 } catch (ClassCastException e) { 195 fail("" + e); 196 } catch (IOException e) { 197 fail("" + e); 198 } 199 //System.out.println("F = " + F); 200 201 G = bb.GB(F.list); 202 assertTrue("isGB( GB(Trinks7) )", bb.isGB(G)); 203 204 //PolynomialList<GenPolynomial<BigRational>> trinks 205 // = new PolynomialList<GenPolynomial<BigRational>>(F.ring,G); 206 //System.out.println("G = " + trinks); 207 //System.out.println("G = " + G); 208 } 209 210}