author | wenzelm |
Wed, 23 Nov 2005 22:23:52 +0100 | |
changeset 18240 | 3b72f559e942 |
parent 18235 | 63da52e2d6dc |
child 18250 | dfe5d09514eb |
permissions | -rw-r--r-- |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Provers/induct_method.ML |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
3 |
Author: Markus Wenzel, TU Muenchen |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
4 |
|
11735 | 5 |
Proof by cases and induction on sets and types. |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
6 |
*) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
7 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
8 |
signature INDUCT_METHOD_DATA = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
9 |
sig |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
10 |
val dest_concls: term -> term list |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
11 |
val cases_default: thm |
11996
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
12 |
val local_impI: thm |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
13 |
val conjI: thm |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
14 |
val atomize: thm list |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
15 |
val rulify1: thm list |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
16 |
val rulify2: thm list |
12240 | 17 |
val localize: thm list |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
18 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
19 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
20 |
signature INDUCT_METHOD = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
21 |
sig |
16391 | 22 |
val cases_tac: Proof.context -> bool -> term option list list -> thm option -> |
18224 | 23 |
thm list -> int -> cases_tactic |
18240 | 24 |
val fix_tac: Proof.context -> (string * typ) list -> int -> tactic |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
25 |
val induct_tac: Proof.context -> bool -> (string option * term) option list list -> |
18235 | 26 |
(string * typ) list list -> term option list -> thm option -> thm list -> int -> cases_tactic |
27 |
val coinduct_tac: Proof.context -> bool -> term option list -> term option list -> |
|
28 |
thm option -> thm list -> int -> cases_tactic |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
29 |
val setup: (theory -> theory) list |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
30 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
31 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
32 |
functor InductMethodFun(Data: INDUCT_METHOD_DATA): INDUCT_METHOD = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
33 |
struct |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
34 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
35 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
36 |
(** misc utils **) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
37 |
|
18205 | 38 |
(* lists *) |
39 |
||
40 |
fun nth_list xss i = nth xss i handle Subscript => []; |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
41 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
42 |
fun align_left msg xs ys = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
43 |
let val m = length xs and n = length ys |
11735 | 44 |
in if m < n then raise ERROR_MESSAGE msg else (Library.take (n, xs) ~~ ys) end; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
45 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
46 |
fun align_right msg xs ys = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
47 |
let val m = length xs and n = length ys |
11735 | 48 |
in if m < n then raise ERROR_MESSAGE msg else (Library.drop (m - n, xs) ~~ ys) end; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
49 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
50 |
|
11735 | 51 |
(* prep_inst *) |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
52 |
|
18205 | 53 |
fun prep_inst thy align tune (tm, ts) = |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
54 |
let |
18205 | 55 |
val cert = Thm.cterm_of thy; |
15531 | 56 |
fun prep_var (x, SOME t) = |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
57 |
let |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
58 |
val cx = cert x; |
18147 | 59 |
val {T = xT, thy, ...} = Thm.rep_cterm cx; |
12799
5472afdd3bd3
MetaSimplifier.rewrite_term replaces slow Tactic.rewrite_cterm;
wenzelm
parents:
12305
diff
changeset
|
60 |
val ct = cert (tune t); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
61 |
in |
18147 | 62 |
if Sign.typ_instance thy (#T (Thm.rep_cterm ct), xT) then SOME (cx, ct) |
11735 | 63 |
else raise ERROR_MESSAGE (Pretty.string_of (Pretty.block |
64 |
[Pretty.str "Ill-typed instantiation:", Pretty.fbrk, |
|
65 |
Display.pretty_cterm ct, Pretty.str " ::", Pretty.brk 1, |
|
66 |
Display.pretty_ctyp (#T (Thm.crep_cterm ct))])) |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
67 |
end |
15531 | 68 |
| prep_var (_, NONE) = NONE; |
11735 | 69 |
val xs = InductAttrib.vars_of tm; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
70 |
in |
11735 | 71 |
align "Rule has fewer variables than instantiations given" xs ts |
15570 | 72 |
|> List.mapPartial prep_var |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
73 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
74 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
75 |
|
18205 | 76 |
(* trace_rules *) |
77 |
||
78 |
fun trace_rules _ kind [] = error ("Unable to figure out " ^ kind ^ " rule") |
|
79 |
| trace_rules ctxt _ rules = Method.trace ctxt rules; |
|
80 |
||
81 |
||
82 |
(* make_cases *) |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
83 |
|
18224 | 84 |
fun make_cases is_open rule = |
85 |
RuleCases.make is_open NONE (Thm.theory_of_thm rule, Thm.prop_of rule); |
|
86 |
||
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
87 |
fun warn_open true = warning "Encountered open rule cases -- deprecated" |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
88 |
| warn_open false = (); |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
89 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
90 |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
91 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
92 |
(** cases method **) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
93 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
94 |
(* |
11735 | 95 |
rule selection scheme: |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
96 |
cases - default case split |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
97 |
`x:A` cases ... - set cases |
11735 | 98 |
cases t - type cases |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
99 |
... cases ... r - explicit rule |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
100 |
*) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
101 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
102 |
local |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
103 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
104 |
fun find_casesT ctxt ((SOME t :: _) :: _) = InductAttrib.find_casesT ctxt (Term.fastype_of t) |
11735 | 105 |
| find_casesT _ _ = []; |
106 |
||
18224 | 107 |
fun find_casesS ctxt (fact :: _) = InductAttrib.find_casesS ctxt (Thm.concl_of fact) |
11735 | 108 |
| find_casesS _ _ = []; |
109 |
||
16391 | 110 |
in |
111 |
||
112 |
fun cases_tac ctxt is_open insts opt_rule facts = |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
113 |
let |
18224 | 114 |
val _ = warn_open is_open; |
18147 | 115 |
val thy = ProofContext.theory_of ctxt; |
116 |
val cert = Thm.cterm_of thy; |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
117 |
|
11735 | 118 |
fun inst_rule r = |
18224 | 119 |
if null insts then `RuleCases.get r |
11735 | 120 |
else (align_left "Rule has fewer premises than arguments given" (Thm.prems_of r) insts |
18205 | 121 |
|> (List.concat o map (prep_inst thy align_left I)) |
18224 | 122 |
|> Drule.cterm_instantiate) r |> pair (RuleCases.get r); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
123 |
|
11735 | 124 |
val ruleq = |
12852 | 125 |
(case opt_rule of |
18205 | 126 |
SOME r => Seq.single (inst_rule r) |
127 |
| NONE => |
|
128 |
(find_casesS ctxt facts @ find_casesT ctxt insts @ [Data.cases_default]) |
|
129 |
|> tap (trace_rules ctxt InductAttrib.casesN) |
|
18224 | 130 |
|> Seq.of_list |> Seq.maps (Seq.try inst_rule)); |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
131 |
in |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
132 |
fn i => fn st => |
18224 | 133 |
ruleq |
18235 | 134 |
|> Seq.maps (RuleCases.consume [] facts) |
18224 | 135 |
|> Seq.maps (fn ((cases, (_, more_facts)), rule) => |
136 |
CASES (make_cases is_open rule cases) |
|
137 |
(Method.insert_tac more_facts i THEN Tactic.rtac rule i) st) |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
138 |
end; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
139 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
140 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
141 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
142 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
143 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
144 |
(** induct method **) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
145 |
|
18235 | 146 |
(* fix_tac *) |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
147 |
|
18240 | 148 |
fun revert_skolem ctxt x = |
149 |
(case ProofContext.revert_skolem ctxt x of |
|
150 |
SOME x' => x' |
|
151 |
| NONE => Syntax.deskolem x); |
|
152 |
||
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
153 |
local |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
154 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
155 |
val meta_spec = PureThy.get_thm Pure.thy (Name "meta_spec"); |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
156 |
|
18240 | 157 |
fun meta_spec_tac ctxt (x, T) = SUBGOAL (fn (goal, i) => fn st => |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
158 |
let |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
159 |
val thy = Thm.theory_of_thm st; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
160 |
val cert = Thm.cterm_of thy; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
161 |
val certT = Thm.ctyp_of thy; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
162 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
163 |
val v = Free (x, T); |
18205 | 164 |
in |
165 |
if Term.exists_subterm (fn t => t aconv v) goal then |
|
166 |
let |
|
167 |
val P = Term.absfree (x, T, goal); |
|
168 |
val rule = meta_spec |
|
169 |
|> Drule.instantiate' [SOME (certT T)] [SOME (cert P), SOME (cert v)] |
|
18240 | 170 |
|> Thm.rename_params_rule ([revert_skolem ctxt x], 1); |
18205 | 171 |
in compose_tac (false, rule, 1) i end |
172 |
else all_tac |
|
18224 | 173 |
end st); |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
174 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
175 |
in |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
176 |
|
18240 | 177 |
fun fix_tac ctxt xs = EVERY' (map (meta_spec_tac ctxt) (rev (gen_distinct (op =) xs))); |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
178 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
179 |
end; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
180 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
181 |
|
18235 | 182 |
(* add_defs *) |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
183 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
184 |
fun add_defs def_insts = |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
185 |
let |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
186 |
fun add (SOME (SOME x, t)) ctxt = |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
187 |
let val ((lhs, def), ctxt') = ProofContext.add_def (x, t) ctxt |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
188 |
in ((SOME (Free lhs), [def]), ctxt') end |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
189 |
| add (SOME (NONE, t)) ctxt = ((SOME t, []), ctxt) |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
190 |
| add NONE ctxt = ((NONE, []), ctxt); |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
191 |
in fold_map add def_insts #> apfst (split_list #> apsnd List.concat) end; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
192 |
|
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
193 |
|
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
194 |
(* atomize and rulify *) |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
195 |
|
18147 | 196 |
fun atomize_term thy = |
197 |
ObjectLogic.drop_judgment thy o MetaSimplifier.rewrite_term thy Data.atomize []; |
|
12799
5472afdd3bd3
MetaSimplifier.rewrite_term replaces slow Tactic.rewrite_cterm;
wenzelm
parents:
12305
diff
changeset
|
198 |
|
5472afdd3bd3
MetaSimplifier.rewrite_term replaces slow Tactic.rewrite_cterm;
wenzelm
parents:
12305
diff
changeset
|
199 |
fun rulified_term thm = |
18147 | 200 |
let val thy = Thm.theory_of_thm thm in |
12799
5472afdd3bd3
MetaSimplifier.rewrite_term replaces slow Tactic.rewrite_cterm;
wenzelm
parents:
12305
diff
changeset
|
201 |
Thm.prop_of thm |
18147 | 202 |
|> MetaSimplifier.rewrite_term thy Data.rulify1 [] |
203 |
|> MetaSimplifier.rewrite_term thy Data.rulify2 [] |
|
204 |
|> pair thy |
|
12799
5472afdd3bd3
MetaSimplifier.rewrite_term replaces slow Tactic.rewrite_cterm;
wenzelm
parents:
12305
diff
changeset
|
205 |
end; |
11756 | 206 |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
207 |
val atomize_tac = Tactic.rewrite_goal_tac Data.atomize; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
208 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
209 |
val rulify_tac = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
210 |
Tactic.rewrite_goal_tac Data.rulify1 THEN' |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
211 |
Tactic.rewrite_goal_tac Data.rulify2 THEN' |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
212 |
Tactic.norm_hhf_tac; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
213 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
214 |
|
18240 | 215 |
(* internalize/localize rules -- pseudo-elimination *) |
18147 | 216 |
|
217 |
local |
|
11996
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
218 |
|
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
219 |
fun imp_intr i raw_th = |
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
220 |
let |
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
221 |
val th = Thm.permute_prems (i - 1) 1 raw_th; |
18147 | 222 |
val {thy, maxidx, ...} = Thm.rep_thm th; |
11996
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
223 |
val cprems = Drule.cprems_of th; |
15570 | 224 |
val As = Library.take (length cprems - 1, cprems); |
18147 | 225 |
val C = Thm.cterm_of thy (Var (("C", maxidx + 1), propT)); |
18023 | 226 |
in th COMP Thm.lift_rule (Drule.list_implies (As, C)) Data.local_impI end; |
11996
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
227 |
|
18147 | 228 |
in |
229 |
||
230 |
fun internalize k th = if k > 0 then internalize (k - 1) (imp_intr k th) else th; |
|
231 |
||
18240 | 232 |
val localize = Goal.norm_hhf o Tactic.simplify false Data.localize; |
233 |
||
18147 | 234 |
end; |
235 |
||
11996
b409a8cbe1fb
induct: internalize ``missing'' consumes-facts from goal state
wenzelm
parents:
11984
diff
changeset
|
236 |
|
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
237 |
(* join multi-rules *) |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
238 |
|
11735 | 239 |
val eq_prems = curry (Term.aconvs o pairself Thm.prems_of); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
240 |
|
11735 | 241 |
fun join_rules [] = [] |
242 |
| join_rules [th] = [th] |
|
243 |
| join_rules (rules as r :: rs) = |
|
244 |
if not (forall (eq_prems r) rs) then [] |
|
245 |
else |
|
246 |
let |
|
247 |
val th :: ths = map Drule.freeze_all rules; |
|
248 |
val cprems = Drule.cprems_of th; |
|
249 |
val asms = map Thm.assume cprems; |
|
250 |
in |
|
251 |
[foldr1 (fn (x, x') => [x, x'] MRS Data.conjI) |
|
252 |
(map (fn x => Drule.implies_elim_list x asms) (th :: ths)) |
|
253 |
|> Drule.implies_intr_list cprems |
|
12305 | 254 |
|> Drule.standard' |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13197
diff
changeset
|
255 |
|> RuleCases.save r] |
11735 | 256 |
end; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
257 |
|
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
258 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
259 |
(* divinate rule instantiation -- cannot handle pending goal parameters *) |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
260 |
|
18205 | 261 |
local |
262 |
||
18147 | 263 |
fun dest_env thy (env as Envir.Envir {iTs, ...}) = |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
264 |
let |
18147 | 265 |
val cert = Thm.cterm_of thy; |
266 |
val certT = Thm.ctyp_of thy; |
|
15794
5de27a5fc5ed
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15708
diff
changeset
|
267 |
val pairs = Envir.alist_of env; |
18147 | 268 |
val ts = map (cert o Envir.norm_term env o #2 o #2) pairs; |
269 |
val xs = map2 (cert o Var) (map #1 pairs, map (#T o Thm.rep_cterm) ts); |
|
270 |
in (map (fn (xi, (S, T)) => (certT (TVar (xi, S)), certT T)) (Vartab.dest iTs), xs ~~ ts) end; |
|
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
271 |
|
18205 | 272 |
in |
273 |
||
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
274 |
fun divinate_inst rule i st = |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
275 |
let |
18147 | 276 |
val {thy, maxidx, ...} = Thm.rep_thm st; |
277 |
val goal = Thm.term_of (Thm.cprem_of st i); (*exception Subscript*) |
|
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
278 |
val params = rev (rename_wrt_term goal (Logic.strip_params goal)); (*as they are printed :-*) |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
279 |
in |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
280 |
if not (null params) then |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
281 |
(warning ("Cannot determine rule instantiation due to pending parameter(s): " ^ |
18147 | 282 |
commas (map (Sign.string_of_term thy o Syntax.mark_boundT) params)); |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
283 |
Seq.single rule) |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
284 |
else |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
285 |
let |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
286 |
val rule' = Thm.incr_indexes (maxidx + 1) rule; |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
287 |
val concl = Logic.strip_assums_concl goal; |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
288 |
in |
18147 | 289 |
Unify.smash_unifiers (thy, Envir.empty (#maxidx (Thm.rep_thm rule')), |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
290 |
[(Thm.concl_of rule', concl)]) |
18147 | 291 |
|> Seq.map (fn env => Drule.instantiate (dest_env thy env) rule') |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
292 |
end |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
293 |
end handle Subscript => Seq.empty; |
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
294 |
|
18205 | 295 |
end; |
296 |
||
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
297 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
298 |
(* special renaming of rule parameters *) |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
299 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
300 |
fun special_rename_params ctxt [[SOME (Free (z, Type (T, _)))]] thm = |
18147 | 301 |
let |
18240 | 302 |
val x = revert_skolem ctxt z; |
18147 | 303 |
fun index i [] = [] |
304 |
| index i (y :: ys) = |
|
305 |
if x = y then x ^ string_of_int i :: index (i + 1) ys |
|
306 |
else y :: index i ys; |
|
307 |
fun rename_params [] = [] |
|
308 |
| rename_params ((y, Type (U, _)) :: ys) = |
|
309 |
(if U = T then x else y) :: rename_params ys |
|
310 |
| rename_params ((y, _) :: ys) = y :: rename_params ys; |
|
311 |
fun rename_asm A = |
|
312 |
let |
|
313 |
val xs = rename_params (Logic.strip_params A); |
|
314 |
val xs' = |
|
315 |
(case List.filter (equal x) xs of |
|
316 |
[] => xs | [_] => xs | _ => index 1 xs); |
|
317 |
in Logic.list_rename_params (xs', A) end; |
|
318 |
fun rename_prop p = |
|
319 |
let val (As, C) = Logic.strip_horn p |
|
320 |
in Logic.list_implies (map rename_asm As, C) end; |
|
321 |
val cp' = cterm_fun rename_prop (Thm.cprop_of thm); |
|
322 |
val thm' = Thm.equal_elim (Thm.reflexive cp') thm; |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
323 |
in RuleCases.save thm thm' end |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
324 |
| special_rename_params _ _ thm = thm; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
325 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
326 |
|
18205 | 327 |
(* rule_versions *) |
328 |
||
329 |
fun rule_versions rule = Seq.cons (rule, |
|
18235 | 330 |
(Seq.make (fn () => |
18240 | 331 |
SOME (localize rule, Seq.empty))) |
18205 | 332 |
|> Seq.filter (not o curry Thm.eq_thm rule)) |
18224 | 333 |
|> Seq.map (pair (RuleCases.get rule)); |
18205 | 334 |
|
18235 | 335 |
fun rule_instance thy inst rule = |
336 |
Drule.cterm_instantiate (prep_inst thy align_left I (Thm.prop_of rule, inst)) rule; |
|
337 |
||
18205 | 338 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
339 |
(* induct_tac *) |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
340 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
341 |
(* |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
342 |
rule selection scheme: |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
343 |
`x:A` induct ... - set induction |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
344 |
induct x - type induction |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
345 |
... induct ... r - explicit rule |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
346 |
*) |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
347 |
|
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
348 |
local |
15235
614a804d7116
Induction now preserves the name of the induction variable.
nipkow
parents:
14981
diff
changeset
|
349 |
|
11735 | 350 |
fun find_inductT ctxt insts = |
18147 | 351 |
fold_rev multiply (insts |> List.mapPartial (fn [] => NONE | ts => List.last ts) |
18205 | 352 |
|> map (InductAttrib.find_inductT ctxt o Term.fastype_of)) [[]] |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
353 |
|> map join_rules |> List.concat; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
354 |
|
18224 | 355 |
fun find_inductS ctxt (fact :: _) = InductAttrib.find_inductS ctxt (Thm.concl_of fact) |
11735 | 356 |
| find_inductS _ _ = []; |
357 |
||
16391 | 358 |
in |
11790
42393a11642d
simplified resolveq_cases_tac for cases, separate version for induct;
wenzelm
parents:
11781
diff
changeset
|
359 |
|
18235 | 360 |
fun induct_tac ctxt is_open def_insts fixing taking opt_rule facts = |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
361 |
let |
18224 | 362 |
val _ = warn_open is_open; |
18147 | 363 |
val thy = ProofContext.theory_of ctxt; |
364 |
val cert = Thm.cterm_of thy; |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
365 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
366 |
val ((insts, defs), defs_ctxt) = fold_map add_defs def_insts ctxt |>> split_list; |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
367 |
|
18224 | 368 |
val inst_rule = apsnd (fn r => |
12168
dc93c2e82205
induct: rule_versions produces localized variants;
wenzelm
parents:
12162
diff
changeset
|
369 |
if null insts then r |
11735 | 370 |
else (align_right "Rule has fewer conclusions than arguments given" |
371 |
(Data.dest_concls (Thm.concl_of r)) insts |
|
18205 | 372 |
|> (List.concat o map (prep_inst thy align_right (atomize_term thy))) |
12168
dc93c2e82205
induct: rule_versions produces localized variants;
wenzelm
parents:
12162
diff
changeset
|
373 |
|> Drule.cterm_instantiate) r); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
374 |
|
11735 | 375 |
val ruleq = |
376 |
(case opt_rule of |
|
18205 | 377 |
SOME r => r |> rule_versions |> Seq.map inst_rule |
378 |
| NONE => |
|
379 |
(find_inductS ctxt facts @ |
|
380 |
map (special_rename_params defs_ctxt insts) (find_inductT ctxt insts)) |
|
381 |
|> tap (trace_rules ctxt InductAttrib.inductN) |
|
18224 | 382 |
|> Seq.of_list |> Seq.maps rule_versions |> Seq.maps (Seq.try inst_rule)); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
383 |
|
18224 | 384 |
fun rule_cases rule = RuleCases.make is_open (SOME (Thm.prop_of rule)) (rulified_term rule); |
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
385 |
in |
18205 | 386 |
(fn i => fn st => |
18224 | 387 |
ruleq |
18235 | 388 |
|> Seq.maps (RuleCases.consume (List.concat defs) facts) |
18224 | 389 |
|> Seq.maps (fn ((cases, (k, more_facts)), rule) => |
18205 | 390 |
(CONJUNCTS (ALLGOALS (fn j => |
391 |
Method.insert_tac (more_facts @ nth_list defs (j - 1)) j |
|
18240 | 392 |
THEN fix_tac defs_ctxt (nth_list fixing (j - 1)) j)) |
18205 | 393 |
THEN' atomize_tac) i st |> Seq.maps (fn st' => |
18235 | 394 |
divinate_inst (internalize k rule) i st' |
395 |
|> Seq.map (rule_instance thy taking) |
|
396 |
|> Seq.maps (fn rule' => |
|
18224 | 397 |
CASES (rule_cases rule' cases) |
398 |
(Tactic.rtac rule' i THEN |
|
399 |
PRIMSEQ (ProofContext.exports defs_ctxt ctxt)) st')))) |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
400 |
THEN_ALL_NEW_CASES rulify_tac |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
401 |
end; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
402 |
|
18205 | 403 |
end; |
404 |
||
405 |
||
406 |
||
407 |
(** coinduct method **) |
|
408 |
||
409 |
(* |
|
410 |
rule selection scheme: |
|
18224 | 411 |
goal "x:A" coinduct ... - set coinduction |
412 |
coinduct x - type coinduction |
|
413 |
coinduct ... r - explicit rule |
|
18205 | 414 |
*) |
415 |
||
416 |
local |
|
417 |
||
418 |
fun find_coinductT ctxt (SOME t :: _) = InductAttrib.find_coinductT ctxt (Term.fastype_of t) |
|
419 |
| find_coinductT _ _ = []; |
|
420 |
||
18224 | 421 |
fun find_coinductS ctxt goal = InductAttrib.find_coinductS ctxt (Logic.strip_assums_concl goal); |
18205 | 422 |
|
423 |
in |
|
424 |
||
18235 | 425 |
fun coinduct_tac ctxt is_open inst taking opt_rule facts = |
18205 | 426 |
let |
18224 | 427 |
val _ = warn_open is_open; |
18205 | 428 |
val thy = ProofContext.theory_of ctxt; |
429 |
val cert = Thm.cterm_of thy; |
|
430 |
||
18224 | 431 |
val inst_rule = apsnd (fn r => |
18205 | 432 |
if null inst then r |
433 |
else Drule.cterm_instantiate (prep_inst thy align_left I (Thm.concl_of r, inst)) r); |
|
434 |
||
18224 | 435 |
fun ruleq goal = |
18205 | 436 |
(case opt_rule of |
437 |
SOME r => r |> rule_versions |> Seq.map inst_rule |
|
438 |
| NONE => |
|
18224 | 439 |
(find_coinductS ctxt goal @ find_coinductT ctxt inst) |
18205 | 440 |
|> tap (trace_rules ctxt InductAttrib.coinductN) |
18224 | 441 |
|> Seq.of_list |> Seq.maps rule_versions |> Seq.maps (Seq.try inst_rule)); |
18205 | 442 |
in |
18224 | 443 |
SUBGOAL_CASES (fn (goal, i) => fn st => |
444 |
ruleq goal |
|
18235 | 445 |
|> Seq.maps (RuleCases.consume [] facts) |
18224 | 446 |
|> Seq.maps (fn ((cases, (_, more_facts)), rule) => |
18235 | 447 |
divinate_inst rule i st |
448 |
|> Seq.map (rule_instance thy taking) |
|
449 |
|> Seq.maps (fn rule' => |
|
18224 | 450 |
CASES (make_cases is_open rule' cases) |
451 |
(Method.insert_tac more_facts i THEN Tactic.rtac rule' i) st))) |
|
18205 | 452 |
end; |
453 |
||
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
454 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
455 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
456 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
457 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
458 |
(** concrete syntax **) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
459 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
460 |
val openN = "open"; |
18205 | 461 |
val fixingN = "fixing"; |
18235 | 462 |
val takingN = "taking"; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
463 |
val ruleN = "rule"; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
464 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
465 |
local |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
466 |
|
15703 | 467 |
fun named_rule k arg get = |
468 |
Scan.lift (Args.$$$ k -- Args.colon) |-- arg :-- (fn name => Scan.peek (fn ctxt => |
|
469 |
(case get ctxt name of SOME x => Scan.succeed x |
|
470 |
| NONE => error ("No rule for " ^ k ^ " " ^ quote name)))) >> #2; |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
471 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
472 |
fun rule get_type get_set = |
15703 | 473 |
named_rule InductAttrib.typeN Args.local_tyname get_type || |
474 |
named_rule InductAttrib.setN Args.local_const get_set || |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
475 |
Scan.lift (Args.$$$ ruleN -- Args.colon) |-- Attrib.local_thm; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
476 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
477 |
val cases_rule = rule InductAttrib.lookup_casesT InductAttrib.lookup_casesS; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
478 |
val induct_rule = rule InductAttrib.lookup_inductT InductAttrib.lookup_inductS; |
18205 | 479 |
val coinduct_rule = rule InductAttrib.lookup_coinductT InductAttrib.lookup_coinductS; |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
480 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
481 |
val inst = Scan.lift (Args.$$$ "_") >> K NONE || Args.local_term >> SOME; |
18147 | 482 |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
483 |
val def_inst = |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
484 |
((Scan.lift (Args.name --| (Args.$$$ "\\<equiv>" || Args.$$$ "==")) >> SOME) |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
485 |
-- Args.local_term) >> SOME || |
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
486 |
inst >> Option.map (pair NONE); |
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
487 |
|
18147 | 488 |
val free = Scan.state -- Args.local_term >> (fn (_, Free v) => v | (ctxt, t) => |
489 |
error ("Bad free variable: " ^ ProofContext.string_of_term ctxt t)); |
|
490 |
||
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
491 |
fun unless_more_args scan = Scan.unless (Scan.lift |
18235 | 492 |
((Args.$$$ fixingN || Args.$$$ takingN || Args.$$$ InductAttrib.typeN || |
493 |
Args.$$$ InductAttrib.setN || Args.$$$ ruleN) -- Args.colon)) scan; |
|
18205 | 494 |
|
495 |
val fixing = Scan.optional (Scan.lift (Args.$$$ fixingN -- Args.colon) |-- |
|
496 |
Args.and_list1 (Scan.repeat (unless_more_args free))) []; |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
497 |
|
18235 | 498 |
val taking = Scan.optional (Scan.lift (Args.$$$ takingN -- Args.colon) |-- |
499 |
Scan.repeat1 (unless_more_args inst)) []; |
|
500 |
||
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
501 |
in |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
502 |
|
18235 | 503 |
fun cases_meth src = |
504 |
Method.syntax (Args.mode openN -- |
|
505 |
(Args.and_list (Scan.repeat (unless_more_args inst)) -- Scan.option cases_rule)) src |
|
506 |
#> (fn (ctxt, (is_open, (insts, opt_rule))) => |
|
507 |
Method.METHOD_CASES (fn facts => |
|
508 |
Seq.DETERM (HEADGOAL (cases_tac ctxt is_open insts opt_rule facts)))); |
|
18178
9e4dfe031525
induct: support local definitions to be passed through the induction;
wenzelm
parents:
18147
diff
changeset
|
509 |
|
18235 | 510 |
fun induct_meth src = |
511 |
Method.syntax (Args.mode openN -- |
|
512 |
(Args.and_list (Scan.repeat (unless_more_args def_inst)) -- |
|
513 |
(fixing -- taking -- Scan.option induct_rule))) src |
|
514 |
#> (fn (ctxt, (is_open, (insts, ((fixing, taking), opt_rule)))) => |
|
515 |
Method.RAW_METHOD_CASES (fn facts => |
|
516 |
Seq.DETERM (HEADGOAL (induct_tac ctxt is_open insts fixing taking opt_rule facts)))); |
|
18205 | 517 |
|
18235 | 518 |
fun coinduct_meth src = |
519 |
Method.syntax (Args.mode openN -- |
|
520 |
(Scan.repeat (unless_more_args inst) -- taking -- Scan.option coinduct_rule)) src |
|
521 |
#> (fn (ctxt, (is_open, ((insts, taking), opt_rule))) => |
|
522 |
Method.RAW_METHOD_CASES (fn facts => |
|
523 |
Seq.DETERM (HEADGOAL (coinduct_tac ctxt is_open insts taking opt_rule facts)))); |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
524 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
525 |
end; |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
526 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
527 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
528 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
529 |
(** theory setup **) |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
530 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
531 |
val setup = |
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
532 |
[Method.add_methods |
18235 | 533 |
[(InductAttrib.casesN, cases_meth, "case analysis on types or sets"), |
534 |
(InductAttrib.inductN, induct_meth, "induction on types or sets"), |
|
535 |
(InductAttrib.coinductN, coinduct_meth, "coinduction on types or sets")]]; |
|
11670
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
536 |
|
59f79df42d1f
proof by cases and induction on types and sets (used to be specific for HOL);
wenzelm
parents:
diff
changeset
|
537 |
end; |