GautschiConvexProperty.java

  1. package org.drip.sample.gamma;

  2. import org.drip.function.definition.R1ToR1Property;
  3. import org.drip.function.definition.R1PropertyVerification;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.specialfunction.property.GammaInequalityLemma;

  7. /*
  8.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  9.  */

  10. /*!
  11.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  12.  *
  13.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  14.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  15.  *      FX, and structured products.
  16.  *  
  17.  *      https://lakshmidrip.github.io/DROP/
  18.  *  
  19.  *  DROP is composed of three main modules:
  20.  *  
  21.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  22.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  23.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  24.  *
  25.  *  DROP Analytics Core implements libraries for the following:
  26.  *  - Fixed Income Analytics
  27.  *  - Asset Backed Analytics
  28.  *  - XVA Analytics
  29.  *  - Exposure and Margin Analytics
  30.  *
  31.  *  DROP Portfolio Core implements libraries for the following:
  32.  *  - Asset Allocation Analytics
  33.  *  - Transaction Cost Analytics
  34.  *
  35.  *  DROP Numerical Core implements libraries for the following:
  36.  *  - Statistical Learning Library
  37.  *  - Numerical Optimizer Library
  38.  *  - Machine Learning Library
  39.  *  - Spline Builder Library
  40.  *
  41.  *  Documentation for DROP is Spread Over:
  42.  *
  43.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  44.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  45.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  46.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  47.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  48.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  49.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  50.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  51.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  52.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  53.  *
  54.  *  Licensed under the Apache License, Version 2.0 (the "License");
  55.  *      you may not use this file except in compliance with the License.
  56.  *  
  57.  *  You may obtain a copy of the License at
  58.  *      http://www.apache.org/licenses/LICENSE-2.0
  59.  *  
  60.  *  Unless required by applicable law or agreed to in writing, software
  61.  *      distributed under the License is distributed on an "AS IS" BASIS,
  62.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  63.  *  
  64.  *  See the License for the specific language governing permissions and
  65.  *      limitations under the License.
  66.  */

  67. /**
  68.  * <i>GautschiConvexProperty</i> demonstrates the Verification of the Gautschi Double-Bound Convex Property
  69.  * of the Gamma Function. The References are:
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li>
  74.  *          Blagouchine, I. V. (2014): Re-discovery of Malmsten's Integrals, their Evaluation by Contour
  75.  *              Integration Methods, and some Related Results <i>Ramanujan Journal</i> <b>35 (1)</b> 21-110
  76.  *      </li>
  77.  *      <li>
  78.  *          Borwein, J. M., and R. M. Corless (2017): Gamma Function and the Factorial in the Monthly
  79.  *              https://arxiv.org/abs/1703.05349 <b>arXiv</b>
  80.  *      </li>
  81.  *      <li>
  82.  *          Davis, P. J. (1959): Leonhard Euler's Integral: A Historical Profile of the Gamma Function
  83.  *              <i>American Mathematical Monthly</i> <b>66 (10)</b> 849-869
  84.  *      </li>
  85.  *      <li>
  86.  *          Whitaker, E. T., and G. N. Watson (1996): <i>A Course on Modern Analysis</i> <b>Cambridge
  87.  *              University Press</b> New York
  88.  *      </li>
  89.  *      <li>
  90.  *          Wikipedia (2019): Gamma Function https://en.wikipedia.org/wiki/Gamma_function
  91.  *      </li>
  92.  *  </ul>
  93.  *
  94.  *  <br><br>
  95.  *  <ul>
  96.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  97.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  98.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  99.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/gamma/README.md">Integrand Estimates of Gamma Functions</a></li>
  100.  *  </ul>
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class GautschiConvexProperty
  105. {

  106.     private static final void Verifier (
  107.         final double s,
  108.         final double[] zArray)
  109.         throws Exception
  110.     {
  111.         System.out.println ("\t|----------------------------------------------------------------------||");

  112.         System.out.println ("\t|               GAMMA FUNCTION GAUTSCHI CONVEX PROPERTY                ||");

  113.         System.out.println ("\t|                               s = " + FormatUtil.FormatDouble (s, 1, 1, 1.));

  114.         System.out.println ("\t|----------------------------------------------------------------------||");

  115.         System.out.println ("\t|        L -> R:                                                       ||");

  116.         System.out.println ("\t|                - z                                                   ||");

  117.         System.out.println ("\t|                - LHS Value                                           ||");

  118.         System.out.println ("\t|                - Middle Value                                        ||");

  119.         System.out.println ("\t|                - RHS Value                                           ||");

  120.         System.out.println ("\t|                - Left Verification Success?                          ||");

  121.         System.out.println ("\t|                - Right Verification Success?                         ||");

  122.         System.out.println ("\t|----------------------------------------------------------------------||");

  123.         R1ToR1Property gautschiLeftProperty = GammaInequalityLemma.GautschiLeft (s);

  124.         R1ToR1Property gautschiRightProperty = GammaInequalityLemma.GautschiRight (s);

  125.         for (double z : zArray)
  126.         {
  127.             R1PropertyVerification leftVerification = gautschiLeftProperty.verify (z);

  128.             R1PropertyVerification rightVerification = gautschiRightProperty.verify (z);

  129.             System.out.println (
  130.                 "\t|" + FormatUtil.FormatDouble (z, 2, 2, 1.) + " => " +
  131.                     FormatUtil.FormatDouble (leftVerification.lValue(), 1, 10, 1.) + " | " +
  132.                     FormatUtil.FormatDouble (leftVerification.rValue(), 1, 10, 1.) + " | " +
  133.                     FormatUtil.FormatDouble (rightVerification.rValue(), 1, 10, 1.) + " | " +
  134.                     leftVerification.verified() + " | " +
  135.                     rightVerification.verified() + " ||"
  136.             );
  137.         }

  138.         System.out.println ("\t|----------------------------------------------------------------------||");

  139.         System.out.println();
  140.     }

  141.     public static final void main (
  142.         final String[] argumentArray)
  143.         throws Exception
  144.     {
  145.         EnvManager.InitEnv ("");

  146.         double[] sArray =
  147.         {
  148.             0.1,
  149.             0.2,
  150.             0.3,
  151.             0.4,
  152.             0.5,
  153.             0.6,
  154.             0.7,
  155.             0.8,
  156.             0.9,
  157.         };
  158.         double[] zArray =
  159.         {
  160.             1.5,
  161.             2.0,
  162.             2.5,
  163.             3.0,
  164.             3.5,
  165.             4.0,
  166.             4.5,
  167.             5.0,
  168.             5.5,
  169.             6.0,
  170.             6.5,
  171.             7.0,
  172.             7.5,
  173.             8.0,
  174.             8.5,
  175.             9.0,
  176.             9.5,
  177.         };

  178.         for (double s : sArray)
  179.         {
  180.             Verifier (
  181.                 s,
  182.                 zArray
  183.             );
  184.         }

  185.         EnvManager.TerminateEnv();
  186.     }
  187. }