]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/variousTactics.ml
95576e2d713b7ba1c47b7f8eb87414fd975496c9
[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 exception AllSelectedTermsMustBeConvertible;;
54
55 (* serve una funzione che cerchi nel ty dal basso a partire da term, i lambda
56 e li aggiunga nel context, poi si conta la lunghezza di questo nuovo
57 contesto e si lifta di tot... COSA SIGNIFICA TUTTO CIO'?????? *)
58
59 let generalize_tac
60  ?(mk_fresh_name_callback = ProofEngineHelpers.mk_fresh_name)
61  terms ~status:((proof,goal) as status)
62 =
63   let module C = Cic in
64   let module P = PrimitiveTactics in
65   let module T = Tacticals in
66    let _,metasenv,_,_ = proof in
67    let _,context,ty = List.find (function (m,_,_) -> m=goal) metasenv in
68     let typ =
69      match terms with
70         [] -> assert false
71       | he::tl ->
72          (* We need to check that all the convertibility of all the terms *)
73          List.iter
74           (function t ->
75             if not (CicReduction.are_convertible context he t) then 
76              raise AllSelectedTermsMustBeConvertible
77           ) tl ;
78          (CicTypeChecker.type_of_aux' metasenv context he)
79     in
80      T.thens 
81       ~start:
82         (P.cut_tac 
83          (C.Prod(
84            (mk_fresh_name_callback context C.Anonymous typ), 
85            typ,
86            (ProofEngineReduction.replace_lifting_csc 1
87              ~equality:(==) 
88              ~what:terms
89              ~with_what:(List.map (function _ -> C.Rel 1) terms)
90              ~where:ty)
91          )))
92       ~continuations: [(P.apply_tac ~term:(C.Rel 1)) ; T.id_tac]
93       ~status
94 ;;
95
96
97 (* IN FASE DI IMPLEMENTAZIONE *)
98
99 let decide_equality_tac =
100 (* il goal e' un termine della forma t1=t2\/~t1=t2; la tattica decide se l'uguaglianza
101 e' vera o no e lo risolve *)
102   Tacticals.id_tac
103 ;;
104
105
106 let compare_tac ~term ~status:((proof, goal) as status) =
107 (* term is in the form t1=t2; the tactic leaves two goals: in the first you have to          *)
108 (* demonstrate the goal with the additional hyp that t1=t2, in the second the hyp is ~t1=t2  *)
109   let module C = Cic in
110   let module U = UriManager in
111   let module P = PrimitiveTactics in
112   let module T = Tacticals in
113    let _,metasenv,_,_ = proof in
114     let _,context,gty = List.find (function (m,_,_) -> m=goal) metasenv in
115      let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
116       match termty with
117          (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) ->
118           
119           let term' = (* (t1=t2)\/~(t1=t2) *)
120            C.Appl [
121             (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ; 
122             term ; 
123             C.Appl [
124              (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/eq.ind"), 1, [])) ; 
125              t1 ; 
126              C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
127             ]
128            ] 
129           in
130             T.thens 
131                ~start:(P.cut_tac term')
132                ~continuations:[
133                  T.then_ ~start:(P.intros_tac ()) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ; 
134                  decide_equality_tac]  
135       | (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) ->
136           let term' = (* (t1=t2) \/ ~(t1=t2) *)
137            C.Appl [
138             (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ; 
139             term ; 
140             C.Appl [
141              (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind"), 1, [])) ; 
142              t1 ; 
143              C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
144             ]
145            ] 
146           in
147             T.thens 
148                ~start:(P.cut_tac term')
149                ~continuations:[
150                  T.then_ ~start:(P.intros_tac ()) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ; 
151                  decide_equality_tac]  
152       | _ -> raise (ProofEngineTypes.Fail "Compare: Not an equality") 
153 ;;
154
155
156 let discriminate_tac ~term ~status:((proof, goal) as status) =
157   let module C = Cic in
158   let module U = UriManager in
159   let module P = PrimitiveTactics in
160   let module T = Tacticals in
161    T.id_tac 
162 ;;
163