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
68 module Make(C:Callbacks) =
71 let call_tactic tactic () =
72 let savedproof = !ProofEngine.proof in
73 let savedgoal = !ProofEngine.goal in
80 RefreshSequentException e ->
82 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
83 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
84 ProofEngine.proof := savedproof ;
85 ProofEngine.goal := savedgoal ;
87 | RefreshProofException e ->
89 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
90 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
91 ProofEngine.proof := savedproof ;
92 ProofEngine.goal := savedgoal ;
97 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
98 ProofEngine.proof := savedproof ;
99 ProofEngine.goal := savedgoal
102 let call_tactic_with_input tactic () =
103 let savedproof = !ProofEngine.proof in
104 let savedgoal = !ProofEngine.goal in
105 let uri,metasenv,bo,ty =
106 match !ProofEngine.proof with
108 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
110 let canonical_context =
111 match !ProofEngine.goal with
114 let (_,canonical_context,_) =
115 List.find (function (m,_,_) -> m=metano) metasenv
121 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
123 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
127 (C.term_editor ())#reset
129 RefreshSequentException e ->
131 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
132 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
133 ProofEngine.proof := savedproof ;
134 ProofEngine.goal := savedgoal ;
136 | RefreshProofException e ->
138 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
139 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
140 ProofEngine.proof := savedproof ;
141 ProofEngine.goal := savedgoal ;
146 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
147 ProofEngine.proof := savedproof ;
148 ProofEngine.goal := savedgoal
150 let call_tactic_with_goal_input tactic () =
151 let module L = LogicalOperations in
152 let module G = Gdome in
153 let savedproof = !ProofEngine.proof in
154 let savedgoal = !ProofEngine.goal in
155 match (C.sequent_viewer ())#get_selected_terms with
163 RefreshSequentException e ->
165 ("<h1 color=\"red\">Exception raised during the refresh of " ^
166 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
167 ProofEngine.proof := savedproof ;
168 ProofEngine.goal := savedgoal ;
170 | RefreshProofException e ->
172 ("<h1 color=\"red\">Exception raised during the refresh of " ^
173 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
174 ProofEngine.proof := savedproof ;
175 ProofEngine.goal := savedgoal ;
180 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
181 ProofEngine.proof := savedproof ;
182 ProofEngine.goal := savedgoal ;
186 ("<h1 color=\"red\">No term selected</h1>")
189 ("<h1 color=\"red\">Many terms selected</h1>")
191 let call_tactic_with_goal_inputs tactic () =
192 let module L = LogicalOperations in
193 let module G = Gdome in
194 let savedproof = !ProofEngine.proof in
195 let savedgoal = !ProofEngine.goal in
197 match (C.sequent_viewer ())#get_selected_terms with
200 ("<h1 color=\"red\">No term selected</h1>")
206 RefreshSequentException e ->
208 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
209 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
210 ProofEngine.proof := savedproof ;
211 ProofEngine.goal := savedgoal ;
213 | RefreshProofException e ->
215 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
216 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
217 ProofEngine.proof := savedproof ;
218 ProofEngine.goal := savedgoal ;
223 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
224 ProofEngine.proof := savedproof ;
225 ProofEngine.goal := savedgoal
227 let call_tactic_with_input_and_goal_input tactic () =
228 let module L = LogicalOperations in
229 let module G = Gdome in
230 let savedproof = !ProofEngine.proof in
231 let savedgoal = !ProofEngine.goal in
232 match (C.sequent_viewer ())#get_selected_terms with
236 let uri,metasenv,bo,ty =
237 match !ProofEngine.proof with
239 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
241 let canonical_context =
242 match !ProofEngine.goal with
245 let (_,canonical_context,_) =
246 List.find (function (m,_,_) -> m=metano) metasenv
249 let (metasenv',expr) =
250 (C.term_editor ())#get_metasenv_and_term canonical_context metasenv
252 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
253 tactic ~goal_input:term ~input:expr ;
256 (C.term_editor ())#reset
258 RefreshSequentException e ->
260 ("<h1 color=\"red\">Exception raised during the refresh of " ^
261 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
262 ProofEngine.proof := savedproof ;
263 ProofEngine.goal := savedgoal ;
265 | RefreshProofException e ->
267 ("<h1 color=\"red\">Exception raised during the refresh of " ^
268 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
269 ProofEngine.proof := savedproof ;
270 ProofEngine.goal := savedgoal ;
275 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
276 ProofEngine.proof := savedproof ;
277 ProofEngine.goal := savedgoal ;
281 ("<h1 color=\"red\">No term selected</h1>")
284 ("<h1 color=\"red\">Many terms selected</h1>")
286 let call_tactic_with_goal_input_in_scratch tactic () =
287 let module L = LogicalOperations in
288 let module G = Gdome in
289 let savedproof = !ProofEngine.proof in
290 let savedgoal = !ProofEngine.goal in
291 let scratch_window = C.scratch_window () in
292 match scratch_window#sequent_viewer#get_selected_terms with
296 let expr = tactic term scratch_window#term in
297 scratch_window#sequent_viewer#load_sequent
298 scratch_window#metasenv (111,scratch_window#context,expr) ;
299 scratch_window#set_term expr ;
300 scratch_window#show () ;
304 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
308 ("<h1 color=\"red\">No term selected</h1>")
311 ("<h1 color=\"red\">Many terms selected</h1>")
313 let call_tactic_with_goal_inputs_in_scratch tactic () =
314 let module L = LogicalOperations in
315 let module G = Gdome in
316 let scratch_window = C.scratch_window () in
317 let savedproof = !ProofEngine.proof in
318 let savedgoal = !ProofEngine.goal in
319 match scratch_window#sequent_viewer#get_selected_terms with
322 ("<h1 color=\"red\">No terms selected</h1>")
325 let expr = tactic terms scratch_window#term in
326 scratch_window#sequent_viewer#load_sequent
327 scratch_window#metasenv (111,scratch_window#context,expr) ;
328 scratch_window#set_term expr ;
329 scratch_window#show () ;
333 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
335 let call_tactic_with_hypothesis_input tactic () =
336 let module L = LogicalOperations in
337 let module G = Gdome in
338 let savedproof = !ProofEngine.proof in
339 let savedgoal = !ProofEngine.goal in
340 match (C.sequent_viewer ())#get_selected_hypotheses with
348 RefreshSequentException e ->
350 ("<h1 color=\"red\">Exception raised during the refresh of " ^
351 "the sequent: " ^ Printexc.to_string e ^ "</h1>") ;
352 ProofEngine.proof := savedproof ;
353 ProofEngine.goal := savedgoal ;
355 | RefreshProofException e ->
357 ("<h1 color=\"red\">Exception raised during the refresh of " ^
358 "the proof: " ^ Printexc.to_string e ^ "</h1>") ;
359 ProofEngine.proof := savedproof ;
360 ProofEngine.goal := savedgoal ;
365 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
366 ProofEngine.proof := savedproof ;
367 ProofEngine.goal := savedgoal ;
371 ("<h1 color=\"red\">No hypothesis selected</h1>")
374 ("<h1 color=\"red\">Many hypothesis selected</h1>")
379 (ProofEngine.intros ~mk_fresh_name_callback:C.mk_fresh_name_callback)
380 let exact = call_tactic_with_input ProofEngine.exact
381 let apply = call_tactic_with_input ProofEngine.apply
382 let elimintrossimpl = call_tactic_with_input ProofEngine.elim_intros_simpl
383 let elimtype = call_tactic_with_input ProofEngine.elim_type
384 let whd = call_tactic_with_goal_inputs ProofEngine.whd
385 let reduce = call_tactic_with_goal_inputs ProofEngine.reduce
386 let simpl = call_tactic_with_goal_inputs ProofEngine.simpl
387 let fold_whd = call_tactic_with_input ProofEngine.fold_whd
388 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce
389 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl
391 call_tactic_with_input
392 (ProofEngine.cut ~mk_fresh_name_callback:C.mk_fresh_name_callback)
393 let change = call_tactic_with_input_and_goal_input ProofEngine.change
395 call_tactic_with_input
396 (ProofEngine.letin ~mk_fresh_name_callback:C.mk_fresh_name_callback)
397 let ring = call_tactic ProofEngine.ring
398 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody
399 let clear = call_tactic_with_hypothesis_input ProofEngine.clear
400 let fourier = call_tactic ProofEngine.fourier
401 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl
402 let rewritebacksimpl = call_tactic_with_input ProofEngine.rewrite_back_simpl
403 let replace = call_tactic_with_input_and_goal_input ProofEngine.replace
404 let reflexivity = call_tactic ProofEngine.reflexivity
405 let symmetry = call_tactic ProofEngine.symmetry
406 let transitivity = call_tactic_with_input ProofEngine.transitivity
407 let exists = call_tactic ProofEngine.exists
408 let split = call_tactic ProofEngine.split
409 let left = call_tactic ProofEngine.left
410 let right = call_tactic ProofEngine.right
411 let assumption = call_tactic ProofEngine.assumption
413 call_tactic_with_goal_inputs
414 (ProofEngine.generalize ~mk_fresh_name_callback:C.mk_fresh_name_callback)
415 let absurd = call_tactic_with_input ProofEngine.absurd
416 let contradiction = call_tactic ProofEngine.contradiction
418 call_tactic_with_input
419 (ProofEngine.decompose
420 ~uris_choice_callback:C.decompose_uris_choice_callback)
422 call_tactic_with_goal_inputs_in_scratch ProofEngine.whd_in_scratch
423 let reduce_in_scratch =
424 call_tactic_with_goal_inputs_in_scratch ProofEngine.reduce_in_scratch
425 let simpl_in_scratch =
426 call_tactic_with_goal_inputs_in_scratch ProofEngine.simpl_in_scratch