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 exception RefreshSequentException of exn;;
37 exception RefreshProofException of exn;;
39 module type Callbacks =
41 val sequent_viewer : unit -> TermViewer.sequent_viewer
42 val term_editor : unit -> TermEditor.term_editor
43 val get_current_scratch_infos :
46 (Cic.id, Cic.term) Hashtbl.t *
47 (Cic.id, Cic.id option) Hashtbl.t *
48 (string, Cic.hypothesis) Hashtbl.t
50 val set_current_scratch_infos :
52 (Cic.id, Cic.term) Hashtbl.t *
53 (Cic.id, Cic.id option) Hashtbl.t *
54 (string, Cic.hypothesis) Hashtbl.t
56 val refresh_proof : unit -> unit
57 val refresh_goals : unit -> unit
58 val decompose_uris_choice_callback :
59 (UriManager.uri * int * 'a) list ->
60 (UriManager.uri * int * 'b list) list
61 val mk_fresh_name_callback :
62 Cic.context -> Cic.name -> typ:Cic.term -> Cic.name
63 val output_html : string -> unit
67 module Make(C:Callbacks) =
70 let call_tactic tactic () =
71 let savedproof = !ProofEngine.proof in
72 let savedgoal = !ProofEngine.goal in
79 RefreshSequentException e ->
81 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
82 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
83 ProofEngine.proof := savedproof ;
84 ProofEngine.goal := savedgoal ;
86 | RefreshProofException e ->
88 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
89 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
90 ProofEngine.proof := savedproof ;
91 ProofEngine.goal := savedgoal ;
96 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
97 ProofEngine.proof := savedproof ;
98 ProofEngine.goal := savedgoal
101 let call_tactic_with_input tactic () =
102 let savedproof = !ProofEngine.proof in
103 let savedgoal = !ProofEngine.goal in
104 let uri,metasenv,bo,ty =
105 match !ProofEngine.proof with
107 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
109 let canonical_context =
110 match !ProofEngine.goal with
113 let (_,canonical_context,_) =
114 List.find (function (m,_,_) -> m=metano) metasenv
120 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
122 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
126 (C.term_editor ())#reset
128 RefreshSequentException e ->
130 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
131 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
132 ProofEngine.proof := savedproof ;
133 ProofEngine.goal := savedgoal ;
135 | RefreshProofException e ->
137 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
138 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
139 ProofEngine.proof := savedproof ;
140 ProofEngine.goal := savedgoal ;
145 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
146 ProofEngine.proof := savedproof ;
147 ProofEngine.goal := savedgoal
149 let call_tactic_with_goal_input tactic () =
150 let module L = LogicalOperations in
151 let module G = Gdome in
152 let savedproof = !ProofEngine.proof in
153 let savedgoal = !ProofEngine.goal in
154 match (C.sequent_viewer ())#get_selected_terms with
162 RefreshSequentException e ->
164 ("<h1 color=\"red\">Exception raised during the refresh of " ^
165 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
166 ProofEngine.proof := savedproof ;
167 ProofEngine.goal := savedgoal ;
169 | RefreshProofException e ->
171 ("<h1 color=\"red\">Exception raised during the refresh of " ^
172 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
173 ProofEngine.proof := savedproof ;
174 ProofEngine.goal := savedgoal ;
179 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
180 ProofEngine.proof := savedproof ;
181 ProofEngine.goal := savedgoal ;
185 ("<h1 color=\"red\">No term selected</h1>")
188 ("<h1 color=\"red\">Many terms selected</h1>")
190 let call_tactic_with_goal_inputs tactic () =
191 let module L = LogicalOperations in
192 let module G = Gdome in
193 let savedproof = !ProofEngine.proof in
194 let savedgoal = !ProofEngine.goal in
196 match (C.sequent_viewer ())#get_selected_terms with
199 ("<h1 color=\"red\">No term selected</h1>")
205 RefreshSequentException e ->
207 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
208 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
209 ProofEngine.proof := savedproof ;
210 ProofEngine.goal := savedgoal ;
212 | RefreshProofException e ->
214 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
215 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
216 ProofEngine.proof := savedproof ;
217 ProofEngine.goal := savedgoal ;
222 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
223 ProofEngine.proof := savedproof ;
224 ProofEngine.goal := savedgoal
226 let call_tactic_with_input_and_goal_input tactic () =
227 let module L = LogicalOperations in
228 let module G = Gdome in
229 let savedproof = !ProofEngine.proof in
230 let savedgoal = !ProofEngine.goal in
231 match (C.sequent_viewer ())#get_selected_terms with
235 let uri,metasenv,bo,ty =
236 match !ProofEngine.proof with
238 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
240 let canonical_context =
241 match !ProofEngine.goal with
244 let (_,canonical_context,_) =
245 List.find (function (m,_,_) -> m=metano) metasenv
248 let (metasenv',expr) =
249 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
251 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
252 tactic ~goal_input:term ~input:expr ;
255 (C.term_editor ())#reset
257 RefreshSequentException e ->
259 ("<h1 color=\"red\">Exception raised during the refresh of " ^
260 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
261 ProofEngine.proof := savedproof ;
262 ProofEngine.goal := savedgoal ;
264 | RefreshProofException e ->
266 ("<h1 color=\"red\">Exception raised during the refresh of " ^
267 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
268 ProofEngine.proof := savedproof ;
269 ProofEngine.goal := savedgoal ;
274 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
275 ProofEngine.proof := savedproof ;
276 ProofEngine.goal := savedgoal ;
280 ("<h1 color=\"red\">No term selected</h1>")
283 ("<h1 color=\"red\">Many terms selected</h1>")
285 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
286 let module L = LogicalOperations in
287 let module G = Gdome in
289 (scratch_window#mmlwidget : GMathViewAux.multi_selection_math_view) in
290 let savedproof = !ProofEngine.proof in
291 let savedgoal = !ProofEngine.goal in
292 match mmlwidget#get_selections with
295 ((node : Gdome.element)#getAttributeNS
296 ~namespaceURI:Misc.helmns
297 ~localName:(G.domString "xref"))#to_string
299 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
303 match C.get_current_scratch_infos () with
304 (* term is the whole goal in the scratch_area *)
305 Some (term,ids_to_terms, ids_to_father_ids,_) ->
307 let expr = tactic term (Hashtbl.find ids_to_terms id) in
308 let mml,scratch_infos =
309 ApplyStylesheets.mml_of_cic_term 111 expr
311 C.set_current_scratch_infos (Some scratch_infos) ;
312 scratch_window#show () ;
313 scratch_window#mmlwidget#load_doc ~dom:mml
314 | None -> assert false (* "ERROR: No current term!!!" *)
318 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
322 ("<h1 color=\"red\">No term selected</h1>")
325 ("<h1 color=\"red\">Many terms selected</h1>")
327 let call_tactic_with_goal_inputs_in_scratch tactic scratch_window () =
328 let module L = LogicalOperations in
329 let module G = Gdome in
331 (scratch_window#mmlwidget : GMathViewAux.multi_selection_math_view) in
332 let savedproof = !ProofEngine.proof in
333 let savedgoal = !ProofEngine.goal in
334 match mmlwidget#get_selections with
337 ("<h1 color=\"red\">No term selected</h1>")
340 match C.get_current_scratch_infos () with
341 (* term is the whole goal in the scratch_area *)
342 Some (term,ids_to_terms, ids_to_father_ids,_) ->
343 let term_of_node node =
345 ((node : Gdome.element)#getAttributeNS
346 ~namespaceURI:Misc.helmns
347 ~localName:(G.domString "xref"))#to_string
349 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
352 Hashtbl.find ids_to_terms id
354 let terms = List.map term_of_node l in
355 let expr = tactic terms term in
356 let mml,scratch_infos =
357 ApplyStylesheets.mml_of_cic_term 111 expr
359 C.set_current_scratch_infos (Some scratch_infos) ;
360 scratch_window#show () ;
361 scratch_window#mmlwidget#load_doc ~dom:mml
362 | None -> assert false (* "ERROR: No current term!!!" *)
366 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
368 let call_tactic_with_hypothesis_input tactic () =
369 let module L = LogicalOperations in
370 let module G = Gdome in
371 let savedproof = !ProofEngine.proof in
372 let savedgoal = !ProofEngine.goal in
373 match (C.sequent_viewer ())#get_selected_hypotheses with
381 RefreshSequentException e ->
383 ("<h1 color=\"red\">Exception raised during the refresh of " ^
384 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
385 ProofEngine.proof := savedproof ;
386 ProofEngine.goal := savedgoal ;
388 | RefreshProofException e ->
390 ("<h1 color=\"red\">Exception raised during the refresh of " ^
391 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
392 ProofEngine.proof := savedproof ;
393 ProofEngine.goal := savedgoal ;
398 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
399 ProofEngine.proof := savedproof ;
400 ProofEngine.goal := savedgoal ;
404 ("<h1 color=\"red\">No hypothesis selected</h1>")
407 ("<h1 color=\"red\">Many hypothesis selected</h1>")
412 (ProofEngine.intros ~mk_fresh_name_callback:C.mk_fresh_name_callback)
413 let exact = call_tactic_with_input ProofEngine.exact
414 let apply = call_tactic_with_input ProofEngine.apply
415 let elimintrossimpl = call_tactic_with_input ProofEngine.elim_intros_simpl
416 let elimtype = call_tactic_with_input ProofEngine.elim_type
417 let whd = call_tactic_with_goal_inputs ProofEngine.whd
418 let reduce = call_tactic_with_goal_inputs ProofEngine.reduce
419 let simpl = call_tactic_with_goal_inputs ProofEngine.simpl
420 let fold_whd = call_tactic_with_input ProofEngine.fold_whd
421 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce
422 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl
424 call_tactic_with_input
425 (ProofEngine.cut ~mk_fresh_name_callback:C.mk_fresh_name_callback)
426 let change = call_tactic_with_input_and_goal_input ProofEngine.change
428 call_tactic_with_input
429 (ProofEngine.letin ~mk_fresh_name_callback:C.mk_fresh_name_callback)
430 let ring = call_tactic ProofEngine.ring
431 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody
432 let clear = call_tactic_with_hypothesis_input ProofEngine.clear
433 let fourier = call_tactic ProofEngine.fourier
434 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl
435 let rewritebacksimpl = call_tactic_with_input ProofEngine.rewrite_back_simpl
436 let replace = call_tactic_with_input_and_goal_input ProofEngine.replace
437 let reflexivity = call_tactic ProofEngine.reflexivity
438 let symmetry = call_tactic ProofEngine.symmetry
439 let transitivity = call_tactic_with_input ProofEngine.transitivity
440 let exists = call_tactic ProofEngine.exists
441 let split = call_tactic ProofEngine.split
442 let left = call_tactic ProofEngine.left
443 let right = call_tactic ProofEngine.right
444 let assumption = call_tactic ProofEngine.assumption
446 call_tactic_with_goal_inputs
447 (ProofEngine.generalize ~mk_fresh_name_callback:C.mk_fresh_name_callback)
448 let absurd = call_tactic_with_input ProofEngine.absurd
449 let contradiction = call_tactic ProofEngine.contradiction
451 call_tactic_with_input
452 (ProofEngine.decompose
453 ~uris_choice_callback:C.decompose_uris_choice_callback)
454 let whd_in_scratch scratch_window =
455 call_tactic_with_goal_inputs_in_scratch ProofEngine.whd_in_scratch
457 let reduce_in_scratch scratch_window =
458 call_tactic_with_goal_inputs_in_scratch ProofEngine.reduce_in_scratch
460 let simpl_in_scratch scratch_window =
461 call_tactic_with_goal_inputs_in_scratch ProofEngine.simpl_in_scratch