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))); *)
39 let metasenv, proofterm =
40 let rec aux k metasenv = function
41 | NCic.Meta _ as t -> metasenv, t
43 let metasenv, i, _, _ =
44 NCicMetaSubst.mk_meta metasenv context `IsTerm
46 metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
47 | t -> NCicUntrusted.map_term_fold_a
48 (fun _ k -> k+1) k aux metasenv t
50 aux 0 metasenv proofterm
52 debug (lazy (NCicPp.ppterm ~metasenv ~subst ~context proofterm));
54 let stamp = Unix.gettimeofday () in
55 let metasenv, subst, proofterm, _prooftype =
57 (rdb#set_coerc_db NCicCoercion.empty_db)
58 metasenv subst context proofterm None
60 print (lazy (Printf.sprintf "Refined in %fs"
61 (Unix.gettimeofday() -. stamp)));
63 proofterm, prooftype, metasenv, subst
65 let nparamod rdb metasenv subst context t table =
68 let metasenv = metasenv
73 let module B = B(C) in
74 let module P = NCicParamod(C) in
75 let module Pp = Pp.Pp(B) in
76 let bag, maxvar = Terms.empty_bag, 0 in
77 let (bag,maxvar), goals =
78 HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
80 let (bag,maxvar), passives =
81 HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
84 P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0)
85 ~g_passives:goals ~passives (bag,maxvar)
87 | P.Error _ | P.GaveUp | P.Timeout _ -> []
88 | P.Unsatisfiable solutions ->
89 List.map (readback rdb metasenv subst context) solutions
99 module CB = NCicBlob.NCicBlob(EmptyC)
100 module P = NCicParamod(EmptyC)
103 let empty_state = P.empty_state
105 let forward_infer_step s t ty =
106 let bag = P.bag_of_state s in
107 let bag,clause = P.mk_passive bag (t,ty) in
108 if Terms.is_eq_clause clause then
109 P.forward_infer_step (P.replace_bag s bag) clause 0
110 else (prerr_endline "not eq"; s)
113 let index_obj s uri =
114 let obj = NCicEnvironment.get_checked_obj uri in
116 | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
117 let nref = NReference.reference_of_spec uri (NReference.Def d) in
118 forward_infer_step s (NCic.Const nref) ty
122 let paramod rdb metasenv subst context s goal =
123 (* let stamp = Unix.gettimeofday () in *)
124 match P.nparamod ~useage:true ~max_steps:max_int
125 ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
126 | P.Error _ | P.GaveUp | P.Timeout _ -> []
127 | P.Unsatisfiable solutions ->
128 (* print (lazy (Printf.sprintf "Got solutions in %fs"
129 (Unix.gettimeofday() -. stamp))); *)
130 List.map (readback rdb metasenv subst context) solutions
133 let fast_eq_check rdb metasenv subst context s goal =
134 (* let stamp = Unix.gettimeofday () in *)
135 match P.fast_eq_check s goal with
136 | P.Error _ | P.GaveUp | P.Timeout _ -> []
137 | P.Unsatisfiable solutions ->
138 (* print (lazy (Printf.sprintf "Got solutions in %fs"
139 (Unix.gettimeofday() -. stamp))); *)
140 List.map (readback rdb metasenv subst context) solutions
143 let is_equation metasenv subst context ty =
145 NCicMetaSubst.saturate ~delta:0 metasenv subst context
148 | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
154 let demodulate rdb metasenv subst context s goal =
155 (* let stamp = Unix.gettimeofday () in *)
156 match P.fast_eq_check s goal with
157 | P.Error _ | P.GaveUp | P.Timeout _ -> []
158 | P.Unsatisfiable solutions ->
159 (* print (lazy (Printf.sprintf "Got solutions in %fs"
160 (Unix.gettimeofday() -. stamp))); *)
161 List.map (readback rdb metasenv subst context) solutions