src/HOL/MicroJava/Comp/AuxLemmas.thy
author hoelzl
Mon, 03 Dec 2012 18:19:08 +0100
changeset 50328 25b1e8686ce0
parent 44890 22f665a2e91c
child 52866 438f578ef1d9
permissions -rw-r--r--
tuned proof
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
    Author:     Martin Strecker
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     3
*)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     4
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     5
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     6
(* Auxiliary Lemmas *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     7
15860
a344c4284972 partial modernising of theory headers
paulson
parents: 14981
diff changeset
     8
theory AuxLemmas
a344c4284972 partial modernising of theory headers
paulson
parents: 14981
diff changeset
     9
imports "../J/JBasis"
a344c4284972 partial modernising of theory headers
paulson
parents: 14981
diff changeset
    10
begin
13673
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 app_nth_greater_len [rule_format (no_asm), simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    19
 "\<forall> ind. length pre \<le> ind \<longrightarrow> (pre @ a # post) ! (Suc ind) = (pre @ post) ! ind"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    20
apply (induct "pre")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    21
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    22
apply (case_tac ind)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    23
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    24
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    26
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
    27
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    28
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    29
lemma nth_length_takeWhile [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    30
  "v \<in> set xs \<Longrightarrow> xs ! (length (takeWhile (%z. z~=v) xs)) = v"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    31
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    32
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    33
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    34
lemma map_list_update [simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    35
  "\<lbrakk> x \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    36
  (map f xs) [length (takeWhile (\<lambda>z. z \<noteq> x) xs) := v] = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    37
  map (f(x:=v)) xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    38
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    39
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    40
apply (case_tac "x=a")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    41
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    42
done
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
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    46
(* Product_Type.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    47
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    48
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    49
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    50
lemma split_compose: "(split f) \<circ> (\<lambda> (a,b). ((fa a), (fb b))) =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    51
  (\<lambda> (a,b). (f (fa a) (fb b)))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    52
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    53
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    54
lemma split_iter: "(\<lambda> (a,b,c). ((g1 a), (g2 b), (g3 c))) = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    55
        (\<lambda> (a,p). ((g1 a), (\<lambda> (b, c). ((g2 b), (g3 c))) p))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    56
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    57
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    58
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    59
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    60
(* Set.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    61
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    62
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    63
lemma singleton_in_set: "A = {a} \<Longrightarrow> a \<in> A" by simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    64
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    65
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    66
(* Map.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    67
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    68
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    69
lemma the_map_upd: "(the \<circ> f(x\<mapsto>v)) = (the \<circ> f)(x:=v)"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    70
by (simp add: fun_eq_iff)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    71
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    72
lemma map_of_in_set: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    73
  "(map_of xs x = None) = (x \<notin> set (map fst xs))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    74
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    75
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    76
lemma map_map_upd [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    77
  "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
    78
by (simp add: the_map_upd)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    79
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    80
lemma map_map_upds [simp]: 
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    81
  "(\<forall>y\<in>set ys. y \<notin> set xs) \<Longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) xs = map (the \<circ> f) xs"
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    82
apply (induct xs arbitrary: f vs)
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
    83
 apply simp
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 39976
diff changeset
    84
apply fastforce
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    85
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    86
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    87
lemma map_upds_distinct [simp]: 
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    88
  "distinct ys \<Longrightarrow> length ys = length vs \<Longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) ys = vs"
39976
2474347538b8 simplified proof
nipkow
parents: 39917
diff changeset
    89
apply (induct ys arbitrary: f vs)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    90
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    91
apply (case_tac vs)
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    92
apply simp_all
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    93
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    94
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    95
lemma map_of_map_as_map_upd:
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    96
  "distinct (map f zs) \<Longrightarrow> map_of (map (\<lambda> p. (f p, g p)) zs) = empty (map f zs [\<mapsto>] map g zs)"
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    97
  by (induct zs) auto
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    98
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    99
(* In analogy to Map.map_of_SomeD *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   100
lemma map_upds_SomeD [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   101
  "\<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
   102
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   103
apply simp
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   104
apply auto
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   105
apply(case_tac ys)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   106
apply auto
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_of_upds_SomeD: "(map_of m (xs[\<mapsto>]ys)) k = Some y 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   110
  \<Longrightarrow> k \<in> (set (xs @ map fst m))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   111
by (auto dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   112
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   113
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   114
lemma map_of_map_prop [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   115
  "(map_of (map f xs) k = Some v) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   116
  (\<forall> x \<in> set xs. (P1 x)) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   117
  (\<forall> x. (P1 x) \<longrightarrow> (P2 (f x))) \<longrightarrow>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   118
  (P2(k, v))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   119
by (induct xs,auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   120
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   121
lemma map_of_map2: "\<forall> x \<in> set xs. (fst (f x)) = (fst x) \<Longrightarrow>
30235
58d147683393 Made Option a separate theory and renamed option_map to Option.map
nipkow
parents: 15860
diff changeset
   122
  map_of (map f xs) a = Option.map (\<lambda> b. (snd (f (a, b)))) (map_of xs a)"
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   123
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   124
30235
58d147683393 Made Option a separate theory and renamed option_map to Option.map
nipkow
parents: 15860
diff changeset
   125
lemma option_map_of [simp]: "(Option.map f (map_of xs k) = None) = ((map_of xs k) = None)"
58d147683393 Made Option a separate theory and renamed option_map to Option.map
nipkow
parents: 15860
diff changeset
   126
by (simp add: Option.map_def split: option.split)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   127
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   128
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   129
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   130
end