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 ~term:equality ?where ?(direction=`Left) (proof,goal) =
30 let module U = UriManager in
31 let module PET = ProofEngineTypes in
32 let module PER = ProofEngineReduction in
33 let module PEH = ProofEngineHelpers in
34 let module PT = PrimitiveTactics in
35 let module HLO = HelmLibraryObjects in
41 let curi, metasenv, pbo, pty = proof in
42 let metano, context, gty = CicUtil.lookup_meta goal metasenv in
43 let eq_uri = HLO.Logic.eq_URI in
45 CicTypeChecker.type_of_aux' metasenv context equality
48 let eq_ind, ty, t1, t2 =
50 | C.Appl [C.MutInd (uri, 0, []); ty; t1; t2] when U.eq uri eq_uri ->
52 C.Const (if_left HLO.Logic.eq_ind_URI HLO.Logic.eq_ind_r_URI,[])
54 if_left (eq_ind, ty, t2, t1) (eq_ind, ty, t1, t2)
55 | _ -> raise (PET.Fail "Rewrite: argument is not a proof of an equality")
57 (* now we always do as if direction was `Left *)
58 let gty' = CicSubstitution.lift 1 gty in
59 let t1' = CicSubstitution.lift 1 t1 in
64 PER.alpha_equivalence, [t1']
65 | Some (hp_paths, goal_path) ->
66 assert (hp_paths = []);
68 | None -> assert false (* (==), [t1'] *)
70 let roots = ProofEngineHelpers.select ~term:gty' ~pattern:path in
74 let wanted = CicSubstitution.lift (List.length i) t1' in
75 PEH.find_subterms ~eq:PER.alpha_equivalence ~wanted r @ acc
81 let rec aux = function
83 | n -> C.Rel 1 :: aux (n-1)
85 aux (List.length what)
88 ProofEngineReduction.replace_lifting_csc 0
89 ~equality:eq_kind ~what ~with_what ~where:gty'
91 let gty_red = CicSubstitution.subst t2 gty'' in
92 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
93 let irl =CicMkImplicit.identity_relocation_list_for_metavariable context in
94 let metasenv' = (fresh_meta,context,gty_red)::metasenv in
96 FreshNamesGenerator.mk_fresh_name
97 ~subst:[] metasenv context C.Anonymous ~typ:ty
99 let pred = C.Lambda (fresh_name, ty, gty'') in
101 C.Appl [eq_ind ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality]
105 (PT.exact_tac ~term:exact_proof) ((curi,metasenv',pbo,pty),goal)
107 assert (List.length goals = 0) ;
108 (proof',[fresh_meta])
112 let rewrite_tac ?where ~term () =
113 let rewrite_tac ?where ~term status =
114 rewrite ?where ~term ~direction:`Right status
116 ProofEngineTypes.mk_tactic (rewrite_tac ?where ~term)
118 let rewrite_simpl_tac ?where ~term () =
119 let rewrite_simpl_tac ?where ~term status =
120 ProofEngineTypes.apply_tactic
122 ~start:(rewrite_tac ?where ~term ())
124 (ReductionTactics.simpl_tac
125 ~pattern:(ProofEngineTypes.conclusion_pattern None)))
128 ProofEngineTypes.mk_tactic (rewrite_simpl_tac ~term)
131 let rewrite_back_tac ?where ~term () =
132 let rewrite_back_tac ?where ~term status =
133 rewrite ?where ~term ~direction:`Left status
135 ProofEngineTypes.mk_tactic (rewrite_back_tac ?where ~term)
137 let rewrite_back_simpl_tac ?where ~term () =
138 let rewrite_back_simpl_tac ?where ~term status =
139 ProofEngineTypes.apply_tactic
141 ~start:(rewrite_back_tac ?where ~term ())
143 (ReductionTactics.simpl_tac
144 ~pattern:(ProofEngineTypes.conclusion_pattern None)))
147 ProofEngineTypes.mk_tactic (rewrite_back_simpl_tac ~term)
150 let replace_tac ~pattern ~with_what =
152 let replace_tac ~pattern ~with_what status =
153 let (proof, goal) = status in
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,u = (* TASSI: FIXME *)
161 CicTypeChecker.type_of_aux' metasenv context what CicUniv.empty_ugraph in
162 let wwty,_ = CicTypeChecker.type_of_aux' metasenv context with_what u in
165 ProofEngineTypes.apply_tactic
170 (C.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, [])) ;
176 T.then_ ~start:(rewrite_simpl_tac ~term:(C.Rel 1) ())
178 ProofEngineStructuralRules.clear
179 ~hyp:(List.hd context)) ;
182 else raise (ProofEngineTypes.Fail "Replace: terms not replaceable")
183 with (Failure "hd") ->
184 raise (ProofEngineTypes.Fail "Replace: empty context")
186 ProofEngineTypes.mk_tactic (replace_tac ~what ~with_what)
191 (* All these tacs do is applying the right constructor/theorem *)
193 let reflexivity_tac =
194 IntroductionTactics.constructor_tac ~n:1
198 let symmetry_tac (proof, goal) =
199 let module C = Cic in
200 let module R = CicReduction in
201 let module U = UriManager in
202 let (_,metasenv,_,_) = proof in
203 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
204 match (R.whd context ty) with
205 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
206 when (U.eq uri HelmLibraryObjects.Logic.eq_URI) ->
207 ProofEngineTypes.apply_tactic
208 (PrimitiveTactics.apply_tac
209 ~term: (C.Const (HelmLibraryObjects.Logic.sym_eq_URI, [])))
212 | _ -> raise (ProofEngineTypes.Fail "Symmetry failed")
214 ProofEngineTypes.mk_tactic symmetry_tac
217 let transitivity_tac ~term =
218 let transitivity_tac ~term status =
219 let (proof, goal) = status in
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, [])); _; _; _])
228 when (uri = HelmLibraryObjects.Logic.eq_URI) ->
229 ProofEngineTypes.apply_tactic
231 ~start:(PrimitiveTactics.apply_tac
232 ~term: (C.Const (HelmLibraryObjects.Logic.trans_eq_URI, [])))
234 [PrimitiveTactics.exact_tac ~term ; T.id_tac ; T.id_tac])
237 | _ -> raise (ProofEngineTypes.Fail "Transitivity failed")
239 ProofEngineTypes.mk_tactic (transitivity_tac ~term)