| 
13062
 | 
     1  | 
(*  Title:      HOL/MicroJava/BV/SemilatAlg.thy
  | 
| 
 | 
     2  | 
    ID:         $Id$
  | 
| 
 | 
     3  | 
    Author:     Gerwin Klein
  | 
| 
 | 
     4  | 
    Copyright   2002 Technische Universitaet Muenchen
  | 
| 
 | 
     5  | 
*)
  | 
| 
 | 
     6  | 
  | 
| 
 | 
     7  | 
header {* \isaheader{More on Semilattices} *}
 | 
| 
 | 
     8  | 
  | 
| 
27681
 | 
     9  | 
theory SemilatAlg
  | 
| 
 | 
    10  | 
imports Typing_Framework Product
  | 
| 
 | 
    11  | 
begin
  | 
| 
13062
 | 
    12  | 
  | 
| 
 | 
    13  | 
  | 
| 
13066
 | 
    14  | 
constdefs 
  | 
| 
 | 
    15  | 
  lesubstep_type :: "(nat \<times> 's) list \<Rightarrow> 's ord \<Rightarrow> (nat \<times> 's) list \<Rightarrow> bool"
  | 
| 
 | 
    16  | 
                    ("(_ /<=|_| _)" [50, 0, 51] 50)
 | 
| 
 | 
    17  | 
  "x <=|r| y \<equiv> \<forall>(p,s) \<in> set x. \<exists>s'. (p,s') \<in> set y \<and> s <=_r s'"
  | 
| 
 | 
    18  | 
  | 
| 
13062
 | 
    19  | 
consts
  | 
| 
 | 
    20  | 
 "@plusplussub" :: "'a list \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a" ("(_ /++'__ _)" [65, 1000, 66] 65)
 | 
| 
 | 
    21  | 
primrec
  | 
| 
 | 
    22  | 
  "[] ++_f y = y"
  | 
| 
 | 
    23  | 
  "(x#xs) ++_f y = xs ++_f (x +_f y)"
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
constdefs
  | 
| 
 | 
    26  | 
 bounded :: "'s step_type \<Rightarrow> nat \<Rightarrow> bool"
  | 
| 
 | 
    27  | 
"bounded step n == !p<n. !s. !(q,t):set(step p s). q<n"  
  | 
| 
 | 
    28  | 
  | 
| 
 | 
    29  | 
 pres_type :: "'s step_type \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
  | 
| 
 | 
    30  | 
"pres_type step n A == \<forall>s\<in>A. \<forall>p<n. \<forall>(q,s')\<in>set (step p s). s' \<in> A"
  | 
| 
 | 
    31  | 
  | 
| 
 | 
    32  | 
 mono :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
  | 
| 
 | 
    33  | 
"mono r step n A ==
  | 
| 
 | 
    34  | 
 \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> step p s <=|r| step p t"
  | 
| 
 | 
    35  | 
  | 
| 
 | 
    36  | 
  | 
| 
 | 
    37  | 
lemma pres_typeD:
  | 
| 
 | 
    38  | 
  "\<lbrakk> pres_type step n A; s\<in>A; p<n; (q,s')\<in>set (step p s) \<rbrakk> \<Longrightarrow> s' \<in> A"
  | 
| 
 | 
    39  | 
  by (unfold pres_type_def, blast)
  | 
| 
 | 
    40  | 
  | 
| 
 | 
    41  | 
lemma monoD:
  | 
| 
 | 
    42  | 
  "\<lbrakk> mono r step n A; p < n; s\<in>A; s <=_r t \<rbrakk> \<Longrightarrow> step p s <=|r| step p t"
  | 
| 
 | 
    43  | 
  by (unfold mono_def, blast)
  | 
| 
 | 
    44  | 
  | 
| 
 | 
    45  | 
lemma boundedD: 
  | 
| 
 | 
    46  | 
  "\<lbrakk> bounded step n; p < n; (q,t) : set (step p xs) \<rbrakk> \<Longrightarrow> q < n" 
  | 
| 
 | 
    47  | 
  by (unfold bounded_def, blast)
  | 
| 
 | 
    48  | 
  | 
| 
13066
 | 
    49  | 
lemma lesubstep_type_refl [simp, intro]:
  | 
| 
 | 
    50  | 
  "(\<And>x. x <=_r x) \<Longrightarrow> x <=|r| x"
  | 
| 
 | 
    51  | 
  by (unfold lesubstep_type_def) auto
  | 
| 
 | 
    52  | 
  | 
| 
 | 
    53  | 
lemma lesub_step_typeD:
  | 
| 
 | 
    54  | 
  "a <=|r| b \<Longrightarrow> (x,y) \<in> set a \<Longrightarrow> \<exists>y'. (x, y') \<in> set b \<and> y <=_r y'"
  | 
| 
 | 
    55  | 
  by (unfold lesubstep_type_def) blast
  | 
| 
 | 
    56  | 
  | 
| 
13062
 | 
    57  | 
  | 
| 
 | 
    58  | 
lemma list_update_le_listI [rule_format]:
  | 
| 
 | 
    59  | 
  "set xs <= A \<longrightarrow> set ys <= A \<longrightarrow> xs <=[r] ys \<longrightarrow> p < size xs \<longrightarrow>  
  | 
| 
 | 
    60  | 
   x <=_r ys!p \<longrightarrow> semilat(A,r,f) \<longrightarrow> x\<in>A \<longrightarrow> 
  | 
| 
 | 
    61  | 
   xs[p := x +_f xs!p] <=[r] ys"
  | 
| 
 | 
    62  | 
  apply (unfold Listn.le_def lesub_def semilat_def)
  | 
| 
 | 
    63  | 
  apply (simp add: list_all2_conv_all_nth nth_list_update)
  | 
| 
 | 
    64  | 
  done
  | 
| 
 | 
    65  | 
  | 
| 
 | 
    66  | 
  | 
| 
27611
 | 
    67  | 
lemma plusplus_closed: assumes "semilat (A, r, f)" shows
  | 
| 
 | 
    68  | 
  "\<And>y. \<lbrakk> set x \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> x ++_f y \<in> A" (is "PROP ?P")
  | 
| 
 | 
    69  | 
proof -
  | 
| 
29235
 | 
    70  | 
  interpret Semilat A r f using assms by (rule Semilat.intro)
  | 
| 
27611
 | 
    71  | 
  show "PROP ?P" proof (induct x)
  | 
| 
 | 
    72  | 
    show "\<And>y. y \<in> A \<Longrightarrow> [] ++_f y \<in> A" by simp
  | 
| 
 | 
    73  | 
    fix y x xs
  | 
| 
 | 
    74  | 
    assume y: "y \<in> A" and xs: "set (x#xs) \<subseteq> A"
  | 
| 
 | 
    75  | 
    assume IH: "\<And>y. \<lbrakk> set xs \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> xs ++_f y \<in> A"
  | 
| 
 | 
    76  | 
    from xs obtain x: "x \<in> A" and xs': "set xs \<subseteq> A" by simp
  | 
| 
 | 
    77  | 
    from x y have "(x +_f y) \<in> A" ..
  | 
| 
 | 
    78  | 
    with xs' have "xs ++_f (x +_f y) \<in> A" by (rule IH)
  | 
| 
 | 
    79  | 
    thus "(x#xs) ++_f y \<in> A" by simp
  | 
| 
 | 
    80  | 
  qed
  | 
| 
13062
 | 
    81  | 
qed
  | 
| 
 | 
    82  | 
  | 
| 
27681
 | 
    83  | 
lemma (in Semilat) pp_ub2:
  | 
| 
13074
 | 
    84  | 
 "\<And>y. \<lbrakk> set x \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> y <=_r x ++_f y"
  | 
| 
13062
 | 
    85  | 
proof (induct x)
  | 
| 
13074
 | 
    86  | 
  from semilat show "\<And>y. y <=_r [] ++_f y" by simp
  | 
| 
13062
 | 
    87  | 
  
  | 
| 
 | 
    88  | 
  fix y a l
  | 
| 
 | 
    89  | 
  assume y:  "y \<in> A"
  | 
| 
 | 
    90  | 
  assume "set (a#l) \<subseteq> A"
  | 
| 
13074
 | 
    91  | 
  then obtain a: "a \<in> A" and x: "set l \<subseteq> A" by simp
  | 
| 
 | 
    92  | 
  assume "\<And>y. \<lbrakk>set l \<subseteq> A; y \<in> A\<rbrakk> \<Longrightarrow> y <=_r l ++_f y"
  | 
| 
23464
 | 
    93  | 
  hence IH: "\<And>y. y \<in> A \<Longrightarrow> y <=_r l ++_f y" using x .
  | 
| 
13062
 | 
    94  | 
  | 
| 
13077
 | 
    95  | 
  from a y have "y <=_r a +_f y" ..
  | 
| 
 | 
    96  | 
  also from a y have "a +_f y \<in> A" ..
  | 
| 
13062
 | 
    97  | 
  hence "(a +_f y) <=_r l ++_f (a +_f y)" by (rule IH)
  | 
| 
13074
 | 
    98  | 
  finally have "y <=_r l ++_f (a +_f y)" .
  | 
| 
13062
 | 
    99  | 
  thus "y <=_r (a#l) ++_f y" by simp
  | 
| 
 | 
   100  | 
qed
  | 
| 
 | 
   101  | 
  | 
| 
 | 
   102  | 
  | 
| 
27681
 | 
   103  | 
lemma (in Semilat) pp_ub1:
  | 
| 
13074
 | 
   104  | 
shows "\<And>y. \<lbrakk>set ls \<subseteq> A; y \<in> A; x \<in> set ls\<rbrakk> \<Longrightarrow> x <=_r ls ++_f y"
  | 
| 
13062
 | 
   105  | 
proof (induct ls)
  | 
| 
 | 
   106  | 
  show "\<And>y. x \<in> set [] \<Longrightarrow> x <=_r [] ++_f y" by simp
  | 
| 
13074
 | 
   107  | 
  | 
| 
13062
 | 
   108  | 
  fix y s ls
  | 
| 
 | 
   109  | 
  assume "set (s#ls) \<subseteq> A"
  | 
| 
 | 
   110  | 
  then obtain s: "s \<in> A" and ls: "set ls \<subseteq> A" by simp
  | 
| 
 | 
   111  | 
  assume y: "y \<in> A" 
  | 
| 
 | 
   112  | 
  | 
| 
 | 
   113  | 
  assume 
  | 
| 
13074
 | 
   114  | 
    "\<And>y. \<lbrakk>set ls \<subseteq> A; y \<in> A; x \<in> set ls\<rbrakk> \<Longrightarrow> x <=_r ls ++_f y"
  | 
| 
23464
 | 
   115  | 
  hence IH: "\<And>y. x \<in> set ls \<Longrightarrow> y \<in> A \<Longrightarrow> x <=_r ls ++_f y" using ls .
  | 
| 
13062
 | 
   116  | 
  | 
| 
 | 
   117  | 
  assume "x \<in> set (s#ls)"
  | 
| 
 | 
   118  | 
  then obtain xls: "x = s \<or> x \<in> set ls" by simp
  | 
| 
 | 
   119  | 
  moreover {
 | 
| 
 | 
   120  | 
    assume xs: "x = s"
  | 
| 
13077
 | 
   121  | 
    from s y have "s <=_r s +_f y" ..
  | 
| 
 | 
   122  | 
    also from s y have "s +_f y \<in> A" ..
  | 
| 
13074
 | 
   123  | 
    with ls have "(s +_f y) <=_r ls ++_f (s +_f y)" by (rule pp_ub2)
  | 
| 
 | 
   124  | 
    finally have "s <=_r ls ++_f (s +_f y)" .
  | 
| 
13062
 | 
   125  | 
    with xs have "x <=_r ls ++_f (s +_f y)" by simp
  | 
| 
 | 
   126  | 
  } 
  | 
| 
 | 
   127  | 
  moreover {
 | 
| 
 | 
   128  | 
    assume "x \<in> set ls"
  | 
| 
 | 
   129  | 
    hence "\<And>y. y \<in> A \<Longrightarrow> x <=_r ls ++_f y" by (rule IH)
  | 
| 
13077
 | 
   130  | 
    moreover from s y have "s +_f y \<in> A" ..
  | 
| 
13074
 | 
   131  | 
    ultimately have "x <=_r ls ++_f (s +_f y)" .
  | 
| 
13062
 | 
   132  | 
  }
  | 
| 
 | 
   133  | 
  ultimately 
  | 
| 
 | 
   134  | 
  have "x <=_r ls ++_f (s +_f y)" by blast
  | 
| 
 | 
   135  | 
  thus "x <=_r (s#ls) ++_f y" by simp
  | 
| 
 | 
   136  | 
qed
  | 
| 
 | 
   137  | 
  | 
| 
 | 
   138  | 
  | 
| 
27681
 | 
   139  | 
lemma (in Semilat) pp_lub:
  | 
| 
23464
 | 
   140  | 
  assumes z: "z \<in> A"
  | 
| 
13069
 | 
   141  | 
  shows 
  | 
| 
 | 
   142  | 
  "\<And>y. y \<in> A \<Longrightarrow> set xs \<subseteq> A \<Longrightarrow> \<forall>x \<in> set xs. x <=_r z \<Longrightarrow> y <=_r z \<Longrightarrow> xs ++_f y <=_r z"
  | 
| 
 | 
   143  | 
proof (induct xs)
  | 
| 
 | 
   144  | 
  fix y assume "y <=_r z" thus "[] ++_f y <=_r z" by simp
  | 
| 
 | 
   145  | 
next
  | 
| 
 | 
   146  | 
  fix y l ls assume y: "y \<in> A" and "set (l#ls) \<subseteq> A"
  | 
| 
 | 
   147  | 
  then obtain l: "l \<in> A" and ls: "set ls \<subseteq> A" by auto
  | 
| 
 | 
   148  | 
  assume "\<forall>x \<in> set (l#ls). x <=_r z"
  | 
| 
23464
 | 
   149  | 
  then obtain lz: "l <=_r z" and lsz: "\<forall>x \<in> set ls. x <=_r z" by auto
  | 
| 
 | 
   150  | 
  assume "y <=_r z" with lz have "l +_f y <=_r z" using l y z ..
  | 
| 
13069
 | 
   151  | 
  moreover
  | 
| 
13077
 | 
   152  | 
  from l y have "l +_f y \<in> A" ..
  | 
| 
13069
 | 
   153  | 
  moreover
  | 
| 
 | 
   154  | 
  assume "\<And>y. y \<in> A \<Longrightarrow> set ls \<subseteq> A \<Longrightarrow> \<forall>x \<in> set ls. x <=_r z \<Longrightarrow> y <=_r z
  | 
| 
 | 
   155  | 
          \<Longrightarrow> ls ++_f y <=_r z"
  | 
| 
 | 
   156  | 
  ultimately
  | 
| 
13077
 | 
   157  | 
  have "ls ++_f (l +_f y) <=_r z" using ls lsz by -
  | 
| 
13069
 | 
   158  | 
  thus "(l#ls) ++_f y <=_r z" by simp
  | 
| 
 | 
   159  | 
qed
  | 
| 
 | 
   160  | 
  | 
| 
 | 
   161  | 
  | 
| 
27611
 | 
   162  | 
lemma ub1':
  | 
| 
 | 
   163  | 
  assumes "semilat (A, r, f)"
  | 
| 
 | 
   164  | 
  shows "\<lbrakk>\<forall>(p,s) \<in> set S. s \<in> A; y \<in> A; (a,b) \<in> set S\<rbrakk> 
  | 
| 
23281
 | 
   165  | 
  \<Longrightarrow> b <=_r map snd [(p', t')\<leftarrow>S. p' = a] ++_f y" 
  | 
| 
13062
 | 
   166  | 
proof -
  | 
| 
29235
 | 
   167  | 
  interpret Semilat A r f using assms by (rule Semilat.intro)
  | 
| 
27611
 | 
   168  | 
  | 
| 
13062
 | 
   169  | 
  let "b <=_r ?map ++_f y" = ?thesis
  | 
| 
 | 
   170  | 
  | 
| 
13074
 | 
   171  | 
  assume "y \<in> A"
  | 
| 
13062
 | 
   172  | 
  moreover
  | 
| 
 | 
   173  | 
  assume "\<forall>(p,s) \<in> set S. s \<in> A"
  | 
| 
 | 
   174  | 
  hence "set ?map \<subseteq> A" by auto
  | 
| 
 | 
   175  | 
  moreover
  | 
| 
 | 
   176  | 
  assume "(a,b) \<in> set S"
  | 
| 
 | 
   177  | 
  hence "b \<in> set ?map" by (induct S, auto)
  | 
| 
 | 
   178  | 
  ultimately
  | 
| 
13074
 | 
   179  | 
  show ?thesis by - (rule pp_ub1)
  | 
| 
13062
 | 
   180  | 
qed
  | 
| 
 | 
   181  | 
    
  | 
| 
 | 
   182  | 
  | 
| 
 | 
   183  | 
lemma plusplus_empty:  
  | 
| 
 | 
   184  | 
  "\<forall>s'. (q, s') \<in> set S \<longrightarrow> s' +_f ss ! q = ss ! q \<Longrightarrow>
  | 
| 
23281
 | 
   185  | 
   (map snd [(p', t') \<leftarrow> S. p' = q] ++_f ss ! q) = ss ! q"
  | 
| 
23464
 | 
   186  | 
  by (induct S) auto 
  | 
| 
13062
 | 
   187  | 
  | 
| 
 | 
   188  | 
end
  |