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