Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
let binomialCoeff n p =
|
||||
let p = if p < n -. p then p else n -. p in
|
||||
let rec cm res num denum =
|
||||
(* this method partially prevents overflow.
|
||||
* float type is choosen to have increased domain on 32-bits computer,
|
||||
* however algorithm ensures an integral result as long as it is possible
|
||||
*)
|
||||
if denum <= p then cm ((res *. num) /. denum) (num -. 1.) (denum +. 1.)
|
||||
else res in
|
||||
cm 1. n 1.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#load "nums.cma";;
|
||||
open Num;;
|
||||
|
||||
let binomial n p =
|
||||
let m = min p (n - p) in
|
||||
if m < 0 then Int 0 else
|
||||
let rec a j v =
|
||||
if j = m then v
|
||||
else a (succ j) ((v */ (Int (n - j))) // (Int (succ j)))
|
||||
in a 0 (Int 1)
|
||||
;;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
open Num;;
|
||||
let rec binomial n k = if n = k then Int 1 else ((binomial (n-1) k) */ Int n) // Int (n-k)
|
||||
Loading…
Add table
Add a link
Reference in a new issue