]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/proofEngineStructuralRules.ml
Initial revision
[helm.git] / helm / gTopLevel / proofEngineStructuralRules.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 open ProofEngineTypes
27
28 let clearbody ~hyp ~status:(proof, goal) =
29  let module C = Cic in
30   match hyp with
31      None -> assert false
32    | Some (_, C.Decl _) -> raise (Fail "No Body To Clear")
33    | Some (n_to_clear_body, C.Def term) as hyp_to_clear_body ->
34       let curi,metasenv,pbo,pty = proof in
35        let metano,_,_ = List.find (function (m,_,_) -> m=goal) metasenv in
36         let string_of_name =
37          function
38             C.Name n -> n
39           | C.Anonimous -> "_"
40         in
41         let metasenv' =
42          List.map
43           (function
44               (m,canonical_context,ty) when m = metano ->
45                 let canonical_context' =
46                  List.fold_right
47                   (fun entry context ->
48                     match entry with
49                        t when t == hyp_to_clear_body ->
50                         let cleared_entry =
51                          let ty =
52                           CicTypeChecker.type_of_aux' metasenv context term
53                          in
54                           Some (n_to_clear_body, Cic.Decl ty)
55                         in
56                          cleared_entry::context
57                      | None -> None::context
58                      | Some (n,C.Decl t)
59                      | Some (n,C.Def t) ->
60                         let _ =
61                          try
62                           CicTypeChecker.type_of_aux' metasenv context t
63                          with
64                           _ ->
65                             raise
66                              (Fail
67                                ("The correctness of hypothesis " ^
68                                 string_of_name n ^
69                                 " relies on the body of " ^
70                                 string_of_name n_to_clear_body)
71                              )
72                         in
73                          entry::context
74                   ) canonical_context []
75                 in
76                  let _ =
77                   try
78                    CicTypeChecker.type_of_aux' metasenv canonical_context' ty
79                   with
80                    _ ->
81                     raise
82                      (Fail
83                       ("The correctness of the goal relies on the body of " ^
84                        string_of_name n_to_clear_body))
85                  in
86                   m,canonical_context',ty
87             | t -> t
88           ) metasenv
89         in
90          (curi,metasenv',pbo,pty), [goal]
91
92 let clear ~hyp:hyp_to_clear ~status:(proof, goal) =
93  let module C = Cic in
94   match hyp_to_clear with
95      None -> assert false
96    | Some (n_to_clear, _) ->
97       let curi,metasenv,pbo,pty = proof in
98        let metano,context,ty =
99         List.find (function (m,_,_) -> m=goal) metasenv
100        in
101         let string_of_name =
102          function
103             C.Name n -> n
104           | C.Anonimous -> "_"
105         in
106         let metasenv' =
107          List.map
108           (function
109               (m,canonical_context,ty) when m = metano ->
110                 let canonical_context' =
111                  List.fold_right
112                   (fun entry context ->
113                     match entry with
114                        t when t == hyp_to_clear -> None::context
115                      | None -> None::context
116                      | Some (n,C.Decl t)
117                      | Some (n,C.Def t) ->
118                         let _ =
119                          try
120                           CicTypeChecker.type_of_aux' metasenv context t
121                          with
122                           _ ->
123                             raise
124                              (Fail
125                                ("Hypothesis " ^
126                                 string_of_name n ^
127                                 " uses hypothesis " ^
128                                 string_of_name n_to_clear)
129                              )
130                         in
131                          entry::context
132                   ) canonical_context []
133                 in
134                  let _ =
135                   try
136                    CicTypeChecker.type_of_aux' metasenv canonical_context' ty
137                   with
138                    _ ->
139                     raise
140                      (Fail
141                       ("Hypothesis " ^ string_of_name n_to_clear ^
142                        " occurs in the goal"))
143                  in
144                   m,canonical_context',ty
145             | t -> t
146           ) metasenv
147         in
148          (curi,metasenv',pbo,pty), [goal]
149