001/*
002 * $Id: SolvablePseudoReductionTest.java 5232 2015-04-19 11:52:38Z kredel $
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
015import org.apache.log4j.BasicConfigurator;
016
017import edu.jas.arith.BigInteger;
018import edu.jas.kern.ComputerThreads;
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.WeylRelations;
025import edu.jas.util.ListUtil;
026
027
028/**
029 * Solvable Reduction tests with JUnit.
030 * @author Heinz Kredel.
031 */
032
033public class SolvablePseudoReductionTest extends TestCase {
034
035
036    /**
037     * main
038     */
039    public static void main(String[] args) {
040        BasicConfigurator.configure();
041        junit.textui.TestRunner.run(suite());
042        ComputerThreads.terminate();
043    }
044
045
046    /**
047     * Constructs a <CODE>SolvablePseudoReductionTest</CODE> object.
048     * @param name String.
049     */
050    public SolvablePseudoReductionTest(String name) {
051        super(name);
052    }
053
054
055    /**
056     * suite.
057     */
058    public static Test suite() {
059        TestSuite suite = new TestSuite(SolvablePseudoReductionTest.class);
060        return suite;
061    }
062
063
064    GenSolvablePolynomialRing<BigInteger> fac;
065
066
067    RelationTable table;
068
069
070    GenSolvablePolynomial<BigInteger> a, b, c, d, e, f, g, h;
071
072
073    List<GenSolvablePolynomial<BigInteger>> L;
074
075
076    PolynomialList<BigInteger> F, G;
077
078
079    SolvablePseudoReduction<BigInteger> sred;
080
081
082    //SolvablePseudoReduction<BigInteger> sredpar;
083
084    int rl = 4;
085
086
087    int kl = 10;
088
089
090    int ll = 5;
091
092
093    int el = 3;
094
095
096    float q = 0.4f;
097
098
099    @Override
100    protected void setUp() {
101        a = b = c = d = e = null;
102        String[] vars = new String[] { "w", "x", "y", "z" };
103        fac = new GenSolvablePolynomialRing<BigInteger>(new BigInteger(0), vars);
104        sred = new SolvablePseudoReductionSeq<BigInteger>();
105        //sredpar = new SolvablePseudoReductionPar<BigInteger>();
106    }
107
108
109    @Override
110    protected void tearDown() {
111        a = b = c = d = e = null;
112        fac = null;
113        sred = null;
114        //sredpar = null;
115    }
116
117
118    /**
119     * Test constants and empty list reduction.
120     */
121    public void testIntReduction0() {
122        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
123
124        a = fac.random(kl, ll, el, q);
125        c = fac.getONE();
126        d = fac.getZERO();
127
128        e = sred.leftNormalform(L, c);
129        assertTrue("isONE( e )", e.isONE());
130
131        e = sred.leftNormalform(L, d);
132        assertTrue("isZERO( e )", e.isZERO());
133
134
135        L.add(c);
136        e = sred.leftNormalform(L, c);
137        assertTrue("isZERO( e )", e.isZERO());
138
139        // e = Reduction.leftNormalform( L, a );
140        // assertTrue("isZERO( e )", e.isZERO() ); 
141
142        e = sred.leftNormalform(L, d);
143        assertTrue("isZERO( e )", e.isZERO());
144
145
146        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
147        L.add(d);
148        e = sred.leftNormalform(L, c);
149        assertTrue("isONE( e )", e.isONE());
150
151        e = sred.leftNormalform(L, d);
152        assertTrue("isZERO( e )", e.isZERO());
153    }
154
155
156    /**
157     * Test constants and empty list reduction.
158     */
159    public void testWeylIntReduction0() {
160        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
161        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
162        wl.generate(fac);
163
164        a = fac.random(kl, ll, el, q);
165        c = fac.getONE();
166        d = fac.getZERO();
167
168        e = sred.leftNormalform(L, c);
169        assertTrue("isONE( e )", e.isONE());
170
171        e = sred.leftNormalform(L, d);
172        assertTrue("isZERO( e )", e.isZERO());
173
174
175        L.add(c);
176        e = sred.leftNormalform(L, c);
177        assertTrue("isZERO( e )", e.isZERO());
178
179        e = sred.leftNormalform(L, a);
180        assertTrue("isZERO( e )", e.isZERO());
181
182        e = sred.leftNormalform(L, d);
183        assertTrue("isZERO( e )", e.isZERO());
184
185
186        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
187        L.add(d);
188        e = sred.leftNormalform(L, c);
189        assertTrue("isONE( e )", e.isONE());
190
191        e = sred.leftNormalform(L, d);
192        assertTrue("isZERO( e )", e.isZERO());
193    }
194
195
196    /**
197     * Test Int reduction.
198     */
199    public void testIntReduction() {
200        a = fac.random(kl, ll, el, q);
201        b = fac.random(kl, ll, el, q);
202
203        assertTrue("not isZERO( a )", !a.isZERO());
204
205        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
206        L.add(a);
207
208        e = sred.leftNormalform(L, a);
209        assertTrue("isZERO( e )", e.isZERO());
210
211        assertTrue("not isZERO( b )", !b.isZERO());
212
213        L.add(b);
214        e = sred.leftNormalform(L, a);
215        assertTrue("isZERO( e ) some times", e.isZERO());
216    }
217
218
219    /**
220     * Test Weyl Integer reduction.
221     */
222    public void testWeylIntReduction() {
223        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
224
225        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
226        wl.generate(fac);
227
228        a = fac.random(kl, ll, el, q);
229        b = fac.random(kl, ll, el, q);
230
231        assertTrue("not isZERO( a )", !a.isZERO());
232
233        L.add(a);
234
235        e = sred.leftNormalform(L, a);
236        assertTrue("isZERO( e )", e.isZERO());
237
238        assertTrue("not isZERO( b )", !b.isZERO());
239
240        L.add(b);
241        e = sred.leftNormalform(L, a);
242        assertTrue("isZERO( e ) some times", e.isZERO());
243    }
244
245
246    /**
247     * Test Int reduction recording.
248     */
249    public void testIntReductionRecording() {
250        List<GenSolvablePolynomial<BigInteger>> row = null;
251        PseudoReductionEntry<BigInteger> mf;
252
253        a = fac.random(kl, ll, el, q);
254        b = fac.random(kl, ll, el, q);
255        c = fac.random(kl, ll, el, q);
256        d = fac.random(kl, ll, el, q);
257
258        assertTrue("not isZERO( a )", !a.isZERO());
259
260        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
261
262        L.add(a);
263        mf = sred.leftNormalformFactor(L, a);
264        f = a.multiply(mf.multiplicator);
265        row = ListUtil.<GenSolvablePolynomial<BigInteger>> fill(L.size(), fac.getZERO());
266        //d = sred.leftNormalform( row, L, a );
267        d = sred.leftNormalform(row, L, f);
268        assertTrue("isZERO( d )", d.isZERO());
269        assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, f, d));
270
271        L.add(b);
272        mf = sred.leftNormalformFactor(L, b);
273        f = b.multiply(mf.multiplicator);
274        row = ListUtil.<GenSolvablePolynomial<BigInteger>> fill(L.size(), fac.getZERO());
275        //e = sred.leftNormalform( row, L, b );
276        d = sred.leftNormalform(row, L, f);
277        assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, f, d));
278
279        L.add(c);
280        mf = sred.leftNormalformFactor(L, c);
281        f = c.multiply(mf.multiplicator);
282        row = ListUtil.<GenSolvablePolynomial<BigInteger>> fill(L.size(), fac.getZERO());
283        d = sred.leftNormalform(row, L, f);
284        assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, f, d));
285
286        L.add(d);
287        mf = sred.leftNormalformFactor(L, d);
288        f = d.multiply(mf.multiplicator);
289        row = ListUtil.<GenSolvablePolynomial<BigInteger>> fill(L.size(), fac.getZERO());
290        e = sred.leftNormalform(row, L, f);
291        assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, f, e));
292    }
293
294
295    /*
296     * Test Int reduction parallel.
297    public void testIntReductionPar() {
298        a = fac.random(kl, ll, el, q );
299        b = fac.random(kl, ll, el, q );
300
301        assertTrue("not isZERO( a )", !a.isZERO() );
302
303        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
304        L.add(a);
305
306        e = sredpar.leftNormalform( L, a );
307        assertTrue("isZERO( e )", e.isZERO() );
308
309        assertTrue("not isZERO( b )", !b.isZERO() );
310
311        L.add(b);
312        e = sredpar.leftNormalform( L, a );
313        assertTrue("isZERO( e ) some times", e.isZERO() ); 
314    }
315     */
316
317    /*
318     * Test Weyl Integer reduction parallel.
319    public void testWeylIntReductionPar() {
320        L = new ArrayList<GenSolvablePolynomial<BigInteger>>();
321
322        RelationGenerator<BigInteger> wl = new WeylRelations<BigInteger>();
323        wl.generate(fac);
324
325        a = fac.random(kl, ll, el, q );
326        b = fac.random(kl, ll, el, q );
327
328        assertTrue("not isZERO( a )", !a.isZERO() );
329
330        L.add(a);
331
332        e = sredpar.leftNormalform( L, a );
333        assertTrue("isZERO( e )", e.isZERO() );
334
335        assertTrue("not isZERO( b )", !b.isZERO() );
336
337        L.add(b);
338        e = sredpar.leftNormalform( L, a );
339        assertTrue("isZERO( e ) some times", e.isZERO() ); 
340    }
341     */
342
343}