# std::beta,std::betaf,std::betal (3) - Linux Man Pages

## NAME

std::beta,std::betaf,std::betal - std::beta,std::betaf,std::betal

## Synopsis

double beta( double x, double y );
float betaf( float x, float y ); (1) (since C++17)
long double betal( long double x, long double y );
Promoted beta( Arithmetic x, Arithmetic y ); (2) (since C++17)

1) Computes the beta_function of x and y.
2) A set of overloads or a function template for all combinations of arguments of arithmetic type not covered by (1). If any argument has integral_type, it is cast to double. If any argument is long double, then the return type Promoted is also long double, otherwise the return type is always double.

## Parameters

x, y - values of a floating-point or integral type

## Return value

If no errors occur, value of the beta function of x and y, that is ∫1
0tx-1
(1-t)(y-1)
dt, or, equivalently,

Γ(x)Γ(y)
Γ(x+y)

is returned.

## Error handling

Errors may be reported as specified in math_errhandling

* If any argument is NaN, NaN is returned and domain error is not reported
* The function is only required to be defined where both x and y are greater than zero, and is allowed to report a domain error otherwise.

## Notes

Implementations that do not support C++17, but support ISO_29124:2010, provide this function if __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before including any standard library headers.
Implementations that do not support ISO 29124:2010 but support TR 19768:2007 (TR1), provide this function in the header tr1/cmath and namespace std::tr1
An implementation of this function is also available_in_boost.math
beta(x, y) equals beta(y, x)
When x and y are positive integers, beta(x,y) equals $$\frac{(x-1)!(y-1)!}{(x+y-1)!}$$

(x-1)!(y-1)!
(x+y-1)!

.

Binomial coefficients can be expressed in terms of the beta function: $$\binom{n}{k} = \frac{1}{(n+1)B(n-k+1,k+1)}$$⎛

⎝n
k⎞

⎠=

1
(n+1)Β(n-k+1,k+1)

## Example

// Run this code

#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
double binom(int n, int k) { return 1/((n+1)*std::beta(n-k+1,k+1)); }
int main()
{
std::cout << "Pascal's triangle:\n";
for(int n = 1; n < 10; ++n) {
std::cout << std::string(20-n*2, ' ');
for(int k = 1; k < n; ++k)
std::cout << std::setw(3) << binom(n,k) << ' ';
std::cout << '\n';
}
}

## Output:

Pascal's triangle:

2
3 3
4 6 4
5 10 10 5
6 15 20 15 6
7 21 35 35 21 7
8 28 56 70 56 28 8
9 36 84 126 126 84 36 9

Weisstein,_Eric_W._"Beta_Function." From MathWorld--A Wolfram Web Resource.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.4869767129421234, "perplexity": 3898.3979975680545}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-21/segments/1620243988725.79/warc/CC-MAIN-20210506023918-20210506053918-00039.warc.gz"}