]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/tactics/paramodulation/indexing.ml
reverted a commented substitution in build_newgoal, added an euristic to
[helm.git] / helm / software / components / tactics / paramodulation / indexing.ml
index 12c8e9bd65c6eb3a7ea6eadb2dd916db6b5e2494..e453d95c12c968a3cd696b157db950a6f87408e7 100644 (file)
@@ -404,7 +404,7 @@ let subsumption_aux use_unification env table target =
         | Founif.MatchingFailure 
         | CicUnification.UnificationFailure _ -> ok what leftorright tl
   in
-  match ok right Utils.Left  leftr with
+  match ok right Utils.Left leftr with
   | Some _ as res -> res
   | None -> 
       let rightr =
@@ -426,6 +426,61 @@ let unification x y z =
   subsumption_aux true x y z
 ;;
 
+let subsumption_aux_all use_unification env table target = 
+  let _, _, (ty, left, right, _), tmetas, _ = Equality.open_equality target in
+  let _, context, ugraph = env in
+  let metasenv = tmetas in
+  let predicate, unif_fun = 
+    if use_unification then
+      Unification, Founif.unification
+    else
+      Matching, Founif.matching
+  in
+  let leftr =
+    match left with
+    | Cic.Meta _ when not use_unification -> []   
+    | _ ->
+        let leftc = get_candidates predicate table left in
+        find_all_matches ~unif_fun
+          metasenv context ugraph 0 left ty leftc
+  in
+  let rightr =
+        match right with
+          | Cic.Meta _ when not use_unification -> [] 
+          | _ ->
+              let rightc = get_candidates predicate table right in
+                find_all_matches ~unif_fun
+                  metasenv context ugraph 0 right ty rightc
+  in
+  let rec ok_all what leftorright = function
+    | [] -> []
+    | (_, subst, menv, ug, (pos,equation))::tl ->
+        let _, _, (_, l, r, o), m,_ = Equality.open_equality equation in
+        try
+          let other = if pos = Utils.Left then r else l in
+          let what' = Subst.apply_subst subst what in
+          let other' = Subst.apply_subst subst other in
+          let subst', menv', ug' =
+            unif_fun metasenv m context what' other' ugraph
+          in
+          (match Subst.merge_subst_if_possible subst subst' with
+          | None -> ok_all what leftorright tl
+          | Some s -> 
+             (s, equation, leftorright <> pos )::(ok_all what leftorright tl))
+        with 
+        | Founif.MatchingFailure 
+        | CicUnification.UnificationFailure _ -> (ok_all what leftorright tl)
+  in
+  (ok_all right Utils.Left leftr)@(ok_all left Utils.Right rightr )
+;;
+
+let subsumption_all x y z =
+  subsumption_aux_all false x y z
+;;
+
+let unification_all x y z = 
+  subsumption_aux_all true x y z
+;;
 let rec demodulation_aux bag ?from ?(typecheck=false) 
   metasenv context ugraph table lift_amount term =
 (*  Printf.eprintf "term = %s\n" (CicPp.ppterm term);*)
@@ -566,6 +621,7 @@ let rec demodulation_equality bag ?from eq_uri newmeta env table target =
       try fst (CicTypeChecker.type_of_aux' metasenv context what ugraph)
       with CicUtil.Meta_not_found _ -> ty
     in
+    let ty, eq_ty = apply_subst subst ty, apply_subst subst eq_ty in
     let what, other = if pos = Utils.Left then what, other else other, what in
     let newterm, newproof =
       let bo = 
@@ -600,7 +656,7 @@ let rec demodulation_equality bag ?from eq_uri newmeta env table target =
     match res with
     | Some t ->
         let newmeta, newtarget = build_newtarget true t in
-          assert (not (Equality.meta_convertibility_eq target newtarget));
+          (* assert (not (Equality.meta_convertibility_eq target newtarget)); *)
           if (Equality.is_weak_identity newtarget) (* || *)
             (*Equality.meta_convertibility_eq target newtarget*) then
               newmeta, newtarget
@@ -803,6 +859,7 @@ let superposition_right bag
       Equality.open_equality  equality in
     let what, other = if pos = Utils.Left then what, other else other, what in
 
+    let ty, eq_ty = apply_subst s ty, apply_subst s eq_ty in
     let newgoal, newproof =
       (* qua *)
       let bo' =
@@ -904,7 +961,7 @@ let rec demodulation_theorem bag newmeta env table theorem =
 let open_goal g =
   match g with
   | (proof,menv,Cic.Appl[(Cic.MutInd(uri,0,_)) as eq;ty;l;r]) -> 
-      assert (LibraryObjects.is_eq_URI uri);
+      (* assert (LibraryObjects.is_eq_URI uri); *)
       proof,menv,eq,ty,l,r
   | _ -> assert false
 ;;
@@ -948,8 +1005,9 @@ let build_newgoal bag context goal posu rule expansion =
       Utils.guarded_simpl context 
         (apply_subst subst (CicSubstitution.subst other t)) 
     in
-    let bo' = (*apply_subst subst*) t in 
-    let name = Cic.Name "x" in
+    let bo' = apply_subst subst t in
+    let ty = apply_subst subst ty in 
+    let name = Cic.Name "x" in 
     let newgoalproofstep = (rule,pos,id,subst,Cic.Lambda (name,ty,bo')) in
     bo, (newgoalproofstep::goalproof)
   in