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