]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/tactics/declarative.ml
Syntax of paramodulation parameters changed.
[helm.git] / helm / software / components / tactics / declarative.ml
1 (* Copyright (C) 2006, 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 let assume id t =
27   Tacticals.then_
28      ~start:
29        (Tactics.intros ~howmany:1
30         ~mk_fresh_name_callback:(fun _ _ _ ~typ -> Cic.Name id) ())
31      ~continuation:
32        (Tactics.change ~pattern:(None,[id,Cic.Implicit (Some `Hole)],None)
33          (fun _ metasenv ugraph -> t,metasenv,ugraph))
34 ;;
35
36 let suppose t id ty =
37 (*BUG: check on t missing *)
38  let ty = match ty with None -> t | Some ty -> ty in
39  Tacticals.then_
40    ~start:
41      (Tactics.intros ~howmany:1
42        ~mk_fresh_name_callback:(fun _ _ _ ~typ -> Cic.Name id) ())
43    ~continuation:
44      (Tactics.change ~pattern:(None,[id,Cic.Implicit (Some `Hole)],None)  
45       (fun _ metasenv ugraph -> ty,metasenv,ugraph))
46 ;;
47
48 let by_term_we_proved ~dbd t ty id ty' =
49  let just =
50   match t with
51      None -> Tactics.auto ~dbd ~params:[]
52    | Some t -> Tactics.apply t
53  in
54   let continuation =
55    match ty' with
56       None -> Tacticals.id_tac
57     | Some ty' ->
58         Tactics.change ~pattern:(None,[id,Cic.Implicit (Some `Hole)],None)
59          (fun _ metasenv ugraph -> ty',metasenv,ugraph)
60   in
61    Tacticals.thens
62    ~start:
63      (Tactics.cut ty
64        ~mk_fresh_name_callback:(fun _ _ _  ~typ -> Cic.Name id))
65    ~continuations:[ continuation ; just ]
66 ;;
67
68 let bydone ~dbd t =
69  let just =
70   match t with
71      None -> Tactics.auto ~dbd ~params:[]
72    | Some t -> Tactics.apply t
73  in
74   just
75 ;;
76
77 let we_need_to_prove t id ty =
78  let aux status =
79   let cont,cutted =
80    match ty with
81       None -> Tacticals.id_tac,t
82     | Some ty ->
83        Tactics.change ~pattern:(None,[id,Cic.Implicit (Some `Hole)],None)
84          (fun _ metasenv ugraph -> t,metasenv,ugraph), ty in
85   let proof,goals =
86    ProofEngineTypes.apply_tactic
87     (Tacticals.thens
88       ~start:
89        (Tactics.cut cutted
90          ~mk_fresh_name_callback:(fun _ _ _  ~typ -> Cic.Name id))
91       ~continuations:[cont])
92     status
93   in
94    let goals' =
95     match goals with
96        [fst; snd] -> [snd; fst]
97      | _ -> assert false
98    in
99     proof,goals'
100  in
101   ProofEngineTypes.mk_tactic aux
102 ;;
103
104 let existselim t id1 t1 id2 t2 =
105 (*BUG: t1 and t2 not used *)
106 (*PARSING BUG: t2 is parsed in the current context, but it may
107   have occurrences of id1 in it *)
108  Tactics.elim_intros t
109   ~mk_fresh_name_callback:
110     (let i = ref 0 in
111       fun _ _ _  ~typ ->
112        incr i;
113        if !i = 1 then Cic.Name id1 else Cic.Name id2)
114
115 let andelim = existselim;;
116
117 let rewritingstep ~dbd lhs rhs just conclude =
118  let aux ((proof,goal) as status) =
119   let (curi,metasenv,proofbo,proofty) = proof in
120   let _,context,_ = CicUtil.lookup_meta goal metasenv in
121   let eq,trans =
122    match LibraryObjects.eq_URI () with
123       None -> raise (ProofEngineTypes.Fail (lazy "You need to register the default equality first. Please use the \"default\" command"))
124     | Some uri ->
125       Cic.MutInd (uri,0,[]), Cic.Const (LibraryObjects.trans_eq_URI ~eq:uri,[])
126   in
127   let ty,_ =
128    CicTypeChecker.type_of_aux' metasenv context rhs CicUniv.empty_ugraph in
129   let just =
130    match just with
131       None ->
132        Tactics.auto ~dbd
133         ~params:["paramodulation","1"; "timeout","3"]
134     | Some just -> Tactics.apply just
135   in
136    match lhs with
137       None ->
138        let plhs,prhs =
139         match 
140          fst
141           (CicTypeChecker.type_of_aux' metasenv context (Cic.Rel 1)
142             CicUniv.empty_ugraph)
143         with
144            Cic.Appl [_;_;plhs;prhs] -> plhs,prhs
145          | _ -> assert false in
146        let last_hyp_name =
147         match context with
148            (Some (Cic.Name id,_))::_ -> id
149          | _ -> assert false
150        in
151         (match conclude with
152             None ->
153              ProofEngineTypes.apply_tactic
154               (Tacticals.thens
155                 ~start:(Tactics.apply ~term:trans)
156                 ~continuations:
157                   [ Tactics.apply prhs ;
158                     Tactics.apply (Cic.Rel 1) ;
159                     just]) status
160           | Some name ->
161              let mk_fresh_name_callback =
162               fun metasenv context _ ~typ ->
163                 FreshNamesGenerator.mk_fresh_name ~subst:[]
164                  metasenv context name ~typ
165              in
166               ProofEngineTypes.apply_tactic
167                (Tacticals.thens
168                  ~start:(Tactics.cut ~mk_fresh_name_callback
169                   (Cic.Appl [eq ; ty ; plhs ; rhs]))
170                  ~continuations:
171                    [ Tactics.clear ~hyps:[last_hyp_name] ;
172                      Tacticals.thens
173                       ~start:(Tactics.apply ~term:trans)
174                       ~continuations:
175                         [ Tactics.apply prhs ;
176                           Tactics.apply (Cic.Rel 1) ;
177                           just]
178                    ]) status)
179     | Some lhs ->
180        match conclude with
181           None -> ProofEngineTypes.apply_tactic just status
182         | Some name ->
183             let mk_fresh_name_callback =
184              fun metasenv context _ ~typ ->
185                FreshNamesGenerator.mk_fresh_name ~subst:[]
186                 metasenv context name ~typ
187             in
188              ProofEngineTypes.apply_tactic
189               (Tacticals.thens
190                 ~start:
191                   (Tactics.cut ~mk_fresh_name_callback
192                     (Cic.Appl [eq ; ty ; lhs ; rhs]))
193                 ~continuations:[ Tacticals.id_tac ; just ]) status
194  in
195   ProofEngineTypes.mk_tactic aux
196 ;;
197
198 let we_proceed_by_induction_on t pat =
199  (*BUG here: pat unused *)
200  Tactics.elim_intros ~depth:0 t
201 ;;
202
203 let case id ~params =
204  (*BUG here: id unused*)
205  (*BUG here: it does not verify that the previous branch is closed *)
206  (*BUG here: the params should be parsed telescopically*)
207  (*BUG here: the tactic_terms should be terms*)
208  let rec aux ~params ((proof,goal) as status) =
209   match params with
210      [] -> proof,[goal]
211    | (id,t)::tl ->
212       match ProofEngineTypes.apply_tactic (assume id t) status with
213          proof,[goal] -> aux tl (proof,goal)
214        | _ -> assert false
215  in
216   ProofEngineTypes.mk_tactic (aux ~params)
217 ;;
218
219 let thesisbecomes t =
220 let ty = None in
221  (*BUG here: missing check on t *)
222  match ty with
223     None -> Tacticals.id_tac
224   | Some ty ->
225      Tactics.change ~pattern:(None,[],Some (Cic.Implicit (Some `Hole)))
226       (fun _ metasenv ugraph -> ty,metasenv,ugraph)
227 ;;
228
229 let byinduction t id  = suppose t id None;;