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 (* Note: this code is almost identical to PrimitiveTactics.change_tac and
29 * it could be unified by making the change function a callback *)
30 let reduction_tac ~reduction ~pattern
33 let curi,metasenv,pbo,pty = proof in
34 let (metano,context,ty) as conjecture = CicUtil.lookup_meta goal metasenv in
35 let change where terms =
36 if terms = [] then where
39 List.split (List.map (fun (context, t) -> t, reduction context t) terms)
41 ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
43 let (selected_context,selected_ty) =
44 ProofEngineHelpers.select ~metasenv ~conjecture ~pattern in
45 let ty' = change ty selected_ty in
48 (fun entry selected_entry context' ->
49 match entry,selected_entry with
50 None,None -> None::context'
51 | Some (name,Cic.Decl ty),Some (`Decl selected_ty) ->
52 let ty' = change ty selected_ty in
53 Some (name,Cic.Decl ty')::context'
54 | Some (name,Cic.Def (bo,ty)),Some (`Def (selected_bo,selected_ty)) ->
55 let bo' = change bo selected_bo in
57 match ty,selected_ty with
59 | Some ty,Some selected_ty -> Some (change ty selected_ty)
62 Some (name,Cic.Def (bo',ty'))::context'
64 ) context selected_context [] in
67 | (n,_,_) when n = metano -> (metano,context',ty')
71 (curi,metasenv',pbo,pty), [metano]
74 let simpl_tac ~pattern =
75 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.simpl ~pattern);;
77 let reduce_tac ~pattern =
78 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.reduce ~pattern);;
80 let whd_tac ~pattern =
81 mk_tactic (reduction_tac ~reduction:CicReduction.whd ~pattern);;
83 let normalize_tac ~pattern =
84 mk_tactic (reduction_tac ~reduction:CicReduction.normalize ~pattern );;
86 let fold_tac ~reduction ~term ~pattern =
88 let fold_tac ~reduction ~pattern:(hyp_patterns,goal_pattern) ~term (proof,goal)
90 let curi,metasenv,pbo,pty = proof in
91 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
92 let term' = reduction context term in
94 ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
96 let ty' = replace ty in
99 if also_in_hypotheses then
102 Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
103 | Some (n,Cic.Def (t,None)) -> Some (n,Cic.Def ((replace t),None))
105 | Some (_,Cic.Def (_,Some _)) -> assert false
112 (n,_,_) when n = metano -> (metano,context',ty')
117 (curi,metasenv',pbo,pty), [metano]
119 mk_tactic (fold_tac ~reduction ~pattern ~term)