]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/tactics/autoTactic.ml
is_identity -> is_weak_identity
[helm.git] / helm / software / components / tactics / autoTactic.ml
1 (* Copyright (C) 2002, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (* $Id$ *)
27
28  let debug = false
29  let debug_print s = if debug then prerr_endline (Lazy.force s)
30
31 (* let debug_print = fun _ -> () *)
32
33 let bool params name default =
34     try 
35       let s = List.assoc name params in 
36       if s = "" || s = "1" || s = "true" || s = "yes" then true
37       else if s = "0" || s = "false" || s = "no" then false
38       else 
39         let msg = "Unrecognized value for parameter "^name^"\n" in
40         let msg = msg ^ "Accepted values are 1,true,yes and 0,false,no" in
41         raise (ProofEngineTypes.Fail (lazy msg))
42     with Not_found -> default
43 ;; 
44
45 let string params name default =
46     try List.assoc name params with
47     | Not_found -> default
48 ;; 
49
50 let int params name default =
51     try int_of_string (List.assoc name params) with
52     | Not_found -> default
53     | Failure _ -> 
54         raise (ProofEngineTypes.Fail (lazy (name ^ " must be an integer")))
55 ;;  
56
57 let auto_tac ~params ~(dbd:HMysql.dbd) (proof, goal) =
58   (* argument parsing *)
59   let int = int params 
60   and string = string params 
61   and bool = bool params in
62   let depth = int "depth" ((AutoTypes.default_flags()).AutoTypes.maxdepth) in
63   let width = int "width" ((AutoTypes.default_flags()).AutoTypes.maxwidth) in
64   let timeout = int "timeout" 0 in
65   let use_paramod = bool "use_paramod" true in
66   let use_only_paramod = bool "paramodulation" false in
67   (* hacks to debug paramod *)
68   let superposition = bool "superposition" false in
69   let target = string "target" "" in
70   let table = string "table" "" in
71   let subterms_only = bool "subterms_only" false in
72   let demod_table = string "demod_table" "" in
73   match superposition with
74   | true -> 
75       (* this is the ugly hack to debug paramod *)
76       Saturation.superposition_tac 
77         ~target ~table ~subterms_only ~demod_table (proof,goal)
78   | false -> 
79       (* this is the real auto *)
80       let _, metasenv, _, _ = proof in
81       let _, context, goalty = CicUtil.lookup_meta goal metasenv in
82       let cache = 
83         AutoCache.cache_add_library dbd proof [goal] AutoCache.cache_empty
84       in 
85       let cache = AutoCache.cache_add_context context metasenv cache in
86       let oldmetasenv = metasenv in
87       let flags = {
88         AutoTypes.maxdepth = depth;
89         AutoTypes.maxwidth = width;
90         AutoTypes.timeout = 
91           if timeout = 0 then float_of_int timeout 
92           else Unix.gettimeofday() +. (float_of_int timeout); 
93         AutoTypes.use_paramod = use_paramod;
94         AutoTypes.use_only_paramod = use_only_paramod;
95         AutoTypes.dont_cache_failures = false
96       }
97       in
98       match Auto.auto dbd cache context metasenv [goal] flags with
99       | None,cache -> 
100           raise (ProofEngineTypes.Fail (lazy "Auto gave up"))
101       | Some (subst,metasenv),cache -> 
102           let proof,metasenv = 
103             ProofEngineHelpers.subst_meta_and_metasenv_in_proof
104               proof goal (CicMetaSubst.apply_subst subst) metasenv
105           in
106           let opened = 
107             ProofEngineHelpers.compare_metasenvs ~oldmetasenv
108               ~newmetasenv:metasenv
109           in
110           proof,opened
111 ;;
112
113 let auto_tac ~params ~dbd =
114       ProofEngineTypes.mk_tactic (auto_tac ~params ~dbd)
115 ;;
116
117 let pp_proofterm = Equality.pp_proofterm;;