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