Logo

LPERMUTA

Updated 2024-03-08 21:46:48.877000

Syntax

SELECT [westclintech].[wct].[LPERMUTA] (
   <@n, int,>
  ,<@k, int,>)

Description

Use the scalar function LPERMUTA to calculate the natural logarithm of the PERMUTATIONA function. The PERMUTATIONA function calculates the number of permutations with replacement defined as:

P_{k,n}=n^k

Arguments

@n

Number of items.

@k

Number chosen.

Return Type

float

Remarks

If n < 0 and k < 0 then NULL is returned.

If k < 0 then NULL is returned.

Examples

Example #1

SELECT wct.LPERMUTA(10, 3) as LPERMUTA;

This produces the following result.

{"columns":[{"field":"LPERMUTA","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"LPERMUTA":"6.90775527898214"}]}

Example #2

Calculate the probability of 2 people having the same birthday in a room containing n people.

SELECT x.n,

       1 - EXP(wct.LPERMUT(365, x.n) - wct.LPERMUTA(365, x.n)) as [p(n)]

FROM

(

    VALUES

        (10),

        (20),

        (22),

        (23),

        (30),

        (57)

) x (n);

This produces the following result.

{"columns":[{"field":"n","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"p(n)","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"n":"10","p(n)":"0.116948177711411"},{"n":"20","p(n)":"0.411438383580767"},{"n":"22","p(n)":"0.475695307662689"},{"n":"23","p(n)":"0.507297234324094"},{"n":"30","p(n)":"0.706316242719354"},{"n":"57","p(n)":"0.990122459341174"}]}

See Also

FACTORIALPOWER - the step-h factorial power x(n,h)

LCHOOSE - Natural logarithm of the binomial coefficient

LPERMUT - Calculate the natural logarithm of the PERMUT function.

PERMUT - calculate the number of permutations for a given number objects that can be selected from a number of objects

PERMUTATIONA - number of permutations with repetition