001 /*
002 * $Id: ElementaryIntegrationTest.java 3356 2010-10-23 16:41:01Z kredel $
003 */
004
005 package edu.jas.integrate;
006
007
008 import junit.framework.Test;
009 import junit.framework.TestCase;
010 import junit.framework.TestSuite;
011
012 import org.apache.log4j.BasicConfigurator;
013 //import org.apache.log4j.Logger;
014
015 import edu.jas.arith.BigRational;
016 import edu.jas.poly.GenPolynomial;
017 import edu.jas.poly.GenPolynomialRing;
018 import edu.jas.poly.TermOrder;
019 import edu.jas.poly.PolyUtil;
020 import edu.jas.ufd.Quotient;
021 import edu.jas.ufd.QuotientRing;
022
023 import edu.jas.kern.ComputerThreads;
024
025
026 /**
027 * Quotient over BigRational GenPolynomial tests with JUnit.
028 * @author Heinz Kredel.
029 */
030
031 public class ElementaryIntegrationTest extends TestCase {
032
033 /**
034 * main.
035 */
036 public static void main (String[] args) {
037 //BasicConfigurator.configure();
038 junit.textui.TestRunner.run( suite() );
039 }
040
041 /**
042 * Constructs a <CODE>ElementaryIntegrationTest</CODE> object.
043 * @param name String.
044 */
045 public ElementaryIntegrationTest(String name) {
046 super(name);
047 }
048
049 /**
050 * suite.
051 */
052 public static Test suite() {
053 TestSuite suite= new TestSuite(ElementaryIntegrationTest.class);
054 return suite;
055 }
056
057 //private final static int bitlen = 100;
058
059 TermOrder tord;
060 QuotientRing<BigRational> qfac;
061 GenPolynomialRing<BigRational> mfac;
062 ElementaryIntegration<BigRational> integrator;
063 QuotIntegral<BigRational> rint;
064
065 Quotient< BigRational > a;
066 Quotient< BigRational > b;
067 Quotient< BigRational > c;
068 Quotient< BigRational > d;
069 Quotient< BigRational > e;
070
071 int rl = 1; // only univariate polynomials
072 int kl = 5;
073 int ll = 3; //6;
074 int el = 4;
075 float q = 0.4f;
076
077 protected void setUp() {
078 a = b = c = d = e = null;
079 tord = new TermOrder( TermOrder.INVLEX );
080 BigRational br = new BigRational(1);
081 String[] vars = new String[]{ "x" };
082 mfac = new GenPolynomialRing<BigRational>( br, rl, tord, vars );
083 qfac = new QuotientRing<BigRational>( mfac );
084 integrator = new ElementaryIntegration<BigRational>(br);
085 }
086
087 protected void tearDown() {
088 a = b = c = d = e = null;
089 //qfac.terminate();
090 qfac = null;
091 ComputerThreads.terminate();
092 }
093
094
095 /**
096 * Test rational integral.
097 *
098 */
099 public void testRational() {
100 for (int i = 0; i < 3; i++) {
101 a = qfac.random(kl, ll+2*i, el+i, q );
102 //System.out.println("a = " + a);
103 // if ( a.isZERO() || a.isONE() ) {
104 // continue;
105 // }
106 b = integrator.deriviative(a);
107 //System.out.println("b = " + b);
108 rint = integrator.integrate(b);
109 //System.out.println("QuotIntegral: " + rint);
110
111 assertTrue("isIntegral ", integrator.isIntegral(rint));
112 }
113 }
114
115
116 /**
117 * Test 1/p pure logarithm integral.
118 *
119 */
120 public void testPureLogarithm1() {
121 for (int i = 0; i < 3; i++) {
122 a = qfac.random(kl, ll+i, el+i, q );
123 //System.out.println("a = " + a);
124 // if ( a.isZERO() || a.isONE() ) {
125 // continue;
126 // }
127 b = new Quotient<BigRational>(qfac,qfac.getONE().num,a.den);
128 //System.out.println("b = " + b);
129 rint = integrator.integrate(b);
130 //System.out.println("QuotIntegral: " + rint);
131
132 assertTrue("isIntegral ", integrator.isIntegral(rint));
133 }
134 }
135
136
137 /**
138 * Test p'/p pure logarithm integral.
139 *
140 */
141 public void testPureLogarithmD() {
142 for (int i = 0; i < 3; i++) {
143 a = qfac.random(kl, ll+i, el+i, q );
144 //System.out.println("a = " + a);
145 // if ( a.isZERO() || a.isONE() ) {
146 // continue;
147 // }
148 GenPolynomial<BigRational> pp = PolyUtil.<BigRational> baseDeriviative(a.den);
149 b = new Quotient<BigRational>(qfac, pp ,a.den);
150 //System.out.println("b = " + b);
151 rint = integrator.integrate(b);
152 //System.out.println("QuotIntegral: " + rint);
153
154 assertTrue("isIntegral ", integrator.isIntegral(rint));
155 }
156 }
157
158
159 /**
160 * Test mixed rational with p'/p logarithm integral.
161 *
162 */
163 public void testRationalWithLogarithmD() {
164 for (int i = 0; i < 3; i++) {
165 a = qfac.random(kl, ll+i, el+i, q );
166 //System.out.println("a = " + a);
167 // if ( a.isZERO() || a.isONE() ) {
168 // continue;
169 // }
170
171 b = integrator.deriviative(a);
172 //System.out.println("b = " + b);
173
174 GenPolynomial<BigRational> pp = PolyUtil.<BigRational> baseDeriviative(a.den);
175 c = new Quotient<BigRational>(qfac, pp ,a.den);
176 //System.out.println("c = " + c);
177
178 e = b.sum(c);
179 //System.out.println("e = " + e);
180
181 rint = integrator.integrate(e);
182 //System.out.println("QuotIntegral: " + rint);
183
184 assertTrue("isIntegral ", integrator.isIntegral(rint));
185 }
186 }
187
188
189 /**
190 * Test mixed rational with 1/p logarithm integral.
191 *
192 */
193 public void xtestRationalWithLogarithm1() {
194 for (int i = 0; i < 3; i++) {
195 a = qfac.random(kl, ll+i, el+i, q );
196 //System.out.println("a = " + a);
197 // if ( a.isZERO() || a.isONE() ) {
198 // continue;
199 // }
200
201 b = integrator.deriviative(a);
202 //System.out.println("b = " + b);
203
204 d = new Quotient<BigRational>(qfac,qfac.getONE().num,a.den);
205 //System.out.println("d = " + d);
206
207 e = b.sum(d);
208 //System.out.println("e = " + e);
209
210 rint = integrator.integrate(e);
211 //System.out.println("QuotIntegral: " + rint);
212
213 assertTrue("isIntegral ", integrator.isIntegral(rint));
214 }
215 }
216
217
218 /**
219 * Test mixed rational with p'/p + 1/p logarithm integral.
220 *
221 */
222 public void testRationalWithLogarithm() {
223 for (int i = 0; i < 3; i++) {
224 a = qfac.random(kl, ll+i, el+i, q );
225 //System.out.println("a = " + a);
226 // if ( a.isZERO() || a.isONE() ) {
227 // continue;
228 // }
229
230 b = integrator.deriviative(a);
231 //System.out.println("b = " + b);
232
233 GenPolynomial<BigRational> pp = PolyUtil.<BigRational> baseDeriviative(a.den);
234 c = new Quotient<BigRational>(qfac, pp ,a.den);
235 //System.out.println("c = " + c);
236
237 d = new Quotient<BigRational>(qfac,qfac.getONE().num,a.den);
238 //System.out.println("d = " + d);
239
240 e = b.sum(c).sum(d);
241 //System.out.println("e = " + e);
242
243 rint = integrator.integrate(e);
244 //System.out.println("QuotIntegral: " + rint);
245
246 assertTrue("isIntegral ", integrator.isIntegral(rint));
247 }
248 }
249
250
251 /**
252 * Test rational integral with quotient coefficients.
253 *
254 */
255 public void testRationalRecursive() {
256
257 QuotientRing<Quotient<BigRational>> qqfac;
258 GenPolynomialRing<Quotient<BigRational>> qmfac;
259 ElementaryIntegration<Quotient<BigRational>> qintegrator;
260 QuotIntegral<Quotient<BigRational>> qrint;
261 String[] vars = new String[]{ "y" };
262
263 qmfac = new GenPolynomialRing<Quotient<BigRational>>(qfac,1,tord,vars);
264 qqfac = new QuotientRing<Quotient<BigRational>>(qmfac);
265
266 qintegrator = new ElementaryIntegration<Quotient<BigRational>>(qfac);
267
268 Quotient< Quotient< BigRational > > qa, qb;
269
270 for (int i = 0; i < 2; i++) {
271 qa = qqfac.random(2, ll, el, q );
272 //System.out.println("qa = " + qa);
273 // if ( a.isZERO() || a.isONE() ) {
274 // continue;
275 // }
276 qb = qintegrator.deriviative(qa);
277 //System.out.println("qb = " + qb);
278 qrint = qintegrator.integrate(qb);
279 //System.out.println("QuotIntegral: " + qrint);
280
281 assertTrue("isIntegral ", qintegrator.isIntegral(qrint));
282 }
283 }
284
285 }