1 (* Copyright (C) 2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 open DisambiguateTypes
31 exception No_choices of domain_item
32 exception NoWellTypedInterpretation
33 exception PathNotWellFormed
35 (** raised when an environment is not enough informative to decide *)
39 let debug_print = if debug then prerr_endline else ignore
42 (** print benchmark information *)
44 let max_refinements = ref 0 (* benchmarking is not thread safe *)
45 let actual_refinements = ref 0
46 let domain_size = ref 0
47 let choices_avg = ref 0.
50 let descr_of_domain_item = function
53 | Num i -> string_of_int i
56 | Ok of 'a * Cic.metasenv
60 let refine_term metasenv context uri term ugraph =
61 (* if benchmark then incr actual_refinements; *)
64 CicMkImplicit.expand_implicits metasenv [] context term in
65 debug_print (sprintf "TEST_INTERPRETATION: %s" (CicPp.ppterm term));
67 let term', _, metasenv',ugraph1 =
68 CicRefine.type_of_aux' metasenv context term ugraph in
69 (Ok (term', metasenv')),ugraph1
71 | CicRefine.Uncertain s ->
72 debug_print ("UNCERTAIN!!! [" ^ s ^ "] " ^ CicPp.ppterm term) ;
74 | CicRefine.RefineFailure msg ->
75 debug_print (sprintf "PRUNED!!!\nterm%s\nmessage:%s"
76 (CicPp.ppterm term) msg);
79 let refine_obj metasenv context uri obj ugraph =
80 assert (context = []);
81 let metasenv, obj = CicMkImplicit.expand_implicits_in_obj metasenv [] obj in
82 debug_print (sprintf "TEST_INTERPRETATION: %s" (CicPp.ppobj obj));
84 let obj', metasenv,ugraph = CicRefine.typecheck metasenv uri obj in
85 (Ok (obj', metasenv)),ugraph
87 | CicRefine.Uncertain s ->
88 debug_print ("UNCERTAIN!!! [" ^ s ^ "] " ^ CicPp.ppobj obj) ;
90 | CicRefine.RefineFailure msg ->
91 debug_print (sprintf "PRUNED!!!\nterm%s\nmessage:%s"
92 (CicPp.ppobj obj) msg);
95 let resolve (env: environment) (item: domain_item) ?(num = "") ?(args = []) () =
97 snd (Environment.find item env) env num args
99 failwith ("Domain item not found: " ^
100 (DisambiguateTypes.string_of_domain_item item))
102 (* TODO move it to Cic *)
103 let find_in_environment name context =
104 let rec aux acc = function
105 | [] -> raise Not_found
106 | Cic.Name hd :: tl when hd = name -> acc
107 | _ :: tl -> aux (acc + 1) tl
111 let interpretate_term ~context ~env ~uri ~is_path ast =
113 let rec aux loc context = function
114 | CicAst.AttributedTerm (`Loc loc, term) ->
116 | CicAst.AttributedTerm (_, term) -> aux loc context term
117 | CicAst.Appl (CicAst.Symbol (symb, i) :: args) ->
118 let cic_args = List.map (aux loc context) args in
119 resolve env (Symbol (symb, i)) ~args:cic_args ()
120 | CicAst.Appl terms -> Cic.Appl (List.map (aux loc context) terms)
121 | CicAst.Binder (binder_kind, (var, typ), body) ->
122 let cic_type = aux_option loc context typ in
123 let cic_body = aux loc (var :: context) body in
124 (match binder_kind with
125 | `Lambda -> Cic.Lambda (var, cic_type, cic_body)
126 | `Pi | `Forall -> Cic.Prod (var, cic_type, cic_body)
128 resolve env (Symbol ("exists", 0))
129 ~args:[ cic_type; Cic.Lambda (var, cic_type, cic_body) ] ())
130 | CicAst.Case (term, indty_ident, outtype, branches) ->
131 let cic_term = aux loc context term in
132 let cic_outtype = aux_option loc context outtype in
133 let do_branch ((head, args), term) =
134 let rec do_branch' context = function
135 | [] -> aux loc context term
136 | (name, typ) :: tl ->
137 let cic_body = do_branch' (name :: context) tl in
140 | None -> Cic.Implicit (Some `Type)
141 | Some typ -> aux loc context typ
143 Cic.Lambda (name, typ, cic_body)
145 do_branch' context args
147 let (indtype_uri, indtype_no) =
148 match indty_ident with
149 | Some indty_ident ->
150 (match resolve env (Id indty_ident) () with
151 | Cic.MutInd (uri, tyno, _) -> (uri, tyno)
152 | Cic.Implicit _ -> raise Try_again
153 | _ -> raise DisambiguateChoices.Invalid_choice)
155 let fst_constructor =
157 | ((head, _), _) :: _ -> head
158 | [] -> raise DisambiguateChoices.Invalid_choice
160 (match resolve env (Id fst_constructor) () with
161 | Cic.MutConstruct (indtype_uri, indtype_no, _, _) ->
162 (indtype_uri, indtype_no)
163 | Cic.Implicit _ -> raise Try_again
164 | _ -> raise DisambiguateChoices.Invalid_choice)
166 Cic.MutCase (indtype_uri, indtype_no, cic_outtype, cic_term,
167 (List.map do_branch branches))
168 | CicAst.LetIn ((name, typ), def, body) ->
169 let cic_def = aux loc context def in
173 | Some t -> Cic.Cast (cic_def, aux loc context t)
175 let cic_body = aux loc (name :: context) body in
176 Cic.LetIn (name, cic_def, cic_body)
177 | CicAst.LetRec (kind, defs, body) ->
179 List.fold_left (fun acc ((name, _), _, _) -> name :: acc)
182 let cic_body = aux loc context' body in
185 (fun ((name, typ), body, decr_idx) ->
186 let cic_body = aux loc context' body in
187 let cic_type = aux_option loc context typ in
191 CicTextualParser2.fail loc
192 "Recursive functions cannot be anonymous"
193 | Cic.Name name -> name
195 (name, decr_idx, cic_type, cic_body))
198 let counter = ref ~-1 in
199 let build_term funs =
200 (* this is the body of the fold_right function below. Rationale: Fix
201 * and CoFix cases differs only in an additional index in the
202 * inductiveFun list, see Cic.term *)
205 (fun (var, _, _, _) cic ->
207 Cic.LetIn (Cic.Name var, Cic.Fix (!counter, funs), cic))
210 List.map (fun (name, _, typ, body) -> (name, typ, body)) funs
212 (fun (var, _, _, _) cic ->
214 Cic.LetIn (Cic.Name var, Cic.CoFix (!counter, funs), cic))
216 List.fold_right (build_term inductiveFuns) inductiveFuns cic_body
218 | CicAst.Uri _ when is_path -> raise PathNotWellFormed
219 | CicAst.Ident (name, subst)
220 | CicAst.Uri (name, subst) as ast ->
221 let is_uri = function CicAst.Uri _ -> true | _ -> false in
223 if is_uri ast then raise Not_found;(* don't search the env for URIs *)
224 let index = find_in_environment name context in
225 if subst <> None then
226 CicTextualParser2.fail loc
227 "Explicit substitutions not allowed here";
231 if is_uri ast then (* we have the URI, build the term out of it *)
233 CicUtil.term_of_uri (UriManager.uri_of_string name)
234 with UriManager.IllFormedUri _ ->
235 CicTextualParser2.fail loc "Ill formed URI"
237 resolve env (Id name) ()
241 List.map (fun uri -> UriManager.name_of_uri uri, uri) uris
248 List.assoc s ids_to_uris, aux loc context term
250 raise DisambiguateChoices.Invalid_choice))
252 | None -> List.map (fun uri -> uri, Cic.Implicit None) uris)
256 | Cic.Const (uri, []) ->
257 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
258 let uris = CicUtil.params_of_obj o in
259 Cic.Const (uri, mk_subst uris)
260 | Cic.Var (uri, []) ->
261 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
262 let uris = CicUtil.params_of_obj o in
263 Cic.Var (uri, mk_subst uris)
264 | Cic.MutInd (uri, i, []) ->
266 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
267 let uris = CicUtil.params_of_obj o in
268 Cic.MutInd (uri, i, mk_subst uris)
270 CicEnvironment.Object_not_found _ ->
271 (* if we are here it is probably the case that during the
272 definition of a mutual inductive type we have met an
273 occurrence of the type in one of its constructors.
274 However, the inductive type is not yet in the environment
276 (*here the explicit_named_substituion is assumed to be of length 0 *)
277 Cic.MutInd (uri,i,[]))
278 | Cic.MutConstruct (uri, i, j, []) ->
279 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
280 let uris = CicUtil.params_of_obj o in
281 Cic.MutConstruct (uri, i, j, mk_subst uris)
282 | Cic.Meta _ | Cic.Implicit _ as t ->
285 "Warning: %s must be instantiated with _[%s] but we do not enforce it"
289 (fun (s, term) -> s ^ " := " ^ CicAstPp.pp_term term)
294 raise DisambiguateChoices.Invalid_choice
296 CicEnvironment.CircularDependency _ ->
297 raise DisambiguateChoices.Invalid_choice))
298 | CicAst.Implicit -> Cic.Implicit None
299 | CicAst.UserInput -> Cic.Implicit (Some `Hole)
300 | CicAst.Num (num, i) -> resolve env (Num i) ~num ()
301 | CicAst.Meta (index, subst) ->
304 (function None -> None | Some term -> Some (aux loc context term))
307 Cic.Meta (index, cic_subst)
308 | CicAst.Sort `Prop -> Cic.Sort Cic.Prop
309 | CicAst.Sort `Set -> Cic.Sort Cic.Set
310 | CicAst.Sort `Type -> Cic.Sort (Cic.Type (CicUniv.fresh())) (* TASSI *)
311 | CicAst.Sort `CProp -> Cic.Sort Cic.CProp
312 | CicAst.Symbol (symbol, instance) ->
313 resolve env (Symbol (symbol, instance)) ()
314 and aux_option loc context = function
315 | None -> Cic.Implicit (Some `Type)
316 | Some term -> aux loc context term
319 | CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
320 | term -> aux CicAst.dummy_floc context term
322 let interpretate_path ~context ~env path =
323 interpretate_term ~context ~env ~uri:None ~is_path:true path
325 let interpretate_obj ~context ~env ~uri ~is_path obj =
326 assert (context = []);
327 assert (is_path = false);
329 | TacticAst.Inductive (params,tyl) ->
330 let uri = match uri with Some uri -> uri | None -> assert false in
334 (fun (context,res) (name,t) ->
335 (Cic.Name name)::context,
336 (name, interpretate_term context env None false t)::res
339 context,List.rev res in
342 (fun (name,ty) t -> Cic.Prod (Cic.Name name,ty,t)) params in
346 (*here the explicit_named_substituion is assumed to be of length 0 *)
347 (fun (i,res) (name,_,_,_) ->
348 i + 1,(name,name,Cic.MutInd (uri,i,[]))::res
350 let con_env = DisambiguateTypes.env_of_list name_to_uris env in
354 (fun (name,_,_,_) (i,t) ->
355 (*here the explicit_named_substituion is assumed to be of length 0 *)
356 let t' = Cic.MutInd (uri,i,[]) in
357 let t = CicSubstitution.subst t' t in
359 ) tyl (List.length tyl - 1,t)) in
362 (fun (name,b,ty,cl) ->
363 let ty' = add_params (interpretate_term context env None false ty) in
368 add_params (interpretate_term context con_env None false ty)
376 Cic.InductiveDefinition (tyl,[],List.length params,[])
377 | TacticAst.Record (params,name,ty,fields) ->
378 let uri = match uri with Some uri -> uri | None -> assert false in
382 (fun (context,res) (name,t) ->
383 (Cic.Name name)::context,
384 (name, interpretate_term context env None false t)::res
387 context,List.rev res in
390 (fun (name,ty) t -> Cic.Prod (Cic.Name name,ty,t)) params in
391 let ty' = add_params (interpretate_term context env None false ty) in
395 (fun (context,res) (name,ty) ->
396 let context' = (Cic.Name name)::context in
397 context',(name,interpretate_term context env None false ty)::res
398 ) (context,[]) fields) in
400 (*here the explicit_named_substituion is assumed to be of length 0 *)
401 let mutind = Cic.MutInd (uri,0,[]) in
402 if params = [] then mutind
405 (mutind::CicUtil.mk_rels (List.length params) (List.length fields)) in
408 (fun t (name,ty) -> Cic.Prod (Cic.Name name,ty,t))
410 let con' = add_params con in
411 let tyl = [name,true,ty',["mk_" ^ name,con']] in
412 let field_names = List.map fst fields in
413 Cic.InductiveDefinition
414 (tyl,[],List.length params,[`Class (`Record field_names)])
415 | TacticAst.Theorem (_,name,ty,bo) ->
416 let ty' = interpretate_term [] env None false ty in
419 Cic.CurrentProof (name,[],Cic.Implicit None,ty',[],[])
421 let bo' = Some (interpretate_term [] env None false bo) in
422 Cic.Constant (name,bo',ty',[],[])
424 (* e.g. [5;1;1;1;2;3;4;1;2] -> [2;1;4;3;5] *)
426 let module SortedItem =
428 type t = DisambiguateTypes.domain_item
429 let compare = Pervasives.compare
432 let module Set = Set.Make (SortedItem) in
434 let rev_l = List.rev l in
435 let (_, uniq_rev_l) =
437 (fun (members, rev_l) elt ->
438 if Set.mem elt members then
441 Set.add elt members, elt :: rev_l)
442 (Set.empty, []) rev_l
446 (* "aux" keeps domain in reverse order and doesn't care about duplicates.
447 * Domain item more in deep in the list will be processed first.
449 let rec domain_rev_of_term ?(loc = CicAst.dummy_floc) context = function
450 | CicAst.AttributedTerm (`Loc loc, term) ->
451 domain_rev_of_term ~loc context term
452 | CicAst.AttributedTerm (_, term) -> domain_rev_of_term ~loc context term
453 | CicAst.Appl terms ->
455 (fun dom term -> domain_rev_of_term ~loc context term @ dom) [] terms
456 | CicAst.Binder (kind, (var, typ), body) ->
459 | `Exists -> [ Symbol ("exists", 0) ]
462 let type_dom = domain_rev_of_term_option loc context typ in
463 let body_dom = domain_rev_of_term ~loc (var :: context) body in
464 body_dom @ type_dom @ kind_dom
465 | CicAst.Case (term, indty_ident, outtype, branches) ->
466 let term_dom = domain_rev_of_term ~loc context term in
467 let outtype_dom = domain_rev_of_term_option loc context outtype in
468 let get_first_constructor = function
470 | ((head, _), _) :: _ -> [ Id head ]
472 let do_branch ((head, args), term) =
473 let (term_context, args_domain) =
475 (fun (cont, dom) (name, typ) ->
479 | Some typ -> domain_rev_of_term ~loc cont typ @ dom)))
482 args_domain @ domain_rev_of_term ~loc term_context term
485 List.fold_left (fun dom branch -> do_branch branch @ dom) [] branches
487 branches_dom @ outtype_dom @ term_dom @
488 (match indty_ident with
489 | None -> get_first_constructor branches
490 | Some ident -> [ Id ident ])
491 | CicAst.LetIn ((var, typ), body, where) ->
492 let body_dom = domain_rev_of_term ~loc context body in
493 let type_dom = domain_rev_of_term_option loc context typ in
494 let where_dom = domain_rev_of_term ~loc (var :: context) where in
495 where_dom @ type_dom @ body_dom
496 | CicAst.LetRec (kind, defs, where) ->
498 List.fold_left (fun acc ((var, typ), _, _) -> var :: acc)
501 let where_dom = domain_rev_of_term ~loc context' where in
504 (fun dom ((_, typ), body, _) ->
505 domain_rev_of_term ~loc context' body @
506 domain_rev_of_term_option loc context typ)
510 | CicAst.Ident (name, subst) ->
512 let index = find_in_environment name context in
513 if subst <> None then
514 CicTextualParser2.fail loc
515 "Explicit substitutions not allowed here"
523 (fun dom (_, term) ->
524 let dom' = domain_rev_of_term ~loc context term in
528 | CicAst.Implicit -> []
529 | CicAst.Num (num, i) -> [ Num i ]
530 | CicAst.Meta (index, local_context) ->
532 (fun dom term -> domain_rev_of_term_option loc context term @ dom) []
534 | CicAst.Sort _ -> []
535 | CicAst.Symbol (symbol, instance) -> [ Symbol (symbol, instance) ]
536 | CicAst.UserInput -> assert false
538 and domain_rev_of_term_option loc context = function
540 | Some t -> domain_rev_of_term ~loc context t
542 let domain_of_term ~context ast =
543 rev_uniq (domain_rev_of_term context ast)
545 let domain_of_obj ~context ast =
546 assert (context = []);
549 | TacticAst.Theorem (_,_,ty,bo) ->
552 | Some bo -> domain_rev_of_term [] bo) @
554 | TacticAst.Inductive (params,tyl) ->
561 (fun (_,ty) -> domain_rev_of_term [] ty) cl) @
562 domain_rev_of_term [] ty) tyl)
566 not ( List.exists (fun (name',_) -> name = Id name') params
567 || List.exists (fun (name',_,_,_) -> name = Id name') tyl)
569 | TacticAst.Record (params,_,ty,fields) ->
572 (List.rev_map (fun (_,ty) -> domain_rev_of_term [] ty) fields) in
576 not ( List.exists (fun (name',_) -> name = Id name') params
577 || List.exists (fun (name',_) -> name = Id name') fields)
580 dom' @ domain_rev_of_term [] ty
585 let domain_diff dom1 dom2 =
586 (* let domain_diff = Domain.diff *)
588 List.fold_left (fun pred elt -> (fun elt' -> elt' = elt || pred elt'))
589 (fun _ -> false) dom2
591 List.filter (fun elt -> not (is_in_dom2 elt)) dom1
593 module type Disambiguator =
595 val disambiguate_term :
597 context:Cic.context ->
598 metasenv:Cic.metasenv ->
599 ?initial_ugraph:CicUniv.universe_graph ->
600 aliases:environment -> (* previous interpretation status *)
602 (environment * (* new interpretation status *)
603 Cic.metasenv * (* new metasenv *)
605 CicUniv.universe_graph) list (* disambiguated term *)
607 val disambiguate_obj :
609 aliases:environment -> (* previous interpretation status *)
610 uri:UriManager.uri option -> (* required only for inductive types *)
612 (environment * (* new interpretation status *)
613 Cic.metasenv * (* new metasenv *)
615 CicUniv.universe_graph) list (* disambiguated obj *)
618 module Make (C: Callbacks) =
620 let choices_of_id dbd id =
621 let uris = MetadataQuery.locate ~dbd id in
625 [(C.input_or_locate_uri
626 ~title:("URI matching \"" ^ id ^ "\" unknown.") ~id ())]
629 C.interactive_user_uri_choice ~selection_mode:`MULTIPLE
630 ~ok:"Try selected." ~enable_button_for_non_vars:true
631 ~title:"Ambiguous input." ~id
632 ~msg: ("Ambiguous input \"" ^ id ^
633 "\". Please, choose one or more interpretations:")
638 (UriManager.string_of_uri uri,
641 CicUtil.term_of_uri uri
643 debug_print (UriManager.string_of_uri uri);
644 debug_print (Printexc.to_string exn);
650 let disambiguate_thing ~dbd ~context ~metasenv
651 ?(initial_ugraph = CicUniv.empty_ugraph) ~aliases:current_env
652 ~uri ~pp_thing ~domain_of_thing ~interpretate_thing ~refine_thing thing
654 debug_print "NEW DISAMBIGUATE INPUT";
655 let disambiguate_context = (* cic context -> disambiguate context *)
657 (function None -> Cic.Anonymous | Some (name, _) -> name)
660 debug_print ("TERM IS: " ^ (pp_thing thing));
661 let thing_dom = domain_of_thing ~context:disambiguate_context thing in
662 debug_print (sprintf "DISAMBIGUATION DOMAIN: %s"
663 (string_of_domain thing_dom));
665 Environment.fold (fun item _ dom -> item :: dom) current_env []
667 let todo_dom = domain_diff thing_dom current_dom in
668 (* (2) lookup function for any item (Id/Symbol/Num) *)
670 let id_choices = Hashtbl.create 1023 in
676 Hashtbl.find id_choices id
678 let choices = choices_of_id dbd id in
679 Hashtbl.add id_choices id choices;
681 | Symbol (symb, _) -> DisambiguateChoices.lookup_symbol_choices symb
682 | Num instance -> DisambiguateChoices.lookup_num_choices ()
684 if choices = [] then raise (No_choices item);
691 if benchmark then begin
692 let per_item_choices =
696 let len = List.length (lookup_choices dom_item) in
697 debug_print (sprintf "BENCHMARK %s: %d"
698 (string_of_domain_item dom_item) len);
700 with No_choices _ -> 0)
703 max_refinements := List.fold_left ( * ) 1 per_item_choices;
704 actual_refinements := 0;
705 domain_size := List.length thing_dom;
707 (float_of_int !max_refinements) ** (1. /. float_of_int !domain_size)
713 (* (3) test an interpretation filling with meta uninterpreted identifiers
715 let test_env current_env todo_dom ugraph =
722 | Id _ | Num _ -> (fun _ _ _ -> Cic.Implicit (Some `Closed))
723 | Symbol _ -> (fun _ _ _ -> Cic.Implicit None))) env)
728 interpretate_thing ~context:disambiguate_context ~env:filled_env
729 ~uri ~is_path:false thing
731 let k,ugraph1 = refine_thing metasenv context uri cic_thing ugraph in
734 | Try_again -> Uncertain,ugraph
735 | DisambiguateChoices.Invalid_choice -> Ko,ugraph
737 (* (4) build all possible interpretations *)
738 let rec aux current_env todo_dom base_univ =
741 (match test_env current_env [] base_univ with
742 | Ok (thing, metasenv),new_univ ->
743 [ current_env, metasenv, thing, new_univ ]
744 | Ko,_ | Uncertain,_ -> [])
745 | item :: remaining_dom ->
746 debug_print (sprintf "CHOOSED ITEM: %s"
747 (string_of_domain_item item));
748 let choices = lookup_choices item in
749 let rec filter univ = function
751 | codomain_item :: tl ->
752 debug_print (sprintf "%s CHOSEN" (fst codomain_item)) ;
754 Environment.add item codomain_item current_env
756 (match test_env new_env remaining_dom univ with
757 | Ok (thing, metasenv),new_univ ->
758 (match remaining_dom with
759 | [] -> [ new_env, metasenv, thing, new_univ ]
760 | _ -> aux new_env remaining_dom new_univ )@
762 | Uncertain,new_univ ->
763 (match remaining_dom with
765 | _ -> aux new_env remaining_dom new_univ )@
767 | Ko,_ -> filter univ tl)
769 filter base_univ choices
771 let base_univ = initial_ugraph in
774 match aux current_env todo_dom base_univ with
775 | [] -> raise NoWellTypedInterpretation
776 | [ e,me,t,u ] as l ->
777 debug_print "UNA SOLA SCELTA";
780 debug_print (sprintf "PIU' SCELTE (%d)" (List.length l));
783 (fun (env, _, _, _) ->
787 fst (Environment.find domain_item env)
789 (descr_of_domain_item domain_item, description))
793 let choosed = C.interactive_interpretation_choice choices in
794 List.map (List.nth l) choosed
798 let res_size = List.length res in
800 ("BENCHMARK: %d/%d refinements performed, domain size %d, interps %d, k %.2f\n" ^^
801 "BENCHMARK: estimated %.2f")
802 !actual_refinements !max_refinements !domain_size res_size
804 (float_of_int (!domain_size - 1) *. !choices_avg *. (float_of_int res_size) +. !choices_avg)));
808 CicEnvironment.CircularDependency s ->
809 failwith "Disambiguate: circular dependency"
811 let disambiguate_term ~dbd ~context ~metasenv
812 ?(initial_ugraph = CicUniv.empty_ugraph) ~aliases term
814 disambiguate_thing ~dbd ~context ~metasenv ~initial_ugraph ~aliases
815 ~uri:None ~pp_thing:CicAstPp.pp_term ~domain_of_thing:domain_of_term
816 ~interpretate_thing:interpretate_term ~refine_thing:refine_term term
818 let disambiguate_obj ~dbd ~aliases ~uri obj =
819 disambiguate_thing ~dbd ~context:[] ~metasenv:[] ~aliases ~uri
820 ~pp_thing:TacticAstPp.pp_obj ~domain_of_thing:domain_of_obj
821 ~interpretate_thing:interpretate_obj ~refine_thing:refine_obj
827 exception Ambiguous_term of string
831 let interactive_user_uri_choice ~selection_mode ?ok
832 ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
834 let interactive_interpretation_choice interp = raise Exit
835 let input_or_locate_uri ~(title:string) ?id = raise Exit
837 module Disambiguator = Make (Callbacks)
838 let disambiguate_string ~dbd ?(context=[]) ?(metasenv=[]) ?initial_ugraph
839 ?(aliases=DisambiguateTypes.Environment.empty) term =
840 let ast = CicTextualParser2.parse_term (Stream.of_string term) in
842 Disambiguator.disambiguate_term ~dbd ~context ~metasenv ast
843 ?initial_ugraph ~aliases
844 with Exit -> raise (Ambiguous_term term)