1 (* Copyright (C) 2000, 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 open ProofEngineHelpers
29 (* proof assistant status *)
31 let proof = ref (None : proof option)
32 let goal = ref (None : goal option)
34 let get_current_status_as_xml () =
37 | Some (uri, metasenv, bo, ty) ->
39 (*CSC: Wrong: [] is just plainly wrong *)
40 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
42 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
43 Cic2acic.acic_object_of_cic_object currentproof
47 Cic2Xml.print_object uri ~ids_to_inner_sorts
48 ~ask_dtd_to_the_getter:true acurrentproof
50 xml,Some bodyxml -> xml,bodyxml
51 | _,None -> assert false
56 let apply_tactic ~tactic =
57 match !proof,!goal with
59 | _,None -> assert false
60 | Some proof', Some goal' ->
61 let (newproof, newgoals) = tactic ~status:(proof', goal') in
62 proof := Some newproof;
64 (match newgoals, newproof with
65 goal::_, _ -> Some goal
66 | [], (_,(goal,_,_)::_,_,_) ->
67 (* the tactic left no open goal ; let's choose the first open goal *)
68 (*CSC: here we could implement and use a proof-tree like notion... *)
73 (* metas_in_term term *)
74 (* Returns the ordered list of the metas that occur in [term]. *)
75 (* Duplicates are removed. The implementation is not very efficient. *)
76 let metas_in_term term =
84 | C.Cast (te,ty) -> (aux te) @ (aux ty)
85 | C.Prod (_,s,t) -> (aux s) @ (aux t)
86 | C.Lambda (_,s,t) -> (aux s) @ (aux t)
87 | C.LetIn (_,s,t) -> (aux s) @ (aux t)
88 | C.Appl l -> List.fold_left (fun i t -> i @ (aux t)) [] l
89 | C.Var (_,exp_named_subst)
90 | C.Const (_,exp_named_subst)
91 | C.MutInd (_,_,exp_named_subst)
92 | C.MutConstruct (_,_,_,exp_named_subst) ->
93 List.fold_left (fun i (_,t) -> i @ (aux t)) [] exp_named_subst
94 | C.MutCase (_,_,outt,t,pl) ->
95 (aux outt) @ (aux t) @
96 (List.fold_left (fun i t -> i @ (aux t)) [] pl)
98 List.fold_left (fun i (_,_,ty,bo) -> i @ (aux bo) @ (aux ty)) [] fl
100 List.fold_left (fun i (_,ty,bo) -> i @ (aux bo) @ (aux ty)) [] fl
102 let metas = aux term in
103 let rec elim_duplicates =
107 he::(elim_duplicates (List.filter (function el -> he <> el) tl))
109 elim_duplicates metas
111 (* perforate context term ty *)
112 (* replaces the term [term] in the proof with a new metavariable whose type *)
113 (* is [ty]. [context] must be the context of [term] in the whole proof. This *)
114 (* could be easily computed; so the only reasons to have it as an argument *)
115 (* are efficiency reasons. *)
116 let perforate context term ty =
117 let module C = Cic in
120 | Some (uri,metasenv,bo,gty as proof') ->
121 let newmeta = new_meta proof' in
122 (* We push the new meta at the end of the list for pretty-printing *)
123 (* purposes: in this way metas are ordered. *)
124 let metasenv' = metasenv@[newmeta,context,ty] in
125 let irl = identity_relocation_list_for_metavariable context in
126 (*CSC: Bug: se ci sono due term uguali nella prova dovrei bucarne uno solo!!!*)
128 ProofEngineReduction.replace (==) [term] [C.Meta (newmeta,irl)] bo
130 (* It may be possible that some metavariables occurred only in *)
131 (* the term we are perforating and they now occurs no more. We *)
132 (* get rid of them, collecting the really useful metavariables *)
134 (*CSC: Bug: una meta potrebbe non comparire in bo', ma comparire nel tipo *)
135 (*CSC: di una metavariabile che compare in bo'!!!!!!! *)
136 let newmetas = metas_in_term bo' in
138 List.filter (function (n,_,_) -> List.mem n newmetas) metasenv'
140 proof := Some (uri,metasenv'',bo',gty) ;
144 (************************************************************)
145 (* Some easy tactics. *)
146 (************************************************************)
148 (* Reduces [term] using [reduction_function] in the current scratch goal [ty] *)
149 let reduction_tactic_in_scratch reduction_function terms ty =
153 | Some (_,metasenv,_,_) -> metasenv
155 let metano,context,_ =
158 | Some metano -> List.find (function (m,_,_) -> m=metano) metasenv
160 let terms' = List.map (reduction_function context) terms in
161 ProofEngineReduction.replace
162 ~equality:(==) ~what:terms ~with_what:terms' ~where:ty
165 let whd_in_scratch = reduction_tactic_in_scratch CicReduction.whd
166 let reduce_in_scratch = reduction_tactic_in_scratch ProofEngineReduction.reduce
167 let simpl_in_scratch = reduction_tactic_in_scratch ProofEngineReduction.simpl
169 (************************************************************)
170 (* Tactics defined elsewhere *)
171 (************************************************************)
173 (* primitive tactics *)
175 let apply term = apply_tactic (PrimitiveTactics.apply_tac ~term)
176 let intros ?mk_fresh_name_callback () =
177 apply_tactic (PrimitiveTactics.intros_tac ?mk_fresh_name_callback ())
178 let cut ?mk_fresh_name_callback term =
179 apply_tactic (PrimitiveTactics.cut_tac ?mk_fresh_name_callback term)
180 let letin ?mk_fresh_name_callback term =
181 apply_tactic (PrimitiveTactics.letin_tac ?mk_fresh_name_callback term)
182 let exact term = apply_tactic (PrimitiveTactics.exact_tac ~term)
183 let elim_intros_simpl term =
184 apply_tactic (PrimitiveTactics.elim_intros_simpl_tac ~term)
185 let change ~goal_input:what ~input:with_what =
186 apply_tactic (PrimitiveTactics.change_tac ~what ~with_what)
188 (* structural tactics *)
190 let clearbody hyp = apply_tactic (ProofEngineStructuralRules.clearbody ~hyp)
191 let clear hyp = apply_tactic (ProofEngineStructuralRules.clear ~hyp)
193 (* reduction tactics *)
197 (ReductionTactics.whd_tac ~also_in_hypotheses:true ~terms:(Some terms))
200 (ReductionTactics.reduce_tac ~also_in_hypotheses:true ~terms:(Some terms))
203 (ReductionTactics.simpl_tac ~also_in_hypotheses:true ~terms:(Some terms))
207 (ReductionTactics.fold_tac ~reduction:CicReduction.whd
208 ~also_in_hypotheses:true ~term)
209 let fold_reduce term =
211 (ReductionTactics.fold_tac ~reduction:ProofEngineReduction.reduce
212 ~also_in_hypotheses:true ~term)
213 let fold_simpl term =
215 (ReductionTactics.fold_tac ~reduction:ProofEngineReduction.simpl
216 ~also_in_hypotheses:true ~term)
220 let elim_type term = apply_tactic (EliminationTactics.elim_type_tac ~term)
221 let ring () = apply_tactic Ring.ring_tac
222 let fourier () = apply_tactic FourierR.fourier_tac
224 let rewrite_simpl term = apply_tactic (EqualityTactics.rewrite_simpl_tac ~term)
225 let rewrite_back_simpl term = apply_tactic (EqualityTactics.rewrite_back_simpl_tac ~term)
226 let replace ~goal_input:what ~input:with_what =
227 apply_tactic (EqualityTactics.replace_tac ~what ~with_what)
229 let reflexivity () = apply_tactic EqualityTactics.reflexivity_tac
230 let symmetry () = apply_tactic EqualityTactics.symmetry_tac
231 let transitivity term = apply_tactic (EqualityTactics.transitivity_tac ~term)
233 let exists () = apply_tactic IntroductionTactics.exists_tac
234 let split () = apply_tactic IntroductionTactics.split_tac
235 let left () = apply_tactic IntroductionTactics.left_tac
236 let right () = apply_tactic IntroductionTactics.right_tac
238 let assumption () = apply_tactic VariousTactics.assumption_tac
240 let generalize ?mk_fresh_name_callback terms =
241 apply_tactic (VariousTactics.generalize_tac ?mk_fresh_name_callback terms)
243 let absurd term = apply_tactic (NegationTactics.absurd_tac ~term)
244 let contradiction () = apply_tactic NegationTactics.contradiction_tac
246 let decompose ~uris_choice_callback term =
247 apply_tactic (EliminationTactics.decompose_tac ~uris_choice_callback term)
249 let injection term = apply_tactic (DiscriminationTactics.injection_tac ~term)
250 let discriminate term = apply_tactic (DiscriminationTactics.discriminate_tac ~term)
251 let decide_equality () = apply_tactic DiscriminationTactics.decide_equality_tac
252 let compare term = apply_tactic (DiscriminationTactics.compare_tac ~term)
255 let prova_tatticali () = apply_tactic Tacticals.prova_tac