# openfermion.transforms.repconversions.weyl_ordering.binom

binom(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])

binom(x, y, out=None)

Binomial coefficient considered as a function of two real variables.

For real arguments, the binomial coefficient is defined as

.. math::

\binom{x}{y} = \frac{\Gamma(x + 1)}{\Gamma(y + 1)\Gamma(x - y + 1)} =
\frac{1}{(x + 1)\mathrm{B}(x - y + 1, y + 1)}


Where :math:\Gamma is the Gamma function (gamma) and :math:\mathrm{B} is the Beta function (beta) [1]_.

## Parameters

x, y: array_like Real arguments to :math:\binom{x}{y}. out : ndarray, optional Optional output array for the function values

## Returns

scalar or ndarray Value of binomial coefficient.

comb : The number of combinations of N things taken k at a time.

## Notes

The Gamma function has poles at non-positive integers and tends to either positive or negative infinity depending on the direction on the real line from which a pole is approached. When considered as a function of two real variables, :math:\binom{x}{y} is thus undefined when x is a negative integer. binom returns nan when x is a negative integer. This is the case even when x is a negative integer and y an integer, contrary to the usual convention for defining :math:\binom{n}{k} when it is considered as a function of two integer variables.

## Examples

The following examples illustrate the ways in which binom differs from the function comb.

from scipy.special import binom, comb


When exact=False and x and y are both positive, comb calls binom internally.

x, y = 3, 2
(binom(x, y), comb(x, y), comb(x, y, exact=True))
(3.0, 3.0, 3)


For larger values, comb with exact=True no longer agrees with binom.

x, y = 43, 23
(binom(x, y), comb(x, y), comb(x, y, exact=True))
(960566918219.9999, 960566918219.9999, 960566918220)


binom returns nan when x is a negative integer, but is otherwise defined for negative arguments. comb returns 0 whenever one of x or y is negative or x is less than y.

x, y = -3, 2
(binom(x, y), comb(x, y), comb(x, y, exact=True))
(nan, 0.0, 0)

x, y = -3.1, 2.2
(binom(x, y), comb(x, y), comb(x, y, exact=True))
(18.714147876804432, 0.0, 0)

x, y = 2.2, 3.1
(binom(x, y), comb(x, y), comb(x, y, exact=True))
(0.037399983365134115, 0.0, 0)

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]