1 (* Copyright (C) 2002, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
28 (** perform debugging output? *)
31 (** debugging print *)
34 prerr_endline ("DECOMPOSE: " ^ s)
39 let induction_tac ~term status =
40 let (proof, goal) = status in
42 let module R = CicReduction in
43 let module P = PrimitiveTactics in
44 let module T = Tacticals in
45 let module S = ProofEngineStructuralRules in
46 let module U = UriManager in
47 let (_,metasenv,_,_) = proof in
48 let _,context,ty = CicUtil.lookup_meta goal metasenv in
49 let termty = CicTypeChecker.type_of_aux' metasenv context term in (* per ora non serve *)
51 T.then_ ~start:(T.repeat_tactic
52 ~tactic:(T.then_ ~start:(VariousTactics.generalize_tac ~term) (* chissa' se cosi' funziona? *)
53 ~continuation:(P.intros))
54 ~continuation:(P.elim_intros_simpl ~term)
60 let elim_type_tac ~term status =
62 let module P = PrimitiveTactics in
63 let module T = Tacticals in
65 ~start: (P.cut_tac term)
66 ~continuations:[ P.elim_intros_simpl_tac ~term:(C.Rel 1) ; T.id_tac ]
71 (* Decompose related stuff *)
73 exception InteractiveUserUriChoiceNotRegistered
75 let interactive_user_uri_choice =
76 (ref (fun ~selection_mode -> raise InteractiveUserUriChoiceNotRegistered) :
77 (selection_mode:[`SINGLE | `EXTENDED] ->
79 ?enable_button_for_non_vars:bool ->
80 title:string -> msg:string -> string list -> string list) ref)
83 exception IllFormedUri of string
85 let cic_textual_parser_uri_of_string uri' =
88 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
89 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
91 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
92 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
96 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
97 CicTextualParser0.IndTyUri (uri'',typeno)
100 (* Constructor of an Inductive Type *)
101 let uri'',typeno,consno =
102 CicTextualLexer.indconuri_of_uri uri'
104 CicTextualParser0.IndConUri (uri'',typeno,consno)
107 _ -> raise (IllFormedUri uri')
111 let constructor_uri_of_string uri =
112 match cic_textual_parser_uri_of_string uri with
113 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
118 (* N.B.: nella finestra c'e' un campo "nessuno deei precedenti, prova questo" che non ha senso? *)
119 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
120 (* domanda: due triple possono essere diverse solo per avere exp_named_subst diverse?? *)
121 let module U = UriManager in
123 (constructor_uri_of_string)
124 (!interactive_user_uri_choice
125 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
126 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
128 (function (uri,typeno,_) -> U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1))
134 let decompose_tac ?(uris_choice_callback=(function l -> l)) term status =
135 let (proof, goal) = status in
136 let module C = Cic in
137 let module R = CicReduction in
138 let module P = PrimitiveTactics in
139 let module T = Tacticals in
140 let module S = ProofEngineStructuralRules in
141 let _,metasenv,_,_ = proof in
142 let _,context,ty = CicUtil.lookup_meta goal metasenv in
143 let old_context_len = List.length context in
144 let termty = CicTypeChecker.type_of_aux' metasenv context term in
146 let rec make_list termty =
147 (* N.B.: altamente inefficente? *)
148 let rec search_inductive_types urilist termty =
149 (* search in term the Inductive Types and return a list of uris as triples like this: (uri,typeno,exp_named_subst) *)
151 (C.MutInd (uri,typeno,exp_named_subst)) (* when (not (List.mem (uri,typeno,exp_named_subst) urilist)) *) ->
152 (uri,typeno,exp_named_subst)::urilist
153 | (C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::applist)) (* when (not (List.mem (uri,typeno,exp_named_subst) urilist)) *) ->
154 (uri,typeno,exp_named_subst)::(List.fold_left search_inductive_types urilist applist)
156 (* N.B: in un caso tipo (and A !C:Prop.(or B C)) l'or *non* viene selezionato! *)
158 let rec purge_duplicates urilist =
159 let rec aux triple urilist =
165 else hd::(aux triple tl)
169 | hd::tl -> hd::(purge_duplicates (aux hd tl))
171 purge_duplicates (search_inductive_types [] termty)
175 (* list of triples (uri,typeno,exp_named_subst) of Inductive Types found in term and chosen by the user *)
176 (* N.B.: due to a bug in uris_choice_callback exp_named_subst are not significant (they all are []) *)
177 uris_choice_callback (make_list termty) in
179 let rec elim_clear_tac ~term' ~nr_of_hyp_still_to_elim status =
180 let (proof, goal) = status in
181 warn ("nr_of_hyp_still_to_elim=" ^ (string_of_int nr_of_hyp_still_to_elim));
182 if nr_of_hyp_still_to_elim <> 0 then
183 let _,metasenv,_,_ = proof in
184 let _,context,_ = CicUtil.lookup_meta goal metasenv in
185 let old_context_len = List.length context in
186 let termty = CicTypeChecker.type_of_aux' metasenv context term' in
187 warn ("elim_clear termty= " ^ CicPp.ppterm termty);
189 C.MutInd (uri,typeno,exp_named_subst)
190 | C.Appl((C.MutInd (uri,typeno,exp_named_subst))::_)
191 when (List.mem (uri,typeno,exp_named_subst) urilist) ->
192 warn ("elim " ^ CicPp.ppterm termty);
194 ~start:(P.elim_intros_simpl_tac ~term:term')
196 (* clear the hyp that has just been eliminated *)
198 let (proof, goal) = status in
199 let _,metasenv,_,_ = proof in
200 let _,context,_ = CicUtil.lookup_meta goal metasenv in
201 let new_context_len = List.length context in
202 warn ("newcon=" ^ (string_of_int new_context_len) ^ " & oldcon=" ^ (string_of_int old_context_len) ^ " & old_nr_of_hyp=" ^ (string_of_int nr_of_hyp_still_to_elim));
203 let new_nr_of_hyp_still_to_elim = nr_of_hyp_still_to_elim + (new_context_len - old_context_len) - 1 in
206 if (term'==term) (* if it's the first application of elim, there's no need to clear the hyp *)
207 then begin prerr_endline ("%%%%%%% no clear"); T.id_tac end
208 else begin prerr_endline ("%%%%%%% clear " ^ (string_of_int (new_nr_of_hyp_still_to_elim))); (S.clear ~hyp:(List.nth context (new_nr_of_hyp_still_to_elim))) end)
209 ~continuation:(elim_clear_tac ~term':(C.Rel new_nr_of_hyp_still_to_elim) ~nr_of_hyp_still_to_elim:new_nr_of_hyp_still_to_elim)
214 let new_nr_of_hyp_still_to_elim = nr_of_hyp_still_to_elim - 1 in
215 warn ("fail; hyp=" ^ (string_of_int new_nr_of_hyp_still_to_elim));
216 elim_clear_tac ~term':(C.Rel new_nr_of_hyp_still_to_elim) ~nr_of_hyp_still_to_elim:new_nr_of_hyp_still_to_elim status
217 else (* no hyp to elim left in this goal *)
221 elim_clear_tac ~term':term ~nr_of_hyp_still_to_elim:1 status