001/*
002 * $Id$
003 */
004
005package edu.jas.gb;
006
007
008import java.util.ArrayList;
009import java.util.List;
010
011import edu.jas.arith.BigComplex;
012import edu.jas.arith.BigInteger;
013import edu.jas.arith.BigRational;
014import edu.jas.poly.ExpVector;
015import edu.jas.poly.GenPolynomial;
016import edu.jas.poly.GenPolynomialRing;
017import edu.jas.poly.PolynomialList;
018import edu.jas.vector.BasicLinAlg;
019
020import junit.framework.Test;
021import junit.framework.TestCase;
022import junit.framework.TestSuite;
023
024
025/**
026 * Reduction / normalform tests with JUnit.
027 * @author Heinz Kredel
028 */
029
030public class ReductionTest extends TestCase {
031
032
033    /**
034     * main
035     */
036    public static void main(String[] args) {
037        junit.textui.TestRunner.run(suite());
038    }
039
040
041    /**
042     * Constructs a <CODE>ReductionTest</CODE> object.
043     * @param name String
044     */
045    public ReductionTest(String name) {
046        super(name);
047    }
048
049
050    /**
051     * suite.
052     * @return a test suite.
053     */
054    public static Test suite() {
055        TestSuite suite = new TestSuite(ReductionTest.class);
056        return suite;
057    }
058
059    //private final static int bitlen = 100;
060
061    GenPolynomialRing<BigRational> fac;
062
063
064    GenPolynomial<BigRational> a, b, c, d, e;
065
066
067    List<GenPolynomial<BigRational>> L;
068
069
070    PolynomialList<BigRational> F, G;
071
072
073    ReductionSeq<BigRational> red;
074
075
076    Reduction<BigRational> redpar;
077
078
079    int rl = 4;
080
081
082    int kl = 10;
083
084
085    int ll = 11;
086
087
088    int el = 5;
089
090
091    float q = 0.6f;
092
093    @Override
094    protected void setUp() {
095        a = b = c = d = e = null;
096        fac = new GenPolynomialRing<BigRational>(new BigRational(0), rl);
097        red = new ReductionSeq<BigRational>();
098        redpar = new ReductionPar<BigRational>();
099    }
100
101
102    @Override
103    protected void tearDown() {
104        a = b = c = d = e = null;
105        fac = null;
106        red = null;
107        redpar = null;
108    }
109
110
111    /**
112     * Test constants and empty list reduction.
113     */
114    public void testRatReduction0() {
115        L = new ArrayList<GenPolynomial<BigRational>>();
116
117        a = fac.random(kl, ll, el, q);
118        c = fac.getONE();
119        d = fac.getZERO();
120
121        e = red.normalform(L, c);
122        assertTrue("isONE( e )", e.isONE());
123
124        e = red.normalform(L, d);
125        assertTrue("isZERO( e )", e.isZERO());
126
127
128        L.add(c);
129        e = red.normalform(L, c);
130        assertTrue("isZERO( e )", e.isZERO());
131
132        e = red.normalform(L, a);
133        assertTrue("isZERO( e )", e.isZERO());
134
135        e = red.normalform(L, d);
136        assertTrue("isZERO( e )", e.isZERO());
137
138
139        L = new ArrayList<GenPolynomial<BigRational>>();
140        L.add(d);
141        e = red.normalform(L, c);
142        assertTrue("isONE( e )", e.isONE());
143
144        e = red.normalform(L, d);
145        assertTrue("isZERO( e )", e.isZERO());
146    }
147
148
149    /**
150     * Test parallel reduction with constants and empty list reduction.
151     */
152    public void testRatReductionPar0() {
153        L = new ArrayList<GenPolynomial<BigRational>>();
154
155        a = fac.random(kl, ll, el, q);
156        c = fac.getONE();
157        d = fac.getZERO();
158
159        e = redpar.normalform(L, c);
160        assertTrue("isONE( e )", e.isONE());
161
162        e = redpar.normalform(L, d);
163        assertTrue("isZERO( e )", e.isZERO());
164
165
166        L.add(c);
167        e = redpar.normalform(L, c);
168        assertTrue("isZERO( e )", e.isZERO());
169
170        e = redpar.normalform(L, a);
171        assertTrue("isZERO( e )", e.isZERO());
172
173        e = redpar.normalform(L, d);
174        assertTrue("isZERO( e )", e.isZERO());
175
176
177        L = new ArrayList<GenPolynomial<BigRational>>();
178        L.add(d);
179        e = redpar.normalform(L, c);
180        assertTrue("isONE( e )", e.isONE());
181
182        e = redpar.normalform(L, d);
183        assertTrue("isZERO( e )", e.isZERO());
184    }
185
186
187    /**
188     * Test rational coefficient reduction.
189     */
190    public void testRatReduction() {
191        a = fac.random(kl, ll, el, q);
192        b = fac.random(kl, ll, el, q);
193
194        assertTrue("not isZERO( a )", !a.isZERO());
195
196        L = new ArrayList<GenPolynomial<BigRational>>();
197        L.add(a);
198
199        e = red.normalform(L, a);
200        assertTrue("isZERO( e )", e.isZERO());
201
202        assertTrue("not isZERO( b )", !b.isZERO());
203
204        L.add(b);
205        e = red.normalform(L, a);
206        assertTrue("isZERO( e ) some times", e.isZERO());
207
208        e = red.SPolynomial(a, b);
209        //System.out.println("e = " + e);
210        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
211        ExpVector ee = e.leadingExpVector();
212        assertTrue("lcm(lt(a),lt(b)) > lt(e) " + ce + " > " + ee,
213                        fac.tord.getAscendComparator().compare(ce, ee) > 0); // findbugs
214
215        L = new ArrayList<GenPolynomial<BigRational>>();
216        L.add(a);
217        assertTrue("isTopRed( a )", red.isTopReducible(L, a));
218        assertTrue("isRed( a )", red.isReducible(L, a));
219        b = fac.random(kl, ll, el, q);
220        L.add(b);
221        assertTrue("isTopRed( b )", red.isTopReducible(L, b));
222        assertTrue("isRed( b )", red.isReducible(L, b));
223        c = fac.random(kl, ll, el, q);
224        e = red.normalform(L, c);
225        assertTrue("isNF( e )", red.isNormalform(L, e));
226    }
227
228
229    /**
230     * Test rational coefficient parallel reduction.
231     */
232    public void testRatReductionPar() {
233        a = fac.random(kl, ll, el, q);
234        b = fac.random(kl, ll, el, q);
235
236        assertTrue("not isZERO( a )", !a.isZERO());
237
238        L = new ArrayList<GenPolynomial<BigRational>>();
239        L.add(a);
240
241        e = redpar.normalform(L, a);
242        assertTrue("isZERO( e )", e.isZERO());
243
244        assertTrue("not isZERO( b )", !b.isZERO());
245
246        L.add(b);
247        e = redpar.normalform(L, a);
248        assertTrue("isZERO( e ) some times", e.isZERO());
249
250        L = new ArrayList<GenPolynomial<BigRational>>();
251        L.add(a);
252        assertTrue("isTopRed( a )", redpar.isTopReducible(L, a));
253        assertTrue("isRed( a )", redpar.isReducible(L, a));
254        b = fac.random(kl, ll, el, q);
255        L.add(b);
256        assertTrue("isTopRed( b )", redpar.isTopReducible(L, b));
257        assertTrue("isRed( b )", redpar.isReducible(L, b));
258        c = fac.random(kl, ll, el, q);
259        e = redpar.normalform(L, c);
260        assertTrue("isNF( e )", redpar.isNormalform(L, e));
261    }
262
263
264    /**
265     * Test complex coefficient reduction.
266     */
267    public void testComplexReduction() {
268        GenPolynomialRing<BigComplex> fac = new GenPolynomialRing<BigComplex>(new BigComplex(0), rl);
269
270        Reduction<BigComplex> cred = new ReductionSeq<BigComplex>();
271
272        GenPolynomial<BigComplex> a = fac.random(kl, ll, el, q);
273        GenPolynomial<BigComplex> b = fac.random(kl, ll, el, q);
274        GenPolynomial<BigComplex> c;
275
276        assertTrue("not isZERO( a )", !a.isZERO());
277
278        List<GenPolynomial<BigComplex>> L = new ArrayList<GenPolynomial<BigComplex>>();
279        L.add(a);
280
281        GenPolynomial<BigComplex> e = cred.normalform(L, a);
282        assertTrue("isZERO( e )", e.isZERO());
283
284        assertTrue("not isZERO( b )", !b.isZERO());
285
286        L.add(b);
287        e = cred.normalform(L, a);
288        assertTrue("isZERO( e ) some times", e.isZERO());
289
290        L = new ArrayList<GenPolynomial<BigComplex>>();
291        L.add(a);
292        assertTrue("isTopRed( a )", cred.isTopReducible(L, a));
293        assertTrue("isRed( a )", cred.isReducible(L, a));
294        b = fac.random(kl, ll, el, q);
295        L.add(b);
296        assertTrue("isTopRed( b )", cred.isTopReducible(L, b));
297        assertTrue("isRed( b )", cred.isReducible(L, b));
298        c = fac.random(kl, ll, el, q);
299        e = cred.normalform(L, c);
300        assertTrue("isNF( e )", cred.isNormalform(L, e));
301    }
302
303
304    /**
305     * Test rational coefficient reduction with recording.
306     */
307    public void testRatReductionRecording() {
308        BasicLinAlg<GenPolynomial<BigRational>> blas = new BasicLinAlg<GenPolynomial<BigRational>>();
309        List<GenPolynomial<BigRational>> row = null;
310
311        a = fac.random(kl, ll, el, q);
312        b = fac.random(kl, ll, el, q);
313        c = fac.random(kl, ll, el, q);
314        d = fac.random(kl, ll, el, q);
315        assertTrue("not isZERO( a )", !a.isZERO());
316
317        L = new ArrayList<GenPolynomial<BigRational>>();
318        L.add(a);
319        row = blas.genVector(L.size(), null);
320        e = red.normalform(row, L, a);
321        assertTrue("isZERO( e )", e.isZERO());
322        assertTrue("not isZERO( b )", !b.isZERO());
323        assertTrue("is Reduction ", red.isReductionNF(row, L, a, e));
324
325        L.add(b);
326        row = blas.genVector(L.size(), null);
327        e = red.normalform(row, L, b);
328        assertTrue("is Reduction ", red.isReductionNF(row, L, b, e));
329
330        L.add(c);
331        row = blas.genVector(L.size(), null);
332        e = red.normalform(row, L, c);
333        assertTrue("is Reduction ", red.isReductionNF(row, L, c, e));
334
335        L.add(d);
336        row = blas.genVector(L.size(), null);
337        e = red.normalform(row, L, d);
338        assertTrue("is Reduction ", red.isReductionNF(row, L, d, e));
339
340        L = new ArrayList<GenPolynomial<BigRational>>();
341        L.add(a);
342        L.add(b);
343        //System.out.println("a = " + a);
344        //System.out.println("b = " + b);
345        row = blas.genVector(L.size(), null);
346        e = red.SPolynomial(row, 0, a, 1, b);
347        //System.out.println("e = " + e);
348        //System.out.println("row = " + row);
349
350        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
351        assertFalse("lcm(lt(a),lt(b)) != lt(e) ", ce.equals(e.leadingExpVector()));
352        assertTrue("is Spol recording: " + e, red.isReductionNF(row, L, e.negate(), fac.getZERO()));
353    }
354
355
356    /**
357     * Test integer coefficient e-reduction.
358     */
359    public void testIntegerEReduction() {
360        BigInteger bi = new BigInteger(0);
361        GenPolynomialRing<BigInteger> fac = new GenPolynomialRing<BigInteger>(bi, rl);
362
363        EReductionSeq<BigInteger> ered = new EReductionSeq<BigInteger>();
364
365        GenPolynomial<BigInteger> a = fac.random(kl, ll, el, q);
366        GenPolynomial<BigInteger> b = fac.random(kl, ll, el, q);
367
368        assertTrue("not isZERO( a )", !a.isZERO());
369
370        List<GenPolynomial<BigInteger>> L = new ArrayList<GenPolynomial<BigInteger>>();
371        L.add(a);
372
373        GenPolynomial<BigInteger> e = ered.normalform(L, a);
374        //System.out.println("a = " + a);
375        //System.out.println("e = " + e);
376        assertTrue("isZERO( e )", e.isZERO());
377
378        assertTrue("not isZERO( b )", !b.isZERO());
379
380        L.add(b);
381        e = ered.normalform(L, a);
382        //System.out.println("b = " + b);
383        //System.out.println("e = " + e);
384        assertTrue("isZERO( e ) some times", e.isZERO());
385
386        GenPolynomial<BigInteger> c = fac.getONE();
387        a = a.sum(c);
388        e = ered.normalform(L, a);
389        //System.out.println("b = " + b);
390        //System.out.println("e = " + e);
391        assertTrue("isONE( e ) some times", e.isONE());
392
393        L = new ArrayList<GenPolynomial<BigInteger>>();
394        a = c.multiply(bi.fromInteger(4));
395        b = c.multiply(bi.fromInteger(5));
396        L.add(a);
397        e = ered.normalform(L, b);
398        //System.out.println("a = " + a);
399        //System.out.println("b = " + b);
400        //System.out.println("e = " + e);
401        assertTrue("isONE( e )", e.isONE());
402
403        a = fac.random(kl, ll, el, q); //.abs();
404        b = fac.random(kl, ll, el, q); //.abs();
405        c = ered.GPolynomial(a, b);
406        e = ered.SPolynomial(a, b);
407        //System.out.println("a = " + a);
408        //System.out.println("b = " + b);
409        //System.out.println("c = " + c);
410        //System.out.println("e = " + e);
411
412        BigInteger ci = a.leadingBaseCoefficient().gcd(b.leadingBaseCoefficient());
413        assertEquals("gcd(lbc(a),lbc(b)) = lbc(c) ", ci, c.leadingBaseCoefficient());
414
415        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
416        assertEquals("lcm(lt(a),lt(b)) == lt(c) ", ce, c.leadingExpVector());
417        assertFalse("lcm(lt(a),lt(b)) != lt(e) ", ce.equals(e.leadingExpVector()));
418
419        L = new ArrayList<GenPolynomial<BigInteger>>();
420        L.add(a);
421        assertTrue("isTopRed( a )", ered.isTopReducible(L, a));
422        assertTrue("isRed( a )", ered.isReducible(L, a));
423        b = fac.random(kl, ll, el, q);
424        L.add(b);
425        assertTrue("isTopRed( b )", ered.isTopReducible(L, b));
426        assertTrue("isRed( b )", ered.isReducible(L, b));
427        c = fac.random(kl, ll, el, q);
428        e = ered.normalform(L, c);
429        assertTrue("isNF( e )", ered.isNormalform(L, e));
430    }
431
432
433    /**
434     * Test integer coefficient e-reduction recording.
435     */
436    public void testIntegerEReductionRecording() {
437        BigInteger bi = new BigInteger(0);
438        GenPolynomialRing<BigInteger> fac = new GenPolynomialRing<BigInteger>(bi, rl);
439
440        GenPolynomial<BigInteger> a, b, c, e;
441
442        EReductionSeq<BigInteger> ered = new EReductionSeq<BigInteger>();
443
444        BasicLinAlg<GenPolynomial<BigInteger>> blas = new BasicLinAlg<GenPolynomial<BigInteger>>();
445        List<GenPolynomial<BigInteger>> row = null;
446        List<GenPolynomial<BigInteger>> L = new ArrayList<GenPolynomial<BigInteger>>();
447
448        a = fac.random(kl, ll, el, q).abs();
449
450        assertTrue("not isZERO( a )", !a.isZERO());
451
452        L.add(a);
453        row = blas.genVector(L.size(), null);
454        e = ered.normalform(row, L, a);
455        //System.out.println("a = " + a);
456        //System.out.println("e = " + e);
457        //System.out.println("L = " + L);
458        //System.out.println("row = " + row);
459        assertTrue("isZERO( e )", e.isZERO());
460        assertTrue("is Reduction ", ered.isReductionNF(row, L, a, e));
461
462        row = blas.genVector(L.size(), null);
463        c = fac.getONE();
464        a = a.sum(c);
465        e = ered.normalform(row, L, a);
466        assertTrue("isONE( e ) some times", e.isONE());
467        assertTrue("is Reduction ", ered.isReductionNF(row, L, a, e));
468        //System.out.println("a = " + a);
469        //System.out.println("e = " + e);
470        //System.out.println("L = " + L);
471        //System.out.println("row = " + row);
472
473        row = blas.genVector(L.size(), null);
474        L = new ArrayList<GenPolynomial<BigInteger>>();
475        a = c.multiply(bi.fromInteger(4));
476        b = c.multiply(bi.fromInteger(5));
477
478        L.add(a);
479        e = ered.normalform(row, L, b);
480        assertTrue("isONE( e )", e.isONE());
481        assertTrue("is Reduction ", ered.isReductionNF(row, L, b, e));
482        //System.out.println("a = " + a);
483        //System.out.println("b = " + b);
484        //System.out.println("e = " + e);
485        //System.out.println("L = " + L);
486        //System.out.println("row = " + row);
487
488        a = fac.random(kl, ll, el, q).abs();
489        b = fac.random(kl, ll / 2, el / 2, q).abs();
490        c = fac.random(kl, ll * 2, el * 2, q * 1.0f).abs();
491        assertTrue("not isZERO( a )", !a.isZERO());
492
493        L = new ArrayList<GenPolynomial<BigInteger>>();
494        L.add(b);
495        L.add(a);
496        row = blas.genVector(L.size(), null);
497        e = ered.normalform(row, L, c);
498        //System.out.println("a = " + a);
499        //System.out.println("b = " + b);
500        //System.out.println("c = " + c);
501        //System.out.println("e = " + e);
502        //System.out.println("L = " + L);
503        //System.out.println("row = " + row);
504        //assertTrue("isZERO( e )", e.isZERO() );
505        assertTrue("is Reduction ", ered.isReductionNF(row, L, c, e));
506
507        L = new ArrayList<GenPolynomial<BigInteger>>();
508        L.add(a);
509        L.add(b);
510        //System.out.println("a = " + a);
511        //System.out.println("b = " + b);
512        row = blas.genVector(2, null);
513        c = ered.GPolynomial(row, 0, a, 1, b);
514        //System.out.println("c = " + c);
515        //System.out.println("row = " + row);
516
517        BigInteger ci = a.leadingBaseCoefficient().gcd(b.leadingBaseCoefficient());
518        assertEquals("gcd(lbc(a),lbc(b)) = lbc(c) ", ci, c.leadingBaseCoefficient());
519        assertTrue("is eGpol recording: " + c, ered.isReductionNF(row, L, c, fac.getZERO()));
520
521        row = blas.genVector(2, null);
522        e = ered.SPolynomial(row, 0, a, 1, b);
523        //System.out.println("e = " + e);
524        //System.out.println("row = " + row);
525
526        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
527        assertEquals("lcm(lt(a),lt(b)) == lt(c) ", ce, c.leadingExpVector());
528        assertFalse("lcm(lt(a),lt(b)) != lt(e) ", ce.equals(e.leadingExpVector()));
529
530        assertTrue("is eSpol recording: " + e, ered.isReductionNF(row, L, e, fac.getZERO()));
531    }
532
533
534    /**
535     * Test integer coefficient d-reduction.
536     */
537    public void testIntegerDReduction() {
538        BigInteger bi = new BigInteger(0);
539        GenPolynomialRing<BigInteger> fac = new GenPolynomialRing<BigInteger>(bi, rl);
540
541        DReductionSeq<BigInteger> dred = new DReductionSeq<BigInteger>();
542
543        GenPolynomial<BigInteger> a = fac.random(kl, ll, el, q);
544        GenPolynomial<BigInteger> b = fac.random(kl, ll, el, q);
545
546        assertTrue("not isZERO( a )", !a.isZERO());
547
548        List<GenPolynomial<BigInteger>> L = new ArrayList<GenPolynomial<BigInteger>>();
549        L.add(a);
550
551        GenPolynomial<BigInteger> e = dred.normalform(L, a);
552        //System.out.println("a = " + a);
553        //System.out.println("e = " + e);
554        assertTrue("isZERO( e )", e.isZERO());
555
556        assertTrue("not isZERO( b )", !b.isZERO());
557
558        L.add(b);
559        e = dred.normalform(L, a);
560        //System.out.println("b = " + b);
561        //System.out.println("e = " + e);
562        assertTrue("isZERO( e ) some times", e.isZERO());
563
564        GenPolynomial<BigInteger> c = fac.getONE();
565        a = a.sum(c);
566        e = dred.normalform(L, a);
567        //System.out.println("b = " + b);
568        //System.out.println("e = " + e);
569        assertTrue("isONE( e ) some times", e.isONE());
570
571        L = new ArrayList<GenPolynomial<BigInteger>>();
572        a = c.multiply(bi.fromInteger(5));
573        L.add(a);
574        b = c.multiply(bi.fromInteger(4));
575        e = dred.normalform(L, b);
576        //System.out.println("a = " + a);
577        //System.out.println("b = " + b);
578        //System.out.println("e = " + e);
579        assertTrue("nf(b) = b ", e.equals(b));
580
581        a = fac.random(kl, ll, el, q); //.abs();
582        b = fac.random(kl, ll, el, q); //.abs();
583        c = dred.GPolynomial(a, b);
584        e = dred.SPolynomial(a, b);
585        //System.out.println("a = " + a);
586        //System.out.println("b = " + b);
587        //System.out.println("c = " + c);
588        //System.out.println("e = " + e);
589
590        BigInteger ci = a.leadingBaseCoefficient().gcd(b.leadingBaseCoefficient());
591        assertEquals("gcd(lbc(a),lbc(b)) = lbc(c) ", ci, c.leadingBaseCoefficient());
592
593        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
594        assertEquals("lcm(lt(a),lt(b)) == lt(c) ", ce, c.leadingExpVector());
595        assertFalse("lcm(lt(a),lt(b)) != lt(e) ", ce.equals(e.leadingExpVector()));
596
597        L = new ArrayList<GenPolynomial<BigInteger>>();
598        L.add(a);
599        assertTrue("isTopRed( a )", dred.isTopReducible(L, a));
600        assertTrue("isRed( a )", dred.isReducible(L, a));
601        b = fac.random(kl, ll, el, q);
602        L.add(b);
603        assertTrue("isTopRed( b )", dred.isTopReducible(L, b));
604        assertTrue("isRed( b )", dred.isReducible(L, b));
605        c = fac.random(kl, ll, el, q);
606        e = dred.normalform(L, c);
607        assertTrue("isNF( e )", dred.isNormalform(L, e));
608    }
609
610
611    /**
612     * Test integer coefficient d-reduction recording.
613     */
614    public void testIntegerDReductionRecording() {
615        BigInteger bi = new BigInteger(0);
616        GenPolynomialRing<BigInteger> fac = new GenPolynomialRing<BigInteger>(bi, rl);
617
618        GenPolynomial<BigInteger> a, b, c, e;
619
620        DReductionSeq<BigInteger> dred = new DReductionSeq<BigInteger>();
621
622        BasicLinAlg<GenPolynomial<BigInteger>> blas = new BasicLinAlg<GenPolynomial<BigInteger>>();
623        List<GenPolynomial<BigInteger>> row = null;
624        List<GenPolynomial<BigInteger>> L = new ArrayList<GenPolynomial<BigInteger>>();
625
626        a = fac.random(kl, ll, el, q).abs();
627
628        assertTrue("not isZERO( a )", !a.isZERO());
629
630        L.add(a);
631        row = blas.genVector(L.size(), null);
632        e = dred.normalform(row, L, a);
633        //System.out.println("a = " + a);
634        //System.out.println("e = " + e);
635        //System.out.println("L = " + L);
636        //System.out.println("row = " + row);
637        //System.out.println("dred.isReductionNF(row,L,a,e) = " + dred.isReductionNF(row,L,a,e));
638        assertTrue("isZERO( e )", e.isZERO());
639        assertTrue("is Reduction ", dred.isReductionNF(row, L, a, e));
640
641        row = blas.genVector(L.size(), null);
642        c = fac.getONE();
643        a = a.sum(c);
644        e = dred.normalform(row, L, a);
645        assertTrue("isONE( e ) some times", e.isONE());
646        assertTrue("is Reduction ", dred.isReductionNF(row, L, a, e));
647        //System.out.println("a = " + a);
648        //System.out.println("e = " + e);
649        //System.out.println("L = " + L);
650        //System.out.println("row = " + row);
651        //System.out.println("dred.isReductionNF(row,L,a,e) = " + dred.isReductionNF(row,L,a,e));
652
653        row = blas.genVector(L.size(), null);
654        L = new ArrayList<GenPolynomial<BigInteger>>();
655        a = c.multiply(bi.fromInteger(4));
656        b = c.multiply(bi.fromInteger(5));
657
658        L.add(a);
659        e = dred.normalform(row, L, b);
660        //System.out.println("a = " + a);
661        //System.out.println("b = " + b);
662        //System.out.println("e = " + e);
663        //System.out.println("L = " + L);
664        //System.out.println("row = " + row);
665        //System.out.println("dred.isReductionNF(row,L,b,e) = " + dred.isReductionNF(row,L,b,e));
666        assertEquals("e == b", e, b);
667        assertTrue("is Reduction ", dred.isReductionNF(row, L, b, e));
668
669        a = fac.random(kl, ll, el, q).abs();
670        b = fac.random(kl, ll / 2, el / 2, q).abs();
671        //c = fac.random(kl, ll*2, el*2, q*1.0f ).abs();
672        c = a.multiply(b);
673        assertTrue("not isZERO( a )", !a.isZERO());
674
675        L = new ArrayList<GenPolynomial<BigInteger>>();
676        L.add(b);
677        L.add(a);
678        row = blas.genVector(L.size(), null);
679        e = dred.normalform(row, L, c);
680        //System.out.println("a = " + a);
681        //System.out.println("b = " + b);
682        //System.out.println("c = " + c);
683        //System.out.println("e = " + e);
684        //System.out.println("L = " + L);
685        //System.out.println("row = " + row);
686        //System.out.println("dred.isReductionNF(row,L,c,e) = " + dred.isReductionNF(row,L,c,e));
687        assertTrue("isZERO( e )", e.isZERO());
688        assertTrue("is Reduction ", dred.isReductionNF(row, L, c, e));
689
690        L = new ArrayList<GenPolynomial<BigInteger>>();
691        L.add(a);
692        L.add(b);
693        //System.out.println("a = " + a);
694        //System.out.println("b = " + b);
695        row = blas.genVector(2, null);
696        c = dred.GPolynomial(row, 0, a, 1, b);
697        //System.out.println("c = " + c);
698        //System.out.println("row = " + row);
699
700        BigInteger ci = a.leadingBaseCoefficient().gcd(b.leadingBaseCoefficient());
701        assertEquals("gcd(lbc(a),lbc(b)) = lbc(c) ", ci, c.leadingBaseCoefficient());
702
703        assertTrue("is dGpol recording: " + c, dred.isReductionNF(row, L, c, fac.getZERO()));
704
705        row = blas.genVector(2, null);
706        e = dred.SPolynomial(row, 0, a, 1, b);
707        //System.out.println("e = " + e);
708        //System.out.println("row = " + row);
709
710        ExpVector ce = a.leadingExpVector().lcm(b.leadingExpVector());
711        assertEquals("lcm(lt(a),lt(b)) == lt(c) ", ce, c.leadingExpVector());
712        assertFalse("lcm(lt(a),lt(b)) != lt(e) ", ce.equals(e.leadingExpVector()));
713
714        assertTrue("is dSpol recording: " + e, dred.isReductionNF(row, L, e, fac.getZERO()));
715    }
716
717}