]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/variousTactics.ml
Dead code removed.
[helm.git] / helm / ocaml / tactics / variousTactics.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 (* TODO se ce n'e' piu' di una, prende la prima che trova... sarebbe meglio
28 chiedere: find dovrebbe restituire una lista di hyp (?) da passare all'utonto con una
29 funzione di callback che restituisce la (sola) hyp da applicare *)
30
31 let assumption_tac ~status:((proof,goal) as status) =
32   let module C = Cic in
33   let module R = CicReduction in
34   let module S = CicSubstitution in
35    let _,metasenv,_,_ = proof in
36     let _,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
37      let rec find n = function 
38         hd::tl -> 
39          (match hd with
40              (Some (_, C.Decl t)) when
41                (R.are_convertible context (S.lift n t) ty) -> n
42            | (Some (_, C.Def t)) when
43                (R.are_convertible context
44                 (CicTypeChecker.type_of_aux' metasenv context (S.lift n t)) ty) -> n 
45            | _ -> find (n+1) tl
46          )
47       | [] -> raise (ProofEngineTypes.Fail "Assumption: No such assumption")
48      in PrimitiveTactics.apply_tac ~status ~term:(C.Rel (find 1 context))
49 ;;
50
51 (* ANCORA DA DEBUGGARE *)
52
53 (* serve una funzione che cerchi nel ty dal basso a partire da term, i lambda
54 e li aggiunga nel context, poi si conta la lunghezza di questo nuovo
55 contesto e si lifta di tot... COSA SIGNIFICA TUTTO CIO'?????? *)
56
57 let generalize_tac ~term ~status:((proof,goal) as status) =
58   let module C = Cic in
59   let module P = PrimitiveTactics in
60   let module T = Tacticals in
61    let _,metasenv,_,_ = proof in
62     let _,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
63 (*
64      let found = false in
65      let rec new_context context ty = 
66       if ty == term then let found = true in context
67        else match ty with
68              C.Rel _
69            | C.Var _ 
70            | C.Meta _ (* ???? *)
71            | C.Sort s 
72            | C.Implicit -> context                   
73            | C.Cast (val,typ) -> 
74               let tmp_context = new_context context val in 
75                tmp_context @ (new_context tmp_context typ)
76            | C.Prod (binder, source, target) -> 
77            | C.Lambda (binder, source, target) -> 
78               let tmp_context = new_context context source in 
79                tmp_context @ (new_context tmp_context binder)
80            | C.LetIn (binder, term, target) ->
81            | C.Appl applist -> 
82               let rec aux context = 
83                match applist with 
84                   [] -> context
85                 | hd::tl -> 
86                    let tmp_context = (new_context context hd)
87                    in aux tmp_context tl 
88               in aux context applist
89            | C.Const (uri, exp_named_subst)
90            | C.MutInd (uri, typeno, exp_named_subst)
91            | C.MutConstruct (uri, typeno, consno, exp_named_subst) -> 
92               match exp_named_subst with
93                  [] -> context
94                | (uri,t)::_ -> new_context context (type_of_aux' context t)
95                | _ -> assert false
96            | C.MutCase (uri, typeno, outtype, iterm, patterns) 
97            | C.Fix (funno, funlist) 
98            | C.CoFix (funno, funlist) ->
99               match funlist with
100                  [] -> context (* caso possibile? *)
101                | (name, index, type, body)::_ -> 
102                   let tmp_context = ~
103      in
104 *)
105      T.thens 
106       ~start:(P.cut_tac 
107        ~term:(
108          C.Prod(
109           (C.Name "dummy_for_gen"), 
110           (CicTypeChecker.type_of_aux' metasenv context term),
111           (ProofEngineReduction.replace_lifting_csc 1
112             ~equality:(==) 
113             ~what:term 
114             ~with_what:(C.Rel 1) (* C.Name "dummy_for_gen" *)  
115             ~where:ty)
116         )))     
117       ~continuations: [(P.apply_tac ~term:(C.Rel 1)) ; T.id_tac]
118       ~status
119 ;;
120
121
122 (* IN FASE DI IMPLEMENTAZIONE *)
123
124 let decide_equality_tac =
125 (* il goal e' un termine della forma t1=t2\/~t1=t2; la tattica decide se l'uguaglianza
126 e' vera o no e lo risolve *)
127   Tacticals.id_tac
128 ;;
129
130
131 let compare_tac ~term ~status:((proof, goal) as status) =
132 (* term is in the form t1=t2; the tactic leaves two goals: in the first you have to          *)
133 (* demonstrate the goal with the additional hyp that t1=t2, in the second the hyp is ~t1=t2  *)
134   let module C = Cic in
135   let module U = UriManager in
136   let module P = PrimitiveTactics in
137   let module T = Tacticals in
138    let _,metasenv,_,_ = proof in
139     let _,context,gty = List.find (function (m,_,_) -> m=goal) metasenv in
140      let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
141       match termty with
142          (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) ->
143           
144           let term' = (* (t1=t2)\/~(t1=t2) *)
145            C.Appl [
146             (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ; 
147             term ; 
148             C.Appl [
149              (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/eq.ind"), 1, [])) ; 
150              t1 ; 
151              C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
152             ]
153            ] 
154           in
155             T.thens 
156                ~start:(P.cut_tac ~term:term')
157                ~continuations:[
158                  T.then_ ~start:(P.intros_tac) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ; 
159                  decide_equality_tac]  
160       | (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) ->
161           let term' = (* (t1=t2) \/ ~(t1=t2) *)
162            C.Appl [
163             (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ; 
164             term ; 
165             C.Appl [
166              (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind"), 1, [])) ; 
167              t1 ; 
168              C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
169             ]
170            ] 
171           in
172             T.thens 
173                ~start:(P.cut_tac ~term:term')
174                ~continuations:[
175                  T.then_ ~start:(P.intros_tac) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ; 
176                  decide_equality_tac]  
177       | _ -> raise (ProofEngineTypes.Fail "Compare: Not an equality") 
178 ;;
179
180
181 let discriminate_tac ~term ~status:((proof, goal) as status) =
182   let module C = Cic in
183   let module U = UriManager in
184   let module P = PrimitiveTactics in
185   let module T = Tacticals in
186    T.id_tac 
187 ;;
188