Special factorials: Difference between revisions

(Added 11l)
 
(10 intermediate revisions by 9 users not shown)
Line 52:
{{trans|Nim}}
 
<langsyntaxhighlight lang="11l">F sf(n)
V result = BigInt(1)
L(i) 2 .. n
Line 107:
L(n) [1, 2, 6, 24, 119, 120, 720, 5040, 40320, 362880, 3628800]
V r = rf(n)
print(f:‘{n:7}: {I r >= 0 {f:‘{r:2}’} E ‘undefined’}’)</langsyntaxhighlight>
 
{{out}}
Line 131:
3628800: 10
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68G's LONG LONG INT with default precision, which is long enough for the values needed for the task, except exponential factorial( 5 ).
The reverse factorial function uses a UNION(INT,STRING) for the result, so the result can either be an integer or the string "undefined".
<syntaxhighlight lang="algol68">
BEGIN # show the values of some "special factorials" #
 
# super factorial: returns the product of the factorials up to to n #
PROC sf = ( INT n )LONG LONG INT:
BEGIN
LONG LONG INT f := 1, p := 1;
FOR i TO n DO
f *:= i;
p *:= f
OD;
p
END # sf # ;
# hyper factorial: returns the product of k^k for k up to n #
PROC hf = ( INT n )LONG LONG INT:
BEGIN
LONG LONG INT p := 1;
FOR i TO n DO
TO i DO p *:= i OD
OD;
p
END # hf # ;
# alternating factorial: returns the sum of (-1)^(i-1)*i! for i up to n #
PROC af = ( INT n )LONG LONG INT:
BEGIN
LONG LONG INT s := 0;
LONG LONG INT f := 1;
INT sign := IF ODD n THEN 1 ELSE - 1 FI;
FOR i TO n DO
f *:= i;
s +:= sign * f;
sign := - sign
OD;
s
END # hf # ;
# exponential factorial: returns n^(n-1)^(n-2)... #
PROC xf = ( INT n )LONG LONG INT:
BEGIN
LONG LONG INT x := 1;
FOR i TO n DO
LONG LONG INT ix := 1;
TO SHORTEN SHORTEN x DO ix *:= i OD;
x := ix
OD;
x
END # hf # ;
# reverse factorial: returns k if n = k! for some integer k #
# "undefined" otherwise #
PROC rf = ( LONG LONG INT n )UNION( INT, STRING ):
IF n < 2
THEN 0
ELSE
LONG LONG INT f := 1;
INT i := 1;
WHILE f < n DO
f *:= i;
i +:= 1
OD;
IF f = n THEN i - 1 ELSE "undefined" FI
FI # rf # ;
 
print( ( "super factorials 0..9:", newline, " " ) );
FOR i FROM 0 TO 9 DO print( ( " ", whole( sf( i ), 0 ) ) ) OD;
print( ( newline, "hyper factorials 0..9:", newline, " " ) );
FOR i FROM 0 TO 9 DO print( ( " ", whole( hf( i ), 0 ) ) ) OD;
print( ( newline, "alternating factorials 0..9:", newline, " " ) );
FOR i FROM 0 TO 9 DO print( ( " ", whole( af( i ), 0 ) ) ) OD;
print( ( newline, "exponential factorials 0..4:", newline, " " ) );
FOR i FROM 0 TO 4 DO print( ( " ", whole( xf( i ), 0 ) ) ) OD;
 
[]INT rf test = ( 1, 2, 6, 24, 119, 120, 720, 5040, 40320, 362880, 3628800 );
print( ( newline, "reverse factorials:", newline ) );
FOR i FROM LWB rf test TO UPB rf test DO
INT tv = rf test[ i ];
print( ( whole( tv, -8 )
, " -> "
, CASE rf( tv )
IN ( INT iv ): whole( iv, 0 )
, ( STRING sv ): sv
OUT "Unexpected value returned by rf( " + whole( tv, 0 ) + " )"
ESAC
, newline
)
)
OD
 
END
</syntaxhighlight>
{{out}}
<pre>
super factorials 0..9:
1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
hyper factorials 0..9:
1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
alternating factorials 0..9:
0 1 1 5 19 101 619 4421 35899 326981
exponential factorials 0..4:
1 1 2 9 262144
reverse factorials:
1 -> 0
2 -> 2
6 -> 3
24 -> 4
119 -> undefined
120 -> 5
720 -> 6
5040 -> 7
40320 -> 8
362880 -> 9
3628800 -> 10
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">super: $ => [fold.seed:1 1..& [x y] -> x * factorial y]
 
hyper: $ => [fold.seed:1 1..& [x y] -> x * y^y]
 
alternating: $[n][
fold 1..n [x y] ->
x + (factorial y) * (neg 1)^n-y
]
 
exponential: $ => [fold.seed:1 0..& [x y] -> y^x]
 
rf: function [n][
if 1 = n -> return 0
b: a: <= 1
while -> n > a [
'b + 1
'a * b
]
if a = n -> return b
return null
]
 
print "First 10 superfactorials:"
print map 0..9 => super
 
print "\nFirst 10 hyperfactorials:"
print map 0..9 => hyper
 
print "\nFirst 10 alternating factorials:"
print map 0..9 => alternating
 
print "\nFirst 5 exponential factorials:"
print map 0..4 => exponential
 
prints "\nNumber of digits in $5: "
print size ~"|exponential 5|"
print ""
 
[1 2 6 24 120 720 5040 40320 362880 3628800 119]
| loop 'x -> print ~"rf(|x|) = |rf x|"</syntaxhighlight>
 
{{out}}
 
<pre>First 10 superfactorials:
1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
 
First 10 hyperfactorials:
1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
 
First 10 alternating factorials:
0.0 1 1 5 19 101 619 4421 35899 326981
 
First 5 exponential factorials:
0 1 2 9 262144
 
Number of digits in $5: 183231
 
rf(1) = 0
rf(2) = 2
rf(6) = 3
rf(24) = 4
rf(120) = 5
rf(720) = 6
rf(5040) = 7
rf(40320) = 8
rf(362880) = 9
rf(3628800) = 10
rf(119) = null</pre>
 
=={{header|Bruijn}}==
 
Implementation for numbers encoded in balanced ternary using Mixfix syntax defined in the Math module:
 
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/List .
:import std/Math .
 
factorial [∏ (+1) → 0 | [0]]
 
superfactorial [∏ (+1) → 0 | factorial]
 
hyperfactorial [∏ (+1) → 0 | [0 ** 0]]
 
alternating-factorial y [[=?0 0 ((factorial 0) - (1 --0))]]
 
exponential-factorial y [[=?0 0 (0 ** (1 --0))]]
 
:test ((factorial (+4)) =? (+24)) ([[1]])
:test ((superfactorial (+4)) =? (+288)) ([[1]])
:test ((hyperfactorial (+4)) =? (+27648)) ([[1]])
:test ((alternating-factorial (+3)) =? (+5)) ([[1]])
:test ((exponential-factorial (+4)) =? (+262144)) ([[1]])
 
invfac y [[[compare-case 1 (2 ++1 0) (-1) 0 (∏ (+0) → --1 | ++‣)]]] (+0)
 
:test ((invfac (+1)) =? (+0)) ([[1]])
:test ((invfac (+2)) =? (+2)) ([[1]])
:test ((invfac (+6)) =? (+3)) ([[1]])
:test ((invfac (+24)) =? (+4)) ([[1]])
:test ((invfac (+120)) =? (+5)) ([[1]])
:test ((invfac (+720)) =? (+6)) ([[1]])
:test ((invfac (+5040)) =? (+7)) ([[1]])
:test ((invfac (+40320)) =? (+8)) ([[1]])
:test ((invfac (+362880)) =? (+9)) ([[1]])
:test ((invfac (+3628800)) =? (+10)) ([[1]])
:test ((invfac (+119)) =? (-1)) ([[1]])
 
seq-a [((superfactorial 0) : ((hyperfactorial 0) : {}(alternating-factorial 0)))] <$> (iterate ++‣ (+0))
 
seq-b exponential-factorial <$> (iterate ++‣ (+0))
 
# return first 10/4 elements of both sequences
main [(take (+10) seq-a) : {}(take (+5) seq-b)]
</syntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <math.h>
#include <stdint.h>
#include <stdio.h>
Line 270 ⟶ 504:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>First 9 super factorials:
Line 298 ⟶ 532:
=={{header|C++}}==
{{trans|C}}
<langsyntaxhighlight lang="cpp">#include <cmath>
#include <cstdint>
#include <iostream>
Line 417 ⟶ 651:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>First 9 super factorials
Line 445 ⟶ 679:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: formatting io kernel math math.factorials math.functions
math.parser math.ranges prettyprint sequences sequences.extras ;
IN: rosetta-code.special-factorials
Line 480 ⟶ 714:
 
{ 1 2 6 24 120 720 5040 40320 362880 3628800 119 }
[ dup rf "rf(%d) = %u\n" printf ] each nl</langsyntaxhighlight>
{{out}}
<pre>
Line 512 ⟶ 746:
 
=={{header|Fermat}}==
<syntaxhighlight lang="text">Function Sf(n) = Prod<k=1, n>[k!].
 
Function H(n) = Prod<k=1, n>[k^k].
Line 532 ⟶ 766:
!!' ';
for n=1 to 10 do !!Rf(n!) od;
!!Rf(119)</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
Only goes up to H(7) due to overflow. Using a library with big int support is possible, but would only add bloat without being illustrative.
<langsyntaxhighlight lang="freebasic">function factorial(n as uinteger) as ulongint
if n<2 then return 1 else return n*factorial(n-1)
end function
Line 589 ⟶ 823:
print rf(factorial(n));" ";
next n
print rf(119)</langsyntaxhighlight>
 
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 703 ⟶ 937:
fmt.Printf("%4s <- rf(%d)\n", srfact, fact)
}
}</langsyntaxhighlight>
 
{{out}}
Line 760 ⟶ 994:
some of the specific tasks (some of the hyperfactorials and the computation of 5$)
but can otherwise be used.
<syntaxhighlight lang="jq">
<lang jq>
# for integer precision:
def power($b): . as $a | reduce range(0;$b) as $i (1; . * $a);
Line 806 ⟶ 1,040:
.i += 1
| .fact = .fact * .i)
| if .fact > $n then null else .i end;</langsyntaxhighlight>
''' The tasks:'''
<syntaxhighlight lang="jq">
<lang jq>
"First 10 superfactorials:",
(range(0;10) | sf),
Line 825 ⟶ 1,059:
"\nReverse factorials:",
( 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 119 | "\(rf) <- rf(\(.))")
</syntaxhighlight>
</lang>
{{out}}
Invocation: gojq -nr -f special-factorials.jq
Line 833 ⟶ 1,067:
=={{header|Julia}}==
No recursion.
<langsyntaxhighlight lang="julia">superfactorial(n) = n < 1 ? 1 : mapreduce(factorial, *, 1:n)
sf(n) = superfactorial(n)
 
Line 874 ⟶ 1,108:
println(rpad(n, 10), rf(n))
end
</langsyntaxhighlight>{{out}}
<pre>
N Superfactorial Hyperfactorial Alternating Factorial Exponential Factorial
Line 909 ⟶ 1,143:
=={{header|Kotlin}}==
{{trans|C}}
<langsyntaxhighlight lang="scala">import java.math.BigInteger
import java.util.function.Function
 
Line 1,024 ⟶ 1,258:
testInverse(3628800)
testInverse(119)
}</langsyntaxhighlight>
{{out}}
<pre>First 10 super factorials:
Line 1,052 ⟶ 1,286:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang="lua">-- n! = 1 * 2 * 3 * ... * n-1 * n
function factorial(n)
local result = 1
Line 1,158 ⟶ 1,392:
test_inverse(362880)
test_inverse(3628800)
test_inverse(119)</langsyntaxhighlight>
{{out}}
<pre>First 9 super factorials
Line 1,185 ⟶ 1,419:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[sf, expf]
sf[n_] := BarnesG[2 + n]
expf[n_] := Power @@ Range[n, 1, -1]
Line 1,192 ⟶ 1,426:
Hyperfactorial /@ Range[0, 9]
AlternatingFactorial /@ Range[0, 9]
expf /@ Range[0, 4]</langsyntaxhighlight>
{{out}}
<pre>{1, 1, 2, 12, 288, 34560, 24883200, 125411328000, 5056584744960000, 1834933472251084800000}
Line 1,201 ⟶ 1,435:
=={{header|Nim}}==
{{libheader|bignum}}
<langsyntaxhighlight Nimlang="nim">import math, strformat, strutils, sugar
import bignum
 
Line 1,265 ⟶ 1,499:
for n in [1, 2, 6, 24, 119, 120, 720, 5040, 40320, 362880, 3628800]:
let r = rf(n)
echo &"{n:7}: ", if r >= 0: &"{r:2}" else: "undefined"</langsyntaxhighlight>
 
{{out}}
Line 1,290 ⟶ 1,524:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature qw<signatures say>;
Line 1,313 ⟶ 1,547:
say '5$ has ' . length(5**4**3**2) . ' digits';
say 'rf : ' . join ' ', map { rf $_ } <1 2 6 24 120 720 5040 40320 362880 3628800>;
say 'rf(119) = ' . rf(119);</langsyntaxhighlight>
{{out}}
<pre>sf : 1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
Line 1,328 ⟶ 1,562:
which means sf/H/af/ef aren't usable independently as-is, but reconstitution should be easy enough
(along with somewhat saner and thread-safe routine-local vars).
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,388 ⟶ 1,622:
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Reverse factorials: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">24</span><span style="color: #0000FF;">,</span><span style="color: #000000;">120</span><span style="color: #0000FF;">,</span><span style="color: #000000;">720</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5040</span><span style="color: #0000FF;">,</span><span style="color: #000000;">40320</span><span style="color: #0000FF;">,</span><span style="color: #000000;">362880</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3628800</span><span style="color: #0000FF;">,</span><span style="color: #000000;">119</span><span style="color: #0000FF;">},</span><span style="color: #000000;">rf</span><span style="color: #0000FF;">))})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,398 ⟶ 1,632:
Reverse factorials: 0 2 3 4 5 6 7 8 9 10 undefined
</pre>
 
=={{header|PureBasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">Procedure.q factorial(n.i)
If n < 2
ProcedureReturn 1
Else
ProcedureReturn n * Factorial(n - 1)
EndIf
EndProcedure
 
Procedure.q sf(n.i)
p.i = 1
For k.i = 1 To n
p = p * factorial(k)
Next k
ProcedureReturn p
EndProcedure
 
Procedure.q H(n.i)
p.i = 1
For k.i = 1 To n
p = p * Pow(k, k)
Next k
ProcedureReturn p
EndProcedure
 
Procedure.q af(n.i)
s.i = 0
For i.i = 1 To n
s = s + Pow((-1), (n-i)) * factorial(i)
Next i
ProcedureReturn s
EndProcedure
 
Procedure.q ef(n.i)
If n < 2
ProcedureReturn 1
Else
ProcedureReturn Pow(n, ef(n-1))
EndIf
EndProcedure
 
Procedure.i rf(n.i)
r.i = 0
While #True
rr.i = factorial(r)
If rr > n : ProcedureReturn -1 : EndIf
If rr = n : ProcedureReturn r : EndIf
r + 1
Wend
EndProcedure
 
OpenConsole()
PrintN("First 8 ...")
PrintN(" superfactorials hyperfactorials alternating factorials")
For n.i = 0 To 7 ;con 8 o más necesitaríamos BigInt
PrintN(RSet(Str(sf(n)),16) + " " + RSet(Str(H(n)),19) + " " + RSet(Str(af(n)),19))
Next n
 
PrintN(#CRLF$ + #CRLF$ + "First 5 exponential factorials:")
For n.i = 0 To 4
Print(Str(ef(n)) + " ")
Next n
 
PrintN(#CRLF$ + #CRLF$ + "Reverse factorials:")
For n.i = 1 To 10
PrintN(RSet(Str(rf(factorial(n))),2) + " <- rf(" + Str(factorial(n)) + ")")
Next n
PrintN(RSet(Str(rf(factorial(119))),2) + " <- rf(119)")
 
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
 
=={{header|Python}}==
Line 1,403 ⟶ 1,710:
 
It also means less code :)
<syntaxhighlight lang="python">
<lang Python>
#Aamrun, 5th October 2021
 
Line 1,452 ⟶ 1,759:
 
print("\nrf(119) : " + inverseFactorial(119))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,474 ⟶ 1,781:
rf(119) : undefined
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery">
[ 1 & ] is odd ( n --> b )
 
[ 1 swap
[ 10 / dup 0 > while
dip 1+ again ]
drop ] is digitcount ( n --> n )
 
[ 1 1 rot times
[ i^ 1+ *
tuck * swap ]
drop ] is s! ( n --> n )
 
[ 1 swap times
[ i^ 1+ dup ** * ] ] is h! ( n --> n )
 
[ 0 1 rot times
[ i^ 1+ * tuck
i odd iff - else +
swap ]
drop ] is a! ( n --> n )
 
[ dup 0 = if done
dup 1 - recurse ** ] is **! ( n --> n )
 
[ this ] is undefined ( --> t )
 
[ dup 1 = iff
[ drop 0 ] done
1 swap
[ over /mod 0 != iff
[ drop undefined
swap ]
done
dip 1+
dup 1 = until
dip [ 1 - ] ]
drop ] is i! ( n --> n )
 
 
say "Superfactorials:" sp
10 times [ i^ s! echo sp ]
cr cr
say "Hyperfactorials:" sp
10 times [ i^ h! echo sp ]
cr cr
say "Alternating factorials: "
10 times [ i^ a! echo sp ]
cr cr
say "Exponential factorials: "
5 times [ i^ **! echo sp ]
cr cr
say "Number of digits in $5: "
5 **! digitcount echo
cr cr
say "Inverse factorials: "
' [ 1 2 6 24 119 120 720 5040
40320 362880 3628800 ]
witheach [ i! echo sp ]</syntaxhighlight>
 
{{out}}
 
<pre>Superfactorials: 1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
 
Hyperfactorials: 1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
 
Alternating factorials: 0 1 1 5 19 101 619 4421 35899 326981
 
Exponential factorials: 0 1 2 9 262144
 
Number of digits in $5: 183231
 
Inverse factorials: 0 2 3 4 undefined 5 6 7 8 9 10
</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>sub postfix:<!> ($n) { [*] 1 .. $n }
sub postfix:<$> ($n) { [R**] 1 .. $n }
 
Line 1,494 ⟶ 1,879:
 
say 'rf : ', map &rf, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800;
say 'rf(119) = ', rf(119).raku;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,506 ⟶ 1,891:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx">
<lang rexx>/*REXX program to compute some special factorials: superfactorials, hyperfactorials,*/
/* REXX program to calculate Special factorials */
/*───────────────────────────────────── alternating factorials, exponential factorials.*/
numeric digits 1000 /*allows humongous results to be shown.*/
call hdr 'super'; do j=0 to 9; $= $ sf(j); end; call tell
call hdr 'hyper'; do j=0 to 9; $= $ hf(j); end; call tell
call hdr 'alternating '; do j=0 to 9; $= $ af(j); end; call tell
call hdr 'exponential '; do j=0 to 5; $= $ ef(j); end; call tell
@= 'the number of decimal digits in the exponential factorial of '
say @ 5 " is:"; $= ' 'commas( efn( ef(5) ) ); call tell
@= 'the inverse factorial of'
do j=1 for 10; say @ right(!(j), 8) " is: " rf(!(j))
end /*j*/
say @ right(119, 8) " is: " rf(119)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x; != 1; do #=2 to x; != ! * #; end; return !
af: procedure; parse arg x; if x==0 then return 0; prev= 0; call af!; return !
af!: do #=1 for x; != !(#) - prev; prev= !; end; return !
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
ef: procedure; parse arg x; if x==0 | x==1 then return 1; return x**ef(x-1)
efn: procedure; parse arg x; numeric digits 9; x= x; parse var x 'E' d; return d+1
sf: procedure; parse arg x; != 1; do #=2 to x; != ! * !(#); end; return !
hf: procedure; parse arg x; != 1; do #=2 to x; != ! * #**#; end; return !
rf: procedure; parse arg x; do #=0 until f>=x; f=!(#); end; return rfr()
rfr: if x==f then return #; ?= 'undefined'; return ?
hdr: parse arg ?,,$; say 'the first ten '?"factorials:"; return
tell: say substr($, 2); say; $=; return</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
the first 10 superfactorials:
1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
 
numeric digits 35
the first 10 hyperfactorials:
1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
 
line = "superfactorials 0-9: "
the first 10 alternating factorials:
do n = 0 to 9
0 1 1 5 19 101 619 4421 35899 326981
line = line superfactorial(n)
end
say line
 
line = "hyperfactorials 0-9: "
the first 5 exponential factorials:
1do 1n 2= 90 262144to 9
line = line hyperfactorial(n)
end
say line
 
line = "alternating factorials 0-9:"
the number of decimal digits in the exponential factorial of 5 is:
do n = 0 to 9
183,231
line = line alternatingfactorial(n)
end
say line
 
line = "exponential factorials 0-4:"
the inverse factorial of 1 is: 0
do n = 0 to 4
the inverse factorial of 2 is: 2
line = line exponentialfactorial(n)
the inverse factorial of 6 is: 3
end
the inverse factorial of 24 is: 4
say line
the inverse factorial of 120 is: 5
 
the inverse factorial of 720 is: 6
thesay inverse"exponential factorial of5: 5040 is: 7",
length(format(exponentialfactorial(5), , , 0)) "digits"
the inverse factorial of 40320 is: 8
 
the inverse factorial of 362880 is: 9
theline = "inverse factorialfactorials: of 3628800 is: 10"
numbers = "1 2 6 24 120 720 5040 40320 362880 3628800 119"
the inverse factorial of 119 is: undefined
do i = 1 to words(numbers)
line = line inversefactorial(word(numbers,i))
end
say line
 
return
 
 
superfactorial: procedure
parse arg n
sf = 1
f = 1
do k = 1 to n
f = f * k
sf = sf * f
end
return sf
 
hyperfactorial: procedure
parse arg n
hf = 1
do k = 1 to n
hf = hf * k ** k
end
return hf
 
alternatingfactorial: procedure
parse arg n
af = 0
f = 1
do i = 1 to n
f = f * i
af = af + (-1) ** (n - i) * f
end
return af
 
exponentialfactorial: procedure
parse arg n
ef = 1
do i = 1 to n
ef = i ** ef
end
return ef
 
inversefactorial: procedure
parse arg f
n = 1
do i = 2 while n < f
n = n * i
end
if n = f then
if i > 2 then
return i - 1
else
return 0
else
return "undefined"
</syntaxhighlight>
{{out}}
<pre>
superfactorials 0-9: 1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
hyperfactorials 0-9: 1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
alternating factorials 0-9: 0 1 1 5 19 101 619 4421 35899 326981
exponential factorials 0-4: 1 1 2 9 262144
exponential factorial 5: 183231 digits
inverse factorials: 0 2 3 4 5 6 7 8 9 10 undefined
</pre>
 
=={{header|RPL}}==
Super factorial:
≪ 1 1 ROT '''FOR''' j j FACT * '''NEXT'''
≫ '<span style="color:blue">SFACT</span>' STO
Hyper factorial:
≪ 1 1 ROT '''FOR''' j j DUP ^ * '''NEXT'''
≫ '<span style="color:blue">HFACT</span>' STO
Alternating factorial:
≪ → n
≪ 0 '''IF''' n '''THEN'''
1 n '''FOR''' j -1 n j - ^ j FACT * + '''NEXT'''
≫ ≫ '<span style="color:blue">AFACT</span>' STO
Exponential factorial:
≪ '''IF''' DUP '''THEN'''
DUP 1 - 1 '''FOR''' j j ^ -1 '''STEP'''
'''ELSE''' NOT '''END'''
≫ '<span style="color:blue">EFACT</span>' STO
Inverse factorial - this function actually inverses Gamma(x+1), so its result is always defined:
≪ 'FACT(x)' OVER - 'x' ROT LN ROOT 'x' PURGE
≫ '<span style="color:blue">IFACT</span>' STO
 
≪ { } 0 9 FOR j j <span style="color:blue">SFACT</span> + NEXT ≫ EVAL
≪ { } 0 9 FOR j j <span style="color:blue">HFACT</span> + NEXT ≫ EVAL
≪ { } 0 9 FOR j j <span style="color:blue">AFACT</span> + NEXT ≫ EVAL
≪ { } 0 4 FOR j j <span style="color:blue">EFACT</span> + NEXT ≫ EVAL
3628800 <span style="color:blue">IFACT</span>
119 <span style="color:blue">IFACT</span>
{{out}}
<pre>
6: { 1 1 2 12 288 34560 24883200 125411328000 5.05658474496E+15 1.83493347225E+21 }
5: { 1 1 4 108 27648 86400000 4.0310784E+12 3.31976639877E+18 5.56964379417E+25 2.15779412229E+34 }
4: { 0 1 1 5 19 101 619 4421 35899 326981 }
3: { 0 1 2 9 262144 }
2: 10
1: 4.99509387149
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "bigint.s7i";
 
Line 1,657 ⟶ 2,124:
writeln("invFactorial(" <& n <& ") = " <& invFactorial(n));
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,686 ⟶ 2,153:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func sf(n) { 1..n -> prod {|k| k! } }
func H(n) { 1..n -> prod {|k| k**k } }
func af(n) { 1..n -> sum {|k| (-1)**(n-k) * k! } }
Line 1,738 ⟶ 2,205:
say ('rf : ', [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800].map(rf))
say ('rf(119) = ', rf(119) \\ 'nil')
say ('rf is defined for: ', 8.by { defined(rf(_)) }.join(', ' ) + ', ...')</langsyntaxhighlight>
{{out}}
<pre>
Line 1,755 ⟶ 2,222:
{{libheader|Wren-fmt}}
We've little choice but to use BigInt here as Wren can only deal natively with integers up to 2^53.
<langsyntaxhighlight ecmascriptlang="wren">import "./big" for BigInt
import "./fmt" for Fmt
 
var sf = Fn.new { |n|
Line 1,823 ⟶ 2,290:
System.print("Reverse factorials:")
var facts = [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 119]
for (fact in facts) Fmt.print("$4s <- rf($d)", rf.call(fact), fact)</langsyntaxhighlight>
 
{{out}}
55

edits