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) =
29 let module U = UriManager in
30 let module PET = ProofEngineTypes in
31 let module PER = ProofEngineReduction in
32 let module PEH = ProofEngineHelpers in
33 let module PT = PrimitiveTactics in
34 let module HLO = HelmLibraryObjects in
40 let curi, metasenv, pbo, pty = proof in
41 let metano, context, gty = CicUtil.lookup_meta goal metasenv in
42 let eq_uri = HLO.Logic.eq_URI in
44 CicTypeChecker.type_of_aux' metasenv context equality
47 let eq_ind, ty, t1, t2 =
49 | C.Appl [C.MutInd (uri, 0, []); ty; t1; t2] when U.eq uri eq_uri ->
51 C.Const (if_left HLO.Logic.eq_ind_URI HLO.Logic.eq_ind_r_URI,[])
53 if_left (eq_ind, ty, t2, t1) (eq_ind, ty, t1, t2)
54 | _ -> raise (PET.Fail "Rewrite: argument is not a proof of an equality")
56 (* now we always do as if direction was `Left *)
57 let gty' = CicSubstitution.lift 1 gty in
58 let t1' = CicSubstitution.lift 1 t1 in
63 PER.alpha_equivalence, [t1']
64 | Some (hp_paths, goal_path) ->
65 assert (hp_paths = []);
67 | None -> assert false (* (==), [t1'] *)
69 let roots = ProofEngineHelpers.select ~term:gty' ~pattern:path in
73 let wanted = CicSubstitution.lift (List.length i) t1' in
74 PEH.find_subterms ~eq:PER.alpha_equivalence ~wanted r @ acc
80 let rec aux = function
82 | n -> C.Rel 1 :: aux (n-1)
84 aux (List.length what)
87 ProofEngineReduction.replace_lifting_csc 0
88 ~equality:eq_kind ~what ~with_what ~where:gty'
90 let gty_red = CicSubstitution.subst t2 gty'' in
91 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
92 let irl =CicMkImplicit.identity_relocation_list_for_metavariable context in
93 let metasenv' = (fresh_meta,context,gty_red)::metasenv in
95 FreshNamesGenerator.mk_fresh_name
96 ~subst:[] metasenv context C.Anonymous ~typ:ty
98 let pred = C.Lambda (fresh_name, ty, gty'') in
100 C.Appl [eq_ind ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality]
104 (PT.exact_tac ~term:exact_proof) ((curi,metasenv',pbo,pty),goal)
106 assert (List.length goals = 0) ;
107 (proof',[fresh_meta])
110 let rewrite_tac ?where ~term () =
111 let rewrite_tac ?where ~term status =
112 rewrite ?where ~term ~direction:`Right status
114 ProofEngineTypes.mk_tactic (rewrite_tac ?where ~term)
116 let rewrite_simpl_tac ?where ~term () =
117 let rewrite_simpl_tac ?where ~term status =
118 ProofEngineTypes.apply_tactic
120 ~start:(rewrite_tac ?where ~term ())
122 (ReductionTactics.simpl_tac ~pattern:ProofEngineTypes.goal_pattern))
125 ProofEngineTypes.mk_tactic (rewrite_simpl_tac ~term)
128 let rewrite_back_tac ?where ~term () =
129 let rewrite_back_tac ?where ~term status =
130 rewrite ?where ~term ~direction:`Left status
132 ProofEngineTypes.mk_tactic (rewrite_back_tac ?where ~term)
134 let rewrite_back_simpl_tac ?where ~term () =
135 let rewrite_back_simpl_tac ?where ~term status =
136 ProofEngineTypes.apply_tactic
138 ~start:(rewrite_back_tac ?where ~term ())
140 (ReductionTactics.simpl_tac ~pattern:ProofEngineTypes.goal_pattern))
143 ProofEngineTypes.mk_tactic (rewrite_back_simpl_tac ~term)
146 let replace_tac ~what ~with_what =
147 let replace_tac ~what ~with_what status =
148 let (proof, goal) = status in
149 let module C = Cic in
150 let module U = UriManager in
151 let module P = PrimitiveTactics in
152 let module T = Tacticals in
153 let _,metasenv,_,_ = proof in
154 let _,context,_ = CicUtil.lookup_meta goal metasenv in
155 let wty,u = (* TASSI: FIXME *)
156 CicTypeChecker.type_of_aux' metasenv context what CicUniv.empty_ugraph in
157 let wwty,_ = CicTypeChecker.type_of_aux' metasenv context with_what u in
160 ProofEngineTypes.apply_tactic
165 (C.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, [])) ;
171 T.then_ ~start:(rewrite_simpl_tac ~term:(C.Rel 1) ())
173 ProofEngineStructuralRules.clear
174 ~hyp:(List.hd context)) ;
177 else raise (ProofEngineTypes.Fail "Replace: terms not replaceable")
178 with (Failure "hd") ->
179 raise (ProofEngineTypes.Fail "Replace: empty context")
181 ProofEngineTypes.mk_tactic (replace_tac ~what ~with_what)
185 (* All these tacs do is applying the right constructor/theorem *)
187 let reflexivity_tac =
188 IntroductionTactics.constructor_tac ~n:1
192 let symmetry_tac (proof, goal) =
193 let module C = Cic in
194 let module R = CicReduction in
195 let module U = UriManager in
196 let (_,metasenv,_,_) = proof in
197 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
198 match (R.whd context ty) with
199 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
200 when (U.eq uri HelmLibraryObjects.Logic.eq_URI) ->
201 ProofEngineTypes.apply_tactic
202 (PrimitiveTactics.apply_tac
203 ~term: (C.Const (HelmLibraryObjects.Logic.sym_eq_URI, [])))
206 | _ -> raise (ProofEngineTypes.Fail "Symmetry failed")
208 ProofEngineTypes.mk_tactic symmetry_tac
211 let transitivity_tac ~term =
212 let transitivity_tac ~term status =
213 let (proof, goal) = status in
214 let module C = Cic in
215 let module R = CicReduction in
216 let module U = UriManager in
217 let module T = Tacticals in
218 let (_,metasenv,_,_) = proof in
219 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
220 match (R.whd context ty) with
221 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
222 when (uri = HelmLibraryObjects.Logic.eq_URI) ->
223 ProofEngineTypes.apply_tactic
225 ~start:(PrimitiveTactics.apply_tac
226 ~term: (C.Const (HelmLibraryObjects.Logic.trans_eq_URI, [])))
228 [PrimitiveTactics.exact_tac ~term ; T.id_tac ; T.id_tac])
231 | _ -> raise (ProofEngineTypes.Fail "Transitivity failed")
233 ProofEngineTypes.mk_tactic (transitivity_tac ~term)