This site is supported by donations to The OEIS Foundation.

Template:Binomial

From OeisWiki
Jump to: navigation, search
The {{binomial}}, {{binom}} or {{C(n,k)}} mathematical formatting template and/or mathematical function template returns either the typeset (HTML+CSS or LaTeX) expression of the the binomial coefficient or the numerical result, for nonnegative integers
n
and
k
, of
(  nk  )
.

Usage

{{binomial|nonnegative integer n|nonnegative integer k|format}}

or

{{binom|nonnegative integer n|nonnegative integer k|format}}

or

{{C(n,k)|nonnegative integer n|nonnegative integer k|format}}

where format is

  • htm: HTML+CSS text style (default), or
  • HTM: HTML+CSS display style, or
  • tex: LaTeX text style, or
  • TEX: LaTeX display style, or
  • #: numerical result.

Examples

The code

: before {{math|{{binom|''n''|''k''|htm}}|&}} after

yields the text style HTML+CSS

before 
(  nk  )
after

The code

: before {{math|{{binom|''n''|''k''|tex}}|$}} after

yields the text style LaTeX

before after

The code

{{indent}}{{math|{{binom|''n''|''k''|HTM}}|&&}}

yields the display style HTML+CSS

     
(
n
k
)

The code

: {{math|{{binom|''n''|''k''|TEX}}|$$}}

yields the display style LaTeX

The code

: before {{math|{{binom|9|3|htm}} {{=}} {{binom|9|3|#}}|&}} after

yields the text style HTML+CSS

before 
(  93  ) = 84
after

The code

: before {{math|{{binom|9|3|tex}} {{=}} {{binom|9|3|#}}|$}} after

yields the text style LaTeX

See Template:Binomial/doc (transcluding the /doc subpage is one transclusion too many)

Examples with numerical result

The algorithm for the evaluation of binomial coefficients uses

     
(
n
k
):=
n(n  − k )
k !
 = 
n  − k  − 1

i  = 0
 (ni )
k !
, n ≥ 0, k ≥ 0,

where
n(m)   :=  
m  − 1

i  = 0
 (n  −  i )
is the falling factorial.

Examples with numerical result: valid input

Numerical tests.— Daniel Forgues 21:55, 11 March 2018 (EDT)
Code Result Comment Code Result Comment
{{binomial|0|0|#}} 1 Green tickY {{binom|0|1|#}} 0 Green tickY
{{binomial|1|1|#}} 1 Green tickY {{binom|2|0|#}} 1 Green tickY
{{binomial|2|1|#}} 2 Green tickY {{binom|2|2|#}} 1 Green tickY
{{C(n,k)|3|1|#}} 3 Green tickY {{C(n,k)|4|2|#}} 6 Green tickY
{{C(n,k)|5|3|#}} 10 Green tickY {{C(n,k)|6|2|#}} 15 Green tickY
{{C(n,k)|7|3|#}} 35 Green tickY {{C(n,k)|8|3|#}} 56 Green tickY
{{C(n,k)|9|3|#}} 84 Green tickY {{C(n,k)|10|3|#}} 120 Green tickY
{{C(n,k)|11|4|#}} 330 Green tickY {{C(n,k)|12|4|#}} 495 Green tickY
{{C(n,k)|13|5|#}} 1287 Green tickY {{C(n,k)|14|5|#}} 2002 Green tickY
{{C(n,k)|15|3|#}} 455 Green tickY {{C(n,k)|16|3|#}} 560 Green tickY
{{C(n,k)|17|3|#}} 680 Green tickY {{C(n,k)|17|23|#}} 0 Green tickY
{{C(n,k)|30|21|#}} 14307150 Green tickY {{C(n,k)|47|13|#}} 140676848445 Green tickY
{{C(n,k)|48|19|#}} 11541847896480 Green tickY {{C(n,k)|49|19|#}} 18851684897585 Red crossY (  4919  ) = 18851684897584 (rounding error)*
{{C(n,k)|80|3|#}} 82160 Green tickY {{C(n,k)|83|3|#}} 91881 Green tickY
{{C(n,k)|99|31|#}} 4.5764000431736E+25 Green tickY {{C(n,k)|91|3|#}} 121485 Green tickY


* 
(  4919  ) = 49(30) / 19! = 2293215102242267478449061888000 / 121645100408832000 = 18851684897584
(rounding error).

Examples with numerical result: invalid input

Code Result
{{C(n,k)|-1|3|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|0.5|3|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|text|3|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|6 blobs|3|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|12|nine|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|99|43|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.
{{C(n,k)|99|33|#}} C(n,k) error: First and second arguments, n and k, must be nonnegative integers, with k up to 32.

See also