Math::SpecialFunctions
Math::SpecialFunctions
Raku package for mathematical special functions.
Installation
From Zef ecosytem:
zef install Math::SpecialFunctionsFrom GitHub:
zef install https://github.com/antononcube/Raku-Math-SpecialFunctions.gitUsage examples
The subsections below show example usage for the currently implemented functions.
Factorial
use Math::SpecialFunctions;
.say for (^11) Z=> (^11)ยป.&factorial# 0 => 1
# 1 => 1
# 2 => 2
# 3 => 6
# 4 => 24
# 5 => 120
# 6 => 720
# 7 => 5040
# 8 => 40320
# 9 => 362880
# 10 => 3628800The function factorial seems reasonably fast:
my $tstart = now;
for ^1_000 { factorial($_ * (1..6).pick ) }
my $tend = now;
say "Total time {$tend - $tstart}";
say "Average time {($tend - $tstart) / 1_000}";# Total time 0.900635487
# Average time 0.000900635487Binomial
Pascal's triangle:
for (^6) -> $n {
say do for (0..$n) -> $k {
binomial($n, $k), " "
}.join
}# 1
# 1 1
# 1 2 1
# 1 3 3 1
# 1 4 6 4 1
# 1 5 10 10 5 1Bernoulli-B
For odd
n, the Bernoulli numbers are equal to0, exceptB[1] = -1/2.bernoulli-bcan be evaluated to arbitrary numerical precision. (UsesFatRat.)
bernoulli-b(60).nude# (-1215233140483755572040304994079820246041491 56786730)Gamma function
The implementation uses approximation formula with machine numbers.
Both function names
gammaandฮcan be used.The property
ฮ(z + 1) = z * ฮ(z)holds.
Synonyms demo:
[gamma(0.3), ฮ(0.3)]# [2.991568987687589 2.991568987687589]Show that the property above holds:
gamma(2.3) - 1.3 * gamma(1.3)# 0TODO
TODO Implementation
TODO Incomplete gamma function
TODO Generalized incomplete gamma function
TODO Digamma function