4,493
edits
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com") Tags: Mobile edit Mobile web edit |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 1: | Line 1: | ||
{{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>!</ | {{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>!</syntaxhighlight> 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</syntaxhighlight> instead of traditional mathematics' <math>Y!</math>. It shares the glyph with the dyadic arithmetic function [[Binomial]]. | ||
== Examples == | == Examples == | ||
Line 10: | Line 10: | ||
×/⍳4 | ×/⍳4 | ||
24 | 24 | ||
</ | </syntaxhighlight> | ||
== Extended definition == | == Extended definition == | ||
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</ | 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</syntaxhighlight> is defined as <math>\Gamma(Y+1)</math>. | ||
<source lang=apl> | <source lang=apl> | ||
Line 21: | Line 21: | ||
!2J1 ¯2J¯1 | !2J1 ¯2J¯1 | ||
0.962865153J1.339097176 ¯0.1715329199J¯0.3264827482 | 0.962865153J1.339097176 ¯0.1715329199J¯0.3264827482 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
The Gamma function diverges at 0 or negative numbers, so <source lang=apl inline>!Y</ | The Gamma function diverges at 0 or negative numbers, so <source lang=apl inline>!Y</syntaxhighlight> is undefined at negative integers. | ||
<source lang=apl> | <source lang=apl> | ||
Line 30: | Line 30: | ||
!¯1 | !¯1 | ||
∧ | ∧ | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
In [[J]], where literal [[infinity]] is supported, negative integer factorial evaluates to positive infinity <source lang=j inline>_</ | In [[J]], where literal [[infinity]] is supported, negative integer factorial evaluates to positive infinity <source lang=j inline>_</syntaxhighlight> (if the argument is odd) or negative infinity <source lang=j inline>__</syntaxhighlight> (if even). This corresponds to the positive-side limit of the Gamma function. | ||
<source lang=j> | <source lang=j> | ||
!_1 _2 _3 _4 | !_1 _2 _3 _4 | ||
_ __ _ __ | _ __ _ __ | ||
</ | </syntaxhighlight>{{Works in|[[J]]}} | ||
== External links == | == External links == |