open Fact (* To use this context, you have to: compile note.v and fact.v using coqc remove fact.mli -- apparently there is a bug in the extraction tool compile fact.ml using ocamlc -c compile this file using ocamlc -o fact fact.cmo context.ml you obtain a program that can be used to compute factorials, even of large numbers, the number has to be given on the command line. try : ./fact 100 *) let z_to_digit = function Z0 -> "0" | Zpos XH -> "1" | Zpos (XO XH) -> "2" | Zpos (XI XH) -> "3" | Zpos (XO (XO XH)) -> "4" | Zpos (XI (XO XH)) -> "5" | Zpos (XO (XI XH)) -> "6" | Zpos (XI (XI XH)) -> "7" | Zpos (XO (XO (XO XH))) -> "8" | Zpos (XI (XO (XO XH))) -> "9" | _ -> assert false;; let z10 = Zpos(XO (XI (XO XH)));; let rec z_to_list z = let Pair(a,b) = zdiv_eucl z z10 in z_to_digit b::if (a = Z0) then [] else z_to_list a;; let rec int_to_positive z = if z = 1 then XH else if z mod 2 = 1 then XI (int_to_positive (z / 2)) else XO (int_to_positive (z / 2));; let int_to_z x = if x = 0 then Z0 else Zpos (int_to_positive x);; let char_to_z c = int_to_z (Char.code c - Char.code '0');; let rec string_to_z z n s = if n >= String.length s then z else string_to_z (zplus (zmult z (int_to_z 10)) (char_to_z (String.get s n))) (n+1) s;; let rec display_char_list = function [] -> print_string "\n" | a::tl -> print_string a; display_char_list tl;; let fact_strings s = match fact (string_to_z Z0 0 s) with Fact.In_pointed l -> String.concat "" (List.rev (z_to_list l)) | _ -> assert false;; if !Sys.interactive then () else let s = fact_strings (Sys.argv.(1)) in (print_string s; print_string "\n");;