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/.
26 let rewrite ~term:equality ?(direction=`Left) (proof,goal) =
28 let module U = UriManager in
29 let module PET = ProofEngineTypes in
30 let module PT = PrimitiveTactics in
31 let module HLO = HelmLibraryObjects in
37 let curi, metasenv, pbo, pty = proof in
38 let metano, context, gty = CicUtil.lookup_meta goal metasenv in
39 let eq_uri = HLO.Logic.eq_URI in
41 CicTypeChecker.type_of_aux' metasenv context equality
44 let eq_ind, ty, t1, t2 =
46 | C.Appl [C.MutInd (uri, 0, []); ty; t1; t2] when U.eq uri eq_uri ->
48 C.Const (if_left HLO.Logic.eq_ind_URI HLO.Logic.eq_ind_r_URI,[])
50 if_left (eq_ind, ty, t2, t1) (eq_ind, ty, t1, t2)
51 | _ -> raise (PET.Fail "Rewrite: argument is not a proof of an equality")
53 (* now we always do as if direction was `Left *)
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'
61 let gty_red = CicSubstitution.subst t2 gty'' in
62 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
63 let irl =CicMkImplicit.identity_relocation_list_for_metavariable context in
64 let metasenv' = (fresh_meta,context,gty_red)::metasenv in
66 FreshNamesGenerator.mk_fresh_name
67 ~subst:[] metasenv context C.Anonymous ~typ:ty
69 let pred = C.Lambda (fresh_name, ty, gty'') in
71 C.Appl [eq_ind ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality]
75 (PT.exact_tac ~term:exact_proof) ((curi,metasenv',pbo,pty),goal)
77 assert (List.length goals = 0) ;
81 let rewrite_tac ~term =
82 let rewrite_tac ~term status =
83 rewrite ~term ~direction:`Right status
85 ProofEngineTypes.mk_tactic (rewrite_tac ~term)
87 let rewrite_simpl_tac ~term =
88 let rewrite_simpl_tac ~term status =
89 ProofEngineTypes.apply_tactic
91 ~start:(rewrite_tac ~term)
93 (ReductionTactics.simpl_tac ~also_in_hypotheses:false ~terms:None))
96 ProofEngineTypes.mk_tactic (rewrite_simpl_tac ~term)
99 let rewrite_back_tac ~term =
100 let rewrite_back_tac ~term status =
101 rewrite ~term ~direction:`Left status
103 ProofEngineTypes.mk_tactic (rewrite_back_tac ~term)
105 let rewrite_back_simpl_tac ~term =
106 let rewrite_back_simpl_tac ~term status =
107 ProofEngineTypes.apply_tactic
109 ~start:(rewrite_back_tac ~term)
111 (ReductionTactics.simpl_tac ~also_in_hypotheses:false ~terms:None))
114 ProofEngineTypes.mk_tactic (rewrite_back_simpl_tac ~term)
117 let replace_tac ~what ~with_what =
118 let replace_tac ~what ~with_what status =
119 let (proof, goal) = status in
120 let module C = Cic in
121 let module U = UriManager in
122 let module P = PrimitiveTactics in
123 let module T = Tacticals in
124 let _,metasenv,_,_ = proof in
125 let _,context,_ = CicUtil.lookup_meta goal metasenv in
126 let wty,u = (* TASSI: FIXME *)
127 CicTypeChecker.type_of_aux' metasenv context what CicUniv.empty_ugraph in
128 let wwty,_ = CicTypeChecker.type_of_aux' metasenv context with_what u in
131 ProofEngineTypes.apply_tactic
136 (C.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, [])) ;
142 T.then_ ~start:(rewrite_simpl_tac ~term:(C.Rel 1))
144 ProofEngineStructuralRules.clear
145 ~hyp:(List.hd context)) ;
148 else raise (ProofEngineTypes.Fail "Replace: terms not replaceable")
149 with (Failure "hd") ->
150 raise (ProofEngineTypes.Fail "Replace: empty context")
152 ProofEngineTypes.mk_tactic (replace_tac ~what ~with_what)
156 (* All these tacs do is applying the right constructor/theorem *)
158 let reflexivity_tac =
159 IntroductionTactics.constructor_tac ~n:1
163 let symmetry_tac (proof, goal) =
164 let module C = Cic in
165 let module R = CicReduction in
166 let module U = UriManager in
167 let (_,metasenv,_,_) = proof in
168 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
169 match (R.whd context ty) with
170 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
171 when (U.eq uri HelmLibraryObjects.Logic.eq_URI) ->
172 ProofEngineTypes.apply_tactic
173 (PrimitiveTactics.apply_tac
174 ~term: (C.Const (HelmLibraryObjects.Logic.sym_eq_URI, [])))
177 | _ -> raise (ProofEngineTypes.Fail "Symmetry failed")
179 ProofEngineTypes.mk_tactic symmetry_tac
182 let transitivity_tac ~term =
183 let transitivity_tac ~term status =
184 let (proof, goal) = status in
185 let module C = Cic in
186 let module R = CicReduction in
187 let module U = UriManager in
188 let module T = Tacticals in
189 let (_,metasenv,_,_) = proof in
190 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
191 match (R.whd context ty) with
192 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
193 when (uri = HelmLibraryObjects.Logic.eq_URI) ->
194 ProofEngineTypes.apply_tactic
196 ~start:(PrimitiveTactics.apply_tac
197 ~term: (C.Const (HelmLibraryObjects.Logic.trans_eq_URI, [])))
199 [PrimitiveTactics.exact_tac ~term ; T.id_tac ; T.id_tac])
202 | _ -> raise (ProofEngineTypes.Fail "Transitivity failed")
204 ProofEngineTypes.mk_tactic (transitivity_tac ~term)