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