InfiniteSumSeriesTerm.java

  1. package org.drip.specialfunction.loggamma;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  *
  9.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  10.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  11.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  12.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  13.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  14.  *      and computational support.
  15.  *  
  16.  *      https://lakshmidrip.github.io/DROP/
  17.  *  
  18.  *  DROP is composed of three modules:
  19.  *  
  20.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  21.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  22.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  23.  *
  24.  *  DROP Product Core implements libraries for the following:
  25.  *  - Fixed Income Analytics
  26.  *  - Loan Analytics
  27.  *  - Transaction Cost Analytics
  28.  *
  29.  *  DROP Portfolio Core implements libraries for the following:
  30.  *  - Asset Allocation Analytics
  31.  *  - Asset Liability Management Analytics
  32.  *  - Capital Estimation Analytics
  33.  *  - Exposure Analytics
  34.  *  - Margin Analytics
  35.  *  - XVA Analytics
  36.  *
  37.  *  DROP Computational Core implements libraries for the following:
  38.  *  - Algorithm Support
  39.  *  - Computation Support
  40.  *  - Function Analysis
  41.  *  - Model Validation
  42.  *  - Numerical Analysis
  43.  *  - Numerical Optimizer
  44.  *  - Spline Builder
  45.  *  - Statistical Learning
  46.  *
  47.  *  Documentation for DROP is Spread Over:
  48.  *
  49.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  50.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  51.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  52.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  53.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  54.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  55.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  56.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  57.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  58.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  59.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  60.  *
  61.  *  Licensed under the Apache License, Version 2.0 (the "License");
  62.  *      you may not use this file except in compliance with the License.
  63.  *  
  64.  *  You may obtain a copy of the License at
  65.  *      http://www.apache.org/licenses/LICENSE-2.0
  66.  *  
  67.  *  Unless required by applicable law or agreed to in writing, software
  68.  *      distributed under the License is distributed on an "AS IS" BASIS,
  69.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  70.  *  
  71.  *  See the License for the specific language governing permissions and
  72.  *      limitations under the License.
  73.  */

  74. /**
  75.  * <i>InfiniteSumSeriesTerm</i> implements a Single Term in the Infinite Series for Log Gamma Estimation. The
  76.  * References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Blagouchine, I. V. (2014): Re-discovery of Malmsten's Integrals, their Evaluation by Contour
  82.  *              Integration Methods, and some Related Results <i>Ramanujan Journal</i> <b>35 (1)</b> 21-110
  83.  *      </li>
  84.  *      <li>
  85.  *          Borwein, J. M., and R. M. Corless (2017): Gamma Function and the Factorial in the Monthly
  86.  *              https://arxiv.org/abs/1703.05349 <b>arXiv</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  90.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  91.  *      </li>
  92.  *      <li>
  93.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  94.  *              University Press</b> New York
  95.  *      </li>
  96.  *      <li>
  97.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  98.  *      </li>
  99.  *  </ul>
  100.  *
  101.  *  <br><br>
  102.  *  <ul>
  103.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  104.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FunctionAnalysisLibrary.md">Function Analysis Library</a></li>
  105.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/README.md">Special Function Implementation Analysis</a></li>
  106.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/loggamma/README.md">Analytic/Series/Integral Log Gamma Estimators</a></li>
  107.  *  </ul>
  108.  *
  109.  * @author Lakshmi Krishnamurthy
  110.  */

  111. public class InfiniteSumSeriesTerm
  112. {

  113.     /**
  114.      * Construct the Euler Infinite Sum Series Term for Log Gamma
  115.      *
  116.      * @return The Euler Infinite Sum Series Term for Log Gamma
  117.      */

  118.     public static final org.drip.numerical.estimation.R1ToR1SeriesTerm Euler()
  119.     {
  120.         try
  121.         {
  122.             return new org.drip.numerical.estimation.R1ToR1SeriesTerm()
  123.             {
  124.                 @Override public double value (
  125.                     final int order,
  126.                     final double z)
  127.                     throws java.lang.Exception
  128.                 {
  129.                     if (0 >= order ||
  130.                         !org.drip.numerical.common.NumberUtil.IsValid (z) || 0. > z)
  131.                     {
  132.                         throw new java.lang.Exception
  133.                             ("InfiniteSumSeriesTerm::Euler::value => Invalid Inputs");
  134.                     }

  135.                     return 0. == z ? 0. : z * java.lang.Math.log (1. + (1. / order)) -
  136.                         java.lang.Math.log (1. + (z / order));
  137.                 }
  138.             };
  139.         }
  140.         catch (java.lang.Exception e)
  141.         {
  142.             e.printStackTrace();
  143.         }

  144.         return null;
  145.     }

  146.     /**
  147.      * Construct the Weierstrass Infinite Sum Series Term for Log Gamma
  148.      *
  149.      * @return The Weierstrass Infinite Sum Series Term for Log Gamma
  150.      */

  151.     public static final org.drip.numerical.estimation.R1ToR1SeriesTerm Weierstrass()
  152.     {
  153.         try
  154.         {
  155.             return new org.drip.numerical.estimation.R1ToR1SeriesTerm()
  156.             {
  157.                 @Override public double value (
  158.                     final int order,
  159.                     final double z)
  160.                     throws java.lang.Exception
  161.                 {
  162.                     if (0 >= order ||
  163.                         !org.drip.numerical.common.NumberUtil.IsValid (z) || 0. > z)
  164.                     {
  165.                         throw new java.lang.Exception
  166.                             ("InfiniteSumSeriesTerm::Euler::value => Invalid Inputs");
  167.                     }

  168.                     double zOverOrder = z / order;

  169.                     return 0. == z ? 0. : zOverOrder - java.lang.Math.log (1. + zOverOrder);
  170.                 }
  171.             };
  172.         }
  173.         catch (java.lang.Exception e)
  174.         {
  175.             e.printStackTrace();
  176.         }

  177.         return null;
  178.     }

  179.     /**
  180.      * Construct the Malmsten-Blagouchine Fourier Series Term for Log Gamma
  181.      *
  182.      * @return The Malmsten-Blagouchine Fourier Series Term for Log Gamma
  183.      */

  184.     public static final org.drip.numerical.estimation.R1ToR1SeriesTerm Fourier()
  185.     {
  186.         try
  187.         {
  188.             return new org.drip.numerical.estimation.R1ToR1SeriesTerm()
  189.             {
  190.                 @Override public double value (
  191.                     final int order,
  192.                     final double z)
  193.                     throws java.lang.Exception
  194.                 {
  195.                     if (0 >= order ||
  196.                         !org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z || 1. <= z)
  197.                     {
  198.                         throw new java.lang.Exception
  199.                             ("InfiniteSumSeriesTerm::Fourier::value => Invalid Inputs");
  200.                     }

  201.                     return java.lang.Math.log (order) *
  202.                         java.lang.Math.sin (2. * java.lang.Math.PI * order * z) / order;
  203.                 }
  204.             };
  205.         }
  206.         catch (java.lang.Exception e)
  207.         {
  208.             e.printStackTrace();
  209.         }

  210.         return null;
  211.     }

  212.     /**
  213.      * Construct the Blagouchine (2015) Series Term for Log Gamma
  214.      *
  215.      * @return The Blagouchine (2015) Series Term for Log Gamma
  216.      */

  217.     public static final org.drip.numerical.estimation.R1ToR1SeriesTerm Blagouchine2015()
  218.     {
  219.         try
  220.         {
  221.             return new org.drip.numerical.estimation.R1ToR1SeriesTerm()
  222.             {
  223.                 @Override public double value (
  224.                     final int order,
  225.                     final double z)
  226.                     throws java.lang.Exception
  227.                 {
  228.                     if (0 >= order ||
  229.                         !org.drip.numerical.common.NumberUtil.IsValid (z) || 0. >= z || 1. <= z || 0.5 == z)
  230.                     {
  231.                         throw new java.lang.Exception
  232.                             ("InfiniteSumSeriesTerm::Blagouchine2015::value => Invalid Inputs");
  233.                     }

  234.                     return (
  235.                         org.drip.specialfunction.gamma.Definitions.EULER_MASCHERONI + java.lang.Math.log
  236.                             (order)
  237.                     ) * java.lang.Math.sin (2. * java.lang.Math.PI * order * z) / order;
  238.                 }
  239.             };
  240.         }
  241.         catch (java.lang.Exception e)
  242.         {
  243.             e.printStackTrace();
  244.         }

  245.         return null;
  246.     }
  247. }