1 (* Title: HOL/MicroJava/Comp/AuxLemmas.thy
2 Author: Martin Strecker
12 (**********************************************************************)
14 (**********************************************************************)
18 lemma app_nth_greater_len [rule_format (no_asm), simp]:
19 "\<forall> ind. length pre \<le> ind \<longrightarrow> (pre @ a # post) ! (Suc ind) = (pre @ post) ! ind"
26 lemma length_takeWhile: "v \<in> set xs \<Longrightarrow> length (takeWhile (%z. z~=v) xs) < length xs"
29 lemma nth_length_takeWhile [simp]:
30 "v \<in> set xs \<Longrightarrow> xs ! (length (takeWhile (%z. z~=v) xs)) = v"
34 lemma map_list_update [simp]:
35 "\<lbrakk> x \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow>
36 (map f xs) [length (takeWhile (\<lambda>z. z \<noteq> x) xs) := v] =
40 apply (case_tac "x=a")
45 (**********************************************************************)
46 (* Product_Type.thy *)
47 (**********************************************************************)
50 lemma split_compose: "(split f) \<circ> (\<lambda> (a,b). ((fa a), (fb b))) =
51 (\<lambda> (a,b). (f (fa a) (fb b)))"
52 by (simp add: split_def o_def)
54 lemma split_iter: "(\<lambda> (a,b,c). ((g1 a), (g2 b), (g3 c))) =
55 (\<lambda> (a,p). ((g1 a), (\<lambda> (b, c). ((g2 b), (g3 c))) p))"
56 by (simp add: split_def o_def)
59 (**********************************************************************)
61 (**********************************************************************)
63 lemma singleton_in_set: "A = {a} \<Longrightarrow> a \<in> A" by simp
65 (**********************************************************************)
67 (**********************************************************************)
69 lemma the_map_upd: "(the \<circ> f(x\<mapsto>v)) = (the \<circ> f)(x:=v)"
70 by (simp add: fun_eq_iff)
73 "(map_of xs x = None) = (x \<notin> set (map fst xs))"
76 lemma map_map_upd [simp]:
77 "y \<notin> set xs \<Longrightarrow> map (the \<circ> f(y\<mapsto>v)) xs = map (the \<circ> f) xs"
78 by (simp add: the_map_upd)
80 lemma map_map_upds [simp]:
81 "(\<forall>y\<in>set ys. y \<notin> set xs) \<Longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) xs = map (the \<circ> f) xs"
82 apply (induct xs arbitrary: f vs)
87 lemma map_upds_distinct [simp]:
88 "distinct ys \<Longrightarrow> length ys = length vs \<Longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) ys = vs"
89 apply (induct ys arbitrary: f vs)
95 lemma map_of_map_as_map_upd:
96 "distinct (map f zs) \<Longrightarrow> map_of (map (\<lambda> p. (f p, g p)) zs) = empty (map f zs [\<mapsto>] map g zs)"
99 (* In analogy to Map.map_of_SomeD *)
100 lemma map_upds_SomeD [rule_format (no_asm)]:
101 "\<forall> m ys. (m(xs[\<mapsto>]ys)) k = Some y \<longrightarrow> k \<in> (set xs) \<or> (m k = Some y)"
109 lemma map_of_upds_SomeD: "(map_of m (xs[\<mapsto>]ys)) k = Some y
110 \<Longrightarrow> k \<in> (set (xs @ map fst m))"
111 by (auto dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma)
114 lemma map_of_map_prop [rule_format (no_asm)]:
115 "(map_of (map f xs) k = Some v) \<longrightarrow>
116 (\<forall> x \<in> set xs. (P1 x)) \<longrightarrow>
117 (\<forall> x. (P1 x) \<longrightarrow> (P2 (f x))) \<longrightarrow>
121 lemma map_of_map2: "\<forall> x \<in> set xs. (fst (f x)) = (fst x) \<Longrightarrow>
122 map_of (map f xs) a = Option.map (\<lambda> b. (snd (f (a, b)))) (map_of xs a)"
125 lemma option_map_of [simp]: "(Option.map f (map_of xs k) = None) = ((map_of xs k) = None)"
126 by (simp add: Option.map_def split: option.split)