001 /*
002 * $Id: Integral.java 3295 2010-08-26 17:01:10Z kredel $
003 */
004
005 package edu.jas.integrate;
006
007
008 import java.io.Serializable;
009 import java.util.ArrayList;
010 import java.util.List;
011
012 import edu.jas.poly.GenPolynomial;
013 import edu.jas.structure.GcdRingElem;
014
015
016 /**
017 * Container for a rational function integral, polynomial version.
018 * integral(num/den) = pol + sum_rat( rat_i/rat_{i+1} ) + sum_log( a_i log ( d_i
019 * ) )
020 * @author Heinz Kredel
021 * @param <C> coefficient type
022 */
023
024 public class Integral<C extends GcdRingElem<C>> implements Serializable {
025
026
027 /**
028 * Original numerator polynomial with coefficients from C.
029 */
030 public final GenPolynomial<C> num;
031
032
033 /**
034 * Original denominator polynomial with coefficients from C.
035 */
036 public final GenPolynomial<C> den;
037
038
039 /**
040 * Integral of the polynomial part.
041 */
042 public final GenPolynomial<C> pol;
043
044
045 /**
046 * Integral of the rational part.
047 */
048 public final List<GenPolynomial<C>> rational;
049
050
051 /**
052 * Integral of the logarithmic part.
053 */
054 public final List<LogIntegral<C>> logarithm;
055
056
057 /**
058 * Constructor.
059 * @param n numerator GenPolynomial over C.
060 * @param d denominator GenPolynomial over C.
061 * @param p integral of polynomial part. n/d =
062 */
063 public Integral(GenPolynomial<C> n, GenPolynomial<C> d, GenPolynomial<C> p) {
064 this(n, d, p, new ArrayList<GenPolynomial<C>>());
065 }
066
067
068 /**
069 * Constructor.
070 * @param n numerator GenPolynomial over C.
071 * @param d denominator GenPolynomial over C.
072 * @param p integral of polynomial part.
073 * @param rat list of rational integrals. n/d =
074 */
075 public Integral(GenPolynomial<C> n, GenPolynomial<C> d, GenPolynomial<C> p, List<GenPolynomial<C>> rat) {
076 this(n, d, p, rat, new ArrayList<LogIntegral<C>>());
077 }
078
079
080 /**
081 * Constructor.
082 * @param n numerator GenPolynomial over C.
083 * @param d denominator GenPolynomial over C.
084 * @param p integral of polynomial part.
085 * @param rat list of rational integrals.
086 * @param log list of logarithmic part. n/d =
087 */
088 public Integral(GenPolynomial<C> n, GenPolynomial<C> d, GenPolynomial<C> p, List<GenPolynomial<C>> rat,
089 List<LogIntegral<C>> log) {
090 num = n;
091 den = d;
092 pol = p;
093 rational = rat;
094 logarithm = log;
095 }
096
097
098 /**
099 * Get the String representation.
100 * @see java.lang.Object#toString()
101 */
102 @Override
103 public String toString() {
104 StringBuffer sb = new StringBuffer();
105 sb.append("integral( (" + num.toString());
106 sb.append(") / (");
107 sb.append(den.toString() + ") )");
108 sb.append(" =\n");
109 if (!pol.isZERO()) {
110 sb.append(pol.toString());
111 }
112 boolean first = true;
113 if (rational.size() != 0) {
114 if (!pol.isZERO()) {
115 sb.append(" + ");
116 }
117 for (int i = 0; i < rational.size(); i++) {
118 if (first) {
119 first = false;
120 } else {
121 sb.append(" + ");
122 }
123 sb.append("(" + rational.get(i++) + ")/(");
124 sb.append(rational.get(i) + ")");
125 }
126 }
127 if (logarithm.size() != 0) {
128 if (!pol.isZERO() || rational.size() != 0) {
129 sb.append(" + ");
130 }
131 first = true;
132 for (LogIntegral<C> pf : logarithm) {
133 if (first) {
134 first = false;
135 } else {
136 sb.append(" + ");
137 }
138 sb.append(pf);
139 }
140 sb.append("\n");
141 }
142 return sb.toString();
143 }
144
145
146 /**
147 * Hash code for Integral.
148 * @see java.lang.Object#hashCode()
149 */
150 @Override
151 public int hashCode() {
152 int h = num.hashCode();
153 h = h * 37 + den.hashCode();
154 h = h * 37 + pol.hashCode();
155 h = h * 37 + rational.hashCode();
156 h = h * 37 + logarithm.hashCode();
157 return h;
158 }
159
160 }