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