Combinatorics

(directly go to documentation on : !, !!, ***, Subfactorial, Bin, Eulerian, LeviCivita, Permutations. )

# 7. Combinatorics

! | factorial
!! | factorial and related functions
*** | factorial and related functions
Subfactorial | factorial and related functions
Bin | binomial coefficients
Eulerian | Eulerian numbers
LeviCivita | totally anti-symmetric Levi-Civita symbol
Permutations | get all permutations of a list

###

! -- factorial

###

!! -- factorial and related functions

###

*** -- factorial and related functions

###

Subfactorial -- factorial and related functions

##### Standard library

##### Calling format:

    n!
    n!!
    a *** b
    Subfactorial(m)

##### Parameters:

`m` -- integer `n` -- integer, half-integer, or list `a`, `b` -- numbers

##### Description:

The factorial function `n!` calculates the factorial of integer or half-integer numbers. For nonnegative integers, n! :=n*(n-1)*(n-2)*...*1. The factorial of half-integers is defined via Euler's Gamma function, z! :=Gamma(z+1). If n=0 the function returns 1.

The "double factorial" function `n!!` calculates n*(n-2)*(n-4)*.... This product terminates either with 1 or with 2 depending on whether n is odd or even. If n=0 the function returns 1.

The "partial factorial" function `a *** b` calculates the product a*(a+1)*... which is terminated at the least integer not greater than b. The arguments a and b do not have to be integers; for integer arguments, `a *** b` = b! /(a-1)!. This function is sometimes a lot faster than evaluating the two factorials, especially if a and b are close together. If a>b the function returns 1.

The `Subfactorial` function can be interpreted as the number of permutations of `m` objects in which no object appears in its natural place, also called "derangements."

The factorial functions are threaded, meaning that if the argument `n` is a list, the function will be applied to each element of the list.

Note: For reasons of Yacas syntax, the factorial sign `!` cannot precede other non-letter symbols such as `+` or `*`. Therefore, you should enter a space after `!` in expressions such as `x! +1`.

The factorial functions terminate and print an error message if the arguments are too large (currently the limit is n<65535) because exact factorials of such large numbers are computationally expensive and most probably not useful. One can call `Internal'LnGammaNum()` to evaluate logarithms of such factorials to desired precision.

##### Examples:

    In> 5!
    Out> 120;
    In> 1 * 2 * 3 * 4 * 5
    Out> 120;
    In> (1/2)!
    Out> Sqrt(Pi)/2;
    In> 7!!;
    Out> 105;
    In> 1/3 *** 10;
    Out> 17041024000/59049;
    In> Subfactorial(10)
    Out> 1334961;

##### See also:

Bin , Factorize , Gamma , !! , *** , Subfactorial .

###

Bin -- binomial coefficients

##### Standard library

##### Calling format:

    Bin(n, m)

##### Parameters:

`n`, `m` -- integers

##### Description:

This function calculates the binomial coefficient "n" above "m", which equals

n! /(m! *(n-m)!)

This is equal to the number of ways to choose "m" objects out of a total of "n" objects if order is not taken into account. The binomial coefficient is defined to be zero if "m" is negative or greater than "n"; `Bin(0,0)`=1.

##### Examples:

    In> Bin(10, 4)
    Out> 210;
    In> 10! / (4! * 6!)
    Out> 210;

##### See also:

! , Eulerian .

###

Eulerian -- Eulerian numbers

##### Standard library

##### Calling format:

    Eulerian(n,m)

##### Parameters:

`n`, `m` --- integers

##### Description:

The Eulerian numbers can be viewed as a generalization of the binomial coefficients, and are given explicitly by

Sum(j,0,k+1,(-1)^j*Bin(n+1,j)*(k-j+1)^n)
.

##### Examples:

    In> Eulerian(6,2)
    Out> 302;
    In> Eulerian(10,9)
    Out> 1;

##### See also:

Bin .

###

LeviCivita -- totally anti-symmetric Levi-Civita symbol

##### Standard library

##### Calling format:

    LeviCivita(list)

##### Parameters:

`list` -- a list of integers 1 .. n in some order

##### Description:

`LeviCivita` implements the Levi-Civita symbol. This is generally useful for tensor calculus. `list` should be a list of integers, and this function returns 1 if the integers are in successive order, eg. `LeviCivita( {1,2,3,...} )` would return 1. Swapping two elements of this list would return -1. So, `LeviCivita( {2,1,3} )` would evaluate to -1.

##### Examples:

    In> LeviCivita({1,2,3})
    Out> 1;
    In> LeviCivita({2,1,3})
    Out> -1;
    In> LeviCivita({2,2,3})
    Out> 0;

##### See also:

Permutations .

###

Permutations -- get all permutations of a list

##### Standard library

##### Calling format:

    Permutations(list)

##### Parameters:

`list` -- a list of elements

##### Description:

Permutations returns a list with all the permutations of the original list.

##### Examples:

    In> Permutations({a,b,c})
    Out> {{a,b,c},{a,c,b},{c,a,b},{b,a,c},
    {b,c,a},{c,b,a}};

##### See also:

LeviCivita .