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