bag, maxvar, res
;;
+
+ let rewrite_eq ~unify l r ty vl table =
+ let retrieve = if unify then IDX.DT.retrieve_unifiables
+ else IDX.DT.retrieve_generalizations in
+ let lcands = retrieve table l in
+ let rcands = retrieve table r in
+ let f b c =
+ let id, dir, l, r, vl =
+ match c with
+ | (d, (id,Terms.Equation (l,r,ty,_),vl,_))-> id, d, l, r, vl
+ |_ -> assert false
+ in
+ let reverse = (dir = Terms.Left2Right) = b in
+ let l, r, proof_rewrite_dir = if reverse then l,r,Terms.Left2Right
+ else r,l, Terms.Right2Left in
+ (id,proof_rewrite_dir,Terms.Node [ Terms.Leaf B.eqP; ty; l; r ], vl)
+ in
+ let cands1 = List.map (f true) (IDX.ClauseSet.elements lcands) in
+ let cands2 = List.map (f false) (IDX.ClauseSet.elements rcands) in
+ let t = Terms.Node [ Terms.Leaf B.eqP; ty; l; r ] in
+ let locked_vars = if unify then [] else vl in
+ let rec aux = function
+ | [] -> None
+ | (id2,dir,c,vl1)::tl ->
+ try
+ let subst,vl1 = Unif.unification (vl@vl1) locked_vars c t in
+ Some (id2, dir, subst)
+ with FoUnif.UnificationFailure _ -> aux tl
+ in
+ aux (cands1 @ cands2)
+ ;;
+
let is_subsumed ~unify bag maxvar (id, lit, vl, _) table =
match lit with
| Terms.Predicate _ -> assert false
| Terms.Equation (l,r,ty,_) ->
- let retrieve = if unify then IDX.DT.retrieve_unifiables
- else IDX.DT.retrieve_generalizations in
- let lcands = retrieve table l in
- let rcands = retrieve table r in
- let f b c =
- let id, dir, l, r, vl =
- match c with
- | (d, (id,Terms.Equation (l,r,ty,_),vl,_))-> id, d, l, r, vl
- |_ -> assert false
- in
- let reverse = (dir = Terms.Left2Right) = b in
- let l, r, proof_rewrite_dir = if reverse then l,r,Terms.Left2Right
- else r,l, Terms.Right2Left in
- (id,proof_rewrite_dir,Terms.Node [ Terms.Leaf B.eqP; ty; l; r ], vl)
- in
- let cands1 = List.map (f true) (IDX.ClauseSet.elements lcands) in
- let cands2 = List.map (f false) (IDX.ClauseSet.elements rcands) in
- let t = Terms.Node [ Terms.Leaf B.eqP; ty; l; r ] in
- let locked_vars = if unify then [] else vl in
- let rec aux = function
- | [] -> None
- | (id2,dir,c,vl1)::tl ->
- try
- let subst,vl1 = Unif.unification (vl@vl1) locked_vars c t in
- let id_t = Terms.Node [ Terms.Leaf B.eqP; ty; r; r ] in
- build_new_clause bag maxvar (fun _ -> true)
- Terms.Superposition id_t subst [] id id2 [2] dir
- with FoUnif.UnificationFailure _ -> aux tl
- in
- aux (cands1 @ cands2)
+ match rewrite_eq ~unify l r ty vl table with
+ | None -> None
+ | Some (id2, dir, subst) ->
+ let id_t = Terms.Node [ Terms.Leaf B.eqP; ty; r; r ] in
+ build_new_clause bag maxvar (fun _ -> true)
+ Terms.Superposition id_t subst [] id id2 [2] dir
;;
+(*
+ let rec deeply_subsumed ~unify bag maxvar (id, lit, vl, _) table =
+ match lit with
+ | Terms.Predicate _ -> assert false
+ | Terms.Equation (l,r,ty,_) ->
+ (match is_subsumed ~unify bag maxvar (id, lit, vl, _) table with
+ | Some((bag,maxvar),c) -> Some((bag,maxvar),c)
+ | None ->
+ match l,r with ->
+ Var i, _ ->
+ ;;
+*)
+
+
(* demodulate and check for subsumption *)
let simplify table maxvar bag clause =
let bag, clause = demodulate bag clause table in