author | ibm-PC\ibm <xingyuanzhang@126.com> |
Fri, 12 Sep 2014 00:41:17 +0800 | |
changeset 23 | 452e8b557b63 |
parent 6 | 38cef5407d82 |
permissions | -rw-r--r-- |
6
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory LetElim |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main Data_slot |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
val _ = print_depth 100 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
val trace_elim = Attrib.setup_config_bool @{binding trace_elim} (K false) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
ML {* (* aux functions *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
val tracing = (fn ctxt => fn str => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
if (Config.get ctxt trace_elim) then tracing str else ()) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
val empty_env = (Vartab.empty, Vartab.empty) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
fun match_env ctxt pat trm env = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
Pattern.match (ctxt |> Proof_Context.theory_of) (pat, trm) env |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
fun match ctxt pat trm = match_env ctxt pat trm empty_env; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
val inst = Envir.subst_term; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
fun term_of_thm thm = thm |> prop_of |> HOLogic.dest_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
fun last [a] = a | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
last (a::b) = last b |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
fun but_last [a] = [] | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
but_last (a::b) = a::(but_last b) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
fun foldr f [] = (fn x => x) | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
foldr f (x :: xs) = (f x) o (foldr f xs) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
fun concat [] = [] | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
concat (x :: xs) = x @ concat xs |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
fun string_of_term ctxt t = t |> Syntax.pretty_term ctxt |> Pretty.str_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
fun string_of_cterm ctxt ct = ct |> term_of |> string_of_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
fun pterm ctxt t = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
t |> string_of_term ctxt |> tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
fun pcterm ctxt ct = ct |> string_of_cterm ctxt |> tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
fun pthm ctxt thm = thm |> prop_of |> pterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
fun string_for_term ctxt t = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
(print_mode_value ())) (Syntax.string_of_term ctxt) t |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
|> String.translate (fn c => if Char.isPrint c then str c else "") |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
|> Sledgehammer_Util.simplify_spaces |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
fun string_for_cterm ctxt ct = ct |> term_of |> string_for_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
fun attemp tac = fn i => fn st => (tac i st) handle exn => Seq.empty |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
fun try_tac tac = fn i => fn st => (tac i st) handle exn => (Seq.single st) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
fun ctxt_show ctxt = ctxt |> Config.put Proof_Context.verbose true |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
Config.put Proof_Context.debug true |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
Config.put Display.show_hyps true |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
Config.put Display.show_tags true |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
fun swf f = (fn x => fn y => f y x) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
*} (* aux end *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
fun close_form_over vars trm = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
fold Logic.all (map Free vars) trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
fun try_star f g = (try_star f (g |> f)) handle _ => g |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
fun bind_judgment ctxt name = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
val thy = Proof_Context.theory_of ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
val ([x], ctxt') = Proof_Context.add_fixes [(Binding.name name, NONE, NoSyn)] ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
val (t as _ $ Free v) = Object_Logic.fixed_judgment thy x; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
in ((v, t), ctxt') end; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
fun let_trm_of ctxt mjp = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
fun is_let_trm (((Const (@{const_name "Let"}, _)) $ let_expr) $ let_rest) = true |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
| is_let_trm _ = false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
ZipperSearch.all_td_lr (mjp |> Zipper.mktop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
|> Seq.filter (fn z => is_let_trm (Zipper.trm z)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
|> Seq.hd |> Zipper.trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
fun decr lev (Bound i) = if i >= lev then Bound (i - 1) else raise Same.SAME |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
| decr lev (Abs (a, T, body)) = Abs (a, T, decr (lev + 1) body) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
| decr lev (t $ u) = (decr lev t $ decrh lev u handle Same.SAME => t $ decr lev u) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
| decr _ _ = raise Same.SAME |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
and decrh lev t = (decr lev t handle Same.SAME => t); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
(* A new version of [result], copied from [obtain.ML] *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
fun eliminate_term ctxt xs tm = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
val vs = map (dest_Free o Thm.term_of) xs; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
val bads = Term.fold_aterms (fn t as Free v => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
if member (op =) vs v then insert (op aconv) t else I | _ => I) tm []; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
val _ = null bads orelse |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
error ("Result contains obtained parameters: " ^ |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
space_implode " " (map (Syntax.string_of_term ctxt) bads)); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
in tm end; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
fun eliminate fix_ctxt rule xs As thm = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
val thy = Proof_Context.theory_of fix_ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
val _ = eliminate_term fix_ctxt xs (Thm.full_prop_of thm); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
val _ = Object_Logic.is_judgment thy (Thm.concl_of thm) orelse |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
error "Conclusion in obtained context must be object-logic judgment"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
val ((_, [thm']), ctxt') = Variable.import true [thm] fix_ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
val prems = Drule.strip_imp_prems (#prop (Thm.crep_thm thm')); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
((Drule.implies_elim_list thm' (map Thm.assume prems) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
|> Drule.implies_intr_list (map Drule.norm_hhf_cterm As) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
|> Drule.forall_intr_list xs) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
COMP rule) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
|> Drule.implies_intr_list prems |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
|> singleton (Variable.export ctxt' fix_ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
end; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
fun obtain_export ctxt rule xs _ As = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
(eliminate ctxt rule xs As, eliminate_term ctxt xs); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
fun check_result ctxt thesis th = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
(case Thm.prems_of th of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
[prem] => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
if Thm.concl_of th aconv thesis andalso |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
Logic.strip_assums_concl prem aconv thesis then th |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
else error ("Guessed a different clause:\n" ^ Display.string_of_thm ctxt th) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
| [] => error "Goal solved -- nothing guessed" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
| _ => error ("Guess split into several cases:\n" ^ Display.string_of_thm ctxt th)); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
130 |
fun result tac facts ctxt = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
131 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
val thy = Proof_Context.theory_of ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
val cert = Thm.cterm_of thy; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
val ([thesisN], _) = Variable.variant_fixes [Auto_Bind.thesisN] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt thesisN; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
val rule = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
139 |
(case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) (Goal.init (cert thesis)) of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
NONE => raise THM ("Obtain.result: tactic failed", 0, facts) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
| SOME th => check_result ctxt thesis (Raw_Simplifier.norm_hhf (Goal.conclude th))); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
val closed_rule = Thm.forall_intr (cert (Free thesis_var)) rule; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
val ((_, [rule']), ctxt') = Variable.import false [closed_rule] ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
val obtain_rule = Thm.forall_elim (cert (Logic.varify_global (Free thesis_var))) rule'; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
val ((params, stmt), fix_ctxt) = Variable.focus_cterm (Thm.cprem_of obtain_rule 1) ctxt'; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
val (prems, ctxt'') = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
Assumption.add_assms (obtain_export fix_ctxt obtain_rule (map #2 params)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
(Drule.strip_imp_prems stmt) fix_ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
in ((params, prems), ctxt'') end; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
local |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
fun let_lhs ctxt vars let_rest = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
case let_rest of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
Const (@{const_name prod_case}, _) $ let_rest => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
val (exp1, rest1) = let_lhs ctxt vars let_rest |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
val vars = Term.add_frees exp1 vars |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
val (exp2, rest2) = let_lhs ctxt vars rest1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
in ((Const (@{const_name Pair}, dummyT) $ exp1 $ exp2), rest2) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
| Abs (var, var_typ, rest) => let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
val (vars', _) = Variable.variant_fixes ((map fst vars)@[var]) ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
val (_, var') = vars' |> split_last |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
val [(var, var_typ)] = Variable.variant_frees ctxt (map Free vars) [(var, var_typ)] in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
(Free (var', var_typ), rest) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
fun sg_lhs_f ctxt (vars, eqns, let_trm) = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
val (((Const (@{const_name "Let"}, _)) $ let_expr) $ let_rest) = let_trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
val let_rest = case let_rest of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
Abs ("", _, let_rest$Bound 0) => decrh 0 let_rest |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
| _ => let_rest |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
val (lhs, let_trm) = let_rest |> let_lhs ctxt vars |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
val lhs = lhs|> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
val let_expr = let_expr |> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
val eqn = HOLogic.mk_eq (lhs, let_expr) |> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
val eqns = (eqn::eqns) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
val vars = Term.add_frees lhs vars |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
val let_trm = Term.subst_bounds ((map Free vars), let_trm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
in (vars, eqns, let_trm) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
fun dest_let ctxt let_trm = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
val (vars, eqns, lrest) = try_star (sg_lhs_f ctxt) ([], [], let_trm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
in (vars, eqns, lrest) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
fun let_elim_rule ctxt mjp = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
val ctxt = ctxt |> Variable.set_body false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
val thy = Proof_Context.theory_of ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
val tracing = tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
val pthm = pthm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
val pterm = pterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
val pcterm = pcterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
val let_trm = let_trm_of ctxt mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
val ([pname], _) = Variable.variant_fixes ["P"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
val P = Free (pname, dummyT) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
val mjp = (Const (@{const_name Trueprop}, dummyT)$(P$let_trm)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
|> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
val (Const (@{const_name Trueprop}, _)$((P as Free(_, _))$let_trm)) = mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
val (vars, eqns, lrest) = dest_let ctxt let_trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
val ([thesisN], _) = Variable.variant_fixes ["let_thesis"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
val thesis_p = Free (thesisN, @{typ bool}) |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
val next_p = (P $ lrest) |> (HOLogic.mk_Trueprop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
val that_prems = (P $ lrest) :: (rev eqns) |> map (HOLogic.mk_Trueprop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
val that_prop = Logic.list_implies (that_prems, thesis_p) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
val that_prop = close_form_over vars that_prop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
fun exists_on_lhs eq = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
val (lhs, rhs) = eq |> HOLogic.dest_eq |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
fun exists_on vars trm = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
fun sg_exists_on (n, ty) trm = HOLogic.mk_exists (n, ty, trm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
in fold sg_exists_on vars trm end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
216 |
in exists_on (Term.add_frees lhs []) eq end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
fun prove_eqn ctxt0 eqn = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
val (lhs, let_expr) = eqn |> HOLogic.dest_eq |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
val eq_e_prop = exists_on_lhs eqn |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
fun case_rule_of ctxt let_expr = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
val case_rule = Induct.find_casesT ctxt (let_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
val case_var = case_rule |> swf Thm.cprem_of 1 |> Thm.term_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
|> Induct.vars_of |> hd |> cterm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
val mt = Thm.match (case_var, let_expr |> cterm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
val case_rule = Thm.instantiate mt case_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
in case_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
227 |
val case_rule = SOME (case_rule_of ctxt0 let_expr) handle _ => NONE |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
val my_case_tac = case case_rule of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
SOME case_rule => (rtac case_rule 1) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
| _ => all_tac |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
val eq_e = Goal.prove ctxt0 [] [] eq_e_prop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
(K (my_case_tac THEN (auto_tac ctxt0))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
in eq_e end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
val peqns = eqns |> map (prove_eqn ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
fun add_result thm (facts, ctxt) = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
val ((_, [fact]), ctxt1) = (result (K (REPEAT (etac @{thm exE} 1))) [thm] ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
in (fact::facts, ctxt1) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
val add_results = fold add_result |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
val (facts, ctxt1) = add_results (rev peqns) ([], ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
(* val facts = rev facts *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
val ([mjp_p, that_p], ctxt2) = ctxt1 |> Assumption.add_assumes (map cterm [mjp, that_prop]) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
val sym_facts = map (swf (curry (op RS)) @{thm sym}) facts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
fun rsn eq that_p = eq RSN (2, that_p) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
val rule1 = fold rsn (rev facts) that_p |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
val tac = (Method.insert_tac ([mjp_p]@sym_facts) 1) THEN (auto_tac ctxt2) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
val next_pp = Goal.prove ctxt [] [] next_p (K tac) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
val result = next_pp RS rule1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
val ctxt3 = fold (fn var => fn ctxt => (Variable.auto_fixes var ctxt)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
[mjp, thesis_p] ctxt2 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
val [let_elim_rule] = Proof_Context.export ctxt3 ctxt [result] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
in let_elim_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
fun let_intro_rule ctxt mjp = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
val ctxt = ctxt |> Variable.set_body false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
val thy = Proof_Context.theory_of ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
val tracing = tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
258 |
val pthm = pthm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
259 |
val pterm = pterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
val pcterm = pcterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
val ([thesisN], _) = Variable.variant_fixes ["let_thesis"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
val thesis_p = Free (thesisN, @{typ bool}) |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
264 |
val let_trm = let_trm_of ctxt mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
265 |
val ([pname], _) = Variable.variant_fixes ["P"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
val P = Free (pname, dummyT) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
val mjp = (Const (@{const_name Trueprop}, dummyT)$(P$let_trm)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
|> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
val (Const (@{const_name Trueprop}, _)$((P as Free(_, _))$let_trm)) = mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
270 |
val (((Const (@{const_name "Let"}, _)) $ let_expr) $ let_rest) = let_trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
271 |
val (vars, eqns, lrest) = dest_let ctxt let_trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
val next_p = (P $ lrest) |> (HOLogic.mk_Trueprop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
val that_prems = (rev eqns) |> map (HOLogic.mk_Trueprop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
275 |
val that_prop = Logic.list_implies (that_prems, next_p) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
276 |
val that_prop = close_form_over vars that_prop |> Syntax.check_term ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
fun exists_on_lhs eq = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
278 |
val (lhs, rhs) = eq |> HOLogic.dest_eq |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
fun exists_on vars trm = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
fun sg_exists_on (n, ty) trm = HOLogic.mk_exists (n, ty, trm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
281 |
in fold sg_exists_on vars trm end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
282 |
in exists_on (Term.add_frees lhs []) eq end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
fun prove_eqn ctxt0 eqn = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
284 |
val (lhs, let_expr) = eqn |> HOLogic.dest_eq |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
val eq_e_prop = exists_on_lhs eqn |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
286 |
fun case_rule_of ctxt let_expr = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
val case_rule = Induct.find_casesT ctxt (let_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
288 |
val case_var = case_rule |> swf Thm.cprem_of 1 |> Thm.term_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
289 |
|> Induct.vars_of |> hd |> cterm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
290 |
val mt = Thm.match (case_var, let_expr |> cterm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
val case_rule = Thm.instantiate mt case_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
292 |
in case_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
val case_rule = SOME (case_rule_of ctxt0 let_expr) handle _ => NONE |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
val my_case_tac = case case_rule of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
295 |
SOME case_rule => (rtac case_rule 1) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
296 |
| _ => all_tac |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
297 |
val eq_e = Goal.prove ctxt0 [] [] eq_e_prop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
298 |
(K (my_case_tac THEN (auto_tac ctxt0))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
299 |
in eq_e end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
300 |
val peqns = eqns |> map (prove_eqn ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
301 |
fun add_result thm (facts, ctxt) = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
302 |
val ((_, [fact]), ctxt1) = (result (K (REPEAT (etac @{thm exE} 1))) [thm] ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
in (fact::facts, ctxt1) end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
304 |
val add_results = fold add_result |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
val (facts, ctxt1) = add_results (rev peqns) ([], ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
306 |
val sym_facts = map (swf (curry (op RS)) @{thm sym}) facts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
307 |
val ([that_p], ctxt2) = ctxt1 |> Assumption.add_assumes (map cterm [that_prop]) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
308 |
fun rsn eq that_p = eq RSN (1, that_p) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
309 |
val rule1 = fold rsn (rev facts) that_p |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
310 |
val tac = (Method.insert_tac (rule1::sym_facts) 1) THEN (auto_tac ctxt2) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
val result = Goal.prove ctxt [] [] mjp (K tac) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
val ctxt3 = fold (fn var => fn ctxt => (Variable.auto_fixes var ctxt)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
313 |
[mjp, thesis_p] ctxt2 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
val [let_intro_rule] = Proof_Context.export ctxt3 ctxt [result] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
in let_intro_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
316 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
320 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
321 |
fun let_elim_tac ctxt i st = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
322 |
val thy = Proof_Context.theory_of ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
324 |
val goal = nth (Thm.prems_of st) (i - 1) |> cterm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
325 |
val mjp = goal |> Drule.strip_imp_prems |> swf nth 0 |> term_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
326 |
val rule = let_elim_rule ctxt mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
327 |
val tac = (etac rule i st) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
328 |
in tac end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
329 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
330 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
331 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
332 |
local |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
333 |
val case_names_tagN = "case_names"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
334 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
335 |
val implode_args = space_implode ";"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
336 |
val explode_args = space_explode ";"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
337 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
338 |
fun add_case_names NONE = I |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
339 |
| add_case_names (SOME names) = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
340 |
Thm.untag_rule case_names_tagN |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
341 |
#> Thm.tag_rule (case_names_tagN, implode_args names); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
342 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
343 |
fun let_elim_cases_tac ctxt facts = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
344 |
val tracing = tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
345 |
val pthm = pthm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
346 |
val pterm = pterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
347 |
val pcterm = pcterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
348 |
val mjp = facts |> swf nth 0 |> prop_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
349 |
val _ = tracing "let_elim_cases_tac: elim rule derived is:" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
350 |
val rule = (let_elim_rule ctxt mjp) |> Rule_Cases.put_consumes (SOME 1) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
351 |
|> add_case_names (SOME ["LetE"]) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
352 |
val _ = rule |> pthm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
353 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
354 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
355 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
356 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
357 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
358 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
359 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
360 |
val ctxt = @{context} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
361 |
val thy = Proof_Context.theory_of ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
362 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
363 |
val mjp = @{prop "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = g x y w; (x2, y2) = e3 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
364 |
in f w x1 y1 u)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
365 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
366 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
367 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
368 |
val mjp1 = @{prop "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = e2 in (w +x1 *y1 +u))"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
369 |
val mjp2 = @{prop "P (let ((x, y), (z, u)) = e; (u, v) = e1 in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
370 |
(case u of (Some t) \<Rightarrow> f t x y z | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
371 |
None \<Rightarrow> g x y z))"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
372 |
val mjp3 = @{prop "P (let x = e1; ((x1, y1), u) = e2 in f x w x1 y1 u)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
373 |
val mjp = @{prop "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = g x y w; (x2, y2) = e3 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
374 |
in f w x1 y1 u)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
375 |
val mjps = [mjp1, mjp2, mjp3, mjp] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
376 |
val t = mjps |> map (let_elim_rule ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
377 |
val t2 = mjps |> map (let_intro_rule ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
378 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
379 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
380 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
381 |
val let_elim_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
382 |
Method.setup @{binding let_elim} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
383 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
384 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
385 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
386 |
(let_elim_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
387 |
"elimination of prems containing lets "; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
388 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
389 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
390 |
setup {* let_elim_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
391 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
392 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
393 |
val ctxt = @{context} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
394 |
val mjp = @{prop "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = g x y w; (x2, y2) = e3 x1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
395 |
in f w x1 y1 u)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
396 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
397 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
398 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
399 |
fun focus_params t ctxt = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
400 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
401 |
val (xs, Ts) = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
402 |
split_list (Term.variant_frees t (Term.strip_all_vars t)); (*as they are printed :-*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
403 |
(* val (xs', ctxt') = variant_fixes xs ctxt; *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
404 |
(* val ps = xs' ~~ Ts; *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
405 |
val ps = xs ~~ Ts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
406 |
val (_, ctxt'') = ctxt |> Variable.add_fixes xs |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
407 |
in ((xs, ps), ctxt'') end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
408 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
409 |
fun focus_concl ctxt t = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
410 |
let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
411 |
val ((xs, ps), ctxt') = focus_params t ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
412 |
val t' = Term.subst_bounds (rev (map Free ps), Term.strip_all_body t); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
413 |
in (t' |> Logic.strip_imp_concl, ctxt') end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
414 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
415 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
416 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
417 |
local |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
418 |
val case_names_tagN = "case_names"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
419 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
420 |
val implode_args = space_implode ";"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
421 |
val explode_args = space_explode ";"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
422 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
423 |
fun add_case_names NONE = I |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
424 |
| add_case_names (SOME names) = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
425 |
Thm.untag_rule case_names_tagN |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
426 |
#> Thm.tag_rule (case_names_tagN, implode_args names); |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
427 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
428 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
429 |
fun let_intro_cases_tac ctxt facts i st = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
430 |
val (mjp, _) = nth (Thm.prems_of st) (i - 1) |> focus_concl ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
431 |
val rule = (let_intro_rule ctxt mjp) |> add_case_names (SOME ["LetI"]) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
432 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
433 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts i st |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
434 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
435 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
436 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
437 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
438 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
439 |
val let_intro_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
440 |
Method.setup @{binding let_intro} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
441 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
442 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
443 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
444 |
(let_intro_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
445 |
"introduction rule for goals containing lets "; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
446 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
447 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
448 |
setup {* let_intro_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
449 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
450 |
lemma assumes "Q xxx" "W uuuu" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
451 |
shows "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = g x y w; (x2, y2) = e3 x1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
452 |
in f w x1 y1 u) = www" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
453 |
using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
454 |
proof(let_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
455 |
case (LetI x y w ww x1 y1 u x2 y2) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
456 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
457 |
oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
458 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
459 |
lemma |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
460 |
assumes "P (let (((x, y), w), ww) = e1; ((x1, y1), u) = g x y w; (x2, y2) = e3 x1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
461 |
in f w x1 y1 u)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
462 |
and "Q xxx" "W uuuu" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
463 |
shows "thesis" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
464 |
proof(let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
465 |
case (LetE x y w ww x1 y1 u x2 y2) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
466 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
467 |
oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
468 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
469 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
470 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
471 |
val mjp = @{prop "P ( case (u@v) of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
472 |
Nil \<Rightarrow> f u v |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
473 |
| x#xs \<Rightarrow> g u v x xs |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
474 |
)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
475 |
val mjp1 = @{term "( case (h u v) of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
476 |
None \<Rightarrow> g u v x |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
477 |
| Some x \<Rightarrow> (case v of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
478 |
Nil \<Rightarrow> f u v | |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
479 |
x#xs \<Rightarrow> h x xs |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
480 |
) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
481 |
)"} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
482 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
483 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
484 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
485 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
486 |
fun case_trm_of ctxt mjp = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
487 |
ZipperSearch.all_td_lr (mjp |> Zipper.mktop) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
488 |
|> Seq.filter (fn z => ((Case_Translation.strip_case ctxt true (Zipper.trm z)) <> NONE)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
489 |
|> Seq.hd |> Zipper.trm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
490 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
491 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
492 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
493 |
fun case_elim_rule ctxt mjp = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
494 |
val ctxt = ctxt |> Variable.set_body false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
495 |
val thy = Proof_Context.theory_of ctxt; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
496 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
497 |
val ([thesisN], _) = Variable.variant_fixes ["my_thesis"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
498 |
val ((_, thesis_p), _) = bind_judgment ctxt thesisN |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
499 |
val case_trm = case_trm_of ctxt mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
500 |
val (case_expr, case_eqns) = case_trm |> Case_Translation.strip_case ctxt true |> the |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
501 |
val ([pname], _) = Variable.variant_fixes ["P"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
502 |
val P = Free (pname, [(case_trm |> type_of)] ---> @{typ bool}) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
503 |
val mjp_p = (P $ case_trm) |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
504 |
val ctxt0 = Proof_Context.init_global thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
505 |
val thats = case_eqns |> map (fn (lhs, rhs) => let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
506 |
val vars = Term.add_frees lhs [] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
507 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
508 |
Logic.list_implies ([(P$rhs)|>HOLogic.mk_Trueprop, |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
509 |
HOLogic.mk_eq (case_expr, lhs) |> HOLogic.mk_Trueprop], thesis_p) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
510 |
close_form_over vars |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
511 |
end) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
512 |
map (Term.map_types (Term.map_type_tvar (fn _ => dummyT))) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
513 |
map (Syntax.check_term ctxt0) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
514 |
val (mjp_p::that_ps, ctxt1) = ctxt |> Assumption.add_assumes (map cterm (mjp_p::thats)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
515 |
fun case_rule_of ctxt let_expr = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
516 |
val case_rule = Induct.find_casesT ctxt (let_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
517 |
val case_var = case_rule |> swf Thm.cprem_of 1 |> Thm.term_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
518 |
|> Induct.vars_of |> hd |> cterm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
519 |
val mt = Thm.match (case_var, let_expr |> cterm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
520 |
val case_rule = Thm.instantiate mt case_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
521 |
in case_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
522 |
val case_rule = case_rule_of ctxt case_expr |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
523 |
val my_case_tac = (rtac case_rule) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
524 |
val my_tac = ((Method.insert_tac (mjp_p::that_ps)) THEN' my_case_tac THEN' (K (auto_tac ctxt1))) 1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
525 |
val result = Goal.prove ctxt1 [] [] thesis_p (K my_tac) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
526 |
val ctxt2 = fold (fn var => fn ctxt => (Variable.auto_fixes var ctxt)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
527 |
[P, thesis_p, mjp] ctxt1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
528 |
val [case_elim_rule] = Proof_Context.export ctxt2 ctxt [result] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
529 |
val ocase_rule = Induct.find_casesT ctxt (case_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
530 |
fun get_case_names rule = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
531 |
AList.lookup (op =) (Thm.get_tags rule) "case_names" |> the |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
532 |
fun put_case_names names rule = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
533 |
Thm.tag_rule ("case_names", names) rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
534 |
val case_elim_rule = put_case_names (get_case_names ocase_rule) case_elim_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
535 |
in case_elim_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
536 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
537 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
538 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
539 |
fun case_elim_cases_tac ctxt facts = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
540 |
val mjp = facts |> swf nth 0 |> prop_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
541 |
val rule = (case_elim_rule ctxt mjp) |> Rule_Cases.put_consumes (SOME 1) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
542 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
543 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
544 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
545 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
546 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
547 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
548 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
549 |
val case_elim_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
550 |
Method.setup @{binding case_elim} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
551 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
552 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
553 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
554 |
(case_elim_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
555 |
"elimination of prems containing case "; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
556 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
557 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
558 |
setup {* case_elim_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
559 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
560 |
lemma assumes |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
561 |
"P (case h u v of None \<Rightarrow> g u v x | Some x \<Rightarrow> case v of [] \<Rightarrow> f u v | x # xs \<Rightarrow> h x xs)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
562 |
"GG u v" "PP w x" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
563 |
shows "thesis" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
564 |
proof(case_elim) (* ccc *) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
565 |
case None |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
566 |
thus ?case oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
567 |
(* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
568 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
569 |
case (Some x) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
570 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
571 |
proof(case_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
572 |
case Nil |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
573 |
thus ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
574 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
575 |
case (Cons y ys) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
576 |
thus ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
577 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
578 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
579 |
*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
580 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
581 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
582 |
fun case_intro_rule ctxt mjp = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
583 |
val ctxt = ctxt |> Variable.set_body false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
584 |
val tracing = tracing ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
585 |
val pthm = pthm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
586 |
val pterm = pterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
587 |
val pcterm = pcterm ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
588 |
val thy = Proof_Context.theory_of ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
589 |
val cterm = cterm_of thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
590 |
val ([thesisN], _) = Variable.variant_fixes ["my_thesis"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
591 |
val ((_, thesis_p), _) = bind_judgment ctxt thesisN |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
592 |
val case_trm = case_trm_of ctxt mjp |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
593 |
val (case_expr, case_eqns) = case_trm |> Case_Translation.strip_case ctxt true |> the |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
594 |
val ([pname], _) = Variable.variant_fixes ["P"] ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
595 |
val P = Free (pname, [(case_trm |> type_of)] ---> @{typ bool}) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
596 |
val mjp_p = (P $ case_trm) |> HOLogic.mk_Trueprop |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
597 |
val ctxt0 = Proof_Context.init_global thy |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
598 |
val thats = case_eqns |> map (fn (lhs, rhs) => let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
599 |
val vars = Term.add_frees lhs [] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
600 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
601 |
Logic.list_implies ([HOLogic.mk_eq (case_expr, lhs) |> HOLogic.mk_Trueprop], |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
602 |
(P$rhs)|>HOLogic.mk_Trueprop) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
603 |
close_form_over vars |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
604 |
end) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
605 |
map (Term.map_types (Term.map_type_tvar (fn _ => dummyT))) |> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
606 |
map (Syntax.check_term ctxt0) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
607 |
val (that_ps, ctxt1) = ctxt |> Assumption.add_assumes (map cterm (thats)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
608 |
fun case_rule_of ctxt let_expr = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
609 |
val case_rule = Induct.find_casesT ctxt (let_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
610 |
val case_var = case_rule |> swf Thm.cprem_of 1 |> Thm.term_of |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
611 |
|> Induct.vars_of |> hd |> cterm |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
612 |
val mt = Thm.match (case_var, let_expr |> cterm) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
613 |
val case_rule = Thm.instantiate mt case_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
614 |
in case_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
615 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
616 |
val case_rule = case_rule_of ctxt case_expr |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
617 |
val my_case_tac = (rtac case_rule) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
618 |
val my_tac = ((Method.insert_tac (that_ps)) THEN' my_case_tac THEN' (K (auto_tac ctxt1))) 1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
619 |
val result = Goal.prove ctxt1 [] [] mjp_p (K my_tac) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
620 |
val ctxt2 = fold (fn var => fn ctxt => (Variable.auto_fixes var ctxt)) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
621 |
[P, thesis_p, mjp] ctxt1 |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
622 |
val [case_intro_rule] = Proof_Context.export ctxt2 ctxt [result] |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
623 |
val ocase_rule = Induct.find_casesT ctxt (case_expr |> type_of) |> hd |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
624 |
fun get_case_names rule = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
625 |
AList.lookup (op =) (Thm.get_tags rule) "case_names" |> the |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
626 |
fun put_case_names names rule = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
627 |
Thm.tag_rule ("case_names", names) rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
628 |
val case_intro_rule = put_case_names (get_case_names ocase_rule) case_intro_rule |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
629 |
in case_intro_rule end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
630 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
631 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
632 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
633 |
val t = [mjp, mjp1] |> map (case_intro_rule ctxt) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
634 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
635 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
636 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
637 |
fun case_intro_cases_tac ctxt facts i st = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
638 |
val (mjp, _) = nth (Thm.prems_of st) (i - 1) |> focus_concl ctxt |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
639 |
val rule = (case_intro_rule ctxt mjp) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
640 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
641 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts i st |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
642 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
643 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
644 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
645 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
646 |
val case_intro_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
647 |
Method.setup @{binding case_intro} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
648 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
649 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
650 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
651 |
(case_intro_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
652 |
"introduction rule for goals containing case"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
653 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
654 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
655 |
setup {* case_intro_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
656 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
657 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
658 |
lemma assumes "QQ (let u = e1; (j, k) = e1; (b, a) = qq j k in TT j k b a)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
659 |
shows "P (hhh y ys)" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
660 |
proof(let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
661 |
oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
662 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
663 |
lemma assumes |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
664 |
"QQ (let (j, k) = e1; (m, n) = qq j k in TT j k m n)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
665 |
"PP w x" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
666 |
shows "P (case h u v of None \<Rightarrow> g u v x | Some x1 \<Rightarrow> case v of [] \<Rightarrow> f u v | xx # xs \<Rightarrow> hhh xx xs)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
667 |
using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
668 |
proof(case_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
669 |
case None |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
670 |
from None(2) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
671 |
show ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
672 |
proof(let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
673 |
case (LetE j k a b) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
674 |
with None |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
675 |
show ?case oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
676 |
(* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
677 |
sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
678 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
679 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
680 |
case (Some x1) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
681 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
682 |
proof(case_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
683 |
case Nil |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
684 |
from Nil(3) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
685 |
show ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
686 |
proof(let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
687 |
case (LetE j k a b) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
688 |
with Nil show ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
689 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
690 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
691 |
case (Cons y ys) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
692 |
from Cons(3) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
693 |
show ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
694 |
proof (let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
695 |
case (LetE j k u v) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
696 |
with Cons |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
697 |
show ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
698 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
699 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
700 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
701 |
*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
702 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
703 |
lemma assumes |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
704 |
"QQ (let (j, k) = e1; (m, n) = qq j k in TT j k m n)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
705 |
"PP w uux" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
706 |
shows "P (case h u v of None \<Rightarrow> g u v x | Some x1 \<Rightarrow> case v of [] \<Rightarrow> f u v | xx # xs \<Rightarrow> hhh xx xs)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
707 |
using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
708 |
proof(let_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
709 |
case (LetE j k m n) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
710 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
711 |
proof(case_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
712 |
case None |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
713 |
thus ?case oops (* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
714 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
715 |
case (Some x) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
716 |
thus ?case |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
717 |
proof(case_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
718 |
case Nil |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
719 |
thus ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
720 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
721 |
case (Cons y ys) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
722 |
thus ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
723 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
724 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
725 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
726 |
*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
727 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
728 |
lemma ifE [consumes 1, case_names If_true If_false]: |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
729 |
assumes "P (if b then e1 else e2)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
730 |
"\<lbrakk>b; P e1\<rbrakk> \<Longrightarrow> thesis" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
731 |
"\<lbrakk>\<not> b; P e2\<rbrakk> \<Longrightarrow> thesis" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
732 |
shows "thesis" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
733 |
by (auto split:if_splits) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
734 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
735 |
lemma ifI [case_names If_true If_false]: |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
736 |
assumes "b \<Longrightarrow> P e1" "\<not> b \<Longrightarrow> P e2" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
737 |
shows "P (if b then e1 else e2)" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
738 |
by auto |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
739 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
740 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
741 |
fun if_elim_cases_tac ctxt facts = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
742 |
val rule = @{thm ifE} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
743 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
744 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
745 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
746 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
747 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
748 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
749 |
val if_elim_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
750 |
Method.setup @{binding if_elim} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
751 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
752 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
753 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
754 |
(if_elim_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
755 |
"elimination of prems containing if "; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
756 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
757 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
758 |
setup {* if_elim_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
759 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
760 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
761 |
fun if_intro_cases_tac ctxt facts i st = let |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
762 |
val rule = @{thm ifI} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
763 |
in |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
764 |
Induct.induct_tac ctxt true [] [] [] (SOME [rule]) facts i st |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
765 |
end |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
766 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
767 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
768 |
ML {* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
769 |
val if_intro_setup = |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
770 |
Method.setup @{binding if_intro} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
771 |
(Scan.lift (Args.mode Induct.no_simpN) >> |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
772 |
(fn no_simp => fn ctxt => |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
773 |
METHOD_CASES (fn facts => (HEADGOAL |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
774 |
(if_intro_cases_tac ctxt facts))))) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
775 |
"introduction rule for goals containing if"; |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
776 |
*} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
777 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
778 |
setup {* if_intro_setup *} |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
779 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
780 |
lemma assumes "(if (B x y) then f x y else g y x) = (t, p)" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
781 |
"P1 xxx" "P2 yyy" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
782 |
shows "that" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
783 |
proof(if_elim) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
784 |
case If_true |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
785 |
thus ?case oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
786 |
(* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
787 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
788 |
case If_false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
789 |
thus ?case oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
790 |
*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
791 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
792 |
lemma assumes "P1 xx" "P2 yy" |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
793 |
shows "P (if b then e1 else e2)" using assms |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
794 |
proof(if_intro) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
795 |
case If_true |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
796 |
thus ?case oops |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
797 |
(* |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
798 |
next |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
799 |
case If_false |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
800 |
thus ?case sorry |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
801 |
qed |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
802 |
*) |
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
803 |
|
38cef5407d82
updated various files to Isabelle-2013-2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
804 |
end |