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