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/.
29 module P = PrimitiveTactics
31 module S = ProofEngineStructuralRules
32 module F = FreshNamesGenerator
33 module E = ProofEngineTypes
34 module H = ProofEngineHelpers
36 (* unexported tactics *******************************************************)
38 let get_name context index =
39 try match List.nth context (pred index) with
40 | Some (Cic.Name name, _) -> Some name
42 with Invalid_argument "List.nth" -> None
44 let rec scan_tac ~old_context_length ~index ~tactic =
46 let (proof, goal) = status in
47 let _, metasenv, _, _ = proof in
48 let _, context, _ = CicUtil.lookup_meta goal metasenv in
49 let context_length = List.length context in
51 match get_name context index with
52 | _ when index <= 0 -> (proof, [goal])
53 | None -> aux (pred index)
55 let tac = T.then_ ~start:(tactic ~what)
56 ~continuation:(scan_tac ~old_context_length:context_length ~index ~tactic)
58 try E.apply_tactic tac status
59 with E.Fail _ -> aux (pred index)
60 in aux (index + context_length - old_context_length - 1)
64 let rec check_inductive_types types = function
65 | C.MutInd (uri, typeno, _) -> List.mem (uri, typeno) types
66 | C.Appl (hd :: tl) -> check_inductive_types types hd
69 let elim_clear_tac ~mk_fresh_name_callback ~types ~what =
70 let elim_clear_tac status =
71 let (proof, goal) = status in
72 let _, metasenv, _, _ = proof in
73 let _, context, _ = CicUtil.lookup_meta goal metasenv in
74 let index, ty = H.lookup_type metasenv context what in
75 if check_inductive_types types ty then
76 let tac = T.then_ ~start:(P.elim_intros_tac ~mk_fresh_name_callback (C.Rel index))
77 ~continuation:(S.clear [what])
79 E.apply_tactic tac status
80 else raise (E.Fail (lazy "unexported elim_clear: not an eliminable type"))
82 E.mk_tactic elim_clear_tac
84 (* elim type ****************************************************************)
86 let elim_type_tac ?(mk_fresh_name_callback = F.mk_fresh_name ~subst:[]) ?depth
90 P.elim_intros_simpl_tac ?using ?depth ~mk_fresh_name_callback what
92 let elim_type_tac status =
94 T.thens ~start: (P.cut_tac what) ~continuations:[elim (C.Rel 1); T.id_tac]
96 E.apply_tactic tac status
98 E.mk_tactic elim_type_tac
100 (* decompose ****************************************************************)
102 (* robaglia --------------------------------------------------------------- *)
104 (** perform debugging output? *)
106 let debug_print = fun _ -> ()
108 (** debugging print *)
109 let warn s = debug_print (lazy ("DECOMPOSE: " ^ (Lazy.force s)))
111 (* search in term the Inductive Types and return a list of uris as triples like this: (uri,typeno,exp_named_subst) *)
112 let search_inductive_types ty =
113 let rec aux types = function
114 | C.MutInd (uri, typeno, _) when (not (List.mem (uri, typeno) types)) ->
115 (uri, typeno) :: types
116 | C.Appl applist -> List.fold_left aux types applist
120 (* N.B: in un caso tipo (and A forall C:Prop.(or B C)) l'or *non* viene selezionato! *)
122 (* roba seria ------------------------------------------------------------- *)
124 let decompose_tac ?(mk_fresh_name_callback = F.mk_fresh_name ~subst:[])
125 ?(user_types=[]) ?what ~dbd =
126 let decompose_tac status =
127 let (proof, goal) = status in
128 let _, metasenv,_,_ = proof in
129 let _, context, _ = CicUtil.lookup_meta goal metasenv in
130 let types = List.rev_append user_types (FwdQueries.decomposables dbd) in
131 let tactic = elim_clear_tac ~mk_fresh_name_callback ~types in
132 let old_context_length = List.length context in
133 let tac = match what with
135 T.then_ ~start:(tactic ~what)
136 ~continuation:(scan_tac ~old_context_length ~index:1 ~tactic)
138 scan_tac ~old_context_length ~index:old_context_length ~tactic
140 E.apply_tactic tac status
142 E.mk_tactic decompose_tac