001/*
002 * $Id: SolvableGroebnerBasePseudoSeqTest.java 5029 2014-12-27 19:30:04Z kredel
003 * $
004 */
005
006package edu.jas.gbufd;
007
008
009import java.util.ArrayList;
010import java.util.List;
011
012import junit.framework.Test;
013import junit.framework.TestCase;
014import junit.framework.TestSuite;
015
016import org.apache.log4j.BasicConfigurator;
017// import org.apache.log4j.Logger;
018
019import edu.jas.arith.BigInteger;
020import edu.jas.kern.ComputerThreads;
021import edu.jas.gb.SolvableGroebnerBaseAbstract;
022import edu.jas.poly.GenSolvablePolynomial;
023import edu.jas.poly.GenSolvablePolynomialRing;
024import edu.jas.poly.PolynomialList;
025import edu.jas.poly.RelationGenerator;
026import edu.jas.poly.RelationTable;
027import edu.jas.poly.TermOrder;
028import edu.jas.poly.WeylRelations;
029
030
031/**
032 * Solvable Groebner base pseudo sequential tests with JUnit.
033 * @author Heinz Kredel.
034 */
035
036public class SolvableGroebnerBasePseudoSeqTest extends TestCase {
037
038
039    //private static final Logger logger = Logger.getLogger(SolvableGroebnerBasePseudoSeqTest.class);
040
041
042    /**
043     * main.
044     */
045    public static void main(String[] args) {
046        BasicConfigurator.configure();
047        junit.textui.TestRunner.run(suite());
048        ComputerThreads.terminate();
049    }
050
051
052    /**
053     * Constructs a <CODE>SolvableGroebnerBasePseudoSeqTest</CODE> object.
054     * @param name String.
055     */
056    public SolvableGroebnerBasePseudoSeqTest(String name) {
057        super(name);
058    }
059
060
061    /**
062     * suite.
063     */
064    public static Test suite() {
065        TestSuite suite = new TestSuite(SolvableGroebnerBasePseudoSeqTest.class);
066        return suite;
067    }
068
069
070    GenSolvablePolynomial<BigInteger> a, b, c, d, e;
071
072
073    List<GenSolvablePolynomial<BigInteger>> L;
074
075
076    PolynomialList<BigInteger> F, G;
077
078
079    GenSolvablePolynomialRing<BigInteger> ring;
080
081
082    SolvableGroebnerBaseAbstract<BigInteger> sbb;
083
084
085    BigInteger cfac;
086
087
088    TermOrder tord;
089
090
091    RelationTable<BigInteger> table;
092
093
094    int rl = 4; //4; //3; 
095
096
097    int kl = 2;
098
099
100    int ll = 3;
101
102
103    int el = 3;
104
105
106    float q = 0.2f; //0.4f
107
108
109    @Override
110    protected void setUp() {
111        cfac = new BigInteger(9);
112        tord = new TermOrder();
113        String[] vars = new String[] { "w", "x", "y", "z" };
114        ring = new GenSolvablePolynomialRing<BigInteger>(cfac, tord, vars);
115        table = ring.table;
116        a = b = c = d = e = null;
117        sbb = new SolvableGroebnerBasePseudoSeq<BigInteger>(cfac);
118
119        a = ring.random(kl, ll, el, q);
120        b = ring.random(kl, ll, el, q);
121        c = ring.random(kl, ll, el, q);
122        d = ring.random(kl, ll, el, q);
123        e = d; //ring.random(kl, ll, el, q );
124    }
125
126
127    @Override
128    protected void tearDown() {
129        a = b = c = d = e = null;
130        ring = null;
131        tord = null;
132        table = null;
133        cfac = null;
134        sbb = null;
135    }
136
137
138    /**
139     * Test sequential GBase.
140     */
141    public void testSequentialGBase() {
142        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
143
144        L.add(a);
145        L = sbb.leftGB(L);
146        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L));
147
148        L.add(b);
149        //System.out.println("L = " + L.size() );
150        L = sbb.leftGB(L);
151        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L));
152
153        L.add(c);
154        L = sbb.leftGB(L);
155        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L));
156
157        L.add(d);
158        L = sbb.leftGB(L);
159        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L));
160
161        L.add(e);
162        L = sbb.leftGB(L);
163        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L));
164    }
165
166
167    /**
168     * Test Weyl sequential GBase.
169     */
170    public void testWeylSequentialGBase() {
171        //int rloc = 4;
172        //ring = new GenSolvablePolynomialRing<BigInteger>(cfac,rloc);
173
174        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
175        wl.generate(ring);
176        table = ring.table;
177
178        a = ring.random(kl, ll, el, q);
179        b = ring.random(kl, ll, el, q);
180        c = ring.random(kl, ll, el, q);
181        d = ring.random(kl, ll, el, q);
182        e = d; //ring.random(kl, ll, el, q );
183
184        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
185
186        L.add(a);
187        L = sbb.leftGB(L);
188        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(L));
189
190        L.add(b);
191        //System.out.println("L = " + L.size() );
192        L = sbb.leftGB(L);
193        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(L));
194
195        L.add(c);
196        L = sbb.leftGB(L);
197        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(L));
198
199        L.add(d);
200        L = sbb.leftGB(L);
201        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(L));
202
203        L.add(e);
204        L = sbb.leftGB(L);
205        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(L));
206    }
207
208
209    /**
210     * Test sequential twosided GBase.
211     */
212    public void testSequentialTSGBase() {
213        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
214
215        L.add(a);
216        L = sbb.twosidedGB(L);
217        //System.out.println("L = " + L.size() );
218        assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L));
219
220        L.add(b);
221        L = sbb.twosidedGB(L);
222        //System.out.println("L = " + L.size() );
223        assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L));
224
225        L.add(c);
226        L = sbb.twosidedGB(L);
227        //System.out.println("L = " + L.size() );
228        assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L));
229
230        L.add(d);
231        L = sbb.twosidedGB(L);
232        //System.out.println("L = " + L.size() );
233        assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L));
234
235        L.add(e);
236        L = sbb.twosidedGB(L);
237        //System.out.println("L = " + L.size() );
238        assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L));
239    }
240
241
242    /**
243     * Test Weyl sequential twosided GBase is always 1.
244     */
245    public void testWeylSequentialTSGBase() {
246        //int rloc = 4;
247        //ring = new GenSolvablePolynomialRing<BigInteger>(cfac,rloc);
248
249        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
250        wl.generate(ring);
251        table = ring.table;
252
253        a = ring.random(kl, ll, el, q);
254        b = ring.random(kl, ll, el, q);
255        c = ring.random(kl, ll, el, q);
256        d = ring.random(kl, ll, el, q);
257        e = d; //ring.random(kl, ll, el, q );
258
259        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
260
261        L.add(a);
262        //System.out.println("La = " + L );
263        L = sbb.twosidedGB(L);
264        //System.out.println("L = " + L );
265        assertTrue("isTwosidedGB( { a } )", sbb.isTwosidedGB(L));
266
267        L.add(b);
268        L = sbb.twosidedGB(L);
269        //System.out.println("L = " + L );
270        assertTrue("isTwosidedGB( { a, b } )", sbb.isTwosidedGB(L));
271
272        L.add(c);
273        L = sbb.twosidedGB(L);
274        //System.out.println("L = " + L );
275        assertTrue("isTwosidedGB( { a, b, c } )", sbb.isTwosidedGB(L));
276
277        L.add(d);
278        L = sbb.twosidedGB(L);
279        //System.out.println("L = " + L );
280        assertTrue("isTwosidedGB( { a, b, c, d } )", sbb.isTwosidedGB(L));
281
282        L.add(e);
283        L = sbb.twosidedGB(L);
284        //System.out.println("L = " + L );
285        assertTrue("isTwosidedGB( { a, b, c, d, e } )", sbb.isTwosidedGB(L));
286    }
287
288
289    /*
290     * Test sequential extended GBase.
291    public void testSequentialExtendedGBase() {
292        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
293
294        SolvableExtendedGB<BigInteger> exgb;
295
296        L.add(a);
297        //System.out.println("L = " + L );
298
299        exgb = sbb.extLeftGB( L );
300        //System.out.println("exgb = " + exgb );
301        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(exgb.G) );
302        assertTrue("isLeftRmat( { a } )", sbb.isLeftReductionMatrix(exgb) );
303
304        L.add(b);
305        //System.out.println("L = " + L );
306        exgb = sbb.extLeftGB( L );
307        //System.out.println("exgb = " + exgb );
308        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(exgb.G) );
309        assertTrue("isLeftRmat( { a, b } )", sbb.isLeftReductionMatrix(exgb) );
310
311        L.add(c);
312        exgb = sbb.extLeftGB( L );
313        //System.out.println("exgb = " + exgb );
314        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(exgb.G) );
315        assertTrue("isLeftRmat( { a, b, c } )", sbb.isLeftReductionMatrix(exgb) );
316
317        L.add(d);
318        exgb = sbb.extLeftGB( L );
319        //System.out.println("exgb = " + exgb );
320        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(exgb.G) );
321        assertTrue("isLeftRmat( { a, b, c, d } )", sbb.isLeftReductionMatrix(exgb) );
322
323        L.add(e);
324        exgb = sbb.extLeftGB( L );
325        //System.out.println("exgb = " + exgb );
326        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(exgb.G) );
327        assertTrue("isLeftRmat( { a, b, c, d, e } )", sbb.isLeftReductionMatrix(exgb) );
328    }
329     */
330
331
332    /*
333     * Test Weyl sequential extended GBase.
334    public void testWeylSequentialExtendedGBase() {
335        //int rloc = 4;
336        //ring = new GenSolvablePolynomialRing<BigInteger>(cfac,rloc);
337
338        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
339        wl.generate(ring);
340        table = ring.table;
341
342        a = ring.random(kl, ll, el, q );
343        b = ring.random(kl, ll, el, q );
344        c = ring.random(kl, ll, el, q );
345        d = ring.random(kl, ll, el, q );
346        e = d; //ring.random(kl, ll, el, q );
347
348        SolvableExtendedGB<BigInteger> exgb;
349
350        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
351
352        L.add(a);
353        exgb = sbb.extLeftGB( L );
354        // System.out.println("exgb = " + exgb );
355        assertTrue("isLeftGB( { a } )", sbb.isLeftGB(exgb.G) );
356        assertTrue("isRmat( { a } )", sbb.isLeftReductionMatrix(exgb) );
357
358        L.add(b);
359        //System.out.println("L = " + L.size() );
360        exgb = sbb.extLeftGB( L );
361        //System.out.println("exgb = " + exgb );
362        assertTrue("isLeftGB( { a, b } )", sbb.isLeftGB(exgb.G) );
363        assertTrue("isRmat( { a, b } )", sbb.isLeftReductionMatrix(exgb) );
364
365        L.add(c);
366        exgb = sbb.extLeftGB( L );
367        //System.out.println("exgb = " + exgb );
368        assertTrue("isLeftGB( { a, b, c } )", sbb.isLeftGB(exgb.G) );
369        assertTrue("isRmat( { a, b, c } )", sbb.isLeftReductionMatrix(exgb) );
370
371        L.add(d);
372        exgb = sbb.extLeftGB( L );
373        //System.out.println("exgb = " + exgb );
374        assertTrue("isLeftGB( { a, b, c, d } )", sbb.isLeftGB(exgb.G) );
375        assertTrue("isRmat( { a, b, c, d } )", sbb.isLeftReductionMatrix(exgb) );
376
377        L.add(e);
378        exgb = sbb.extLeftGB( L );
379        //System.out.println("exgb = " + exgb );
380        assertTrue("isLeftGB( { a, b, c, d, e } )", sbb.isLeftGB(exgb.G) );
381        assertTrue("isRmat( { a, b, c, d, e } )", sbb.isLeftReductionMatrix(exgb) );
382    }
383     */
384
385}