For an alternative with double factorial (user defined) and Gamma (built-in) in Asymptote.
// http://asymptote.ualberta.ca/
// Double factorial.
int doublefactorial(int n){
int b=n;
while (n>2){
b=b*(n-2);
n=n-2;
}
return b;
}
for (int i=1; i<8; ++i)
write(string(i)+' !! = ',doublefactorial(i));
for (int i=3; i<8; ++i)
write('Gamma('+string(i)+') = '+string(i-1)+'! = ',gamma(i));
Output:
1 !! = 1
2 !! = 2
3 !! = 3
4 !! = 8
5 !! = 15
6 !! = 48
7 !! = 105
Gamma(3) = 2! = 2
Gamma(4) = 3! = 6
Gamma(5) = 4! = 24
Gamma(6) = 5! = 120
Gamma(7) = 6! = 720
declare function
in the manual\tikzmath{ function gamma(\x) { if isodd(2*\x) then { \pgfmathsetmacro\myresult{1} for \i in {2\x,2\x-2,...,1}{ \pgfmathsetmacro{\myresult}{\myresult * \x} }; return \myresult * sqrt(pi) / 2^(\x-0.5); } else { return factorial(\x-1); }; }; }
- I get! Undefined control sequence. <argument> \myresult
... any suggestion?