src/HOL/MicroJava/BV/Err.thy
author kleing
Tue, 12 Dec 2000 14:08:26 +0100
changeset 10650 114999ff8d19
parent 10496 f2d304bdf3cc
child 10812 ead84e90bfeb
permissions -rw-r--r--
added direction dynamic ==> static
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     1
(*  Title:      HOL/BCV/Err.thy
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
The error type
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     7
*)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     8
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
     9
header "The Error Type"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    10
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    11
theory Err = Semilat:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    12
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    13
datatype 'a err = Err | OK 'a
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    14
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    15
types 'a ebinop = "'a => 'a => 'a err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    16
      'a esl =    "'a set * 'a ord * 'a ebinop"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    17
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    18
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    19
consts
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    20
  ok_val :: "'a err => 'a"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    21
primrec
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    22
  "ok_val (OK x) = x"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    23
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    24
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    25
constdefs
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    26
 lift :: "('a => 'b err) => ('a err => 'b err)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    27
"lift f e == case e of Err => Err | OK x => f x"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    28
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    29
 lift2 :: "('a => 'b => 'c err) => 'a err => 'b err => 'c err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    30
"lift2 f e1 e2 ==
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    31
 case e1 of Err  => Err
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    32
          | OK x => (case e2 of Err => Err | OK y => f x y)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    33
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    34
 le :: "'a ord => 'a err ord"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    35
"le r e1 e2 ==
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    36
        case e2 of Err => True |
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    37
                   OK y => (case e1 of Err => False | OK x => x <=_r y)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    38
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    39
 sup :: "('a => 'b => 'c) => ('a err => 'b err => 'c err)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    40
"sup f == lift2(%x y. OK(x +_f y))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    41
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    42
 err :: "'a set => 'a err set"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    43
"err A == insert Err {x . ? y:A. x = OK y}"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    44
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    45
 esl :: "'a sl => 'a esl"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    46
"esl == %(A,r,f). (A,r, %x y. OK(f x y))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    47
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    48
 sl :: "'a esl => 'a err sl"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    49
"sl == %(A,r,f). (err A, le r, lift2 f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    50
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    51
syntax
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    52
 err_semilat :: "'a esl => bool"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    53
translations
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    54
"err_semilat L" == "semilat(Err.sl L)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    55
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    56
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    57
lemma not_Err_eq:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    58
  "(x \<noteq> Err) = (\<exists>a. x = OK a)" 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    59
  by (cases x) auto
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    60
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    61
lemma not_OK_eq:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    62
  "(\<forall>y. x \<noteq> OK y) = (x = Err)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    63
  by (cases x) auto  
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    64
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    65
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    66
lemma unfold_lesub_err:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    67
  "e1 <=_(le r) e2 == le r e1 e2"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    68
  by (simp add: lesub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    69
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    70
lemma le_err_refl:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    71
  "!x. x <=_r x ==> e <=_(Err.le r) e"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    72
apply (unfold lesub_def Err.le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    73
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    74
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    75
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    76
lemma le_err_trans [rule_format]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    77
  "order r ==> e1 <=_(le r) e2 --> e2 <=_(le r) e3 --> e1 <=_(le r) e3"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    78
apply (unfold unfold_lesub_err le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    79
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    80
apply (blast intro: order_trans)
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 le_err_antisym [rule_format]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    84
  "order r ==> e1 <=_(le r) e2 --> e2 <=_(le r) e1 --> e1=e2"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    85
apply (unfold unfold_lesub_err le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    86
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    87
apply (blast intro: order_antisym)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    88
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    89
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    90
lemma OK_le_err_OK:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    91
  "(OK x <=_(le r) OK y) = (x <=_r y)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    92
  by (simp add: unfold_lesub_err le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    93
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    94
lemma order_le_err [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    95
  "order(le r) = order r"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    96
apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    97
 apply (subst order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    98
 apply (blast dest: order_antisym OK_le_err_OK [THEN iffD2]
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
    99
              intro: order_trans OK_le_err_OK [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   100
apply (subst order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   101
apply (blast intro: le_err_refl le_err_trans le_err_antisym
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   102
             dest: order_refl)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   103
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   104
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   105
lemma le_Err [iff]:  "e <=_(le r) Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   106
  by (simp add: unfold_lesub_err le_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   107
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   108
lemma Err_le_conv [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   109
 "Err <=_(le r) e  = (e = Err)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   110
  by (simp add: unfold_lesub_err le_def  split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   111
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   112
lemma le_OK_conv [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   113
  "e <=_(le r) OK x  =  (? y. e = OK y & y <=_r x)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   114
  by (simp add: unfold_lesub_err le_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   115
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   116
lemma OK_le_conv:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   117
 "OK x <=_(le r) e  =  (e = Err | (? y. e = OK y & x <=_r y))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   118
  by (simp add: unfold_lesub_err le_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   119
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   120
lemma top_Err [iff]: "top (le r) Err";
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   121
  by (simp add: top_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   122
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   123
lemma OK_less_conv [rule_format, iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   124
  "OK x <_(le r) e = (e=Err | (? y. e = OK y & x <_r y))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   125
  by (simp add: lesssub_def lesub_def le_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   126
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   127
lemma not_Err_less [rule_format, iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   128
  "~(Err <_(le r) x)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   129
  by (simp add: lesssub_def lesub_def le_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   130
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   131
lemma semilat_errI:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   132
  "semilat(A,r,f) ==> semilat(err A, Err.le r, lift2(%x y. OK(f x y)))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   133
apply (unfold semilat_Def closed_def plussub_def lesub_def lift2_def Err.le_def err_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   134
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   135
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   136
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   137
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   138
lemma err_semilat_eslI: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   139
  "!!L. semilat L ==> err_semilat(esl L)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   140
apply (unfold sl_def esl_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   141
apply (simp (no_asm_simp) only: split_tupled_all)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   142
apply (simp add: semilat_errI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   143
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   144
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   145
lemma acc_err [simp, intro!]:  "acc r ==> acc(le r)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   146
apply (unfold acc_def lesub_def le_def lesssub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   147
apply (simp add: wf_eq_minimal split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   148
apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   149
apply (case_tac "Err : Q")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   150
 apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   151
apply (erule_tac x = "{a . OK a : Q}" in allE)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   152
apply (case_tac "x")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   153
 apply fast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   154
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   155
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   156
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   157
lemma Err_in_err [iff]: "Err : err A"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   158
  by (simp add: err_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   159
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   160
lemma Ok_in_err [iff]: "(OK x : err A) = (x:A)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   161
  by (auto simp add: err_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   162
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   163
(** lift **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   164
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   165
lemma lift_in_errI:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   166
  "[| e : err S; !x:S. e = OK x --> f x : err S |] ==> lift f e : err S"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   167
apply (unfold lift_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   168
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   169
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   170
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   171
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   172
(** lift2 **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   173
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   174
lemma Err_lift2 [simp]: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   175
  "Err +_(lift2 f) x = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   176
  by (simp add: lift2_def plussub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   177
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   178
lemma lift2_Err [simp]: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   179
  "x +_(lift2 f) Err = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   180
  by (simp add: lift2_def plussub_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   181
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   182
lemma OK_lift2_OK [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   183
  "OK x +_(lift2 f) OK y = x +_f y"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   184
  by (simp add: lift2_def plussub_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   185
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   186
(** sup **)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   187
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   188
lemma Err_sup_Err [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   189
  "Err +_(Err.sup f) x = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   190
  by (simp add: plussub_def Err.sup_def Err.lift2_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   191
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   192
lemma Err_sup_Err2 [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   193
  "x +_(Err.sup f) Err = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   194
  by (simp add: plussub_def Err.sup_def Err.lift2_def split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   195
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   196
lemma Err_sup_OK [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   197
  "OK x +_(Err.sup f) OK y = OK(x +_f y)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   198
  by (simp add: plussub_def Err.sup_def Err.lift2_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   199
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   200
lemma Err_sup_eq_OK_conv [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   201
  "(Err.sup f ex ey = OK z) = (? x y. ex = OK x & ey = OK y & f x y = z)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   202
apply (unfold Err.sup_def lift2_def plussub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   203
apply (rule iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   204
 apply (simp split: err.split_asm)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   205
apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   206
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   207
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   208
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   209
lemma Err_sup_eq_Err [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   210
  "(Err.sup f ex ey = Err) = (ex=Err | ey=Err)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   211
apply (unfold Err.sup_def lift2_def plussub_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   212
apply (simp split: err.split)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   213
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   214
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   215
(*** semilat (err A) (le r) f ***)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   216
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   217
lemma semilat_le_err_Err_plus [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   218
  "[| x: err A; semilat(err A, le r, f) |] ==> Err +_f x = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   219
  by (blast intro: le_iff_plus_unchanged [THEN iffD1] le_iff_plus_unchanged2 [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   220
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   221
lemma semilat_le_err_plus_Err [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   222
  "[| x: err A; semilat(err A, le r, f) |] ==> x +_f Err = Err"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   223
  by (blast intro: le_iff_plus_unchanged [THEN iffD1] le_iff_plus_unchanged2 [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   224
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   225
lemma semilat_le_err_OK1:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   226
  "[| x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z |] 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   227
  ==> x <=_r z";
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   228
apply (rule OK_le_err_OK [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   229
apply (erule subst)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   230
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   231
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   232
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   233
lemma semilat_le_err_OK2:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   234
  "[| x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z |] 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   235
  ==> y <=_r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   236
apply (rule OK_le_err_OK [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   237
apply (erule subst)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   238
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   239
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   240
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   241
lemma eq_order_le:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   242
  "[| x=y; order r |] ==> x <=_r y"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   243
apply (unfold order_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   244
apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   245
done
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   246
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   247
lemma OK_plus_OK_eq_Err_conv [simp]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   248
  "[| x:A; y:A; semilat(err A, le r, fe) |] ==> 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   249
  ((OK x) +_fe (OK y) = Err) = (~(? z:A. x <=_r z & y <=_r z))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   250
proof -
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   251
  have plus_le_conv3: "!!A x y z f r. 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   252
    [| semilat (A,r,f); x +_f y <=_r z; x:A; y:A; z:A |] 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   253
    ==> x <=_r z \<and> y <=_r z"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   254
    by (rule plus_le_conv [THEN iffD1])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   255
  case antecedent
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   256
  thus ?thesis
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   257
  apply (rule_tac iffI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   258
   apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   259
   apply (drule OK_le_err_OK [THEN iffD2])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   260
   apply (drule OK_le_err_OK [THEN iffD2])
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   261
   apply (drule semilat_lub)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   262
        apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   263
       apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   264
      apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   265
     apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   266
    apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   267
   apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   268
  apply (case_tac "(OK x) +_fe (OK y)")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   269
   apply assumption
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   270
  apply (rename_tac z)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   271
  apply (subgoal_tac "OK z: err A")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   272
  apply (drule eq_order_le)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   273
    apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   274
   apply (blast dest: plus_le_conv3) 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   275
  apply (erule subst)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   276
  apply (blast intro: closedD)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   277
  done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   278
qed
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   279
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   280
(*** semilat (err(Union AS)) ***)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   281
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   282
(* FIXME? *)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   283
lemma all_bex_swap_lemma [iff]:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   284
  "(!x. (? y:A. x = f y) --> P x) = (!y:A. P(f y))"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   285
  by blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   286
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   287
lemma closed_err_Union_lift2I: 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   288
  "[| !A:AS. closed (err A) (lift2 f); AS ~= {}; 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   289
      !A:AS.!B:AS. A~=B --> (!a:A.!b:B. a +_f b = Err) |] 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   290
  ==> closed (err(Union AS)) (lift2 f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   291
apply (unfold closed_def err_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   292
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   293
apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   294
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   295
apply fast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   296
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   297
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   298
(* If AS = {} the thm collapses to
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   299
   order r & closed {Err} f & Err +_f Err = Err
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   300
   which may not hold *)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   301
lemma err_semilat_UnionI:
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   302
  "[| !A:AS. err_semilat(A, r, f); AS ~= {}; 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   303
      !A:AS.!B:AS. A~=B --> (!a:A.!b:B. ~ a <=_r b & a +_f b = Err) |] 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   304
  ==> err_semilat(Union AS, r, f)"
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   305
apply (unfold semilat_def sl_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   306
apply (simp add: closed_err_Union_lift2I)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   307
apply (rule conjI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   308
 apply blast
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   309
apply (simp add: err_def)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   310
apply (rule conjI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   311
 apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   312
 apply (rename_tac A a u B b)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   313
 apply (case_tac "A = B")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   314
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   315
 apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   316
apply (rule conjI)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   317
 apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   318
 apply (rename_tac A a u B b)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   319
 apply (case_tac "A = B")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   320
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   321
 apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   322
apply clarify
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   323
apply (rename_tac A ya yb B yd z C c a b)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   324
apply (case_tac "A = B")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   325
 apply (case_tac "A = C")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   326
  apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   327
 apply (rotate_tac -1)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   328
 apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   329
apply (rotate_tac -1)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   330
apply (case_tac "B = C")
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   331
 apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   332
apply (rotate_tac -1)
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   333
apply simp
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   334
done 
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   335
f2d304bdf3cc BCV integration (first step)
kleing
parents:
diff changeset
   336
end