GaussContinuedFractionProperty.java

  1. package org.drip.sample.hypergeometric;

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

  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>GaussContinuedFractionProperty</i> verifies the Gauss Continued Fraction Identity Property Lemma for
  69.  * Rational Z. The References are:
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li>
  74.  *          Gessel, I., and D. Stanton (1982): Strange Evaluations of Hyper-geometric Series <i>SIAM Journal
  75.  *              on Mathematical Analysis</i> <b>13 (2)</b> 295-308
  76.  *      </li>
  77.  *      <li>
  78.  *          Koepf, W (1995): Algorithms for m-fold Hyper-geometric Summation <i>Journal of Symbolic
  79.  *              Computation</i> <b>20 (4)</b> 399-417
  80.  *      </li>
  81.  *      <li>
  82.  *          Lavoie, J. L., F. Grondin, and A. K. Rathie (1996): Generalization of Whipple’s Theorem on the
  83.  *              Sum of a (_2^3)F(a,b;c;z) <i>Journal of Computational and Applied Mathematics</i> <b>72</b>
  84.  *              293-300
  85.  *      </li>
  86.  *      <li>
  87.  *          National Institute of Standards and Technology (2019): Hyper-geometric Function
  88.  *              https://dlmf.nist.gov/15
  89.  *      </li>
  90.  *      <li>
  91.  *          Wikipedia (2019): Hyper-geometric Function https://en.wikipedia.org/wiki/Hypergeometric_function
  92.  *      </li>
  93.  *  </ul>
  94.  *
  95.  *  <br><br>
  96.  *  <ul>
  97.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  98.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  99.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Function</a></li>
  100.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/hypergeometric/README.md">Estimates of Hyper-geometric Function</a></li>
  101.  *  </ul>
  102.  *
  103.  * @author Lakshmi Krishnamurthy
  104.  */

  105. public class GaussContinuedFractionProperty
  106. {

  107.     private static final void Verifier (
  108.         final double a,
  109.         final double b,
  110.         final double c,
  111.         final double[] zArray,
  112.         final R1ToR1Property gaussContinuedFractionProperty)
  113.         throws Exception
  114.     {
  115.         for (double z : zArray)
  116.         {
  117.             R1PropertyVerification propertyVerification = gaussContinuedFractionProperty.verify (z);

  118.             System.out.println (
  119.                 "\t| {" + FormatUtil.FormatDouble (a, 1, 2, 1., false) + ", " +
  120.                     FormatUtil.FormatDouble (b, 1, 2, 1., false) + ", " +
  121.                     FormatUtil.FormatDouble (c, 1, 2, 1., false) + ", " +
  122.                     FormatUtil.FormatDouble (z, 1, 2, 1.) + "} => " +
  123.                     FormatUtil.FormatDouble (propertyVerification.lValue(), 1, 10, 1.) + " | " +
  124.                     FormatUtil.FormatDouble (propertyVerification.rValue(), 1, 10, 1.) + " | " +
  125.                     propertyVerification.verified() + " ||"
  126.             );
  127.         }
  128.     }

  129.     public static final void main (
  130.         final String[] argumentArray)
  131.         throws Exception
  132.     {
  133.         EnvManager.InitEnv ("");

  134.         double[] aArray =
  135.         {
  136.             1.0,
  137.             2.0,
  138.             3.0,
  139.             4.0,
  140.             5.0,
  141.         };
  142.         double[] bArray =
  143.         {
  144.             1.0,
  145.             2.0,
  146.         };
  147.         double[] cArray =
  148.         {
  149.             3.0,
  150.             4.0,
  151.             5.0,
  152.         };
  153.         double[] zArray =
  154.         {
  155.             -0.99,
  156.             -0.75,
  157.             -0.50,
  158.             -0.25,
  159.              0.00,
  160.              0.25,
  161.              0.50,
  162.              0.75,
  163.              0.99,
  164.         };

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

  166.         System.out.println ("\t|             GAUSS CONTINUED FRACTION PROPERTY VERIFIER            ||");

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

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

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

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

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

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

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

  174.         System.out.println ("\t|                - Verified?                                        ||");

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

  176.         for (double a : aArray)
  177.         {
  178.             for (double b : bArray)
  179.             {
  180.                 for (double c : cArray)
  181.                 {
  182.                     Verifier (
  183.                         a,
  184.                         b,
  185.                         c,
  186.                         zArray,
  187.                         HypergeometricEqualityLemma.GaussContinuedFractionRecursive (
  188.                             a,
  189.                             b,
  190.                             c
  191.                         )
  192.                     );
  193.                 }
  194.             }
  195.         }

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

  197.         EnvManager.TerminateEnv();
  198.     }
  199. }