src/HOL/MicroJava/Comp/AuxLemmas.thy
author kleing
Thu, 28 May 2015 17:25:57 +1000
changeset 60304 3f429b7d8eb5
parent 55466 786edc984c98
child 61424 c3658c18b7bc
permissions -rw-r--r--
modernized (slightly) type compiler in MicroJava
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
52866
438f578ef1d9 tuned proofs;
wenzelm
parents: 44890
diff changeset
    18
lemma app_nth_greater_len [simp]:
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    19
  "length pre \<le> ind \<Longrightarrow> (pre @ a # post) ! (Suc ind) = (pre @ post) ! ind"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    20
  apply (induct pre arbitrary: ind)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    21
   apply clarsimp
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    22
  apply (case_tac ind)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    23
   apply auto
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    24
  done
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    26
lemma length_takeWhile: "v \<in> set xs \<Longrightarrow> length (takeWhile (\<lambda>z. z \<noteq> v) xs) < length xs"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    27
  by (induct xs) auto
13673
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"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    31
  by (induct xs) auto
13673
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> 
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    36
  (map f xs) [length (takeWhile (\<lambda>z. z \<noteq> x) xs) := v] = map (f(x:=v)) xs"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    37
  apply (induct xs)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    38
   apply simp
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    39
  apply (rename_tac a xs)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    40
  apply (case_tac "x=a")
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    41
   apply auto
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    42
  done
13673
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
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    50
lemma split_compose: 
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    51
  "(split f) \<circ> (\<lambda> (a,b). ((fa a), (fb b))) = (\<lambda> (a,b). (f (fa a) (fb b)))"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    52
  by (simp add: split_def o_def)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    53
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    54
lemma split_iter:
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    55
  "(\<lambda> (a,b,c). ((g1 a), (g2 b), (g3 c))) = (\<lambda> (a,p). ((g1 a), (\<lambda> (b, c). ((g2 b), (g3 c))) p))"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    56
  by (simp add: split_def o_def)
13673
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)"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
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))"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    74
  by (induct xs, auto)
13673
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"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    78
  by (simp add: the_map_upd)
13673
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"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    82
  by (induct xs arbitrary: f vs) auto
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    83
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    84
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
    85
  "distinct ys \<Longrightarrow> length ys = length vs \<Longrightarrow> map (the \<circ> f(ys[\<mapsto>]vs)) ys = vs"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    86
  apply (induct ys arbitrary: f vs)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    87
   apply simp
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    88
  apply (case_tac vs)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    89
   apply simp_all
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    90
  done
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    91
39917
b85bfa89a387 turned distinct and sorted into inductive predicates: yields nice induction principles for free; more elegant proofs
haftmann
parents: 39302
diff changeset
    92
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
    93
  "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
    94
  by (induct zs) auto
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    95
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    96
(* In analogy to Map.map_of_SomeD *)
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    97
lemma map_upds_SomeD: 
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    98
  "(m(xs[\<mapsto>]ys)) k = Some y \<Longrightarrow> k \<in> (set xs) \<or> (m k = Some y)"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
    99
  apply (induct xs arbitrary: m ys)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   100
   apply simp
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   101
  apply (case_tac ys)
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   102
   apply fastforce+
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   103
  done
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   104
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   105
lemma map_of_upds_SomeD: "(map_of m (xs[\<mapsto>]ys)) k = Some y 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   106
  \<Longrightarrow> k \<in> (set (xs @ map fst m))"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   107
  by (auto dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   108
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   109
lemma map_of_map_prop:
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   110
  "\<lbrakk>map_of (map f xs) k = Some v; \<forall>x \<in> set xs. P1 x; \<forall>x. P1 x \<longrightarrow> P2 (f x)\<rbrakk> \<Longrightarrow> P2 (k, v)"
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   111
  by (induct xs) (auto split: split_if_asm)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   112
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   113
lemma map_of_map2: "\<forall>x \<in> set xs. (fst (f x)) = (fst x) \<Longrightarrow>
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 52866
diff changeset
   114
  map_of (map f xs) a = map_option (\<lambda> b. (snd (f (a, b)))) (map_of xs a)"
60304
3f429b7d8eb5 modernized (slightly) type compiler in MicroJava
kleing
parents: 55466
diff changeset
   115
  by (induct xs, auto)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   116
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   117
end