src/HOL/MicroJava/Comp/AuxLemmas.thy
author nipkow
Mon, 12 Sep 2011 07:55:43 +0200
changeset 45761 22f665a2e91c
parent 40157 2474347538b8
child 54003 438f578ef1d9
permissions -rw-r--r--
new fastforce replacing fastsimp - less confusing name
     1 (*  Title:      HOL/MicroJava/Comp/AuxLemmas.thy
     2     Author:     Martin Strecker
     3 *)
     4 
     5 
     6 (* Auxiliary Lemmas *)
     7 
     8 theory AuxLemmas
     9 imports "../J/JBasis"
    10 begin
    11 
    12 (**********************************************************************)
    13 (* List.thy *)
    14 (**********************************************************************)
    15 
    16 
    17 
    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"
    20 apply (induct "pre")
    21 apply auto
    22 apply (case_tac ind)
    23 apply auto
    24 done
    25 
    26 lemma length_takeWhile: "v \<in> set xs \<Longrightarrow> length (takeWhile (%z. z~=v) xs) < length xs"
    27 by (induct xs, auto)
    28 
    29 lemma nth_length_takeWhile [simp]: 
    30   "v \<in> set xs \<Longrightarrow> xs ! (length (takeWhile (%z. z~=v) xs)) = v"
    31 by (induct xs, auto)
    32 
    33 
    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] = 
    37   map (f(x:=v)) xs"
    38 apply (induct xs)
    39 apply simp
    40 apply (case_tac "x=a")
    41 apply auto
    42 done
    43 
    44 
    45 (**********************************************************************)
    46 (* Product_Type.thy *)
    47 (**********************************************************************)
    48 
    49 
    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)
    53 
    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)
    57 
    58 
    59 (**********************************************************************)
    60 (* Set.thy *)
    61 (**********************************************************************)
    62 
    63 lemma singleton_in_set: "A = {a} \<Longrightarrow> a \<in> A" by simp
    64 
    65 (**********************************************************************)
    66 (* Map.thy *)
    67 (**********************************************************************)
    68 
    69 lemma the_map_upd: "(the \<circ> f(x\<mapsto>v)) = (the \<circ> f)(x:=v)"
    70 by (simp add: fun_eq_iff)
    71 
    72 lemma map_of_in_set: 
    73   "(map_of xs x = None) = (x \<notin> set (map fst xs))"
    74 by (induct xs, auto)
    75 
    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)
    79 
    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)
    83  apply simp
    84 apply fastforce
    85 done
    86 
    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)
    90 apply simp
    91 apply (case_tac vs)
    92 apply simp_all
    93 done
    94 
    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)"
    97   by (induct zs) auto
    98 
    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)"
   102 apply (induct xs)
   103 apply simp
   104 apply auto
   105 apply(case_tac ys)
   106 apply auto
   107 done
   108 
   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)
   112 
   113 
   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>
   118   (P2(k, v))"
   119 by (induct xs,auto)
   120 
   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)"
   123 by (induct xs, auto)
   124 
   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)
   127 
   128 
   129 
   130 end