]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/reductionTactics.ml
80cb3306a18b79a4c08e1c8b40e9625014f86c9e
[helm.git] / helm / ocaml / tactics / reductionTactics.ml
1 (* Copyright (C) 2002, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (*
27 let reduction_tac ~reduction (proof,goal) =
28  let curi,metasenv,pbo,pty = proof in
29  let metano,context,ty = CicUtil.lookup_meta goal metasenv in
30   let new_ty = reduction context ty in
31    let new_metasenv = 
32     List.map
33     (function
34       (n,_,_) when n = metano -> (metano,context,new_ty)
35       | _ as t -> t
36     ) metasenv
37    in
38     (curi,new_metasenv,pbo,pty), [metano]
39 ;;
40 *)
41
42 (* The default of term is the thesis of the goal to be prooved *)
43 let reduction_tac ~also_in_hypotheses ~reduction ~terms (proof,goal) =
44  let curi,metasenv,pbo,pty = proof in
45  let metano,context,ty = CicUtil.lookup_meta goal metasenv in
46   let terms =
47    match terms with None -> [ty] | Some l -> l
48   in
49   (* We don't know if [term] is a subterm of [ty] or a subterm of *)
50   (* the type of one metavariable. So we replace it everywhere.   *)
51   (*CSC: Il vero problema e' che non sapendo dove sia il term non *)
52   (*CSC: sappiamo neppure quale sia il suo contesto!!!! Insomma,  *)
53   (*CSC: e' meglio prima cercare il termine e scoprirne il        *)
54   (*CSC: contesto, poi ridurre e infine rimpiazzare.              *)
55    let replace context where=
56 (*CSC: Per il momento se la riduzione fallisce significa solamente che *)
57 (*CSC: siamo nel contesto errato. Metto il try, ma che schifo!!!!      *)
58 (*CSC: Anche perche' cosi' catturo anche quelle del replace che non dovrei *)
59    try
60     let terms' = List.map (reduction context) terms in
61      ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
62       ~where:where
63    with
64     _ -> where
65    in
66     let ty' = replace context ty in
67     let context' =
68      if also_in_hypotheses then
69       List.fold_right
70        (fun entry context ->
71          match entry with
72             Some (name,Cic.Def (t,None)) ->
73              (Some (name,Cic.Def ((replace context t),None)))::context
74           | Some (name,Cic.Decl t) ->
75              (Some (name,Cic.Decl (replace context t)))::context
76           | None -> None::context
77           | Some (_,Cic.Def (_,Some _)) -> assert false
78        ) context []
79      else
80       context
81     in
82      let metasenv' = 
83       List.map
84        (function
85            (n,_,_) when n = metano -> (metano,context',ty')
86          | _ as t -> t
87        ) metasenv
88      in
89       (curi,metasenv',pbo,pty), [metano]
90 ;;
91
92 let simpl_tac = reduction_tac ~reduction:ProofEngineReduction.simpl ;;
93 let reduce_tac = reduction_tac ~reduction:ProofEngineReduction.reduce ;;
94 let whd_tac = reduction_tac ~reduction:CicReduction.whd ;;
95
96 let fold_tac ~reduction ~also_in_hypotheses ~term (proof,goal) =
97  let curi,metasenv,pbo,pty = proof in
98  let metano,context,ty = CicUtil.lookup_meta goal metasenv in
99   let term' = reduction context term in
100    (* We don't know if [term] is a subterm of [ty] or a subterm of *)
101    (* the type of one metavariable. So we replace it everywhere.   *)
102    (*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
103    (*CSC: che si guadagni nulla in fatto di efficienza.    *) 
104    let replace =
105     ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
106    in
107     let ty' = replace ty in
108     let metasenv' =
109      let context' =
110       if also_in_hypotheses then
111        List.map
112         (function
113             Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
114           | Some (n,Cic.Def (t,None))  -> Some (n,Cic.Def ((replace t),None))
115           | None -> None
116           | Some (_,Cic.Def (_,Some _)) -> assert false
117         ) context
118       else
119        context
120      in
121       List.map
122        (function
123            (n,_,_) when n = metano -> (metano,context',ty')
124          | _ as t -> t
125        ) metasenv
126      
127     in
128      (curi,metasenv',pbo,pty), [metano]
129 ;;