001/* 002 * $Id: SolvableReductionTest.java 5863 2018-07-20 11:13:34Z kredel $ 003 */ 004 005package edu.jas.gb; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import junit.framework.Test; 012import junit.framework.TestCase; 013import junit.framework.TestSuite; 014 015 016import edu.jas.arith.BigRational; 017import edu.jas.poly.GenSolvablePolynomial; 018import edu.jas.poly.GenSolvablePolynomialRing; 019import edu.jas.poly.PolynomialList; 020import edu.jas.poly.RelationGenerator; 021import edu.jas.poly.RelationTable; 022import edu.jas.poly.WeylRelations; 023 024 025/** 026 * Solvable Reduction tests with JUnit. 027 * @author Heinz Kredel 028 */ 029 030public class SolvableReductionTest extends TestCase { 031 032 033 /** 034 * main 035 */ 036 public static void main(String[] args) { 037 junit.textui.TestRunner.run(suite()); 038 } 039 040 041 /** 042 * Constructs a <CODE>SolvableReductionTest</CODE> object. 043 * @param name String. 044 */ 045 public SolvableReductionTest(String name) { 046 super(name); 047 } 048 049 050 /** 051 * suite. 052 */ 053 public static Test suite() { 054 TestSuite suite = new TestSuite(SolvableReductionTest.class); 055 return suite; 056 } 057 058 059 //private final static int bitlen = 100; 060 061 GenSolvablePolynomialRing<BigRational> fac; 062 063 064 RelationTable table; 065 066 067 GenSolvablePolynomial<BigRational> a, b, c, d, e; 068 069 070 List<GenSolvablePolynomial<BigRational>> L; 071 072 073 PolynomialList<BigRational> F, G; 074 075 076 SolvableReduction<BigRational> sred; 077 078 079 SolvableReduction<BigRational> sredpar; 080 081 082 int rl = 4; 083 084 085 int kl = 10; 086 087 088 int ll = 5; 089 090 091 int el = 3; 092 093 094 float q = 0.4f; 095 096 097 @Override 098 protected void setUp() { 099 a = b = c = d = e = null; 100 fac = new GenSolvablePolynomialRing<BigRational>(new BigRational(0), rl); 101 sred = new SolvableReductionSeq<BigRational>(); 102 sredpar = new SolvableReductionPar<BigRational>(); 103 } 104 105 106 @Override 107 protected void tearDown() { 108 a = b = c = d = e = null; 109 fac = null; 110 sred = null; 111 sredpar = null; 112 } 113 114 115 /** 116 * Test constants and empty list reduction. 117 */ 118 public void testRatReduction0() { 119 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 120 121 a = fac.random(kl, ll, el, q); 122 c = fac.getONE(); 123 d = fac.getZERO(); 124 125 e = sred.leftNormalform(L, c); 126 assertTrue("isONE( e )", e.isONE()); 127 128 e = sred.leftNormalform(L, d); 129 assertTrue("isZERO( e )", e.isZERO()); 130 131 132 L.add(c); 133 e = sred.leftNormalform(L, c); 134 assertTrue("isZERO( e )", e.isZERO()); 135 136 // e = Reduction.leftNormalform( L, a ); 137 // assertTrue("isZERO( e )", e.isZERO() ); 138 139 e = sred.leftNormalform(L, d); 140 assertTrue("isZERO( e )", e.isZERO()); 141 142 143 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 144 L.add(d); 145 e = sred.leftNormalform(L, c); 146 assertTrue("isONE( e )", e.isONE()); 147 148 e = sred.leftNormalform(L, d); 149 assertTrue("isZERO( e )", e.isZERO()); 150 } 151 152 153 /** 154 * Test constants and empty list reduction. 155 */ 156 public void testWeylRatReduction0() { 157 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 158 159 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 160 wl.generate(fac); 161 162 a = fac.random(kl, ll, el, q); 163 c = fac.getONE(); 164 d = fac.getZERO(); 165 166 e = sred.leftNormalform(L, c); 167 assertTrue("isONE( e )", e.isONE()); 168 169 e = sred.leftNormalform(L, d); 170 assertTrue("isZERO( e )", e.isZERO()); 171 172 173 L.add(c); 174 e = sred.leftNormalform(L, c); 175 assertTrue("isZERO( e )", e.isZERO()); 176 177 e = sred.leftNormalform(L, a); 178 assertTrue("isZERO( e )", e.isZERO()); 179 180 e = sred.leftNormalform(L, d); 181 assertTrue("isZERO( e )", e.isZERO()); 182 183 184 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 185 L.add(d); 186 e = sred.leftNormalform(L, c); 187 assertTrue("isONE( e )", e.isONE()); 188 189 e = sred.leftNormalform(L, d); 190 assertTrue("isZERO( e )", e.isZERO()); 191 } 192 193 194 /** 195 * Test Rat reduction. 196 */ 197 public void testRatReduction() { 198 a = fac.random(kl, ll, el, q); 199 b = fac.random(kl, ll, el, q); 200 201 assertTrue("not isZERO( a )", !a.isZERO()); 202 203 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 204 L.add(a); 205 206 e = sred.leftNormalform(L, a); 207 assertTrue("isZERO( e )", e.isZERO()); 208 209 assertTrue("not isZERO( b )", !b.isZERO()); 210 211 L.add(b); 212 e = sred.leftNormalform(L, a); 213 assertTrue("isZERO( e ) some times", e.isZERO()); 214 } 215 216 217 /** 218 * Test Rat reduction parallel. 219 */ 220 public void testRatReductionPar() { 221 a = fac.random(kl, ll, el, q); 222 b = fac.random(kl, ll, el, q); 223 224 assertTrue("not isZERO( a )", !a.isZERO()); 225 226 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 227 L.add(a); 228 229 e = sredpar.leftNormalform(L, a); 230 assertTrue("isZERO( e )", e.isZERO()); 231 232 assertTrue("not isZERO( b )", !b.isZERO()); 233 234 L.add(b); 235 e = sredpar.leftNormalform(L, a); 236 assertTrue("isZERO( e ) some times", e.isZERO()); 237 } 238 239 240 /** 241 * Test Weyl Rational reduction. 242 */ 243 public void testWeylRatReduction() { 244 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 245 246 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 247 wl.generate(fac); 248 249 a = fac.random(kl, ll, el, q); 250 b = fac.random(kl, ll, el, q); 251 252 assertTrue("not isZERO( a )", !a.isZERO()); 253 254 L.add(a); 255 256 e = sred.leftNormalform(L, a); 257 assertTrue("isZERO( e )", e.isZERO()); 258 259 assertTrue("not isZERO( b )", !b.isZERO()); 260 261 L.add(b); 262 e = sred.leftNormalform(L, a); 263 assertTrue("isZERO( e ) some times", e.isZERO()); 264 } 265 266 267 /** 268 * Test Weyl Rational reduction parallel. 269 */ 270 public void testWeylRatReductionPar() { 271 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 272 273 RelationGenerator<BigRational> wl = new WeylRelations<BigRational>(); 274 wl.generate(fac); 275 276 a = fac.random(kl, ll, el, q); 277 b = fac.random(kl, ll, el, q); 278 279 assertTrue("not isZERO( a )", !a.isZERO()); 280 281 L.add(a); 282 283 e = sredpar.leftNormalform(L, a); 284 assertTrue("isZERO( e )", e.isZERO()); 285 286 assertTrue("not isZERO( b )", !b.isZERO()); 287 288 L.add(b); 289 e = sredpar.leftNormalform(L, a); 290 assertTrue("isZERO( e ) some times", e.isZERO()); 291 } 292 293 294 /** 295 * Test Rat reduction recording. 296 */ 297 public void testRatReductionRecording() { 298 List<GenSolvablePolynomial<BigRational>> row = null; 299 300 a = fac.random(kl, ll, el, q); 301 b = fac.random(kl, ll, el, q); 302 c = fac.random(kl, ll, el, q); 303 d = fac.random(kl, ll, el, q); 304 305 assertTrue("not isZERO( a )", !a.isZERO()); 306 307 L = new ArrayList<GenSolvablePolynomial<BigRational>>(); 308 309 L.add(a); 310 row = new ArrayList<GenSolvablePolynomial<BigRational>>(L.size()); 311 for (int m = 0; m < L.size(); m++) { 312 row.add(null); 313 } 314 e = sred.leftNormalform(row, L, a); 315 assertTrue("isZERO( e )", e.isZERO()); 316 assertTrue("not isZERO( b )", !b.isZERO()); 317 assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, a, e)); 318 319 L.add(b); 320 row = new ArrayList<GenSolvablePolynomial<BigRational>>(L.size()); 321 for (int m = 0; m < L.size(); m++) { 322 row.add(null); 323 } 324 e = sred.leftNormalform(row, L, b); 325 assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, b, e)); 326 327 L.add(c); 328 row = new ArrayList<GenSolvablePolynomial<BigRational>>(L.size()); 329 for (int m = 0; m < L.size(); m++) { 330 row.add(null); 331 } 332 e = sred.leftNormalform(row, L, c); 333 assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, c, e)); 334 335 L.add(d); 336 row = new ArrayList<GenSolvablePolynomial<BigRational>>(L.size()); 337 for (int m = 0; m < L.size(); m++) { 338 row.add(null); 339 } 340 e = sred.leftNormalform(row, L, d); 341 assertTrue("is leftReduction ", sred.isLeftReductionNF(row, L, d, e)); 342 } 343 344}