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