edu.jas.integrate.QuotIntegral Maven / Gradle / Ivy
/*
* $Id: QuotIntegral.java 4046 2012-07-25 16:48:54Z kredel $
*/
package edu.jas.integrate;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import edu.jas.poly.GenPolynomial;
import edu.jas.structure.GcdRingElem;
import edu.jas.ufd.Quotient;
import edu.jas.ufd.QuotientRing;
/**
* Container for a rational function integral, quotient version .
* integral(num/den) = pol + sum_rat( rat_i/rat_{i+1} ) + sum_log( a_i log ( d_i
* ) )
* @author Heinz Kredel
* @param coefficient type
*/
public class QuotIntegral> implements Serializable {
/**
* Original rational function with coefficients from C.
*/
public final Quotient quot;
/**
* Integral of the polynomial and rational part.
*/
public final List> rational;
/**
* Integral of the logarithmic part.
*/
public final List> logarithm;
/**
* Constructor.
* @param ri integral.
*/
public QuotIntegral(Integral ri) {
this(new QuotientRing(ri.den.ring), ri);
}
/**
* Constructor.
* @param r rational function QuotientRing over C.
* @param ri integral.
*/
public QuotIntegral(QuotientRing r, Integral ri) {
this(new Quotient(r, ri.num, ri.den), ri.pol, ri.rational, ri.logarithm);
}
/**
* Constructor.
* @param r rational function Quotient over C.
* @param p integral of polynomial part.
* @param rat list of rational integrals.
*/
public QuotIntegral(Quotient r, GenPolynomial p, List> rat) {
this(r, p, rat, new ArrayList>());
}
/**
* Constructor.
* @param r rational function Quotient over C.
* @param p integral of polynomial part.
* @param rat list of rational integrals.
* @param log list of logarithmic part.
*/
public QuotIntegral(Quotient r, GenPolynomial p, List> rat,
List> log) {
quot = r;
QuotientRing qr = r.ring;
rational = new ArrayList>();
if (!p.isZERO()) {
rational.add(new Quotient(qr, p));
}
for (int i = 0; i < rat.size(); i++) {
GenPolynomial rn = rat.get(i++);
GenPolynomial rd = rat.get(i);
rational.add(new Quotient(qr, rn, rd));
}
logarithm = log;
}
/**
* Get the String representation.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("integral( " + quot.toString() + " )");
sb.append(" =\n");
boolean first = true;
if (rational.size() != 0) {
for (int i = 0; i < rational.size(); i++) {
if (first) {
first = false;
} else {
sb.append(" + ");
}
sb.append("(" + rational.get(i) + ")");
}
}
if (logarithm.size() != 0) {
if (rational.size() != 0) {
sb.append(" + ");
}
first = true;
for (LogIntegral pf : logarithm) {
if (first) {
first = false;
} else {
sb.append(" + ");
}
sb.append(pf);
}
sb.append("\n");
}
return sb.toString();
}
/**
* Hash code for QuotIntegral.
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
int h = quot.hashCode();
h = h * 37 + rational.hashCode();
h = h * 37 + logarithm.hashCode();
return h;
}
/**
* Comparison with any other object.
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object B) {
QuotIntegral b = null;
try {
b = (QuotIntegral) B;
} catch (ClassCastException ignored) {
}
if (b == null) {
return false;
}
return quot.equals(b.quot) &&
rational.equals(b.rational) &&
logarithm.equals(b.logarithm);
}
}