]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/fwdSimplTactic.ml
Asts generalized: a lot of tactics where restricted to identifiers in place
[helm.git] / helm / ocaml / tactics / fwdSimplTactic.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 module MI = CicMkImplicit
27 module TC = CicTypeChecker 
28 module PET = ProofEngineTypes 
29 module U  = CicUniv
30 module S = CicSubstitution
31 module PT = PrimitiveTactics
32
33 let fail_msg1 = "no applicable simplification"
34
35 let error msg = raise (PET.Fail msg)
36
37 (* lapply *******************************************************************)
38
39 let lapply_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) what =
40    let rec strip_dependent_prods metasenv context ss = function
41       | Cic.Prod (name, t1, t2) as t -> 
42         if TC.does_not_occur context 0 1 t2 then metasenv, ss, t else 
43         let metasenv, index = MI.mk_implicit metasenv [] context in 
44         let rs = MI.identity_relocation_list_for_metavariable context in
45         let e, s = Some (name, Cic.Decl t1), Some (Cic.Meta (index, rs)) in
46         strip_dependent_prods metasenv (e :: context) (s :: ss) t2
47       | t    -> metasenv, ss, t
48    in
49    let update_metasenv metasenv ((xuri, _, u,t), goal) =
50       ((xuri, metasenv, u,t), goal)
51    in
52    let lapply_tac status =
53       let (proof, goal) = status in
54       let _,metasenv,_,_ = proof in
55       let _,context,ty = CicUtil.lookup_meta goal metasenv in
56       let lemma, _ = TC.type_of_aux' metasenv context what U.empty_ugraph in
57       let metasenv, substs, stripped_lemma = strip_dependent_prods metasenv context [] lemma in
58       let status = update_metasenv metasenv status in
59       let holed_lemma = S.subst_meta substs stripped_lemma in      
60       PET.apply_tactic (PT.cut_tac ~mk_fresh_name_callback holed_lemma) status
61    in
62    PET.mk_tactic lapply_tac
63
64 (* fwd **********************************************************************)
65
66 let fwd_simpl_tac ~term ~dbd =
67    let fwd_simpl_tac status =
68       let (proof, goal) = status in
69       let _,metasenv,_,_ = proof in
70       let _,context,ty = CicUtil.lookup_meta goal metasenv in
71       let major,_ =
72        CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph
73       in 
74       match  MetadataQuery.fwd_simpl ~dbd major with
75          | []       -> error fail_msg1
76          | uri :: _ -> prerr_endline (UriManager.string_of_uri uri); (proof, [])  
77    in
78    PET.mk_tactic fwd_simpl_tac