001/* 002 * $Id: RGroebnerBasePseudoSeqTest.java 5866 2018-07-20 15:02:16Z 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.Product; 021import edu.jas.arith.ProductRing; 022import edu.jas.gb.GroebnerBase; 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; 028import edu.jas.structure.RingFactory; 029 030 031/** 032 * R-Groebner base sequential tests with JUnit. 033 * @author Heinz Kredel 034 */ 035 036public class RGroebnerBasePseudoSeqTest extends TestCase { 037 038 039 // private static final Logger logger = 040 041 /** 042 * main 043 */ 044 public static void main(String[] args) { 045 junit.textui.TestRunner.run(suite()); 046 // ComputerThreads.terminate(); 047 } 048 049 050 /** 051 * Constructs a <CODE>RGroebnerBasePseudoSeqTest</CODE> object. 052 * @param name String. 053 */ 054 public RGroebnerBasePseudoSeqTest(String name) { 055 super(name); 056 } 057 058 059 /** 060 * suite. 061 */ 062 public static Test suite() { 063 TestSuite suite = new TestSuite(RGroebnerBasePseudoSeqTest.class); 064 return suite; 065 } 066 067 068 ProductRing<BigInteger> pfac; 069 070 071 GenPolynomialRing<Product<BigInteger>> fac; 072 073 074 List<GenPolynomial<Product<BigInteger>>> L, G; 075 076 077 PolynomialList<Product<BigInteger>> F; 078 079 080 GroebnerBase<Product<BigInteger>> bb; 081 082 083 GenPolynomial<Product<BigInteger>> a, b, c, d, e; 084 085 086 int pl = 3; 087 088 089 int rl = 3; // 4; //3; 090 091 092 int kl = 7; // 10; 093 094 095 int ll = 7; 096 097 098 int el = 3; 099 100 101 float q = 0.3f; // 0.4f 102 103 104 @Override 105 protected void setUp() { 106 BigInteger coeff = new BigInteger(9); 107 pfac = new ProductRing<BigInteger>(coeff, pl); 108 fac = new GenPolynomialRing<Product<BigInteger>>(pfac, rl); 109 a = b = c = d = e = null; 110 bb = new RGroebnerBasePseudoSeq<Product<BigInteger>>(pfac); 111 } 112 113 114 @Override 115 protected void tearDown() { 116 a = b = c = d = e = null; 117 fac = null; 118 bb = null; 119 } 120 121 122 /** 123 * Test sequential GBase. 124 */ 125 public void testSequentialGBase() { 126 L = new ArrayList<GenPolynomial<Product<BigInteger>>>(); 127 128 a = fac.random(kl, ll, el, q); 129 b = fac.random(kl, ll, el, q); 130 c = fac.random(kl, ll, el, q); 131 d = fac.random(kl, ll, el, q); 132 e = d; // fac.random(kl, ll, el, q ); 133 134 if (a.isZERO() || b.isZERO() /* || c.isZERO() || d.isZERO() */) { 135 return; 136 } 137 138 assertTrue("not isZERO( a )", !a.isZERO()); 139 L.add(a); 140 // System.out.println("L = " + L ); 141 142 L = bb.GB(L); 143 // System.out.println("L = " + L ); 144 assertTrue("isGB( { a } )", bb.isGB(L)); 145 146 assertTrue("not isZERO( b )", !b.isZERO()); 147 L.add(b); 148 // System.out.println("L = " + L ); 149 150 L = bb.GB(L); 151 // System.out.println("L = " + L ); 152 assertTrue("isGB( { a, b } )", bb.isGB(L)); 153 154 // assertTrue("not isZERO( c )", !c.isZERO() ); 155 L.add(c); 156 // System.out.println("L = " + L ); 157 158 L = bb.GB(L); 159 // System.out.println("L = " + L ); 160 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 161 162 // assertTrue("not isZERO( d )", !d.isZERO() ); 163 L.add(d); 164 // System.out.println("L = " + L ); 165 166 L = bb.GB(L); 167 // System.out.println("L = " + L ); 168 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 169 170 // assertTrue("not isZERO( e )", !e.isZERO() ); 171 L.add(e); 172 // System.out.println("L = " + L ); 173 174 L = bb.GB(L); 175 // System.out.println("L = " + L ); 176 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 177 } 178 179 180 /** 181 * Test Trinks7 GBase. 182 */ 183 @SuppressWarnings("unchecked") 184 public void testTrinks7() { 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 192 PolynomialList<BigInteger> F = null; 193 194 try { 195 F = (PolynomialList<BigInteger>) parser.nextPolynomialSet(); 196 } catch (ClassCastException e) { 197 fail("" + e); 198 } catch (IOException e) { 199 fail("" + e); 200 } 201 // System.out.println("F = " + F); 202 PolynomialList<Product<BigInteger>> trinks; 203 204 List<RingFactory<BigInteger>> colist; 205 colist = new ArrayList<RingFactory<BigInteger>>(); 206 207 // colist.add( new BigInteger() ); 208 // colist.add( new BigInteger() ); 209 // colist.add( new BigInteger() ); 210 // colist.add( new BigInteger() ); 211 colist.add(new BigInteger()); 212 colist.add(new BigInteger()); 213 // colist.add( new BigInteger() ); 214 // System.out.println("colist = " + colist); 215 216 ProductRing<BigInteger> pfac; 217 pfac = new ProductRing<BigInteger>(colist); 218 // System.out.println("pfac = " + pfac); 219 220 GenPolynomialRing<Product<BigInteger>> fac; 221 fac = new GenPolynomialRing<Product<BigInteger>>(pfac, F.ring); 222 // System.out.println("fac = " + fac); 223 224 List<GenPolynomial<Product<BigInteger>>> Fp = null; 225 Fp = PolyUtil.<BigInteger> toProductGen(fac, F.list); 226 227 228 List<GenPolynomial<Product<BigInteger>>> Fpp; 229 Fpp = new ArrayList<GenPolynomial<Product<BigInteger>>>(); 230 for (GenPolynomial<Product<BigInteger>> a : Fp) { 231 Fpp.add(a.multiply(pfac.getAtomic(0))); 232 Fpp.add(a.multiply(pfac.getAtomic(1))); 233 // Fpp.add( a ); 234 } 235 Fp = Fpp; 236 237 //trinks = new PolynomialList<Product<BigInteger>>(fac, Fp); 238 // System.out.println("Fp = " + trinks); 239 GroebnerBase<Product<BigInteger>> bbri = new RGroebnerBasePseudoSeq<Product<BigInteger>>(pfac); 240 241 List<GenPolynomial<Product<BigInteger>>> G; 242 G = bbri.GB(Fp); 243 // System.out.println("gb = " + G ); 244 245 // assertEquals("#GB(Trinks7) == 6", 6, G.size() ); 246 // System.out.println("Fp = " + trinks); 247 trinks = new PolynomialList<Product<BigInteger>>(fac, G); 248 // System.out.println("G = " + trinks); 249 assertFalse("trinks != null", trinks == null); 250 251 assertTrue("isGB( GB(Trinks7) )", bbri.isGB(G)); 252 } 253 254 255}