001/*
002 * $Id: CGBSeqTest.java 5042 2014-12-29 12:32:59Z kredel $
003 */
004
005package edu.jas.application;
006
007
008import java.io.IOException;
009import java.io.Reader;
010import java.io.StringReader;
011import java.util.ArrayList;
012import java.util.List;
013
014import junit.framework.Test;
015import junit.framework.TestCase;
016import junit.framework.TestSuite;
017
018import org.apache.log4j.BasicConfigurator;
019
020import edu.jas.arith.BigRational;
021import edu.jas.kern.ComputerThreads;
022import edu.jas.poly.GenPolynomial;
023import edu.jas.poly.GenPolynomialRing;
024import edu.jas.poly.GenPolynomialTokenizer;
025import edu.jas.poly.PolynomialList;
026
027
028/**
029 * Comprehenssive Groebner base sequential tests with JUnit.
030 * @author Heinz Kredel.
031 */
032
033public class CGBSeqTest extends TestCase {
034
035
036    //private static final Logger logger = Logger.getLogger(CGBSeqTest.class);
037
038    /**
039     * main
040     */
041    public static void main(String[] args) {
042        BasicConfigurator.configure();
043        junit.textui.TestRunner.run(suite());
044        ComputerThreads.terminate();
045    }
046
047
048    /**
049     * Constructs a <CODE>CGBSeqTest</CODE> object.
050     * @param name String.
051     */
052    public CGBSeqTest(String name) {
053        super(name);
054    }
055
056
057    /**
058     * suite.
059     */
060    public static Test suite() {
061        TestSuite suite = new TestSuite(CGBSeqTest.class);
062        return suite;
063    }
064
065
066    GenPolynomialRing<BigRational> cfac;
067
068
069    GenPolynomialRing<GenPolynomial<BigRational>> fac;
070
071
072    List<GenPolynomial<GenPolynomial<BigRational>>> L;
073
074
075    ComprehensiveGroebnerBaseSeq<BigRational> bb;
076
077
078    GenPolynomial<GenPolynomial<BigRational>> a, b, c, d, e;
079
080
081    int rl = 2; //4; //3; 
082
083
084    int kl = 2;
085
086
087    int ll = 3;
088
089
090    int el = 3;
091
092
093    float q = 0.2f; //0.4f
094
095
096    @Override
097    protected void setUp() {
098        BigRational coeff = new BigRational(kl);
099        String[] cv = { "a" }; //, "b" }; 
100        cfac = new GenPolynomialRing<BigRational>(coeff, 1, cv);
101        String[] v = { "x" }; //, "y" }; 
102        fac = new GenPolynomialRing<GenPolynomial<BigRational>>(cfac, 1, v);
103        a = b = c = d = e = null;
104        bb = new ComprehensiveGroebnerBaseSeq<BigRational>(coeff);
105    }
106
107
108    @Override
109    protected void tearDown() {
110        a = b = c = d = e = null;
111        fac = null;
112        cfac = null;
113        bb = null;
114    }
115
116
117    /*
118     * Dummy test method for jUnit.
119     * 
120    public void testDummy() {
121    }
122     */
123
124
125    /**
126     * Test sequential CGB.
127     * 
128     */
129    public void testSequentialCGB() {
130
131        L = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>();
132
133        a = fac.random(kl, ll, el, q);
134        b = fac.random(kl, ll, el, q);
135        c = a; //fac.random(kl, ll, el, q );
136        d = c; //fac.random(kl, ll, el, q );
137        e = d; //fac.random(kl, ll, el, q );
138
139        if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) {
140            return;
141        }
142
143        assertTrue("not isZERO( a )", !a.isZERO());
144        L.add(a);
145
146        L = bb.GB(L);
147        assertTrue("isGB( { a } )", bb.isGB(L));
148
149        assertTrue("not isZERO( b )", !b.isZERO());
150        L.add(b);
151        //System.out.println("L = " + L.size() );
152
153        L = bb.GB(L);
154        assertTrue("isGB( { a, b } )", bb.isGB(L));
155
156        assertTrue("not isZERO( c )", !c.isZERO());
157        L.add(c);
158
159        L = bb.GB(L);
160        assertTrue("isGB( { a, b, c } )", bb.isGB(L));
161    }
162
163
164    /**
165     * Test Trinks CGB.
166     * 
167     */
168    @SuppressWarnings("cast")
169    public void testTrinks7GBase() {
170        PolynomialList<GenPolynomial<BigRational>> F = null;
171        List<GenPolynomial<GenPolynomial<BigRational>>> G = null;
172        String exam = "IntFunc(b) (S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - { 165 b + 36 } ), "
173                        + "( 35 P + 40 Z + 25 T - 27 S ), "
174                        + "( 15 W + 25 S P + 30 Z - 18 T - { 165 b**2 } ), "
175                        + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - { 11 b**3 } ), "
176                        + "( 99 W - { 11 b } S + { 3 b**2 } ), " + "( { b**2 + 33/50 b + 2673/10000 } ) "
177                        + ") ";
178        Reader source = new StringReader(exam);
179        GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source);
180        try {
181            F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet();
182        } catch (ClassCastException e) {
183            fail("" + e);
184        } catch (IOException e) {
185            fail("" + e);
186        }
187        //System.out.println("F = " + F);
188
189        G = bb.GB(F.list);
190        assertTrue("isGB( GB(Trinks7) )", bb.isGB(G));
191
192        //PolynomialList<GenPolynomial<BigRational>> trinks 
193        //    = new PolynomialList<GenPolynomial<BigRational>>(F.ring,G);
194        //System.out.println("G = " + trinks);
195        //System.out.println("G = " + G);
196    }
197
198}