001/* 002 * $Id: WordGroebnerBasePseudoRecSeqTest.java 5059 2015-01-01 17:42:25Z kredel $ 003 */ 004 005package edu.jas.gbufd; 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// import org.apache.log4j.Logger; 020 021import edu.jas.arith.BigInteger; 022import edu.jas.arith.BigRational; 023import edu.jas.gb.WordGroebnerBaseAbstract; 024import edu.jas.gb.WordGroebnerBaseSeq; 025import edu.jas.kern.ComputerThreads; 026import edu.jas.poly.GenPolynomial; 027import edu.jas.poly.GenPolynomialRing; 028import edu.jas.poly.GenPolynomialTokenizer; 029import edu.jas.poly.GenWordPolynomial; 030import edu.jas.poly.GenWordPolynomialRing; 031import edu.jas.poly.PolyUtil; 032import edu.jas.poly.PolynomialList; 033import edu.jas.ufd.PolyUfdUtil; 034import edu.jas.ufd.Quotient; 035import edu.jas.ufd.QuotientRing; 036 037 038/** 039 * Word Groebner base recursive pseudo reduction sequential tests with JUnit. 040 * @author Heinz Kredel. 041 */ 042 043public class WordGroebnerBasePseudoRecSeqTest extends TestCase { 044 045 046 //private static final Logger logger = Logger.getLogger(WordGroebnerBasePseudoRecSeqTest.class); 047 048 /** 049 * main 050 */ 051 public static void main(String[] args) { 052 BasicConfigurator.configure(); 053 junit.textui.TestRunner.run(suite()); 054 ComputerThreads.terminate(); 055 } 056 057 058 /** 059 * Constructs a <CODE>WordGroebnerBasePseudoRecSeqTest</CODE> object. 060 * @param name String. 061 */ 062 public WordGroebnerBasePseudoRecSeqTest(String name) { 063 super(name); 064 } 065 066 067 /** 068 * suite. 069 */ 070 public static Test suite() { 071 TestSuite suite = new TestSuite(WordGroebnerBasePseudoRecSeqTest.class); 072 return suite; 073 } 074 075 076 GenWordPolynomialRing<GenPolynomial<BigInteger>> fac; 077 078 079 List<GenWordPolynomial<GenPolynomial<BigInteger>>> L, G; 080 081 082 WordGroebnerBaseAbstract<GenPolynomial<BigInteger>> bb; 083 084 085 WordGroebnerBaseAbstract<GenPolynomial<BigRational>> bbr; 086 087 088 GenWordPolynomial<GenPolynomial<BigInteger>> a, b, c, d, e; 089 090 091 int rl = 2; //4; //3; 092 093 094 int kl = 2; 095 096 097 int ll = 3; 098 099 100 int el = 2; 101 102 103 @Override 104 protected void setUp() { 105 BigInteger coeff = new BigInteger(9); 106 String[] cvars = new String[] { "x", "y" }; 107 GenPolynomialRing<BigInteger> cofac = new GenPolynomialRing<BigInteger>(coeff, cvars); 108 String vars = "a b"; 109 fac = new GenWordPolynomialRing<GenPolynomial<BigInteger>>(cofac, vars); 110 //System.out.println("fac = " + fac.toScript()); 111 a = b = c = d = e = null; 112 bb = new WordGroebnerBasePseudoRecSeq<BigInteger>(cofac); 113 } 114 115 116 @Override 117 protected void tearDown() { 118 a = b = c = d = e = null; 119 fac = null; 120 //bb.terminate(); 121 bb = null; 122 } 123 124 125 /** 126 * Test recursive sequential GBase. 127 */ 128 public void testRecSequentialGBase() { 129 L = new ArrayList<GenWordPolynomial<GenPolynomial<BigInteger>>>(); 130 131 a = fac.random(kl, ll, el); 132 b = fac.random(kl, ll, el); 133 c = fac.random(kl, ll, el); 134 d = fac.getZERO(); //fac.random(kl, ll, el); 135 e = c; //fac.random(kl, ll, el); 136 //System.out.println("a = " + a); 137 //System.out.println("b = " + b); 138 //System.out.println("c = " + c); 139 140 L.add(a); 141 //System.out.println("La = " + L ); 142 143 L = bb.GB(L); 144 assertTrue("isGB( { a } )", bb.isGB(L)); 145 146 L.add(b); 147 //System.out.println("Lb = " + L ); 148 149 L = bb.GB(L); 150 assertTrue("isGB( { a, b } )", bb.isGB(L)); 151 152 if (bb.commonZeroTest(L) < 0) { 153 //System.out.println("Gb = " + L ); 154 //d = a; 155 L.clear(); 156 } 157 L.add(c); 158 //System.out.println("Lc = " + L ); 159 160 L = bb.GB(L); 161 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 162 163 L.add(d); 164 //System.out.println("Ld = " + L ); 165 166 L = bb.GB(L); 167 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 168 169 L.add(e); 170 //System.out.println("Le = " + L ); 171 172 L = bb.GB(L); 173 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 174 } 175 176 177 /** 178 * Test Hawes2 GBase with commutative relations. 179 */ 180 //@SuppressWarnings("unchecked") 181 public void testHawes2GBase() { 182 String exam = "IntFunc(a, c, b) (y2, y1, z1, z2, x) G" + "(" 183 + "( x + 2 y1 z1 + { 3 a } y1^2 + 5 y1^4 + { 2 c } y1 )," 184 + "( x + 2 y2 z2 + { 3 a } y2^2 + 5 y2^4 + { 2 c } y2 )," 185 + "( 2 z2 + { 6 a } y2 + 20 y2^3 + { 2 c } )," + "( 3 z1^2 + y1^2 + { b } )," 186 + "( 3 z2^2 + y2^2 + { b } )" + ")"; 187 Reader source = new StringReader(exam); 188 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 189 PolynomialList<GenPolynomial<BigRational>> Fr = null; 190 try { 191 Fr = parser.nextPolynomialSet(); 192 } catch (ClassCastException e) { 193 fail("" + e); 194 } catch (IOException e) { 195 fail("" + e); 196 } 197 GenPolynomialRing<BigRational> cofac = (GenPolynomialRing<BigRational>) Fr.ring.coFac; 198 GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), cofac); 199 GenPolynomialRing<GenPolynomial<BigInteger>> rifac; 200 rifac = new GenPolynomialRing<GenPolynomial<BigInteger>>(ifac, Fr.ring); 201 List<GenPolynomial<GenPolynomial<BigInteger>>> Li; 202 Li = PolyUfdUtil.integerFromRationalCoefficients(rifac, Fr.list); 203 //System.out.println("Fr = " + Fr); 204 205 fac = new GenWordPolynomialRing<GenPolynomial<BigInteger>>(rifac); 206 //System.out.println("fac = " + fac.toScript()); 207 208 L = fac.valueOf(Li); 209 //System.out.println("L = " + L); 210 L.addAll(fac.commute()); 211 //System.out.println("L = " + L); 212 213 long t, i; 214 t = System.currentTimeMillis(); 215 G = bb.GB(L); 216 t = System.currentTimeMillis() - t; 217 //System.out.println("G = " + G); 218 assertTrue("isGB( G )", bb.isGB(G)); 219 220 221 QuotientRing<BigInteger> qi = new QuotientRing<BigInteger>(ifac); 222 GenPolynomialRing<Quotient<BigInteger>> iring; 223 iring = new GenPolynomialRing<Quotient<BigInteger>>(qi, rifac); 224 List<GenPolynomial<Quotient<BigInteger>>> Lqi; 225 Lqi = PolyUfdUtil.<BigInteger> quotientFromIntegralCoefficients(iring, Li); 226 Lqi = PolyUtil.<Quotient<BigInteger>> monic(Lqi); 227 //System.out.println("Lqi = " + Lqi); 228 229 WordGroebnerBaseAbstract<Quotient<BigInteger>> bbqi; 230 bbqi = new WordGroebnerBaseSeq<Quotient<BigInteger>>(); //qi); 231 //System.out.println("bbqi = " + bbqi); 232 233 GenWordPolynomialRing<Quotient<BigInteger>> qfac; 234 qfac = new GenWordPolynomialRing<Quotient<BigInteger>>(iring); 235 //System.out.println("qfac = " + qfac.toScript()); 236 237 List<GenWordPolynomial<Quotient<BigInteger>>> Lq, Gq; 238 Lq = qfac.valueOf(Lqi); 239 //System.out.println("Lq = " + Lq); 240 Lq.addAll(qfac.commute()); 241 //System.out.println("Lq = " + Lq); 242 243 i = System.currentTimeMillis(); 244 Gq = bbqi.GB(Lq); 245 i = System.currentTimeMillis() - i; 246 //System.out.println("Gq = " + Gq); 247 assertTrue("isGB( Gq )", bbqi.isGB(Gq)); 248 249 //System.out.println("time: intGB = " + t + ", quotIntGB = " + i); 250 assertTrue("nonsense", i >= t ); 251 } 252 253}