1 (* Copyright (C) 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/.
27 let rewrite_tac ~term:equality ~status:(proof,goal) =
29 let module U = UriManager in
30 let curi,metasenv,pbo,pty = proof in
31 let metano,context,gty = CicUtil.lookup_meta goal metasenv in
32 let eq_ind_r,ty,t1,t2 =
33 match CicTypeChecker.type_of_aux' metasenv context equality with
34 C.Appl [C.MutInd (uri,0,[]) ; ty ; t1 ; t2]
35 when U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind") ->
38 (U.uri_of_string "cic:/Coq/Init/Logic/eq_ind_r.con",[])
41 | C.Appl [C.MutInd (uri,0,[]) ; ty ; t1 ; t2]
42 when U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind") ->
45 (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT_ind_r.con",[])
50 (ProofEngineTypes.Fail
51 "Rewrite: the argument is not a proof of an equality")
54 let gty' = CicSubstitution.lift 1 gty in
55 let t1' = CicSubstitution.lift 1 t1 in
57 ProofEngineReduction.replace_lifting
58 ~equality:ProofEngineReduction.alpha_equivalence
59 ~what:[t1'] ~with_what:[C.Rel 1] ~where:gty'
62 (FreshNamesGenerator.mk_fresh_name metasenv context C.Anonymous ty,
65 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
66 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
67 let metasenv' = (fresh_meta,context,C.Appl [pred ; t2])::metasenv in
70 PrimitiveTactics.exact_tac
72 [eq_ind_r ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality])
73 ~status:((curi,metasenv',pbo,pty),goal)
75 assert (List.length goals = 0) ;
80 let rewrite_simpl_tac ~term ~status =
82 ~start:(rewrite_tac ~term)
84 (ReductionTactics.simpl_tac ~also_in_hypotheses:false ~terms:None)
89 let rewrite_back_tac ~term:equality ~status:(proof,goal) =
91 let module U = UriManager in
92 let curi,metasenv,pbo,pty = proof in
93 let metano,context,gty = CicUtil.lookup_meta goal metasenv in
94 let eq_ind_r,ty,t1,t2 =
95 match CicTypeChecker.type_of_aux' metasenv context equality with
96 C.Appl [C.MutInd (uri,0,[]) ; ty ; t1 ; t2]
97 when U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind") ->
100 (U.uri_of_string "cic:/Coq/Init/Logic/eq_ind.con",[])
103 | C.Appl [C.MutInd (uri,0,[]) ; ty ; t1 ; t2]
104 when U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind") ->
107 (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT_ind.con",[])
112 (ProofEngineTypes.Fail
113 "Rewrite: the argument is not a proof of an equality")
116 let gty' = CicSubstitution.lift 1 gty in
117 let t1' = CicSubstitution.lift 1 t1 in
119 ProofEngineReduction.replace_lifting
120 ~equality:ProofEngineReduction.alpha_equivalence
121 ~what:[t1'] ~with_what:[C.Rel 1] ~where:gty'
124 (FreshNamesGenerator.mk_fresh_name metasenv context C.Anonymous ty,
127 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
129 CicMkImplicit.identity_relocation_list_for_metavariable context in
130 let metasenv' = (fresh_meta,context,C.Appl [pred ; t2])::metasenv in
133 PrimitiveTactics.exact_tac
135 [eq_ind_r ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality])
136 ~status:((curi,metasenv',pbo,pty),goal)
138 assert (List.length goals = 0) ;
139 (proof',[fresh_meta])
144 let rewrite_back_simpl_tac ~term ~status =
146 ~start:(rewrite_back_tac ~term)
148 (ReductionTactics.simpl_tac ~also_in_hypotheses:false ~terms:None)
153 let replace_tac ~what ~with_what ~status:((proof, goal) as status) =
154 let module C = Cic in
155 let module U = UriManager in
156 let module P = PrimitiveTactics in
157 let module T = Tacticals in
158 let _,metasenv,_,_ = proof in
159 let _,context,_ = CicUtil.lookup_meta goal metasenv in
160 let wty = CicTypeChecker.type_of_aux' metasenv context what in
162 if (wty = (CicTypeChecker.type_of_aux' metasenv context with_what))
165 match CicTypeChecker.type_of_aux' metasenv context wty with
166 C.Sort C.Set -> "cic:/Coq/Init/Logic/eq.ind"
169 | C.Sort C.Prop -> "cic:/Coq/Init/Logic_Type/eqT.ind"
176 (C.MutInd ((U.uri_of_string equality), 0, [])) ;
182 ~start:(rewrite_simpl_tac ~term:(C.Rel 1))
184 ProofEngineStructuralRules.clear
185 ~hyp:(List.hd context)) ;
188 else raise (ProofEngineTypes.Fail "Replace: terms not replaceable")
189 with (Failure "hd") -> raise (ProofEngineTypes.Fail "Replace: empty context")
193 (* All these tacs do is applying the right constructor/theorem *)
195 let reflexivity_tac =
196 IntroductionTactics.constructor_tac ~n:1
200 let symmetry_tac ~status:(proof, goal) =
201 let module C = Cic in
202 let module R = CicReduction in
203 let module U = UriManager in
204 let (_,metasenv,_,_) = proof in
205 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
206 match (R.whd context ty) with
207 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _]) when (U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) ->
208 PrimitiveTactics.apply_tac ~status:(proof,goal)
209 ~term: (C.Const (U.uri_of_string "cic:/Coq/Init/Logic/sym_eq.con", []))
211 | (C.Appl [(C.MutInd (uri, 0, [])); _; _; _]) when (U.eq uri (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) ->
212 PrimitiveTactics.apply_tac ~status:(proof,goal)
213 ~term: (C.Const (U.uri_of_string "cic:/Coq/Init/Logic_Type/sym_eqT.con", []))
215 | _ -> raise (ProofEngineTypes.Fail "Symmetry failed")
219 let transitivity_tac ~term ~status:((proof, goal) as status) =
220 let module C = Cic in
221 let module R = CicReduction in
222 let module U = UriManager in
223 let module T = Tacticals in
224 let (_,metasenv,_,_) = proof in
225 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
226 match (R.whd context ty) with
227 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) ->
229 ~start:(PrimitiveTactics.apply_tac
230 ~term: (C.Const (U.uri_of_string "cic:/Coq/Init/Logic/trans_eq.con", [])))
232 [PrimitiveTactics.exact_tac ~term ; T.id_tac ; T.id_tac]
235 | (C.Appl [(C.MutInd (uri, 0, [])); _; _; _]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) ->
237 ~start:(PrimitiveTactics.apply_tac
238 ~term: (C.Const (U.uri_of_string "cic:/Coq/Init/Logic_Type/trans_eqT.con", [])))
240 [T.id_tac ; T.id_tac ; PrimitiveTactics.exact_tac ~term]
243 | _ -> raise (ProofEngineTypes.Fail "Transitivity failed")