001/* 002 * $Id: GroebnerBaseQuotientTest.java 4806 2014-04-13 12:17:31Z kredel $ 003 */ 004 005package edu.jas.gbufd; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import junit.framework.Test; 012import junit.framework.TestCase; 013import junit.framework.TestSuite; 014 015import org.apache.log4j.BasicConfigurator; 016// import org.apache.log4j.Logger; 017 018import edu.jas.arith.BigRational; 019import edu.jas.gb.GroebnerBaseAbstract; 020import edu.jas.kern.ComputerThreads; 021import edu.jas.poly.GenPolynomial; 022import edu.jas.poly.GenPolynomialRing; 023import edu.jas.poly.PolynomialList; 024import edu.jas.ufd.Quotient; 025import edu.jas.ufd.QuotientRing; 026 027 028/** 029 * Groebner base sequential quotient fraction free tests with JUnit. 030 * @author Heinz Kredel. 031 */ 032 033public class GroebnerBaseQuotientTest extends TestCase { 034 035 036 //private static final Logger logger = Logger.getLogger(GroebnerBaseQuotientTest.class); 037 038 039 /** 040 * main 041 */ 042 public static void main(String[] args) { 043 BasicConfigurator.configure(); 044 junit.textui.TestRunner.run(suite()); 045 } 046 047 048 /** 049 * Constructs a <CODE>GroebnerBaseQuotientTest</CODE> object. 050 * @param name String. 051 */ 052 public GroebnerBaseQuotientTest(String name) { 053 super(name); 054 } 055 056 057 /** 058 * suite. 059 */ 060 public static Test suite() { 061 TestSuite suite = new TestSuite(GroebnerBaseQuotientTest.class); 062 return suite; 063 } 064 065 066 GenPolynomialRing<Quotient<BigRational>> fac; 067 068 069 List<GenPolynomial<Quotient<BigRational>>> L, Lp, Lq; 070 071 072 PolynomialList<Quotient<BigRational>> F; 073 074 075 List<GenPolynomial<Quotient<BigRational>>> G, Gp; 076 077 078 GroebnerBaseAbstract<Quotient<BigRational>> bb; 079 080 081 GroebnerBaseAbstract<Quotient<BigRational>> bbp; 082 083 084 GroebnerBaseAbstract<Quotient<BigRational>> bbq; 085 086 087 GenPolynomial<Quotient<BigRational>> a, b, c, d, e; 088 089 090 int threads = 2; 091 092 093 int rl = 4; 094 095 096 int kl = 1; //7; // 10 097 098 099 int ll = 3; //7; 100 101 102 int el = 3; // 4 103 104 105 float q = 0.2f; //0.4f 106 107 108 @Override 109 protected void setUp() { 110 BigRational coeff = new BigRational(9); 111 GenPolynomialRing<BigRational> cf = new GenPolynomialRing<BigRational>(coeff, rl / 2, new String[] { 112 "a", "b" }); 113 QuotientRing<BigRational> qf = new QuotientRing<BigRational>(cf); 114 fac = new GenPolynomialRing<Quotient<BigRational>>(qf, rl / 2, new String[] { "x", "y" }); 115 a = b = c = d = e = null; 116 bb = new GroebnerBaseQuotient<BigRational>(qf); 117 bbp = new GroebnerBaseQuotient<BigRational>(threads, qf); 118 //bbq = new GroebnerBaseSeq<Quotient<BigRational>>(); 119 bbq = GBFactory.<Quotient<BigRational>> getImplementation(qf); 120 } 121 122 123 @Override 124 protected void tearDown() { 125 bbp.terminate(); 126 a = b = c = d = e = null; 127 fac = null; 128 bb = null; 129 bbp = null; 130 bbq = null; 131 ComputerThreads.terminate(); 132 } 133 134 135 /** 136 * Test sequential GBase. 137 */ 138 public void testSequentialGBase() { 139 L = new ArrayList<GenPolynomial<Quotient<BigRational>>>(); 140 141 a = fac.random(kl, ll, el, q); 142 b = fac.random(kl, ll, el, q); 143 c = fac.random(kl, ll, el, q); 144 d = fac.random(kl, ll, el, q); 145 e = d; //fac.random(kl, ll, el, q ); 146 147 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 148 return; 149 } 150 151 assertTrue("not isZERO( a )", !a.isZERO()); 152 L.add(a); 153 154 L = bb.GB(L); 155 assertTrue("isGB( { a } )", bb.isGB(L)); 156 assertTrue("isMinimalGB( { a } )", bb.isMinimalGB(L)); 157 158 assertTrue("not isZERO( b )", !b.isZERO()); 159 L.add(b); 160 //System.out.println("L = " + L.size() ); 161 162 L = bb.GB(L); 163 assertTrue("isGB( { a, b } )", bb.isGB(L)); 164 assertTrue("isMinimalGB( { a, b } )", bb.isMinimalGB(L)); 165 166 assertTrue("not isZERO( c )", !c.isZERO()); 167 L.add(c); 168 169 L = bb.GB(L); 170 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 171 assertTrue("isMinimalGB( { a, b, c } )", bb.isMinimalGB(L)); 172 173 assertTrue("not isZERO( d )", !d.isZERO()); 174 L.add(d); 175 176 L = bb.GB(L); 177 assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 178 assertTrue("isMinimalGB( { a, b, c, d } )", bb.isMinimalGB(L)); 179 180 assertTrue("not isZERO( e )", !e.isZERO()); 181 L.add(e); 182 183 L = bb.GB(L); 184 assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L)); 185 assertTrue("isMinimalGB( { a, b, c, d, e } )", bb.isMinimalGB(L)); 186 } 187 188 189 /** 190 * Test parallel GBase. 191 */ 192 public void testParallelGBase() { 193 L = new ArrayList<GenPolynomial<Quotient<BigRational>>>(); 194 195 a = fac.random(kl, ll, el, q); 196 b = fac.random(kl, ll, el, q); 197 c = fac.random(kl, ll, el, q); 198 d = fac.random(kl, ll, el, q); 199 e = d; //fac.random(kl, ll, el, q ); 200 201 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 202 return; 203 } 204 205 assertTrue("not isZERO( a )", !a.isZERO()); 206 L.add(a); 207 208 L = bbp.GB(L); 209 assertTrue("isGB( { a } )", bbp.isGB(L)); 210 assertTrue("isMinimalGB( { a } )", bbp.isMinimalGB(L)); 211 212 assertTrue("not isZERO( b )", !b.isZERO()); 213 L.add(b); 214 //System.out.println("L = " + L.size() ); 215 216 L = bbp.GB(L); 217 assertTrue("isGB( { a, b } )", bbp.isGB(L)); 218 assertTrue("isMinimalGB( { a, b } )", bbp.isMinimalGB(L)); 219 220 assertTrue("not isZERO( c )", !c.isZERO()); 221 L.add(c); 222 223 L = bbp.GB(L); 224 assertTrue("isGB( { a, b, c } )", bbp.isGB(L)); 225 assertTrue("isMinimalGB( { a, b, c } )", bbp.isMinimalGB(L)); 226 227 assertTrue("not isZERO( d )", !d.isZERO()); 228 L.add(d); 229 230 L = bbp.GB(L); 231 assertTrue("isGB( { a, b, c, d } )", bbp.isGB(L)); 232 assertTrue("isMinimalGB( { a, b, c, d } )", bbp.isMinimalGB(L)); 233 234 assertTrue("not isZERO( e )", !e.isZERO()); 235 L.add(e); 236 237 L = bbp.GB(L); 238 assertTrue("isGB( { a, b, c, d, e } )", bbp.isGB(L)); 239 assertTrue("isMinimalGB( { a, b, c, d, e } )", bbp.isMinimalGB(L)); 240 } 241 242 243 /** 244 * Test compare GBases. 245 */ 246 public void testCompareGBase() { 247 L = new ArrayList<GenPolynomial<Quotient<BigRational>>>(); 248 249 a = fac.random(kl, ll, el, q); 250 b = fac.random(kl, ll, el, q); 251 c = a.sum(b); //fac.random(kl, ll, el, q); 252 d = c; //fac.random(kl, ll, el, q); 253 e = d; //fac.random(kl, ll, el, q ); 254 255 if (a.isZERO() || b.isZERO()) { 256 return; 257 } 258 259 //assertTrue("not isZERO( a )", !a.isZERO()); 260 L.add(a); 261 Lp = bbp.GB(L); 262 Lq = bbq.GB(L); 263 L = bb.GB(L); 264 assertTrue("isGB( { a } )", bb.isGB(L)); 265 assertTrue("isMinimalGB( { a } )", bb.isMinimalGB(L)); 266 assertEquals("Lp == L: ", Lp, L); 267 assertEquals("Lq == L: ", Lq, L); 268 //System.out.println("L = " + L); 269 270 L.add(b); 271 Lp = bbp.GB(L); 272 Lq = bbq.GB(L); 273 L = bb.GB(L); 274 assertTrue("isGB( { a, b } )", bb.isGB(L)); 275 assertTrue("isMinimalGB( { a, b } )", bb.isMinimalGB(L)); 276 assertEquals("Lp == L: ", Lp, L); 277 assertEquals("Lq == L: ", Lq, L); 278 //System.out.println("L = " + L); 279 280 L.add(c); 281 Lp = bbp.GB(L); 282 Lq = bbq.GB(L); 283 L = bb.GB(L); 284 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 285 assertTrue("isMinimalGB( { a, b, c } )", bb.isMinimalGB(L)); 286 assertEquals("Lp == L: ", Lp, L); 287 assertEquals("Lq == L: ", Lq, L); 288 //System.out.println("L = " + L); 289 290 //L.add(d); 291 //Lp = bbp.GB(L); 292 //Lq = bbq.GB(L); 293 //L = bb.GB(L); 294 //assertTrue("isGB( { a, b, c, d } )", bb.isGB(L)); 295 //assertTrue("isMinimalGB( { a, b, c, d } )", bb.isMinimalGB(L)); 296 //assertEquals("Lp == L: ", Lp, L); 297 //assertEquals("Lq == L: ", Lq, L); 298 //System.out.println("L = " + L); 299 } 300 301}