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 ~direction ~pattern equality =
28 let rewrite_tac ~direction ~pattern equality status =
31 let module U = UriManager in
32 let module PET = ProofEngineTypes in
33 let module PER = ProofEngineReduction in
34 let module PEH = ProofEngineHelpers in
35 let module PT = PrimitiveTactics in
36 let module HLO = HelmLibraryObjects in
37 let proof,goal = status in
43 let curi, metasenv, pbo, pty = proof in
44 let metano, context, gty = CicUtil.lookup_meta goal metasenv in
45 let eq_uri = HLO.Logic.eq_URI in
47 CicTypeChecker.type_of_aux' metasenv context equality
50 let eq_ind, ty, t1, t2 =
52 | C.Appl [C.MutInd (uri, 0, []); ty; t1; t2] when U.eq uri eq_uri ->
54 C.Const (if_left HLO.Logic.eq_ind_URI HLO.Logic.eq_ind_r_URI,[])
56 if_left (eq_ind, ty, t2, t1) (eq_ind, ty, t1, t2)
57 | _ -> raise (PET.Fail "Rewrite: argument is not a proof of an equality")
59 (* now we always do as if direction was `Left *)
60 let gty' = CicSubstitution.lift 1 gty in
61 let t1' = CicSubstitution.lift 1 t1 in
66 PER.alpha_equivalence, [t1']
67 | Some (hp_paths, goal_path) ->
68 assert (hp_paths = []);
70 | None -> assert false (* (==), [t1'] *)
72 let roots = ProofEngineHelpers.select ~term:gty' ~pattern:path in
76 let wanted = CicSubstitution.lift (List.length i) t1' in
77 PEH.find_subterms ~eq:PER.alpha_equivalence ~wanted r @ acc
83 let rec aux = function
85 | n -> C.Rel 1 :: aux (n-1)
87 aux (List.length what)
90 ProofEngineReduction.replace_lifting_csc 0
91 ~equality:eq_kind ~what ~with_what ~where:gty'
93 let gty_red = CicSubstitution.subst t2 gty'' in
94 let fresh_meta = ProofEngineHelpers.new_meta_of_proof proof in
95 let irl =CicMkImplicit.identity_relocation_list_for_metavariable context in
96 let metasenv' = (fresh_meta,context,gty_red)::metasenv in
98 FreshNamesGenerator.mk_fresh_name
99 ~subst:[] metasenv context C.Anonymous ~typ:ty
101 let pred = C.Lambda (fresh_name, ty, gty'') in
103 C.Appl [eq_ind ; ty ; t2 ; pred ; C.Meta (fresh_meta,irl) ; t1 ;equality]
107 (PT.exact_tac ~term:exact_proof) ((curi,metasenv',pbo,pty),goal)
109 assert (List.length goals = 0) ;
110 (proof',[fresh_meta])
111 ProofEngineTypes.mk_tactic (rewrite_tac ?where ~term)
113 ProofEngineTypes.mk_tactic (rewrite_tac ~direction ~pattern equality)
116 let rewrite_simpl_tac ~direction ~pattern equality =
117 let rewrite_simpl_tac ~direction ~pattern equality status =
118 ProofEngineTypes.apply_tactic
120 ~start:(rewrite_tac ~direction:`LeftToRight ~pattern equality)
122 (ReductionTactics.simpl_tac
123 ~pattern:(ProofEngineTypes.conclusion_pattern None)))
126 ProofEngineTypes.mk_tactic (rewrite_simpl_tac ~direction ~pattern equality)
129 let replace_tac ~pattern ~with_what =
131 let replace_tac ~pattern ~with_what status =
132 let (proof, goal) = status in
133 let module C = Cic in
134 let module U = UriManager in
135 let module P = PrimitiveTactics in
136 let module T = Tacticals in
137 let _,metasenv,_,_ = proof in
138 let _,context,_ = CicUtil.lookup_meta goal metasenv in
139 let wty,u = (* TASSI: FIXME *)
140 CicTypeChecker.type_of_aux' metasenv context what CicUniv.empty_ugraph in
141 let wwty,_ = CicTypeChecker.type_of_aux' metasenv context with_what u in
144 ProofEngineTypes.apply_tactic
149 (C.MutInd (HelmLibraryObjects.Logic.eq_URI, 0, [])) ;
155 T.then_ ~start:(rewrite_simpl_tac ~term:(C.Rel 1) ())
157 ProofEngineStructuralRules.clear
158 ~hyp:(List.hd context)) ;
161 else raise (ProofEngineTypes.Fail "Replace: terms not replaceable")
162 with (Failure "hd") ->
163 raise (ProofEngineTypes.Fail "Replace: empty context")
165 ProofEngineTypes.mk_tactic (replace_tac ~what ~with_what)
170 (* All these tacs do is applying the right constructor/theorem *)
172 let reflexivity_tac =
173 IntroductionTactics.constructor_tac ~n:1
177 let symmetry_tac (proof, goal) =
178 let module C = Cic in
179 let module R = CicReduction in
180 let module U = UriManager in
181 let (_,metasenv,_,_) = proof in
182 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
183 match (R.whd context ty) with
184 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
185 when (U.eq uri HelmLibraryObjects.Logic.eq_URI) ->
186 ProofEngineTypes.apply_tactic
187 (PrimitiveTactics.apply_tac
188 ~term: (C.Const (HelmLibraryObjects.Logic.sym_eq_URI, [])))
191 | _ -> raise (ProofEngineTypes.Fail "Symmetry failed")
193 ProofEngineTypes.mk_tactic symmetry_tac
196 let transitivity_tac ~term =
197 let transitivity_tac ~term status =
198 let (proof, goal) = status in
199 let module C = Cic in
200 let module R = CicReduction in
201 let module U = UriManager in
202 let module T = Tacticals in
203 let (_,metasenv,_,_) = proof in
204 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
205 match (R.whd context ty) with
206 (C.Appl [(C.MutInd (uri, 0, [])); _; _; _])
207 when (uri = HelmLibraryObjects.Logic.eq_URI) ->
208 ProofEngineTypes.apply_tactic
210 ~start:(PrimitiveTactics.apply_tac
211 ~term: (C.Const (HelmLibraryObjects.Logic.trans_eq_URI, [])))
213 [PrimitiveTactics.exact_tac ~term ; T.id_tac ; T.id_tac])
216 | _ -> raise (ProofEngineTypes.Fail "Transitivity failed")
218 ProofEngineTypes.mk_tactic (transitivity_tac ~term)