let debug = true
let debug_print = if debug then prerr_endline else ignore
+(*
+ (** print benchmark information *)
+let benchmark = true
+let max_refinements = ref 0 (* benchmarking is not thread safe *)
+let actual_refinements = ref 0
+let domain_size = ref 0
+let choices_avg = ref 0.
+*)
+
let descr_of_domain_item = function
| Id s -> s
| Symbol (s, _) -> s
| Uncertain
let refine metasenv context term =
- let metasenv, term = CicMkImplicit.expand_implicits metasenv context term in
+(* if benchmark then incr actual_refinements; *)
+ let metasenv, term = CicMkImplicit.expand_implicits metasenv [] context term in
debug_print (sprintf "TEST_INTERPRETATION: %s" (CicPp.ppterm term));
try
let term', _, metasenv' = CicRefine.type_of_aux' metasenv context term in
raise DisambiguateChoices.Invalid_choice))
subst
| None -> List.map (fun uri -> uri, Cic.Implicit None) uris)
- in
- (try
+ in
+ (* the try is for CicTypeChecker.typecheck *)
+ (try
match cic with
| Cic.Const (uri, []) ->
let uris =
- (*match CicEnvironment.get_obj uri with*)
- match CicTypeChecker.typecheck uri with
+ match CicEnvironment.get_obj uri with
+ (*match CicTypeChecker.typecheck uri with*)
| Cic.Constant (_, _, _, uris) -> uris
| _ -> assert false
in
Cic.Const (uri, mk_subst uris)
| Cic.Var (uri, []) ->
let uris =
- (*match CicEnvironment.get_obj uri with*)
- match CicTypeChecker.typecheck uri with
+ match CicEnvironment.get_obj uri with
+ (*match CicTypeChecker.typecheck uri with*)
| Cic.Variable (_, _, _, uris) -> uris
| _ -> assert false
in
Cic.Var (uri, mk_subst uris)
| Cic.MutInd (uri, i, []) ->
let uris =
- (*match CicEnvironment.get_obj uri with*)
- match CicTypeChecker.typecheck uri with
+ match CicEnvironment.get_obj uri with
+ (*match CicTypeChecker.typecheck uri with*)
| Cic.InductiveDefinition (_, uris, _) -> uris
| _ -> assert false
in
Cic.MutInd (uri, i, mk_subst uris)
| Cic.MutConstruct (uri, i, j, []) ->
let uris =
- (*match CicEnvironment.get_obj uri with*)
- match CicTypeChecker.typecheck uri with
+ match CicEnvironment.get_obj uri with
+ (*match CicTypeChecker.typecheck uri with*)
| Cic.InductiveDefinition (_, uris, _) -> uris
| _ -> assert false
in
in
match ast with
| CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
- | term -> aux (-1, -1) context term
+ | term -> aux CicAst.dummy_floc context term
let domain_of_term ~context ast =
(* "aux" keeps domain in reverse order and doesn't care about duplicates.
rev_uniq
(match ast with
| CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
- | term -> aux (-1, -1) context term)
-
+ | term -> aux CicAst.dummy_floc context term)
(* dom1 \ dom2 *)
let domain_diff dom1 dom2 =
if choices = [] then raise (No_choices item);
choices
in
+
+(*
+ (* <benchmark> *)
+ let _ =
+ if benchmark then begin
+ let per_item_choices =
+ List.map
+ (fun dom_item ->
+ try
+ let len = List.length (lookup_choices dom_item) in
+ prerr_endline (sprintf "BENCHMARK %s: %d"
+ (string_of_domain_item dom_item) len);
+ len
+ with No_choices _ -> 0)
+ term_dom
+ in
+ max_refinements := List.fold_left ( * ) 1 per_item_choices;
+ actual_refinements := 0;
+ domain_size := List.length term_dom;
+ choices_avg :=
+ (float_of_int !max_refinements) ** (1. /. float_of_int !domain_size)
+ end
+ in
+ (* </benchmark> *)
+*)
+
(* (3) test an interpretation filling with meta uninterpreted identifiers
*)
let test_env current_env todo_dom univ =
in
let base_univ = CicUniv.get_working () in
try
- match aux current_env todo_dom base_univ with
- | [] -> raise NoWellTypedInterpretation
- | [ e,me,t,u ] as l ->
- debug_print "UNA SOLA SCELTA";
- CicUniv.set_working u;
- [ e,me,t ]
- | l ->
- debug_print (sprintf "PIU' SCELTE (%d)" (List.length l));
- let choices =
- List.map
- (fun (env, _, _, _) ->
- List.map
- (fun domain_item ->
- let description =
- fst (Environment.find domain_item env)
- in
- (descr_of_domain_item domain_item, description))
- term_dom)
- l
- in
- let choosed = C.interactive_interpretation_choice choices in
- let l' = List.map (List.nth l) choosed in
- match l' with
- [] -> assert false
- | [e,me,t,u] ->
- CicUniv.set_working u;
- (*CicUniv.print_working_graph ();*)
- [e,me,t]
- | hd::tl -> (* ok, testlibrary... cosi' stampa MANY... bah *)
- List.map (fun (e,me,t,u) -> (e,me,t)) l'
+ let res =
+ match aux current_env todo_dom base_univ with
+ | [] -> raise NoWellTypedInterpretation
+ | [ e,me,t,u ] as l ->
+ debug_print "UNA SOLA SCELTA";
+ CicUniv.set_working u;
+ [ e,me,t ]
+ | l ->
+ debug_print (sprintf "PIU' SCELTE (%d)" (List.length l));
+ let choices =
+ List.map
+ (fun (env, _, _, _) ->
+ List.map
+ (fun domain_item ->
+ let description =
+ fst (Environment.find domain_item env)
+ in
+ (descr_of_domain_item domain_item, description))
+ term_dom)
+ l
+ in
+ let choosed = C.interactive_interpretation_choice choices in
+ let l' = List.map (List.nth l) choosed in
+ match l' with
+ [] -> assert false
+ | [e,me,t,u] ->
+ CicUniv.set_working u;
+ (*CicUniv.print_working_graph ();*)
+ [e,me,t]
+ | hd::tl -> (* ok, testlibrary... cosi' stampa MANY... bah *)
+ List.map (fun (e,me,t,u) -> (e,me,t)) l'
+ in
+(*
+ (if benchmark then
+ let res_size = List.length res in
+ prerr_endline (sprintf
+ ("BENCHMARK: %d/%d refinements performed, domain size %d, interps %d, k %.2f\n" ^^
+ "BENCHMARK: estimated %.2f")
+ !actual_refinements !max_refinements !domain_size res_size
+ !choices_avg
+ (float_of_int (!domain_size - 1) *. !choices_avg *. (float_of_int res_size) +. !choices_avg)));
+*)
+ res
with
CicEnvironment.CircularDependency s ->
raise (Failure "e chi la becca sta CircularDependency?");