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 =
42 val sequent_viewer : unit -> TermViewer.sequent_viewer
43 val term_editor : unit -> TermEditor.term_editor
46 < sequent_viewer: TermViewer.sequent_viewer ;
49 set_term : Cic.term -> unit ;
50 metasenv: Cic.metasenv ;
51 set_metasenv : Cic.metasenv -> unit ;
52 context: Cic.context ;
53 set_context : Cic.context -> unit >
55 val output_html : string -> unit
56 (* GUI refresh functions *)
57 val refresh_proof : unit -> unit
58 val refresh_goals : unit -> unit
59 (* callbacks for user-tactics interaction *)
60 val decompose_uris_choice_callback :
61 (UriManager.uri * int * 'a) list ->
62 (UriManager.uri * int * 'b list) list
63 val mk_fresh_name_callback :
64 Cic.context -> Cic.name -> typ:Cic.term -> Cic.name
70 val intros : unit -> unit
71 val exact : ?term:string -> unit -> unit
72 val apply : ?term:string -> unit -> unit
73 val elimintrossimpl : ?term:string -> unit -> unit
74 val elimtype : ?term:string -> unit -> unit
75 val whd : unit -> unit
76 val reduce : unit -> unit
77 val simpl : unit -> unit
78 val fold_whd : ?term:string -> unit -> unit
79 val fold_reduce : ?term:string -> unit -> unit
80 val fold_simpl : ?term:string -> unit -> unit
81 val cut : ?term:string -> unit -> unit
82 val change : unit -> unit
83 val letin : ?term:string -> unit -> unit
84 val ring : unit -> unit
85 val clearbody : unit -> unit
86 val clear : unit -> unit
87 val fourier : unit -> unit
88 val rewritesimpl : ?term:string -> unit -> unit
89 val rewritebacksimpl : ?term:string -> unit -> unit
90 val replace : unit -> unit
91 val reflexivity : unit -> unit
92 val symmetry : unit -> unit
93 val transitivity : ?term:string -> unit -> unit
94 val exists : unit -> unit
95 val split : unit -> unit
96 val left : unit -> unit
97 val right : unit -> unit
98 val assumption : unit -> unit
99 val generalize : unit -> unit
100 val absurd : ?term:string -> unit -> unit
101 val contradiction : unit -> unit
102 val decompose : ?term:string -> unit -> unit
103 val injection : ?term:string -> unit -> unit
104 val discriminate : ?term:string -> unit -> unit
105 val whd_in_scratch : unit -> unit
106 val reduce_in_scratch : unit -> unit
107 val simpl_in_scratch : unit -> unit
110 module Make (C: Callbacks) : Tactics =
113 let call_tactic tactic () =
114 let savedproof = ProofEngine.get_proof () in
115 let savedgoal = !ProofEngine.goal in
122 RefreshSequentException e ->
124 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
125 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
126 ProofEngine.set_proof savedproof ;
127 ProofEngine.goal := savedgoal ;
129 | RefreshProofException e ->
131 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
132 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
133 ProofEngine.set_proof savedproof ;
134 ProofEngine.goal := savedgoal ;
139 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
140 ProofEngine.set_proof savedproof ;
141 ProofEngine.goal := savedgoal
144 let call_tactic_with_input tactic ?term () =
145 let savedproof = ProofEngine.get_proof () in
146 let savedgoal = !ProofEngine.goal in
147 let uri,metasenv,bo,ty =
148 match ProofEngine.get_proof () with
150 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
152 let canonical_context =
153 match !ProofEngine.goal with
156 let (_,canonical_context,_) =
157 List.find (function (m,_,_) -> m=metano) metasenv
165 | Some t -> (C.term_editor ())#set_term t);
166 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
168 ProofEngine.set_proof (Some (uri,metasenv',bo,ty)) ;
172 (C.term_editor ())#reset
174 RefreshSequentException e ->
176 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
177 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
178 ProofEngine.set_proof savedproof ;
179 ProofEngine.goal := savedgoal ;
181 | RefreshProofException e ->
183 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
184 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
185 ProofEngine.set_proof savedproof ;
186 ProofEngine.goal := savedgoal ;
191 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
192 ProofEngine.set_proof savedproof ;
193 ProofEngine.goal := savedgoal
195 let call_tactic_with_goal_input tactic () =
196 let module L = LogicalOperations in
197 let module G = Gdome in
198 let savedproof = ProofEngine.get_proof () in
199 let savedgoal = !ProofEngine.goal in
200 match (C.sequent_viewer ())#get_selected_terms with
208 RefreshSequentException e ->
210 ("<h1 color=\"red\">Exception raised during the refresh of " ^
211 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
212 ProofEngine.set_proof savedproof ;
213 ProofEngine.goal := savedgoal ;
215 | RefreshProofException e ->
217 ("<h1 color=\"red\">Exception raised during the refresh of " ^
218 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
219 ProofEngine.set_proof savedproof ;
220 ProofEngine.goal := savedgoal ;
225 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
226 ProofEngine.set_proof savedproof ;
227 ProofEngine.goal := savedgoal ;
231 ("<h1 color=\"red\">No term selected</h1>")
234 ("<h1 color=\"red\">Many terms selected</h1>")
236 let call_tactic_with_goal_inputs tactic () =
237 let module L = LogicalOperations in
238 let module G = Gdome in
239 let savedproof = ProofEngine.get_proof () in
240 let savedgoal = !ProofEngine.goal in
242 match (C.sequent_viewer ())#get_selected_terms with
245 ("<h1 color=\"red\">No term selected</h1>")
251 RefreshSequentException e ->
253 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
254 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
255 ProofEngine.set_proof savedproof ;
256 ProofEngine.goal := savedgoal ;
258 | RefreshProofException e ->
260 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
261 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
262 ProofEngine.set_proof savedproof ;
263 ProofEngine.goal := savedgoal ;
268 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
269 ProofEngine.set_proof savedproof ;
270 ProofEngine.goal := savedgoal
272 let call_tactic_with_input_and_goal_input tactic () =
273 let module L = LogicalOperations in
274 let module G = Gdome in
275 let savedproof = ProofEngine.get_proof () in
276 let savedgoal = !ProofEngine.goal in
277 match (C.sequent_viewer ())#get_selected_terms with
281 let uri,metasenv,bo,ty =
282 match ProofEngine.get_proof () with
284 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
286 let canonical_context =
287 match !ProofEngine.goal with
290 let (_,canonical_context,_) =
291 List.find (function (m,_,_) -> m=metano) metasenv
294 let (metasenv',expr) =
295 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
297 ProofEngine.set_proof (Some (uri,metasenv',bo,ty)) ;
298 tactic ~goal_input:term ~input:expr ;
301 (C.term_editor ())#reset
303 RefreshSequentException e ->
305 ("<h1 color=\"red\">Exception raised during the refresh of " ^
306 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
307 ProofEngine.set_proof savedproof ;
308 ProofEngine.goal := savedgoal ;
310 | RefreshProofException e ->
312 ("<h1 color=\"red\">Exception raised during the refresh of " ^
313 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
314 ProofEngine.set_proof savedproof ;
315 ProofEngine.goal := savedgoal ;
320 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
321 ProofEngine.set_proof savedproof ;
322 ProofEngine.goal := savedgoal ;
326 ("<h1 color=\"red\">No term selected</h1>")
329 ("<h1 color=\"red\">Many terms selected</h1>")
331 let call_tactic_with_goal_input_in_scratch tactic () =
332 let module L = LogicalOperations in
333 let module G = Gdome in
334 let scratch_window = C.scratch_window () in
335 match scratch_window#sequent_viewer#get_selected_terms with
339 let expr = tactic term scratch_window#term in
340 scratch_window#sequent_viewer#load_sequent
341 scratch_window#metasenv (111,scratch_window#context,expr) ;
342 scratch_window#set_term expr ;
343 scratch_window#show () ;
347 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
351 ("<h1 color=\"red\">No term selected</h1>")
354 ("<h1 color=\"red\">Many terms selected</h1>")
356 let call_tactic_with_goal_inputs_in_scratch tactic () =
357 let module L = LogicalOperations in
358 let module G = Gdome in
359 let scratch_window = C.scratch_window () in
360 match scratch_window#sequent_viewer#get_selected_terms with
363 ("<h1 color=\"red\">No terms selected</h1>")
366 let expr = tactic terms scratch_window#term in
367 scratch_window#sequent_viewer#load_sequent
368 scratch_window#metasenv (111,scratch_window#context,expr) ;
369 scratch_window#set_term expr ;
370 scratch_window#show () ;
374 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
376 let call_tactic_with_hypothesis_input tactic () =
377 let module L = LogicalOperations in
378 let module G = Gdome in
379 let savedproof = ProofEngine.get_proof () in
380 let savedgoal = !ProofEngine.goal in
381 match (C.sequent_viewer ())#get_selected_hypotheses with
389 RefreshSequentException e ->
391 ("<h1 color=\"red\">Exception raised during the refresh of " ^
392 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
393 ProofEngine.set_proof savedproof ;
394 ProofEngine.goal := savedgoal ;
396 | RefreshProofException e ->
398 ("<h1 color=\"red\">Exception raised during the refresh of " ^
399 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
400 ProofEngine.set_proof savedproof ;
401 ProofEngine.goal := savedgoal ;
406 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
407 ProofEngine.set_proof savedproof ;
408 ProofEngine.goal := savedgoal ;
412 ("<h1 color=\"red\">No hypothesis selected</h1>")
415 ("<h1 color=\"red\">Many hypothesis selected</h1>")
420 (ProofEngine.intros ~mk_fresh_name_callback:C.mk_fresh_name_callback)
421 let exact = call_tactic_with_input ProofEngine.exact
422 let apply = call_tactic_with_input ProofEngine.apply
423 let elimintrossimpl = call_tactic_with_input ProofEngine.elim_intros_simpl
424 let elimtype = call_tactic_with_input ProofEngine.elim_type
425 let whd = call_tactic_with_goal_inputs ProofEngine.whd
426 let reduce = call_tactic_with_goal_inputs ProofEngine.reduce
427 let simpl = call_tactic_with_goal_inputs ProofEngine.simpl
428 let fold_whd = call_tactic_with_input ProofEngine.fold_whd
429 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce
430 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl
432 call_tactic_with_input
433 (ProofEngine.cut ~mk_fresh_name_callback:C.mk_fresh_name_callback)
434 let change = call_tactic_with_input_and_goal_input ProofEngine.change
436 call_tactic_with_input
437 (ProofEngine.letin ~mk_fresh_name_callback:C.mk_fresh_name_callback)
438 let ring = call_tactic ProofEngine.ring
439 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody
440 let clear = call_tactic_with_hypothesis_input ProofEngine.clear
441 let fourier = call_tactic ProofEngine.fourier
442 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl
443 let rewritebacksimpl = call_tactic_with_input ProofEngine.rewrite_back_simpl
444 let replace = call_tactic_with_input_and_goal_input ProofEngine.replace
445 let reflexivity = call_tactic ProofEngine.reflexivity
446 let symmetry = call_tactic ProofEngine.symmetry
447 let transitivity = call_tactic_with_input ProofEngine.transitivity
448 let exists = call_tactic ProofEngine.exists
449 let split = call_tactic ProofEngine.split
450 let left = call_tactic ProofEngine.left
451 let right = call_tactic ProofEngine.right
452 let assumption = call_tactic ProofEngine.assumption
453 let injection = call_tactic_with_input ProofEngine.injection
454 let discriminate = call_tactic_with_input ProofEngine.discriminate
456 call_tactic_with_goal_inputs
457 (ProofEngine.generalize ~mk_fresh_name_callback:C.mk_fresh_name_callback)
458 let absurd = call_tactic_with_input ProofEngine.absurd
459 let contradiction = call_tactic ProofEngine.contradiction
461 call_tactic_with_input
462 (ProofEngine.decompose
463 ~uris_choice_callback:C.decompose_uris_choice_callback)
465 call_tactic_with_goal_inputs_in_scratch ProofEngine.whd_in_scratch
466 let reduce_in_scratch =
467 call_tactic_with_goal_inputs_in_scratch ProofEngine.reduce_in_scratch
468 let simpl_in_scratch =
469 call_tactic_with_goal_inputs_in_scratch ProofEngine.simpl_in_scratch