aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Spiwack2016-07-30 17:51:19 +0200
committerArnaud Spiwack2016-11-07 19:49:24 +0100
commite0e52953a7b06b52603eb6f592dbf40cb325a4de (patch)
treed1276a2d9000ffa4b2051f93f9616967ace0e487
parent970bd8e901267916ae23bbe661d05c7d64f60b48 (diff)
Refine the relevance measure
Having more disctinc symbols incurs a penalty.
-rw-r--r--toplevel/search.ml23
1 files changed, 21 insertions, 2 deletions
diff --git a/toplevel/search.ml b/toplevel/search.ml
index d207ba7e0e..e4db764759 100644
--- a/toplevel/search.ml
+++ b/toplevel/search.ml
@@ -118,12 +118,29 @@ module ConstrPriority = struct
type t = Globnames.global_reference * Environ.env * Constr.t
+ module ConstrSet = CSet.Make(Constr)
+
(** A measure of the size of a term *)
let rec size t =
Constr.fold (fun s t -> 1 + s + size t) 0 t
+ (** Set of the "symbols" (definitions, inductives, constructors)
+ which appear in a term. *)
+ let rec symbols acc t =
+ let open Constr in
+ match kind t with
+ | Const _ | Ind _ | Construct _ -> ConstrSet.add t acc
+ | _ -> Constr.fold symbols acc t
+
+ (** The number of distinct "symbols" (see {!symbols}) which appear
+ in a term. *)
+ let num_symbols t =
+ ConstrSet.(cardinal (symbols empty t))
+
+ -(3*(num_symbols t) + size t)
+
let compare (_,_,t1) (_,_,t2) =
- -compare (size t1) (size t2)
+ compare (priority t1) (priority t2)
end
module PriorityQueue = Heap.Functional(ConstrPriority)
@@ -137,7 +154,9 @@ let rec iter_priority_queue q fn =
with Heap.EmptyHeap -> None
end in
match next with
- | Some (gref,env,t) -> fn gref env t; iter_priority_queue (PriorityQueue.remove q) fn
+ | Some (gref,env,t) ->
+ fn gref env t;
+ iter_priority_queue (PriorityQueue.remove q) fn
| None -> ()
let prioritize_search seq fn =