]> matita.cs.unibo.it Git - helm.git/blob - components/binaries/saturate/saturate_main.ml
tagged 0.5.0-rc1
[helm.git] / components / binaries / saturate / saturate_main.ml
1 (* Copyright (C) 2005, 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 module Trivial_disambiguate:
29 sig
30   exception Ambiguous_term of string Lazy.t
31   (** disambiguate an _unanmbiguous_ term using dummy callbacks which fail if a
32     * choice from the user is needed to disambiguate the term
33     * @raise Ambiguous_term for ambiguous term *)
34   val disambiguate_string:
35     dbd:HSql.dbd ->
36     ?context:Cic.context ->
37     ?metasenv:Cic.metasenv ->
38     ?initial_ugraph:CicUniv.universe_graph -> 
39     ?aliases:DisambiguateTypes.environment ->(* previous interpretation status*)
40     string ->
41     ((DisambiguateTypes.domain_item * DisambiguateTypes.codomain_item) list *
42      Cic.metasenv *                 (* new metasenv *)
43      Cic.term *
44      CicUniv.universe_graph) list   (* disambiguated term *)
45 end
46 =
47 struct
48   exception Ambiguous_term of string Lazy.t
49   exception Exit
50   module Callbacks =
51   struct
52     let non p x = not (p x)
53     let interactive_user_uri_choice ~selection_mode ?ok
54           ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
55             List.filter (non UriManager.uri_is_var) uris
56     let interactive_interpretation_choice interp = raise Exit
57     let input_or_locate_uri ~(title:string) ?id = raise Exit
58   end
59   module Disambiguator = Disambiguate.Make (Callbacks)
60   let disambiguate_string ~dbd ?(context = []) ?(metasenv = []) ?initial_ugraph
61     ?(aliases = DisambiguateTypes.Environment.empty) term
62   =
63     let ast =
64       CicNotationParser.parse_level2_ast (Ulexing.from_utf8_string term)
65     in
66     try
67       fst (Disambiguator.disambiguate_term ~dbd ~context ~metasenv ("",0,ast)
68         ?initial_ugraph ~aliases ~universe:None)
69     with Exit -> raise (Ambiguous_term (lazy term))
70 end
71
72 let configuration_file = ref "../../../matita/matita.conf.xml";;
73
74 let core_notation_script = "../../../matita/core_notation.moo";;
75
76 let get_from_user ~(dbd:HSql.dbd) =
77   let rec get () =
78     match read_line () with
79     | "" -> []
80     | t -> t::(get ())
81   in
82   let term_string = String.concat "\n" (get ()) in
83   let env, metasenv, term, ugraph =
84     List.nth (Trivial_disambiguate.disambiguate_string dbd term_string) 0
85   in
86   term, metasenv, ugraph
87 ;;
88
89 let full = ref false;;
90
91 let retrieve_only = ref false;;
92
93 let demod_equalities = ref false;;
94
95 let main () =
96   let module S = Saturation in
97   let set_ratio v = S.weight_age_ratio := v; S.weight_age_counter := v
98   and set_sel v = S.symbols_ratio := v; S.symbols_counter := v;
99   and set_conf f = configuration_file := f
100   and set_ordering o =
101     match o with
102     | "lpo" -> Utils.compare_terms := Utils.lpo
103     | "kbo" -> Utils.compare_terms := Utils.kbo
104     | "nr-kbo" -> Utils.compare_terms := Utils.nonrec_kbo
105     | "ao" -> Utils.compare_terms := Utils.ao
106     | o -> raise (Arg.Bad ("Unknown term ordering: " ^ o))
107   and set_fullred b = S.use_fullred := b
108   and set_time_limit v = S.time_limit := float_of_int v
109   and set_width w = S.maxwidth := w
110   and set_depth d = S.maxdepth := d
111   and set_full () = full := true
112   and set_retrieve () = retrieve_only := true
113   and set_demod_equalities () = demod_equalities := true
114   in
115   Arg.parse [
116     "-full", Arg.Unit set_full, "Enable full mode";
117     "-f", Arg.Bool set_fullred,
118     "Enable/disable full-reduction strategy (default: enabled)";
119     
120     "-r", Arg.Int set_ratio, "Weight-Age equality selection ratio (default: 4)";
121
122     "-s", Arg.Int set_sel,
123     "symbols-based selection ratio (relative to the weight ratio, default: 0)";
124
125     "-c", Arg.String set_conf, "Configuration file (for the db connection)";
126
127     "-o", Arg.String set_ordering,
128     "Term ordering. Possible values are:\n" ^
129       "\tkbo: Knuth-Bendix ordering\n" ^
130       "\tnr-kbo: Non-recursive variant of kbo (default)\n" ^
131       "\tlpo: Lexicographic path ordering";
132
133     "-l", Arg.Int set_time_limit, "Time limit in seconds (default: no limit)";
134     
135     "-w", Arg.Int set_width,
136     Printf.sprintf "Maximal width (default: %d)" !Saturation.maxwidth;
137     
138     "-d", Arg.Int set_depth,
139     Printf.sprintf "Maximal depth (default: %d)" !Saturation.maxdepth;
140
141     "-retrieve", Arg.Unit set_retrieve, "retrieve only";
142     "-demod-equalities", Arg.Unit set_demod_equalities, "demod equalities";
143   ] (fun a -> ()) "Usage:";
144   Helm_registry.load_from !configuration_file;
145   ignore (CicNotation2.load_notation [] core_notation_script);
146   ignore (CicNotation2.load_notation [] "../../../matita/library/legacy/coq.ma");
147   let dbd = HSql.quick_connect
148     ~host:(Helm_registry.get "db.host")
149     ~user:(Helm_registry.get "db.user")
150     ~database:(Helm_registry.get "db.database")
151     ()
152   in
153   let term, metasenv, ugraph = get_from_user ~dbd in
154   if !retrieve_only then
155     Saturation.retrieve_and_print dbd term metasenv ugraph
156   else if !demod_equalities then
157     Saturation.main_demod_equalities dbd term metasenv ugraph
158   else
159     Saturation.main dbd !full term metasenv ugraph
160 ;;
161
162 let _ =
163   (*try*)
164     main ()
165   (*with exn -> prerr_endline (Printexc.to_string exn)*)
166