From 9a7efce50583b19214320afac57fb90ae78353ea Mon Sep 17 00:00:00 2001 From: denes Date: Tue, 23 Jun 2009 16:56:02 +0000 Subject: [PATCH] Rewrote the main loop for paramodulation --- .../components/ng_paramodulation/.depend | 4 +- .../components/ng_paramodulation/paramod.ml | 190 ++++++++++-------- .../ng_paramodulation/superposition.ml | 53 +++-- 3 files changed, 143 insertions(+), 104 deletions(-) diff --git a/helm/software/components/ng_paramodulation/.depend b/helm/software/components/ng_paramodulation/.depend index 666cba23e..54d1bb266 100644 --- a/helm/software/components/ng_paramodulation/.depend +++ b/helm/software/components/ng_paramodulation/.depend @@ -25,8 +25,8 @@ superposition.cmo: terms.cmi pp.cmi orderings.cmi index.cmi foUtils.cmi \ foUnif.cmi foSubst.cmi superposition.cmi superposition.cmx: terms.cmx pp.cmx orderings.cmx index.cmx foUtils.cmx \ foUnif.cmx foSubst.cmx superposition.cmi -nCicBlob.cmo: terms.cmi foUtils.cmi nCicBlob.cmi -nCicBlob.cmx: terms.cmx foUtils.cmx nCicBlob.cmi +nCicBlob.cmo: terms.cmi foUtils.cmi foSubst.cmi nCicBlob.cmi +nCicBlob.cmx: terms.cmx foUtils.cmx foSubst.cmx nCicBlob.cmi cicBlob.cmo: terms.cmi cicBlob.cmi cicBlob.cmx: terms.cmx cicBlob.cmi paramod.cmo: terms.cmi superposition.cmi pp.cmi nCicBlob.cmi index.cmi \ diff --git a/helm/software/components/ng_paramodulation/paramod.ml b/helm/software/components/ng_paramodulation/paramod.ml index d01292790..fc44be048 100644 --- a/helm/software/components/ng_paramodulation/paramod.ml +++ b/helm/software/components/ng_paramodulation/paramod.ml @@ -1,7 +1,7 @@ (* LOOPING : COL057-1.ma *) let debug s = - () (* prerr_endline s *) + prerr_endline s ;; let nparamod rdb metasenv subst context t table = @@ -34,14 +34,97 @@ let nparamod rdb metasenv subst context t table = PassiveSet.add (Utils.mk_passive_clause cl) passives in let timeout = Unix.gettimeofday () +. amount_of_time in + (* TODO : fairness condition *) - let select passives = - if PassiveSet.is_empty passives then None + let select passives g_passives = + if PassiveSet.is_empty passives then begin + assert (not (PassiveSet.is_empty g_passives)); + let g_cl = PassiveSet.min_elt g_passives in + (true,snd g_cl,passives,PassiveSet.remove g_cl g_passives) + end else let cl = PassiveSet.min_elt passives in - Some (snd cl,PassiveSet.remove cl passives) + if PassiveSet.is_empty g_passives then + (false,snd cl,PassiveSet.remove cl passives,g_passives) + else + let g_cl = PassiveSet.min_elt g_passives in + if (fst cl <= fst g_cl) then + (false,snd cl,PassiveSet.remove cl passives,g_passives) + else + (true,snd g_cl,passives,PassiveSet.remove g_cl g_passives) + in + + let backward_infer_step bag maxvar actives passives g_actives g_passives g_current = + (* superposition left, simplifications on goals *) + debug "infer_left step..."; + debug ("Selected goal : " ^ Pp.pp_unit_clause g_current); + let bag, g_current = + Sup.simplify_goal maxvar (snd actives) bag g_current + in + debug "Simplified goal"; + let bag, maxvar, new_goals = + Sup.infer_left bag maxvar g_current actives + in + debug "Performed infer_left step"; + let new_goals = List.fold_left add_passive_clause + PassiveSet.empty new_goals + in + bag, maxvar, actives, passives, g_current::g_actives, + (PassiveSet.union new_goals g_passives) + in + + let forward_infer_step bag maxvar actives passives g_actives + g_passives current = + (* forward step *) + + (* e = select P * + * e' = demod A e * + * A' = demod [e'] A * + * A'' = A' + e' * + * e'' = fresh e' * + * new = supright e'' A'' * + * new'= demod A'' new * + * P' = P + new' *) + debug "Forward infer step..."; + debug "Selected and simplified"; + (* debug ("Fact after simplification :" + ^ Pp.pp_unit_clause current); *) + let bag, maxvar, actives, new_clauses = + Sup.infer_right bag maxvar current actives + in + debug "Demodulating goals with actives..."; + debug ("Current : " ^ (Pp.pp_unit_clause current)); + debug ("Active goal : " ^ (Pp.pp_unit_clause (List.hd g_actives))); + (* keep goals demodulated w.r.t. actives and check if solved *) + let bag, g_actives = + List.fold_left + (fun (bag,acc) c -> + let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in + bag, c::acc) + (bag,[]) g_actives + in + debug (Pp.pp_unit_clause current); + debug (Pp.pp_unit_clause (List.hd g_actives)); + let ctable = IDX.index_unit_clause IDX.DT.empty current in + let bag, maxvar, new_goals = + List.fold_left + (fun (bag,m,acc) g -> + let bag, m, ng = Sup.infer_left bag m g + ([current],ctable) in + bag,m,ng@acc) + (bag,maxvar,[]) g_actives + in + let new_clauses = List.fold_left add_passive_clause + PassiveSet.empty new_clauses in + let new_goals = List.fold_left add_passive_clause + PassiveSet.empty new_goals in + debug (string_of_int (PassiveSet.cardinal new_goals)); + debug (string_of_int (PassiveSet.cardinal g_passives)); + bag, maxvar, actives, + PassiveSet.union new_clauses passives, g_actives, + PassiveSet.union new_goals g_passives in - let rec given_clause bag maxvar actives - passives g_actives g_passives = + + let rec given_clause bag maxvar actives passives g_actives g_passives = (* prerr_endline "Bag :"; prerr_endline (Pp.pp_bag bag); prerr_endline "Active table :"; (List.iter (fun x -> prerr_endline (Pp.pp_unit_clause x)) @@ -52,90 +135,31 @@ let nparamod rdb metasenv subst context t table = raise (Failure "Timeout !"); - - (* superposition left, simplifications on goals *) - debug "infer_left step..."; - let bag, maxvar, g_actives, g_passives = - match select g_passives with - | None -> bag, maxvar, g_actives, g_passives - | Some (g_current, g_passives) -> - debug ("Selected goal : " ^ Pp.pp_unit_clause g_current); - let bag, g_current = - Sup.simplify_goal maxvar (snd actives) bag g_current - in - debug "Simplified goal"; - let bag, maxvar, new_goals = - Sup.infer_left bag maxvar g_current actives - in - debug "Performed infer_left step"; - let new_goals = List.fold_left add_passive_clause - PassiveSet.empty new_goals - in - bag, maxvar, g_current::g_actives, - (PassiveSet.union new_goals g_passives) + let rec aux_select passives g_passives = + let backward,current,passives,g_passives = select passives g_passives in + if backward then + backward_infer_step bag maxvar actives passives + g_actives g_passives current + else + (* debug ("Selected fact : " ^ Pp.pp_unit_clause current); *) + match Sup.keep_simplified current actives bag maxvar with + (* match Sup.one_pass_simplification current actives bag maxvar with*) + | None -> aux_select passives g_passives + | Some x -> let (current, bag, actives) = x in + forward_infer_step bag maxvar actives passives + g_actives g_passives current + in + + let bag,maxvar,actives,passives,g_actives,g_passives = + aux_select passives g_passives in + assert (PassiveSet.cardinal g_passives < 2); debug (Printf.sprintf "Number of active goals : %d" (List.length g_actives)); debug (Printf.sprintf "Number of passive goals : %d" (PassiveSet.cardinal g_passives)); - - (* forward step *) - - (* e = select P * - * e' = demod A e * - * A' = demod [e'] A * - * A'' = A' + e' * - * e'' = fresh e' * - * new = supright e'' A'' * - * new'= demod A'' new * - * P' = P + new' *) - debug "Forward infer step..."; - let bag, maxvar, actives, passives, g_passives = - let rec aux_simplify passives = - match select passives with - | None -> assert false - | Some (current, passives) -> - debug ("Selected fact : " ^ Pp.pp_unit_clause current); - match Sup.keep_simplified current actives bag maxvar with -(* match Sup.one_pass_simplification current actives bag maxvar with*) - | None -> aux_simplify passives - | Some x -> x,passives - in - let (current, bag, actives),passives = aux_simplify passives - in - debug ("Fact after simplification :" - ^ Pp.pp_unit_clause current); - let bag, maxvar, actives, new_clauses = - Sup.infer_right bag maxvar current actives - in - debug "Demodulating goals with actives..."; - (* keep goals demodulated w.r.t. actives and check if solved *) - let bag, g_actives = - List.fold_left - (fun (bag,acc) c -> - let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in - bag, c::acc) - (bag,[]) g_actives - in - let ctable = IDX.index_unit_clause IDX.DT.empty current in - let bag, maxvar, new_goals = - List.fold_left - (fun (bag,m,acc) g -> - let bag, m, ng = Sup.infer_left bag m g - ([current],ctable) in - bag,m,ng@acc) - (bag,maxvar,[]) g_actives - in - let new_clauses = List.fold_left add_passive_clause - PassiveSet.empty new_clauses in - let new_goals = List.fold_left add_passive_clause - PassiveSet.empty new_goals in - bag, maxvar, actives, - PassiveSet.union new_clauses passives, - PassiveSet.union new_goals g_passives - in debug (Printf.sprintf "Number of actives : %d" (List.length (fst actives))); debug diff --git a/helm/software/components/ng_paramodulation/superposition.ml b/helm/software/components/ng_paramodulation/superposition.ml index aef672c14..82fe83037 100644 --- a/helm/software/components/ng_paramodulation/superposition.ml +++ b/helm/software/components/ng_paramodulation/superposition.ml @@ -120,7 +120,7 @@ module Superposition (B : Terms.Blob) = let newside = Subst.apply_subst subst newside in let o = Order.compare_terms newside side in (* Riazanov, pp. 45 (ii) *) - if o = Terms.Lt then + if o = Terms.Lt then Some (context newside, subst, varlist, id, pos, dir) else ((*prerr_endline ("Filtering: " ^ @@ -133,20 +133,25 @@ module Superposition (B : Terms.Blob) = (IDX.ClauseSet.elements cands) ;; - (* XXX: possible optimization, if the literal has a "side" already - * in normal form we should not traverse it again *) - let demodulate_once bag (id, literal, vl, pr) table = + let demodulate_once ~jump_to_right bag (id, literal, vl, pr) table = (* debug ("Demodulating : " ^ (Pp.pp_unit_clause (id, literal, vl, pr)));*) match literal with | Terms.Predicate t -> assert false | Terms.Equation (l,r,ty,_) -> - match first_position [2] - (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) l - (demod table vl) - with + let left_position = if jump_to_right then None else + first_position [2] + (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) l + (demod table vl) + in + match left_position with | Some (newt, subst, varlist, id2, pos, dir) -> - build_clause bag (fun _ -> true) Terms.Demodulation - newt subst varlist id id2 pos dir + begin + match build_clause bag (fun _ -> true) Terms.Demodulation + newt subst varlist id id2 pos dir + with + | None -> assert false + | Some x -> Some (x,false) + end | None -> match first_position [3] (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) r @@ -154,14 +159,22 @@ module Superposition (B : Terms.Blob) = with | None -> None | Some (newt, subst, varlist, id2, pos, dir) -> - build_clause bag (fun _ -> true) Terms.Demodulation - newt subst varlist id id2 pos dir + match build_clause bag (fun _ -> true) + Terms.Demodulation newt subst varlist id id2 pos dir + with + | None -> assert false + | Some x -> Some (x,true) ;; - let rec demodulate bag clause table = - match demodulate_once bag clause table with + let rec demodulate ~jump_to_right bag clause table = + match demodulate_once ~jump_to_right bag clause table with | None -> bag, clause - | Some (bag, clause) -> demodulate bag clause table + | Some ((bag, clause),r) -> demodulate ~jump_to_right:r + bag clause table + ;; + + let demodulate bag clause table = demodulate ~jump_to_right:false + bag clause table ;; (* move away *) @@ -438,6 +451,8 @@ module Superposition (B : Terms.Blob) = in debug "Another superposition"; let new_clauses = new_clauses @ additional_new_clauses in + debug (Printf.sprintf "Demodulating %d clauses" + (List.length new_clauses)); let bag, new_clauses = HExtlib.filter_map_acc (simplify atable maxvar) bag new_clauses in @@ -451,15 +466,15 @@ module Superposition (B : Terms.Blob) = superposition_with_table bag maxvar goal atable in debug "Superposed goal with active clauses"; - (* We demodulate the new goals with active clauses *) + (* We simplify the new goals with active clauses *) let bag, new_goals = List.fold_left (fun (bag, acc) g -> - let bag, g = demodulate bag g atable in - bag, g :: acc) + let bag, g = simplify_goal maxvar atable bag g in + bag,g::acc) (bag, []) new_goals in - debug "Demodulated goal with active clauses"; + debug "Simplified new goals with active clauses"; bag, maxvar, List.rev new_goals ;; -- 2.39.2