答案1
通过创建双阶乘的递归定义,我能够为 Gamma 函数的整数和半整数找到解决方案。可能效率不高,但确实有效。
\tikzmath{
function doublefactorial(\x) {
if (\x > 1) then {
return \x * doublefactorial(\x-2);
} else {
return 1;
};
};
% this definition only works for positive integers and half integers
function gamma(\x) {
if isodd(int(2*\x)) then {
return doublefactorial(int(2*\x-2))* sqrt(pi) / 2^(\x-0.5);
} else {
return factorial(int(\x-1));
};
};
}
答案2
在 Asymptote 中,可以使用双阶乘(用户定义)和 Gamma(内置)作为替代方案。
// 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));
输出:
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