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 ?(demod=false) 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 ~demod 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 (debug (lazy "not eq"); s)
113 let index_obj s uri =
114 let obj = NCicEnvironment.get_checked_obj uri in
115 debug (lazy ("indexing : " ^ (NUri.string_of_uri uri)));
116 debug (lazy ("no : " ^ (string_of_int (fst (Obj.magic uri)))));
118 | (_,_,[],[],NCic.Constant(_,_,None,ty,_)) ->
119 let nref = NReference.reference_of_spec uri NReference.Decl in
120 forward_infer_step s (NCic.Const nref) ty
121 | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
122 let nref = NReference.reference_of_spec uri (NReference.Def d) in
123 forward_infer_step s (NCic.Const nref) ty
127 let demod rdb metasenv subst context s goal =
128 (* let stamp = Unix.gettimeofday () in *)
129 match P.demod s goal with
130 | P.Error _ | P.GaveUp | P.Timeout _ -> []
131 | P.Unsatisfiable solutions ->
132 (* print (lazy (Printf.sprintf "Got solutions in %fs"
133 (Unix.gettimeofday() -. stamp))); *)
134 List.map (readback ~demod:true rdb metasenv subst context) solutions
137 let paramod rdb metasenv subst context s goal =
138 (* let stamp = Unix.gettimeofday () in *)
139 match P.nparamod ~useage:true ~max_steps:max_int
140 ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
141 | P.Error _ | P.GaveUp | P.Timeout _ -> []
142 | P.Unsatisfiable solutions ->
143 (* print (lazy (Printf.sprintf "Got solutions in %fs"
144 (Unix.gettimeofday() -. stamp))); *)
145 List.map (readback rdb metasenv subst context) solutions
148 let fast_eq_check rdb metasenv subst context s goal =
149 (* let stamp = Unix.gettimeofday () in *)
150 match P.fast_eq_check s goal with
151 | P.Error _ | P.GaveUp | P.Timeout _ -> []
152 | P.Unsatisfiable solutions ->
153 (* print (lazy (Printf.sprintf "Got solutions in %fs"
154 (Unix.gettimeofday() -. stamp))); *)
155 List.map (readback rdb metasenv subst context) solutions
158 let is_equation metasenv subst context ty =
160 NCicMetaSubst.saturate ~delta:0 metasenv subst context
163 | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
169 let demodulate rdb metasenv subst context s goal =
170 (* let stamp = Unix.gettimeofday () in *)
171 match P.fast_eq_check s goal with
172 | P.Error _ | P.GaveUp | P.Timeout _ -> []
173 | P.Unsatisfiable solutions ->
174 (* print (lazy (Printf.sprintf "Got solutions in %fs"
175 (Unix.gettimeofday() -. stamp))); *)
176 List.map (readback rdb metasenv subst context) solutions