thys2/PDerivs.thy
author Chengsong
Mon, 10 Jul 2023 19:29:22 +0100
changeset 664 ba44144875b1
parent 436 222333d2bdc2
permissions -rw-r--r--
introduction Contribution section update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     1
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     2
theory PDerivs
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     3
  imports Spec 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     4
begin
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     5
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     6
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     7
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     8
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     9
  "SEQs rs r \<equiv> (\<Union>r' \<in> rs. {SEQ r' r})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    10
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    11
lemma SEQs_eq_image:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    12
  "SEQs rs r = (\<lambda>r'. SEQ r' r) ` rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    13
  by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    14
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 389
diff changeset
    15
fun
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    16
  pder :: "char \<Rightarrow> rexp \<Rightarrow> rexp set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    17
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    18
  "pder c ZERO = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    19
| "pder c ONE = {}"
378
Chengsong
parents: 365
diff changeset
    20
| "pder c (CH d) = (if c = d then {ONE} else {})"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    21
| "pder c (ALT r1 r2) = (pder c r1) \<union> (pder c r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    22
| "pder c (SEQ r1 r2) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    23
    (if nullable r1 then SEQs (pder c r1) r2 \<union> pder c r2 else SEQs (pder c r1) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    24
| "pder c (STAR r) = SEQs (pder c r) (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    25
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 389
diff changeset
    26
fun
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    27
  pders :: "char list \<Rightarrow> rexp \<Rightarrow> rexp set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    28
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    29
  "pders [] r = {r}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    30
| "pders (c # s) r = \<Union> (pders s ` pder c r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    31
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    32
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    33
 pder_set :: "char \<Rightarrow> rexp set \<Rightarrow> rexp set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    34
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    35
  "pder_set c rs \<equiv> \<Union> (pder c ` rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    36
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    37
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    38
  pders_set :: "char list \<Rightarrow> rexp set \<Rightarrow> rexp set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    39
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    40
  "pders_set s rs \<equiv> \<Union> (pders s ` rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    41
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    42
lemma pders_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    43
  "pders (s1 @ s2) r = \<Union> (pders s2 ` pders s1 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    44
by (induct s1 arbitrary: r) (simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    45
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    46
lemma pders_snoc:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    47
  shows "pders (s @ [c]) r = pder_set c (pders s r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    48
by (simp add: pders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    49
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    50
lemma pders_simps [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    51
  shows "pders s ZERO = (if s = [] then {ZERO} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    52
  and   "pders s ONE = (if s = [] then {ONE} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    53
  and   "pders s (ALT r1 r2) = (if s = [] then {ALT r1 r2} else (pders s r1) \<union> (pders s r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    54
by (induct s) (simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    55
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    56
lemma pders_CHAR:
378
Chengsong
parents: 365
diff changeset
    57
  shows "pders s (CH c) \<subseteq> {CH c, ONE}"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    58
by (induct s) (simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    59
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    60
subsection \<open>Relating left-quotients and partial derivatives\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    61
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    62
lemma Sequ_UNION_distrib:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    63
shows "A ;; \<Union>(M ` I) = \<Union>((\<lambda>i. A ;; M i) ` I)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    64
and   "\<Union>(M ` I) ;; A = \<Union>((\<lambda>i. M i ;; A) ` I)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    65
by (auto simp add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    66
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    67
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    68
lemma Der_pder:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    69
  shows "Der c (L r) = \<Union> (L ` pder c r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    70
by (induct r) (simp_all add: nullable_correctness Sequ_UNION_distrib)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    71
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    72
lemma Ders_pders:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    73
  shows "Ders s (L r) = \<Union> (L ` pders s r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    74
proof (induct s arbitrary: r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    75
  case (Cons c s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    76
  have ih: "\<And>r. Ders s (L r) = \<Union> (L ` pders s r)" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    77
  have "Ders (c # s) (L r) = Ders s (Der c (L r))" by (simp add: Ders_def Der_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    78
  also have "\<dots> = Ders s (\<Union> (L ` pder c r))" by (simp add: Der_pder)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    79
  also have "\<dots> = (\<Union>A\<in>(L ` (pder c r)). (Ders s A))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    80
    by (auto simp add:  Ders_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    81
  also have "\<dots> = \<Union> (L ` (pders_set s (pder c r)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    82
    using ih by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    83
  also have "\<dots> = \<Union> (L ` (pders (c # s) r))" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    84
  finally show "Ders (c # s) (L r) = \<Union> (L ` pders (c # s) r)" .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    85
qed (simp add: Ders_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    86
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    87
subsection \<open>Relating derivatives and partial derivatives\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    88
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    89
lemma der_pder:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    90
  shows "\<Union> (L ` (pder c r)) = L (der c r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    91
unfolding der_correctness Der_pder by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    92
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    93
lemma ders_pders:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    94
  shows "\<Union> (L ` (pders s r)) = L (ders s r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    95
unfolding der_correctness ders_correctness Ders_pders by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    96
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    97
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    98
subsection \<open>Finiteness property of partial derivatives\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    99
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   100
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   101
  pders_Set :: "string set \<Rightarrow> rexp \<Rightarrow> rexp set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   102
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   103
  "pders_Set A r \<equiv> \<Union>x \<in> A. pders x r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   104
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   105
lemma pders_Set_subsetI:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   106
  assumes "\<And>s. s \<in> A \<Longrightarrow> pders s r \<subseteq> C"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   107
  shows "pders_Set A r \<subseteq> C"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   108
using assms unfolding pders_Set_def by (rule UN_least)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   109
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   110
lemma pders_Set_union:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   111
  shows "pders_Set (A \<union> B) r = (pders_Set A r \<union> pders_Set B r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   112
by (simp add: pders_Set_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   113
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   114
lemma pders_Set_subset:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   115
  shows "A \<subseteq> B \<Longrightarrow> pders_Set A r \<subseteq> pders_Set B r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   116
by (auto simp add: pders_Set_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   117
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   118
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   119
  "UNIV1 \<equiv> UNIV - {[]}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   120
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   121
lemma pders_Set_ZERO [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   122
  shows "pders_Set UNIV1 ZERO = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   123
unfolding UNIV1_def pders_Set_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   124
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   125
lemma pders_Set_ONE [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   126
  shows "pders_Set UNIV1 ONE = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   127
unfolding UNIV1_def pders_Set_def by (auto split: if_splits)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   128
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   129
lemma pders_Set_CHAR [simp]:
378
Chengsong
parents: 365
diff changeset
   130
  shows "pders_Set UNIV1 (CH c) = {ONE}"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   131
unfolding UNIV1_def pders_Set_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   132
apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   133
apply(frule rev_subsetD)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   134
apply(rule pders_CHAR)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   135
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   136
apply(case_tac xa)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   137
apply(auto split: if_splits)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   138
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   139
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   140
lemma pders_Set_ALT [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   141
  shows "pders_Set UNIV1 (ALT r1 r2) = pders_Set UNIV1 r1 \<union> pders_Set UNIV1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   142
unfolding UNIV1_def pders_Set_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
text \<open>Non-empty suffixes of a string (needed for the cases of @{const SEQ} and @{const STAR} below)\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
  "PSuf s \<equiv> {v. v \<noteq> [] \<and> (\<exists>u. u @ v = s)}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   149
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
lemma PSuf_snoc:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
  shows "PSuf (s @ [c]) = (PSuf s) ;; {[c]} \<union> {[c]}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
unfolding PSuf_def Sequ_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   153
by (auto simp add: append_eq_append_conv2 append_eq_Cons_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
lemma PSuf_Union:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
  shows "(\<Union>v \<in> PSuf s ;; {[c]}. f v) = (\<Union>v \<in> PSuf s. f (v @ [c]))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
by (auto simp add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
lemma pders_Set_snoc:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
  shows "pders_Set (PSuf s ;; {[c]}) r = (pder_set c (pders_Set (PSuf s) r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   161
unfolding pders_Set_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
by (simp add: PSuf_Union pders_snoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
lemma pders_SEQ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
  shows "pders s (SEQ r1 r2) \<subseteq> SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
proof (induct s rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
  case (snoc c s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
  have ih: "pders s (SEQ r1 r2) \<subseteq> SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   169
    by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   170
  have "pders (s @ [c]) (SEQ r1 r2) = pder_set c (pders s (SEQ r1 r2))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   171
    by (simp add: pders_snoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   172
  also have "\<dots> \<subseteq> pder_set c (SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   173
    using ih by fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
  also have "\<dots> = pder_set c (SEQs (pders s r1) r2) \<union> pder_set c (pders_Set (PSuf s) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   175
    by (simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   176
  also have "\<dots> = pder_set c (SEQs (pders s r1) r2) \<union> pders_Set (PSuf s ;; {[c]}) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   177
    by (simp add: pders_Set_snoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
  also 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
  have "\<dots> \<subseteq> pder_set c (SEQs (pders s r1) r2) \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   180
    by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
  also 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   182
  have "\<dots> \<subseteq> SEQs (pder_set c (pders s r1)) r2 \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   183
    by (auto simp add: if_splits)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   184
  also have "\<dots> = SEQs (pders (s @ [c]) r1) r2 \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   185
    by (simp add: pders_snoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   186
  also have "\<dots> \<subseteq> SEQs (pders (s @ [c]) r1) r2 \<union> pders_Set (PSuf (s @ [c])) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   187
    unfolding pders_Set_def by (auto simp add: PSuf_snoc)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   188
  finally show ?case .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   189
qed (simp) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   190
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   191
lemma pders_Set_SEQ_aux1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   192
  assumes a: "s \<in> UNIV1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   193
  shows "pders_Set (PSuf s) r \<subseteq> pders_Set UNIV1 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   194
using a unfolding UNIV1_def PSuf_def pders_Set_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   195
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
lemma pders_Set_SEQ_aux2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
  assumes a: "s \<in> UNIV1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
  shows "SEQs (pders s r1) r2 \<subseteq> SEQs (pders_Set UNIV1 r1) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
using a unfolding pders_Set_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
lemma pders_Set_SEQ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
  shows "pders_Set UNIV1 (SEQ r1 r2) \<subseteq> SEQs (pders_Set UNIV1 r1) r2 \<union> pders_Set UNIV1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
apply(rule pders_Set_subsetI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
apply(rule subset_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
apply(rule pders_SEQ)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
using pders_Set_SEQ_aux1 pders_Set_SEQ_aux2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   209
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
lemma pders_STAR:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
  assumes a: "s \<noteq> []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
  shows "pders s (STAR r) \<subseteq> SEQs (pders_Set (PSuf s) r) (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
using a
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   215
proof (induct s rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   216
  case (snoc c s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   217
  have ih: "s \<noteq> [] \<Longrightarrow> pders s (STAR r) \<subseteq> SEQs (pders_Set (PSuf s) r) (STAR r)" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   218
  { assume asm: "s \<noteq> []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   219
    have "pders (s @ [c]) (STAR r) = pder_set c (pders s (STAR r))" by (simp add: pders_snoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   220
    also have "\<dots> \<subseteq> pder_set c (SEQs (pders_Set (PSuf s) r) (STAR r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   221
      using ih[OF asm] by fast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   222
    also have "\<dots> \<subseteq> SEQs (pder_set c (pders_Set (PSuf s) r)) (STAR r) \<union> pder c (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   223
      by (auto split: if_splits)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   224
    also have "\<dots> \<subseteq> SEQs (pders_Set (PSuf (s @ [c])) r) (STAR r) \<union> (SEQs (pder c r) (STAR r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
      by (simp only: PSuf_snoc pders_Set_snoc pders_Set_union)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   226
         (auto simp add: pders_Set_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   227
    also have "\<dots> = SEQs (pders_Set (PSuf (s @ [c])) r) (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   228
      by (auto simp add: PSuf_snoc PSuf_Union pders_snoc pders_Set_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   229
    finally have ?case .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   230
  }
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  { assume asm: "s = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
    then have ?case by (auto simp add: pders_Set_def pders_snoc PSuf_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   234
  }
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   235
  ultimately show ?case by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   236
qed (simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
lemma pders_Set_STAR:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  shows "pders_Set UNIV1 (STAR r) \<subseteq> SEQs (pders_Set UNIV1 r) (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   240
apply(rule pders_Set_subsetI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   241
apply(rule subset_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   242
apply(rule pders_STAR)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
apply(simp add: UNIV1_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
apply(simp add: UNIV1_def PSuf_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
apply(auto simp add: pders_Set_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   248
lemma finite_SEQs [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   249
  assumes a: "finite A"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   250
  shows "finite (SEQs A r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   251
using a by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   252
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   253
thm finite.intros
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   254
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   255
lemma finite_pders_Set_UNIV1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   256
  shows "finite (pders_Set UNIV1 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   257
apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   258
apply(simp_all add: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   259
  finite_subset[OF pders_Set_SEQ]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
  finite_subset[OF pders_Set_STAR])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   262
    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   263
lemma pders_Set_UNIV:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
  shows "pders_Set UNIV r = pders [] r \<union> pders_Set UNIV1 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
unfolding UNIV1_def pders_Set_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
lemma finite_pders_Set_UNIV:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
  shows "finite (pders_Set UNIV r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
unfolding pders_Set_UNIV
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
by (simp add: finite_pders_Set_UNIV1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   273
lemma finite_pders_set:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   274
  shows "finite (pders_Set A r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   275
by (metis finite_pders_Set_UNIV pders_Set_subset rev_finite_subset subset_UNIV)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   276
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   277
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   278
text \<open>The following relationship between the alphabetic width of regular expressions
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   279
(called \<open>awidth\<close> below) and the number of partial derivatives was proved
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   280
by Antimirov~\cite{Antimirov95} and formalized by Max Haslbeck.\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   281
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   282
fun awidth :: "rexp \<Rightarrow> nat" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   283
"awidth ZERO = 0" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
"awidth ONE = 0" |
378
Chengsong
parents: 365
diff changeset
   285
"awidth (CH a) = 1" |
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
"awidth (ALT r1 r2) = awidth r1 + awidth r2" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   287
"awidth (SEQ r1 r2) = awidth r1 + awidth r2" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   288
"awidth (STAR r1) = awidth r1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   289
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
lemma card_SEQs_pders_Set_le:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
  shows  "card (SEQs (pders_Set A r) s) \<le> card (pders_Set A r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
  using finite_pders_set 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
  unfolding SEQs_eq_image 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
  by (rule card_image_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   295
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   296
lemma card_pders_set_UNIV1_le_awidth: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   297
  shows "card (pders_Set UNIV1 r) \<le> awidth r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   298
proof (induction r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
  case (ALT r1 r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
  have "card (pders_Set UNIV1 (ALT r1 r2)) = card (pders_Set UNIV1 r1 \<union> pders_Set UNIV1 r2)" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
  also have "\<dots> \<le> card (pders_Set UNIV1 r1) + card (pders_Set UNIV1 r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
    by(simp add: card_Un_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
  also have "\<dots> \<le> awidth (ALT r1 r2)" using ALT.IH by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
  finally show ?case .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
  case (SEQ r1 r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
  have "card (pders_Set UNIV1 (SEQ r1 r2)) \<le> card (SEQs (pders_Set UNIV1 r1) r2 \<union> pders_Set UNIV1 r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   308
    by (simp add: card_mono finite_pders_set pders_Set_SEQ)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   309
  also have "\<dots> \<le> card (SEQs (pders_Set UNIV1 r1) r2) + card (pders_Set UNIV1 r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   310
    by (simp add: card_Un_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   311
  also have "\<dots> \<le> card (pders_Set UNIV1 r1) + card (pders_Set UNIV1 r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
    by (simp add: card_SEQs_pders_Set_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   313
  also have "\<dots> \<le> awidth (SEQ r1 r2)" using SEQ.IH by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   314
  finally show ?case .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
  case (STAR r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   317
  have "card (pders_Set UNIV1 (STAR r)) \<le> card (SEQs (pders_Set UNIV1 r) (STAR r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   318
    by (simp add: card_mono finite_pders_set pders_Set_STAR)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   319
  also have "\<dots> \<le> card (pders_Set UNIV1 r)" by (rule card_SEQs_pders_Set_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   320
  also have "\<dots> \<le> awidth (STAR r)" by (simp add: STAR.IH)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
  finally show ?case .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
qed (auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
text\<open>Antimirov's Theorem 3.4:\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   326
theorem card_pders_set_UNIV_le_awidth: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   327
  shows "card (pders_Set UNIV r) \<le> awidth r + 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   328
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   329
  have "card (insert r (pders_Set UNIV1 r)) \<le> Suc (card (pders_Set UNIV1 r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   330
    by(auto simp: card_insert_if[OF finite_pders_Set_UNIV1])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   331
  also have "\<dots> \<le> Suc (awidth r)" by(simp add: card_pders_set_UNIV1_le_awidth)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   332
  finally show ?thesis by(simp add: pders_Set_UNIV)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   333
qed 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   334
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   335
text\<open>Antimirov's Corollary 3.5:\<close>
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   336
(*W stands for word set*)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
corollary card_pders_set_le_awidth: 
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   338
  shows "card (pders_Set W r) \<le> awidth r + 1"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   339
proof -
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   340
  have "card (pders_Set W r) \<le> card (pders_Set UNIV r)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   341
    by (simp add: card_mono finite_pders_set pders_Set_subset)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   342
  also have "... \<le> awidth r + 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   343
    by (rule card_pders_set_UNIV_le_awidth)
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   344
  finally show "card (pders_Set W r) \<le> awidth r + 1" by simp
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   345
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   346
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
(* other result by antimirov *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   348
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
lemma card_pders_awidth: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   350
  shows "card (pders s r) \<le> awidth r + 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   351
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
  have "pders s r \<subseteq> pders_Set UNIV r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   353
    using pders_Set_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
  then have "card (pders s r) \<le> card (pders_Set UNIV r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   355
    by (simp add: card_mono finite_pders_set)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   356
  then show "card (pders s r) \<le> awidth r + 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
    using card_pders_set_le_awidth order_trans by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   358
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   359
    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   360
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   361
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   362
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   363
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
fun subs :: "rexp \<Rightarrow> rexp set" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
"subs ZERO = {ZERO}" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   366
"subs ONE = {ONE}" |
378
Chengsong
parents: 365
diff changeset
   367
"subs (CH a) = {CH a, ONE}" |
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   368
"subs (ALT r1 r2) = (subs r1 \<union> subs r2 \<union> {ALT r1 r2})" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   369
"subs (SEQ r1 r2) = (subs r1 \<union> subs r2 \<union> {SEQ r1 r2} \<union>  SEQs (subs r1) r2)" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   370
"subs (STAR r1) = (subs r1 \<union> {STAR r1} \<union> SEQs (subs r1) (STAR r1))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   371
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   372
lemma subs_finite:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   373
  shows "finite (subs r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   374
  apply(induct r) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   375
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   376
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   377
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   378
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   379
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   380
lemma pders_subs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   381
  shows "pders s r \<subseteq> subs r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   382
  apply(induct r arbitrary: s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   383
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   384
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   385
     apply(simp add: pders_CHAR)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   386
(*  SEQ case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   387
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   388
    apply(rule subset_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   389
     apply(rule pders_SEQ)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   390
    defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   391
(* ALT case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   392
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   393
    apply(rule impI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   394
    apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   395
  apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   396
    apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   397
(* STAR case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   398
    apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   399
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   400
   apply(rule subset_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   401
  thm pders_STAR
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   402
     apply(rule pders_STAR)
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   403
    apply(simp)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   404
   apply(auto simp add: pders_Set_def)[1]
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   405
(* rest of SEQ case *)  
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   406
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   407
  apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   408
   apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   409
apply(auto simp add: pders_Set_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   410
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   411
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   412
fun size2 :: "rexp \<Rightarrow> nat" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   413
  "size2 ZERO = 1" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   414
  "size2 ONE = 1" |
378
Chengsong
parents: 365
diff changeset
   415
  "size2 (CH c) = 1" |
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   416
  "size2 (ALT r1 r2) = Suc (size2 r1 + size2 r2)" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   417
  "size2 (SEQ r1 r2) = Suc (size2 r1 + size2 r2)" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   418
  "size2 (STAR r1) = Suc (size2 r1)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   419
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   420
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   421
lemma size_rexp:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   422
  fixes r :: rexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   423
  shows "1 \<le> size2 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   424
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   425
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   426
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   427
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   428
378
Chengsong
parents: 365
diff changeset
   429
(*
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   430
lemma subs_card:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   431
  shows "card (subs r) \<le> Suc (size2 r + size2 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   432
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   433
       apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   434
    apply(subst card_insert)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   435
     apply(simp add: subs_finite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   436
    apply(simp add: subs_finite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   437
  oops
378
Chengsong
parents: 365
diff changeset
   438
*)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   439
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   440
lemma subs_size2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   441
  shows "\<forall>r1 \<in> subs r. size2 r1 \<le> Suc (size2 r * size2 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   442
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   443
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   444
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   445
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   446
(* SEQ case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   447
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   448
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   449
  apply (smt Suc_n_not_le_n add.commute distrib_left le_Suc_eq left_add_mult_distrib nat_le_linear trans_le_add1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   450
  apply (smt Suc_le_mono Suc_n_not_le_n le_trans nat_le_linear power2_eq_square power2_sum semiring_normalization_rules(23) trans_le_add2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   451
  apply (smt Groups.add_ac(3) Suc_n_not_le_n distrib_left le_Suc_eq left_add_mult_distrib nat_le_linear trans_le_add1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   452
(*  ALT case  *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   453
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   454
   apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   455
  apply (smt Groups.add_ac(2) Suc_le_mono Suc_n_not_le_n le_add2 linear order_trans power2_eq_square power2_sum)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   456
  apply (smt Groups.add_ac(2) Suc_le_mono Suc_n_not_le_n left_add_mult_distrib linear mult.commute order.trans trans_le_add1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   457
(* STAR case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   458
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   459
  apply(drule_tac x="r'" in bspec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   460
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   461
  apply(rule le_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   462
   apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   463
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   464
  using size_rexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   465
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   466
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   467
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   468
lemma awidth_size:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   469
  shows "awidth r \<le> size2 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   470
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   471
       apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   472
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   473
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   474
lemma Sum1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   475
  fixes A B :: "nat set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   476
  assumes "A \<subseteq> B" "finite A" "finite B"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   477
  shows "\<Sum>A \<le> \<Sum>B"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   478
  using  assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   479
  by (simp add: sum_mono2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   480
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   481
lemma Sum2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   482
  fixes A :: "rexp set"  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   483
  and   f g :: "rexp \<Rightarrow> nat" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   484
  assumes "finite A" "\<forall>x \<in> A. f x \<le> g x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   485
  shows "sum f A \<le> sum g A"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   486
  using  assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   487
  apply(induct A)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   488
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   489
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   490
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   491
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   492
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   493
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   494
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   495
lemma pders_max_size:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   496
  shows "(sum size2 (pders s r)) \<le> (Suc (size2 r)) ^ 3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   497
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   498
  have "(sum size2 (pders s r)) \<le> sum (\<lambda>_. Suc (size2 r  * size2 r)) (pders s r)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   499
    apply(rule_tac Sum2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   500
     apply (meson pders_subs rev_finite_subset subs_finite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   501
    using pders_subs subs_size2 by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   502
  also have "... \<le> (Suc (size2 r  * size2 r)) * (sum (\<lambda>_. 1) (pders s r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   503
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   504
  also have "... \<le> (Suc (size2 r  * size2 r)) * card (pders s r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   505
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   506
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (awidth r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   507
    using Suc_eq_plus1 card_pders_awidth mult_le_mono2 by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   508
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (size2 r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   509
    using Suc_le_mono awidth_size mult_le_mono2 by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   510
  also have "... \<le> (Suc (size2 r)) ^ 3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   511
    by (smt One_nat_def Suc_1 Suc_mult_le_cancel1 Suc_n_not_le_n antisym_conv le_Suc_eq mult.commute nat_le_linear numeral_3_eq_3 power2_eq_square power2_le_imp_le power_Suc size_rexp)    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   512
  finally show ?thesis  .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   513
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   514
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   515
lemma pders_Set_max_size:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   516
  shows "(sum size2 (pders_Set A r)) \<le> (Suc (size2 r)) ^ 3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   517
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   518
  have "(sum size2 (pders_Set A r)) \<le> sum (\<lambda>_. Suc (size2 r  * size2 r)) (pders_Set A r)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   519
    apply(rule_tac Sum2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   520
     apply (simp add: finite_pders_set)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   521
    by (meson pders_Set_subsetI pders_subs subs_size2 subsetD)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   522
  also have "... \<le> (Suc (size2 r  * size2 r)) * (sum (\<lambda>_. 1) (pders_Set A r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   523
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   524
  also have "... \<le> (Suc (size2 r  * size2 r)) * card (pders_Set A r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   525
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   526
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (awidth r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   527
    using Suc_eq_plus1 card_pders_set_le_awidth mult_le_mono2 by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   528
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (size2 r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   529
    using Suc_le_mono awidth_size mult_le_mono2 by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   530
  also have "... \<le> (Suc (size2 r)) ^ 3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   531
    by (smt One_nat_def Suc_1 Suc_mult_le_cancel1 Suc_n_not_le_n antisym_conv le_Suc_eq mult.commute nat_le_linear numeral_3_eq_3 power2_eq_square power2_le_imp_le power_Suc size_rexp)    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   532
  finally show ?thesis  .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   533
qed    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   534
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   535
fun height :: "rexp \<Rightarrow> nat" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   536
  "height ZERO = 1" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   537
  "height ONE = 1" |
378
Chengsong
parents: 365
diff changeset
   538
  "height (CH c) = 1" |
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   539
  "height (ALT r1 r2) = Suc (max (height r1) (height r2))" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   540
  "height (SEQ r1 r2) = Suc (max (height r1) (height r2))" |
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   541
  "height (STAR r1) = Suc (height r1)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   542
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   543
lemma height_size2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   544
  shows "height r \<le> size2 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   545
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   546
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   547
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   548
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   549
lemma height_rexp:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   550
  fixes r :: rexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   551
  shows "1 \<le> height r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   552
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   553
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   554
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   555
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   556
lemma subs_height:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   557
  shows "\<forall>r1 \<in> subs r. height r1 \<le> Suc (height r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   558
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   559
  apply(auto)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   560
  done  
378
Chengsong
parents: 365
diff changeset
   561
Chengsong
parents: 365
diff changeset
   562
fun lin_concat :: "(char \<times> rexp) \<Rightarrow> rexp \<Rightarrow> (char \<times> rexp)" (infixl "[.]" 91)
Chengsong
parents: 365
diff changeset
   563
  where
Chengsong
parents: 365
diff changeset
   564
"(c, ZERO) [.] t = (c, ZERO)"
Chengsong
parents: 365
diff changeset
   565
| "(c, ONE) [.] t = (c, t)"
Chengsong
parents: 365
diff changeset
   566
| "(c, p) [.] t = (c, SEQ p t)"
Chengsong
parents: 365
diff changeset
   567
Chengsong
parents: 365
diff changeset
   568
Chengsong
parents: 365
diff changeset
   569
fun circle_concat :: "(char \<times> rexp ) set \<Rightarrow> rexp \<Rightarrow> (char \<times> rexp) set" ( infixl "\<circle>" 90)
Chengsong
parents: 365
diff changeset
   570
  where
Chengsong
parents: 365
diff changeset
   571
"l \<circle> ZERO = {}"
Chengsong
parents: 365
diff changeset
   572
| "l \<circle> ONE = l"
Chengsong
parents: 365
diff changeset
   573
| "l \<circle> t  = ( (\<lambda>p.  p [.] t) ` l ) "
Chengsong
parents: 365
diff changeset
   574
Chengsong
parents: 365
diff changeset
   575
Chengsong
parents: 365
diff changeset
   576
Chengsong
parents: 365
diff changeset
   577
fun linear_form :: "rexp \<Rightarrow>( char \<times> rexp ) set" 
Chengsong
parents: 365
diff changeset
   578
  where
Chengsong
parents: 365
diff changeset
   579
  "linear_form ZERO = {}"
Chengsong
parents: 365
diff changeset
   580
| "linear_form ONE = {}"
Chengsong
parents: 365
diff changeset
   581
| "linear_form (CH c)  = {(c, ONE)}"
Chengsong
parents: 365
diff changeset
   582
| "linear_form (ALT r1 r2) = (linear_form) r1 \<union> (linear_form r2)"
Chengsong
parents: 365
diff changeset
   583
| "linear_form (SEQ r1 r2) = (if (nullable r1) then (linear_form r1) \<circle> r2 \<union> linear_form r2 else  (linear_form r1) \<circle> r2) "
Chengsong
parents: 365
diff changeset
   584
| "linear_form (STAR r ) = (linear_form r) \<circle> (STAR r)"
Chengsong
parents: 365
diff changeset
   585
Chengsong
parents: 365
diff changeset
   586
Chengsong
parents: 365
diff changeset
   587
value "linear_form (SEQ (STAR (CH x)) (STAR (ALT (SEQ (CH x) (CH x)) (CH y)  ))  )"
Chengsong
parents: 365
diff changeset
   588
Chengsong
parents: 365
diff changeset
   589
Chengsong
parents: 365
diff changeset
   590
value "linear_form  (STAR (ALT (SEQ (CH x) (CH x)) (CH y)  ))  "
Chengsong
parents: 365
diff changeset
   591
Chengsong
parents: 365
diff changeset
   592
fun pdero :: "char \<Rightarrow> rexp \<Rightarrow> rexp set"
Chengsong
parents: 365
diff changeset
   593
  where
Chengsong
parents: 365
diff changeset
   594
"pdero c t  = \<Union> ((\<lambda>(d, p). if d = c then {p} else {}) ` (linear_form t) )"
Chengsong
parents: 365
diff changeset
   595
Chengsong
parents: 365
diff changeset
   596
fun pderso :: "char list \<Rightarrow> rexp \<Rightarrow> rexp set"
Chengsong
parents: 365
diff changeset
   597
  where
Chengsong
parents: 365
diff changeset
   598
  "pderso [] r = {r}"
Chengsong
parents: 365
diff changeset
   599
|  "pderso (c # s) r = \<Union> ( pderso s ` (pdero c r) )"
Chengsong
parents: 365
diff changeset
   600
Chengsong
parents: 365
diff changeset
   601
lemma alternative_pder: 
Chengsong
parents: 365
diff changeset
   602
  shows "pderso s r = pders s r"
Chengsong
parents: 365
diff changeset
   603
  sledgehammer
Chengsong
parents: 365
diff changeset
   604
  oops
Chengsong
parents: 365
diff changeset
   605
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   606
lemma pdero_result: 
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   607
  shows "pdero  c (STAR (ALT (CH c) (SEQ (CH c) (CH c)))) =  {SEQ (CH c)(STAR (ALT (CH c) (SEQ (CH c) (CH c)))),(STAR (ALT (CH c) (SEQ (CH c) (CH c))))}"
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   608
  apply(simp)
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   609
  by auto
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   610
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   611
fun concatLen :: "rexp \<Rightarrow> nat" where
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   612
"concatLen ZERO = 0" |
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   613
"concatLen ONE = 0" |
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   614
"concatLen (CH c) = 0" |
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   615
"concatLen (SEQ v1 v2) = Suc (max (concatLen v1) (concatLen v2))" |
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   616
" concatLen (ALT v1 v2) =  max (concatLen v1) (concatLen v2)" |
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   617
" concatLen (STAR v) = Suc (concatLen v)" 
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   618
388
Chengsong
parents: 387
diff changeset
   619
text\<open>Antimirov's Theorem 3.8:\<close>
Chengsong
parents: 387
diff changeset
   620
lemma Maxsubterms38:
Chengsong
parents: 387
diff changeset
   621
  shows "\<forall>pt \<in> (pders_Set UNIV t). pt \<in> (subs t) \<or> pt = ONE \<or> pt = (SEQ t0 t1)"
389
d4b3b0f942f4 aaastar
Chengsong
parents: 388
diff changeset
   622
  oops
d4b3b0f942f4 aaastar
Chengsong
parents: 388
diff changeset
   623
388
Chengsong
parents: 387
diff changeset
   624
387
b257b9ba8a25 concatlen
Chengsong
parents: 378
diff changeset
   625
378
Chengsong
parents: 365
diff changeset
   626
Chengsong
parents: 365
diff changeset
   627
export_code height pders subs pderso in Scala module_name Pders 
Chengsong
parents: 365
diff changeset
   628
export_code pdero pderso in Scala module_name Pderso
Chengsong
parents: 365
diff changeset
   629
export_code pdero pderso in Scala module_name Pderso
Chengsong
parents: 365
diff changeset
   630
Chengsong
parents: 365
diff changeset
   631
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   632
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   633
end