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