thys/PDerivs.thy
author Chengsong
Mon, 12 Sep 2022 23:32:18 +0200
changeset 600 fd068f39ac23
parent 359 fedc16924b76
permissions -rw-r--r--
chap4 comments done
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
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
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
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
     6
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
     7
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     8
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     9
  "SEQs rs r \<equiv> (\<Union>r' \<in> rs. {SEQ r' r})"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
    11
lemma SEQs_eq_image:
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    12
  "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
    13
  by auto
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    14
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    15
primrec
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    16
  pder :: "char \<Rightarrow> rexp \<Rightarrow> rexp set"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    17
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    18
  "pder c ZERO = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    19
| "pder c ONE = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    20
| "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
    21
| "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
    22
| "pder c (SEQ r1 r2) = 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    23
    (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
    24
| "pder c (STAR r) = SEQs (pder c r) (STAR r)"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    26
primrec
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    27
  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
    28
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    29
  "pders [] r = {r}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    30
| "pders (c # s) r = \<Union> (pders s ` pder c r)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    31
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    32
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    33
 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
    34
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    35
  "pder_set c rs \<equiv> \<Union> (pder c ` rs)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    36
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    37
abbreviation
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    38
  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
    39
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    40
  "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
    41
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    42
lemma pders_append:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    43
  "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
    44
by (induct s1 arbitrary: r) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    46
lemma pders_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    47
  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
    48
by (simp add: pders_append)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    49
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    50
lemma pders_simps [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    51
  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
    52
  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
    53
  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
    54
by (induct s) (simp_all)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    55
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    56
lemma pders_CHAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    57
  shows "pders s (CHAR c) \<subseteq> {CHAR c, ONE}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    58
by (induct s) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    60
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
    61
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    62
lemma Sequ_UNION_distrib:
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
    63
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
    64
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
    65
by (auto simp add: Sequ_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    66
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    67
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    68
lemma Der_pder:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    69
  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
    70
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
    71
  
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    72
lemma Ders_pders:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    73
  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
    74
proof (induct s arbitrary: r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    75
  case (Cons c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    76
  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
    77
  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
    78
  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
    79
  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
    80
    by (auto simp add:  Ders_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    81
  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
    82
    using ih by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    83
  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
    84
  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
    85
qed (simp add: Ders_def)
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
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
    88
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    89
lemma der_pder:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    90
  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
    91
unfolding der_correctness Der_pder by simp
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    92
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    93
lemma ders_pders:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    94
  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
    95
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
    96
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    97
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    98
subsection \<open>Finiteness property of partial derivatives\<close>
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    99
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   100
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   101
  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
   102
where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   103
  "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
   104
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   105
lemma pders_Set_subsetI:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   106
  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
   107
  shows "pders_Set A r \<subseteq> C"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   108
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
   109
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   110
lemma pders_Set_union:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   111
  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
   112
by (simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   113
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   114
lemma pders_Set_subset:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   115
  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
   116
by (auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   117
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   118
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   119
  "UNIV1 \<equiv> UNIV - {[]}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   120
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   121
lemma pders_Set_ZERO [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   122
  shows "pders_Set UNIV1 ZERO = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   123
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
   124
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   125
lemma pders_Set_ONE [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   126
  shows "pders_Set UNIV1 ONE = {}"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   127
unfolding UNIV1_def pders_Set_def by (auto split: if_splits)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   128
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   129
lemma pders_Set_CHAR [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   130
  shows "pders_Set UNIV1 (CHAR c) = {ONE}"
359
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 329
diff changeset
   131
unfolding UNIV1_def pders_Set_def
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   132
apply(auto)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   133
apply(frule rev_subsetD)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   134
apply(rule pders_CHAR)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   135
apply(simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   136
apply(case_tac xa)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   137
apply(auto split: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   138
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   139
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   140
lemma pders_Set_ALT [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   141
  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
   142
unfolding UNIV1_def pders_Set_def by auto
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   143
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   145
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
   146
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   147
definition
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   148
  "PSuf s \<equiv> {v. v \<noteq> [] \<and> (\<exists>u. u @ v = s)}"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   150
lemma PSuf_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   151
  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
   152
unfolding PSuf_def Sequ_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   153
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
   154
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   155
lemma PSuf_Union:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   156
  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
   157
by (auto simp add: Sequ_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   158
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   159
lemma pders_Set_snoc:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   160
  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
   161
unfolding pders_Set_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   162
by (simp add: PSuf_Union pders_snoc)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   164
lemma pders_SEQ:
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   165
  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
   166
proof (induct s rule: rev_induct)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   167
  case (snoc c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   168
  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
   169
    by fact
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   170
  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
   171
    by (simp add: pders_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   172
  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
   173
    using ih by fastforce
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> 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
   175
    by (simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   176
  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
   177
    by (simp add: pders_Set_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   178
  also 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
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"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   180
    by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   181
  also 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
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"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   183
    by (auto simp add: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   184
  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
   185
    by (simp add: pders_snoc)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   186
  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
   187
    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
   188
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   189
qed (simp) 
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   191
lemma pders_Set_SEQ_aux1:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   192
  assumes a: "s \<in> UNIV1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   193
  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
   194
using a unfolding UNIV1_def PSuf_def pders_Set_def by auto
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   196
lemma pders_Set_SEQ_aux2:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   197
  assumes a: "s \<in> UNIV1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   198
  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
   199
using a unfolding pders_Set_def by auto
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   201
lemma pders_Set_SEQ:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   202
  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
   203
apply(rule pders_Set_subsetI)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   204
apply(rule subset_trans)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   205
apply(rule pders_SEQ)
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   206
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
   207
apply auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   208
apply blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   209
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   210
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   211
lemma pders_STAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   212
  assumes a: "s \<noteq> []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   213
  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
   214
using a
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   215
proof (induct s rule: rev_induct)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   216
  case (snoc c s)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   217
  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
   218
  { assume asm: "s \<noteq> []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   219
    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
   220
    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
   221
      using ih[OF asm] by fast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   222
    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
   223
      by (auto split: if_splits)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   224
    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
   225
      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
   226
         (auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   227
    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
   228
      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
   229
    finally have ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   230
  }
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  moreover
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   232
  { assume asm: "s = []"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   233
    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
   234
  }
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   235
  ultimately show ?case by blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   236
qed (simp)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   237
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   238
lemma pders_Set_STAR:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   239
  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
   240
apply(rule pders_Set_subsetI)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   241
apply(rule subset_trans)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   242
apply(rule pders_STAR)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   243
apply(simp add: UNIV1_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   244
apply(simp add: UNIV1_def PSuf_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   245
apply(auto simp add: pders_Set_def)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   246
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   247
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   248
lemma finite_SEQs [simp]:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   249
  assumes a: "finite A"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   250
  shows "finite (SEQs A r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   251
using a by auto
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   252
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   253
thm finite.intros
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   254
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   255
lemma finite_pders_Set_UNIV1:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   256
  shows "finite (pders_Set UNIV1 r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   257
apply(induct r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   258
apply(simp_all add: 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   259
  finite_subset[OF pders_Set_SEQ]
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   260
  finite_subset[OF pders_Set_STAR])
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   261
done
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   262
    
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   263
lemma pders_Set_UNIV:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   264
  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
   265
unfolding UNIV1_def pders_Set_def
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   266
by blast
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   267
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   268
lemma finite_pders_Set_UNIV:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   269
  shows "finite (pders_Set UNIV r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   270
unfolding pders_Set_UNIV
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   271
by (simp add: finite_pders_Set_UNIV1)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   272
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   273
lemma finite_pders_set:
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   274
  shows "finite (pders_Set A r)"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   275
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
   276
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   278
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
   279
(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
   280
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
   281
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   282
fun awidth :: "rexp \<Rightarrow> nat" where
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   283
"awidth ZERO = 0" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   284
"awidth ONE = 0" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   285
"awidth (CHAR a) = 1" |
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   286
"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
   287
"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
   288
"awidth (STAR r1) = awidth r1"
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   289
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   290
lemma card_SEQs_pders_Set_le:
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   291
  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
   292
  using finite_pders_set 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   293
  unfolding SEQs_eq_image 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   294
  by (rule card_image_le)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
309
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   296
lemma card_pders_set_UNIV1_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   297
  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
   298
proof (induction r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   299
  case (ALT r1 r2)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   300
  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
   301
  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
   302
    by(simp add: card_Un_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   303
  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
   304
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   305
next
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   306
  case (SEQ r1 r2)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   307
  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
   308
    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
   309
  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
   310
    by (simp add: card_Un_le)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   311
  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
   312
    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
   313
  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
   314
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   315
next
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   316
  case (STAR r)
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   317
  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
   318
    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
   319
  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
   320
  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
   321
  finally show ?case .
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   322
qed (auto)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   324
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
   325
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   326
theorem card_pders_set_UNIV_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   327
  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
   328
proof -
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   329
  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
   330
    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
   331
  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
   332
  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
   333
qed 
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   334
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   335
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
   336
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   337
corollary card_pders_set_le_awidth: 
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   338
  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
   339
proof -
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   340
  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
   341
    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
   342
  also have "... \<le> awidth r + 1"
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   343
    by (rule card_pders_set_UNIV_le_awidth)
a7769a89c529 added cardinality proof of Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 308
diff changeset
   344
  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
   345
qed
308
496a37d816e9 added partial derivative proof from Antimirov
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   346
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   347
(* other result by antimirov *)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   348
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   349
lemma card_pders_awidth: 
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   350
  shows "card (pders s r) \<le> awidth r + 1"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   351
proof -
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   352
  have "pders s r \<subseteq> pders_Set UNIV r"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   353
    using pders_Set_def by auto
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   354
  then have "card (pders s r) \<le> card (pders_Set UNIV r)"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   355
    by (simp add: card_mono finite_pders_set)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   356
  then show "card (pders s r) \<le> awidth r + 1"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   357
    using card_pders_set_le_awidth order_trans by blast
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   358
qed
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   359
    
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   360
  
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   361
  
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   362
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   363
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   364
fun subs :: "rexp \<Rightarrow> rexp set" where
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   365
"subs ZERO = {ZERO}" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   366
"subs ONE = {ONE}" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   367
"subs (CHAR a) = {CHAR a, ONE}" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   368
"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
   369
"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
   370
"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
   371
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   372
lemma subs_finite:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   373
  shows "finite (subs r)"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   374
  apply(induct r) 
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   375
  apply(simp_all)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   376
  done
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   377
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   378
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   379
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   380
lemma pders_subs:
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   381
  shows "pders s r \<subseteq> subs r"
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   382
  apply(induct r arbitrary: s)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   383
       apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   384
      apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   385
     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
   386
(*  SEQ case *)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   387
    apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   388
    apply(rule subset_trans)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   389
     apply(rule pders_SEQ)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   390
    defer
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   391
(* ALT case *)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   392
    apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   393
    apply(rule impI)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   394
    apply(rule conjI)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   395
  apply blast
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   396
    apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   397
(* STAR case *)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   398
    apply(case_tac s)
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(rule subset_trans)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   401
  thm pders_STAR
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   402
     apply(rule pders_STAR)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   403
     apply(simp)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   404
    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
   405
  apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   406
  apply(rule conjI)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   407
   apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   408
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
   409
  done
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   410
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   411
fun size2 :: "rexp \<Rightarrow> nat" where
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   412
  "size2 ZERO = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   413
  "size2 ONE = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   414
  "size2 (CHAR c) = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   415
  "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
   416
  "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
   417
  "size2 (STAR r1) = Suc (size2 r1)" 
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   418
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   419
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   420
lemma size_rexp:
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   421
  fixes r :: rexp
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   422
  shows "1 \<le> size2 r"
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   423
  apply(induct r)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   424
  apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   425
  apply(simp_all)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   426
  done
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   427
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   428
lemma subs_card:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   429
  shows "card (subs r) \<le> Suc (size2 r + size2 r)"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   430
  apply(induct r)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   431
       apply(auto)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   432
    apply(subst card_insert)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   433
     apply(simp add: subs_finite)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   434
    apply(simp add: subs_finite)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   435
  oops
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   436
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   437
lemma subs_size2:
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   438
  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
   439
  apply(induct r)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   440
       apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   441
      apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   442
     apply(simp)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 312
diff changeset
   443
(* SEQ case *)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   444
    apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   445
    apply(auto)[1]
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   446
  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
   447
  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
   448
  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
   449
(*  ALT case  *)
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   450
   apply(simp)
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   451
   apply(auto)[1]
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   452
  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
   453
  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
   454
(* STAR case *)
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   455
  apply(auto)[1]
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   456
  apply(drule_tac x="r'" in bspec)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   457
   apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   458
  apply(rule le_trans)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   459
   apply(assumption)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   460
  apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   461
  using size_rexp
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   462
  apply(simp)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   463
  done
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   464
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   465
lemma awidth_size:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   466
  shows "awidth r \<le> size2 r"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   467
  apply(induct r)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   468
       apply(simp_all)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   469
  done
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   470
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   471
lemma Sum1:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   472
  fixes A B :: "nat set"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   473
  assumes "A \<subseteq> B" "finite A" "finite B"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   474
  shows "\<Sum>A \<le> \<Sum>B"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   475
  using  assms
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   476
  by (simp add: sum_mono2)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   477
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   478
lemma Sum2:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   479
  fixes A :: "rexp set"  
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   480
  and   f g :: "rexp \<Rightarrow> nat" 
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   481
  assumes "finite A" "\<forall>x \<in> A. f x \<le> g x"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   482
  shows "sum f A \<le> sum g A"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   483
  using  assms
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   484
  apply(induct A)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   485
   apply(auto)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   486
  done
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   487
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   488
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   489
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   490
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   491
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   492
lemma pders_max_size:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   493
  shows "(sum size2 (pders s r)) \<le> (Suc (size2 r)) ^ 3"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   494
proof -
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   495
  have "(sum size2 (pders s r)) \<le> sum (\<lambda>_. Suc (size2 r  * size2 r)) (pders s r)" 
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   496
    apply(rule_tac Sum2)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   497
     apply (meson pders_subs rev_finite_subset subs_finite)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   498
    using pders_subs subs_size2 by blast
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   499
  also have "... \<le> (Suc (size2 r  * size2 r)) * (sum (\<lambda>_. 1) (pders s r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   500
    by simp
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   501
  also have "... \<le> (Suc (size2 r  * size2 r)) * card (pders s r)"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   502
    by simp
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   503
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (awidth r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   504
    using Suc_eq_plus1 card_pders_awidth mult_le_mono2 by presburger
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   505
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (size2 r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   506
    using Suc_le_mono awidth_size mult_le_mono2 by presburger
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   507
  also have "... \<le> (Suc (size2 r)) ^ 3"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   508
    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)    
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   509
  finally show ?thesis  .
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   510
qed
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   511
  
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   512
lemma pders_Set_max_size:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   513
  shows "(sum size2 (pders_Set A r)) \<le> (Suc (size2 r)) ^ 3"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   514
proof -
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   515
  have "(sum size2 (pders_Set A r)) \<le> sum (\<lambda>_. Suc (size2 r  * size2 r)) (pders_Set A r)" 
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   516
    apply(rule_tac Sum2)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   517
     apply (simp add: finite_pders_set)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   518
    by (meson pders_Set_subsetI pders_subs subs_size2 subsetD)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   519
  also have "... \<le> (Suc (size2 r  * size2 r)) * (sum (\<lambda>_. 1) (pders_Set A r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   520
    by simp
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   521
  also have "... \<le> (Suc (size2 r  * size2 r)) * card (pders_Set A r)"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   522
    by simp
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   523
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (awidth r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   524
    using Suc_eq_plus1 card_pders_set_le_awidth mult_le_mono2 by presburger
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   525
  also have "... \<le> (Suc (size2 r  * size2 r)) * (Suc (size2 r))"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   526
    using Suc_le_mono awidth_size mult_le_mono2 by presburger
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   527
  also have "... \<le> (Suc (size2 r)) ^ 3"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   528
    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)    
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   529
  finally show ?thesis  .
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   530
qed    
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   531
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   532
fun height :: "rexp \<Rightarrow> nat" where
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   533
  "height ZERO = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   534
  "height ONE = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   535
  "height (CHAR c) = 1" |
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   536
  "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
   537
  "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
   538
  "height (STAR r1) = Suc (height r1)" 
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   539
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   540
lemma height_size2:
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   541
  shows "height r \<le> size2 r"
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   542
  apply(induct r)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   543
  apply(simp_all)
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   544
  done
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   545
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   546
lemma height_rexp:
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   547
  fixes r :: rexp
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   548
  shows "1 \<le> height r"
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   549
  apply(induct r)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   550
  apply(simp_all)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   551
  done
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   552
329
a730a5a0bab9 proved cubic size bound for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   553
lemma subs_height:
312
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   554
  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
   555
  apply(induct r)
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   556
  apply(auto)+
8b0b414e71b0 added size bounds for partial derivatives
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   557
  done  
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   558
  
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 309
diff changeset
   559
  
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 279
diff changeset
   560
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
end