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);;
23 module B(C : NCicBlob.NCicContext): Orderings.Blob
24 with type t = NCic.term and type input = NCic.term
25 = Orderings.LPO(NCicBlob.NCicBlob(C))
27 module NCicParamod(C : NCicBlob.NCicContext) = Paramod.Paramod(B(C))
29 let readback status ?(demod=false) metasenv subst context (bag,i,fo_subst,l) =
32 print_endline (Pp.pp_unit_clause ~margin:max_int
33 (fst(Terms.M.find x bag)))) l;
35 (* let stamp = Unix.gettimeofday () in *)
36 let proofterm,prooftype = NCicProof.mk_proof status ~demod bag i fo_subst l in
37 (* debug (lazy (Printf.sprintf "Got proof term in %fs"
38 (Unix.gettimeofday() -. stamp))); *)
40 let metasenv, proofterm =
41 let rec aux k metasenv = function
42 | NCic.Meta _ as t -> metasenv, t
44 let metasenv, i, _, _ =
45 NCicMetaSubst.mk_meta metasenv context `IsTerm
47 metasenv, NCic.Meta (i,(k,NCic.Irl (List.length context)))
48 | t -> NCicUntrusted.map_term_fold_a
49 (fun _ k -> k+1) k aux metasenv t
51 aux 0 metasenv proofterm
53 debug (lazy (status#ppterm ~metasenv ~subst ~context proofterm));
55 let stamp = Unix.gettimeofday () in
56 let metasenv, subst, proofterm, _prooftype =
58 (status#set_coerc_db NCicCoercion.empty_db)
59 metasenv subst context proofterm None
61 print (lazy (Printf.sprintf "Refined in %fs"
62 (Unix.gettimeofday() -. stamp)));
64 proofterm, prooftype, metasenv, subst
66 let nparamod status metasenv subst context t table =
69 let metasenv = metasenv
74 let module B = B(C) in
75 let module P = NCicParamod(C) in
76 let module Pp = Pp.Pp(B) in
77 let bag, maxvar = Terms.empty_bag, 0 in
78 let (bag,maxvar), goals =
79 HExtlib.list_mapi_acc (fun x _ a -> P.mk_goal a x) (bag,maxvar) [t]
81 let (bag,maxvar), passives =
82 HExtlib.list_mapi_acc (fun x _ a -> P.mk_passive a x) (bag,maxvar) table
85 P.paramod ~useage:true ~max_steps:max_int ~timeout:(Unix.gettimeofday () +. 300.0)
86 ~g_passives:goals ~passives (bag,maxvar)
88 | P.Error _ | P.GaveUp | P.Timeout _ -> []
89 | P.Unsatisfiable solutions ->
90 List.map (readback status metasenv subst context) solutions
100 module CB = NCicBlob.NCicBlob(EmptyC)
101 module P = NCicParamod(EmptyC)
104 let empty_state = P.empty_state
106 let forward_infer_step s t ty =
107 let bag = P.bag_of_state s in
108 let bag,clause = P.mk_passive bag (t,ty) in
109 if Terms.is_eq_clause clause then
110 P.forward_infer_step (P.replace_bag s bag) clause 0
111 else (debug (lazy "not eq"); s)
114 let index_obj status s uri =
115 let obj = NCicEnvironment.get_checked_obj status uri in
116 debug (lazy ("indexing : " ^ (NUri.string_of_uri uri)));
117 debug (lazy ("no : " ^ (string_of_int (fst (Obj.magic uri)))));
119 | (_,_,[],[],NCic.Constant(_,_,None,ty,_)) ->
120 let nref = NReference.reference_of_spec uri NReference.Decl in
121 forward_infer_step s (NCic.Const nref) ty
122 | (_,d,[],[],NCic.Constant(_,_,Some(_),ty,_)) ->
123 let nref = NReference.reference_of_spec uri (NReference.Def d) in
124 forward_infer_step s (NCic.Const nref) ty
128 let demod status metasenv subst context s goal =
129 (* let stamp = Unix.gettimeofday () in *)
130 match P.demod s goal with
131 | P.Error _ | P.GaveUp | P.Timeout _ -> []
132 | P.Unsatisfiable solutions ->
133 (* print (lazy (Printf.sprintf "Got solutions in %fs"
134 (Unix.gettimeofday() -. stamp))); *)
135 List.map (readback ~demod:true status metasenv subst context) solutions
138 let paramod status metasenv subst context s goal =
139 (* let stamp = Unix.gettimeofday () in *)
140 match P.nparamod ~useage:true ~max_steps:max_int
141 ~timeout:(Unix.gettimeofday () +. 300.0) s goal with
142 | P.Error _ | P.GaveUp | P.Timeout _ -> []
143 | P.Unsatisfiable solutions ->
144 (* print (lazy (Printf.sprintf "Got solutions in %fs"
145 (Unix.gettimeofday() -. stamp))); *)
146 List.map (readback status metasenv subst context) solutions
149 let fast_eq_check status metasenv subst context s goal =
150 (* let stamp = Unix.gettimeofday () in *)
151 match P.fast_eq_check s goal with
152 | P.Error _ | P.GaveUp | P.Timeout _ -> []
153 | P.Unsatisfiable solutions ->
154 (* print (lazy (Printf.sprintf "Got solutions in %fs"
155 (Unix.gettimeofday() -. stamp))); *)
156 List.map (readback status metasenv subst context) solutions
159 let is_equation status metasenv subst context ty =
161 NCicMetaSubst.saturate status ~delta:0 metasenv subst context
164 | NCic.Appl (eq ::tl) when eq = CB.eqP -> true
169 let demodulate status 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 status metasenv subst context) solutions