From 8a3045a162622e8a76ffdb267309faff496ee7ec Mon Sep 17 00:00:00 2001 From: denes Date: Tue, 28 Jul 2009 17:50:12 +0000 Subject: [PATCH] Various architectural changes --- .../binaries/matitaprover/matitaprover.ml | 95 ++++++++++--------- .../binaries/matitaprover/tptp_cnf.ml | 17 ++-- .../binaries/matitaprover/tptp_cnf.mli | 3 +- 3 files changed, 63 insertions(+), 52 deletions(-) diff --git a/helm/software/components/binaries/matitaprover/matitaprover.ml b/helm/software/components/binaries/matitaprover/matitaprover.ml index 3736c024d..12fb6b9aa 100644 --- a/helm/software/components/binaries/matitaprover/matitaprover.ml +++ b/helm/software/components/binaries/matitaprover/matitaprover.ml @@ -46,36 +46,40 @@ module type LeafComparer = end ;; +let rec embed m = function + | Ast.Variable name -> + (try m, List.assoc name m + with Not_found -> + let t = Terms.Var ~-(List.length m) in + (name,t)::m, t) + | Ast.Constant name -> m, Terms.Leaf (hash name) + | Ast.Function (name,args) -> + let m, args = + HExtlib.list_mapi_acc + (fun x _ m -> embed m x) m args + in + m, Terms.Node (Terms.Leaf (hash name):: args) +;; + +let saturate bo (nlit,plit) = + let vars,nlit = HExtlib.list_mapi_acc (fun x _ m -> embed m x) [] nlit in + let vars,plit = HExtlib.list_mapi_acc (fun x _ m -> embed m x) vars plit in + let _, bo = embed vars bo in + let bo = Terms.Node (bo :: List.map snd (List.rev vars)) in + bo, (nlit, plit) +;; + +let embed t = snd(embed [] t);; + + module MakeBlob(C:LeafComparer) : Terms.Blob - with type t = leaf and type input = Ast.term = struct + with type t = leaf = struct type t = leaf let eq a b = a == b let compare a b = C.cmp a b let eqP = hash "==" let pp (_,a) = a - type input = Ast.term - let rec embed m = function - | Ast.Variable name -> - (try m, List.assoc name m - with Not_found -> - let t = Terms.Var ~-(List.length m) in - (name,t)::m, t) - | Ast.Constant name -> m, Terms.Leaf (hash name) - | Ast.Function (name,args) -> - let m, args = - HExtlib.list_mapi_acc - (fun x _ m -> embed m x) m args - in - m, Terms.Node (Terms.Leaf (hash name):: args) - ;; - let saturate bo ty = - let vars, ty = embed [] ty in - let _, bo = embed vars bo in - let bo = Terms.Node (bo :: List.map snd (List.rev vars)) in - bo, ty - ;; - let embed t = snd(embed [] t);; - + end ;; @@ -100,13 +104,14 @@ let success_msg bag l (pp : ?margin:int -> leaf Terms.clause -> string) ord = (times.Unix.tms_utime +. times.Unix.tms_stime) ^ " using " ^ ord); ;; -let start_msg stats passives g_passives (pp : ?margin:int -> leaf Terms.clause -> string) oname = +let start_msg stats hypotheses (g_t,g_ty) + (pp : ?margin:int -> leaf Terms.clause -> string) oname = let prefix = string_of_int (Unix.getpid ()) in let prerr_endline s = prerr_endline (prefix ^ ": " ^ s) in prerr_endline "Facts:"; - List.iter (fun x -> prerr_endline (" " ^ pp x)) passives; + (*List.iter (fun x -> prerr_endline (" " ^ pp x)) passives;*) prerr_endline "Goal:"; - prerr_endline (" " ^ pp g_passives); + (*prerr_endline (" " ^ pp g_passives);*) prerr_endline "Order:"; prerr_endline (" " ^ oname); prerr_endline "Leaf order:"; @@ -120,18 +125,17 @@ let start_msg stats passives g_passives (pp : ?margin:int -> leaf Terms.clause - let report_error s = prerr_endline (string_of_int (Unix.getpid())^": "^s);; -module Main(P : Paramod.Paramod with type t = leaf) = struct +module Main(O : Orderings.Blob with type t = leaf) = struct + module P = Paramod.Paramod(O) + module Utils = FoUtils.Utils(O) - let run ~useage ~printmsg stats goal hypotheses pp_clause name = - let bag = Terms.empty_bag, 0 in - let bag, g_passives = P.mk_goal bag goal in - let bag, passives = - HExtlib.list_mapi_acc (fun x _ b -> P.mk_passive b x) bag hypotheses - in - if printmsg then start_msg stats passives g_passives pp_clause name; + let run ~useage ~printmsg stats (g_t,g_ty) hypotheses pp_clause name = + let g_t,g_ty = saturate g_t g_ty in + let hypotheses = List.map (fun (t,(nlit,plit)) -> saturate t (nlit,plit)) hypotheses in + if printmsg then start_msg stats hypotheses (g_t,g_ty) pp_clause name; match P.paramod ~useage - ~max_steps:max_int bag ~g_passives:[g_passives] ~passives + ~max_steps:max_int (g_t,g_ty) ~print_problem:printmsg hypotheses with | P.Error s -> report_error s; 3 | P.Unsatisfiable ((bag,_,l)::_) -> @@ -143,7 +147,7 @@ module Main(P : Paramod.Paramod with type t = leaf) = struct ;; end - let compute_stats goal hypotheses = +(* let compute_stats goal hypotheses = let module C = struct type t = leaf let cmp (a,_) (b,_) = Pervasives.compare a b end in @@ -179,14 +183,14 @@ end in if res = 0 then Pervasives.compare (HExtlib.list_index ((=) n1) oplist) (HExtlib.list_index ((=) n2) oplist) else res) data - ;; + ;;*) let worker order ~useage ~printmsg goal hypotheses = - let stats = compute_stats goal hypotheses in + (*let stats = compute_stats goal hypotheses in*) let module C = struct let cmp = - let raw = List.map snd stats in + (*let raw = List.map snd stats in let rec pos x = function | ((y,_)::tl) when y = x -> 0 | _::tl -> 1 + pos x tl @@ -201,25 +205,26 @@ let worker order ~useage ~printmsg goal hypotheses = (pos a stats) (pos b stats)) else - (prerr_endline "CLASH, statistics insufficient"; - fun (a,_) (b,_) -> Pervasives.compare a b) + (prerr_endline "CLASH, statistics insufficient";*) + fun (a,_) (b,_) -> Pervasives.compare a b(* ) *) ;; end in let module B = MakeBlob(C) in let module Pp = Pp.Pp(B) in + let stats = [] in match order with | `NRKBO -> let module O = Orderings.NRKBO(B) in - let module Main = Main(Paramod.Paramod(O)) in + let module Main = Main(O) in Main.run ~useage ~printmsg stats goal hypotheses Pp.pp_clause O.name | `KBO -> let module O = Orderings.KBO(B) in - let module Main = Main(Paramod.Paramod(O)) in + let module Main = Main(O) in Main.run ~useage ~printmsg stats goal hypotheses Pp.pp_clause O.name | `LPO -> let module O = Orderings.LPO(B) in - let module Main = Main(Paramod.Paramod(O)) in + let module Main = Main(O) in Main.run ~useage ~printmsg stats goal hypotheses Pp.pp_clause O.name ;; diff --git a/helm/software/components/binaries/matitaprover/tptp_cnf.ml b/helm/software/components/binaries/matitaprover/tptp_cnf.ml index 8d3cedfd4..06f777ff6 100644 --- a/helm/software/components/binaries/matitaprover/tptp_cnf.ml +++ b/helm/software/components/binaries/matitaprover/tptp_cnf.ml @@ -5,12 +5,17 @@ let trans_atom = function | Ast.NotEq (a,b) -> false, Ast.Function ("==",[Ast.Constant "_"; a; b]) ;; -let trans_formulae = function - | Ast.Disjunction _ -> assert false - | Ast.Atom a -> trans_atom a +let rec trans_formulae (nlit,plit) = function + | Ast.Disjunction (a,b) -> + trans_formulae (trans_formulae (nlit,plit) b) a + | Ast.Atom a -> + let is_positive,lit = trans_atom a in + if is_positive then (nlit,lit::plit) else (lit::nlit,plit) | Ast.NegAtom _ -> assert false ;; +let trans_formulae = trans_formulae ([],[]);; + (* HELPERS *) let resolve ~tptppath s = @@ -50,9 +55,9 @@ let parse ~tptppath filename = | Ast.Comment _ :: tl -> aux p n tl | Ast.AnnotatedFormula (name, (Ast.Axiom | Ast.Hypothesis|Ast.Negated_conjecture), f,_,_) :: tl-> - let is_positive, f = trans_formulae f in - if is_positive then aux (p@[Ast.Constant name,f]) n tl - else aux p (n@[Ast.Constant name,f]) tl + let (nlit,plit) = trans_formulae f in + if plit = [] then aux p (n@[Ast.Constant name,(nlit,plit)]) tl + else aux (p@[Ast.Constant name,(nlit,plit)]) n tl | _ -> prerr_endline "bad syntax"; assert false in aux [] [] statements diff --git a/helm/software/components/binaries/matitaprover/tptp_cnf.mli b/helm/software/components/binaries/matitaprover/tptp_cnf.mli index 48b57dbd7..18933ee67 100644 --- a/helm/software/components/binaries/matitaprover/tptp_cnf.mli +++ b/helm/software/components/binaries/matitaprover/tptp_cnf.mli @@ -13,4 +13,5 @@ val parse: tptppath:string -> string -> - (Ast.term * Ast.term) list * (Ast.term * Ast.term) list + (Ast.term * (Ast.term list * Ast.term list)) list + * (Ast.term * (Ast.term list * Ast.term list)) list -- 2.39.2