001/*
002 * $Id: GroebnerBaseSeqPairSeqTest.java 4010 2012-07-21 20:39:56Z kredel $
003 */
004
005package edu.jas.gb;
006
007
008import java.util.List;
009import java.util.ArrayList;
010import java.io.IOException;
011import java.io.Reader;
012import java.io.StringReader;
013
014import junit.framework.Test;
015import junit.framework.TestCase;
016import junit.framework.TestSuite;
017
018import org.apache.log4j.BasicConfigurator;
019//import org.apache.log4j.Logger;
020
021import edu.jas.arith.BigRational;
022import edu.jas.gb.ExtendedGB;
023import edu.jas.gb.GroebnerBase;
024import edu.jas.gb.GroebnerBaseSeqPairSeq;
025import edu.jas.poly.GenPolynomial;
026import edu.jas.poly.GenPolynomialRing;
027import edu.jas.poly.GenPolynomialTokenizer;
028import edu.jas.poly.PolynomialList;
029
030
031
032
033/**
034 * Groebner base sequential, sequential pair list, tests with JUnit.
035 * @author Heinz Kredel.
036 */
037
038public class GroebnerBaseSeqPairSeqTest extends TestCase {
039
040    //private static final Logger logger = Logger.getLogger(GroebnerBaseSeqPairSeqTest.class);
041
042/**
043 * main
044 */
045   public static void main (String[] args) {
046          BasicConfigurator.configure();
047          junit.textui.TestRunner.run( suite() );
048   }
049
050/**
051 * Constructs a <CODE>GroebnerBaseSeqPairSeqTest</CODE> object.
052 * @param name String.
053 */
054   public GroebnerBaseSeqPairSeqTest(String name) {
055          super(name);
056   }
057
058/**
059 * suite.
060 */ 
061 public static Test suite() {
062     TestSuite suite= new TestSuite(GroebnerBaseSeqPairSeqTest.class);
063     return suite;
064   }
065
066   GenPolynomialRing<BigRational> fac;
067
068   List<GenPolynomial<BigRational>> L;
069   PolynomialList<BigRational> F;
070   List<GenPolynomial<BigRational>> G;
071
072   GroebnerBase<BigRational> bb; // do interface
073
074   GenPolynomial<BigRational> a;
075   GenPolynomial<BigRational> b;
076   GenPolynomial<BigRational> c;
077   GenPolynomial<BigRational> d;
078   GenPolynomial<BigRational> e;
079
080   int rl = 3; //4; //3; 
081   int kl = 2; // 10;
082   int ll = 5; //7;
083   int el = 3;
084   float q = 0.3f; //0.2f; //0.4f
085
086   protected void setUp() {
087       BigRational coeff = new BigRational(9);
088       fac = new GenPolynomialRing<BigRational>(coeff,rl);
089       a = b = c = d = e = null;
090       bb = new GroebnerBaseSeqPairSeq<BigRational>();
091   }
092
093   protected void tearDown() {
094       a = b = c = d = e = null;
095       fac = null;
096       bb = null;
097   }
098
099
100/**
101 * Test sequential GBase.
102 * 
103 */
104 public void testSeqPairSequentialGBase() {
105
106     L = new ArrayList<GenPolynomial<BigRational>>();
107
108     a = fac.random(kl, ll, el, q );
109     b = fac.random(kl, ll, el, q );
110     c = fac.random(kl, ll, el, q );
111     d = fac.random(kl, ll, el, q );
112     e = d; //fac.random(kl, ll, el, q );
113
114     if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) {
115        return;
116     }
117
118     assertTrue("not isZERO( a )", !a.isZERO() );
119     L.add(a);
120
121     L = bb.GB( L );
122     assertTrue("isGB( { a } )", bb.isGB(L) );
123
124     assertTrue("not isZERO( b )", !b.isZERO() );
125     L.add(b);
126     //System.out.println("L = " + L.size() );
127
128     L = bb.GB( L );
129     assertTrue("isGB( { a, b } )", bb.isGB(L) );
130
131     assertTrue("not isZERO( c )", !c.isZERO() );
132     L.add(c);
133
134     L = bb.GB( L );
135     assertTrue("isGB( { a, b, c } )", bb.isGB(L) );
136
137     assertTrue("not isZERO( d )", !d.isZERO() );
138     L.add(d);
139
140     L = bb.GB( L );
141     assertTrue("isGB( { a, b, c, d } )", bb.isGB(L) );
142
143     assertTrue("not isZERO( e )", !e.isZERO() );
144     L.add(e);
145
146     L = bb.GB( L );
147     assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(L) );
148 }
149
150
151/**
152 * Test Trinks7 GBase.
153 * 
154 */
155 @SuppressWarnings("unchecked") // not jet working
156 public void testTrinks7GBase() {
157     String exam = "(B,S,T,Z,P,W) L "
158                 + "( "  
159                 + "( 45 P + 35 S - 165 B - 36 ), " 
160                 + "( 35 P + 40 Z + 25 T - 27 S ), "
161                 + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), "
162                 + "( - 9 W + 15 T P + 20 S Z ), "
163                 + "( P W + 2 T Z - 11 B**3 ), "
164                 + "( 99 W - 11 B S + 3 B**2 ), "
165                 + "( B**2 + 33/50 B + 2673/10000 ) "
166                 + ") ";
167     Reader source = new StringReader( exam );
168     GenPolynomialTokenizer parser
169                  = new GenPolynomialTokenizer( source );
170     try {
171         F = (PolynomialList<BigRational>) parser.nextPolynomialSet();
172     } catch(ClassCastException e) {
173         fail(""+e);
174     } catch(IOException e) {
175         fail(""+e);
176     }
177     //System.out.println("F = " + F);
178
179     G = bb.GB(F.list);
180     assertTrue("isGB( GB(Trinks7) )", bb.isGB(G) );
181     assertEquals("#GB(Trinks7) == 6", 6, G.size() );
182     //PolynomialList<BigRational> trinks = new PolynomialList<BigRational>(F.ring,G);
183     //System.out.println("G = " + trinks);
184
185 }
186
187
188/**
189 * Test sequential extended GBase.
190 * 
191 */
192 public void testSeqPairSequentialExtendedGBase() {
193
194     L = new ArrayList<GenPolynomial<BigRational>>();
195
196     ExtendedGB<BigRational> exgb;
197
198     a = fac.random(kl, ll, el, q );
199     b = fac.random(kl, ll, el, q );
200     c = fac.random(kl, ll, el, q );
201     d = fac.random(kl, ll, el, q );
202     e = d; //fac.random(kl, ll, el, q );
203
204     if ( a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO() ) {
205        return;
206     }
207
208     assertTrue("not isZERO( a )", !a.isZERO() );
209     L.add(a);
210     //System.out.println("L = " + L );
211
212     exgb = bb.extGB( L );
213     // System.out.println("exgb = " + exgb );
214     assertTrue("isGB( { a } )", bb.isGB(exgb.G) );
215     assertTrue("isRmat( { a } )", bb.isReductionMatrix(exgb) );
216
217     assertTrue("not isZERO( b )", !b.isZERO() );
218     L.add(b);
219     //System.out.println("L = " + L );
220
221     exgb = bb.extGB( L );
222     //System.out.println("exgb = " + exgb );
223     assertTrue("isGB( { a, b } )", bb.isGB(exgb.G) );
224     assertTrue("isRmat( { a, b } )", bb.isReductionMatrix(exgb) );
225
226     assertTrue("not isZERO( c )", !c.isZERO() );
227     L.add(c);
228
229     exgb = bb.extGB( L );
230     //System.out.println("exgb = " + exgb );
231     assertTrue("isGB( { a, b, c } )", bb.isGB(exgb.G) );
232     assertTrue("isRmat( { a, b, c } )", bb.isReductionMatrix(exgb) );
233
234     assertTrue("not isZERO( d )", !d.isZERO() );
235     L.add(d);
236
237     exgb = bb.extGB( L );
238     //System.out.println("exgb = " + exgb );
239     assertTrue("isGB( { a, b, c, d } )", bb.isGB(exgb.G) );
240     assertTrue("isRmat( { a, b, c, d } )", bb.isReductionMatrix(exgb) );
241
242
243     assertTrue("not isZERO( e )", !e.isZERO() );
244     L.add(e);
245
246     exgb = bb.extGB( L );
247     //System.out.println("exgb = " + exgb );
248     assertTrue("isGB( { a, b, c, d, e } )", bb.isGB(exgb.G) );
249     assertTrue("isRmat( { a, b, c, d, e } )", bb.isReductionMatrix(exgb) );
250 }
251
252
253/**
254 * Test Trinks7 GBase.
255 * 
256 */
257 @SuppressWarnings("unchecked") // not jet working
258 public void testTrinks7ExtendedGBase() {
259     String exam = "(B,S,T,Z,P,W) L "
260                 + "( "  
261                 + "( 45 P + 35 S - 165 B - 36 ), " 
262                 + "( 35 P + 40 Z + 25 T - 27 S ), "
263                 + "( 15 W + 25 S P + 30 Z - 18 T - 165 B**2 ), "
264                 + "( - 9 W + 15 T P + 20 S Z ), "
265                 + "( P W + 2 T Z - 11 B**3 ), "
266                 + "( 99 W - 11 B S + 3 B**2 ), "
267                 + "( B**2 + 33/50 B + 2673/10000 ) "
268                 + ") ";
269     Reader source = new StringReader( exam );
270     GenPolynomialTokenizer parser
271                  = new GenPolynomialTokenizer( source );
272     try {
273         F = (PolynomialList<BigRational>) parser.nextPolynomialSet();
274     } catch(ClassCastException e) {
275         fail(""+e);
276     } catch(IOException e) {
277         fail(""+e);
278     }
279     //System.out.println("F = " + F);
280
281
282     ExtendedGB<BigRational> exgb;
283     
284     exgb = bb.extGB(F.list);
285     //System.out.println("exgb = " + exgb );
286     assertTrue("isGB( GB(Trinks7) )", bb.isGB(exgb.G) );
287     //assertEquals("#GB(Trinks7) == 6", 6, exgb.G.size() );
288     assertTrue("isRmat( GB(Trinks7) )", bb.isReductionMatrix(exgb) );
289     //PolynomialList<BigRational> trinks = new PolynomialList<BigRational>(F.ring,G);
290     //System.out.println("G = " + trinks);
291
292 }
293
294}