1 (* Copyright (C) 2000-2002, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 module MQI = MQueryInterpreter
38 module I = MQueryInterpreter
40 module G = MQueryGenerator
42 (* search arguments on which Apply tactic doesn't fail *)
43 let matchConclusion mqi_handle ?(output_html = (fun _ -> ())) ~choose_must() status =
44 let ((_, metasenv, _, _), metano) = status in
45 let (_, ey ,ty) = CicUtil.lookup_meta metano metasenv in
46 let list_of_must, only = CGMatchConclusion.get_constraints metasenv ey ty in
47 match list_of_must with
50 let must = choose_must list_of_must only in
54 (G.query_of_constraints
55 (Some CGMatchConclusion.universe)
56 (must,[],[]) (Some only,None,None)) in
61 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri
65 (* TODO ristretto per ragioni di efficienza *)
66 prerr_endline "STO FILTRANDO";
67 List.filter (fun uri -> Pcre.pmatch ~pat:"^cic:/Coq/" uri) uris
69 prerr_endline "HO FILTRATO";
75 let tl',exc = filter_out tl in
80 (PrimitiveTactics.apply_tac
81 ~term:(MQueryMisc.term_of_cic_textual_parser_uri
82 (MQueryMisc.cic_textual_parser_uri_of_string uri))
85 with ProofEngineTypes.Fail _ -> false)
91 (ProofEngineTypes.Fail _) as e ->
93 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
94 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
101 " <h1>Objects that can actually be applied: </h1> " ^
102 String.concat "<br>" uris' ^ exc ^
103 " <h1>Number of false matches: " ^
104 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
105 " <h1>Number of good matches: " ^
106 string_of_int (List.length uris') ^ "</h1>"
113 (*matchConclusion modificata per evitare una doppia apply*)
114 let matchConclusion2 mqi_handle ?(output_html = (fun _ -> ())) ~choose_must() status =
115 let ((_, metasenv, _, _), metano) = status in
116 let (_, ey ,ty) = CicUtil.lookup_meta metano metasenv in
117 let list_of_must, only = CGMatchConclusion.get_constraints metasenv ey ty in
118 match list_of_must with
121 let must = choose_must list_of_must only in
124 (G.query_of_constraints
125 (Some CGMatchConclusion.universe)
126 (must,[],[]) (Some only,None,None)) in
130 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri
134 (* TODO ristretto per ragioni di efficienza *)
135 prerr_endline "STO FILTRANDO2";
136 List.filter (fun uri -> Pcre.pmatch ~pat:"^cic:/Coq/" uri) uris
139 let len = String.length s in
140 let suffix = String.sub s (len-4) 4 in
141 not (suffix = ".var") in
142 let uris = List.filter isvar uris in
143 prerr_endline "HO FILTRATO2";
149 let tl' = filter_out tl in
151 ((PrimitiveTactics.apply_tac
152 ~term:(MQueryMisc.term_of_cic_textual_parser_uri
153 (MQueryMisc.cic_textual_parser_uri_of_string uri))
155 with ProofEngineTypes.Fail _ -> tl'
157 prerr_endline (string_of_int (List.length uris));
163 (*funzione che sceglie il penultimo livello di profondita' dei must*)
166 let choose_must list_of_must only=
167 let n = (List.length list_of_must) - 1 in
168 List.nth list_of_must n
171 let choose_must list_of_must only =
172 List.nth list_of_must 0
174 (* OLD CODE: TO BE REMOVED
175 (*Funzione position prende una lista e un elemento e mi ritorna la posizione dell'elem nella lista*)
176 (*Mi serve per ritornare la posizione del teo che produce meno subgoal*)
178 exception NotInTheList;;
184 [] -> raise NotInTheList
186 | _::tl -> aux (k+1) tl in
192 (*function taking a status and returning a new status after having searching a theorem to apply ,theorem which *)
193 (*generate the less number of subgoals*)
195 let searchTheorem (proof,goal) =
196 let mqi_flags = [MQIC.Postgres ; MQIC.Stat ; MQIC.Warn ; MQIC.Log] (* default MathQL interpreter options *)
198 let mqi_handle = MQIC.init mqi_flags prerr_string
202 mqi_handle ~choose_must() (proof, goal)
207 (MQueryMisc.term_of_cic_textual_parser_uri
208 (MQueryMisc.cic_textual_parser_uri_of_string string))
215 PrimitiveTactics.apply_tac ~term (proof,goal))
218 let (list_of_subgoal: int list list) =
219 List.map snd list_proofgoal
222 List.map List.length list_of_subgoal
225 List.sort Pervasives.compare list_of_num
226 in (*ordino la lista in modo cresc*)
227 let min= List.nth list_sort 0 (*prendo il minimo*)
229 let uri' = (*cerco il teo di pos k*)
230 List.nth list_of_termin (position min list_of_num)
233 String.sub uri' 4 (String.length uri' - 4)
235 (* modifico la str in modo che sia accettata da apply*)
237 PrimitiveTactics.apply_tac ~term:uri' (proof,goal)
242 let searchTheorems mqi_handle (proof,goal) =
243 (*prerr_endline "1";*)
245 matchConclusion2 mqi_handle ~choose_must() (proof, goal) in
246 prerr_endline (string_of_int (List.length uris'));
247 (*prerr_endline "2";*)
248 (* let list_of_termin =
251 (MQueryMisc.term_of_cic_textual_parser_uri
252 (MQueryMisc.cic_textual_parser_uri_of_string string)))
258 PrimitiveTactics.apply_tac ~term (proof,goal)) list_of_termin in*)
259 (*prerr_endline "4";*)
262 (fun (_,gl1) (_,gl2) ->
263 Pervasives.compare (List.length gl1) (List.length gl2))
266 (*prerr_endline "5";*)