src/HOL/Library/Kleene_Algebra.thy
author hoelzl
Tue Jul 19 14:37:49 2011 +0200 (2011-07-19)
changeset 43922 c6f35921056e
parent 39749 fa94799e3a3b
child 44918 6a80fbc4e72c
permissions -rw-r--r--
add nat => enat coercion
krauss@31990
     1
(*  Title:      HOL/Library/Kleene_Algebra.thy
krauss@31990
     2
    Author:     Alexander Krauss, TU Muenchen
webertj@37088
     3
    Author:     Tjark Weber, University of Cambridge
krauss@31990
     4
*)
krauss@31990
     5
webertj@37091
     6
header {* Kleene Algebras *}
krauss@31990
     7
krauss@31990
     8
theory Kleene_Algebra
krauss@31990
     9
imports Main 
krauss@31990
    10
begin
krauss@31990
    11
webertj@37088
    12
text {* WARNING: This is work in progress. Expect changes in the future. *}
krauss@31990
    13
webertj@37088
    14
text {* Various lemmas correspond to entries in a database of theorems
webertj@37088
    15
  about Kleene algebras and related structures maintained by Peter
webertj@37088
    16
  H\"ofner: see
webertj@37088
    17
  \url{http://www.informatik.uni-augsburg.de/~hoefnepe/kleene_db/lemmas/index.html}. *}
webertj@37088
    18
webertj@37088
    19
subsection {* Preliminaries *}
krauss@31990
    20
webertj@37088
    21
text {* A class where addition is idempotent. *}
krauss@31990
    22
webertj@37088
    23
class idem_add = plus +
krauss@31990
    24
  assumes add_idem [simp]: "x + x = x"
webertj@37088
    25
webertj@37088
    26
text {* A class of idempotent abelian semigroups (written additively). *}
webertj@37088
    27
webertj@37088
    28
class idem_ab_semigroup_add = ab_semigroup_add + idem_add
krauss@31990
    29
begin
krauss@31990
    30
webertj@37088
    31
lemma add_idem2 [simp]: "x + (x + y) = x + y"
krauss@31990
    32
unfolding add_assoc[symmetric] by simp
krauss@31990
    33
webertj@37088
    34
lemma add_idem3 [simp]: "x + (y + x) = x + y"
webertj@37088
    35
by (simp add: add_commute)
webertj@37088
    36
krauss@31990
    37
end
krauss@31990
    38
webertj@37088
    39
text {* A class where order is defined in terms of addition. *}
webertj@37088
    40
webertj@37088
    41
class order_by_add = plus + ord +
webertj@37088
    42
  assumes order_def: "x \<le> y \<longleftrightarrow> x + y = y"
webertj@37088
    43
  assumes strict_order_def: "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
krauss@31990
    44
begin
krauss@31990
    45
webertj@37088
    46
lemma ord_simp [simp]: "x \<le> y \<Longrightarrow> x + y = y"
krauss@31990
    47
  unfolding order_def .
krauss@31990
    48
krauss@31990
    49
lemma ord_intro: "x + y = y \<Longrightarrow> x \<le> y"
krauss@31990
    50
  unfolding order_def .
krauss@31990
    51
webertj@37088
    52
end
webertj@37088
    53
webertj@37088
    54
text {* A class of idempotent abelian semigroups (written additively)
webertj@37088
    55
  where order is defined in terms of addition. *}
webertj@37088
    56
webertj@37088
    57
class ordered_idem_ab_semigroup_add = idem_ab_semigroup_add + order_by_add
webertj@37088
    58
begin
webertj@37088
    59
webertj@37088
    60
lemma ord_simp2 [simp]: "x \<le> y \<Longrightarrow> y + x = y"
webertj@37088
    61
  unfolding order_def add_commute .
webertj@37088
    62
krauss@31990
    63
subclass order proof
krauss@31990
    64
  fix x y z :: 'a
webertj@37088
    65
  show "x \<le> x"
webertj@37088
    66
    unfolding order_def by simp
krauss@31990
    67
  show "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
webertj@37088
    68
    unfolding order_def by (metis add_assoc)
webertj@37088
    69
  show "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
webertj@37088
    70
    unfolding order_def by (simp add: add_commute)
webertj@37088
    71
  show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
webertj@37088
    72
    by (fact strict_order_def)
krauss@31990
    73
qed
krauss@31990
    74
webertj@37088
    75
subclass ordered_ab_semigroup_add proof
webertj@37088
    76
  fix a b c :: 'a
webertj@37088
    77
  assume "a \<le> b" show "c + a \<le> c + b"
webertj@37088
    78
  proof (rule ord_intro)
webertj@37088
    79
    have "c + a + (c + b) = a + b + c" by (simp add: add_ac)
webertj@37088
    80
    also have "\<dots> = c + b" by (simp add: `a \<le> b` add_ac)
webertj@37088
    81
    finally show "c + a + (c + b) = c + b" .
webertj@37088
    82
  qed
webertj@37088
    83
qed
webertj@37088
    84
webertj@37088
    85
lemma plus_leI [simp]: 
krauss@31990
    86
  "x \<le> z \<Longrightarrow> y \<le> z \<Longrightarrow> x + y \<le> z"
krauss@31990
    87
  unfolding order_def by (simp add: add_assoc)
krauss@31990
    88
webertj@37088
    89
lemma less_add [simp]: "x \<le> x + y" "y \<le> x + y"
webertj@37088
    90
unfolding order_def by (auto simp: add_ac)
krauss@31990
    91
webertj@37088
    92
lemma add_est1 [elim]: "x + y \<le> z \<Longrightarrow> x \<le> z"
krauss@31990
    93
using less_add(1) by (rule order_trans)
krauss@31990
    94
webertj@37088
    95
lemma add_est2 [elim]: "x + y \<le> z \<Longrightarrow> y \<le> z"
krauss@31990
    96
using less_add(2) by (rule order_trans)
krauss@31990
    97
webertj@37088
    98
lemma add_supremum: "(x + y \<le> z) = (x \<le> z \<and> y \<le> z)"
webertj@37088
    99
by auto
webertj@37088
   100
krauss@31990
   101
end
krauss@31990
   102
webertj@37088
   103
text {* A class of commutative monoids (written additively) where
webertj@37088
   104
  order is defined in terms of addition. *}
webertj@37088
   105
webertj@37088
   106
class ordered_comm_monoid_add = comm_monoid_add + order_by_add
webertj@37088
   107
begin
webertj@37088
   108
webertj@37088
   109
lemma zero_minimum [simp]: "0 \<le> x"
webertj@37088
   110
unfolding order_def by simp
webertj@37088
   111
webertj@37088
   112
end
webertj@37088
   113
webertj@37088
   114
text {* A class of idempotent commutative monoids (written additively)
webertj@37088
   115
  where order is defined in terms of addition. *}
webertj@37088
   116
webertj@37088
   117
class ordered_idem_comm_monoid_add = ordered_comm_monoid_add + idem_add
krauss@31990
   118
begin
krauss@31990
   119
webertj@37088
   120
subclass ordered_idem_ab_semigroup_add ..
webertj@37088
   121
webertj@37088
   122
lemma sum_is_zero: "(x + y = 0) = (x = 0 \<and> y = 0)"
webertj@37088
   123
by (simp add: add_supremum eq_iff)
webertj@37088
   124
webertj@37088
   125
end
webertj@37088
   126
webertj@37091
   127
subsection {* A class of Kleene algebras *}
webertj@37088
   128
webertj@37088
   129
text {* Class @{text pre_kleene} provides all operations of Kleene
webertj@37088
   130
  algebras except for the Kleene star. *}
webertj@37088
   131
webertj@37088
   132
class pre_kleene = semiring_1 + idem_add + order_by_add
webertj@37088
   133
begin
webertj@37088
   134
webertj@37088
   135
subclass ordered_idem_comm_monoid_add ..
webertj@37088
   136
haftmann@35028
   137
subclass ordered_semiring proof
webertj@37088
   138
  fix a b c :: 'a
webertj@37088
   139
  assume "a \<le> b"
krauss@31990
   140
webertj@37088
   141
  show "c * a \<le> c * b"
krauss@31990
   142
  proof (rule ord_intro)
webertj@37088
   143
    from `a \<le> b` have "c * (a + b) = c * b" by simp
webertj@37088
   144
    thus "c * a + c * b = c * b" by (simp add: right_distrib)
krauss@31990
   145
  qed
krauss@31990
   146
webertj@37088
   147
  show "a * c \<le> b * c"
krauss@31990
   148
  proof (rule ord_intro)
webertj@37088
   149
    from `a \<le> b` have "(a + b) * c = b * c" by simp
webertj@37088
   150
    thus "a * c + b * c = b * c" by (simp add: left_distrib)
krauss@31990
   151
  qed
krauss@31990
   152
qed
krauss@31990
   153
webertj@37088
   154
end
webertj@37088
   155
webertj@37088
   156
text {* A class that provides a star operator. *}
krauss@31990
   157
webertj@37088
   158
class star =
webertj@37088
   159
  fixes star :: "'a \<Rightarrow> 'a"
webertj@37088
   160
webertj@37088
   161
text {* Finally, a class of Kleene algebras. *}
krauss@31990
   162
krauss@31990
   163
class kleene = pre_kleene + star +
krauss@31990
   164
  assumes star1: "1 + a * star a \<le> star a"
krauss@31990
   165
  and star2: "1 + star a * a \<le> star a"
krauss@31990
   166
  and star3: "a * x \<le> x \<Longrightarrow> star a * x \<le> x"
krauss@31990
   167
  and star4: "x * a \<le> x \<Longrightarrow> x * star a \<le> x"
krauss@31990
   168
begin
krauss@31990
   169
webertj@37088
   170
lemma star3' [simp]:
krauss@31990
   171
  assumes a: "b + a * x \<le> x"
krauss@31990
   172
  shows "star a * b \<le> x"
webertj@37088
   173
by (metis assms less_add mult_left_mono order_trans star3 zero_minimum)
krauss@31990
   174
webertj@37088
   175
lemma star4' [simp]:
krauss@31990
   176
  assumes a: "b + x * a \<le> x"
krauss@31990
   177
  shows "b * star a \<le> x"
webertj@37088
   178
by (metis assms less_add mult_right_mono order_trans star4 zero_minimum)
krauss@31990
   179
webertj@37088
   180
lemma star_unfold_left: "1 + a * star a = star a"
krauss@31990
   181
proof (rule antisym, rule star1)
krauss@31990
   182
  have "1 + a * (1 + a * star a) \<le> 1 + a * star a"
webertj@37088
   183
    by (metis add_left_mono mult_left_mono star1 zero_minimum)
krauss@31990
   184
  with star3' have "star a * 1 \<le> 1 + a * star a" .
krauss@31990
   185
  thus "star a \<le> 1 + a * star a" by simp
krauss@31990
   186
qed
krauss@31990
   187
krauss@31990
   188
lemma star_unfold_right: "1 + star a * a = star a"
krauss@31990
   189
proof (rule antisym, rule star2)
krauss@31990
   190
  have "1 + (1 + star a * a) * a \<le> 1 + star a * a"
webertj@37088
   191
    by (metis add_left_mono mult_right_mono star2 zero_minimum)
krauss@31990
   192
  with star4' have "1 * star a \<le> 1 + star a * a" .
krauss@31990
   193
  thus "star a \<le> 1 + star a * a" by simp
krauss@31990
   194
qed
krauss@31990
   195
webertj@37088
   196
lemma star_zero [simp]: "star 0 = 1"
krauss@31990
   197
by (fact star_unfold_left[of 0, simplified, symmetric])
krauss@31990
   198
webertj@37088
   199
lemma star_one [simp]: "star 1 = 1"
krauss@31990
   200
by (metis add_idem2 eq_iff mult_1_right ord_simp2 star3 star_unfold_left)
krauss@31990
   201
webertj@37088
   202
lemma one_less_star [simp]: "1 \<le> star x"
krauss@31990
   203
by (metis less_add(1) star_unfold_left)
krauss@31990
   204
webertj@37088
   205
lemma ka1 [simp]: "x * star x \<le> star x"
krauss@31990
   206
by (metis less_add(2) star_unfold_left)
krauss@31990
   207
webertj@37088
   208
lemma star_mult_idem [simp]: "star x * star x = star x"
krauss@31990
   209
by (metis add_commute add_est1 eq_iff mult_1_right right_distrib star3 star_unfold_left)
krauss@31990
   210
webertj@37088
   211
lemma less_star [simp]: "x \<le> star x"
krauss@31990
   212
by (metis less_add(2) mult_1_right mult_left_mono one_less_star order_trans star_unfold_left zero_minimum)
krauss@31990
   213
webertj@37088
   214
lemma star_simulation_leq_1:
webertj@37088
   215
  assumes a: "a * x \<le> x * b"
webertj@37088
   216
  shows "star a * x \<le> x * star b"
webertj@37088
   217
proof (rule star3', rule order_trans)
webertj@37090
   218
  from a have "a * x * star b \<le> x * b * star b"
webertj@37088
   219
    by (rule mult_right_mono) simp
webertj@37088
   220
  thus "x + a * (x * star b) \<le> x + x * b * star b"
webertj@37088
   221
    using add_left_mono by (auto simp: mult_assoc)
webertj@37088
   222
  show "\<dots> \<le> x * star b"
webertj@37088
   223
    by (metis add_supremum ka1 mult.right_neutral mult_assoc mult_left_mono one_less_star zero_minimum)
webertj@37088
   224
qed
webertj@37088
   225
webertj@37088
   226
lemma star_simulation_leq_2:
webertj@37088
   227
  assumes a: "x * a \<le> b * x"
webertj@37088
   228
  shows "x * star a \<le> star b * x"
webertj@37088
   229
proof (rule star4', rule order_trans)
webertj@37090
   230
  from a have "star b * x * a \<le> star b * b * x"
webertj@37090
   231
    by (metis mult_assoc mult_left_mono zero_minimum)
webertj@37088
   232
  thus "x + star b * x * a \<le> x + star b * b * x"
webertj@37088
   233
    using add_mono by auto
webertj@37088
   234
  show "\<dots> \<le> star b * x"
webertj@37092
   235
    by (metis add_supremum left_distrib less_add mult.left_neutral mult_assoc mult_right_mono star_unfold_right zero_minimum)
webertj@37088
   236
qed
webertj@37088
   237
webertj@37088
   238
lemma star_simulation [simp]:
krauss@31990
   239
  assumes a: "a * x = x * b"
krauss@31990
   240
  shows "star a * x = x * star b"
webertj@37088
   241
by (metis antisym assms order_refl star_simulation_leq_1 star_simulation_leq_2)
krauss@31990
   242
webertj@37088
   243
lemma star_slide2 [simp]: "star x * x = x * star x"
krauss@31990
   244
by (metis star_simulation)
krauss@31990
   245
webertj@37088
   246
lemma star_idemp [simp]: "star (star x) = star x"
krauss@31990
   247
by (metis add_idem2 eq_iff less_star mult_1_right star3' star_mult_idem star_unfold_left)
krauss@31990
   248
webertj@37088
   249
lemma star_slide [simp]: "star (x * y) * x = x * star (y * x)"
webertj@37179
   250
by (metis mult_assoc star_simulation)
krauss@31990
   251
krauss@31990
   252
lemma star_one':
krauss@31990
   253
  assumes "p * p' = 1" "p' * p = 1"
krauss@31990
   254
  shows "p' * star a * p = star (p' * a * p)"
krauss@31990
   255
proof -
krauss@31990
   256
  from assms
krauss@31990
   257
  have "p' * star a * p = p' * star (p * p' * a) * p"
krauss@31990
   258
    by simp
krauss@31990
   259
  also have "\<dots> = p' * p * star (p' * a * p)"
krauss@31990
   260
    by (simp add: mult_assoc)
krauss@31990
   261
  also have "\<dots> = star (p' * a * p)"
krauss@31990
   262
    by (simp add: assms)
krauss@31990
   263
  finally show ?thesis .
krauss@31990
   264
qed
krauss@31990
   265
webertj@37088
   266
lemma x_less_star [simp]: "x \<le> x * star a"
webertj@37088
   267
by (metis mult.right_neutral mult_left_mono one_less_star zero_minimum)
krauss@31990
   268
webertj@37088
   269
lemma star_mono [simp]: "x \<le> y \<Longrightarrow> star x \<le> star y"
krauss@31990
   270
by (metis add_commute eq_iff less_star ord_simp2 order_trans star3 star4' star_idemp star_mult_idem x_less_star)
krauss@31990
   271
krauss@31990
   272
lemma star_sub: "x \<le> 1 \<Longrightarrow> star x = 1"
webertj@37088
   273
by (metis add_commute ord_simp star_idemp star_mono star_mult_idem star_one star_unfold_left)
krauss@31990
   274
krauss@31990
   275
lemma star_unfold2: "star x * y = y + x * star x * y"
krauss@31990
   276
by (subst star_unfold_right[symmetric]) (simp add: mult_assoc left_distrib)
krauss@31990
   277
webertj@37088
   278
lemma star_absorb_one [simp]: "star (x + 1) = star x"
webertj@37088
   279
by (metis add_commute eq_iff left_distrib less_add mult_1_left mult_assoc star3 star_mono star_mult_idem star_unfold2 x_less_star)
krauss@31990
   280
webertj@37088
   281
lemma star_absorb_one' [simp]: "star (1 + x) = star x"
krauss@31990
   282
by (subst add_commute) (fact star_absorb_one)
krauss@31990
   283
krauss@31990
   284
lemma ka16: "(y * star x) * star (y * star x) \<le> star x * star (y * star x)"
krauss@31990
   285
by (metis ka1 less_add(1) mult_assoc order_trans star_unfold2)
krauss@31990
   286
krauss@31990
   287
lemma ka16': "(star x * y) * star (star x * y) \<le> star (star x * y) * star x"
krauss@31990
   288
by (metis ka1 mult_assoc order_trans star_slide x_less_star)
krauss@31990
   289
krauss@31990
   290
lemma ka17: "(x * star x) * star (y * star x) \<le> star x * star (y * star x)"
krauss@31990
   291
by (metis ka1 mult_assoc mult_right_mono zero_minimum)
krauss@31990
   292
krauss@31990
   293
lemma ka18: "(x * star x) * star (y * star x) + (y * star x) * star (y * star x)
krauss@31990
   294
  \<le> star x * star (y * star x)"
krauss@31990
   295
by (metis ka16 ka17 left_distrib mult_assoc plus_leI)
krauss@31990
   296
webertj@37088
   297
lemma star_decomp: "star (x + y) = star x * star (y * star x)"
krauss@32238
   298
proof (rule antisym)
webertj@37088
   299
  have "1 + (x + y) * star x * star (y * star x) \<le>
webertj@37088
   300
    1 + x * star x * star (y * star x) + y * star x * star (y * star x)"
krauss@32238
   301
    by (metis add_commute add_left_commute eq_iff left_distrib mult_assoc)
webertj@37088
   302
  also have "\<dots> \<le> star x * star (y * star x)"
krauss@32238
   303
    by (metis add_commute add_est1 add_left_commute ka18 plus_leI star_unfold_left x_less_star)
webertj@37088
   304
  finally show "star (x + y) \<le> star x * star (y * star x)"
krauss@32238
   305
    by (metis mult_1_right mult_assoc star3')
krauss@32238
   306
next
webertj@37088
   307
  show "star x * star (y * star x) \<le> star (x + y)"
krauss@32238
   308
    by (metis add_assoc add_est1 add_est2 add_left_commute less_star mult_mono'
krauss@32238
   309
      star_absorb_one star_absorb_one' star_idemp star_mono star_mult_idem zero_minimum)
krauss@32238
   310
qed
krauss@31990
   311
krauss@31990
   312
lemma ka22: "y * star x \<le> star x * star y \<Longrightarrow>  star y * star x \<le> star x * star y"
krauss@31990
   313
by (metis mult_assoc mult_right_mono plus_leI star3' star_mult_idem x_less_star zero_minimum)
krauss@31990
   314
krauss@31990
   315
lemma ka23: "star y * star x \<le> star x * star y \<Longrightarrow> y * star x \<le> star x * star y"
krauss@31990
   316
by (metis less_star mult_right_mono order_trans zero_minimum)
krauss@31990
   317
krauss@31990
   318
lemma ka24: "star (x + y) \<le> star (star x * star y)"
krauss@31990
   319
by (metis add_est1 add_est2 less_add(1) mult_assoc order_def plus_leI star_absorb_one star_mono star_slide2 star_unfold2 star_unfold_left x_less_star)
krauss@31990
   320
krauss@31990
   321
lemma ka25: "star y * star x \<le> star x * star y \<Longrightarrow> star (star y * star x) \<le> star x * star y"
krauss@37095
   322
proof -
krauss@37095
   323
  assume "star y * star x \<le> star x * star y"
krauss@37095
   324
  hence "\<forall>x\<^isub>1. star y * (star x * x\<^isub>1) \<le> star x * (star y * x\<^isub>1)" by (metis mult_assoc mult_right_mono zero_minimum)
krauss@37095
   325
  hence "star y * (star x * star y) \<le> star x * star y" by (metis star_mult_idem)
krauss@37095
   326
  hence "\<exists>x\<^isub>1. star (star y * star x) * star x\<^isub>1 \<le> star x * star y" by (metis star_decomp star_idemp star_simulation_leq_2 star_slide)
krauss@37095
   327
  hence "\<exists>x\<^isub>1\<ge>star (star y * star x). x\<^isub>1 \<le> star x * star y" by (metis x_less_star)
krauss@37095
   328
  thus "star (star y * star x) \<le> star x * star y" by (metis order_trans)
krauss@37095
   329
qed
webertj@37088
   330
webertj@37088
   331
lemma church_rosser: 
webertj@37088
   332
  "star y * star x \<le> star x * star y \<Longrightarrow> star (x + y) \<le> star x * star y"
webertj@37088
   333
by (metis add_commute ka24 ka25 order_trans)
krauss@31990
   334
krauss@31990
   335
lemma kleene_bubblesort: "y * x \<le> x * y \<Longrightarrow> star (x + y) \<le> star x * star y"
webertj@37088
   336
by (metis church_rosser star_simulation_leq_1 star_simulation_leq_2)
webertj@37088
   337
webertj@37088
   338
lemma ka27: "star (x + star y) = star (x + y)"
webertj@37088
   339
by (metis add_commute star_decomp star_idemp)
webertj@37088
   340
webertj@37088
   341
lemma ka28: "star (star x + star y) = star (x + y)"
webertj@37088
   342
by (metis add_commute ka27)
webertj@37088
   343
webertj@37088
   344
lemma ka29: "(y * (1 + x) \<le> (1 + x) * star y) = (y * x \<le> (1 + x) * star y)"
webertj@37088
   345
by (metis add_supremum left_distrib less_add(1) less_star mult.left_neutral mult.right_neutral order_trans right_distrib)
webertj@37088
   346
webertj@37088
   347
lemma ka30: "star x * star y \<le> star (x + y)"
webertj@37088
   348
by (metis mult_left_mono star_decomp star_mono x_less_star zero_minimum)
webertj@37088
   349
webertj@37088
   350
lemma simple_simulation: "x * y = 0 \<Longrightarrow> star x * y = y"
webertj@37088
   351
by (metis mult.right_neutral mult_zero_right star_simulation star_zero)
webertj@37088
   352
webertj@37088
   353
lemma ka32: "star (x * y) = 1 + x * star (y * x) * y"
webertj@37088
   354
by (metis mult_assoc star_slide star_unfold_left)
webertj@37088
   355
webertj@37088
   356
lemma ka33: "x * y + 1 \<le> y \<Longrightarrow> star x \<le> y"
webertj@37088
   357
by (metis add_commute mult.right_neutral star3')
krauss@31990
   358
krauss@31990
   359
end
krauss@31990
   360
webertj@37091
   361
subsection {* Complete lattices are Kleene algebras *}
krauss@31990
   362
krauss@31990
   363
lemma (in complete_lattice) le_SUPI':
krauss@31990
   364
  assumes "l \<le> M i"
krauss@31990
   365
  shows "l \<le> (SUP i. M i)"
krauss@31990
   366
  using assms by (rule order_trans) (rule le_SUPI [OF UNIV_I])
krauss@31990
   367
krauss@31990
   368
class kleene_by_complete_lattice = pre_kleene
krauss@31990
   369
  + complete_lattice + power + star +
krauss@31990
   370
  assumes star_cont: "a * star b * c = SUPR UNIV (\<lambda>n. a * b ^ n * c)"
krauss@31990
   371
begin
krauss@31990
   372
krauss@31990
   373
subclass kleene
krauss@31990
   374
proof
krauss@31990
   375
  fix a x :: 'a
krauss@31990
   376
  
krauss@31990
   377
  have [simp]: "1 \<le> star a"
krauss@31990
   378
    unfolding star_cont[of 1 a 1, simplified] 
krauss@31990
   379
    by (subst power_0[symmetric]) (rule le_SUPI [OF UNIV_I])
krauss@31990
   380
  
webertj@37088
   381
  show "1 + a * star a \<le> star a"
krauss@31990
   382
    apply (rule plus_leI, simp)
krauss@31990
   383
    apply (simp add:star_cont[of a a 1, simplified])
krauss@31990
   384
    apply (simp add:star_cont[of 1 a 1, simplified])
krauss@31990
   385
    apply (subst power_Suc[symmetric])
krauss@31990
   386
    by (intro SUP_leI le_SUPI UNIV_I)
krauss@31990
   387
krauss@31990
   388
  show "1 + star a * a \<le> star a" 
krauss@31990
   389
    apply (rule plus_leI, simp)
krauss@31990
   390
    apply (simp add:star_cont[of 1 a a, simplified])
krauss@31990
   391
    apply (simp add:star_cont[of 1 a 1, simplified])
krauss@31990
   392
    by (auto intro: SUP_leI le_SUPI simp add: power_Suc[symmetric] power_commutes simp del: power_Suc)
krauss@31990
   393
krauss@31990
   394
  show "a * x \<le> x \<Longrightarrow> star a * x \<le> x"
krauss@31990
   395
  proof -
krauss@31990
   396
    assume a: "a * x \<le> x"
krauss@31990
   397
krauss@31990
   398
    {
krauss@31990
   399
      fix n
krauss@31990
   400
      have "a ^ (Suc n) * x \<le> a ^ n * x"
krauss@31990
   401
      proof (induct n)
krauss@31990
   402
        case 0 thus ?case by (simp add: a)
krauss@31990
   403
      next
krauss@31990
   404
        case (Suc n)
krauss@31990
   405
        hence "a * (a ^ Suc n * x) \<le> a * (a ^ n * x)"
krauss@31990
   406
          by (auto intro: mult_mono)
krauss@31990
   407
        thus ?case
krauss@31990
   408
          by (simp add: mult_assoc)
krauss@31990
   409
      qed
krauss@31990
   410
    }
krauss@31990
   411
    note a = this
krauss@31990
   412
    
krauss@31990
   413
    {
krauss@31990
   414
      fix n have "a ^ n * x \<le> x"
krauss@31990
   415
      proof (induct n)
krauss@31990
   416
        case 0 show ?case by simp
krauss@31990
   417
      next
krauss@31990
   418
        case (Suc n) with a[of n]
krauss@31990
   419
        show ?case by simp
krauss@31990
   420
      qed
krauss@31990
   421
    }
krauss@31990
   422
    note b = this
krauss@31990
   423
    
krauss@31990
   424
    show "star a * x \<le> x"
krauss@31990
   425
      unfolding star_cont[of 1 a x, simplified]
krauss@31990
   426
      by (rule SUP_leI) (rule b)
krauss@31990
   427
  qed
krauss@31990
   428
krauss@31990
   429
  show "x * a \<le> x \<Longrightarrow> x * star a \<le> x" (* symmetric *)
krauss@31990
   430
  proof -
krauss@31990
   431
    assume a: "x * a \<le> x"
krauss@31990
   432
krauss@31990
   433
    {
krauss@31990
   434
      fix n
krauss@31990
   435
      have "x * a ^ (Suc n) \<le> x * a ^ n"
krauss@31990
   436
      proof (induct n)
krauss@31990
   437
        case 0 thus ?case by (simp add: a)
krauss@31990
   438
      next
krauss@31990
   439
        case (Suc n)
krauss@31990
   440
        hence "(x * a ^ Suc n) * a  \<le> (x * a ^ n) * a"
krauss@31990
   441
          by (auto intro: mult_mono)
krauss@31990
   442
        thus ?case
krauss@31990
   443
          by (simp add: power_commutes mult_assoc)
krauss@31990
   444
      qed
krauss@31990
   445
    }
krauss@31990
   446
    note a = this
krauss@31990
   447
    
krauss@31990
   448
    {
krauss@31990
   449
      fix n have "x * a ^ n \<le> x"
krauss@31990
   450
      proof (induct n)
krauss@31990
   451
        case 0 show ?case by simp
krauss@31990
   452
      next
krauss@31990
   453
        case (Suc n) with a[of n]
krauss@31990
   454
        show ?case by simp
krauss@31990
   455
      qed
krauss@31990
   456
    }
krauss@31990
   457
    note b = this
krauss@31990
   458
    
krauss@31990
   459
    show "x * star a \<le> x"
krauss@31990
   460
      unfolding star_cont[of x a 1, simplified]
krauss@31990
   461
      by (rule SUP_leI) (rule b)
krauss@31990
   462
  qed
krauss@31990
   463
qed
krauss@31990
   464
krauss@31990
   465
end
krauss@31990
   466
webertj@37091
   467
subsection {* Transitive closure *}
krauss@31990
   468
krauss@31990
   469
context kleene
krauss@31990
   470
begin
krauss@31990
   471
webertj@37088
   472
definition
webertj@37088
   473
  tcl_def: "tcl x = star x * x"
krauss@31990
   474
krauss@31990
   475
lemma tcl_zero: "tcl 0 = 0"
krauss@31990
   476
unfolding tcl_def by simp
krauss@31990
   477
krauss@31990
   478
lemma tcl_unfold_right: "tcl a = a + tcl a * a"
webertj@37088
   479
by (metis star_slide2 star_unfold2 tcl_def)
krauss@31990
   480
krauss@31990
   481
lemma less_tcl: "a \<le> tcl a"
webertj@37088
   482
by (metis star_slide2 tcl_def x_less_star)
krauss@31990
   483
krauss@31990
   484
end
krauss@31990
   485
krauss@31990
   486
end