]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/reductionTactics.ml
new simpl semantic (now = and not == since you can't write a pointer to a script)
[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 open ProofEngineTypes
27
28 (*
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
33    let new_metasenv = 
34     List.map
35     (function
36       (n,_,_) when n = metano -> (metano,context,new_ty)
37       | _ as t -> t
38     ) metasenv
39    in
40     (curi,new_metasenv,pbo,pty), [metano]
41 ;;
42 *)
43
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
48   let terms =
49     match terms with None -> [ty] | Some l -> l
50   in
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 lift 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*)
61      try
62       let terms = List.fold_left 
63         (fun acc t -> 
64             try
65               (CicSubstitution.delift lift t) :: acc
66             with Failure _ -> acc
67         ) [] terms
68       in 
69       let terms' = List.map (reduction context) terms in
70       ProofEngineReduction.replace 
71         ~equality:(=) ~what:terms ~with_what:terms' ~where:where
72      with
73       _ -> where
74    in
75    let ty' = replace 0 context ty in
76    let context', _ =
77      if also_in_hypotheses then
78       List.fold_right
79        (fun entry (context,i) ->
80          match entry with
81           | Some (name,Cic.Def (t,None)) ->
82              (Some (name,Cic.Def ((replace i context t),None)))::context, i-1
83           | Some (name,Cic.Decl t) ->
84              (Some (name,Cic.Decl (replace i context t)))::context, i-1
85           | None -> None::context, i-1
86           | Some (_,Cic.Def (_,Some _)) -> assert false
87        ) context ([],(List.length context))
88      else
89       context, 0
90     in
91      let metasenv' = 
92       List.map
93        (function
94            (n,_,_) when n = metano -> (metano,context',ty')
95          | _ as t -> t
96        ) metasenv
97      in
98       (curi,metasenv',pbo,pty), [metano]
99 ;;
100
101 let simpl_tac ~also_in_hypotheses ~terms = 
102  mk_tactic ( reduction_tac ~reduction:ProofEngineReduction.simpl 
103   ~also_in_hypotheses ~terms);;
104
105 let reduce_tac ~also_in_hypotheses ~terms = 
106  mk_tactic ( reduction_tac ~reduction:ProofEngineReduction.reduce
107   ~also_in_hypotheses ~terms);;
108   
109 let whd_tac ~also_in_hypotheses ~terms = 
110  mk_tactic ( reduction_tac ~reduction:CicReduction.whd 
111   ~also_in_hypotheses ~terms);;
112
113 let fold_tac ~reduction ~also_in_hypotheses ~term =
114  let fold_tac ~reduction ~also_in_hypotheses ~term (proof,goal) =
115   let curi,metasenv,pbo,pty = proof in
116   let metano,context,ty = CicUtil.lookup_meta goal metasenv in
117    let term' = reduction context term in
118     (* We don't know if [term] is a subterm of [ty] or a subterm of *)
119     (* the type of one metavariable. So we replace it everywhere.   *)
120     (*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
121     (*CSC: che si guadagni nulla in fatto di efficienza.    *) 
122     let replace =
123      ProofEngineReduction.replace ~equality:(=) ~what:[term'] ~with_what:[term]
124     in
125      let ty' = replace ty in
126      let metasenv' =
127       let context' =
128        if also_in_hypotheses then
129         List.map
130          (function
131              Some (n,Cic.Decl t) -> Some (n,Cic.Decl (replace t))
132            | Some (n,Cic.Def (t,None))  -> Some (n,Cic.Def ((replace t),None))
133            | None -> None
134            | Some (_,Cic.Def (_,Some _)) -> assert false
135          ) context
136        else
137         context
138       in
139        List.map
140         (function
141             (n,_,_) when n = metano -> (metano,context',ty')
142           | _ as t -> t
143         ) metasenv
144       
145      in
146       (curi,metasenv',pbo,pty), [metano]
147  in
148   mk_tactic (fold_tac ~reduction ~also_in_hypotheses ~term)
149 ;;