let debug s = prerr_endline (Lazy.force s);;
let debug _ = ();;
-module COT : Set.OrderedType with type t = int * NCic.term =
+module HOT : Set.OrderedType
+with type t = int * NCic.term * NCic.term * NCic.term =
struct
- type t = int * NCic.term
+ (* precedence, skel1, skel2, term *)
+ type t = int * NCic.term * NCic.term * NCic.term
let compare = Pervasives.compare
end
-module HintSet = Set.Make(COT)
+module EOT : Set.OrderedType
+with type t = int * NCic.term =
+ struct
+ type t = int * NCic.term
+ let compare = Pervasives.compare
+ end
+
+module HintSet = Set.Make(HOT)
+module EqSet = Set.Make(EOT)
module HDB =
Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
module EQDB =
- Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
+ Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(EqSet)
type db =
HDB.t * (* hint database: (dummy A B)[?] |-> \forall X.(summy a b)[X] *)
| NCic.Def (b,ty) -> NCic.LetIn (n,ty,b,t))
t context
in
- let data_hint = ctx2abstractions context (pair t1 t2) in
+ let data_hint =
+ precedence, t1_skeleton, t2_skeleton, ctx2abstractions context (pair t1 t2)
+ in
let data_t1 = t2_skeleton in
let data_t2 = t1_skeleton in
debug(lazy ("INDEXING: " ^
NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^
- NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] data_hint));
+ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[]
+ (let _,x,_,_ = data_hint in x)));
hdb#set_uhint_db (
- HDB.index (fst (hdb#uhint_db)) src (precedence, data_hint),
+ HDB.index (fst (hdb#uhint_db)) src data_hint,
EQDB.index
(EQDB.index (snd (hdb#uhint_db)) t2_skeleton (precedence, data_t2))
t1_skeleton (precedence, data_t1))
it sould retulr the whole content of the trie *)
else
let candidates = EQDB.retrieve_unifiables (snd hdb#uhint_db) t1 in
- let candidates = HintSet.elements candidates in
+ let candidates = EqSet.elements candidates in
let candidates = List.sort (fun (x,_) (y,_) -> compare x y) candidates in
List.map snd candidates
in
let candidates1 = HDB.retrieve_unifiables (fst hdb#uhint_db) (pair t1 t2) in
let candidates2 = HDB.retrieve_unifiables (fst hdb#uhint_db) (pair t2 t1) in
let candidates1 =
- List.map (fun (prec,ty) ->
+ List.map (fun (prec,_,_,ty) ->
prec,true,saturate ~delta:max_int metasenv subst context ty 0)
(HintSet.elements candidates1)
in
let candidates2 =
- List.map (fun (prec,ty) ->
+ List.map (fun (prec,_,_,ty) ->
prec,false,saturate ~delta:max_int metasenv subst context ty 0)
(HintSet.elements candidates2)
in
rc
;;
+
+
+let generate_dot_file status fmt =
+ let module Pp = GraphvizPp.Dot in
+ let h_db, _ = status#uhint_db in
+ let names = ref [] in
+ let id = ref 0 in
+ let mangle l =
+ try List.assoc l !names
+ with Not_found ->
+ incr id;
+ names := (l,"node"^string_of_int!id) :: !names;
+ List.assoc l !names
+ in
+ let nodes = ref [] in
+ let edges = ref [] in
+ HDB.iter h_db (fun _key dataset ->
+ List.iter
+ (fun (precedence, l,r, hint) ->
+ let l =
+ Str.global_substitute (Str.regexp "\n") (fun _ -> "")
+ (NCicPp.ppterm
+ ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] l)
+ in
+ let r =
+ Str.global_substitute (Str.regexp "\n") (fun _ -> "")
+ (NCicPp.ppterm
+ ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] r)
+ in
+ let hint =
+ string_of_int precedence ^ "..." ^
+ Str.global_substitute (Str.regexp "\n") (fun _ -> "")
+ (NCicPp.ppterm
+ ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] hint)
+ in
+ nodes := (mangle l,l) :: (mangle r,r) :: !nodes;
+ edges := (mangle l, mangle r, hint) :: !edges)
+ (HintSet.elements dataset);
+ );
+ List.iter (fun x, l -> Pp.node x ~attrs:["label",l] fmt) !nodes;
+ List.iter (fun x, y, l ->
+ Pp.raw (Printf.sprintf "%s -- %s [ label=\"%s\" ];\n" x y "?") fmt)
+ !edges;
+;;
let load_easter_egg = lazy (
win#browserImage#set_file (MatitaMisc.image_path "meegg.png"))
in
+ let load_hints () =
+ let module Pp = GraphvizPp.Dot in
+ let filename, oc = Filename.open_temp_file "matita" ".dot" in
+ let fmt = Format.formatter_of_out_channel oc in
+ let status = (MatitaScript.current ())#grafite_status in
+ Pp.header
+ ~name:"Hints"
+ ~graph_type:"graph"
+ ~graph_attrs:["overlap", "false"]
+ ~node_attrs:["fontsize", "9"; "width", ".4";
+ "height", ".4"; "shape", "box"]
+ ~edge_attrs:["fontsize", "10"; "len", "2"] fmt;
+ NCicUnifHint.generate_dot_file status fmt;
+ Pp.trailer fmt;
+ Pp.raw "@." fmt;
+ close_out oc;
+ gviz#load_graph_from_file ~gviz_cmd:"neato -Tpng" filename;
+ (*HExtlib.safe_remove filename*)
+ in
let load_coerchgraph tred () =
let module Pp = GraphvizPp.Dot in
let filename, oc = Filename.open_temp_file "matita" ".dot" in
| `About `Us -> self#egg ()
| `About `CoercionsFull -> self#coerchgraph false ()
| `About `Coercions -> self#coerchgraph true ()
+ | `About `Hints -> self#hints ()
| `About `TeX -> self#tex ()
| `About `Grammar -> self#grammar ()
| `Check term -> self#_loadCheck term
load_coerchgraph tred ();
self#_showGviz
+ method private hints () =
+ load_hints ();
+ self#_showGviz
+
method private tex () =
let b = Buffer.create 1000 in
Printf.bprintf b "UTF-8 equivalence classes (rotate with ALT-L):\n\n";