Data update

This commit is contained in:
Ingy döt Net 2023-10-02 18:11:16 -07:00
parent 796d366b97
commit 35bcdeebf8
504 changed files with 7045 additions and 610 deletions

View file

@ -1,4 +1,4 @@
( ( C
( C
= n k coef
. !arg:(?n,?k)
& (!n+-1*!k:<!k:?k|)
@ -11,6 +11,35 @@
)
& !coef
)
& ( compileBinomialFunctionThatDoesFloatingPointCalculations
=
. new
$ ( UFP
,
' ( (s.n) (s.k)
. "**************************************************************
*** Notice the difference between the following four lines ***
*** of code and the much shorter (!n+-1*!k:<!k:?k|) in ***
*** function C above. UFP grammar is simpler than usual ***
*** Bracmat grammar. UFP code is therefore less terse. ***
**************************************************************"
& !n+-1*!k:?n-k
& ( !n-k:<!k&!n-k:?k
|
)
& 1:?coef
& whl
' ( !k:>0
& !coef*!n*!k^-1:?coef
& !k+-1:?k
& !n+-1:?n
)
& !coef
)
)
)
& compileBinomialFunctionThatDoesFloatingPointCalculations$
: ?binom
& ( P
= n k result
. !arg:(?n,?k)
@ -23,6 +52,25 @@
)
& !result
)
& ( compilePermutationFunctionThatDoesFloatingPointCalculations
=
. new
$ ( UFP
,
' ( (s.n) (s.k)
. !n+-1*!k:?k
& 1:?result
& whl
' ( !n:>!k
& !n*!result:?result
& !n+-1:?n
)
& !result
)
)
)
& compilePermutationFunctionThatDoesFloatingPointCalculations$
: ?permu
& 0:?i
& whl
' ( 1+!i:~>12:?i
@ -33,7 +81,8 @@
& whl
' ( 10+!i:~>60:?i
& div$(!i.3):?k
& out$(!i C !k "=" C$(!i,!k))
& out$(!i Cn !k "= " C$(!i,!k))
& out$(!i Cf !k "=" (binom..go)$(!i,!k))
)
& ( displayBig
=
@ -45,12 +94,26 @@
& whl
' ( !is:%?i ?is
& div$(!i.3):?k
& out$(str$(!i " P " !k " = " displayBig$(P$(!i,!k))))
& out
$ ( str
$ (!i " Pn " !k " = " displayBig$(P$(!i,!k)))
)
& out
$ ( str
$ (!i " Pf " !k " = " (permu..go)$(!i,!k))
)
)
& 0:?i
& whl
' ( 100+!i:~>1000:?i
& div$(!i.3):?k
& out$(str$(!i " C " !k " = " displayBig$(C$(!i,!k))))
& out
$ ( str
$ (!i " Cn " !k " = " displayBig$(C$(!i,!k)))
)
& out
$ ( str
$ (!i " Cf " !k " = " (binom..go)$(!i,!k))
)
)
);
& all done;

View file

@ -0,0 +1,32 @@
const std = @import("std");
const num = f64;
pub fn perm(n: num, k: num) num {
var result: num = 1;
var i: num = 0;
while (i < k) : (i += 1) {
result *= n - i;
}
return result;
}
pub fn comb(n: num, k: num) num {
return perm(n, k) / perm(k, k);
}
pub fn main() !void {
var stdout = std.io.getStdOut().writer();
const p: num = 12;
const c: num = 60;
var j: num = 1;
var k: num = 10;
while (j < p) : (j += 1) {
try stdout.print("P({d},{d}) = {d}\n", .{ p, j, @floor(perm(p, j)) });
}
while (k < c) : (k += 10) {
try stdout.print("C({d},{d}) = {d}\n", .{ c, k, @floor(comb(c, k)) });
}
}