Beta.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.numbers.gamma;

  18. /**
  19.  * <a href="https://mathworld.wolfram.com/BetaFunction.html">Beta function</a>.
  20.  *
  21.  * <p>\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} = \frac{(a-1)!\ (b-1)!}{(a+b-1)!} \]
  22.  *
  23.  * <p>where \( \Gamma(z) \) is the gamma function.
  24.  *
  25.  * <p>This code has been adapted from the <a href="https://www.boost.org/">Boost</a>
  26.  * {@code c++} implementation {@code <boost/math/special_functions/beta.hpp>}.
  27.  *
  28.  * @see
  29.  * <a href="https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html">
  30.  * Boost C++ Beta function</a>
  31.  * @since 1.1
  32.  */
  33. public final class Beta {

  34.     /** Private constructor. */
  35.     private Beta() {
  36.         // intentionally empty.
  37.     }

  38.     /**
  39.      * Computes the value of the
  40.      * <a href="https://mathworld.wolfram.com/BetaFunction.html">
  41.      * beta function</a> B(a, b).
  42.      *
  43.      * <p>\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} \]
  44.      *
  45.      * <p>where \( \Gamma(z) \) is the gamma function.
  46.      *
  47.      * @param a Parameter {@code a}.
  48.      * @param b Parameter {@code b}.
  49.      * @return the beta function \( B(a, b) \).
  50.      */
  51.     public static double value(double a,
  52.                                double b) {
  53.         return BoostBeta.beta(a, b);
  54.     }
  55. }