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 ~reduction ~pattern:(hyp_patterns,goal_pattern) (proof,goal) =
46 let curi,metasenv,pbo,pty = proof in
47 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
48 (* We don't know if [term] is a subterm of [ty] or a subterm of *)
49 (* the type of one metavariable. So we replace it everywhere. *)
50 (*CSC: Il vero problema e' che non sapendo dove sia il term non *)
51 (*CSC: sappiamo neppure quale sia il suo contesto!!!! Insomma, *)
52 (*CSC: e' meglio prima cercare il termine e scoprirne il *)
53 (*CSC: contesto, poi ridurre e infine rimpiazzare. *)
54 let replace context where terms =
55 (*CSC: Per il momento se la riduzione fallisce significa solamente che *)
56 (*CSC: siamo nel contesto errato. Metto il try, ma che schifo!!!! *)
57 (*CSC: Anche perche' cosi' catturo anche quelle del replace che non dovrei *)
62 (fun i, t -> t, reduction (i @ context) t)
65 ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
67 (* FIXME this is a catch ALL... bad thing *)
68 with exc -> (*prerr_endline (Printexc.to_string exc);*) where
70 let find_pattern_for name =
71 try Some (snd(List.find (fun (n, pat) -> Cic.Name n = name) hyp_patterns))
72 with Not_found -> None
75 match goal_pattern with
76 | None -> replace context ty [[],ty]
78 let terms = ProofEngineHelpers.select ~term:ty ~pattern:pat in
79 replace context ty terms
82 if hyp_patterns <> [] then
86 | Some (name,Cic.Decl term) ->
87 (match find_pattern_for name with
88 | None -> entry::context
90 let terms = ProofEngineHelpers.select ~term ~pattern:pat in
91 let where = replace context term terms in
92 let entry = Some (name,Cic.Decl where) in
94 | Some (name,Cic.Def (term, None)) ->
95 (match find_pattern_for name with
96 | None -> entry::context
98 let terms = ProofEngineHelpers.select ~term ~pattern:pat in
99 let where = replace context term terms in
100 let entry = Some (name,Cic.Def (where,None)) in
102 | _ -> entry::context
109 | (n,_,_) when n = metano -> (metano,context',ty')
113 (curi,metasenv',pbo,pty), [metano]
116 let simpl_tac ~pattern =
117 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.simpl ~pattern);;
119 let reduce_tac ~pattern =
120 mk_tactic (reduction_tac ~reduction:ProofEngineReduction.reduce ~pattern);;
122 let whd_tac ~pattern =
123 mk_tactic (reduction_tac ~reduction:CicReduction.whd ~pattern);;
125 let normalize_tac ~pattern =
126 mk_tactic (reduction_tac ~reduction:CicReduction.normalize ~pattern );;
128 let fold_tac ~reduction ~also_in_hypotheses ~term =
129 let fold_tac ~reduction ~also_in_hypotheses ~term (proof,goal) =
130 let curi,metasenv,pbo,pty = proof in
131 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
132 let term' = reduction context term in
133 (* We don't know if [term] is a subterm of [ty] or a subterm of *)
134 (* the type of one metavariable. So we replace it everywhere. *)
135 (*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
136 (*CSC: che si guadagni nulla in fatto di efficienza. *)
138 ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
140 let ty' = replace ty in
143 if also_in_hypotheses then
146 Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
147 | Some (n,Cic.Def (t,None)) -> Some (n,Cic.Def ((replace t),None))
149 | Some (_,Cic.Def (_,Some _)) -> assert false
156 (n,_,_) when n = metano -> (metano,context',ty')
161 (curi,metasenv',pbo,pty), [metano]
163 mk_tactic (fold_tac ~reduction ~also_in_hypotheses ~term)