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 /** 20 * <a href="https://mathworld.wolfram.com/BetaFunction.html">Beta function</a>. 21 * 22 * <p>\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} = \frac{(a-1)!\ (b-1)!}{(a+b-1)!} \] 23 * 24 * <p>where \( \Gamma(z) \) is the gamma function. 25 * 26 * <p>This code has been adapted from the <a href="https://www.boost.org/">Boost</a> 27 * {@code c++} implementation {@code <boost/math/special_functions/beta.hpp>}. 28 * 29 * @see 30 * <a href="https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html"> 31 * Boost C++ Beta function</a> 32 * @since 1.1 33 */ 34 public final class Beta { 35 36 /** Private constructor. */ 37 private Beta() { 38 // intentionally empty. 39 } 40 41 /** 42 * Computes the value of the 43 * <a href="https://mathworld.wolfram.com/BetaFunction.html"> 44 * beta function</a> B(a, b). 45 * 46 * <p>\[ B(a, b) = \frac{\Gamma(a)\ \Gamma(b)}{\Gamma(a+b)} \] 47 * 48 * <p>where \( \Gamma(z) \) is the gamma function. 49 * 50 * @param a Parameter {@code a}. 51 * @param b Parameter {@code b}. 52 * @return the beta function \( B(a, b) \). 53 */ 54 public static double value(double a, 55 double b) { 56 return BoostBeta.beta(a, b); 57 } 58 }