2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: orderings.ml 9869 2009-06-11 22:52:38Z denes $ *)
14 NCicBlob.set_default_eqP()
16 NCicProof.set_default_sig()
20 let print s = prerr_endline (Lazy.force s);;
22 module B(C : NCicBlob.NCicContext): Orderings.Blob
23 with type t = NCic.term and type input = NCic.term
24 = Orderings.LPO(NCicBlob.NCicBlob(C))
26 module NCicParamod(C : NCicBlob.NCicContext) = Paramod.Paramod(B(C))
28 let readback rdb metasenv subst context (bag,i,fo_subst,l) =
31 print_endline (Pp.pp_unit_clause ~margin:max_int
32 (fst(Terms.M.find x bag)))) l;
34 (* let stamp = Unix.gettimeofday () in *)
35 let proofterm,prooftype = NCicProof.mk_proof bag i fo_subst l in
36 (* debug (lazy (Printf.sprintf "Got proof term in %fs"
37 (Unix.gettimeofday() -. stamp))); *)
38 let metasenv, proofterm =
39 let rec aux k metasenv = function
40 | NCic.Meta _ as t -> metasenv, t
42 let metasenv, i, _, _ =
43 NCicMetaSubst.mk_meta metasenv context `IsTerm
45 metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
46 | t -> NCicUntrusted.map_term_fold_a
47 (fun _ k -> k+1) k aux metasenv t
49 aux 0 metasenv proofterm
51 debug (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
53 let stamp = Unix.gettimeofday () in
54 let metasenv, subst, proofterm, _prooftype =
56 (rdb#set_coerc_db NCicCoercion.empty_db)
57 metasenv subst context proofterm None
59 print (lazy (Printf.sprintf "Refined in %fs"
60 (Unix.gettimeofday() -. stamp)));
62 proofterm, prooftype, metasenv, subst
64 let nparamod rdb metasenv subst context t table =
67 let metasenv = metasenv
72 let module B = B(C) in
73 let module P = NCicParamod(C) in
74 let module Pp = Pp.Pp(B) in
75 let bag, maxvar = Terms.empty_bag, 0 in
76 let (bag,maxvar), goals =
77 HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
79 let (bag,maxvar), passives =
80 HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
83 P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0)
84 ~g_passives:goals ~passives (bag,maxvar)
86 | P.Error _ | P.GaveUp | P.Timeout _ -> []
87 | P.Unsatisfiable solutions ->
88 List.map (readback rdb metasenv subst context) solutions
98 module CB = NCicBlob.NCicBlob(EmptyC)
99 module P = NCicParamod(EmptyC)
102 let empty_state = P.empty_state
104 let forward_infer_step s t ty =
105 let bag = P.bag_of_state s in
106 let bag,clause = P.mk_passive bag (t,ty) in
107 if Terms.is_eq_clause clause then
108 P.forward_infer_step (P.replace_bag s bag) clause 0
109 else (prerr_endline "not eq"; s)
112 let index_obj s uri =
113 let obj = NCicEnvironment.get_checked_obj uri in
115 | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
116 let nref = NReference.reference_of_spec uri (NReference.Def d) in
117 forward_infer_step s (NCic.Const nref) ty
121 let paramod rdb metasenv subst context s goal =
122 (* let stamp = Unix.gettimeofday () in *)
123 match P.nparamod ~useage:true ~max_steps:max_int
124 ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
125 | P.Error _ | P.GaveUp | P.Timeout _ -> []
126 | P.Unsatisfiable solutions ->
127 (* print (lazy (Printf.sprintf "Got solutions in %fs"
128 (Unix.gettimeofday() -. stamp))); *)
129 List.map (readback rdb metasenv subst context) solutions
132 let fast_eq_check rdb metasenv subst context s goal =
133 (* let stamp = Unix.gettimeofday () in *)
134 match P.fast_eq_check s goal with
135 | P.Error _ | P.GaveUp | P.Timeout _ -> []
136 | P.Unsatisfiable solutions ->
137 (* print (lazy (Printf.sprintf "Got solutions in %fs"
138 (Unix.gettimeofday() -. stamp))); *)
139 List.map (readback rdb metasenv subst context) solutions
142 let is_equation metasenv subst context ty =
144 NCicMetaSubst.saturate ~delta:0 metasenv subst context
147 | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
153 let demodulate rdb metasenv subst context s goal =
154 (* let stamp = Unix.gettimeofday () in *)
155 match P.fast_eq_check s goal with
156 | P.Error _ | P.GaveUp | P.Timeout _ -> []
157 | P.Unsatisfiable solutions ->
158 (* print (lazy (Printf.sprintf "Got solutions in %fs"
159 (Unix.gettimeofday() -. stamp))); *)
160 List.map (readback rdb metasenv subst context) solutions