]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/reductionTactics.ml
- the mathql interpreter is not helm-dependent any more
[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 ~status:(proof,goal) =
28  let curi,metasenv,pbo,pty = proof in
29  let metano,context,ty = List.find (function (m,_,_) -> m=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 ~status:(proof,goal) =
44  let curi,metasenv,pbo,pty = proof in
45  let metano,context,ty = List.find (function (m,_,_) -> m=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) ->
73              (Some (name,Cic.Def  (replace context t)))::context
74           | Some (name,Cic.Decl t) ->
75              (Some (name,Cic.Decl (replace context t)))::context
76           | None -> None::context
77        ) context []
78      else
79       context
80     in
81      let metasenv' = 
82       List.map
83        (function
84            (n,_,_) when n = metano -> (metano,context',ty')
85          | _ as t -> t
86        ) metasenv
87      in
88       (curi,metasenv',pbo,pty), [metano]
89 ;;
90
91 let simpl_tac = reduction_tac ~reduction:ProofEngineReduction.simpl ;;
92 let reduce_tac = reduction_tac ~reduction:ProofEngineReduction.reduce ;;
93 let whd_tac = reduction_tac ~reduction:CicReduction.whd ;;
94
95 let fold_tac ~reduction ~also_in_hypotheses ~term ~status:(proof,goal) =
96  let curi,metasenv,pbo,pty = proof in
97  let metano,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
98   let term' = reduction context term in
99    (* We don't know if [term] is a subterm of [ty] or a subterm of *)
100    (* the type of one metavariable. So we replace it everywhere.   *)
101    (*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
102    (*CSC: che si guadagni nulla in fatto di efficienza.    *) 
103    let replace =
104     ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
105    in
106     let ty' = replace ty in
107     let metasenv' =
108      let context' =
109       if also_in_hypotheses then
110        List.map
111         (function
112             Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
113           | Some (n,Cic.Def t)  -> Some (n,Cic.Def  (replace t))
114           | None -> None
115         ) context
116       else
117        context
118      in
119       List.map
120        (function
121            (n,_,_) when n = metano -> (metano,context',ty')
122          | _ as t -> t
123        ) metasenv
124      
125     in
126      (curi,metasenv',pbo,pty), [metano]
127 ;;