001/* 002 * $Id: ElementaryIntegrationBernoulli.java 5850 2018-06-24 15:39:36Z elbarbary $ 003 */ 004 005package edu.jas.integrate; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011import org.apache.log4j.Logger; 012 013import edu.jas.poly.AlgebraicNumber; 014import edu.jas.poly.GenPolynomial; 015import edu.jas.poly.GenPolynomialRing; 016import edu.jas.structure.GcdRingElem; 017import edu.jas.structure.RingFactory; 018import edu.jas.ufd.FactorAbsolute; 019import edu.jas.ufd.PartialFraction; 020 021 022/** 023 * Methods related to the Bernoulli algorithm for elementary integration. The 024 * denominator is factored into linear factors over iterated algebraic 025 * extensions over the rational numbers. 026 * 027 * @author Heinz Kredel 028 * @param <C> coefficient type 029 */ 030 031public class ElementaryIntegrationBernoulli<C extends GcdRingElem<C>> extends ElementaryIntegration<C> { 032 033 034 private static final Logger logger = Logger.getLogger(ElementaryIntegrationBernoulli.class); 035 036 037 //private static final boolean debug = logger.isDebugEnabled(); 038 039 040 /** 041 * Constructor. 042 */ 043 public ElementaryIntegrationBernoulli(RingFactory<C> br) { 044 super(br); 045 if (!(irr instanceof FactorAbsolute)) { 046 logger.error("no absolute factorization available for coefficient ring " + br); 047 throw new IllegalArgumentException( 048 "no absolute factorization available for coefficient ring " + br); 049 } 050 irredLogPart = true; // force to true? 051 } 052 053 054 /** 055 * Univariate GenPolynomial integration of the logarithmic part, Bernoulli 056 * linear factorization algorithm. 057 * @param A univariate GenPolynomial, deg(A) < deg(P). 058 * @param P univariate squarefree or irreducible GenPolynomial. // gcd(A,P) 059 * == 1 automatic 060 * @return logarithmic part container. 061 */ 062 @Override 063 public LogIntegral<C> integrateLogPart(GenPolynomial<C> A, GenPolynomial<C> P) { 064 if (P == null || P.isZERO()) { 065 throw new IllegalArgumentException("P == null or P == 0"); 066 } 067 //System.out.println("\nP_base_algeb_part = " + P); 068 GenPolynomialRing<C> pfac = P.ring; // K[x] 069 if (pfac.nvar > 1) { 070 throw new IllegalArgumentException("only for univariate polynomials " + pfac); 071 } 072 // pfac.coFac.isField() by FactorAbsolute 073 List<C> cfactors = new ArrayList<C>(); 074 List<GenPolynomial<C>> cdenom = new ArrayList<GenPolynomial<C>>(); 075 List<AlgebraicNumber<C>> afactors = new ArrayList<AlgebraicNumber<C>>(); 076 List<GenPolynomial<AlgebraicNumber<C>>> adenom = new ArrayList<GenPolynomial<AlgebraicNumber<C>>>(); 077 // P linear 078 if (P.degree(0) <= 1) { 079 cfactors.add(A.leadingBaseCoefficient()); 080 cdenom.add(P); 081 return new LogIntegral<C>(A, P, cfactors, cdenom, afactors, adenom); 082 } 083 // complete factorization to linear factors 084 PartialFraction<C> F = ((FactorAbsolute<C>) irr).baseAlgebraicPartialFraction(A, P); 085 //System.out.println("\npartial fraction " + F); 086 087 return new LogIntegral<C>(A, P, F.cfactors, F.cdenom, F.afactors, F.adenom); 088 } 089 090}