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)
59 let elim_type_tac ~term =
60 let elim_type_tac ~term status =
62 let module P = PrimitiveTactics in
63 let module T = Tacticals in
64 ProofEngineTypes.apply_tactic
66 ~start: (P.cut_tac term)
67 ~continuations:[ P.elim_intros_simpl_tac ~term:(C.Rel 1) ; T.id_tac ])
70 ProofEngineTypes.mk_tactic (elim_type_tac ~term)
74 (* Decompose related stuff *)
76 exception InteractiveUserUriChoiceNotRegistered
78 let interactive_user_uri_choice =
79 (ref (fun ~selection_mode -> raise InteractiveUserUriChoiceNotRegistered) :
80 (selection_mode:[`SINGLE | `EXTENDED] ->
82 ?enable_button_for_non_vars:bool ->
83 title:string -> msg:string -> string list -> string list) ref)
86 let decompose_tac ?(uris_choice_callback=(function l -> l)) term =
87 let decompose_tac uris_choice_callback term status =
88 let (proof, goal) = status in
90 let module R = CicReduction in
91 let module P = PrimitiveTactics in
92 let module T = Tacticals in
93 let module S = ProofEngineStructuralRules in
94 let _,metasenv,_,_ = proof in
95 let _,context,ty = CicUtil.lookup_meta goal metasenv in
96 let old_context_len = List.length context in
98 CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in
99 let rec make_list termty =
100 (* N.B.: altamente inefficente? *)
101 let rec search_inductive_types urilist termty =
102 (* search in term the Inductive Types and return a list of uris as triples like this: (uri,typeno,exp_named_subst) *)
104 (C.MutInd (uri,typeno,exp_named_subst)) (* when (not (List.mem (uri,typeno,exp_named_subst) urilist)) *) ->
105 (uri,typeno,exp_named_subst)::urilist
106 | (C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::applist)) (* when (not (List.mem (uri,typeno,exp_named_subst) urilist)) *) ->
107 (uri,typeno,exp_named_subst)::(List.fold_left search_inductive_types urilist applist)
109 (* N.B: in un caso tipo (and A !C:Prop.(or B C)) l'or *non* viene selezionato! *)
111 let rec purge_duplicates urilist =
112 let rec aux triple urilist =
118 else hd::(aux triple tl)
122 | hd::tl -> hd::(purge_duplicates (aux hd tl))
124 purge_duplicates (search_inductive_types [] termty)
128 (* list of triples (uri,typeno,exp_named_subst) of Inductive Types found in term and chosen by the user *)
129 (* N.B.: due to a bug in uris_choice_callback exp_named_subst are not significant (they all are []) *)
130 uris_choice_callback (make_list termty) in
132 let rec elim_clear_tac ~term' ~nr_of_hyp_still_to_elim status =
133 let (proof, goal) = status in
134 warn ("nr_of_hyp_still_to_elim=" ^ (string_of_int nr_of_hyp_still_to_elim));
135 if nr_of_hyp_still_to_elim <> 0 then
136 let _,metasenv,_,_ = proof in
137 let _,context,_ = CicUtil.lookup_meta goal metasenv in
138 let old_context_len = List.length context in
140 CicTypeChecker.type_of_aux' metasenv context term'
141 CicUniv.empty_ugraph in
142 warn ("elim_clear termty= " ^ CicPp.ppterm termty);
144 C.MutInd (uri,typeno,exp_named_subst)
145 | C.Appl((C.MutInd (uri,typeno,exp_named_subst))::_)
146 when (List.mem (uri,typeno,exp_named_subst) urilist) ->
147 warn ("elim " ^ CicPp.ppterm termty);
148 ProofEngineTypes.apply_tactic
150 ~start:(P.elim_intros_simpl_tac ~term:term')
152 (* clear the hyp that has just been eliminated *)
153 ProofEngineTypes.mk_tactic (fun status ->
154 let (proof, goal) = status in
155 let _,metasenv,_,_ = proof in
156 let _,context,_ = CicUtil.lookup_meta goal metasenv in
157 let new_context_len = List.length context in
158 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));
159 let new_nr_of_hyp_still_to_elim = nr_of_hyp_still_to_elim + (new_context_len - old_context_len) - 1 in
160 ProofEngineTypes.apply_tactic
163 if (term'==term) (* if it's the first application of elim, there's no need to clear the hyp *)
164 then begin prerr_endline ("%%%%%%% no clear"); T.id_tac end
165 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)
166 ~continuation:(ProofEngineTypes.mk_tactic (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)))
171 let new_nr_of_hyp_still_to_elim = nr_of_hyp_still_to_elim - 1 in
172 warn ("fail; hyp=" ^ (string_of_int new_nr_of_hyp_still_to_elim));
173 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
174 else (* no hyp to elim left in this goal *)
175 ProofEngineTypes.apply_tactic T.id_tac status
178 elim_clear_tac ~term':term ~nr_of_hyp_still_to_elim:1 status
180 ProofEngineTypes.mk_tactic (decompose_tac uris_choice_callback term)