src/HOL/MicroJava/BV/Semilat.thy
author kleing
Wed, 20 Mar 2002 13:21:07 +0100
changeset 13062 4b1edf2f6bd2
parent 13006 51c5f3f11d16
child 13068 472b1c91b09f
permissions -rw-r--r--
small refactoring for lbv with semilattices
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents: 11175
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Semilat.thy
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     2
    ID:         $Id$
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     3
    Author:     Tobias Nipkow
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     4
    Copyright   2000 TUM
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     5
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     6
Semilattices
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     7
*)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     8
12911
704713ca07ea new document
kleing
parents: 12773
diff changeset
     9
header {* 
704713ca07ea new document
kleing
parents: 12773
diff changeset
    10
  \chapter{Bytecode Verifier}\label{cha:bv}
704713ca07ea new document
kleing
parents: 12773
diff changeset
    11
  \isaheader{Semilattices} 
704713ca07ea new document
kleing
parents: 12773
diff changeset
    12
*}
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    13
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
    14
theory Semilat = While_Combinator:
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    15
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    16
types 'a ord    = "'a \<Rightarrow> 'a \<Rightarrow> bool"
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    17
      'a binop  = "'a \<Rightarrow> 'a \<Rightarrow> 'a"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    18
      'a sl     = "'a set * 'a ord * 'a binop"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    19
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    20
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    21
 "@lesub"   :: "'a \<Rightarrow> 'a ord \<Rightarrow> 'a \<Rightarrow> bool" ("(_ /<='__ _)" [50, 1000, 51] 50)
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    22
 "@lesssub" :: "'a \<Rightarrow> 'a ord \<Rightarrow> 'a \<Rightarrow> bool" ("(_ /<'__ _)" [50, 1000, 51] 50)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    23
defs
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    24
lesub_def:   "x <=_r y == r x y"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    25
lesssub_def: "x <_r y  == x <=_r y & x ~= y"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    26
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    27
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    28
 "@plussub" :: "'a \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'c" ("(_ /+'__ _)" [65, 1000, 66] 65)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    29
defs
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    30
plussub_def: "x +_f y == f x y"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    31
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    32
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    33
constdefs
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    34
 ord :: "('a*'a)set \<Rightarrow> 'a ord"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    35
"ord r == %x y. (x,y):r"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    36
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    37
 order :: "'a ord \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    38
"order r == (!x. x <=_r x) &
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    39
            (!x y. x <=_r y & y <=_r x \<longrightarrow> x=y) &
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    40
            (!x y z. x <=_r y & y <=_r z \<longrightarrow> x <=_r z)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    41
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    42
 acc :: "'a ord \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    43
"acc r == wf{(y,x) . x <_r y}"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    44
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    45
 top :: "'a ord \<Rightarrow> 'a \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    46
"top r T == !x. x <=_r T"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    47
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    48
 closed :: "'a set \<Rightarrow> 'a binop \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    49
"closed A f == !x:A. !y:A. x +_f y : A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    50
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    51
 semilat :: "'a sl \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    52
"semilat == %(A,r,f). order r & closed A f &
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    53
                (!x:A. !y:A. x <=_r x +_f y)  &
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    54
                (!x:A. !y:A. y <=_r x +_f y)  &
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    55
                (!x:A. !y:A. !z:A. x <=_r z & y <=_r z \<longrightarrow> x +_f y <=_r z)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    56
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    57
 is_ub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    58
"is_ub r x y u == (x,u):r & (y,u):r"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    59
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    60
 is_lub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    61
"is_lub r x y u == is_ub r x y u & (!z. is_ub r x y z \<longrightarrow> (u,z):r)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    62
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    63
 some_lub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    64
"some_lub r x y == SOME z. is_lub r x y z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    65
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    66
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    67
lemma order_refl [simp, intro]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    68
  "order r \<Longrightarrow> x <=_r x";
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    69
  by (simp add: order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    70
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    71
lemma order_antisym:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    72
  "\<lbrakk> order r; x <=_r y; y <=_r x \<rbrakk> \<Longrightarrow> x = y"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    73
apply (unfold order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    74
apply (simp (no_asm_simp))  
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    75
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    76
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    77
lemma order_trans:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    78
   "\<lbrakk> order r; x <=_r y; y <=_r z \<rbrakk> \<Longrightarrow> x <=_r z"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    79
apply (unfold order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    80
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    81
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    82
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    83
lemma order_less_irrefl [intro, simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    84
   "order r \<Longrightarrow> ~ x <_r x"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    85
apply (unfold order_def lesssub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    86
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    87
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    88
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    89
lemma order_less_trans:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    90
  "\<lbrakk> order r; x <_r y; y <_r z \<rbrakk> \<Longrightarrow> x <_r z"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    91
apply (unfold order_def lesssub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    92
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    93
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    94
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    95
lemma topD [simp, intro]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    96
  "top r T \<Longrightarrow> x <=_r T"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    97
  by (simp add: top_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    98
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    99
lemma top_le_conv [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   100
  "\<lbrakk> order r; top r T \<rbrakk> \<Longrightarrow> (T <=_r x) = (x = T)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   101
  by (blast intro: order_antisym)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   102
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   103
lemma semilat_Def:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   104
"semilat(A,r,f) == order r & closed A f & 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   105
                 (!x:A. !y:A. x <=_r x +_f y) & 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   106
                 (!x:A. !y:A. y <=_r x +_f y) & 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   107
                 (!x:A. !y:A. !z:A. x <=_r z & y <=_r z \<longrightarrow> x +_f y <=_r z)"
10918
9679326489cd renamed Product_Type.split to split_conv;
wenzelm
parents: 10797
diff changeset
   108
apply (unfold semilat_def split_conv [THEN eq_reflection])
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   109
apply (rule refl [THEN eq_reflection])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   110
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   111
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   112
lemma semilatDorderI [simp, intro]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   113
  "semilat(A,r,f) \<Longrightarrow> order r"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   114
  by (simp add: semilat_Def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   115
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   116
lemma semilatDclosedI [simp, intro]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   117
  "semilat(A,r,f) \<Longrightarrow> closed A f"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   118
apply (unfold semilat_Def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   119
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   120
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   121
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   122
lemma semilat_ub1 [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   123
  "\<lbrakk> semilat(A,r,f); x:A; y:A \<rbrakk> \<Longrightarrow> x <=_r x +_f y"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   124
  by (unfold semilat_Def, simp)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   125
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   126
lemma semilat_ub2 [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   127
  "\<lbrakk> semilat(A,r,f); x:A; y:A \<rbrakk> \<Longrightarrow> y <=_r x +_f y"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   128
  by (unfold semilat_Def, simp)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   129
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   130
lemma semilat_lub [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   131
 "\<lbrakk> x <=_r z; y <=_r z; semilat(A,r,f); x:A; y:A; z:A \<rbrakk> \<Longrightarrow> x +_f y <=_r z";
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   132
  by (unfold semilat_Def, simp)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   133
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   134
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   135
lemma plus_le_conv [simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   136
  "\<lbrakk> x:A; y:A; z:A; semilat(A,r,f) \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   137
  \<Longrightarrow> (x +_f y <=_r z) = (x <=_r z & y <=_r z)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   138
apply (unfold semilat_Def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   139
apply (blast intro: semilat_ub1 semilat_ub2 semilat_lub order_trans)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   140
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   141
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   142
lemma le_iff_plus_unchanged:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   143
  "\<lbrakk> x:A; y:A; semilat(A,r,f) \<rbrakk> \<Longrightarrow> (x <=_r y) = (x +_f y = y)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   144
apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   145
 apply (intro semilatDorderI order_antisym semilat_lub order_refl semilat_ub2, assumption+)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   146
apply (erule subst)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   147
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   148
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   149
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   150
lemma le_iff_plus_unchanged2:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   151
  "\<lbrakk> x:A; y:A; semilat(A,r,f) \<rbrakk> \<Longrightarrow> (x <=_r y) = (y +_f x = y)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   152
apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   153
 apply (intro semilatDorderI order_antisym semilat_lub order_refl semilat_ub1, assumption+)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   154
apply (erule subst)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   155
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   156
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   157
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   158
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   159
lemma closedD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   160
  "\<lbrakk> closed A f; x:A; y:A \<rbrakk> \<Longrightarrow> x +_f y : A"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   161
apply (unfold closed_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   162
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   163
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   164
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   165
lemma closed_UNIV [simp]: "closed UNIV f"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   166
  by (simp add: closed_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   167
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   168
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   169
lemma is_lubD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   170
  "is_lub r x y u \<Longrightarrow> is_ub r x y u & (!z. is_ub r x y z \<longrightarrow> (u,z):r)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   171
  by (simp add: is_lub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   172
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   173
lemma is_ubI:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   174
  "\<lbrakk> (x,u) : r; (y,u) : r \<rbrakk> \<Longrightarrow> is_ub r x y u"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   175
  by (simp add: is_ub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   176
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   177
lemma is_ubD:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   178
  "is_ub r x y u \<Longrightarrow> (x,u) : r & (y,u) : r"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   179
  by (simp add: is_ub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   180
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   181
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   182
lemma is_lub_bigger1 [iff]:  
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   183
  "is_lub (r^* ) x y y = ((x,y):r^* )"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   184
apply (unfold is_lub_def is_ub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   185
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   186
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   187
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   188
lemma is_lub_bigger2 [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   189
  "is_lub (r^* ) x y x = ((y,x):r^* )"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   190
apply (unfold is_lub_def is_ub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   191
apply blast 
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   192
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   193
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   194
lemma extend_lub:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   195
  "\<lbrakk> single_valued r; is_lub (r^* ) x y u; (x',x) : r \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   196
  \<Longrightarrow> EX v. is_lub (r^* ) x' y v"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   197
apply (unfold is_lub_def is_ub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   198
apply (case_tac "(y,x) : r^*")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   199
 apply (case_tac "(y,x') : r^*")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   200
  apply blast
11175
56ab6a5ba351 recoded function iter with the help of the while-combinator.
nipkow
parents: 11085
diff changeset
   201
 apply (blast elim: converse_rtranclE dest: single_valuedD)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   202
apply (rule exI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   203
apply (rule conjI)
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12542
diff changeset
   204
 apply (blast intro: converse_rtrancl_into_rtrancl dest: single_valuedD)
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12542
diff changeset
   205
apply (blast intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl 
10797
028d22926a41 ^^ -> ```
nipkow
parents: 10496
diff changeset
   206
             elim: converse_rtranclE dest: single_valuedD)
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   207
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   208
10797
028d22926a41 ^^ -> ```
nipkow
parents: 10496
diff changeset
   209
lemma single_valued_has_lubs [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   210
  "\<lbrakk> single_valued r; (x,u) : r^* \<rbrakk> \<Longrightarrow> (!y. (y,u) : r^* \<longrightarrow> 
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   211
  (EX z. is_lub (r^* ) x y z))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   212
apply (erule converse_rtrancl_induct)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   213
 apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   214
 apply (erule converse_rtrancl_induct)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   215
  apply blast
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12542
diff changeset
   216
 apply (blast intro: converse_rtrancl_into_rtrancl)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   217
apply (blast intro: extend_lub)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   218
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   219
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   220
lemma some_lub_conv:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   221
  "\<lbrakk> acyclic r; is_lub (r^* ) x y u \<rbrakk> \<Longrightarrow> some_lub (r^* ) x y = u"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   222
apply (unfold some_lub_def is_lub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   223
apply (rule someI2)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   224
 apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   225
apply (blast intro: antisymD dest!: acyclic_impl_antisym_rtrancl)
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   226
done
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   227
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   228
lemma is_lub_some_lub:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   229
  "\<lbrakk> single_valued r; acyclic r; (x,u):r^*; (y,u):r^* \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   230
  \<Longrightarrow> is_lub (r^* ) x y (some_lub (r^* ) x y)";
10797
028d22926a41 ^^ -> ```
nipkow
parents: 10496
diff changeset
   231
  by (fastsimp dest: single_valued_has_lubs simp add: some_lub_conv)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   232
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   233
subsection{*An executable lub-finder*}
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   234
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   235
constdefs
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   236
 exec_lub :: "('a * 'a) set \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a binop"
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   237
"exec_lub r f x y == while (\<lambda>z. (x,z) \<notin> r\<^sup>*) f y"
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   238
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   239
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   240
lemma acyclic_single_valued_finite:
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   241
 "\<lbrakk>acyclic r; single_valued r; (x,y) \<in> r\<^sup>*\<rbrakk>
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   242
  \<Longrightarrow> finite (r \<inter> {a. (x, a) \<in> r\<^sup>*} \<times> {b. (b, y) \<in> r\<^sup>*})"
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   243
apply(erule converse_rtrancl_induct)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   244
 apply(rule_tac B = "{}" in finite_subset)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   245
  apply(simp only:acyclic_def)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   246
  apply(blast intro:rtrancl_into_trancl2 rtrancl_trancl_trancl)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   247
 apply simp
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   248
apply(rename_tac x x')
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   249
apply(subgoal_tac "r \<inter> {a. (x,a) \<in> r\<^sup>*} \<times> {b. (b,y) \<in> r\<^sup>*} =
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   250
                   insert (x,x') (r \<inter> {a. (x', a) \<in> r\<^sup>*} \<times> {b. (b, y) \<in> r\<^sup>*})")
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   251
 apply simp
12566
fe20540bcf93 renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents: 12542
diff changeset
   252
apply(blast intro:converse_rtrancl_into_rtrancl
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   253
            elim:converse_rtranclE dest:single_valuedD)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   254
done
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   255
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   256
12773
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   257
lemma exec_lub_conv:
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   258
  "\<lbrakk> acyclic r; !x y. (x,y) \<in> r \<longrightarrow> f x = y; is_lub (r\<^sup>*) x y u \<rbrakk> \<Longrightarrow>
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   259
  exec_lub r f x y = u";
12542
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   260
apply(unfold exec_lub_def)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   261
apply(rule_tac P = "\<lambda>z. (y,z) \<in> r\<^sup>* \<and> (z,u) \<in> r\<^sup>*" and
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   262
               r = "(r \<inter> {(a,b). (y,a) \<in> r\<^sup>* \<and> (b,u) \<in> r\<^sup>*})^-1" in while_rule)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   263
    apply(blast dest: is_lubD is_ubD)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   264
   apply(erule conjE)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   265
   apply(erule_tac z = u in converse_rtranclE)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   266
    apply(blast dest: is_lubD is_ubD)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   267
   apply(blast dest:rtrancl_into_rtrancl)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   268
  apply(rename_tac s)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   269
  apply(subgoal_tac "is_ub (r\<^sup>*) x y s")
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   270
   prefer 2; apply(simp add:is_ub_def)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   271
  apply(subgoal_tac "(u, s) \<in> r\<^sup>*")
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   272
   prefer 2; apply(blast dest:is_lubD)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   273
  apply(erule converse_rtranclE)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   274
   apply blast
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   275
  apply(simp only:acyclic_def)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   276
  apply(blast intro:rtrancl_into_trancl2 rtrancl_trancl_trancl)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   277
 apply(rule finite_acyclic_wf)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   278
  apply simp
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   279
  apply(erule acyclic_single_valued_finite)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   280
   apply(blast intro:single_valuedI)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   281
  apply(simp add:is_lub_def is_ub_def)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   282
 apply simp
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   283
 apply(erule acyclic_subset)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   284
 apply blast
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   285
apply simp
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   286
apply(erule conjE)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   287
apply(erule_tac z = u in converse_rtranclE)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   288
 apply(blast dest: is_lubD is_ubD)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   289
apply(blast dest:rtrancl_into_rtrancl)
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   290
done
ff5e3f11e1ef added exec_lub
nipkow
parents: 12516
diff changeset
   291
12773
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   292
lemma is_lub_exec_lub:
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   293
  "\<lbrakk> single_valued r; acyclic r; (x,u):r^*; (y,u):r^*; !x y. (x,y) \<in> r \<longrightarrow> f x = y \<rbrakk>
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   294
  \<Longrightarrow> is_lub (r^* ) x y (exec_lub r f x y)"
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   295
  by (fastsimp dest: single_valued_has_lubs simp add: exec_lub_conv)
a47f51daa6dc use exec_lub instead of some_lub
kleing
parents: 12566
diff changeset
   296
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   297
end