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 (* The default of term is the thesis of the goal to be prooved *)
29 let reduction_tac ~reduction ~pattern:(what,hyp_patterns,goal_pattern)
32 let curi,metasenv,pbo,pty = proof in
33 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
34 let replace where terms =
36 List.split (List.map (fun (context, t) -> t, reduction context t) terms)
38 ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
40 let find_pattern_for name =
41 try Some (snd(List.find (fun (n, pat) -> Cic.Name n = name) hyp_patterns))
42 with Not_found -> None in
45 ProofEngineHelpers.select ~context ~term:ty ~pattern:(what,goal_pattern)
48 let context_len = List.length context in
50 if hyp_patterns <> [] then
55 | Some (name,Cic.Decl term) ->
56 (match find_pattern_for name with
57 | None -> entry::context
64 let what,subst',metasenv' =
65 CicMetaSubst.delift_rels [] metasenv
66 (context_len - List.length context) what
69 assert (metasenv' = metasenv);
72 ProofEngineHelpers.select ~context ~term ~pattern:(what,pat) in
73 let term' = replace term terms in
74 Some (name,Cic.Decl term') :: context
76 CicMetaSubst.DeliftingARelWouldCaptureAFreeVariable ->
78 (ProofEngineTypes.Fail
79 ("The term the user wants to convert is not closed " ^
80 "in the context of the position of the substitution.")))
81 | Some (name,Cic.Def (term, ty)) ->
82 (match find_pattern_for name with
83 | None -> entry::context
90 let what,subst',metasenv' =
91 CicMetaSubst.delift_rels [] metasenv
92 (context_len - List.length context) what
95 assert (metasenv' = metasenv);
98 ProofEngineHelpers.select ~context ~term ~pattern:(what,pat) in
99 let term' = replace term terms in
105 ProofEngineHelpers.select
106 ~context ~term:ty ~pattern:(what,pat)
108 Some (replace ty terms)
110 Some (name,Cic.Def (term',ty')) :: context
112 CicMetaSubst.DeliftingARelWouldCaptureAFreeVariable ->
114 (ProofEngineTypes.Fail
115 ("The term the user wants to convert is not closed " ^
116 "in the context of the position of the substitution.")))
123 | (n,_,_) when n = metano -> (metano,context',ty')
127 (curi,metasenv',pbo,pty), [metano]
130 let simpl_tac ~pattern =
131 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.simpl ~pattern);;
133 let reduce_tac ~pattern =
134 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.reduce ~pattern);;
136 let whd_tac ~pattern =
137 mk_tactic (reduction_tac ~reduction:CicReduction.whd ~pattern);;
139 let normalize_tac ~pattern =
140 mk_tactic (reduction_tac ~reduction:CicReduction.normalize ~pattern );;
142 let fold_tac ~reduction ~pattern =
144 let fold_tac ~reduction ~pattern:(hyp_patterns,goal_pattern) ~term (proof,goal)
146 let curi,metasenv,pbo,pty = proof in
147 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
148 let term' = reduction context term in
150 ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
152 let ty' = replace ty in
155 if also_in_hypotheses then
158 Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
159 | Some (n,Cic.Def (t,None)) -> Some (n,Cic.Def ((replace t),None))
161 | Some (_,Cic.Def (_,Some _)) -> assert false
168 (n,_,_) when n = metano -> (metano,context',ty')
173 (curi,metasenv',pbo,pty), [metano]
175 mk_tactic (fold_tac ~reduction ~pattern ~term)