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