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