src/HOL/MicroJava/Comp/AuxLemmas.thy
author nipkow
Wed, 14 May 2003 10:22:09 +0200
changeset 14025 d9b155757dc8
parent 13673 2950128b8206
child 14402 4201e1916482
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/Comp/AuxLemmas.thy
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     2
    ID:         $Id$
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     3
    Author:     Martin Strecker
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     4
    Copyright   GPL 2002
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     5
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     6
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     7
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     8
(* Auxiliary Lemmas *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     9
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    10
theory AuxLemmas = JBasis:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    11
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    12
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    13
(* List.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    14
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    15
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    16
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    17
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    18
lemma foldr_foldl: "foldr f xs a = foldl (\<lambda> x y. (f y x)) a (rev xs)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    19
by (induct xs, simp, simp)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    20
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    21
lemma foldl_foldr: "foldl f a xs = foldr (\<lambda> x y. (f y x)) (rev xs) a"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    22
by (simp add: foldr_foldl [of "(\<lambda> x y. (f y x))" "(rev xs)"])
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    23
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    24
lemma foldr_append: "foldr f (xs @ ys) a = foldr f xs (foldr f ys a)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    26
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    27
lemma app_nth_len [simp]: "(pre @ a # post) ! length pre = a"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    28
by (induct "pre") auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    29
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    30
lemma app_nth_len_plus [simp]: "(pre @ post) ! ((length pre) + n) = post ! n"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    31
by (induct "pre") auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    32
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    33
lemma app_nth_greater_len [rule_format (no_asm), simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    34
 "\<forall> ind. length pre \<le> ind \<longrightarrow> (pre @ a # post) ! (Suc ind) = (pre @ post) ! ind"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    35
apply (induct "pre")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    36
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    37
apply (case_tac ind)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    38
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    39
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    40
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    41
lemma list_update_length [simp]: "(xs @ a# ys)[length xs := b] = (xs @ b# ys)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    42
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    43
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    44
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    45
lemma length_takeWhile: "v \<in> set xs \<Longrightarrow> length (takeWhile (%z. z~=v) xs) < length xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    46
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    47
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    48
lemma nth_length_takeWhile [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    49
  "v \<in> set xs \<Longrightarrow> xs ! (length (takeWhile (%z. z~=v) xs)) = v"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    50
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    51
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    52
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    53
lemma map_fun_upd [simp]: "y \<notin> set xs \<Longrightarrow> map (f(y:=v)) xs = map f xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    54
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    55
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    56
lemma map_list_update [simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    57
  "\<lbrakk> x \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    58
  (map f xs) [length (takeWhile (\<lambda>z. z \<noteq> x) xs) := v] = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    59
  map (f(x:=v)) xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    60
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    61
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    62
apply (case_tac "x=a")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    63
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    64
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    65
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    66
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    67
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    68
(* Product_Type.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    69
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    70
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    71
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    72
lemma split_compose: "(split f) \<circ> (\<lambda> (a,b). ((fa a), (fb b))) =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    73
  (\<lambda> (a,b). (f (fa a) (fb b)))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    74
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    75
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    76
lemma split_iter: "(\<lambda> (a,b,c). ((g1 a), (g2 b), (g3 c))) = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    77
        (\<lambda> (a,p). ((g1 a), (\<lambda> (b, c). ((g2 b), (g3 c))) p))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    78
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    79
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    80
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    81
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    82
(* Set.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    83
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    84
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    85
lemma singleton_in_set: "A = {a} \<Longrightarrow> a \<in> A" by simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    86
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    87
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    88
(* Map.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    89
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    90
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    91
lemma the_map_upd: "(the \<circ> f(x\<mapsto>v)) = (the \<circ> f)(x:=v)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    92
by (simp add: expand_fun_eq)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    93
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    94
lemma map_of_in_set: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    95
  "(map_of xs x = None) = (x \<notin> set (map fst xs))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    96
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    97
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    98
lemma map_map_upd [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    99
  "y \<notin> set xs \<Longrightarrow> map (the \<circ> f(y\<mapsto>v)) xs = map (the \<circ> f) xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   100
by (simp add: the_map_upd)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   101
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   102
lemma map_map_upds [rule_format (no_asm), simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   103
"\<forall> f vs. (\<forall>y\<in>set ys. y \<notin> set xs) \<longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) xs = map (the \<circ> f) xs"
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   104
apply (induct xs)
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   105
 apply simp
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   106
apply fastsimp
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   107
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   108
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   109
lemma map_upds_distinct [rule_format (no_asm), simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   110
  "\<forall> f vs. length ys = length vs \<longrightarrow> distinct ys \<longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) ys = vs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   111
apply (induct ys)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   112
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   113
apply (intro strip)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   114
apply (case_tac vs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   115
apply simp
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   116
apply (simp only: map_upds_Cons distinct.simps hd.simps tl.simps map.simps)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   117
apply clarify
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   118
apply (simp del: o_apply)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   119
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   120
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   121
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   122
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   123
lemma map_of_map_as_map_upd [rule_format (no_asm)]: "distinct (map f zs) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   124
map_of (map (\<lambda> p. (f p, g p)) zs) = empty (map f zs [\<mapsto>] map g zs)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   125
by (induct zs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   126
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   127
(* In analogy to Map.map_of_SomeD *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   128
lemma map_upds_SomeD [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   129
  "\<forall> m ys. (m(xs[\<mapsto>]ys)) k = Some y \<longrightarrow> k \<in> (set xs) \<or> (m k = Some y)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   130
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   131
apply simp
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   132
apply auto
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   133
apply(case_tac ys)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   134
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   135
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   136
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   137
lemma map_of_upds_SomeD: "(map_of m (xs[\<mapsto>]ys)) k = Some y 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   138
  \<Longrightarrow> k \<in> (set (xs @ map fst m))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   139
by (auto dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   140
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   141
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   142
lemma map_of_map_prop [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   143
  "(map_of (map f xs) k = Some v) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   144
  (\<forall> x \<in> set xs. (P1 x)) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   145
  (\<forall> x. (P1 x) \<longrightarrow> (P2 (f x))) \<longrightarrow>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   146
  (P2(k, v))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   147
by (induct xs,auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   148
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   149
lemma map_of_map2: "\<forall> x \<in> set xs. (fst (f x)) = (fst x) \<Longrightarrow>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   150
  map_of (map f xs) a = option_map (\<lambda> b. (snd (f (a, b)))) (map_of xs a)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   151
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   152
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   153
lemma option_map_of [simp]: "(option_map f (map_of xs k) = None) = ((map_of xs k) = None)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   154
by (simp add: option_map_def split: option.split)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   155
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   156
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   157
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   158
end