thys/PDerivs.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 17 Feb 2019 22:15:06 +0000
changeset 311 8b8db9558ecf
parent 309 a7769a89c529
child 312 8b0b414e71b0
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
   
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     2
theory PDerivs
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     3
  imports Spec
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     6
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     7
  "SEQs rs r \<equiv> (\<Union>r' \<in> rs. {SEQ r' r})"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
     9
lemma SEQs_eq_image:
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    10
  "SEQs rs r = (\<lambda>r'. SEQ r' r) ` rs"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    11
  by auto
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    12
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    13
primrec
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    14
  pder :: "char \<Rightarrow> rexp \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    15
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    16
  "pder c ZERO = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    17
| "pder c ONE = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    18
| "pder c (CHAR d) = (if c = d then {ONE} else {})"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    19
| "pder c (ALT r1 r2) = (pder c r1) \<union> (pder c r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    20
| "pder c (SEQ r1 r2) = 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    21
    (if nullable r1 then SEQs (pder c r1) r2 \<union> pder c r2 else SEQs (pder c r1) r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    22
| "pder c (STAR r) = SEQs (pder c r) (STAR r)"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    24
primrec
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    25
  pders :: "char list \<Rightarrow> rexp \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    26
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    27
  "pders [] r = {r}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    28
| "pders (c # s) r = \<Union> (pders s ` pder c r)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    29
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    30
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    31
 pder_set :: "char \<Rightarrow> rexp set \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    32
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    33
  "pder_set c rs \<equiv> \<Union> (pder c ` rs)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    34
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    35
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    36
  pders_set :: "char list \<Rightarrow> rexp set \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    37
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    38
  "pders_set s rs \<equiv> \<Union> (pders s ` rs)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    39
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    40
lemma pders_append:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    41
  "pders (s1 @ s2) r = \<Union> (pders s2 ` pders s1 r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    42
by (induct s1 arbitrary: r) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    44
lemma pders_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    45
  shows "pders (s @ [c]) r = pder_set c (pders s r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    46
by (simp add: pders_append)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    47
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    48
lemma pders_simps [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    49
  shows "pders s ZERO = (if s = [] then {ZERO} else {})"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    50
  and   "pders s ONE = (if s = [] then {ONE} else {})"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    51
  and   "pders s (ALT r1 r2) = (if s = [] then {ALT r1 r2} else (pders s r1) \<union> (pders s r2))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    52
by (induct s) (simp_all)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    53
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    54
lemma pders_CHAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    55
  shows "pders s (CHAR c) \<subseteq> {CHAR c, ONE}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    56
by (induct s) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    58
subsection \<open>Relating left-quotients and partial derivatives\<close>
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    59
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    60
lemma Sequ_UNION_distrib:
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
    61
shows "A ;; \<Union>(M ` I) = \<Union>((\<lambda>i. A ;; M i) ` I)"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
    62
and   "\<Union>(M ` I) ;; A = \<Union>((\<lambda>i. M i ;; A) ` I)"
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    63
by (auto simp add: Sequ_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    64
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    65
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    66
lemma Der_pder:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    67
  shows "Der c (L r) = \<Union> (L ` pder c r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    68
by (induct r) (simp_all add: nullable_correctness Sequ_UNION_distrib)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    69
  
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    70
lemma Ders_pders:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    71
  shows "Ders s (L r) = \<Union> (L ` pders s r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    72
proof (induct s arbitrary: r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    73
  case (Cons c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    74
  have ih: "\<And>r. Ders s (L r) = \<Union> (L ` pders s r)" by fact
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    75
  have "Ders (c # s) (L r) = Ders s (Der c (L r))" by (simp add: Ders_def Der_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    76
  also have "\<dots> = Ders s (\<Union> (L ` pder c r))" by (simp add: Der_pder)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    77
  also have "\<dots> = (\<Union>A\<in>(L ` (pder c r)). (Ders s A))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    78
    by (auto simp add:  Ders_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    79
  also have "\<dots> = \<Union> (L ` (pders_set s (pder c r)))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    80
    using ih by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    81
  also have "\<dots> = \<Union> (L ` (pders (c # s) r))" by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    82
  finally show "Ders (c # s) (L r) = \<Union> (L ` pders (c # s) r)" .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    83
qed (simp add: Ders_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    84
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    85
subsection \<open>Relating derivatives and partial derivatives\<close>
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    86
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    87
lemma der_pder:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    88
  shows "\<Union> (L ` (pder c r)) = L (der c r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    89
unfolding der_correctness Der_pder by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    90
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    91
lemma ders_pders:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    92
  shows "\<Union> (L ` (pders s r)) = L (ders s r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    93
unfolding der_correctness ders_correctness Ders_pders by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    94
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    95
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    96
subsection \<open>Finiteness property of partial derivatives\<close>
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    97
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    98
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    99
  pders_Set :: "string set \<Rightarrow> rexp \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   100
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   101
  "pders_Set A r \<equiv> \<Union>x \<in> A. pders x r"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   102
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   103
lemma pders_Set_subsetI:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   104
  assumes "\<And>s. s \<in> A \<Longrightarrow> pders s r \<subseteq> C"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   105
  shows "pders_Set A r \<subseteq> C"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   106
using assms unfolding pders_Set_def by (rule UN_least)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   107
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   108
lemma pders_Set_union:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   109
  shows "pders_Set (A \<union> B) r = (pders_Set A r \<union> pders_Set B r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   110
by (simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   111
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   112
lemma pders_Set_subset:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   113
  shows "A \<subseteq> B \<Longrightarrow> pders_Set A r \<subseteq> pders_Set B r"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   114
by (auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   115
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   116
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   117
  "UNIV1 \<equiv> UNIV - {[]}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   118
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   119
lemma pders_Set_ZERO [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   120
  shows "pders_Set UNIV1 ZERO = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   121
unfolding UNIV1_def pders_Set_def by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   122
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   123
lemma pders_Set_ONE [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   124
  shows "pders_Set UNIV1 ONE = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   125
unfolding UNIV1_def pders_Set_def by (auto split: if_splits)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   126
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   127
lemma pders_Set_CHAR [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   128
  shows "pders_Set UNIV1 (CHAR c) = {ONE}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   129
unfolding UNIV1_def pders_Set_def 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   130
apply(auto)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   131
apply(frule rev_subsetD)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   132
apply(rule pders_CHAR)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   133
apply(simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   134
apply(case_tac xa)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   135
apply(auto split: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   136
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   137
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   138
lemma pders_Set_ALT [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   139
  shows "pders_Set UNIV1 (ALT r1 r2) = pders_Set UNIV1 r1 \<union> pders_Set UNIV1 r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   140
unfolding UNIV1_def pders_Set_def by auto
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   141
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   143
text \<open>Non-empty suffixes of a string (needed for the cases of @{const SEQ} and @{const STAR} below)\<close>
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   144
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   145
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   146
  "PSuf s \<equiv> {v. v \<noteq> [] \<and> (\<exists>u. u @ v = s)}"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   148
lemma PSuf_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   149
  shows "PSuf (s @ [c]) = (PSuf s) ;; {[c]} \<union> {[c]}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   150
unfolding PSuf_def Sequ_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   151
by (auto simp add: append_eq_append_conv2 append_eq_Cons_conv)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   152
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   153
lemma PSuf_Union:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   154
  shows "(\<Union>v \<in> PSuf s ;; {[c]}. f v) = (\<Union>v \<in> PSuf s. f (v @ [c]))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   155
by (auto simp add: Sequ_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   156
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   157
lemma pders_Set_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   158
  shows "pders_Set (PSuf s ;; {[c]}) r = (pder_set c (pders_Set (PSuf s) r))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   159
unfolding pders_Set_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   160
by (simp add: PSuf_Union pders_snoc)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   162
lemma pderivs_SEQ:
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   163
  shows "pders s (SEQ r1 r2) \<subseteq> SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   164
proof (induct s rule: rev_induct)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   165
  case (snoc c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   166
  have ih: "pders s (SEQ r1 r2) \<subseteq> SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2)" 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   167
    by fact
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   168
  have "pders (s @ [c]) (SEQ r1 r2) = pder_set c (pders s (SEQ r1 r2))" 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   169
    by (simp add: pders_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   170
  also have "\<dots> \<subseteq> pder_set c (SEQs (pders s r1) r2 \<union> (pders_Set (PSuf s) r2))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   171
    using ih by fastforce
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   172
  also have "\<dots> = pder_set c (SEQs (pders s r1) r2) \<union> pder_set c (pders_Set (PSuf s) r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   173
    by (simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   174
  also have "\<dots> = pder_set c (SEQs (pders s r1) r2) \<union> pders_Set (PSuf s ;; {[c]}) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   175
    by (simp add: pders_Set_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   176
  also 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   177
  have "\<dots> \<subseteq> pder_set c (SEQs (pders s r1) r2) \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   178
    by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   179
  also 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   180
  have "\<dots> \<subseteq> SEQs (pder_set c (pders s r1)) r2 \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   181
    by (auto simp add: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   182
  also have "\<dots> = SEQs (pders (s @ [c]) r1) r2 \<union> pder c r2 \<union> pders_Set (PSuf s ;; {[c]}) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   183
    by (simp add: pders_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   184
  also have "\<dots> \<subseteq> SEQs (pders (s @ [c]) r1) r2 \<union> pders_Set (PSuf (s @ [c])) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   185
    unfolding pders_Set_def by (auto simp add: PSuf_snoc)  
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   186
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   187
qed (simp) 
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   189
lemma pders_Set_SEQ_aux1:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   190
  assumes a: "s \<in> UNIV1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   191
  shows "pders_Set (PSuf s) r \<subseteq> pders_Set UNIV1 r"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   192
using a unfolding UNIV1_def PSuf_def pders_Set_def by auto
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   194
lemma pders_Set_SEQ_aux2:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   195
  assumes a: "s \<in> UNIV1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   196
  shows "SEQs (pders s r1) r2 \<subseteq> SEQs (pders_Set UNIV1 r1) r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   197
using a unfolding pders_Set_def by auto
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   199
lemma pders_Set_SEQ:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   200
  shows "pders_Set UNIV1 (SEQ r1 r2) \<subseteq> SEQs (pders_Set UNIV1 r1) r2 \<union> pders_Set UNIV1 r2"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   201
apply(rule pders_Set_subsetI)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   202
apply(rule subset_trans)
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   203
apply(rule pderivs_SEQ)
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   204
using pders_Set_SEQ_aux1 pders_Set_SEQ_aux2
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   205
apply auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   206
apply blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   207
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   208
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   209
lemma pders_STAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   210
  assumes a: "s \<noteq> []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   211
  shows "pders s (STAR r) \<subseteq> SEQs (pders_Set (PSuf s) r) (STAR r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   212
using a
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   213
proof (induct s rule: rev_induct)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   214
  case (snoc c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   215
  have ih: "s \<noteq> [] \<Longrightarrow> pders s (STAR r) \<subseteq> SEQs (pders_Set (PSuf s) r) (STAR r)" by fact
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   216
  { assume asm: "s \<noteq> []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   217
    have "pders (s @ [c]) (STAR r) = pder_set c (pders s (STAR r))" by (simp add: pders_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   218
    also have "\<dots> \<subseteq> pder_set c (SEQs (pders_Set (PSuf s) r) (STAR r))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   219
      using ih[OF asm] by fast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   220
    also have "\<dots> \<subseteq> SEQs (pder_set c (pders_Set (PSuf s) r)) (STAR r) \<union> pder c (STAR r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   221
      by (auto split: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   222
    also have "\<dots> \<subseteq> SEQs (pders_Set (PSuf (s @ [c])) r) (STAR r) \<union> (SEQs (pder c r) (STAR r))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   223
      by (simp only: PSuf_snoc pders_Set_snoc pders_Set_union)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   224
         (auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   225
    also have "\<dots> = SEQs (pders_Set (PSuf (s @ [c])) r) (STAR r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   226
      by (auto simp add: PSuf_snoc PSuf_Union pders_snoc pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   227
    finally have ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   228
  }
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
  moreover
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   230
  { assume asm: "s = []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   231
    then have ?case by (auto simp add: pders_Set_def pders_snoc PSuf_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   232
  }
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   233
  ultimately show ?case by blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   234
qed (simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   235
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   236
lemma pders_Set_STAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   237
  shows "pders_Set UNIV1 (STAR r) \<subseteq> SEQs (pders_Set UNIV1 r) (STAR r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   238
apply(rule pders_Set_subsetI)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   239
apply(rule subset_trans)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   240
apply(rule pders_STAR)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   241
apply(simp add: UNIV1_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   242
apply(simp add: UNIV1_def PSuf_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   243
apply(auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   244
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   245
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   246
lemma finite_SEQs [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   247
  assumes a: "finite A"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   248
  shows "finite (SEQs A r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   249
using a by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   250
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   251
lemma finite_pders_Set_UNIV1:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   252
  shows "finite (pders_Set UNIV1 r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   253
apply(induct r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   254
apply(simp_all add: 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   255
  finite_subset[OF pders_Set_SEQ]
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   256
  finite_subset[OF pders_Set_STAR])
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   257
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   258
    
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   259
lemma pders_Set_UNIV:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   260
  shows "pders_Set UNIV r = pders [] r \<union> pders_Set UNIV1 r"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   261
unfolding UNIV1_def pders_Set_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   262
by blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   263
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   264
lemma finite_pders_Set_UNIV:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   265
  shows "finite (pders_Set UNIV r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   266
unfolding pders_Set_UNIV
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   267
by (simp add: finite_pders_Set_UNIV1)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   268
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   269
lemma finite_pders_set:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   270
  shows "finite (pders_Set A r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   271
by (metis finite_pders_Set_UNIV pders_Set_subset rev_finite_subset subset_UNIV)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   274
text \<open>The following relationship between the alphabetic width of regular expressions
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   275
(called \<open>awidth\<close> below) and the number of partial derivatives was proved
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   276
by Antimirov~\cite{Antimirov95} and formalized by Max Haslbeck.\<close>
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   277
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   278
fun awidth :: "rexp \<Rightarrow> nat" where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   279
"awidth ZERO = 0" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   280
"awidth ONE = 0" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   281
"awidth (CHAR a) = 1" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   282
"awidth (ALT r1 r2) = awidth r1 + awidth r2" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   283
"awidth (SEQ r1 r2) = awidth r1 + awidth r2" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   284
"awidth (STAR r1) = awidth r1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   285
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   286
lemma card_SEQs_pders_Set_le:
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   287
  shows  "card (SEQs (pders_Set A r) s) \<le> card (pders_Set A r)"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   288
  using finite_pders_set 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   289
  unfolding SEQs_eq_image 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   290
  by (rule card_image_le)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   292
lemma card_pders_set_UNIV1_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   293
  shows "card (pders_Set UNIV1 r) \<le> awidth r"
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   294
proof (induction r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   295
  case (ALT r1 r2)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   296
  have "card (pders_Set UNIV1 (ALT r1 r2)) = card (pders_Set UNIV1 r1 \<union> pders_Set UNIV1 r2)" by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   297
  also have "\<dots> \<le> card (pders_Set UNIV1 r1) + card (pders_Set UNIV1 r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   298
    by(simp add: card_Un_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   299
  also have "\<dots> \<le> awidth (ALT r1 r2)" using ALT.IH by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   300
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   301
next
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   302
  case (SEQ r1 r2)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   303
  have "card (pders_Set UNIV1 (SEQ r1 r2)) \<le> card (SEQs (pders_Set UNIV1 r1) r2 \<union> pders_Set UNIV1 r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   304
    by (simp add: card_mono finite_pders_set pders_Set_SEQ)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   305
  also have "\<dots> \<le> card (SEQs (pders_Set UNIV1 r1) r2) + card (pders_Set UNIV1 r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   306
    by (simp add: card_Un_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   307
  also have "\<dots> \<le> card (pders_Set UNIV1 r1) + card (pders_Set UNIV1 r2)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   308
    by (simp add: card_SEQs_pders_Set_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   309
  also have "\<dots> \<le> awidth (SEQ r1 r2)" using SEQ.IH by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   310
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   311
next
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   312
  case (STAR r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   313
  have "card (pders_Set UNIV1 (STAR r)) \<le> card (SEQs (pders_Set UNIV1 r) (STAR r))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   314
    by (simp add: card_mono finite_pders_set pders_Set_STAR)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   315
  also have "\<dots> \<le> card (pders_Set UNIV1 r)" by (rule card_SEQs_pders_Set_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   316
  also have "\<dots> \<le> awidth (STAR r)" by (simp add: STAR.IH)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   317
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   318
qed (auto)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   320
text\<open>Antimirov's Theorem 3.4:\<close>
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   321
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   322
theorem card_pders_set_UNIV_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   323
  shows "card (pders_Set UNIV r) \<le> awidth r + 1"
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   324
proof -
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   325
  have "card (insert r (pders_Set UNIV1 r)) \<le> Suc (card (pders_Set UNIV1 r))"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   326
    by(auto simp: card_insert_if[OF finite_pders_Set_UNIV1])
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   327
  also have "\<dots> \<le> Suc (awidth r)" by(simp add: card_pders_set_UNIV1_le_awidth)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   328
  finally show ?thesis by(simp add: pders_Set_UNIV)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   329
qed 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   330
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   331
text\<open>Antimirov's Corollary 3.5:\<close>
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   332
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   333
corollary card_pders_set_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   334
  shows "card (pders_Set A r) \<le> awidth r + 1"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   335
proof -
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   336
  have "card (pders_Set A r) \<le> card (pders_Set UNIV r)"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   337
    by (simp add: card_mono finite_pders_set pders_Set_subset)
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   338
  also have "... \<le> awidth r + 1"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   339
    by (rule card_pders_set_UNIV_le_awidth)
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   340
  finally show "card (pders_Set A r) \<le> awidth r + 1" by simp
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   341
qed
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   342
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   343
(* tests *)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   344
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   345
lemma b: 
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   346
  assumes "rd \<in> pder c r"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   347
  shows "size rd \<le> (Suc (size r)) * (Suc (size r))"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   348
  using assms
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   349
  apply(induct r arbitrary: rd)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   350
  apply(auto)[3]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   351
  apply(case_tac "c = x")
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   352
      apply(auto)[2]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   353
  prefer 2
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   354
    apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   355
  oops
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   356
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   357
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   358
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   359
lemma a: 
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   360
  assumes "rd \<in> pders s (SEQ r1 r2)"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   361
  shows "size  rd \<le> Suc (size r1 + size r2)"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   362
  using assms
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   363
  apply(induct s arbitrary: r1 r2 rd)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   364
   apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   365
  apply(auto)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   366
  apply(case_tac "nullable r1")
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   367
   apply(auto)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   368
  oops
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   369
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   370
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   371
lemma
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   372
  shows "\<forall>rd \<in> (pders_Set UNIV r). size rd \<le> size r"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   373
  apply(induct r)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   374
       apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   375
       apply(simp add: pders_Set_def)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   376
      apply(simp add: pders_Set_def)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   377
     apply(simp add: pders_Set_def pders_CHAR)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   378
  using pders_CHAR apply fastforce
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   379
    prefer 2
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   380
    apply(simp add: pders_Set_def)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   381
    apply (meson Un_iff le_SucI trans_le_add1 trans_le_add2)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   382
  apply(simp add: pders_Set_def)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   383
   apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   384
  apply(case_tac y)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   385
  apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   386
   apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   387
   apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   388
   apply(case_tac "nullable r1")
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   389
    apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   390
    apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   391
     prefer 3
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   392
     apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   393
     apply(auto)[1]
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   394
     apply(subgoal_tac "size xa \<le> size r1")
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   395
      prefer 2
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   396
      apply (metis UN_I pders.simps(1) pders_snoc singletonI)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   397
  oops
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   398
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   399
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   400
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   401
  
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 279
diff changeset
   402
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
end