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/.
29 let reduction_tac ~reduction (proof,goal) =
30 let curi,metasenv,pbo,pty = proof in
31 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
32 let new_ty = reduction context ty in
36 (n,_,_) when n = metano -> (metano,context,new_ty)
40 (curi,new_metasenv,pbo,pty), [metano]
44 (* The default of term is the thesis of the goal to be prooved *)
45 let reduction_tac ~also_in_hypotheses ~reduction ~terms (proof,goal) =
46 let curi,metasenv,pbo,pty = proof in
47 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
49 match terms with None -> [ty] | Some l -> l
51 (* We don't know if [term] is a subterm of [ty] or a subterm of *)
52 (* the type of one metavariable. So we replace it everywhere. *)
53 (*CSC: Il vero problema e' che non sapendo dove sia il term non *)
54 (*CSC: sappiamo neppure quale sia il suo contesto!!!! Insomma, *)
55 (*CSC: e' meglio prima cercare il termine e scoprirne il *)
56 (*CSC: contesto, poi ridurre e infine rimpiazzare. *)
57 let replace context where=
58 (*CSC: Per il momento se la riduzione fallisce significa solamente che *)
59 (*CSC: siamo nel contesto errato. Metto il try, ma che schifo!!!! *)
60 (*CSC: Anche perche' cosi' catturo anche quelle del replace che non dovrei *)
62 let terms' = List.map (reduction context) terms in
63 ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
68 let ty' = replace context ty in
70 if also_in_hypotheses then
74 Some (name,Cic.Def (t,None)) ->
75 (Some (name,Cic.Def ((replace context t),None)))::context
76 | Some (name,Cic.Decl t) ->
77 (Some (name,Cic.Decl (replace context t)))::context
78 | None -> None::context
79 | Some (_,Cic.Def (_,Some _)) -> assert false
87 (n,_,_) when n = metano -> (metano,context',ty')
91 (curi,metasenv',pbo,pty), [metano]
94 let simpl_tac ~also_in_hypotheses ~terms =
95 mk_tactic ( reduction_tac ~reduction:ProofEngineReduction.simpl
96 ~also_in_hypotheses ~terms);;
98 let reduce_tac ~also_in_hypotheses ~terms =
99 mk_tactic ( reduction_tac ~reduction:ProofEngineReduction.reduce
100 ~also_in_hypotheses ~terms);;
102 let whd_tac ~also_in_hypotheses ~terms =
103 mk_tactic ( reduction_tac ~reduction:CicReduction.whd
104 ~also_in_hypotheses ~terms);;
106 let fold_tac ~reduction ~also_in_hypotheses ~term =
107 let fold_tac ~reduction ~also_in_hypotheses ~term (proof,goal) =
108 let curi,metasenv,pbo,pty = proof in
109 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
110 let term' = reduction context term in
111 (* We don't know if [term] is a subterm of [ty] or a subterm of *)
112 (* the type of one metavariable. So we replace it everywhere. *)
113 (*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
114 (*CSC: che si guadagni nulla in fatto di efficienza. *)
116 ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
118 let ty' = replace ty in
121 if also_in_hypotheses then
124 Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
125 | Some (n,Cic.Def (t,None)) -> Some (n,Cic.Def ((replace t),None))
127 | Some (_,Cic.Def (_,Some _)) -> assert false
134 (n,_,_) when n = metano -> (metano,context',ty')
139 (curi,metasenv',pbo,pty), [metano]
141 mk_tactic (fold_tac ~reduction ~also_in_hypotheses ~term)