src/HOL/MicroJava/BV/Opt.thy
author haftmann
Tue, 16 Jan 2007 08:06:57 +0100
changeset 22068 00bed5ac9884
parent 16417 9bc16273c2d4
child 22271 51a80e238b29
permissions -rw-r--r--
renamed locale partial_order to order
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents: 11085
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Opt.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
More about options
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: 12516
diff changeset
     9
header {* \isaheader{More about Options} *}
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    10
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 13062
diff changeset
    11
theory Opt imports Err begin
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    12
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    13
constdefs
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    14
 le :: "'a ord \<Rightarrow> 'a option ord"
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    15
"le r o1 o2 == case o2 of None \<Rightarrow> o1=None |
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    16
                              Some y \<Rightarrow> (case o1 of None \<Rightarrow> True
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    17
                                                  | Some x \<Rightarrow> x <=_r y)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    18
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    19
 opt :: "'a set \<Rightarrow> 'a option set"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    20
"opt A == insert None {x . ? y:A. x = Some y}"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    21
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    22
 sup :: "'a ebinop \<Rightarrow> 'a option ebinop"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    23
"sup f o1 o2 ==  
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    24
 case o1 of None \<Rightarrow> OK o2 | Some x \<Rightarrow> (case o2 of None \<Rightarrow> OK o1
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    25
     | Some y \<Rightarrow> (case f x y of Err \<Rightarrow> Err | OK z \<Rightarrow> OK (Some z)))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    26
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    27
 esl :: "'a esl \<Rightarrow> 'a option esl"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    28
"esl == %(A,r,f). (opt A, le r, sup f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    29
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    30
lemma unfold_le_opt:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    31
  "o1 <=_(le r) o2 = 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    32
  (case o2 of None \<Rightarrow> o1=None | 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    33
              Some y \<Rightarrow> (case o1 of None \<Rightarrow> True | Some x \<Rightarrow> x <=_r y))"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    34
apply (unfold lesub_def le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    35
apply (rule refl)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    36
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    37
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    38
lemma le_opt_refl:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    39
  "order r \<Longrightarrow> o1 <=_(le r) o1"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    40
by (simp add: unfold_le_opt split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    41
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    42
lemma le_opt_trans [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    43
  "order r \<Longrightarrow> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    44
   o1 <=_(le r) o2 \<longrightarrow> o2 <=_(le r) o3 \<longrightarrow> o1 <=_(le r) o3"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    45
apply (simp add: unfold_le_opt split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    46
apply (blast intro: order_trans)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    47
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    48
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    49
lemma le_opt_antisym [rule_format]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    50
  "order r \<Longrightarrow> o1 <=_(le r) o2 \<longrightarrow> o2 <=_(le r) o1 \<longrightarrow> o1=o2"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    51
apply (simp add: unfold_le_opt split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    52
apply (blast intro: order_antisym)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    53
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    54
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    55
lemma order_le_opt [intro!,simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
    56
  "order r \<Longrightarrow> order(le r)"
22068
00bed5ac9884 renamed locale partial_order to order
haftmann
parents: 16417
diff changeset
    57
apply (subst Semilat.order_def)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    58
apply (blast intro: le_opt_refl le_opt_trans le_opt_antisym)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    59
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    60
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    61
lemma None_bot [iff]: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    62
  "None <=_(le r) ox"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    63
apply (unfold lesub_def le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    64
apply (simp split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    65
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    66
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    67
lemma Some_le [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    68
  "(Some x <=_(le r) ox) = (? y. ox = Some y & x <=_r y)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    69
apply (unfold lesub_def le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    70
apply (simp split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    71
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    72
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    73
lemma le_None [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    74
  "(ox <=_(le r) None) = (ox = None)";
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    75
apply (unfold lesub_def le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    76
apply (simp split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    77
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    78
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    79
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    80
lemma OK_None_bot [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    81
  "OK None <=_(Err.le (le r)) x"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    82
  by (simp add: lesub_def Err.le_def le_def split: option.split err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    83
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    84
lemma sup_None1 [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    85
  "x +_(sup f) None = OK x"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    86
  by (simp add: plussub_def sup_def split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    87
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    88
lemma sup_None2 [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    89
  "None +_(sup f) x = OK x"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    90
  by (simp add: plussub_def sup_def split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    91
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    92
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    93
lemma None_in_opt [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    94
  "None : opt A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    95
by (simp add: opt_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    96
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    97
lemma Some_in_opt [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    98
  "(Some x : opt A) = (x:A)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    99
apply (unfold opt_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   100
apply auto
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   101
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   102
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   103
13062
4b1edf2f6bd2 small refactoring for lbv with semilattices
kleing
parents: 13006
diff changeset
   104
lemma semilat_opt [intro, simp]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   105
  "\<And>L. err_semilat L \<Longrightarrow> err_semilat (Opt.esl L)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   106
proof (unfold Opt.esl_def Err.sl_def, simp add: split_tupled_all)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   107
  
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   108
  fix A r f
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   109
  assume s: "semilat (err A, Err.le r, lift2 f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   110
 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   111
  let ?A0 = "err A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   112
  let ?r0 = "Err.le r"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   113
  let ?f0 = "lift2 f"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   114
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   115
  from s
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   116
  obtain
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   117
    ord: "order ?r0" and
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   118
    clo: "closed ?A0 ?f0" and
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   119
    ub1: "\<forall>x\<in>?A0. \<forall>y\<in>?A0. x <=_?r0 x +_?f0 y" and
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   120
    ub2: "\<forall>x\<in>?A0. \<forall>y\<in>?A0. y <=_?r0 x +_?f0 y" and
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   121
    lub: "\<forall>x\<in>?A0. \<forall>y\<in>?A0. \<forall>z\<in>?A0. x <=_?r0 z \<and> y <=_?r0 z \<longrightarrow> x +_?f0 y <=_?r0 z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   122
    by (unfold semilat_def) simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   123
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   124
  let ?A = "err (opt A)" 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   125
  let ?r = "Err.le (Opt.le r)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   126
  let ?f = "lift2 (Opt.sup f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   127
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   128
  from ord
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   129
  have "order ?r"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   130
    by simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   131
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   132
  moreover
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   133
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   134
  have "closed ?A ?f"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   135
  proof (unfold closed_def, intro strip)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   136
    fix x y    
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   137
    assume x: "x : ?A" 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   138
    assume y: "y : ?A" 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   139
11085
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   140
    { fix a b
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   141
      assume ab: "x = OK a" "y = OK b"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   142
      
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   143
      with x 
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   144
      have a: "\<And>c. a = Some c \<Longrightarrow> c : A"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   145
        by (clarsimp simp add: opt_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   146
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   147
      from ab y
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   148
      have b: "\<And>d. b = Some d \<Longrightarrow> d : A"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   149
        by (clarsimp simp add: opt_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   150
      
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   151
      { fix c d assume "a = Some c" "b = Some d"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   152
        with ab x y
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   153
        have "c:A & d:A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   154
          by (simp add: err_def opt_def Bex_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   155
        with clo
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   156
        have "f c d : err A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   157
          by (simp add: closed_def plussub_def err_def lift2_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   158
        moreover
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   159
        fix z assume "f c d = OK z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   160
        ultimately
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   161
        have "z : A" by simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   162
      } note f_closed = this    
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   163
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   164
      have "sup f a b : ?A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   165
      proof (cases a)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   166
        case None
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   167
        thus ?thesis
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   168
          by (simp add: sup_def opt_def) (cases b, simp, simp add: b Bex_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   169
      next
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   170
        case Some
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   171
        thus ?thesis
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   172
          by (auto simp add: sup_def opt_def Bex_def a b f_closed split: err.split option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   173
      qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   174
    }
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   175
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   176
    thus "x +_?f y : ?A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   177
      by (simp add: plussub_def lift2_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   178
  qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   179
    
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   180
  moreover
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   181
11085
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   182
  { fix a b c 
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   183
    assume "a \<in> opt A" "b \<in> opt A" "a +_(sup f) b = OK c" 
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   184
    moreover
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   185
    from ord have "order r" by simp
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   186
    moreover
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   187
    { fix x y z
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   188
      assume "x \<in> A" "y \<in> A" 
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   189
      hence "OK x \<in> err A \<and> OK y \<in> err A" by simp
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   190
      with ub1 ub2
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   191
      have "(OK x) <=_(Err.le r) (OK x) +_(lift2 f) (OK y) \<and>
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   192
            (OK y) <=_(Err.le r) (OK x) +_(lift2 f) (OK y)"
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   193
        by blast
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   194
      moreover
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   195
      assume "x +_f y = OK z"
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   196
      ultimately
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   197
      have "x <=_r z \<and> y <=_r z"
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   198
        by (auto simp add: plussub_def lift2_def Err.le_def lesub_def)
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   199
    }
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   200
    ultimately
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   201
    have "a <=_(le r) c \<and> b <=_(le r) c"
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   202
      by (auto simp add: sup_def le_def lesub_def plussub_def 
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   203
               dest: order_refl split: option.splits err.splits)
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   204
  }
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   205
     
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   206
  hence "(\<forall>x\<in>?A. \<forall>y\<in>?A. x <=_?r x +_?f y) \<and> (\<forall>x\<in>?A. \<forall>y\<in>?A. y <=_?r x +_?f y)"
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10496
diff changeset
   207
    by (auto simp add: lesub_def plussub_def Err.le_def lift2_def split: err.split)
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   208
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   209
  moreover
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   210
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   211
  have "\<forall>x\<in>?A. \<forall>y\<in>?A. \<forall>z\<in>?A. x <=_?r z \<and> y <=_?r z \<longrightarrow> x +_?f y <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   212
  proof (intro strip, elim conjE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   213
    fix x y z
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   214
    assume xyz: "x : ?A" "y : ?A" "z : ?A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   215
    assume xz: "x <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   216
    assume yz: "y <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   217
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   218
    { fix a b c
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   219
      assume ok: "x = OK a" "y = OK b" "z = OK c"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   220
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   221
      { fix d e g
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   222
        assume some: "a = Some d" "b = Some e" "c = Some g"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   223
        
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   224
        with ok xyz
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   225
        obtain "OK d:err A" "OK e:err A" "OK g:err A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   226
          by simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   227
        with lub
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   228
        have "\<lbrakk> (OK d) <=_(Err.le r) (OK g); (OK e) <=_(Err.le r) (OK g) \<rbrakk>
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   229
          \<Longrightarrow> (OK d) +_(lift2 f) (OK e) <=_(Err.le r) (OK g)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   230
          by blast
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   231
        hence "\<lbrakk> d <=_r g; e <=_r g \<rbrakk> \<Longrightarrow> \<exists>y. d +_f e = OK y \<and> y <=_r g"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   232
          by simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   233
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   234
        with ok some xyz xz yz
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   235
        have "x +_?f y <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   236
          by (auto simp add: sup_def le_def lesub_def lift2_def plussub_def Err.le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   237
      } note this [intro!]
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   238
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   239
      from ok xyz xz yz
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   240
      have "x +_?f y <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   241
        by - (cases a, simp, cases b, simp, cases c, simp, blast)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   242
    }
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   243
    
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   244
    with xyz xz yz
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   245
    show "x +_?f y <=_?r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   246
      by - (cases x, simp, cases y, simp, cases z, simp+)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   247
  qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   248
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   249
  ultimately
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   250
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   251
  show "semilat (?A,?r,?f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   252
    by (unfold semilat_def) simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   253
qed 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   254
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   255
lemma top_le_opt_Some [iff]: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   256
  "top (le r) (Some T) = top r T"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   257
apply (unfold top_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   258
apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   259
 apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   260
apply (rule allI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   261
apply (case_tac "x")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   262
apply simp+
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   263
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   264
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   265
lemma Top_le_conv:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   266
  "\<lbrakk> order r; top r T \<rbrakk> \<Longrightarrow> (T <=_r x) = (x = T)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   267
apply (unfold top_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   268
apply (blast intro: order_antisym)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   269
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   270
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   271
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   272
lemma acc_le_optI [intro!]:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   273
  "acc r \<Longrightarrow> acc(le r)"
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   274
apply (unfold acc_def lesub_def le_def lesssub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   275
apply (simp add: wf_eq_minimal split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   276
apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   277
apply (case_tac "? a. Some a : Q")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   278
 apply (erule_tac x = "{a . Some a : Q}" in allE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   279
 apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   280
apply (case_tac "x")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   281
 apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   282
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   283
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   284
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   285
lemma option_map_in_optionI:
13006
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   286
  "\<lbrakk> ox : opt S; !x:S. ox = Some x \<longrightarrow> f x : S \<rbrakk> 
51c5f3f11d16 symbolized
kleing
parents: 12911
diff changeset
   287
  \<Longrightarrow> option_map f ox : opt S";
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   288
apply (unfold option_map_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   289
apply (simp split: option.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   290
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   291
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   292
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   293
end