Binomial

From APL Wiki
Revision as of 21:47, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

Binomial (!) is a dyadic scalar function which gives the binomial coefficient between the two arguments. The argument order <syntaxhighlight lang=apl inline>k!n</source> is reversed compared to most of traditional mathematical notation's alternative notations, for example and , but not others, like . Binomial shares the glyph <syntaxhighlight lang=apl inline>!</source> with the monadic arithmetic function Factorial.

Examples

For non-negative integer arguments, the binomial coefficient <syntaxhighlight lang=apl inline>k!n</source> is equal to the number of ways to choose k items out of n distinct items. For example, <syntaxhighlight lang=apl inline>3!5</source> is 10 because there are 10 ways to pick 3 items out of 5: 123, 124, 125, 134, 135, 145, 234, 235, 245, 345.

<syntaxhighlight lang=apl>

     0 1 2 3 4 5!5

1 5 10 10 5 1 </source>

<syntaxhighlight lang=apl inline>k!n</source> also corresponds to the k-th value (zero-indexed) on the n-th row (also zero-indexed) of Pascal's triangle.

<syntaxhighlight lang=apl>

     ⍉∘.!⍨ 0,⍳5

1 0 0 0 0 0 1 1 0 0 0 0 1 2 1 0 0 0 1 3 3 1 0 0 1 4 6 4 1 0 1 5 10 10 5 1

</source>

Works in: Dyalog APL

Properties

The value of <syntaxhighlight lang=apl inline>X!Y</source> equals <syntaxhighlight lang=apl inline>(!Y)÷(!X)×!Y-X</source>.

<syntaxhighlight lang=apl>

     Alt←{(!⍵)÷(!⍺)×!⍵-⍺}
     0 1 2 3 4 5 Alt 5

1 5 10 10 5 1 </source>

In multiple implementations where Factorial is extended to use the Gamma function  , Binomial is defined to use the above equality for non-integers. In that case, the Beta function   becomes closely related to the Binomial, giving the identity     <syntaxhighlight lang=apl inline>÷Y×(X-1)!X+Y-1</source>.

<syntaxhighlight lang=apl>

     1 1.2 1.4 1.6 1.8 2!5

5 6.105689248 7.219424686 8.281104786 9.227916704 10

     2!3j2

1J5

</source>

Works in: Dyalog APL

External links

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector