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