001/* 002 * $Id: CGBSeqTest.java 5866 2018-07-20 15:02:16Z 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 018 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 037 /** 038 * main 039 */ 040 public static void main(String[] args) { 041 042 junit.textui.TestRunner.run(suite()); 043 ComputerThreads.terminate(); 044 } 045 046 047 /** 048 * Constructs a <CODE>CGBSeqTest</CODE> object. 049 * @param name String. 050 */ 051 public CGBSeqTest(String name) { 052 super(name); 053 } 054 055 056 /** 057 * suite. 058 */ 059 public static Test suite() { 060 TestSuite suite = new TestSuite(CGBSeqTest.class); 061 return suite; 062 } 063 064 065 GenPolynomialRing<BigRational> cfac; 066 067 068 GenPolynomialRing<GenPolynomial<BigRational>> fac; 069 070 071 List<GenPolynomial<GenPolynomial<BigRational>>> L; 072 073 074 ComprehensiveGroebnerBaseSeq<BigRational> bb; 075 076 077 GenPolynomial<GenPolynomial<BigRational>> a, b, c, d, e; 078 079 080 int rl = 2; //4; //3; 081 082 083 int kl = 2; 084 085 086 int ll = 3; 087 088 089 int el = 3; 090 091 092 float q = 0.2f; //0.4f 093 094 095 @Override 096 protected void setUp() { 097 BigRational coeff = new BigRational(kl); 098 String[] cv = { "a" }; //, "b" }; 099 cfac = new GenPolynomialRing<BigRational>(coeff, 1, cv); 100 String[] v = { "x" }; //, "y" }; 101 fac = new GenPolynomialRing<GenPolynomial<BigRational>>(cfac, 1, v); 102 a = b = c = d = e = null; 103 bb = new ComprehensiveGroebnerBaseSeq<BigRational>(coeff); 104 } 105 106 107 @Override 108 protected void tearDown() { 109 a = b = c = d = e = null; 110 fac = null; 111 cfac = null; 112 bb = null; 113 } 114 115 116 /* 117 * Dummy test method for jUnit. 118 * 119 public void testDummy() { 120 } 121 */ 122 123 124 /** 125 * Test sequential CGB. 126 * 127 */ 128 public void testSequentialCGB() { 129 130 L = new ArrayList<GenPolynomial<GenPolynomial<BigRational>>>(); 131 132 a = fac.random(kl, ll, el, q); 133 b = fac.random(kl, ll, el, q); 134 c = a; //fac.random(kl, ll, el, q ); 135 d = c; //fac.random(kl, ll, el, q ); 136 e = d; //fac.random(kl, ll, el, q ); 137 138 if (a.isZERO() || b.isZERO() || c.isZERO() || d.isZERO()) { 139 return; 140 } 141 142 assertTrue("not isZERO( a )", !a.isZERO()); 143 L.add(a); 144 145 L = bb.GB(L); 146 assertTrue("isGB( { a } )", bb.isGB(L)); 147 148 assertTrue("not isZERO( b )", !b.isZERO()); 149 L.add(b); 150 //System.out.println("L = " + L.size() ); 151 152 L = bb.GB(L); 153 assertTrue("isGB( { a, b } )", bb.isGB(L)); 154 155 assertTrue("not isZERO( c )", !c.isZERO()); 156 L.add(c); 157 158 L = bb.GB(L); 159 assertTrue("isGB( { a, b, c } )", bb.isGB(L)); 160 } 161 162 163 /** 164 * Test Trinks CGB. 165 * 166 */ 167 @SuppressWarnings("unchecked") 168 public void testTrinks7GBase() { 169 PolynomialList<GenPolynomial<BigRational>> F = null; 170 List<GenPolynomial<GenPolynomial<BigRational>>> G = null; 171 String exam = "IntFunc(b) (S,T,Z,P,W) L " + "( " + "( 45 P + 35 S - { 165 b + 36 } ), " 172 + "( 35 P + 40 Z + 25 T - 27 S ), " 173 + "( 15 W + 25 S P + 30 Z - 18 T - { 165 b**2 } ), " 174 + "( - 9 W + 15 T P + 20 S Z ), " + "( P W + 2 T Z - { 11 b**3 } ), " 175 + "( 99 W - { 11 b } S + { 3 b**2 } ), " + "( { b**2 + 33/50 b + 2673/10000 } ) " 176 + ") "; 177 Reader source = new StringReader(exam); 178 GenPolynomialTokenizer parser = new GenPolynomialTokenizer(source); 179 try { 180 F = (PolynomialList<GenPolynomial<BigRational>>) parser.nextPolynomialSet(); 181 } catch (ClassCastException e) { 182 fail("" + e); 183 } catch (IOException e) { 184 fail("" + e); 185 } 186 //System.out.println("F = " + F); 187 188 G = bb.GB(F.list); 189 assertTrue("isGB( GB(Trinks7) )", bb.isGB(G)); 190 191 //PolynomialList<GenPolynomial<BigRational>> trinks 192 // = new PolynomialList<GenPolynomial<BigRational>>(F.ring,G); 193 //System.out.println("G = " + trinks); 194 //System.out.println("G = " + G); 195 } 196 197}