2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: stats.ml 9822 2009-06-03 15:37:06Z denes $ *)
14 module Stats (B : Terms.Blob) =
17 module SymbMap = Map.Make(B)
19 let rec occ_nbr t acc = function
20 | Terms.Leaf u when B.eq t u -> 1+acc
21 | Terms.Node l -> List.fold_left (occ_nbr t) acc l
25 let occ_nbr t = occ_nbr t 0;;
27 let goal_occ_nbr t = function
28 | (_,Terms.Equation (l,r,_,_),_,_) ->
29 occ_nbr t l + occ_nbr t r
33 let rec parse_symbols acc l =
34 let rec aux acc = function
37 let (occ,ar) = SymbMap.find t acc in
38 SymbMap.add t (occ+1,ar) acc
39 with Not_found -> SymbMap.add t (1,0) acc)
41 | Terms.Node (Terms.Leaf hd::tl) ->
43 try let (occ,ar) = SymbMap.find hd acc in
44 SymbMap.add hd (occ+1,ar) acc
45 with Not_found -> SymbMap.add hd (1,List.length tl) acc
46 in List.fold_left aux acc tl
53 | Terms.Equation (l,r,_,_) ->
54 parse_symbols (aux (aux acc l) r) tl
55 | Terms.Predicate _ -> assert false;
59 let rec aux path = function
62 if B.eq t x then path else []
67 let p = aux (i::path) x in
68 if p = [] then None else Some p)
76 | _,Terms.Equation (l,r,ty,_),_,_ -> Terms.Node [ Terms.Leaf B.eqP; ty; l; r ]
77 | _,Terms.Predicate p,_,_ -> p)
80 let parse_symbols l goal =
81 let res = parse_symbols (parse_symbols SymbMap.empty [goal]) l in
82 SymbMap.fold (fun t (occ,ar) acc ->
83 (t,occ,ar,goal_occ_nbr t goal,goal_pos t goal)::acc) res []
86 let rec dependencies op clauses acc =
91 | Terms.Predicate _ -> assert false
92 | Terms.Equation (l,r,_,_) ->
94 | (Terms.Node (Terms.Leaf op1::_),Terms.Node
95 (Terms.Leaf op2::_)) ->
96 if (B.eq op1 op) && not (B.eq op2 op) then
97 let already = List.exists (B.eq op2) acc in
98 let occ_l = occ_nbr op l in
99 let occ_r = occ_nbr op r in
100 if not already && occ_r > occ_l then
101 dependencies op tl (op2::acc)
102 else dependencies op tl acc
103 else if not (B.eq op1 op) && (B.eq op2 op) then
104 let already = List.exists (B.eq op1) acc in
105 let occ_l = occ_nbr op l in
106 let occ_r = occ_nbr op r in
107 if not already && occ_l > occ_r then
108 dependencies op tl (op1::acc)
110 dependencies op tl acc
111 else dependencies op tl acc
112 | _ -> dependencies op tl acc
115 let dependencies op clauses = dependencies op clauses [];;
117 (* let max_weight_hyp = *)