module Constr = MetadataConstraints
-let locate ~(dbh:Dbi.connection) name =
+let nonvar s =
+ let len = String.length s in
+ let suffix = String.sub s (len-4) 4 in
+ not (suffix = ".var")
+
+let locate ~(dbh:Dbi.connection) ?(vars = false) name =
let query =
- dbh#prepare (sprintf "SELECT value FROM %s WHERE source = \"%s\""
+ dbh#prepare (sprintf "SELECT source FROM %s WHERE value = \"%s\""
MetadataTypes.name_tbl name)
in
query#execute [];
- List.map (function [`String s] -> s | _ -> assert false) (query#fetchall ())
+ List.filter nonvar
+ (List.map (function [`String s] -> s | _ -> assert false)
+ (query#fetchall ()))
let match_term ~(dbh:Dbi.connection) ty =
- let constraints =
- List.map MetadataTypes.constr_of_metadata
- (MetadataExtractor.compute ~body:None ~ty)
+ let metadata = MetadataExtractor.compute ~body:None ~ty in
+ let constants_no =
+ MetadataConstraints.StringSet.cardinal (MetadataConstraints.constants_of ty)
in
- Constr.at_least ~dbh constraints
-
-let nonvar s =
- let len = String.length s in
- let suffix = String.sub s (len-4) 4 in
- not (suffix = ".var")
+ let constraints = List.map MetadataTypes.constr_of_metadata metadata in
+ Constr.at_least ~dbh ~full_card:(MetadataConstraints.Eq constants_no)
+ constraints
let ( ** ) x y = int_of_float ((float_of_int x) ** (float_of_int y))
Constr.StringSet.union set (Constr.constants_of t))
Constr.StringSet.empty context
-let intersect l1 l2 =
- let set1 = List.fold_right Constr.StringSet.add l1 Constr.StringSet.empty in
- let set2 = List.fold_right Constr.StringSet.add l2 Constr.StringSet.empty in
- Constr.StringSet.elements (Constr.StringSet.inter set1 set2)
+let intersect uris siguris =
+ let set1 = List.fold_right Constr.StringSet.add uris Constr.StringSet.empty in
+ let set2 =
+ List.fold_right Constr.StringSet.add siguris Constr.StringSet.empty
+ in
+ let inter = Constr.StringSet.inter set1 set2 in
+ List.filter (fun s -> Constr.StringSet.mem s inter) uris
let filter_uris_forward ~dbh (main, constants) uris =
let main_uris =
let full_signature =
List.fold_right Constr.StringSet.add main_uris constants
in
- List.filter (Constr.at_most ~dbh full_signature) uris
+ List.filter (Constr.at_most ~dbh ~where:`Statement full_signature) uris
let filter_uris_backward ~dbh signature uris =
let siguris =
in
intersect uris siguris
+let compare_goal_list proof goal1 goal2 =
+ let _,metasenv,_,_ = proof in
+ let (_, ey1, ty1) = CicUtil.lookup_meta goal1 metasenv in
+ let (_, ey2, ty2) = CicUtil.lookup_meta goal2 metasenv in
+ let ty_sort1 = CicTypeChecker.type_of_aux' metasenv ey1 ty1 in
+ let ty_sort2 = CicTypeChecker.type_of_aux' metasenv ey2 ty2 in
+ let prop1 =
+ if CicReduction.are_convertible ey1 (Cic.Sort Cic.Prop) ty_sort1 then 0
+ else 1
+ in
+ let prop2 =
+ if CicReduction.are_convertible ey2 (Cic.Sort Cic.Prop) ty_sort2 then 0
+ else 1
+ in
+ prop1 - prop2
+
let hint ~(dbh:Dbi.connection) ?signature ((proof, goal) as status) =
let (_, metasenv, _, _) = proof in
let (_, context, ty) = CicUtil.lookup_meta goal metasenv in
in
let other_constants = Constr.StringSet.union sig_constants hyp_constants in
let uris =
- if (List.length uris < 2 ** (Constr.StringSet.cardinal other_constants))
+ let pow = 2 ** (Constr.StringSet.cardinal other_constants) in
+ if ((List.length uris < pow) or (pow <= 0))
then begin
prerr_endline "MetadataQuery: large sig, falling back to old method";
filter_uris_forward ~dbh (main, other_constants) uris
end else
filter_uris_backward ~dbh (main, other_constants) uris
in
- List.map
- (fun uri ->
- (uri,
- ProofEngineTypes.apply_tactic
- (PrimitiveTactics.apply_tac ~term:(CicUtil.term_of_uri uri))
- status))
- uris
+ let rec aux = function
+ | [] -> []
+ | uri :: tl ->
+ (let status' =
+ try
+ let (proof, goal_list) =
+ ProofEngineTypes.apply_tactic
+ (PrimitiveTactics.apply_tac ~term:(CicUtil.term_of_uri uri))
+ status
+ in
+ let goal_list =
+ List.stable_sort (compare_goal_list proof) goal_list
+ in
+ Some (uri, (proof, goal_list))
+ with ProofEngineTypes.Fail _ -> None
+ in
+ match status' with
+ | None -> aux tl
+ | Some status' ->
+ prerr_endline ("HO APPLICATO " ^ uri);
+ status' :: aux tl)
+ in
+ List.stable_sort
+ (fun (_, (_, goals1)) (_, (_, goals2)) ->
+ Pervasives.compare (List.length goals1) (List.length goals2))
+ (aux uris)
+
+let elim ~dbh uri =
+ let constraints =
+ [`Rel [`MainConclusion None];
+ `Sort (Cic.Prop,[`MainHypothesis (Some 1)]);
+ `Obj (uri,[`MainHypothesis (Some 0)]);
+ `Obj (uri,[`InHypothesis]);
+ ]
+ in
+ MetadataConstraints.at_least ~dbh constraints