001/*
002 * $Id: IdealTest.java 5313 2015-10-26 22:46:38Z kredel $
003 */
004
005package edu.jas.application;
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;
016import org.apache.log4j.Logger;
017
018import edu.jas.arith.BigDecimal;
019import edu.jas.arith.BigRational;
020import edu.jas.gb.GroebnerBase;
021import edu.jas.gbufd.GBFactory;
022import edu.jas.kern.ComputerThreads;
023import edu.jas.poly.Complex;
024import edu.jas.poly.ComplexRing;
025import edu.jas.poly.GenPolynomial;
026import edu.jas.poly.GenPolynomialRing;
027import edu.jas.poly.PolyUtil;
028import edu.jas.poly.PolynomialList;
029import edu.jas.poly.TermOrder;
030import edu.jas.ufd.Quotient;
031import edu.jas.util.KsubSet;
032
033
034/**
035 * Ideal tests with JUnit.
036 * @author Heinz Kredel.
037 */
038public class IdealTest extends TestCase {
039
040
041    private static final Logger logger = Logger.getLogger(IdealTest.class);
042
043
044    /**
045     * main
046     */
047    public static void main(String[] args) {
048        BasicConfigurator.configure();
049        junit.textui.TestRunner.run(suite());
050    }
051
052
053    /**
054     * Constructs a <CODE>IdealTest</CODE> object.
055     * @param name String.
056     */
057    public IdealTest(String name) {
058        super(name);
059    }
060
061
062    /**
063     * suite.
064     */
065    public static Test suite() {
066        TestSuite suite = new TestSuite(IdealTest.class);
067        return suite;
068    }
069
070
071    TermOrder to;
072
073
074    GenPolynomialRing<BigRational> fac;
075
076
077    List<GenPolynomial<BigRational>> L, M, G;
078
079
080    PolynomialList<BigRational> F;
081
082
083    GroebnerBase<BigRational> bb;
084
085
086    GenPolynomial<BigRational> a;
087
088
089    GenPolynomial<BigRational> b;
090
091
092    GenPolynomial<BigRational> c;
093
094
095    GenPolynomial<BigRational> d;
096
097
098    GenPolynomial<BigRational> e;
099
100
101    int rl = 3; //4; //3; 
102
103
104    int kl = 4; //10
105
106
107    int ll = 5; //7
108
109
110    int el = 3;
111
112
113    float q = 0.2f; //0.4f
114
115
116    @Override
117    protected void setUp() {
118        BigRational coeff = new BigRational(17, 1);
119        to = new TermOrder( /*TermOrder.INVLEX*/);
120        String[] vars = new String[] { "x", "y", "z" };
121        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
122        //bb = new GroebnerBaseSeq<BigRational>();
123        bb = GBFactory.getImplementation(coeff);
124        a = b = c = d = e = null;
125    }
126
127
128    @Override
129    protected void tearDown() {
130        a = b = c = d = e = null;
131        fac = null;
132        bb = null;
133        ComputerThreads.terminate();
134    }
135
136
137    /**
138     * Test Ideal sum.
139     */
140    public void testIdealSum() {
141
142        Ideal<BigRational> I;
143        Ideal<BigRational> J;
144        Ideal<BigRational> K;
145
146        L = new ArrayList<GenPolynomial<BigRational>>();
147
148        a = fac.random(kl, ll, el, q);
149        b = fac.random(kl, ll, el, q);
150        c = fac.random(kl, ll, el, q);
151        d = fac.random(kl, ll, el, q);
152        e = d; //fac.random(kl, ll, el, q );
153
154        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
155            return;
156        }
157
158        assertTrue("not isZERO( a )", !a.isZERO());
159        L.add(a);
160
161        I = new Ideal<BigRational>(fac, L, true);
162        assertTrue("not isZERO( I )", !I.isZERO());
163        assertTrue("not isONE( I )", !I.isONE());
164        assertTrue("isGB( I )", I.isGB());
165
166        I = new Ideal<BigRational>(fac, L, false);
167        assertTrue("not isZERO( I )", !I.isZERO());
168        assertTrue("not isONE( I )", !I.isONE());
169        assertTrue("isGB( I )", I.isGB());
170
171
172        L = bb.GB(L);
173        assertTrue("isGB( { a } )", bb.isGB(L));
174
175        I = new Ideal<BigRational>(fac, L, true);
176        assertTrue("not isZERO( I )", !I.isZERO());
177        //assertTrue("not isONE( I )", !I.isONE() );
178        assertTrue("isGB( I )", I.isGB());
179
180        I = new Ideal<BigRational>(fac, L, false);
181        assertTrue("not isZERO( I )", !I.isZERO());
182        //assertTrue("not isONE( I )", !I.isONE() );
183        assertTrue("isGB( I )", I.isGB());
184
185
186        assertTrue("not isZERO( b )", !b.isZERO());
187        L.add(b);
188        //System.out.println("L = " + L.size() );
189
190        I = new Ideal<BigRational>(fac, L, false);
191        assertTrue("not isZERO( I )", !I.isZERO());
192        //assertTrue("not isONE( I )", !I.isONE() );
193        //assertTrue("not isGB( I )", !I.isGB() );
194
195
196        L = bb.GB(L);
197        assertTrue("isGB( { a, b } )", bb.isGB(L));
198
199        I = new Ideal<BigRational>(fac, L, true);
200        assertTrue("not isZERO( I )", !I.isZERO());
201        // assertTrue("not isONE( I )", !I.isONE() );
202        assertTrue("isGB( I )", I.isGB());
203
204
205        J = I;
206        K = J.sum(I);
207        assertTrue("not isZERO( K )", !K.isZERO());
208        assertTrue("isGB( K )", K.isGB());
209        assertTrue("equals( K, I )", K.equals(I));
210
211
212        L = new ArrayList<GenPolynomial<BigRational>>();
213        assertTrue("not isZERO( c )", !c.isZERO());
214        L.add(c);
215        assertTrue("isGB( { c } )", bb.isGB(L));
216
217        J = new Ideal<BigRational>(fac, L, true);
218        K = J.sum(I);
219        assertTrue("not isZERO( K )", !K.isZERO());
220        assertTrue("isGB( K )", K.isGB());
221        assertTrue("K contains(I)", K.contains(I));
222        assertTrue("K contains(J)", K.contains(J));
223
224        L = new ArrayList<GenPolynomial<BigRational>>();
225        assertTrue("not isZERO( d )", !d.isZERO());
226        L.add(d);
227
228        assertTrue("isGB( { d } )", bb.isGB(L));
229        J = new Ideal<BigRational>(fac, L, true);
230        I = K;
231        K = J.sum(I);
232        assertTrue("not isZERO( K )", !K.isZERO());
233        assertTrue("isGB( K )", K.isGB());
234        assertTrue("K contains(I)", K.contains(I));
235        assertTrue("K contains(J)", K.contains(J));
236
237
238        L = new ArrayList<GenPolynomial<BigRational>>();
239        assertTrue("not isZERO( e )", !e.isZERO());
240        L.add(e);
241
242        assertTrue("isGB( { e } )", bb.isGB(L));
243        J = new Ideal<BigRational>(fac, L, true);
244        I = K;
245        K = J.sum(I);
246        assertTrue("not isZERO( K )", !K.isZERO());
247        assertTrue("isGB( K )", K.isGB());
248        assertTrue("equals( K, I )", K.equals(I));
249        assertTrue("K contains(J)", K.contains(I));
250        assertTrue("I contains(K)", I.contains(K));
251    }
252
253
254    /**
255     * Test Ideal product.
256     */
257    public void testIdealProduct() {
258
259        Ideal<BigRational> I;
260        Ideal<BigRational> J;
261        Ideal<BigRational> K;
262        Ideal<BigRational> H;
263
264        a = fac.random(kl, ll, el, q);
265        b = fac.random(kl, ll, el, q);
266        c = fac.random(kl, ll, el, q);
267        d = fac.random(kl, ll, el, q);
268        e = d; //fac.random(kl, ll, el, q );
269
270        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
271            return;
272        }
273
274        L = new ArrayList<GenPolynomial<BigRational>>();
275        assertTrue("not isZERO( a )", !a.isZERO());
276        L.add(a);
277
278        I = new Ideal<BigRational>(fac, L, true);
279        assertTrue("not isZERO( I )", !I.isZERO());
280        assertTrue("not isONE( I )", !I.isONE());
281        assertTrue("isGB( I )", I.isGB());
282
283        L = new ArrayList<GenPolynomial<BigRational>>();
284        assertTrue("not isZERO( b )", !a.isZERO());
285        L.add(b);
286
287        J = new Ideal<BigRational>(fac, L, true);
288        assertTrue("not isZERO( J )", !J.isZERO());
289        assertTrue("not isONE( J )", !J.isONE());
290        assertTrue("isGB( J )", J.isGB());
291
292        K = I.product(J);
293        assertTrue("not isZERO( K )", !K.isZERO());
294        assertTrue("isGB( K )", K.isGB());
295        assertTrue("I contains(K)", I.contains(K));
296        assertTrue("J contains(K)", J.contains(K));
297
298        H = I.intersect(J);
299        assertTrue("not isZERO( H )", !H.isZERO());
300        assertTrue("isGB( H )", H.isGB());
301        assertTrue("I contains(H)", I.contains(H));
302        assertTrue("J contains(H)", J.contains(H));
303        assertTrue("H contains(K)", H.contains(K));
304        //if (false /*! H.equals(K)*/) {
305        //    System.out.println("I = " + I);
306        //    System.out.println("J = " + J);
307        //    System.out.println("K = " + K);
308        //    System.out.println("H = " + H);
309        //}
310
311
312        L = new ArrayList<GenPolynomial<BigRational>>();
313        assertTrue("not isZERO( a )", !a.isZERO());
314        L.add(a);
315        assertTrue("not isZERO( c )", !c.isZERO());
316        L.add(c);
317        L = bb.GB(L);
318
319        I = new Ideal<BigRational>(fac, L, true);
320        assertTrue("not isZERO( I )", !I.isZERO());
321        //assertTrue("not isONE( I )", !I.isONE() );
322        assertTrue("isGB( I )", I.isGB());
323
324        K = I.product(J);
325        assertTrue("not isZERO( K )", !K.isZERO());
326        assertTrue("isGB( K )", K.isGB());
327        assertTrue("I contains(K)", I.contains(K));
328        assertTrue("J contains(K)", J.contains(K));
329
330        H = I.intersect(J);
331        assertTrue("not isZERO( H )", !H.isZERO());
332        assertTrue("isGB( H )", H.isGB());
333        assertTrue("I contains(H)", I.contains(H));
334        assertTrue("J contains(H)", J.contains(H));
335        assertTrue("H contains(K)", H.contains(K));
336        //if (false /*! H.equals(K)*/) {
337        //    System.out.println("I = " + I);
338        //    System.out.println("J = " + J);
339        //    System.out.println("K = " + K);
340        //    System.out.println("H = " + H);
341        //}
342
343
344        L = new ArrayList<GenPolynomial<BigRational>>();
345        assertTrue("not isZERO( b )", !b.isZERO());
346        L.add(b);
347        assertTrue("not isZERO( d )", !d.isZERO());
348        L.add(d);
349        L = bb.GB(L);
350
351        J = new Ideal<BigRational>(fac, L, true);
352        assertTrue("not isZERO( J )", !J.isZERO());
353        //assertTrue("not isONE( J )", !J.isONE() );
354        assertTrue("isGB( J )", J.isGB());
355
356        K = I.product(J);
357        assertTrue("not isZERO( K )", !K.isZERO());
358        assertTrue("isGB( K )", K.isGB());
359        assertTrue("I contains(K)", I.contains(K));
360        assertTrue("J contains(K)", J.contains(K));
361
362        H = I.intersect(J);
363        assertTrue("not isZERO( H )", !H.isZERO());
364        assertTrue("isGB( H )", H.isGB());
365        assertTrue("I contains(H)", I.contains(H));
366        assertTrue("J contains(H)", J.contains(H));
367        assertTrue("H contains(K)", H.contains(K));
368        //if (false /*! H.equals(K)*/) {
369        //    System.out.println("I = " + I);
370        //    System.out.println("J = " + J);
371        //    System.out.println("K = " + K);
372        //    System.out.println("H = " + H);
373        //}
374    }
375
376
377    /**
378     * Test Ideal quotient.
379     */
380    public void testIdealQuotient() {
381
382        Ideal<BigRational> I;
383        Ideal<BigRational> J;
384        Ideal<BigRational> K;
385        Ideal<BigRational> H;
386
387        a = fac.random(kl, ll, el, q);
388        b = fac.random(kl, ll, el, q);
389        c = fac.random(kl, ll, el, q);
390        d = fac.random(kl, ll, el, q);
391        e = d; //fac.random(kl, ll, el, q );
392
393        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
394            return;
395        }
396
397        L = new ArrayList<GenPolynomial<BigRational>>();
398        assertTrue("not isZERO( a )", !a.isZERO());
399        L.add(a);
400        L = bb.GB(L);
401
402        I = new Ideal<BigRational>(fac, L, true);
403        assertTrue("not isZERO( I )", !I.isZERO());
404        //assertTrue("not isONE( I )", !I.isONE() );
405        assertTrue("isGB( I )", I.isGB());
406
407
408        L = new ArrayList<GenPolynomial<BigRational>>();
409        assertTrue("not isZERO( b )", !a.isZERO());
410        L.add(b);
411        L = bb.GB(L);
412
413        J = new Ideal<BigRational>(fac, L, true);
414        assertTrue("not isZERO( J )", !J.isZERO());
415        //assertTrue("not isONE( J )", !J.isONE() );
416        assertTrue("isGB( J )", J.isGB());
417
418        K = I.product(J);
419        assertTrue("not isZERO( K )", !K.isZERO());
420        assertTrue("isGB( K )", K.isGB());
421        assertTrue("I contains(K)", I.contains(K));
422        assertTrue("J contains(K)", J.contains(K));
423
424        H = K.quotient(J.getList().get(0));
425        assertTrue("not isZERO( H )", !H.isZERO());
426        assertTrue("isGB( H )", H.isGB());
427        assertTrue("equals(H,I)", H.equals(I)); // GBs only
428
429        H = K.quotient(J);
430        assertTrue("not isZERO( H )", !H.isZERO());
431        assertTrue("isGB( H )", H.isGB());
432        assertTrue("equals(H,I)", H.equals(I)); // GBs only
433
434
435        L = new ArrayList<GenPolynomial<BigRational>>();
436        assertTrue("not isZERO( b )", !b.isZERO());
437        L.add(b);
438        assertTrue("not isZERO( c )", !c.isZERO());
439        L.add(c);
440        L = bb.GB(L);
441
442        J = new Ideal<BigRational>(fac, L, true);
443        assertTrue("not isZERO( J )", !J.isZERO());
444        //assertTrue("not isONE( J )", !J.isONE() );
445        assertTrue("isGB( J )", J.isGB());
446
447        K = I.product(J);
448        assertTrue("not isZERO( K )", !K.isZERO());
449        assertTrue("isGB( K )", K.isGB());
450        assertTrue("I contains(K)", I.contains(K));
451        assertTrue("J contains(K)", J.contains(K));
452
453        H = K.quotient(J);
454        assertTrue("not isZERO( H )", !H.isZERO());
455        assertTrue("isGB( H )", H.isGB());
456        assertTrue("equals(H,I)", H.equals(I)); // GBs only
457
458
459        L = new ArrayList<GenPolynomial<BigRational>>();
460        assertTrue("not isZERO( a )", !a.isZERO());
461        L.add(a);
462        assertTrue("not isZERO( d )", !d.isZERO());
463        L.add(d);
464        L = bb.GB(L);
465
466        I = new Ideal<BigRational>(fac, L, true);
467        assertTrue("not isZERO( I )", !I.isZERO());
468        //assertTrue("not isONE( J )", !J.isONE() );
469        assertTrue("isGB( I )", I.isGB());
470
471        K = I.product(J);
472        assertTrue("not isZERO( K )", !K.isZERO());
473        assertTrue("isGB( K )", K.isGB());
474        assertTrue("I contains(K)", I.contains(K));
475        assertTrue("J contains(K)", J.contains(K));
476
477        H = K.quotient(J);
478        assertTrue("not isZERO( H )", !H.isZERO());
479        assertTrue("isGB( H )", H.isGB());
480        assertTrue("equals(H,I)", H.equals(I)); // GBs only
481    }
482
483
484    /**
485     * Test Ideal infinite quotient.
486     */
487    public void testIdealInfiniteQuotient() {
488
489        Ideal<BigRational> I;
490        Ideal<BigRational> J;
491        Ideal<BigRational> K;
492
493        a = fac.random(kl, ll, el, q);
494        b = fac.random(kl, ll, el, q);
495        c = fac.random(kl, ll, el, q);
496        d = fac.random(kl, ll, el, q);
497        e = d; //fac.random(kl, ll, el, q );
498
499        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
500            return;
501        }
502
503        L = new ArrayList<GenPolynomial<BigRational>>();
504        assertTrue("not isZERO( b )", !b.isZERO());
505        L.add(b);
506        L = bb.GB(L);
507        I = new Ideal<BigRational>(fac, L, true);
508        assertTrue("not isZERO( I )", !I.isZERO());
509        //assertTrue("not isONE( I )", !I.isONE() );
510        assertTrue("isGB( I )", I.isGB());
511
512        J = I.infiniteQuotient(a);
513
514        assertTrue("not isZERO( c )", !c.isZERO());
515        L.add(c);
516        L = bb.GB(L);
517        I = new Ideal<BigRational>(fac, L, true);
518        assertTrue("not isZERO( I )", !I.isZERO());
519        //assertTrue("not isONE( I )", !I.isONE() );
520        assertTrue("isGB( I )", I.isGB());
521
522        J = I.infiniteQuotient(a);
523        assertTrue("equals(J,I)", J.equals(I)); // GBs only
524
525        assertTrue("not isZERO( d )", !d.isZERO());
526        L.add(d);
527        L = bb.GB(L);
528        I = new Ideal<BigRational>(fac, L, true);
529        assertTrue("not isZERO( I )", !I.isZERO());
530        //assertTrue("not isONE( I )", !I.isONE() );
531        assertTrue("isGB( I )", I.isGB());
532
533        J = I.infiniteQuotient(a);
534        assertTrue("isGB( J )", J.isGB());
535        assertTrue("equals(J,I)", J.equals(I)); // GBs only
536
537
538        G = new ArrayList<GenPolynomial<BigRational>>();
539        assertTrue("not isZERO( a )", !a.isZERO());
540        G.add(a);
541        G = bb.GB(G);
542        K = new Ideal<BigRational>(fac, G, true);
543        assertTrue("not isZERO( K )", !K.isZERO());
544        //assertTrue("not isONE( I )", !I.isONE() );
545        assertTrue("isGB( K )", K.isGB());
546
547        J = I.infiniteQuotient(K);
548        assertTrue("equals(J,I)", J.equals(I)); // GBs only
549
550
551        assertTrue("not isZERO( e )", !e.isZERO());
552        G.add(e);
553        G = bb.GB(G);
554        K = new Ideal<BigRational>(fac, G, true);
555        assertTrue("not isZERO( K )", !K.isZERO());
556        //assertTrue("not isONE( I )", !I.isONE() );
557        assertTrue("isGB( K )", K.isGB());
558
559        J = I.infiniteQuotient(K);
560        assertTrue("equals(J,I)", J.equals(I)); // GBs only
561    }
562
563
564    /**
565     * Test Ideal infinite quotient with Rabinowich trick.
566     */
567    public void testIdealInfiniteQuotientRabi() {
568
569        Ideal<BigRational> I;
570        Ideal<BigRational> J;
571        Ideal<BigRational> K;
572        Ideal<BigRational> JJ;
573
574        a = fac.random(kl - 1, ll - 1, el - 1, q / 2);
575        b = fac.random(kl - 1, ll - 1, el, q / 2);
576        c = fac.random(kl - 1, ll - 1, el, q / 2);
577        d = fac.random(kl - 1, ll - 1, el, q / 2);
578        e = a; //fac.random(kl, ll-1, el, q );
579
580        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
581            return;
582        }
583
584        L = new ArrayList<GenPolynomial<BigRational>>();
585        assertTrue("not isZERO( b )", !b.isZERO());
586        L.add(b);
587        L = bb.GB(L);
588        I = new Ideal<BigRational>(fac, L, true);
589        assertTrue("not isZERO( I )", !I.isZERO());
590        //assertTrue("not isONE( I )", !I.isONE() );
591        assertTrue("isGB( I )", I.isGB());
592
593        J = I.infiniteQuotientRab(a);
594        JJ = I.infiniteQuotient(a);
595        assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only
596
597        assertTrue("not isZERO( c )", !c.isZERO());
598        L.add(c);
599        L = bb.GB(L);
600        I = new Ideal<BigRational>(fac, L, true);
601        assertTrue("not isZERO( I )", !I.isZERO());
602        //assertTrue("not isONE( I )", !I.isONE() );
603        assertTrue("isGB( I )", I.isGB());
604
605        J = I.infiniteQuotientRab(a);
606        assertTrue("equals(J,I)", J.equals(I)); // GBs only
607        JJ = I.infiniteQuotient(a);
608        assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only
609
610        assertTrue("not isZERO( d )", !d.isZERO());
611        L.add(d);
612        L = bb.GB(L);
613        I = new Ideal<BigRational>(fac, L, true);
614        assertTrue("not isZERO( I )", !I.isZERO());
615        //assertTrue("not isONE( I )", !I.isONE() );
616        assertTrue("isGB( I )", I.isGB());
617
618        J = I.infiniteQuotientRab(a);
619        assertTrue("isGB( J )", J.isGB());
620        assertTrue("equals(J,I)", J.equals(I)); // GBs only
621        JJ = I.infiniteQuotient(a);
622        assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only
623
624
625        G = new ArrayList<GenPolynomial<BigRational>>();
626        assertTrue("not isZERO( a )", !a.isZERO());
627        G.add(a);
628        G = bb.GB(G);
629        K = new Ideal<BigRational>(fac, G, true);
630        assertTrue("not isZERO( K )", !K.isZERO());
631        //assertTrue("not isONE( I )", !I.isONE() );
632        assertTrue("isGB( K )", K.isGB());
633
634        J = I.infiniteQuotientRab(K);
635        assertTrue("equals(J,I)", J.equals(I)); // GBs only
636        JJ = I.infiniteQuotient(a);
637        assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only
638
639
640        assertTrue("not isZERO( e )", !e.isZERO());
641        G.add(e);
642        G = bb.GB(G);
643        K = new Ideal<BigRational>(fac, G, true);
644        assertTrue("not isZERO( K )", !K.isZERO());
645        //assertTrue("not isONE( I )", !I.isONE() );
646        assertTrue("isGB( K )", K.isGB());
647
648        J = I.infiniteQuotientRab(K);
649        assertTrue("equals(J,I)", J.equals(I)); // GBs only
650        JJ = I.infiniteQuotient(a);
651        assertTrue("equals(J,JJ)", J.equals(JJ)); // GBs only
652    }
653
654
655    /**
656     * Test Ideal radical membership.
657     */
658    public void testIdealRadicalMember() {
659
660        Ideal<BigRational> I;
661        //Ideal<BigRational> J;
662        //Ideal<BigRational> K;
663        //Ideal<BigRational> JJ;
664
665        a = fac.random(kl - 1, ll, el - 1, q);
666        b = fac.random(kl - 1, ll, el, q);
667        c = fac.random(kl - 1, ll - 1, el, q / 2);
668        d = fac.random(kl - 1, ll - 1, el, q / 2);
669        e = a; //fac.random(kl, ll-1, el, q );
670
671        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
672            return;
673        }
674
675        L = new ArrayList<GenPolynomial<BigRational>>();
676        L.add(b);
677        L = bb.GB(L);
678        I = new Ideal<BigRational>(fac, L, true);
679        assertTrue("not isZERO( I )", !I.isZERO());
680        //assertTrue("not isONE( I )", !I.isONE() );
681        assertTrue("isGB( I )", I.isGB());
682
683        //System.out.println("a = " + a);
684        //System.out.println("b = " + b);
685        //System.out.println("I = " + I);
686
687        if (!I.isONE()) {
688            assertFalse("a in radical(b)", I.isRadicalMember(a));
689            assertTrue("b in radical(b)", I.isRadicalMember(b));
690        }
691
692        L = new ArrayList<GenPolynomial<BigRational>>();
693        L.add(b.multiply(b));
694        L = bb.GB(L);
695        I = new Ideal<BigRational>(fac, L, true);
696        assertTrue("not isZERO( I )", !I.isZERO());
697        //assertTrue("not isONE( I )", !I.isONE() );
698        assertTrue("isGB( I )", I.isGB());
699
700        //System.out.println("I = " + I);
701
702        if (!I.isONE()) {
703            assertFalse("a in radical(b*b)", I.isRadicalMember(a));
704            assertTrue("b in radical(b*b)", I.isRadicalMember(b));
705        }
706
707        //System.out.println("c = " + c);
708        L.add(c);
709        L = bb.GB(L);
710        I = new Ideal<BigRational>(fac, L, true);
711        assertTrue("not isZERO( I )", !I.isZERO());
712        //assertTrue("not isONE( I )", !I.isONE() );
713        assertTrue("isGB( I )", I.isGB());
714
715        //System.out.println("I = " + I);
716
717        if (!I.isONE()) {
718            assertFalse("a in radical(b*b)", I.isRadicalMember(a));
719            assertTrue("b in radical(b*b)", I.isRadicalMember(b));
720        }
721    }
722
723
724    /**
725     * Test Ideal common zeros.
726     */
727    public void testIdealCommonZeros() {
728
729        Ideal<BigRational> I;
730        L = new ArrayList<GenPolynomial<BigRational>>();
731
732        I = new Ideal<BigRational>(fac, L, true);
733        assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1);
734
735        a = fac.getZERO();
736        L.add(a);
737        I = new Ideal<BigRational>(fac, L, true);
738        assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1);
739
740        b = fac.getONE();
741        L.add(b);
742        I = new Ideal<BigRational>(fac, L, true);
743        assertEquals("commonZeroTest( I )", I.commonZeroTest(), -1);
744
745        L = new ArrayList<GenPolynomial<BigRational>>();
746        a = fac.random(kl, ll, el, q);
747        if (!a.isZERO() && !a.isConstant()) {
748            L.add(a);
749            I = new Ideal<BigRational>(fac, L, true);
750            assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1);
751        }
752
753        L = (List<GenPolynomial<BigRational>>) fac.univariateList();
754        I = new Ideal<BigRational>(fac, L, true);
755        assertEquals("commonZeroTest( I )", I.commonZeroTest(), 0);
756
757        L.remove(0);
758        I = new Ideal<BigRational>(fac, L, true);
759        assertEquals("commonZeroTest( I )", I.commonZeroTest(), 1);
760    }
761
762
763    /**
764     * Test Ideal dimension.
765     */
766    public void testIdealDimension() {
767
768        Ideal<BigRational> I;
769        L = new ArrayList<GenPolynomial<BigRational>>();
770        Dimension dim;
771
772        I = new Ideal<BigRational>(fac, L, true);
773        assertEquals("dimension( I )", rl, I.dimension().d);
774
775        a = fac.getZERO();
776        L.add(a);
777        I = new Ideal<BigRational>(fac, L, true);
778        assertEquals("dimension( I )", rl, I.dimension().d);
779
780        b = fac.getONE();
781        L.add(b);
782        I = new Ideal<BigRational>(fac, L, true);
783        assertEquals("dimension( I )", -1, I.dimension().d);
784
785        L = new ArrayList<GenPolynomial<BigRational>>();
786        a = fac.random(kl, ll, el, q);
787        if (!a.isZERO() && !a.isConstant()) {
788            L.add(a);
789            I = new Ideal<BigRational>(fac, L, true);
790            //System.out.println("a = " + a);
791            dim = I.dimension();
792            //System.out.println("dim(I) = " + dim);
793            assertTrue("dimension( I )", dim.d >= 1);
794        }
795
796        L = (List<GenPolynomial<BigRational>>) fac.univariateList();
797        I = new Ideal<BigRational>(fac, L, true);
798        dim = I.dimension();
799        assertEquals("dimension( I )", 0, dim.d);
800
801        while (L.size() > 0) {
802            L.remove(0);
803            I = new Ideal<BigRational>(fac, L, true);
804            //System.out.println("I = " + I);
805            dim = I.dimension();
806            //System.out.println("dim(I) = " + dim);
807            assertEquals("dimension( I )", rl - L.size(), dim.d);
808        }
809
810        L = (List<GenPolynomial<BigRational>>) fac.univariateList();
811        I = new Ideal<BigRational>(fac, L, true);
812        I = I.product(I);
813        //System.out.println("I = " + I);
814        dim = I.dimension();
815        //System.out.println("dim(I) = " + dim);
816        assertEquals("dimension( I )", 0, dim.d);
817
818        L = I.getList();
819        while (L.size() > 0) {
820            L.remove(0);
821            I = new Ideal<BigRational>(fac, L, true);
822            //System.out.println("I = " + I);
823            dim = I.dimension();
824            //System.out.println("dim(I) = " + dim);
825            assertTrue("dimension( I )", dim.d > 0);
826        }
827    }
828
829
830    /**
831     * Test Ideal term order optimization.
832     */
833    public void testIdealTopt() {
834
835        Ideal<BigRational> I;
836        Ideal<BigRational> J;
837        Ideal<BigRational> K;
838
839        L = new ArrayList<GenPolynomial<BigRational>>();
840
841        a = fac.random(kl, ll, el, q);
842        b = fac.random(kl, ll, el, q);
843        c = fac.random(kl, ll, el, q);
844        d = fac.random(kl, ll, el, q);
845        e = d; //fac.random(kl, ll, el, q );
846
847        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
848            return;
849        }
850
851        assertTrue("not isZERO( a )", !a.isZERO());
852        L.add(a);
853
854        I = new Ideal<BigRational>(fac, L);
855        I.doGB();
856        assertTrue("not isZERO( I )", !I.isZERO());
857        assertTrue("isGB( I )", I.isGB());
858        //System.out.println("I = " + I);
859
860        J = I.copy(); //new Ideal<BigRational>(fac,L);
861        J.doToptimize();
862        assertTrue("not isZERO( J )", !J.isZERO());
863        assertTrue("isGB( J )", J.isGB());
864        //System.out.println("J = " + J);
865
866        if (I.isONE()) {
867            return;
868        }
869
870        assertTrue("not isZERO( b )", !b.isZERO());
871        L.add(b);
872
873        I = new Ideal<BigRational>(fac, L);
874        K = I.copy();
875        I.doGB();
876        assertTrue("not isZERO( I )", !I.isZERO());
877        assertTrue("isGB( I )", I.isGB());
878        //System.out.println("GB(I) = " + I);
879
880        K.doToptimize();
881        K.doGB();
882        assertTrue("not isZERO( K )", !K.isZERO());
883        assertTrue("isGB( K )", K.isGB());
884        //System.out.println("GB(opt(K)) = " + K);
885
886        J = I.copy();
887        J.doToptimize();
888        assertTrue("not isZERO( J )", !J.isZERO());
889        assertTrue("isGB( J )", J.isGB());
890        //System.out.println("opt(GB(J)) = " + J);
891
892        if (I.isONE()) {
893            return;
894        }
895
896        assertTrue("not isZERO( c )", !c.isZERO());
897        L.add(c);
898
899        I = new Ideal<BigRational>(fac, L);
900        K = I.copy();
901        I.doGB();
902        assertTrue("not isZERO( I )", !I.isZERO());
903        assertTrue("isGB( I )", I.isGB());
904        //System.out.println("GB(I) = " + I);
905
906        K.doToptimize();
907        K.doGB();
908        assertTrue("not isZERO( K )", !K.isZERO());
909        assertTrue("isGB( K )", K.isGB());
910        //System.out.println("GB(opt(K)) = " + K);
911
912        J = I.copy();
913        J.doToptimize();
914        assertTrue("not isZERO( J )", !J.isZERO());
915        assertTrue("isGB( J )", J.isGB());
916        //System.out.println("opt(GB(J)) = " + J);
917    }
918
919
920    /**
921     * Test elimination Ideals.
922     */
923    public void testElimIdeal() {
924
925        String[] vars = fac.getVars();
926        //System.out.println("vars = " + Arrays.toString(vars));
927        //System.out.println("fac = " + fac);
928
929        Ideal<BigRational> I;
930        Ideal<BigRational> J;
931
932        L = new ArrayList<GenPolynomial<BigRational>>();
933
934        a = fac.univariate(2, 3L); //fac.random(kl, ll, el, q );
935        b = fac.univariate(1, 2L); //fac.random(kl, ll, el, q );
936        c = fac.univariate(0, 1L); //fac.random(kl, ll, el, q );
937
938        if (a.isZERO() || b.isZERO() || c.isZERO()) {
939            return;
940        }
941
942        L.add(a);
943        L.add(b);
944        L.add(c);
945
946        I = new Ideal<BigRational>(fac, L);
947        //I.doGB();
948        assertTrue("not isZERO( I )", !I.isZERO());
949        assertTrue("isGB( I )", I.isGB());
950        //System.out.println("I = " + I);
951
952        List<String> sv = new ArrayList<String>(vars.length);
953        for (int i = 0; i < vars.length; i++) {
954            sv.add(vars[i]);
955        }
956        //System.out.println("sv    = " + sv);
957
958        for (int i = 0; i <= vars.length; i++) {
959            KsubSet<String> ps = new KsubSet<String>(sv, i);
960            //System.out.println("========================== ps : " + i);
961            for (List<String> ev : ps) {
962                //System.out.println("ev = " + ev);
963
964                String[] evars = new String[ev.size()];
965                for (int j = 0; j < ev.size(); j++) {
966                    evars[j] = ev.get(j);
967                }
968                GenPolynomialRing<BigRational> efac;
969                efac = new GenPolynomialRing<BigRational>(fac.coFac, evars.length, fac.tord, evars);
970                //System.out.println("efac = " + efac);
971
972                J = I.eliminate(efac);
973                assertTrue("isGB( J )", J.isGB());
974                assertTrue("size( J ) <=  |ev|", J.getList().size() <= ev.size());
975                //System.out.println("J = " + J);
976            }
977        }
978    }
979
980
981    /**
982     * Test univariate polynomials in ideal.
983     */
984    public void testUnivPoly() {
985        String[] vars;
986
987        BigRational coeff = new BigRational(17, 1);
988        to = new TermOrder(TermOrder.INVLEX);
989        vars = new String[] { "x", "y", "z" };
990        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
991
992        vars = fac.getVars();
993        //System.out.println("vars = " + Arrays.toString(vars));
994        //System.out.println("fac = " + fac);
995        assertTrue("vars.length == 3 ", vars.length == 3);
996
997        Ideal<BigRational> I;
998        L = new ArrayList<GenPolynomial<BigRational>>();
999
1000        a = fac.parse("( x^3 + 34/55 x^2 + 1/9 x + 99 )");
1001        b = fac.parse("( y^4 - x )");
1002        c = fac.parse("( z^3 - x y )");
1003
1004        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1005            return;
1006        }
1007
1008        L.add(a);
1009        L.add(b);
1010        L.add(c);
1011        I = new Ideal<BigRational>(fac, L);
1012        //I.doGB();
1013        assertTrue("not isZERO( I )", !I.isZERO());
1014        assertTrue("isGB( I )", I.isGB());
1015        //System.out.println("I = " + I);
1016
1017        for (int i = 0; i < rl; i++) { // rl
1018            GenPolynomial<BigRational> u = I.constructUnivariate(rl - 1 - i);
1019            //System.out.println("u = " + u);
1020            GenPolynomial<BigRational> U = fac.parse(u.toString());
1021            //System.out.println("U = " + U + "\n");
1022            assertTrue("I.contains(U) ", I.contains(U));
1023        }
1024
1025        List<GenPolynomial<BigRational>> Us = I.constructUnivariate();
1026        for (GenPolynomial<BigRational> u : Us) {
1027            //System.out.println("u = " + u);
1028            GenPolynomial<BigRational> U = fac.parse(u.toString());
1029            //System.out.println("U = " + U + "\n");
1030            assertTrue("I.contains(U) ", I.contains(U));
1031        }
1032    }
1033
1034
1035    /**
1036     * Test complex roots univariate polynomials in zero dim ideal.
1037     */
1038    public void testComplexRoot() {
1039        String[] vars;
1040
1041        BigRational coeff = new BigRational(17, 1);
1042        to = new TermOrder(TermOrder.INVLEX);
1043        vars = new String[] { "x", "y", "z" };
1044        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1045
1046        vars = fac.getVars();
1047        //System.out.println("vars = " + Arrays.toString(vars));
1048        //System.out.println("fac = " + fac);
1049        assertTrue("vars.length == 3 ", vars.length == 3);
1050
1051        Ideal<BigRational> I;
1052        L = new ArrayList<GenPolynomial<BigRational>>();
1053
1054        a = fac.parse("( x^3 - 27 )");
1055        b = fac.parse("( y^2 - 9 )");
1056        c = fac.parse("( z - 7 )");
1057
1058        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1059            return;
1060        }
1061
1062        L.add(a);
1063        L.add(b);
1064        L.add(c);
1065        I = new Ideal<BigRational>(fac, L);
1066        //I.doGB();
1067        assertTrue("not isZERO( I )", !I.isZERO());
1068        assertTrue("isGB( I )", I.isGB());
1069        //System.out.println("I = " + I);
1070
1071        BigRational eps = new BigRational(1, 1000000);
1072        eps = eps.multiply(eps);
1073        eps = eps.multiply(eps).multiply(eps);
1074        BigDecimal e = new BigDecimal(eps.getRational());
1075        e = e.abs(); //.multiply(e); 
1076
1077        BigDecimal dc = BigDecimal.ONE;
1078        GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, fac);
1079        //System.out.println("dfac = " + dfac);
1080        ComplexRing<BigDecimal> dcc = new ComplexRing<BigDecimal>(dc);
1081        GenPolynomialRing<Complex<BigDecimal>> dcfac = new GenPolynomialRing<Complex<BigDecimal>>(dcc, dfac);
1082        //System.out.println("dcfac = " + dcfac);
1083
1084        List<List<Complex<BigDecimal>>> roots = PolyUtilApp.<BigRational> complexRootTuples(I, eps);
1085        //System.out.println("roots = " + roots + "\n");
1086        for (GenPolynomial<BigRational> p : I.getList()) {
1087            GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p);
1088            GenPolynomial<Complex<BigDecimal>> dpc = PolyUtil.<BigDecimal> toComplex(dcfac, dp);
1089            //System.out.println("dpc = " + dpc);
1090            for (List<Complex<BigDecimal>> r : roots) {
1091                //System.out.println("r = " + r);
1092                Complex<BigDecimal> ev = PolyUtil.<Complex<BigDecimal>> evaluateAll(dcc, dcfac, dpc, r);
1093                if (ev.norm().getRe().compareTo(e) > 0) {
1094                    //System.out.println("ev = " + ev);
1095                    fail("ev > eps : " + ev + " > " + e);
1096                }
1097            }
1098        }
1099        //System.out.println();
1100    }
1101
1102
1103    /**
1104     * Test real roots univariate polynomials in zero dim ideal.
1105     */
1106    public void testRealRoot() {
1107        String[] vars;
1108
1109        BigRational coeff = new BigRational(17, 1);
1110        to = new TermOrder(TermOrder.INVLEX);
1111        vars = new String[] { "x", "y", "z" };
1112        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1113
1114        vars = fac.getVars();
1115        //System.out.println("vars = " + Arrays.toString(vars));
1116        //System.out.println("fac = " + fac);
1117        assertTrue("vars.length == 3 ", vars.length == 3);
1118
1119        Ideal<BigRational> I;
1120        L = new ArrayList<GenPolynomial<BigRational>>();
1121
1122        a = fac.parse("( x^3 - 27 )");
1123        b = fac.parse("( y^4 - x )");
1124        c = fac.parse("( z^2 - x^2 )");
1125
1126        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1127            return;
1128        }
1129
1130        L.add(a);
1131        L.add(b);
1132        L.add(c);
1133        I = new Ideal<BigRational>(fac, L);
1134        //I.doGB();
1135        assertTrue("not isZERO( I )", !I.isZERO());
1136        assertTrue("isGB( I )", I.isGB());
1137        //System.out.println("I = " + I);
1138
1139        BigRational eps = new BigRational(1, 1000000);
1140        eps = eps.multiply(eps);
1141        eps = eps.multiply(eps); //.multiply(eps);
1142        BigDecimal e = new BigDecimal(eps.getRational());
1143        e = e.abs(); //.multiply(e);
1144        eps = eps.multiply(new BigRational(1, 100));
1145
1146        List<List<BigDecimal>> roots = PolyUtilApp.<BigRational> realRootTuples(I, eps);
1147        //System.out.println("roots = " + roots + "\n");
1148        // polynomials with decimal coefficients
1149        BigDecimal dc = BigDecimal.ONE;
1150        GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, fac);
1151        //System.out.println("dfac = " + dfac);
1152        for (GenPolynomial<BigRational> p : I.getList()) {
1153            GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p);
1154            //System.out.println("dp = " + dp);
1155            for (List<BigDecimal> r : roots) {
1156                //System.out.println("r = " + r);
1157                BigDecimal ev = PolyUtil.<BigDecimal> evaluateAll(dc, dfac, dp, r);
1158                if (ev.abs().compareTo(e) > 0) {
1159                    //System.out.println("ev = " + ev);
1160                    fail("ev > e : " + ev + " > " + e + ", eps = " + new BigDecimal(eps));
1161                }
1162            }
1163        }
1164        //System.out.println();
1165    }
1166
1167
1168    /**
1169     * Test zero dimensional decomposition.
1170     */
1171    public void testZeroDimDecomp() {
1172        String[] vars;
1173
1174        BigRational coeff = new BigRational(17, 1);
1175        to = new TermOrder(TermOrder.INVLEX);
1176        vars = new String[] { "x", "y", "z" };
1177        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1178
1179        vars = fac.getVars();
1180        //System.out.println("vars = " + Arrays.toString(vars));
1181        //System.out.println("fac = " + fac);
1182        assertTrue("vars.length == 3 ", vars.length == 3);
1183
1184        Ideal<BigRational> I;
1185        L = new ArrayList<GenPolynomial<BigRational>>();
1186
1187        a = fac.parse("( x^3 - 27 )");
1188        b = fac.parse("( y^4 - x )");
1189        c = fac.parse("( z^2 - x^2 )");
1190
1191        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1192            return;
1193        }
1194
1195        L.add(a);
1196        L.add(b);
1197        L.add(c);
1198        I = new Ideal<BigRational>(fac, L);
1199        //I.doGB();
1200        assertTrue("not isZERO( I )", !I.isZERO());
1201        assertTrue("isGB( I )", I.isGB());
1202        //System.out.println("I = " + I);
1203
1204        List<IdealWithUniv<BigRational>> zd = I.zeroDimDecomposition();
1205        //System.out.println("I = " + I);
1206        //System.out.println("zd = " + zd);
1207
1208        boolean t = I.isZeroDimDecomposition(zd);
1209        //System.out.println("t = " + t);
1210        assertTrue("is decomposition ", t);
1211    }
1212
1213
1214    /**
1215     * Test real roots univariate polynomials in zero dim ideal.
1216     */
1217    public void testIdealRealRoot() {
1218        String[] vars;
1219
1220        BigRational coeff = new BigRational(17, 1);
1221        to = new TermOrder(TermOrder.INVLEX);
1222        vars = new String[] { "x", "y", "z" };
1223        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1224
1225        vars = fac.getVars();
1226        //System.out.println("vars = " + Arrays.toString(vars));
1227        //System.out.println("fac = " + fac);
1228        assertTrue("vars.length == 3 ", vars.length == 3);
1229
1230        Ideal<BigRational> I;
1231        L = new ArrayList<GenPolynomial<BigRational>>();
1232
1233        a = fac.parse("( x^3 - 27 )");
1234        b = fac.parse("( y^4 - x )");
1235        c = fac.parse("( z^2 - x^2 )");
1236
1237        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1238            return;
1239        }
1240
1241        L.add(a);
1242        L.add(b);
1243        L.add(c);
1244        I = new Ideal<BigRational>(fac, L);
1245        //I.doGB();
1246        assertTrue("not isZERO( I )", !I.isZERO());
1247        assertTrue("isGB( I )", I.isGB());
1248        //System.out.println("I = " + I);
1249
1250        List<IdealWithUniv<BigRational>> zd = I.zeroDimDecomposition();
1251        //System.out.println("zd = " + zd);
1252        assertTrue("is decomposition ", I.isZeroDimDecomposition(zd));
1253
1254        BigRational eps = new BigRational(1, 1000000);
1255        eps = eps.multiply(eps);
1256        eps = eps.multiply(eps); //.multiply(eps);
1257        BigDecimal e = new BigDecimal(eps.getRational());
1258        e = e.abs(); //.multiply(e);
1259        eps = eps.multiply(new BigRational(1, 10));
1260        BigDecimal dc = BigDecimal.ONE;
1261
1262        List<IdealWithRealRoots<BigRational>> roots = PolyUtilApp.<BigRational> realRoots(zd, eps);
1263        //System.out.println("roots = " + roots + "\n");
1264
1265        for (IdealWithRealRoots<BigRational> Ir : roots) {
1266            List<GenPolynomial<BigRational>> L = Ir.ideal.getList();
1267            List<GenPolynomial<BigDecimal>> Ld = new ArrayList<GenPolynomial<BigDecimal>>(L.size());
1268
1269            GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(dc, Ir.ideal.list.ring);
1270            //System.out.println("dfac = " + dfac);
1271
1272            for (GenPolynomial<BigRational> p : L) {
1273                GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p);
1274                //System.out.println("dp = " + dp);
1275                Ld.add(dp);
1276            }
1277            boolean t = PolyUtilApp.isRealRoots(Ld, Ir.rroots, e);
1278            assertTrue("isRealRoots ", t); // this example only
1279        }
1280    }
1281
1282
1283    /**
1284     * Test complex roots univariate polynomials in zero dim ideal.
1285     */
1286    public void testIdealComplexRoot() {
1287        String[] vars;
1288
1289        BigRational coeff = new BigRational(1, 1);
1290        to = new TermOrder(TermOrder.INVLEX);
1291        //vars = new String[] { "x", "y" };
1292        vars = new String[] { "x", "y", "z" };
1293        fac = new GenPolynomialRing<BigRational>(coeff, vars.length, to, vars);
1294
1295        vars = fac.getVars();
1296        //System.out.println("vars = " + Arrays.toString(vars));
1297        //System.out.println("fac = " + fac);
1298        assertTrue("vars.length == 3 ", vars.length == 3);
1299
1300        Ideal<BigRational> I;
1301        L = new ArrayList<GenPolynomial<BigRational>>();
1302
1303        a = fac.parse("( x^3 + 3 )");
1304        //a = fac.parse("( x^3 - 3 )");
1305        //a = fac.parse("( x^2 + 3 )");
1306        b = fac.parse("( y^2 - x )");
1307        //b = fac.parse("( y^2 + x )");
1308        //b = fac.parse("( y^2 + 4 )");
1309        c = fac.parse("( z^2 - x y )");
1310
1311        if (a.isZERO() || b.isZERO()) {
1312            return;
1313        }
1314
1315        L.add(a);
1316        L.add(b);
1317        L.add(c);
1318        I = new Ideal<BigRational>(fac, L);
1319        //I.doGB();
1320        assertTrue("not isZERO( I )", !I.isZERO());
1321        assertTrue("isGB( I )", I.isGB());
1322        //System.out.println("I = " + I);
1323
1324        List<IdealWithUniv<BigRational>> zd = I.zeroDimRootDecomposition();
1325        //System.out.println("zd = " + zd);
1326        assertTrue("is decomposition ", I.isZeroDimDecomposition(zd));
1327
1328        BigRational eps = new BigRational(1, 1000000);
1329        //eps = eps.multiply(eps);
1330        eps = eps.multiply(eps).multiply(eps);
1331        BigDecimal e = new BigDecimal(eps.getRational());
1332        e = e.abs(); //.multiply(e);
1333
1334        List<IdealWithComplexAlgebraicRoots<BigRational>> roots = PolyUtilApp
1335                        .<BigRational> complexAlgebraicRoots(zd); //, eps);
1336        //System.out.println("roots = " + roots + "\n");
1337
1338        ComplexRing<BigDecimal> dcc = new ComplexRing<BigDecimal>(e);
1339
1340        int d = 0;
1341        int s = 0;
1342        for (IdealWithComplexAlgebraicRoots<BigRational> Ic : roots) {
1343            List<GenPolynomial<BigRational>> L = Ic.ideal.getList();
1344            List<GenPolynomial<Complex<BigDecimal>>> Ld = new ArrayList<GenPolynomial<Complex<BigDecimal>>>(
1345                            L.size());
1346            s += Ic.can.size();
1347
1348            GenPolynomialRing<BigDecimal> dfac = new GenPolynomialRing<BigDecimal>(e, Ic.ideal.list.ring);
1349            //System.out.println("dfac = " + dfac);
1350            GenPolynomialRing<Complex<BigDecimal>> dcfac;
1351            dcfac = new GenPolynomialRing<Complex<BigDecimal>>(dcc, dfac);
1352            //System.out.println("dcfac = " + dcfac);
1353            int ds = 1;
1354            for (GenPolynomial<BigRational> p : L) {
1355                long dl = p.leadingExpVector().totalDeg();
1356                ds *= dl;
1357                GenPolynomial<BigDecimal> dp = PolyUtil.<BigRational> decimalFromRational(dfac, p);
1358                GenPolynomial<Complex<BigDecimal>> dpc = PolyUtil.<BigDecimal> toComplex(dcfac, dp);
1359                //System.out.println("p   = " + p);
1360                //System.out.println("dpc = " + dpc);
1361                Ld.add(dpc);
1362            }
1363            d += ds;
1364            assertTrue("#L == #Ld: ", L.size() == Ld.size());
1365            @SuppressWarnings("unused")
1366            List<List<Complex<BigDecimal>>> droot = Ic.decimalApproximation();
1367            //for (List<Complex<BigDecimal>> dr : droot) {
1368            //System.out.println("dr = " + dr); // TODO
1369            //}
1370            assertTrue("#droot == ds: ", droot.size() == ds);
1371        }
1372        logger.info("#roots = " + s + ", #vr-dim = " + d);
1373        assertTrue("#roots(" + s + ") == degree(" + d + "): ", s == d);
1374    }
1375
1376
1377    /**
1378     * Test normal position.
1379     */
1380    public void testNormalPosition() {
1381        String[] vars;
1382
1383        BigRational coeff = new BigRational(17, 1);
1384        to = new TermOrder(TermOrder.INVLEX);
1385        vars = new String[] { "x", "y", "z" };
1386        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1387
1388        vars = fac.getVars();
1389        //System.out.println("vars = " + Arrays.toString(vars));
1390        //System.out.println("fac = " + fac);
1391        assertTrue("vars.length == 3 ", vars.length == 3);
1392
1393        Ideal<BigRational> I;
1394        L = new ArrayList<GenPolynomial<BigRational>>();
1395
1396        a = fac.parse("( x^3 - 27 )");
1397        b = fac.parse("( y^3 - x )");
1398        c = fac.parse("( z^2 - x^2 )");
1399
1400        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1401            return;
1402        }
1403
1404        L.add(a);
1405        L.add(b);
1406        L.add(c);
1407        I = new Ideal<BigRational>(fac, L);
1408        I.doGB();
1409        assertTrue("not isZERO( I )", !I.isZERO());
1410        assertTrue("isGB( I )", I.isGB());
1411        //System.out.println("I = " + I);
1412
1413        int[] np = I.normalPositionIndex2Vars();
1414        //System.out.println("np = " + np);
1415        if (np == null) {
1416            np = I.normalPositionIndexUnivars();
1417            //System.out.println("np = " + np);
1418        }
1419        if (np == null) {
1420            return;
1421        }
1422        int i = np[0];
1423        int j = np[1];
1424        IdealWithUniv<BigRational> Ip = I.normalPositionFor(i, j, null);
1425        //System.out.println("Ip = " + Ip);
1426
1427        boolean t = Ip.ideal.isNormalPositionFor(i + 1, j + 1); // sic
1428        //System.out.println("t = " + t);
1429        assertTrue("is normal position ", t);
1430
1431        np = Ip.ideal.normalPositionIndex2Vars();
1432        //System.out.println("np = " + np);
1433        if (np == null) {
1434            np = Ip.ideal.normalPositionIndexUnivars();
1435            //System.out.println("np = " + Arrays.toString(np));
1436        }
1437        if (np == null) {
1438            return;
1439        }
1440        i = np[0];
1441        j = np[1];
1442        assertTrue("i == 0: " + i, i == 0);
1443        assertTrue("j == 2: " + j, j == 2); // fixed, was 3
1444    }
1445
1446
1447    /**
1448     * Test 0-dim root decomposition.
1449     */
1450    public void testRootDecomposition() {
1451        String[] vars;
1452
1453        BigRational coeff = new BigRational(17, 1);
1454        to = new TermOrder(TermOrder.INVLEX);
1455        vars = new String[] { "x", "y", "z" };
1456        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1457
1458        vars = fac.getVars();
1459        //System.out.println("vars = " + Arrays.toString(vars));
1460        //System.out.println("fac = " + fac);
1461        assertTrue("vars.length == 3 ", vars.length == 3);
1462
1463        Ideal<BigRational> I;
1464        L = new ArrayList<GenPolynomial<BigRational>>();
1465
1466        a = fac.parse("( x^2 - 7 )");
1467        b = fac.parse("( y^2 - 5 )");
1468        c = fac.parse("( z^3 - x * y )");
1469
1470        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1471            return;
1472        }
1473
1474        L.add(a);
1475        L.add(b);
1476        L.add(c);
1477        I = new Ideal<BigRational>(fac, L);
1478        I.doGB();
1479        assertTrue("not isZERO( I )", !I.isZERO());
1480        assertTrue("isGB( I )", I.isGB());
1481        //System.out.println("I = " + I);
1482
1483        List<IdealWithUniv<BigRational>> rzd = I.zeroDimRootDecomposition();
1484        //System.out.println("rzd = " + rzd);
1485
1486        assertTrue("is contained in intersection ", I.isZeroDimDecomposition(rzd));
1487    }
1488
1489
1490    /**
1491     * Test 0-dim prime decomposition.
1492     */
1493    public void testPrimeDecomposition() {
1494        String[] vars;
1495
1496        BigRational coeff = new BigRational(17, 1);
1497        to = new TermOrder(TermOrder.INVLEX);
1498        vars = new String[] { "x", "y", "z" };
1499        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1500
1501        vars = fac.getVars();
1502        //System.out.println("vars = " + Arrays.toString(vars));
1503        //System.out.println("fac = " + fac);
1504        assertTrue("vars.length == 3 ", vars.length == 3);
1505
1506        Ideal<BigRational> I;
1507        L = new ArrayList<GenPolynomial<BigRational>>();
1508
1509        a = fac.parse("( x^2 - 5 )^2 ");
1510        b = fac.parse("( y^2 - 5 )");
1511        c = fac.parse("( z^3 - x )");
1512
1513        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1514            return;
1515        }
1516
1517        L.add(a);
1518        L.add(b);
1519        L.add(c);
1520        I = new Ideal<BigRational>(fac, L);
1521        I.doGB();
1522        assertTrue("not isZERO( I )", !I.isZERO());
1523        assertTrue("isGB( I )", I.isGB());
1524        //System.out.println("I = " + I);
1525
1526        List<IdealWithUniv<BigRational>> pzd = I.zeroDimPrimeDecomposition();
1527        //System.out.println("pzd = " + pzd);
1528        //System.out.println("I   = " + I);
1529
1530        assertTrue("is contained in intersection ", I.isZeroDimDecomposition(pzd));
1531    }
1532
1533
1534    /**
1535     * Test 0-dim primary decomposition.
1536     */
1537    public void testPrimaryDecomposition() {
1538        String[] vars;
1539
1540        BigRational coeff = new BigRational(17, 1);
1541        to = new TermOrder(TermOrder.INVLEX);
1542        vars = new String[] { "x", "y", "z" };
1543        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1544
1545        vars = fac.getVars();
1546        //System.out.println("vars = " + Arrays.toString(vars));
1547        //System.out.println("fac = " + fac);
1548        assertTrue("vars.length == 3 ", vars.length == 3);
1549
1550        Ideal<BigRational> I;
1551        L = new ArrayList<GenPolynomial<BigRational>>();
1552
1553        a = fac.parse("( x^2 - 5 )^2 ");
1554        b = fac.parse("( y^2 - 5 )");
1555        c = fac.parse("( z^3 - x )");
1556
1557        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1558            return;
1559        }
1560
1561        L.add(a);
1562        L.add(b);
1563        L.add(c);
1564        I = new Ideal<BigRational>(fac, L);
1565        I.doGB();
1566        assertTrue("not isZERO( I )", !I.isZERO());
1567        assertTrue("isGB( I )", I.isGB());
1568        //System.out.println("I = " + I);
1569
1570        List<PrimaryComponent<BigRational>> qzd = I.zeroDimPrimaryDecomposition();
1571        //System.out.println("qzd = " + qzd);
1572        //System.out.println("I   = " + I);
1573
1574        assertTrue("is intersection ", I.isPrimaryDecomposition(qzd));
1575    }
1576
1577
1578    /**
1579     * Test 0-dim root decomposition and real roots.
1580     */
1581    public void testRootDecompositionReal() {
1582        String[] vars;
1583
1584        BigRational coeff = new BigRational(17, 1);
1585        to = new TermOrder(TermOrder.INVLEX);
1586        vars = new String[] { "x", "y", "z" };
1587        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1588
1589        vars = fac.getVars();
1590        //System.out.println("vars = " + Arrays.toString(vars));
1591        //System.out.println("fac = " + fac);
1592        assertTrue("vars.length == 3 ", vars.length == 3);
1593
1594        Ideal<BigRational> I;
1595        L = new ArrayList<GenPolynomial<BigRational>>();
1596
1597        a = fac.parse("( x^2 - 5 )");
1598        b = fac.parse("( y^2 - 7 )");
1599        c = fac.parse("( z^3 - x * y )");
1600
1601        if (a.isZERO() || b.isZERO() || c.isZERO()) {
1602            return;
1603        }
1604
1605        L.add(a);
1606        L.add(b);
1607        L.add(c);
1608        I = new Ideal<BigRational>(fac, L);
1609        I.doGB();
1610        assertTrue("not isZERO( I )", !I.isZERO());
1611        assertTrue("isGB( I )", I.isGB());
1612        //System.out.println("I = " + I);
1613
1614        List<IdealWithRealAlgebraicRoots<BigRational>> iur;
1615        iur = PolyUtilApp.<BigRational> realAlgebraicRoots(I);
1616
1617        List<IdealWithUniv<BigRational>> iul = new ArrayList<IdealWithUniv<BigRational>>();
1618        for (IdealWithRealAlgebraicRoots<BigRational> iu : iur) {
1619            iul.add(iu);
1620        }
1621        assertTrue("is contained in intersection ", I.isZeroDimDecomposition(iul));
1622
1623        for (IdealWithRealAlgebraicRoots<BigRational> iu : iur) {
1624            //System.out.println("iu = " + iu);
1625            //System.out.println("");
1626            @SuppressWarnings("unused")
1627            List<List<BigDecimal>> rd = iu.decimalApproximation(); // TODO
1628            //System.out.println("iu = " + iu);
1629            //System.out.println("");
1630        }
1631    }
1632
1633
1634    /**
1635     * Test extension-contraction.
1636     */
1637    public void testExtCont() {
1638        String[] vars;
1639
1640        BigRational coeff = new BigRational(17, 1);
1641        to = new TermOrder(); //TermOrder.INVLEX);
1642        vars = new String[] { "x", "y", "z" };
1643        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1644
1645        vars = fac.getVars();
1646        //System.out.println("vars = " + Arrays.toString(vars));
1647        //System.out.println("fac = " + fac);
1648        assertTrue("vars.length == 3 ", vars.length == 3);
1649
1650        Ideal<BigRational> I;
1651        L = new ArrayList<GenPolynomial<BigRational>>();
1652
1653        //a = fac.parse("( y^2 - 5 ) x ");
1654        //b = fac.parse("( y^2 - 5 ) x ");
1655        //c = fac.parse("( x z^3 - 3 )");
1656
1657        //a = fac.parse("( x^2 + 2 x y z + z^4 ) ");
1658        //b = fac.parse("( y z - z^2 ) ");
1659        //c = fac.parse("0");
1660
1661        a = fac.parse("( y + x y^2 ) ");
1662        b = fac.parse("( x z + x^2 y ) ");
1663        //c = fac.parse("0");
1664
1665        if (a.isZERO() || b.isZERO()) {
1666            return;
1667        }
1668
1669        L.add(a);
1670        L.add(b);
1671        //L.add(c);
1672        I = new Ideal<BigRational>(fac, L);
1673        I.doGB();
1674        assertTrue("not isZERO( I )", !I.isZERO());
1675        assertTrue("isGB( I )", I.isGB());
1676        //System.out.println("I = " + I);
1677
1678        IdealWithUniv<Quotient<BigRational>> Ext = I.extension(new String[] { "x" });
1679        //Ideal<Quotient<BigRational>> Ext = I.extension( new String[] { "y", "z" } );
1680        //System.out.println("Ext = " + Ext);
1681        //System.out.println("I   = " + I);
1682
1683        IdealWithUniv<BigRational> Con = I.permContraction(Ext);
1684        //System.out.println("Con = " + Con);
1685        //System.out.println("I   = " + I);
1686
1687        assertTrue("I subseteq Con(Ext(I)) ", Con.ideal.contains(I));
1688    }
1689
1690
1691    /**
1692     * Test prime ideal decomposition.
1693     */
1694    public void testPrimeDecomp() {
1695        String[] vars;
1696
1697        BigRational coeff = new BigRational(17, 1);
1698        to = new TermOrder(TermOrder.INVLEX);
1699        vars = new String[] { "x", "y", "z" };
1700        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1701
1702        vars = fac.getVars();
1703        //System.out.println("vars = " + Arrays.toString(vars));
1704        //System.out.println("fac = " + fac);
1705        assertTrue("vars.length == 3 ", vars.length == 3);
1706
1707        Ideal<BigRational> I;
1708        L = new ArrayList<GenPolynomial<BigRational>>();
1709
1710        //a = fac.parse("( y^2 - 5 ) x ");
1711        //b = fac.parse("( y^2 - 5 ) x ");
1712        //c = fac.parse("( x z^3 - 3 )");
1713
1714        //a = fac.parse("( x^2 + 2 x y z + z^4 ) ");
1715        //b = fac.parse("( y z - z^2 ) ");
1716
1717        //a = fac.parse("( y + x y^2 ) ");
1718        //b = fac.parse("( x z + x^2 y ) ");
1719
1720        a = fac.parse("( z^2 - x ) ");
1721        b = fac.parse("( y^2 - x ) ");
1722
1723        //a = fac.parse("( x y ) ");
1724        //b = fac.parse("( x z ) ");
1725
1726        if (a.isZERO() || b.isZERO()) {
1727            return;
1728        }
1729
1730        L.add(a);
1731        L.add(b);
1732        //L.add(c);
1733        I = new Ideal<BigRational>(fac, L);
1734        I.doGB();
1735        assertTrue("not isZERO( I )", !I.isZERO());
1736        assertTrue("isGB( I )", I.isGB());
1737        //System.out.println("I = " + I);
1738
1739        List<IdealWithUniv<BigRational>> pdec = I.primeDecomposition();
1740        //System.out.println("pdec = " + pdec);
1741        //System.out.println("I    = " + I);
1742
1743        assertTrue("I subseteq cup G_i ", I.isDecomposition(pdec));
1744
1745        List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(pdec.size());
1746        for (IdealWithUniv<BigRational> pu : pdec) {
1747            dec.add(pu.ideal);
1748        }
1749        Ideal<BigRational> Ii = I.intersect(dec);
1750        //System.out.println("Ii   = " + Ii);
1751        //System.out.println("I    = " + I);
1752
1753        // not always:
1754        assertTrue("I == Ii ", I.equals(Ii));
1755    }
1756
1757
1758    /**
1759     * Test radical ideal decomposition.
1760     */
1761    public void testRadicalDecomp() {
1762        String[] vars;
1763
1764        BigRational coeff = new BigRational(17, 1);
1765        to = new TermOrder(TermOrder.INVLEX);
1766        vars = new String[] { "x", "y", "z" };
1767        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1768
1769        vars = fac.getVars();
1770        //System.out.println("vars = " + Arrays.toString(vars));
1771        //System.out.println("fac = " + fac);
1772        assertTrue("vars.length == 3 ", vars.length == 3);
1773
1774        Ideal<BigRational> I;
1775        L = new ArrayList<GenPolynomial<BigRational>>();
1776
1777        //a = fac.parse("( y^2 - 5 ) x ");
1778        //b = fac.parse("( y^2 - 5 ) x ");
1779        //c = fac.parse("( x z^3 - 3 )");
1780
1781        a = fac.parse("( x^2 + 2 x y z + z^4 ) ");
1782        b = fac.parse("( y z - z^2 ) ");
1783
1784        //a = fac.parse("( y + x y^2 ) ");
1785        //b = fac.parse("( x z + x^2 y ) ");
1786
1787        //a = fac.parse("( z^2 - x )^2 ");
1788        //b = fac.parse("( y^2 - x ) ");
1789
1790        //a = fac.parse("( x^2 y^3 ) ");
1791        //b = fac.parse("( x^2 z^5 ) ");
1792
1793        if (a.isZERO() || b.isZERO()) {
1794            return;
1795        }
1796
1797        L.add(a);
1798        L.add(b);
1799        //L.add(c);
1800        I = new Ideal<BigRational>(fac, L);
1801        I.doGB();
1802        assertTrue("not isZERO( I )", !I.isZERO());
1803        assertTrue("isGB( I )", I.isGB());
1804        //System.out.println("I = " + I);
1805
1806        List<IdealWithUniv<BigRational>> rdec = I.radicalDecomposition();
1807        //System.out.println("rdec = " + rdec);
1808        //System.out.println("I    = " + I);
1809
1810        assertTrue("I subseteq cup G_i ", I.isDecomposition(rdec));
1811
1812        List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(rdec.size());
1813        for (IdealWithUniv<BigRational> ru : rdec) {
1814            dec.add(ru.ideal);
1815        }
1816        Ideal<BigRational> Ii = I.intersect(dec);
1817        //System.out.println("Ii   = " + Ii);
1818        //System.out.println("I    = " + I);
1819
1820        assertTrue("Ii.contains(I) ", Ii.contains(I));
1821
1822        //Ii = I.radical();
1823        //System.out.println("Ii   = " + Ii);
1824        //System.out.println("I    = " + I);
1825        //assertTrue("Ii.contains(I) ", Ii.contains(I));
1826    }
1827
1828
1829    /**
1830     * Test ideal decomposition.
1831     */
1832    public void testIrredDecomp() {
1833        String[] vars;
1834
1835        BigRational coeff = new BigRational(17, 1);
1836        to = new TermOrder(TermOrder.INVLEX);
1837        vars = new String[] { "x", "y", "z" };
1838        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1839
1840        vars = fac.getVars();
1841        //System.out.println("vars = " + Arrays.toString(vars));
1842        //System.out.println("fac = " + fac);
1843        assertTrue("vars.length == 3 ", vars.length == 3);
1844
1845        Ideal<BigRational> I;
1846        L = new ArrayList<GenPolynomial<BigRational>>();
1847
1848        //a = fac.parse("( y^2 - 5 ) x ");
1849        //b = fac.parse("( y^2 - 5 ) x ");
1850        //c = fac.parse("( x z^3 - 3 )");
1851
1852        a = fac.parse("( x^2 + 2 x y z + z^4 ) ");
1853        b = fac.parse("( y z - z^2 ) ");
1854
1855        //a = fac.parse("( y + x y^2 ) ");
1856        //b = fac.parse("( x z + x^2 y ) ");
1857
1858        //a = fac.parse("( z^2 - x )^2 ");
1859        //b = fac.parse("( y^2 - x ) ");
1860
1861        //a = fac.parse("( x^2 y^3 ) ");
1862        //b = fac.parse("( x^2 z^5 ) ");
1863
1864        if (a.isZERO() || b.isZERO()) {
1865            return;
1866        }
1867
1868        L.add(a);
1869        L.add(b);
1870        //L.add(c);
1871        I = new Ideal<BigRational>(fac, L);
1872        I.doGB();
1873        assertTrue("not isZERO( I )", !I.isZERO());
1874        assertTrue("isGB( I )", I.isGB());
1875        //System.out.println("I = " + I);
1876
1877        List<IdealWithUniv<BigRational>> rdec = I.decomposition();
1878        //System.out.println("rdec = " + rdec);
1879        //System.out.println("I    = " + I);
1880
1881        assertTrue("I subseteq cup G_i ", I.isDecomposition(rdec));
1882
1883        List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(rdec.size());
1884        for (IdealWithUniv<BigRational> ru : rdec) {
1885            dec.add(ru.ideal);
1886        }
1887        Ideal<BigRational> Ii = I.intersect(dec);
1888        //System.out.println("Ii   = " + Ii);
1889        //System.out.println("I    = " + I);
1890
1891        assertTrue("Ii.contains(I) ", Ii.contains(I));
1892
1893        //Ii = I.radical();
1894        //System.out.println("Ii   = " + Ii);
1895        //System.out.println("I    = " + I);
1896        //assertTrue("Ii.contains(I) ", Ii.contains(I));
1897    }
1898
1899
1900    /**
1901     * Test primary ideal decomposition.
1902     */
1903    public void testPrimaryDecomp() {
1904        String[] vars;
1905
1906        BigRational coeff = new BigRational(17, 1);
1907        to = new TermOrder(TermOrder.INVLEX);
1908        vars = new String[] { "x", "y", "z" };
1909        fac = new GenPolynomialRing<BigRational>(coeff, rl, to, vars);
1910
1911        vars = fac.getVars();
1912        //System.out.println("vars = " + Arrays.toString(vars));
1913        //System.out.println("fac = " + fac);
1914        assertTrue("vars.length == 3 ", vars.length == 3);
1915
1916        Ideal<BigRational> I;
1917        L = new ArrayList<GenPolynomial<BigRational>>();
1918
1919        //a = fac.parse("( y^2 - 5 ) x ");
1920        //b = fac.parse("( y^2 - 5 ) x ");
1921        //c = fac.parse("( x z^3 - 3 )");
1922
1923        //a = fac.parse("( x^2 + 2 x y z + z^4 ) ");
1924        //b = fac.parse("( y z - z^2 ) ");
1925
1926        //a = fac.parse("( y + x y^2 ) ");
1927        //b = fac.parse("( x z + x^2 y ) ");
1928
1929        a = fac.parse("( x z^2 - 1 )^2 ");
1930        b = fac.parse("( y^2 - x ) ");
1931
1932        //a = fac.parse("( x^2 y ) ");
1933        //b = fac.parse("( x z^3 ) ");
1934
1935        if (a.isZERO() || b.isZERO()) {
1936            return;
1937        }
1938
1939        L.add(a);
1940        L.add(b);
1941        //L.add(c);
1942        I = new Ideal<BigRational>(fac, L);
1943        I.doGB();
1944        assertTrue("not isZERO( I )", !I.isZERO());
1945        assertTrue("isGB( I )", I.isGB());
1946        //System.out.println("I = " + I);
1947
1948        List<PrimaryComponent<BigRational>> qdec = I.primaryDecomposition();
1949        //System.out.println("qdec = " + qdec);
1950        //System.out.println("I    = " + I);
1951
1952        List<Ideal<BigRational>> dec = new ArrayList<Ideal<BigRational>>(qdec.size());
1953        for (PrimaryComponent<BigRational> ru : qdec) {
1954            dec.add(ru.primary);
1955        }
1956        assertTrue("#qdec == #dec: ", qdec.size() == dec.size());
1957        assertTrue("I eq cup G_i ", I.isPrimaryDecomposition(qdec));
1958    }
1959
1960
1961    /**
1962     * Test Ideal annihilator.
1963     */
1964    public void testAnnihilator() {
1965        Ideal<BigRational> I, J, K;
1966        do {
1967            a = fac.random(kl, ll, el, q);
1968        } while (a.isZERO() || a.isConstant());
1969        b = fac.univariate(1);
1970        c = fac.univariate(rl - 1);
1971        //b = fac.random(kl - 1, ll, el, q);
1972        //c = fac.random(kl - 1, ll - 1, el, q / 2);
1973
1974        L = new ArrayList<GenPolynomial<BigRational>>();
1975        L.add(a);
1976        L.add(b);
1977        //System.out.println("L = " + L);
1978        L = bb.GB(L);
1979        I = new Ideal<BigRational>(fac, L, true);
1980        assertTrue("isGB( I )", I.isGB());
1981        //System.out.println("I = " + I + "\n");
1982
1983        J = I.annihilator(c);
1984        //System.out.println("J = " + J + "\n");
1985        J.doGB();
1986        //System.out.println("c = " + c);
1987        //System.out.println("J = " + J + "\n");
1988        assertTrue("isAnnihilator(c,J)", I.isAnnihilator(c, J));
1989
1990        d = fac.univariate(rl - 2);
1991        //d = fac.random(kl - 1, ll, el, q);
1992        M = new ArrayList<GenPolynomial<BigRational>>();
1993        M.add(c);
1994        M.add(d);
1995        //System.out.println("M = " + M);
1996        K = new Ideal<BigRational>(fac, M);
1997        //System.out.println("K = " + K + "\n");
1998
1999        J = I.annihilator(K);
2000        //System.out.println("J = " + J + "\n");
2001        J.doGB();
2002        //System.out.println("K = " + K);
2003        //System.out.println("J = " + J + "\n");
2004        assertTrue("isAnnihilator(M,J)", I.isAnnihilator(K, J));
2005    }
2006
2007}