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/.
28 module PET = ProofEngineTypes
32 let clearbody (proof, goal) =
33 let curi,metasenv,_subst,pbo,pty, attrs = proof in
34 let metano,_,_ = CicUtil.lookup_meta goal metasenv in
43 (m,canonical_context,ty) when m = metano ->
44 let canonical_context' =
48 Some (C.Name hyp',C.Def (term,ty)) when hyp = hyp' ->
49 let cleared_entry = Some (C.Name hyp, Cic.Decl ty) in
50 cleared_entry::context
51 | None -> None::context
52 | Some (n,C.Decl t) ->
55 CicTypeChecker.type_of_aux' metasenv context t
56 CicUniv.oblivion_ugraph (* TASSI: FIXME *)
61 (lazy ("The correctness of hypothesis " ^
63 " relies on the body of " ^ hyp)
67 | Some (n,Cic.Def (te,ty)) ->
70 (CicTypeChecker.type_of_aux' metasenv context te
71 CicUniv.oblivion_ugraph (* TASSI: FIXME *));
73 (CicTypeChecker.type_of_aux' metasenv context ty
74 CicUniv.oblivion_ugraph (* TASSI: FIXME *));
79 (lazy ("The correctness of hypothesis " ^
81 " relies on the body of " ^ hyp)
84 ) canonical_context []
88 CicTypeChecker.type_of_aux' metasenv canonical_context' ty
89 CicUniv.oblivion_ugraph (* TASSI: FIXME *)
94 (lazy ("The correctness of the goal relies on the body of " ^
97 m,canonical_context',ty
101 (curi,metasenv',_subst,pbo,pty, attrs), [goal]
103 PET.mk_tactic clearbody
106 let clear_one (proof, goal) =
107 let curi,metasenv,_subst,pbo,pty, attrs = proof in
108 let metano,context,ty =
109 CicUtil.lookup_meta goal metasenv
119 (m,canonical_context,ty) when m = metano ->
120 let context_changed, canonical_context' =
122 (fun entry (b, context) ->
124 Some (Cic.Name hyp',_) when hyp' = hyp ->
125 (true, None::context)
126 | None -> (b, None::context)
128 | Some (n,Cic.Def (t,_)) ->
132 CicTypeChecker.type_of_aux' metasenv context t
133 CicUniv.oblivion_ugraph
137 (lazy ("Hypothesis " ^ string_of_name n ^
138 " uses hypothesis " ^ hyp)))
143 ) canonical_context (false, [])
145 if not context_changed then
146 raise (PET.Fail (lazy ("Hypothesis " ^ hyp ^ " does not exist")));
149 CicTypeChecker.type_of_aux' metasenv canonical_context' ty
150 CicUniv.oblivion_ugraph
152 raise (PET.Fail (lazy ("Hypothesis " ^ hyp ^ " occurs in the goal")))
154 m,canonical_context',ty
158 (curi,metasenv',_subst,pbo,pty, attrs), [goal]
160 PET.mk_tactic clear_one
165 match PET.apply_tactic (clear_one ~hyp) status with
166 | proof, [g] -> proof, g
167 | _ -> raise (PET.Fail (lazy "clear: internal error"))
169 let proof, g = List.fold_left aux status hyps in
174 (* Warning: this tactic has no effect on the proof term.
175 It just changes the name of an hypothesis in the current sequent *)
176 let rename ~froms ~tos =
177 let rename (proof, goal) =
178 let error = "rename: lists of different length" in
180 try List.combine froms tos
181 with Invalid_argument _ -> raise (PET.Fail (lazy error))
183 let curi, metasenv, _subst, pbo, pty, attrs = proof in
184 let metano, _, _ = CicUtil.lookup_meta goal metasenv in
185 let rename_map = function
186 | Some (Cic.Name hyp, decl_or_def) as entry ->
187 begin try Some (Cic.Name (List.assoc hyp assocs), decl_or_def)
188 with Not_found -> entry end
192 | m, canonical_context, ty when m = metano ->
193 let canonical_context = List.map rename_map canonical_context in
194 m, canonical_context, ty
195 | conjecture -> conjecture
197 let metasenv = List.map map metasenv in
198 (curi, metasenv, _subst, pbo, pty, attrs), [goal]