thys/SpecExt.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 05 Oct 2017 12:45:13 +0100
changeset 275 deea42c83c9e
parent 274 692b62426677
child 276 a3134f7de065
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
   
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory SpecExt
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
  imports Main "~~/src/HOL/Library/Sublist"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
section {* Sequential Composition of Languages *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
definition
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
where 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
text {* Two Simple Properties about Sequential Composition *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
lemma Sequ_empty_string [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  shows "A ;; {[]} = A"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and   "{[]} ;; A = A"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
by (simp_all add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
lemma Sequ_empty [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  shows "A ;; {} = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  and   "{} ;; A = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
by (simp_all add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
lemma Sequ_assoc:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  shows "(A ;; B) ;; C = A ;; (B ;; C)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
apply blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
by (metis append_assoc)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
lemma Sequ_Union_in:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  shows "(A ;; (\<Union>x\<in> B. C x)) = (\<Union>x\<in> B. A ;; C x)" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
by (auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
section {* Semantic Derivative (Left Quotient) of Languages *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
definition
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  "Der c A \<equiv> {s. c # s \<in> A}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
definition
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  Ders :: "string \<Rightarrow> string set \<Rightarrow> string set"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  "Ders s A \<equiv> {s'. s @ s' \<in> A}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
lemma Der_null [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  shows "Der c {} = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
unfolding Der_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
lemma Der_empty [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  shows "Der c {[]} = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
unfolding Der_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
lemma Der_char [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  shows "Der c {[d]} = (if c = d then {[]} else {})"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
unfolding Der_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
lemma Der_union [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  shows "Der c (A \<union> B) = Der c A \<union> Der c B"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
unfolding Der_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
lemma Der_UNION [simp]: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  shows "Der c (\<Union>x\<in>A. B x) = (\<Union>x\<in>A. Der c (B x))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
by (auto simp add: Der_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
lemma Der_Sequ [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
unfolding Der_def Sequ_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
by (auto simp add: Cons_eq_append_conv)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
section {* Kleene Star for Languages *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
inductive_set
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  for A :: "string set"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  start[intro]: "[] \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
| step[intro]:  "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
(* Arden's lemma *)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
lemma Star_cases:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  shows "A\<star> = {[]} \<union> A ;; A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
unfolding Sequ_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
by (auto) (metis Star.simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
lemma Star_decomp: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  assumes "c # x \<in> A\<star>" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
  shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
by (induct x\<equiv>"c # x" rule: Star.induct) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
   (auto simp add: append_eq_Cons_conv)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
lemma Star_Der_Sequ: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
unfolding Der_def Sequ_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
by(auto simp add: Star_decomp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
lemma Der_star [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
  shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
proof -    
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
    by (simp only: Star_cases[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  also have "... = Der c (A ;; A\<star>)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
    by (simp only: Der_union Der_empty) (simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
    by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  also have "... =  (Der c A) ;; A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
    using Star_Der_Sequ by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
qed
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
section {* Power operation for Sets *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
fun 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  Pow :: "string set \<Rightarrow> nat \<Rightarrow> string set" ("_ \<up> _" [101, 102] 101)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
   "A \<up> 0 = {[]}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
|  "A \<up> (Suc n) = A ;; (A \<up> n)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
lemma Pow_empty [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  shows "[] \<in> A \<up> n \<longleftrightarrow> (n = 0 \<or> [] \<in> A)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
by(induct n) (auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
lemma Pow_Suc_rev:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  "A \<up> (Suc n) =  (A \<up> n) ;; A"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
apply(induct n arbitrary: A)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
apply(simp_all)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
by (metis Sequ_assoc)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
lemma Pow_decomp: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  assumes "c # x \<in> A \<up> n" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A \<up> (n - 1)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
apply(induct n) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
apply(auto simp add: Cons_eq_append_conv Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
apply(case_tac n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
apply(blast)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
lemma Star_Pow:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
  assumes "s \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
  shows "\<exists>n. s \<in> A \<up> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
apply(induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
apply(auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
apply(rule_tac x="Suc n" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
lemma Pow_Star:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  assumes "s \<in> A \<up> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
  shows "s \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
apply(induct n arbitrary: s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
lemma Der_Pow_0:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  shows "Der c (A \<up> 0) = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
by(simp add: Der_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
lemma Der_Pow_Suc:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  shows "Der c (A \<up> (Suc n)) = (Der c A) ;; (A \<up> n)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
unfolding Der_def Sequ_def 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
apply(auto simp add: Cons_eq_append_conv Sequ_def dest!: Pow_decomp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
apply(case_tac n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
apply(force simp add: Sequ_def)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
lemma Der_Pow [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
  shows "Der c (A \<up> n) = (if n = 0 then {} else (Der c A) ;; (A \<up> (n - 1)))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
apply(case_tac n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
apply(simp_all del: Pow.simps add: Der_Pow_0 Der_Pow_Suc)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
lemma Der_Pow_Sequ [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
  shows "Der c (A ;; A \<up> n) = (Der c A) ;; (A \<up> n)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
by (simp only: Pow.simps[symmetric] Der_Pow) (simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
lemma Pow_Sequ_Un:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  assumes "0 < x"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  shows "(\<Union>n \<in> {..x}. (A \<up> n)) = ({[]} \<union> (\<Union>n \<in> {..x - Suc 0}. A ;; (A \<up> n)))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
apply(smt Pow.elims Sequ_def Suc_le_mono Suc_pred atMost_iff empty_iff insert_iff mem_Collect_eq)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
apply(rule_tac x="Suc xa" in bexI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
lemma Pow_Sequ_Un2:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  assumes "0 < x"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  shows "(\<Union>n \<in> {x..}. (A \<up> n)) = (\<Union>n \<in> {x - Suc 0..}. A ;; (A \<up> n))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
apply(case_tac n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
apply fastforce
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
apply(case_tac x)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
apply(auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
apply(rule_tac x="Suc xa" in bexI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
apply(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
section {* Regular Expressions *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
datatype rexp =
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  ZERO
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
| ONE
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
| CHAR char
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
| SEQ rexp rexp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
| ALT rexp rexp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
| STAR rexp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
| UPNTIMES rexp nat
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
| NTIMES rexp nat
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
| FROMNTIMES rexp nat
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
| NMTIMES rexp nat nat
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
section {* Semantics of Regular Expressions *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
fun
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  L :: "rexp \<Rightarrow> string set"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
  "L (ZERO) = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
| "L (ONE) = {[]}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
| "L (CHAR c) = {[c]}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
| "L (ALT r1 r2) = (L r1) \<union> (L r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
| "L (STAR r) = (L r)\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
| "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
| "L (NTIMES r n) = (L r) \<up> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
| "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
| "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
section {* Nullable, Derivatives *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
fun
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
 nullable :: "rexp \<Rightarrow> bool"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
  "nullable (ZERO) = False"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
| "nullable (ONE) = True"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
| "nullable (CHAR c) = False"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
| "nullable (STAR r) = True"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
| "nullable (UPNTIMES r n) = True"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
| "nullable (NTIMES r n) = (if n = 0 then True else nullable r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
| "nullable (FROMNTIMES r n) = (if n = 0 then True else nullable r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
| "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
fun
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
  "der c (ZERO) = ZERO"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
| "der c (ONE) = ZERO"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
| "der c (SEQ r1 r2) = 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
     (if nullable r1
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
      then ALT (SEQ (der c r1) r2) (der c r2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
      else SEQ (der c r1) r2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
| "der c (STAR r) = SEQ (der c r) (STAR r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
| "der c (UPNTIMES r n) = (if n = 0 then ZERO else SEQ (der c r) (UPNTIMES r (n - 1)))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
| "der c (NTIMES r n) = (if n = 0 then ZERO else SEQ (der c r) (NTIMES r (n - 1)))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
| "der c (FROMNTIMES r n) = SEQ (der c r) (FROMNTIMES r (n - 1))"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
| "der c (NMTIMES r n m) = 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
     (if m < n then ZERO 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
      else (if n = 0 then (if m = 0 then ZERO else 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
                           SEQ (der c r) (UPNTIMES r (m - 1))) else 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
                           SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
fun 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
  "ders [] r = r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
| "ders (c # s) r = ders s (der c r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
lemma nullable_correctness:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
  shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
by(induct r) (auto simp add: Sequ_def) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
lemma der_correctness:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
  shows "L (der c r) = Der c (L r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
apply(induct r) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
prefer 2
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
apply(rule impI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
apply(subst Sequ_Union_in)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
apply(subst Der_Pow_Sequ[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
apply(subst Pow.simps[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
apply(subst Der_UNION[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
apply(subst Pow_Sequ_Un)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
apply(simp only: Der_union Der_empty)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
apply(subst Sequ_Union_in)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
apply(subst Der_Pow_Sequ[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
apply(subst Pow.simps[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
apply(case_tac x2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
prefer 2
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
apply(subst Pow_Sequ_Un2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
apply(auto simp add: Sequ_def Der_def)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
apply(rule_tac x="Suc xa" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
apply(auto simp add: Sequ_def)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
apply(drule Pow_decomp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
apply(auto)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
apply (metis append_Cons)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
apply(simp add: nullable_correctness del: Der_UNION)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
apply(rule impI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
apply(rule conjI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
apply(rule impI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
apply(subst Sequ_Union_in)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
apply(subst Der_Pow_Sequ[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
apply(subst Pow.simps[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
apply(subst Der_UNION[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
apply(case_tac x3a)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
apply(auto simp add: Sequ_def Der_def Cons_eq_append_conv)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
apply(rule_tac x="Suc xa" in bexI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
apply(auto simp add: Sequ_def)[2]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
apply (metis append_Cons)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
apply (metis (no_types, hide_lams) Pow_decomp atMost_iff diff_Suc_eq_diff_pred diff_is_0_eq)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
apply(rule impI)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
apply(subst Sequ_Union_in)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
apply(subst Der_Pow_Sequ[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
apply(subst Pow.simps[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
apply(subst Der_UNION[symmetric])
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
apply(case_tac x2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
apply(simp del: Pow.simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
apply(auto simp add: Sequ_def Der_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
apply (metis One_nat_def Suc_le_D Suc_le_mono atLeastAtMost_iff diff_Suc_1 not_le)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
by fastforce
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
lemma ders_correctness:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
  shows "L (ders s r) = Ders s (L r)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
by (induct s arbitrary: r)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
   (simp_all add: Ders_def der_correctness Der_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
section {* Values *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
datatype val = 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
  Void
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
| Char char
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
| Seq val val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
| Right val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
| Left val
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
| Stars "val list"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
section {* The string behind a value *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
fun 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
  flat :: "val \<Rightarrow> string"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
  "flat (Void) = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
| "flat (Char c) = [c]"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
| "flat (Left v) = flat v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
| "flat (Right v) = flat v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
| "flat (Stars []) = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
abbreviation
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
  "flats vs \<equiv> concat (map flat vs)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
lemma flat_Stars [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
 "flat (Stars vs) = flats vs"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
by (induct vs) (auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
lemma Star_concat:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
  assumes "\<forall>s \<in> set ss. s \<in> A"  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
  shows "concat ss \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
using assms by (induct ss) (auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
lemma Star_cstring:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
  assumes "s \<in> A\<star>"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
  shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
apply(induct rule: Star.induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
apply(auto)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
apply(rule_tac x="[]" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
apply(erule exE)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
apply(case_tac "s1 = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
apply(rule_tac x="ss" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
apply(rule_tac x="s1#ss" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
lemma Aux:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
  assumes "\<forall>s\<in>set ss. s = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
  shows "concat ss = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
by (induct ss) (auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
lemma Pow_cstring_nonempty:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
  assumes "s \<in> A \<up> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
  shows "\<exists>ss. concat ss = s \<and> length ss \<le> n \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
apply(induct n arbitrary: s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
apply(auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
apply(simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
apply(erule exE)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
apply(drule_tac x="s2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
apply(case_tac "s1 = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
apply(rule_tac x="ss" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
apply(rule_tac x="s1 # ss" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
lemma Pow_cstring:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  assumes "s \<in> A \<up> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
  shows "\<exists>ss1 ss2. concat (ss1 @ ss2) = s \<and> length (ss1 @ ss2) = n \<and> 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
         (\<forall>s \<in> set ss1. s \<in> A \<and> s \<noteq> []) \<and> (\<forall>s \<in> set ss2. s \<in> A \<and> s = [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
apply(induct n arbitrary: s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
apply(auto)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
apply(simp only: Pow_Suc_rev)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
apply(simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
apply(erule exE)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
apply(drule_tac x="s1" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
apply(erule exE)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
apply(case_tac "s2 = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
apply(rule_tac x="ss1" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
apply(rule_tac x="s2#ss2" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
apply(rule_tac x="ss1 @ [s2]" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
apply(rule_tac x="ss2" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
apply(subst Aux)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
apply(auto)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
apply(subst Aux)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
apply(auto)[1]
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
section {* Lexical Values *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
inductive 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
  Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
| "\<Turnstile> Void : ONE"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
| "\<Turnstile> Char c : CHAR c"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> []\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : STAR r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> []; length vs \<le> n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : UPNTIMES r n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []; 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
    \<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = []; 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
    length (vs1 @ vs2) = n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : NTIMES r n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r  \<and> flat v \<noteq> []; 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
    \<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = []; 
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   496
    length (vs1 @ vs2) = n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : FROMNTIMES r n"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   497
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r  \<and> flat v \<noteq> []; length vs > n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : FROMNTIMES r n"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> [];
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
    \<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = []; 
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   500
    length (vs1 @ vs2) = n; length (vs1 @ vs2) \<le> m\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : NMTIMES r n m"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   501
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [];
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   502
    length vs > n; length vs \<le> m\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : NMTIMES r n m"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   504
  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
inductive_cases Prf_elims:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
  "\<Turnstile> v : ZERO"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
  "\<Turnstile> v : SEQ r1 r2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
  "\<Turnstile> v : ALT r1 r2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
  "\<Turnstile> v : ONE"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
  "\<Turnstile> v : CHAR c"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
  "\<Turnstile> vs : STAR r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
  "\<Turnstile> vs : UPNTIMES r n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
  "\<Turnstile> vs : NTIMES r n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
  "\<Turnstile> vs : FROMNTIMES r n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
  "\<Turnstile> vs : NMTIMES r n m"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
lemma Prf_Stars_appendE:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
  assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
by (auto intro: Prf.intros elim!: Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   523
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   524
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
lemma flats_empty:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
  assumes "(\<forall>v\<in>set vs. flat v = [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
  shows "flats vs = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
by(induct vs) (simp_all)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
lemma Star_cval:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
  shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
apply(induct ss)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
apply(auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
apply(rule_tac x="[]" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
apply(case_tac "flat v = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
apply(rule_tac x="vs" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
apply(rule_tac x="v#vs" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
lemma flats_cval:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
  shows "\<exists>vs1 vs2. flats (vs1 @ vs2) = concat ss \<and> length (vs1 @ vs2) = length ss \<and> 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
          (\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []) \<and>
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   551
          (\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = [])"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   552
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
apply(induct ss rule: rev_induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   554
apply(rule_tac x="[]" in exI)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   558
apply(case_tac "flat v = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   559
apply(rule_tac x="vs1" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   560
apply(rule_tac x="v#vs2" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   561
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   562
apply(rule_tac x="vs1 @ [v]" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
apply(rule_tac x="vs2" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
apply(subst (asm) (2) flats_empty)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   569
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   570
lemma flats_cval_nonempty:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
  shows "\<exists>vs. flats vs = concat ss \<and> length vs \<le> length ss \<and> 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   573
          (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   574
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   575
apply(induct ss)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   576
apply(rule_tac x="[]" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   577
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   578
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
apply(case_tac "flat v = []")
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
apply(rule_tac x="vs" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   583
apply(rule_tac x="v # vs" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   584
apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   585
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   586
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   587
lemma Pow_flats:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   588
  assumes "\<forall>v \<in> set vs. flat v \<in> A"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   589
  shows "flats vs \<in> A \<up> length vs"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   590
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   591
by(induct vs)(auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   592
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   593
lemma Pow_flats_appends:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   594
  assumes "\<forall>v \<in> set vs1. flat v \<in> A" "\<forall>v \<in> set vs2. flat v \<in> A"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   595
  shows "flats vs1 @ flats vs2 \<in> A \<up> (length vs1 + length vs2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   596
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   597
apply(induct vs1)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   598
apply(auto simp add: Sequ_def Pow_flats)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   599
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   600
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
lemma L_flat_Prf1:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
  assumes "\<Turnstile> v : r" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
  shows "flat v \<in> L r"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
apply(induct) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
apply(auto simp add: Sequ_def Star_concat Pow_flats)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607
apply(meson Pow_flats atMost_iff)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   608
using Pow_flats_appends apply blast
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   609
using Pow_flats_appends apply blast
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   610
apply (meson Pow_flats atLeast_iff less_imp_le)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   611
apply(rule_tac x="length vs1 + length vs2" in  bexI)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   612
apply(meson Pow_flats_appends atLeastAtMost_iff)
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   613
apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   614
apply(meson Pow_flats atLeastAtMost_iff less_or_eq_imp_le)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   615
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   616
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   617
lemma L_flat_Prf2:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   618
  assumes "s \<in> L r" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   619
  shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   620
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   621
proof(induct r arbitrary: s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   622
  case (STAR r s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   623
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   624
  have "s \<in> L (STAR r)" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   625
  then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   626
  using Star_cstring by auto  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   627
  then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   628
  using IH Star_cval by metis 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   629
  then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   630
  using Prf.intros(6) flat_Stars by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   631
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   632
  case (SEQ r1 r2 s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   633
  then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   634
  unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   635
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   636
  case (ALT r1 r2 s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   637
  then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   638
  unfolding L.simps by (fastforce intro: Prf.intros)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   639
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   640
  case (NTIMES r n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
  have "s \<in> L (NTIMES r n)" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
  then obtain ss1 ss2 where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = n" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
    "\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
  using Pow_cstring by force
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
  then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = n" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647
      "\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
  using IH flats_cval 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
  apply -
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
  apply(drule_tac x="ss1 @ ss2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
  apply(drule_tac x="r" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   652
  apply(drule meta_mp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   653
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   654
  apply (metis Un_iff)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   655
  apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   656
  apply(drule_tac x="vs1" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   657
  apply(drule_tac x="vs2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   658
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   659
  done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
  then show "\<exists>v. \<Turnstile> v : NTIMES r n \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   661
  using Prf.intros(8) flat_Stars by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   663
  case (FROMNTIMES r n)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
  have "s \<in> L (FROMNTIMES r n)" by fact 
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   666
  then obtain ss1 ss2 m where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = m"  "n \<le> m"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
    "\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   668
    using Pow_cstring by force 
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
  then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = m" "n \<le> m"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
      "\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671
  using IH flats_cval 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   672
  apply -
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   673
  apply(drule_tac x="ss1 @ ss2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   674
  apply(drule_tac x="r" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   675
  apply(drule meta_mp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   676
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   677
  apply (metis Un_iff)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   678
  apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   679
  apply(drule_tac x="vs1" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   680
  apply(drule_tac x="vs2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   681
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   682
  done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   683
  then show "\<exists>v. \<Turnstile> v : FROMNTIMES r n \<and> flat v = s"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   684
  apply(case_tac "length vs1 \<le> n")
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   685
  apply(rule_tac x="Stars (vs1 @ take (n - length vs1) vs2)" in exI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   686
  apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   687
  apply(subgoal_tac "flats (take (n - length vs1) vs2) = []")
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   688
  prefer 2
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   689
  apply (meson flats_empty in_set_takeD)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   690
  apply(clarify)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   691
    apply(rule conjI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   692
      apply(rule Prf.intros)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   693
        apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   694
       apply (meson in_set_takeD)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   695
      apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   696
     apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   697
     apply (simp add: flats_empty)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   698
      apply(rule_tac x="Stars vs1" in exI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   699
  apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   700
    apply(rule conjI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   701
     apply(rule Prf.intros(10))
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   702
      apply(auto)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   703
  done    
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   704
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   705
  case (NMTIMES r n m)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   706
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   707
  have "s \<in> L (NMTIMES r n m)" by fact 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   708
  then obtain ss1 ss2 k where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = k" "n \<le> k" "k \<le> m" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   709
    "\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   710
  using Pow_cstring by (auto, blast)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   711
  then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = k" "n \<le> k" "k \<le> m"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
      "\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
  using IH flats_cval 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
  apply -
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
  apply(drule_tac x="ss1 @ ss2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
  apply(drule_tac x="r" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
  apply(drule meta_mp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   719
  apply (metis Un_iff)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   720
  apply(clarify)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   721
  apply(drule_tac x="vs1" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   722
  apply(drule_tac x="vs2" in meta_spec)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   723
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
  done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
  then show "\<exists>v. \<Turnstile> v : NMTIMES r n m \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
  apply(rule_tac x="Stars (vs1 @ vs2)" in exI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   727
  apply(simp)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   728
  apply(rule Prf.intros)
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   729
       apply(auto) 
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   730
  sorry
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   731
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   732
  case (UPNTIMES r n s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   733
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   734
  have "s \<in> L (UPNTIMES r n)" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
  then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []" "length ss \<le> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
  using Pow_cstring_nonempty by force
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   737
  then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []" "length vs \<le> n"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   738
  using IH flats_cval_nonempty by (smt order.trans) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   739
  then show "\<exists>v. \<Turnstile> v : UPNTIMES r n \<and> flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   740
  using Prf.intros(7) flat_Stars by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   741
qed (auto intro: Prf.intros)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   742
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   743
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   744
lemma L_flat_Prf:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   745
  shows "L(r) = {flat v | v. \<Turnstile> v : r}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   746
using L_flat_Prf1 L_flat_Prf2 by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   747
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   748
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   749
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   750
section {* Sets of Lexical Values *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   751
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   752
text {*
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   753
  Shows that lexical values are finite for a given regex and string.
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   754
*}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   755
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   756
definition
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   757
  LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   758
where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   759
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   760
lemma LV_simps:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   761
  shows "LV ZERO s = {}"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   762
  and   "LV ONE s = (if s = [] then {Void} else {})"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   763
  and   "LV (CHAR c) s = (if s = [c] then {Char c} else {})"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   764
  and   "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   765
unfolding LV_def
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   766
apply(auto intro: Prf.intros elim: Prf.cases)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   767
done
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   768
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   769
abbreviation
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   770
  "Prefixes s \<equiv> {s'. prefix s' s}"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   771
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   772
abbreviation
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   773
  "Suffixes s \<equiv> {s'. suffix s' s}"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   774
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   775
abbreviation
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   776
  "SSuffixes s \<equiv> {s'. strict_suffix s' s}"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   777
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   778
lemma Suffixes_cons [simp]:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   779
  shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   780
by (auto simp add: suffix_def Cons_eq_append_conv)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   781
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   782
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   783
lemma finite_Suffixes: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   784
  shows "finite (Suffixes s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   785
by (induct s) (simp_all)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   786
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   787
lemma finite_SSuffixes: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   788
  shows "finite (SSuffixes s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   789
proof -
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   790
  have "SSuffixes s \<subseteq> Suffixes s"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   791
   unfolding suffix_def strict_suffix_def by auto
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   792
  then show "finite (SSuffixes s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   793
   using finite_Suffixes finite_subset by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   794
qed
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   795
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   796
lemma finite_Prefixes: 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   797
  shows "finite (Prefixes s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   798
proof -
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   799
  have "finite (Suffixes (rev s))" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   800
    by (rule finite_Suffixes)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   801
  then have "finite (rev ` Suffixes (rev s))" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   802
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   803
  have "rev ` (Suffixes (rev s)) = Prefixes s"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   804
  unfolding suffix_def prefix_def image_def
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   805
   by (auto)(metis rev_append rev_rev_ident)+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   806
  ultimately show "finite (Prefixes s)" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   807
qed
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   808
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   809
lemma LV_STAR_finite:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   810
  assumes "\<forall>s. finite (LV r s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   811
  shows "finite (LV (STAR r) s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   812
proof(induct s rule: length_induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   813
  fix s::"char list"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   814
  assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   815
  then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   816
    by (auto simp add: strict_suffix_def) 
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   817
  define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   818
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   819
  define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   820
  have "finite S1" using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   821
    unfolding S1_def by (simp_all add: finite_Prefixes)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   822
  moreover 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   823
  with IH have "finite S2" unfolding S2_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   824
    by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   825
  ultimately 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   826
  have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   827
  moreover 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   828
  have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   829
  unfolding S1_def S2_def f_def
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   830
  unfolding LV_def image_def prefix_def strict_suffix_def
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   831
  apply(auto)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   832
  apply(case_tac x)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   833
  apply(auto elim: Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   834
  apply(erule Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   835
  apply(auto)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   836
  apply(case_tac vs)
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   837
  apply(auto intro: Prf.intros)  
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   838
  apply(rule exI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   839
  apply(rule conjI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   840
  apply(rule_tac x="flat a" in exI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   841
  apply(rule conjI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   842
  apply(rule_tac x="flats list" in exI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   843
  apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   844
  apply(blast)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   845
  using Prf.intros(6) by blast  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
  ultimately
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   847
  show "finite (LV (STAR r) s)" by (simp add: finite_subset)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
qed  
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849
    
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   850
lemma LV_UPNTIMES_STAR:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   851
  "LV (UPNTIMES r n) s \<subseteq> LV (STAR r) s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   852
by(auto simp add: LV_def intro: Prf.intros elim: Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   853
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   854
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   855
lemma LV_NTIMES_0:
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   856
  shows "LV (NTIMES r 0) s \<subseteq> {Stars []}"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   857
unfolding LV_def
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   858
apply(auto elim: Prf_elims)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   859
done
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   860
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   861
lemma LV_NTIMES_1:
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   862
  shows "LV (NTIMES r 1) s \<subseteq> (\<lambda>v. Stars [v]) ` (LV r s)"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   863
unfolding LV_def
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   864
apply(auto elim!: Prf_elims)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   865
apply(case_tac vs1)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   866
apply(simp)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   867
apply(case_tac vs2)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   868
apply(simp)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   869
apply(simp)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   870
apply(simp)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   871
done
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   872
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   873
lemma LV_NTIMES_2:
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   874
  shows "LV (NTIMES r 2) [] \<subseteq> (\<lambda>(v1,v2). Stars [v1,v2]) ` (LV r [] \<times> LV r [])"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   875
unfolding LV_def
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   876
apply(auto elim!: Prf_elims simp add: image_def)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   877
apply(case_tac vs1)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   878
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   879
apply(case_tac vs2)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   880
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   881
apply(case_tac list)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   882
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   883
done
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   884
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   885
lemma LV_NTIMES_3:
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   886
  shows "LV (NTIMES r (Suc n)) [] = (\<lambda>(v,vs). Stars (v#vs)) ` (LV r [] \<times> (Stars -` (LV (NTIMES r n) [])))"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   887
unfolding LV_def
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   888
apply(auto elim!: Prf_elims simp add: image_def)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   889
apply(case_tac vs1)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   890
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   891
apply(case_tac vs2)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   892
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   893
apply(subst append.simps(1)[symmetric])
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   894
apply(rule Prf.intros)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   895
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   896
apply(subst append.simps(1)[symmetric])
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   897
apply(rule Prf.intros)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   898
apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   899
done
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   900
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   901
thm card_cartesian_product
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   902
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   903
lemma finite_list:
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   904
  assumes "finite A"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   905
  shows "finite {vs. \<forall>v\<in>set vs. v \<in> A \<and> length vs = n}"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   906
  apply(induct n)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   907
   apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   908
   apply (smt Collect_cong empty_iff finite.emptyI finite.insertI 
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   909
   in_listsI list.set(1) lists_empty mem_Collect_eq singleton_conv2)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   910
  apply(rule_tac B="{[]} \<union> (\<lambda>(v,vs). v # vs) `(A \<times> {vs. \<forall>v\<in>set vs. v \<in> A \<and> length vs = n})" in finite_subset)  
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   911
   apply(auto simp add: image_def)[1]
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   912
   apply(case_tac x)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   913
    apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   914
   apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   915
  apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   916
  apply(rule finite_imageI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   917
    using assms
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   918
    apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   919
    done
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   920
      
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   921
lemma test:
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   922
  "LV (NTIMES r n) [] \<subseteq> Stars ` {vs. \<forall>v \<in> set vs. v \<in> LV r [] \<and> length vs = n}"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   923
apply(auto simp add: LV_def elim: Prf_elims)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   924
done
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   925
    
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   926
lemma test3:
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   927
  "LV (FROMNTIMES r n) [] \<subseteq> Stars ` {vs. \<forall>v \<in> set vs. v \<in> LV r [] \<and> length vs = n}"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   928
  apply(auto simp add: image_def LV_def elim!: Prf_elims)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   929
   apply blast
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   930
  apply(case_tac vs)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   931
    apply(auto)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   932
  done   
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   933
    
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   934
    
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   935
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   936
lemma LV_NTIMES_empty_finite:
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   937
  assumes "finite (LV r [])"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   938
  shows "finite (LV (NTIMES r n) [])"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   939
  using assms
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   940
  apply -  
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   941
  apply(rule finite_subset)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   942
   apply(rule test)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   943
  apply(rule finite_imageI)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   944
    apply(rule finite_list)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   945
   apply(simp)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   946
  done
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   947
    
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   948
lemma LV_NTIMES_STAR:
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   949
  "LV (NTIMES r n) s \<subseteq> LV (STAR r) s"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   950
apply(auto simp add: LV_def intro: Prf.intros elim!: Prf_elims)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   951
apply(rule Prf.intros)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   952
oops
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   953
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   954
lemma LV_FROMNTIMES_STAR:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   955
  "LV (FROMNTIMES r n) s \<subseteq> LV (STAR r) s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   956
apply(auto simp add: LV_def intro: Prf.intros elim!: Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   957
oops
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   958
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   959
lemma LV_finite:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   960
  shows "finite (LV r s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   961
proof(induct r arbitrary: s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   962
  case (ZERO s) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   963
  show "finite (LV ZERO s)" by (simp add: LV_simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   964
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   965
  case (ONE s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   966
  show "finite (LV ONE s)" by (simp add: LV_simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   967
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   968
  case (CHAR c s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   969
  show "finite (LV (CHAR c) s)" by (simp add: LV_simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   970
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   971
  case (ALT r1 r2 s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   972
  then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   973
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   974
  case (SEQ r1 r2 s)
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   975
  define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   976
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'"
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   977
  define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'"
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   978
  have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   979
  then have "finite S1" "finite S2" unfolding S1_def S2_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   980
    by (simp_all add: finite_Prefixes finite_Suffixes)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   981
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   982
  have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   983
    unfolding f_def S1_def S2_def 
275
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   984
    unfolding LV_def image_def prefix_def suffix_def
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   985
    apply (auto elim!: Prf_elims)
deea42c83c9e updated
Christian Urban <urbanc@in.tum.de>
parents: 274
diff changeset
   986
    by (metis (mono_tags, lifting) mem_Collect_eq)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   987
  ultimately 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   988
  show "finite (LV (SEQ r1 r2) s)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   989
    by (simp add: finite_subset)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   990
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   991
  case (STAR r s)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   992
  then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   993
next 
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   994
  case (UPNTIMES r n s)
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   995
  have "\<And>s. finite (LV r s)" by fact
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   996
  then show "finite (LV (UPNTIMES r n) s)"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   997
  by (meson LV_STAR_finite LV_UPNTIMES_STAR rev_finite_subset)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   998
next 
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
   999
  case (FROMNTIMES r n s)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
  1000
  have "\<And>s. finite (LV r s)" by fact
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
  1001
  then show "finite (LV (FROMNTIMES r n) s)"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 273
diff changeset
  1002
  
273
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1003
qed
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1004
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1005
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1006
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1007
section {* Our POSIX Definition *}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1008
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1009
inductive 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1010
  Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1011
where
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1012
  Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1013
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1014
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1015
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1016
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1017
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r1 \<and> s\<^sub>4 \<in> L r2)\<rbrakk> \<Longrightarrow> 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1018
    (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1019
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1020
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk>
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1021
    \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1022
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1023
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1024
inductive_cases Posix_elims:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1025
  "s \<in> ZERO \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1026
  "s \<in> ONE \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1027
  "s \<in> CHAR c \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1028
  "s \<in> ALT r1 r2 \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1029
  "s \<in> SEQ r1 r2 \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1030
  "s \<in> STAR r \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1031
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1032
lemma Posix1:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1033
  assumes "s \<in> r \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1034
  shows "s \<in> L r" "flat v = s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1035
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1036
by (induct s r v rule: Posix.induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1037
   (auto simp add: Sequ_def)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1038
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1039
text {*
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1040
  Our Posix definition determines a unique value.
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1041
*}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1042
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1043
lemma Posix_determ:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1044
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1045
  shows "v1 = v2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1046
using assms
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1047
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1048
  case (Posix_ONE v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1049
  have "[] \<in> ONE \<rightarrow> v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1050
  then show "Void = v2" by cases auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1051
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1052
  case (Posix_CHAR c v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1053
  have "[c] \<in> CHAR c \<rightarrow> v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1054
  then show "Char c = v2" by cases auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1055
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1056
  case (Posix_ALT1 s r1 v r2 v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1057
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1058
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1059
  have "s \<in> r1 \<rightarrow> v" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1060
  then have "s \<in> L r1" by (simp add: Posix1)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1061
  ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1062
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1063
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1064
  ultimately have "v = v'" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1065
  then show "Left v = v2" using eq by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1066
next 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1067
  case (Posix_ALT2 s r2 v r1 v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1068
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1069
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1070
  have "s \<notin> L r1" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1071
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1072
    by cases (auto simp add: Posix1) 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1073
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1074
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1075
  ultimately have "v = v'" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1076
  then show "Right v = v2" using eq by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1077
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1078
  case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1079
  have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1080
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1081
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by fact+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1082
  then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1083
  apply(cases) apply (auto simp add: append_eq_append_conv2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1084
  using Posix1(1) by fastforce+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1085
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1086
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1087
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1088
  ultimately show "Seq v1 v2 = v'" by simp
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1089
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1090
  case (Posix_STAR1 s1 r v s2 vs v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1091
  have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" 
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1092
       "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1093
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" by fact+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1094
  then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1095
  apply(cases) apply (auto simp add: append_eq_append_conv2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1096
  using Posix1(1) apply fastforce
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1097
  apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1098
  using Posix1(2) by blast
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1099
  moreover
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1100
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1101
            "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1102
  ultimately show "Stars (v # vs) = v2" by auto
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1103
next
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1104
  case (Posix_STAR2 r v2)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1105
  have "[] \<in> STAR r \<rightarrow> v2" by fact
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1106
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1107
qed
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1108
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1109
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1110
text {*
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1111
  Our POSIX value is a lexical value.
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1112
*}
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1113
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1114
lemma Posix_LV:
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1115
  assumes "s \<in> r \<rightarrow> v"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1116
  shows "v \<in> LV r s"
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1117
using assms unfolding LV_def
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1118
apply(induct rule: Posix.induct)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1119
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1120
done
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1121
e85099ac4c6c updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1122
end