X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_paramodulation%2Fsuperposition.ml;h=6b98ed5be24667a5c6be75049bab6f71ff0de53e;hb=40ce8d1c14808ea7608ee2988bd9aba77ddf8200;hp=b002dce33a05c4be5bc2f823d31f0c952293ed31;hpb=be2a030746e20744f9a317a31c7053bcfbb6e505;p=helm.git diff --git a/helm/software/components/ng_paramodulation/superposition.ml b/helm/software/components/ng_paramodulation/superposition.ml index b002dce33..6b98ed5be 100644 --- a/helm/software/components/ng_paramodulation/superposition.ml +++ b/helm/software/components/ng_paramodulation/superposition.ml @@ -17,11 +17,13 @@ module Superposition (B : Terms.Blob) = module Unif = FoUnif.Founif(B) module Subst = FoSubst.Subst(B) module Order = Orderings.Orderings(B) + module Utils = FoUtils.Utils(B) + module Pp = Pp.Pp(B) - let all_positions t f = + let all_positions pos ctx t f = let rec aux pos ctx = function - | Terms.Leaf a as t -> f t pos ctx - | Terms.Var i -> [] + | Terms.Leaf _ as t -> f t pos ctx + | Terms.Var _ -> [] | Terms.Node l as t-> let acc, _, _ = List.fold_left @@ -34,50 +36,123 @@ module Superposition (B : Terms.Blob) = in acc in - aux [] (fun x -> x) t + aux pos ctx t ;; let superposition_right table varlist subterm pos context = let cands = IDX.DT.retrieve_unifiables table subterm in HExtlib.filter_map - (fun (dir, (id,lit,vl,_)) -> + (fun (dir, (id,lit,vl,_ (*as uc*))) -> match lit with | Terms.Predicate _ -> assert false | Terms.Equation (l,r,_,o) -> + assert(o <> Terms.Eq); let side, newside = if dir=Terms.Left2Right then l,r else r,l in try let subst, varlist = Unif.unification (varlist@vl) [] subterm side in - Some (context newside, subst, varlist, id, pos, dir) + if o = Terms.Incomparable then + let side = Subst.apply_subst subst side in + let newside = Subst.apply_subst subst newside in + let o = Order.compare_terms side newside in + (* XXX: check Riazanov p. 33 (iii) *) + if o <> Terms.Lt && o <> Terms.Eq then + Some (context newside, subst, varlist, id, pos, dir) + else + ((*prerr_endline ("Filtering: " ^ + Pp.pp_foterm side ^ " =(< || =)" ^ + Pp.pp_foterm newside ^ " coming from " ^ + Pp.pp_unit_clause uc );*)None) + else + Some (context newside, subst, varlist, id, pos, dir) with FoUnif.UnificationFailure _ -> None) (IDX.ClauseSet.elements cands) ;; - let superposition_right_step bag (id,selected,vl,_) table = + let build_new_clause bag maxvar filter t subst vl id id2 pos dir = + let maxvar, vl, relocsubst = Utils.relocate maxvar vl in + let subst = Subst.concat relocsubst subst in + let proof = Terms.Step(Terms.SuperpositionRight,id,id2,dir,pos,subst) in + let t = Subst.apply_subst subst t in + if filter t then + let literal = + match t with + | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq -> + let o = Order.compare_terms l r in + Terms.Equation (l, r, ty, o) + | t -> Terms.Predicate t + in + let bag, uc = + Utils.add_to_bag bag (0, literal, vl, proof) + in + Some (bag, maxvar, uc) + else + ((*prerr_endline ("Filtering: " ^ Pp.pp_foterm t);*)None) + ;; + + let fold_build_new_clause bag maxvar id filter res = + let maxvar, bag, new_clauses = + List.fold_left + (fun (maxvar, bag, acc) (t,subst,vl,id2,pos,dir) -> + match build_new_clause bag maxvar filter t subst vl id id2 pos dir + with Some (bag, maxvar, uc) -> maxvar, bag, uc::acc + | None -> maxvar, bag, acc) + (maxvar, bag, []) res + in + bag, maxvar, new_clauses + ;; + + let superposition_right_with_table bag maxvar (id,selected,vl,_) table = match selected with | Terms.Predicate _ -> assert false - | Terms.Equation (l,r,ty,Terms.Lt) -> - let res = all_positions r (superposition_right table vl) in - let _new_clauses = - List.map - (fun (r,subst,vl,id2,pos,dir) -> - let proof = - Terms.Step(Terms.SuperpositionRight,id,id2, dir, pos, subst) - in - let r = Subst.apply_subst subst r in - let l = Subst.apply_subst subst l in - let ty = Subst.apply_subst subst ty in - let o = Order.compare_terms l r in - (* can unif compute the right vl for both sides? *) - (0, Terms.Equation (l,r,ty,o), vl, proof)) - res - in - (* fresh ID and metas and compute orientataion of new_clauses *) - assert false - | Terms.Equation (l,r,_,Terms.Gt) -> assert false + | Terms.Equation (l,r,ty,Terms.Lt) -> + fold_build_new_clause bag maxvar id (fun _ -> true) + (all_positions [3] + (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) + r (superposition_right table vl)) + | Terms.Equation (l,r,ty,Terms.Gt) -> + fold_build_new_clause bag maxvar id (fun _ -> true) + (all_positions [2] + (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) + l (superposition_right table vl)) + | Terms.Equation (l,r,ty,Terms.Incomparable) -> + fold_build_new_clause bag maxvar id + (function (* Riazanov: p.33 condition (iv) *) + | Terms.Node [Terms.Leaf eq; ty; l; r ] when B.eq B.eqP eq -> + Order.compare_terms l r <> Terms.Eq + | _ -> assert false) + ((all_positions [3] + (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) + r (superposition_right table vl)) @ + (all_positions [2] + (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) + l (superposition_right table vl))) | _ -> assert false ;; + + (* the current equation is normal w.r.t. demodulation with atable + * (and is not the identity) *) + let superposition_right bag maxvar current (alist,atable) = + let ctable = IDX.index_unit_clause IDX.DT.empty current in + let bag, maxvar, new_clauses = + List.fold_left + (fun (bag, maxvar, acc) active -> + let bag, maxvar, newc = + superposition_right_with_table bag maxvar active ctable + in + bag, maxvar, newc @ acc) + (bag, maxvar, []) alist + in + let alist, atable = + current :: alist, IDX.index_unit_clause atable current + in + let fresh_current, maxvar = Utils.fresh_unit_clause maxvar current in + let bag, maxvar, additional_new_clauses = + superposition_right_with_table bag maxvar fresh_current atable + in + bag, maxvar, (alist, atable), new_clauses @ additional_new_clauses + ;; end