Derivatives.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 22 Dec 2013 07:37:26 +0000
changeset 393 058f29ab515c
parent 379 8c4b6fb43ebe
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
241
68d48522ea9a tuning on the derivatives and closures theories
urbanc
parents: 203
diff changeset
     1
header "Derivatives of regular expressions"
68d48522ea9a tuning on the derivatives and closures theories
urbanc
parents: 203
diff changeset
     2
68d48522ea9a tuning on the derivatives and closures theories
urbanc
parents: 203
diff changeset
     3
(* Author: Christian Urban *)
68d48522ea9a tuning on the derivatives and closures theories
urbanc
parents: 203
diff changeset
     4
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
     5
theory Derivatives
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
     6
imports Regular_Exp
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
     7
begin
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
     8
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
     9
text{* This theory is based on work by Brozowski \cite{Brzozowski64} and Antimirov \cite{Antimirov95}. *}
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    10
241
68d48522ea9a tuning on the derivatives and closures theories
urbanc
parents: 203
diff changeset
    11
subsection {* Brozowski's derivatives of regular expressions *}
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    12
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    13
fun
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    14
  deriv :: "'a \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    15
where
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    16
  "deriv c (Zero) = Zero"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    17
| "deriv c (One) = Zero"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    18
| "deriv c (Atom c') = (if c = c' then One else Zero)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    19
| "deriv c (Plus r1 r2) = Plus (deriv c r1) (deriv c r2)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    20
| "deriv c (Times r1 r2) = 
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    21
    (if nullable r1 then Plus (Times (deriv c r1) r2) (deriv c r2) else Times (deriv c r1) r2)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    22
| "deriv c (Star r) = Times (deriv c r) (Star r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    23
179
edacc141060f small improvements
urbanc
parents: 174
diff changeset
    24
fun 
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    25
  derivs :: "'a list \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    26
where
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    27
  "derivs [] r = r"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    28
| "derivs (c # s) r = derivs s (deriv c r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    29
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    30
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    31
lemma lang_deriv: "lang (deriv c r) = Deriv c (lang r)"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    32
by (induct r) (simp_all add: nullable_iff)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    33
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    34
lemma lang_derivs: "lang (derivs s r) = Derivs s (lang r)"
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    35
by (induct s arbitrary: r) (simp_all add: lang_deriv)
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    36
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    37
text {* A regular expression matcher: *}
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    38
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    39
definition matcher :: "'a rexp \<Rightarrow> 'a list \<Rightarrow> bool" where
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    40
"matcher r s = nullable (derivs s r)"
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    41
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    42
lemma matcher_correctness: "matcher r s \<longleftrightarrow> s \<in> lang r"
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    43
by (induct s arbitrary: r)
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    44
   (simp_all add: nullable_iff lang_deriv matcher_def Deriv_def)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    45
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    46
246
urbanc
parents: 241
diff changeset
    47
subsection {* Antimirov's partial derivatives *}
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    48
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    49
abbreviation
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    50
  "Timess rs r \<equiv> (\<Union>r' \<in> rs. {Times r' r})"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    51
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    52
fun
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    53
  pderiv :: "'a \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp set"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    54
where
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    55
  "pderiv c Zero = {}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    56
| "pderiv c One = {}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    57
| "pderiv c (Atom c') = (if c = c' then {One} else {})"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    58
| "pderiv c (Plus r1 r2) = (pderiv c r1) \<union> (pderiv c r2)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    59
| "pderiv c (Times r1 r2) = 
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    60
    (if nullable r1 then Timess (pderiv c r1) r2 \<union> pderiv c r2 else Timess (pderiv c r1) r2)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    61
| "pderiv c (Star r) = Timess (pderiv c r) (Star r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    62
179
edacc141060f small improvements
urbanc
parents: 174
diff changeset
    63
fun
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    64
  pderivs :: "'a list \<Rightarrow> 'a rexp \<Rightarrow> ('a rexp) set"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    65
where
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    66
  "pderivs [] r = {r}"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    67
| "pderivs (c # s) r = \<Union> (pderivs s ` pderiv c r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    68
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    69
abbreviation
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    70
 pderiv_set :: "'a \<Rightarrow> 'a rexp set \<Rightarrow> 'a rexp set"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    71
where
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    72
  "pderiv_set c rs \<equiv> \<Union> (pderiv c ` rs)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    73
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    74
abbreviation
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    75
  pderivs_set :: "'a list \<Rightarrow> 'a rexp set \<Rightarrow> 'a rexp set"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    76
where
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    77
  "pderivs_set s rs \<equiv> \<Union> (pderivs s ` rs)"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    78
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    79
lemma pderivs_append:
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
    80
  "pderivs (s1 @ s2) r = \<Union> (pderivs s2 ` pderivs s1 r)"
179
edacc141060f small improvements
urbanc
parents: 174
diff changeset
    81
by (induct s1 arbitrary: r) (simp_all)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    82
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    83
lemma pderivs_snoc:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    84
  shows "pderivs (s @ [c]) r = pderiv_set c (pderivs s r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    85
by (simp add: pderivs_append)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    86
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    87
lemma pderivs_simps [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    88
  shows "pderivs s Zero = (if s = [] then {Zero} else {})"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    89
  and   "pderivs s One = (if s = [] then {One} else {})"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    90
  and   "pderivs s (Plus r1 r2) = (if s = [] then {Plus r1 r2} else (pderivs s r1) \<union> (pderivs s r2))"
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
    91
by (induct s) (simp_all)
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
    92
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    93
lemma pderivs_Atom:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    94
  shows "pderivs s (Atom c) \<subseteq> {Atom c, One}"
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
    95
by (induct s) (simp_all)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
    96
246
urbanc
parents: 241
diff changeset
    97
subsection {* Relating left-quotients and partial derivatives *}
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
    98
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
    99
lemma Deriv_pderiv:
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   100
  shows "Deriv c (lang r) = \<Union> (lang ` pderiv c r)"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   101
by (induct r) (auto simp add: nullable_iff conc_UNION_distrib)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   102
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   103
lemma Derivs_pderivs:
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   104
  shows "Derivs s (lang r) = \<Union> (lang ` pderivs s r)"
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   105
proof (induct s arbitrary: r)
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   106
  case (Cons c s)
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   107
  have ih: "\<And>r. Derivs s (lang r) = \<Union> (lang ` pderivs s r)" by fact
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   108
  have "Derivs (c # s) (lang r) = Derivs s (Deriv c (lang r))" by simp
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   109
  also have "\<dots> = Derivs s (\<Union> (lang ` pderiv c r))" by (simp add: Deriv_pderiv)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   110
  also have "\<dots> = Derivss s (lang ` (pderiv c r))"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   111
    by (auto simp add:  Derivs_def)
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   112
  also have "\<dots> = \<Union> (lang ` (pderivs_set s (pderiv c r)))"
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   113
    using ih by auto
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   114
  also have "\<dots> = \<Union> (lang ` (pderivs (c # s) r))" by simp
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   115
  finally show "Derivs (c # s) (lang r) = \<Union> (lang ` pderivs (c # s) r)" .
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   116
qed (simp add: Derivs_def)
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   117
246
urbanc
parents: 241
diff changeset
   118
subsection {* Relating derivatives and partial derivatives *}
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   119
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   120
lemma deriv_pderiv:
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   121
  shows "\<Union> (lang ` (pderiv c r)) = lang (deriv c r)"
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   122
unfolding lang_deriv Deriv_pderiv by simp
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   123
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   124
lemma derivs_pderivs:
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   125
  shows "\<Union> (lang ` (pderivs s r)) = lang (derivs s r)"
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   126
unfolding lang_derivs Derivs_pderivs by simp
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   127
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   128
246
urbanc
parents: 241
diff changeset
   129
subsection {* Finiteness property of partial derivatives *}
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   130
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   131
definition
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   132
  pderivs_lang :: "'a lang \<Rightarrow> 'a rexp \<Rightarrow> 'a rexp set"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   133
where
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   134
  "pderivs_lang A r \<equiv> \<Union>x \<in> A. pderivs x r"
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   135
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   136
lemma pderivs_lang_subsetI:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   137
  assumes "\<And>s. s \<in> A \<Longrightarrow> pderivs s r \<subseteq> C"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   138
  shows "pderivs_lang A r \<subseteq> C"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   139
using assms unfolding pderivs_lang_def by (rule UN_least)
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   140
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   141
lemma pderivs_lang_union:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   142
  shows "pderivs_lang (A \<union> B) r = (pderivs_lang A r \<union> pderivs_lang B r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   143
by (simp add: pderivs_lang_def)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   144
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   145
lemma pderivs_lang_subset:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   146
  shows "A \<subseteq> B \<Longrightarrow> pderivs_lang A r \<subseteq> pderivs_lang B r"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   147
by (auto simp add: pderivs_lang_def)
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   148
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   149
definition
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   150
  "UNIV1 \<equiv> UNIV - {[]}"
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   151
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   152
lemma pderivs_lang_Zero [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   153
  shows "pderivs_lang UNIV1 Zero = {}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   154
unfolding UNIV1_def pderivs_lang_def by auto
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   155
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   156
lemma pderivs_lang_One [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   157
  shows "pderivs_lang UNIV1 One = {}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   158
unfolding UNIV1_def pderivs_lang_def by (auto split: if_splits)
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   159
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   160
lemma pderivs_lang_Atom [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   161
  shows "pderivs_lang UNIV1 (Atom c) = {One}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   162
unfolding UNIV1_def pderivs_lang_def 
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   163
apply(auto)
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   164
apply(frule rev_subsetD)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   165
apply(rule pderivs_Atom)
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   166
apply(simp)
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   167
apply(case_tac xa)
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   168
apply(auto split: if_splits)
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   169
done
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   170
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   171
lemma pderivs_lang_Plus [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   172
  shows "pderivs_lang UNIV1 (Plus r1 r2) = pderivs_lang UNIV1 r1 \<union> pderivs_lang UNIV1 r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   173
unfolding UNIV1_def pderivs_lang_def by auto
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   174
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   175
246
urbanc
parents: 241
diff changeset
   176
text {* Non-empty suffixes of a string (needed for the cases of @{const Times} and @{const Star} below) *}
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   177
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   178
definition
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   179
  "PSuf s \<equiv> {v. v \<noteq> [] \<and> (\<exists>u. u @ v = s)}"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   180
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   181
lemma PSuf_snoc:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   182
  shows "PSuf (s @ [c]) = (PSuf s) @@ {[c]} \<union> {[c]}"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   183
unfolding PSuf_def conc_def
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   184
by (auto simp add: append_eq_append_conv2 append_eq_Cons_conv)
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   185
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   186
lemma PSuf_Union:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   187
  shows "(\<Union>v \<in> PSuf s @@ {[c]}. f v) = (\<Union>v \<in> PSuf s. f (v @ [c]))"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   188
by (auto simp add: conc_def)
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   189
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   190
lemma pderivs_lang_snoc:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   191
  shows "pderivs_lang (PSuf s @@ {[c]}) r = (pderiv_set c (pderivs_lang (PSuf s) r))"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   192
unfolding pderivs_lang_def
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   193
by (simp add: PSuf_Union pderivs_snoc)
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   194
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   195
lemma pderivs_Times:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   196
  shows "pderivs s (Times r1 r2) \<subseteq> Timess (pderivs s r1) r2 \<union> (pderivs_lang (PSuf s) r2)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   197
proof (induct s rule: rev_induct)
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   198
  case (snoc c s)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   199
  have ih: "pderivs s (Times r1 r2) \<subseteq> Timess (pderivs s r1) r2 \<union> (pderivs_lang (PSuf s) r2)" 
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   200
    by fact
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   201
  have "pderivs (s @ [c]) (Times r1 r2) = pderiv_set c (pderivs s (Times r1 r2))" 
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   202
    by (simp add: pderivs_snoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   203
  also have "\<dots> \<subseteq> pderiv_set c (Timess (pderivs s r1) r2 \<union> (pderivs_lang (PSuf s) r2))"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   204
    using ih by fast
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   205
  also have "\<dots> = pderiv_set c (Timess (pderivs s r1) r2) \<union> pderiv_set c (pderivs_lang (PSuf s) r2)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   206
    by (simp)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   207
  also have "\<dots> = pderiv_set c (Timess (pderivs s r1) r2) \<union> pderivs_lang (PSuf s @@ {[c]}) r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   208
    by (simp add: pderivs_lang_snoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   209
  also 
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   210
  have "\<dots> \<subseteq> pderiv_set c (Timess (pderivs s r1) r2) \<union> pderiv c r2 \<union> pderivs_lang (PSuf s @@ {[c]}) r2"
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   211
    by auto
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   212
  also 
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   213
  have "\<dots> \<subseteq> Timess (pderiv_set c (pderivs s r1)) r2 \<union> pderiv c r2 \<union> pderivs_lang (PSuf s @@ {[c]}) r2"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   214
    by (auto simp add: if_splits)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   215
  also have "\<dots> = Timess (pderivs (s @ [c]) r1) r2 \<union> pderiv c r2 \<union> pderivs_lang (PSuf s @@ {[c]}) r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   216
    by (simp add: pderivs_snoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   217
  also have "\<dots> \<subseteq> Timess (pderivs (s @ [c]) r1) r2 \<union> pderivs_lang (PSuf (s @ [c])) r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   218
    unfolding pderivs_lang_def by (auto simp add: PSuf_snoc)  
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   219
  finally show ?case .
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   220
qed (simp) 
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   221
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   222
lemma pderivs_lang_Times_aux1:
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   223
  assumes a: "s \<in> UNIV1"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   224
  shows "pderivs_lang (PSuf s) r \<subseteq> pderivs_lang UNIV1 r"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   225
using a unfolding UNIV1_def PSuf_def pderivs_lang_def by auto
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   226
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   227
lemma pderivs_lang_Times_aux2:
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   228
  assumes a: "s \<in> UNIV1"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   229
  shows "Timess (pderivs s r1) r2 \<subseteq> Timess (pderivs_lang UNIV1 r1) r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   230
using a unfolding pderivs_lang_def by auto
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   231
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   232
lemma pderivs_lang_Times:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   233
  shows "pderivs_lang UNIV1 (Times r1 r2) \<subseteq> Timess (pderivs_lang UNIV1 r1) r2 \<union> pderivs_lang UNIV1 r2"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   234
apply(rule pderivs_lang_subsetI)
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   235
apply(rule subset_trans)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   236
apply(rule pderivs_Times)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   237
using pderivs_lang_Times_aux1 pderivs_lang_Times_aux2
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   238
apply(blast)
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   239
done
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   240
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   241
lemma pderivs_Star:
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   242
  assumes a: "s \<noteq> []"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   243
  shows "pderivs s (Star r) \<subseteq> Timess (pderivs_lang (PSuf s) r) (Star r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   244
using a
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   245
proof (induct s rule: rev_induct)
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   246
  case (snoc c s)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   247
  have ih: "s \<noteq> [] \<Longrightarrow> pderivs s (Star r) \<subseteq> Timess (pderivs_lang (PSuf s) r) (Star r)" by fact
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   248
  { assume asm: "s \<noteq> []"
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   249
    have "pderivs (s @ [c]) (Star r) = pderiv_set c (pderivs s (Star r))" by (simp add: pderivs_snoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   250
    also have "\<dots> \<subseteq> pderiv_set c (Timess (pderivs_lang (PSuf s) r) (Star r))"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   251
      using ih[OF asm] by fast
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   252
    also have "\<dots> \<subseteq> Timess (pderiv_set c (pderivs_lang (PSuf s) r)) (Star r) \<union> pderiv c (Star r)"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   253
      by (auto split: if_splits)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   254
    also have "\<dots> \<subseteq> Timess (pderivs_lang (PSuf (s @ [c])) r) (Star r) \<union> (Timess (pderiv c r) (Star r))"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   255
      by (simp only: PSuf_snoc pderivs_lang_snoc pderivs_lang_union)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   256
         (auto simp add: pderivs_lang_def)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   257
    also have "\<dots> = Timess (pderivs_lang (PSuf (s @ [c])) r) (Star r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   258
      by (auto simp add: PSuf_snoc PSuf_Union pderivs_snoc pderivs_lang_def)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   259
    finally have ?case .
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   260
  }
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   261
  moreover
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   262
  { assume asm: "s = []"
379
8c4b6fb43ebe polished more and updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   263
    then have ?case by (auto simp add: pderivs_lang_def pderivs_snoc PSuf_def)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   264
  }
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   265
  ultimately show ?case by blast
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   266
qed (simp)
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   267
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   268
lemma pderivs_lang_Star:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   269
  shows "pderivs_lang UNIV1 (Star r) \<subseteq> Timess (pderivs_lang UNIV1 r) (Star r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   270
apply(rule pderivs_lang_subsetI)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   271
apply(rule subset_trans)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   272
apply(rule pderivs_Star)
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   273
apply(simp add: UNIV1_def)
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   274
apply(simp add: UNIV1_def PSuf_def)
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   275
apply(auto simp add: pderivs_lang_def)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   276
done
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   277
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   278
lemma finite_Timess [simp]:
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   279
  assumes a: "finite A"
187
9f46a9571e37 more on the derivatives section
urbanc
parents: 181
diff changeset
   280
  shows "finite (Timess A r)"
190
b73478aaf33e more on paper
urbanc
parents: 187
diff changeset
   281
using a by auto
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   282
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   283
lemma finite_pderivs_lang_UNIV1:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   284
  shows "finite (pderivs_lang UNIV1 r)"
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   285
apply(induct r)
193
2a5ac68db24b finished section about derivatives and closure properties
urbanc
parents: 191
diff changeset
   286
apply(simp_all add: 
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   287
  finite_subset[OF pderivs_lang_Times]
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   288
  finite_subset[OF pderivs_lang_Star])
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   289
done
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   290
    
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   291
lemma pderivs_lang_UNIV:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   292
  shows "pderivs_lang UNIV r = pderivs [] r \<union> pderivs_lang UNIV1 r"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   293
unfolding UNIV1_def pderivs_lang_def
191
f6a603be52d6 slight polishing
urbanc
parents: 190
diff changeset
   294
by blast
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   295
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   296
lemma finite_pderivs_lang_UNIV:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   297
  shows "finite (pderivs_lang UNIV r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   298
unfolding pderivs_lang_UNIV
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   299
by (simp add: finite_pderivs_lang_UNIV1)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   300
203
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   301
lemma finite_pderivs_lang:
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   302
  shows "finite (pderivs_lang A r)"
5d724fe0e096 changes according to afp-submission
urbanc
parents: 195
diff changeset
   303
by (metis finite_pderivs_lang_UNIV pderivs_lang_subset rev_finite_subset subset_UNIV)
170
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   304
b1258b7d2789 made the theories compatible with the existing developments in the AFP; old theories are in the directory Attic
urbanc
parents:
diff changeset
   305
end