let chi_square_table significance_level =
let critical_value = chi_square_critical_value significance_level in
let length = ref 42 in
let table = ref (Array.init !length critical_value) in
fun degrees_of_freedom ->
if degrees_of_freedom < !length
then !table.(degrees_of_freedom)
else (
let new_length = max (2 * !length) (succ degrees_of_freedom) in
let new_table = Array.make new_length (-1.) in
Array.blit !table 0 new_table 0 !length;
for i = !length to pred new_length do new_table.(i) <- critical_value i done;
length := new_length;
table := new_table;
!table.(degrees_of_freedom))