src/HOL/MicroJava/Comp/AuxLemmas.thy
author ballarin
Mon, 02 Aug 2004 10:15:37 +0200
changeset 15097 b807858b97bd
parent 14981 e73f8140af78
child 15860 a344c4284972
permissions -rw-r--r--
Modifications for trancl_tac (new solver in simplifier).
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
*)
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
(* Auxiliary Lemmas *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     8
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
     9
theory AuxLemmas = JBasis:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    10
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    11
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    12
(* List.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    13
(**********************************************************************)
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
lemma app_nth_greater_len [rule_format (no_asm), simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    18
 "\<forall> ind. length pre \<le> ind \<longrightarrow> (pre @ a # post) ! (Suc ind) = (pre @ post) ! ind"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    19
apply (induct "pre")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    20
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    21
apply (case_tac ind)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    22
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    23
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    24
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    25
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
    26
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    27
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    28
lemma nth_length_takeWhile [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    29
  "v \<in> set xs \<Longrightarrow> xs ! (length (takeWhile (%z. z~=v) xs)) = v"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    30
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    31
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    32
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    33
lemma map_list_update [simp]:
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    34
  "\<lbrakk> x \<in> set xs; distinct xs\<rbrakk> \<Longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    35
  (map f xs) [length (takeWhile (\<lambda>z. z \<noteq> x) xs) := v] = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    36
  map (f(x:=v)) xs"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    37
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    38
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    39
apply (case_tac "x=a")
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    40
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    41
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    42
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
(* Product_Type.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    46
(**********************************************************************)
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
lemma split_compose: "(split f) \<circ> (\<lambda> (a,b). ((fa a), (fb b))) =
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    50
  (\<lambda> (a,b). (f (fa a) (fb b)))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    51
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    52
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    53
lemma split_iter: "(\<lambda> (a,b,c). ((g1 a), (g2 b), (g3 c))) = 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    54
        (\<lambda> (a,p). ((g1 a), (\<lambda> (b, c). ((g2 b), (g3 c))) p))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    55
by (simp add: split_def o_def)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    56
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
(* Set.thy *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    60
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    61
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    62
lemma singleton_in_set: "A = {a} \<Longrightarrow> a \<in> A" by simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    63
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    64
(**********************************************************************)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    65
(* Map.thy *)
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
lemma the_map_upd: "(the \<circ> f(x\<mapsto>v)) = (the \<circ> f)(x:=v)"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    69
by (simp add: expand_fun_eq)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    70
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    71
lemma map_of_in_set: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    72
  "(map_of xs x = None) = (x \<notin> set (map fst xs))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    73
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    74
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    75
lemma map_map_upd [simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    76
  "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
    77
by (simp add: the_map_upd)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    78
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    79
lemma map_map_upds [rule_format (no_asm), simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    80
"\<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
    81
apply (induct xs)
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
    82
 apply simp
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
    83
apply fastsimp
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    84
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    85
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    86
lemma map_upds_distinct [rule_format (no_asm), simp]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    87
  "\<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
    88
apply (induct ys)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    89
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    90
apply (intro strip)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    91
apply (case_tac vs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    92
apply simp
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
    93
apply (simp only: map_upds_Cons distinct.simps hd.simps tl.simps map.simps)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    94
apply clarify
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
    95
apply (simp del: o_apply)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    96
apply simp
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    97
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    98
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
    99
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   100
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
   101
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
   102
by (induct zs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   103
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   104
(* In analogy to Map.map_of_SomeD *)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   105
lemma map_upds_SomeD [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   106
  "\<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
   107
apply (induct xs)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   108
apply simp
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   109
apply auto
d9b155757dc8 *** empty log message ***
nipkow
parents: 13673
diff changeset
   110
apply(case_tac ys)
13673
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   111
apply auto
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   112
done
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   113
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   114
lemma map_of_upds_SomeD: "(map_of m (xs[\<mapsto>]ys)) k = Some y 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   115
  \<Longrightarrow> k \<in> (set (xs @ map fst m))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   116
by (auto dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   117
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   118
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   119
lemma map_of_map_prop [rule_format (no_asm)]: 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   120
  "(map_of (map f xs) k = Some v) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   121
  (\<forall> x \<in> set xs. (P1 x)) \<longrightarrow> 
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   122
  (\<forall> x. (P1 x) \<longrightarrow> (P2 (f x))) \<longrightarrow>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   123
  (P2(k, v))"
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   124
by (induct xs,auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   125
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   126
lemma map_of_map2: "\<forall> x \<in> set xs. (fst (f x)) = (fst x) \<Longrightarrow>
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   127
  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
   128
by (induct xs, auto)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   129
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   130
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
   131
by (simp add: option_map_def split: option.split)
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   132
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   133
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   134
2950128b8206 First checkin of compiler
streckem
parents:
diff changeset
   135
end