gmp_binomial


gmp apg

CALCULATE the binomial coefficient.

How many ways there are to choose a certain number of things out of larger set.


This function is only available in PHP 7.3.0 or later

Binomial coefficient - from Statists How To 

Binomial coefficient - from Wikipedia 







This function calculates the binomial coeficent C(n,k).



<?php

GMP gmp_binomial 
GMP|int|string $nint $k )


where,

$n The number of items

$k 
The number of item to choose

?>
 

$n


The number of items.



$k


The number of items to choose.



  1 EXERCISE   

<?php

$dn01 
= [ 'Thumb''Pointer''Middle''Ring''Pinky' ];

$n01 count($dn01);

echo 
$n01 ' finger names are:<br><br>';

for(
$x01 0$x01 <= 4$x01++)
{
    
    if(
$x01 <= 2)
    {
echo 
'(' . ($x01+1) . ') ' $dn01[$x01] . ', ';
    } 
    elseif(
$x01 == 3)
    {
    echo 
'(' . ($x01+1) . ') ' $dn01[$x01] . ' and ';    
    }
    else
    {
    echo 
'(' . ($x01+1) . ') ' $dn01[$x01] . '.<br><br><br>';    
    }
}

echo 
'How many subsets of 3 finger names 
                    we can obtain from its 7 names?<br><br>'
;

echo 
'Such an answer will be given by: ';

$ssa01 gmp_binomial($n013);

echo 
'<br><br>gmp_binomial( ' $n01 ', 3 ) = ' $ssa01 
                             
' subsets.<br><br>The same thing as:<br><br>';

$ssb01 gmp_div(gmp_fact($n01), 
                     
gmp_mul(gmp_fact(3), 
                                   
gmp_fact(gmp_sub($n013))));

echo 
'gmp_div(gmp_fact(' $n01 '), 
                   gmp_mul(gmp_fact(3), 
                                  gmp_fact(gmp_sub(' 
$n01 ' , 3)))) = ' 
                                     
$ssb01 ' subsets.<br><br>
                                     That is, a combination of 5 items 3 
                                     through 3 produces the following
                                                                subsets:<br><br>'
;

echo 
'(01) Thumb, Pointer and Middley<br>
(02) Thumb, Pointer and Ring<br>
(03) Thumb, Pointer and Pinky<br>

(04) Thumb, Middley and Ring<br>
(05) Thumb, Middley and Pinky<br>
(06) Thumb, Ring and Pinky<br>

(07) Pointer, Middle and Ring<br>
(08) Pointer, Middle and Pinky<br>
(09) Pointer, Ring and Pinky<br>

(10) Middle, Ring and Pinky.'
;

?> 

 RESULT   

5 finger names are:

(1) Thumb, (2) Pointer, (3) Middle, (4) Ring and (5) Pinky.


How many subsets of 3 finger names we can obtain from its 7 names?

Such an answer will be given by:

gmp_binomial( 5, 3 ) = 10 subsets.

The same thing as:


cnk

gmp_div(gmp_fact(5), gmp_mul(gmp_fact(3), gmp_fact(gmp_sub(5 , 3)))) = 10 subsets.

The combination of 5 items 3 through 3 produces the following subsets:

(01) Thumb, Pointer and Middley
(02) Thumb, Pointer and Ring
(03) Thumb, Pointer and Pinky
(04) Thumb, Middley and Ring
(05) Thumb, Middley and Pinky
(06) Thumb, Ring and Pinky
(07) Pointer, Middle and Ring
(08) Pointer, Middle and Pinky
(09) Pointer, Ring and Pinky
(10) Middle, Ring and Pinky.