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