Factorial: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "{{Built-in|Factorial|!}} is a monadic scalar function which gives the factorial of a non-negative integer. Factorial shares the glyph <sour...")
 
No edit summary
Line 1: Line 1:
{{Built-in|Factorial|!}} is a [[monadic]] [[scalar function]] which gives the [[wikipedia:factorial|factorial]] of a non-negative integer. Factorial shares the [[glyph]] <source lang=apl inline>!</source> with the dyadic arithmetic function [[Binomial]].
{{Built-in|Factorial|!}} is a [[monadic]] [[scalar function]] which gives the [[wikipedia:factorial|factorial]] of a non-negative integer. Factorial takes its [[glyph]] <source lang=apl inline>!</source> from [[Comparison_with_traditional_mathematics#Prefix|traditional mathematics]] but, like all [[monadic function]]s, takes its argument on the right  <source lang=apl inline>!Y</source> instead of traditional mathematics' <math>Y!</math>. It shares the glyph with the dyadic arithmetic function [[Binomial]].


== Examples ==
== Examples ==
Line 14: Line 14:
== Extended definition ==
== Extended definition ==


In multiple implementations, this function has an extended definition using the [[wikipedia:Gamma function|Gamma function]] Gamma(n), so that it is defined for real and [[complex]] numbers. Because Gamma(n) equals (n-1)!, <source lang=apl inline>!Y</source> is defined as Gamma(Y+1).
In multiple implementations, this function has an extended definition using the [[wikipedia:Gamma function|Gamma function]] <math>\Gamma(n)</math>, so that it is defined for real and [[complex]] numbers. Because <math>\Gamma(n)</math> equals <math>(n-1)!</math>, <source lang=apl inline>!Y</source> is defined as <math>\Gamma(Y+1)</math>.


<source lang=apl>
<source lang=apl>

Revision as of 19:07, 3 June 2020

!

Factorial (!) is a monadic scalar function which gives the factorial of a non-negative integer. Factorial takes its glyph ! from traditional mathematics but, like all monadic functions, takes its argument on the right !Y instead of traditional mathematics' . It shares the glyph with the dyadic arithmetic function Binomial.

Examples

The factorial of a positive integer n is defined as the product of 1 to n inclusive.

      !0 1 2 3 4
1 1 2 6 24
      ×/⍳4
24

Extended definition

In multiple implementations, this function has an extended definition using the Gamma function , so that it is defined for real and complex numbers. Because equals , !Y is defined as .

      !¯1.2 0.5 2.7
¯5.821148569 0.8862269255 4.170651784
      !2J1 ¯2J¯1
0.962865153J1.339097176 ¯0.1715329199J¯0.3264827482
Works in: Dyalog APL

The Gamma function diverges at 0 or negative numbers, so !Y is undefined at negative integers.

      !¯1
DOMAIN ERROR
 !¯1        
 ∧
Works in: Dyalog APL

In J, where literal infinity is supported, negative integer factorial evaluates to positive infinity _ (if the argument is odd) or negative infinity __ (if even). This corresponds to the positive-side limit of the Gamma function.

      !_1 _2 _3 _4
_ __ _ __
Works in: J

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