001    /*
002     * $Id: SolvableReductionTest.java 2412 2009-02-07 12:17:54Z kredel $
003     */
004    
005    package edu.jas.gb;
006    
007    import java.util.ArrayList;
008    import java.util.List;
009    
010    import junit.framework.Test;
011    import junit.framework.TestCase;
012    import junit.framework.TestSuite;
013    
014    import org.apache.log4j.BasicConfigurator;
015    
016    import edu.jas.arith.BigRational;
017    import edu.jas.poly.GenSolvablePolynomial;
018    import edu.jas.poly.GenSolvablePolynomialRing;
019    import edu.jas.poly.PolynomialList;
020    import edu.jas.poly.RelationTable;
021    import edu.jas.poly.WeylRelations;
022    
023    
024    /**
025     * Solvable Reduction tests with JUnit.
026     * @author Heinz Kredel.
027     */
028    
029    public class SolvableReductionTest extends TestCase {
030    
031    /**
032     * main
033     */
034       public static void main (String[] args) {
035              BasicConfigurator.configure();
036              junit.textui.TestRunner.run( suite() );
037       }
038    
039    /**
040     * Constructs a <CODE>ReductionSolvableTest</CODE> object.
041     * @param name String.
042     */
043       public SolvableReductionTest(String name) {
044              super(name);
045       }
046    
047    /**
048     * suite.
049     */ 
050     public static Test suite() {
051         TestSuite suite= new TestSuite(SolvableReductionTest.class);
052         return suite;
053       }
054    
055       //private final static int bitlen = 100;
056    
057       GenSolvablePolynomialRing<BigRational> fac;
058    
059       RelationTable table;
060    
061       GenSolvablePolynomial<BigRational> a;
062       GenSolvablePolynomial<BigRational> b;
063       GenSolvablePolynomial<BigRational> c;
064       GenSolvablePolynomial<BigRational> d;
065       GenSolvablePolynomial<BigRational> e;
066    
067       List<GenSolvablePolynomial<BigRational>> L;
068       PolynomialList<BigRational> F;
069       PolynomialList<BigRational> G;
070    
071       SolvableReduction<BigRational> sred;
072       SolvableReduction<BigRational> sredpar;
073    
074       int rl = 4; 
075       int kl = 10;
076       int ll = 5;
077       int el = 3;
078       float q = 0.4f;
079    
080       protected void setUp() {
081           a = b = c = d = e = null;
082           fac = new GenSolvablePolynomialRing<BigRational>( new BigRational(0), rl );
083           sred = new SolvableReductionSeq<BigRational>();
084           sredpar = new SolvableReductionPar<BigRational>();
085       }
086    
087       protected void tearDown() {
088           a = b = c = d = e = null;
089           fac = null;
090           sred = null;
091           sredpar = null;
092       }
093    
094    
095    /**
096     * Test constants and empty list reduction.
097     * 
098     */
099     public void testRatReduction0() {
100         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
101    
102         a = fac.random(kl, ll, el, q );
103         c = fac.getONE();
104         d = fac.getZERO();
105    
106         e = sred.leftNormalform( L, c );
107         assertTrue("isONE( e )", e.isONE() ); 
108    
109         e = sred.leftNormalform( L, d );
110         assertTrue("isZERO( e )", e.isZERO() ); 
111    
112    
113         L.add( c );
114         e = sred.leftNormalform( L, c );
115         assertTrue("isZERO( e )", e.isZERO() ); 
116    
117         // e = Reduction.leftNormalform( L, a );
118         // assertTrue("isZERO( e )", e.isZERO() ); 
119    
120         e = sred.leftNormalform( L, d );
121         assertTrue("isZERO( e )", e.isZERO() ); 
122    
123    
124         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
125         L.add( d );
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    
134    /**
135     * Test constants and empty list reduction.
136     * 
137     */
138     public void testWeylRatReduction0() {
139         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
140    
141         WeylRelations<BigRational> wl = new WeylRelations<BigRational>(fac);
142         wl.generate();
143    
144         a = fac.random(kl, ll, el, q );
145         c = fac.getONE();
146         d = fac.getZERO();
147    
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         L.add( c );
156         e = sred.leftNormalform( L, c );
157         assertTrue("isZERO( e )", e.isZERO() ); 
158    
159         e = sred.leftNormalform( L, a );
160         assertTrue("isZERO( e )", e.isZERO() ); 
161    
162         e = sred.leftNormalform( L, d );
163         assertTrue("isZERO( e )", e.isZERO() ); 
164    
165    
166         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
167         L.add( d );
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    
176    /**
177     * Test Rat reduction.
178     * 
179     */
180     public void testRatReduction() {
181    
182         a = fac.random(kl, ll, el, q );
183         b = fac.random(kl, ll, el, q );
184    
185         assertTrue("not isZERO( a )", !a.isZERO() );
186    
187         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
188         L.add(a);
189    
190         e = sred.leftNormalform( L, a );
191         assertTrue("isZERO( e )", e.isZERO() );
192    
193         assertTrue("not isZERO( b )", !b.isZERO() );
194    
195         L.add(b);
196         e = sred.leftNormalform( L, a );
197         assertTrue("isZERO( e ) some times", e.isZERO() ); 
198     }
199    
200    
201    /**
202     * Test Rat reduction parallel.
203     * 
204     */
205     public void testRatReductionPar() {
206    
207         a = fac.random(kl, ll, el, q );
208         b = fac.random(kl, ll, el, q );
209    
210         assertTrue("not isZERO( a )", !a.isZERO() );
211    
212         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
213         L.add(a);
214    
215         e = sredpar.leftNormalform( L, a );
216         assertTrue("isZERO( e )", e.isZERO() );
217    
218         assertTrue("not isZERO( b )", !b.isZERO() );
219    
220         L.add(b);
221         e = sredpar.leftNormalform( L, a );
222         assertTrue("isZERO( e ) some times", e.isZERO() ); 
223     }
224    
225    
226    /**
227     * Test Weyl Rational reduction.
228     * 
229     */
230     public void testWeylRatReduction() {
231         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
232    
233         WeylRelations<BigRational> wl = new WeylRelations<BigRational>(fac);
234         wl.generate();
235    
236         a = fac.random(kl, ll, el, q );
237         b = fac.random(kl, ll, el, q );
238    
239         assertTrue("not isZERO( a )", !a.isZERO() );
240    
241         L.add(a);
242    
243         e = sred.leftNormalform( L, a );
244         assertTrue("isZERO( e )", e.isZERO() );
245    
246         assertTrue("not isZERO( b )", !b.isZERO() );
247    
248         L.add(b);
249         e = sred.leftNormalform( L, a );
250         assertTrue("isZERO( e ) some times", e.isZERO() ); 
251     }
252    
253    
254    /**
255     * Test Weyl Rational reduction parallel.
256     * 
257     */
258     public void testWeylRatReductionPar() {
259         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
260    
261         WeylRelations<BigRational> wl = new WeylRelations<BigRational>(fac);
262         wl.generate();
263    
264         a = fac.random(kl, ll, el, q );
265         b = fac.random(kl, ll, el, q );
266    
267         assertTrue("not isZERO( a )", !a.isZERO() );
268    
269         L.add(a);
270    
271         e = sredpar.leftNormalform( L, a );
272         assertTrue("isZERO( e )", e.isZERO() );
273    
274         assertTrue("not isZERO( b )", !b.isZERO() );
275    
276         L.add(b);
277         e = sredpar.leftNormalform( L, a );
278         assertTrue("isZERO( e ) some times", e.isZERO() ); 
279     }
280    
281    
282    /**
283     * Test Rat reduction recording.
284     * 
285     */
286     public void testRatReductionRecording() {
287    
288         List<GenSolvablePolynomial<BigRational>> row = null;
289    
290    
291         a = fac.random(kl, ll, el, q );
292         b = fac.random(kl, ll, el, q );
293         c = fac.random(kl, ll, el, q );
294         d = fac.random(kl, ll, el, q );
295    
296         assertTrue("not isZERO( a )", !a.isZERO() );
297    
298         L = new ArrayList<GenSolvablePolynomial<BigRational>>();
299    
300         L.add(a);
301         row = new ArrayList<GenSolvablePolynomial<BigRational>>( L.size() );
302         for ( int m = 0; m < L.size(); m++ ) {
303             row.add(null);
304         }
305         e = sred.leftNormalform( row, L, a );
306         assertTrue("isZERO( e )", e.isZERO() );
307         assertTrue("not isZERO( b )", !b.isZERO() );
308         assertTrue("is leftReduction ", sred.isLeftReductionNF(row,L,a,e) );
309    
310         L.add(b);
311         row = new ArrayList<GenSolvablePolynomial<BigRational>>( L.size() );
312         for ( int m = 0; m < L.size(); m++ ) {
313             row.add(null);
314         }
315         e = sred.leftNormalform( row, L, b );
316         assertTrue("is leftReduction ", sred.isLeftReductionNF(row,L,b,e) );
317    
318         L.add(c);
319         row = new ArrayList<GenSolvablePolynomial<BigRational>>( L.size() );
320         for ( int m = 0; m < L.size(); m++ ) {
321             row.add(null);
322         }
323         e = sred.leftNormalform( row, L, c );
324         assertTrue("is leftReduction ", sred.isLeftReductionNF(row,L,c,e) );
325    
326         L.add(d);
327         row = new ArrayList<GenSolvablePolynomial<BigRational>>( L.size() );
328         for ( int m = 0; m < L.size(); m++ ) {
329             row.add(null);
330         }
331         e = sred.leftNormalform( row, L, d );
332         assertTrue("is leftReduction ", sred.isLeftReductionNF(row,L,d,e) );
333     }
334    
335    
336    }