]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/fwdSimplTactic.ml
many strings that are supposed to be URIs are now UriManager.uri
[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 (*
34 let module R = CicReduction
35 *)
36
37 let fail_msg0 = "not a declaration of the current context"
38 let fail_msg1 = "no applicable simplification"
39
40 let error msg = raise (PET.Fail msg)
41
42 let rec declaration name = function 
43    | []                                           -> error fail_msg0
44    | Some (hyp, Cic.Decl ty) :: _ when hyp = name -> ty
45    | _ :: tail                                    -> declaration name tail 
46
47 (* lapply *******************************************************************)
48
49 let lapply_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
50                ?(substs = []) what =
51    let rec strip_dependent_prods metasenv context ss = function
52       | Cic.Prod (name, t1, t2) as t -> 
53         if TC.does_not_occur context 0 1 t2 then metasenv, ss, t else 
54         let metasenv, index = MI.mk_implicit metasenv [] context in 
55         let rs = MI.identity_relocation_list_for_metavariable context in
56         let e, s = Some (name, Cic.Decl t1), Some (Cic.Meta (index, rs)) in
57         strip_dependent_prods metasenv (e :: context) (s :: ss) t2
58       | t    -> metasenv, ss, t
59    in
60    let update_metasenv metasenv ((xuri, _, u,t), goal) =
61       ((xuri, metasenv, u,t), goal)
62    in
63    let lapply_tac status =
64       let (proof, goal) = status in
65       let _,metasenv,_,_ = proof in
66       let _,context,ty = CicUtil.lookup_meta goal metasenv in
67       let lemma, _ = TC.type_of_aux' metasenv context what U.empty_ugraph in
68       let metasenv, substs, stripped_lemma = strip_dependent_prods metasenv context [] lemma in
69       let status = update_metasenv metasenv status in
70       let holed_lemma = S.subst_meta substs stripped_lemma in      
71       PET.apply_tactic (PT.cut_tac ~mk_fresh_name_callback holed_lemma) status
72    in
73    PET.mk_tactic lapply_tac
74
75 (* fwd **********************************************************************)
76
77 let fwd_simpl_tac ~hyp ~dbd =
78    let fwd_simpl_tac status =
79       let (proof, goal) = status in
80       let _,metasenv,_,_ = proof in
81       let _,context,ty = CicUtil.lookup_meta goal metasenv in
82       let major = declaration hyp context in 
83       match  MetadataQuery.fwd_simpl ~dbd major with
84          | []       -> error fail_msg1
85          | uri :: _ -> prerr_endline (UriManager.string_of_uri uri); (proof, [])  
86    in
87    PET.mk_tactic fwd_simpl_tac