MyhillNerode.thy
author urbanc
Sun, 03 Oct 2010 06:32:12 +0000
changeset 0 932f27fc6b55
child 2 0d63f1c1f67f
permissions -rw-r--r--
added initial version by Chunhan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     1
theory RegExp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     2
  imports "Main" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     3
begin
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     4
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     5
text {* sequential composition of languages *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     6
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     7
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     8
  lang_seq :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ; _" [100,100] 100)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
     9
where 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    10
  "L1 ; L2 = {s1@s2 | s1 s2. s1 \<in> L1 \<and> s2 \<in> L2}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    11
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    12
lemma lang_seq_empty:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    13
  shows "{[]} ; L = L"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    14
  and   "L ; {[]} = L"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    15
unfolding lang_seq_def by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    16
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    17
lemma lang_seq_null:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    18
  shows "{} ; L = {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    19
  and   "L ; {} = {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    20
unfolding lang_seq_def by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    21
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    22
lemma lang_seq_append:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    23
  assumes a: "s1 \<in> L1"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    24
  and     b: "s2 \<in> L2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    25
  shows "s1@s2 \<in> L1 ; L2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    26
unfolding lang_seq_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    27
using a b by auto 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    28
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    29
lemma lang_seq_union:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    30
  shows "(L1 \<union> L2); L3 = (L1; L3) \<union> (L2; L3)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    31
  and   "L1; (L2 \<union> L3) = (L1; L2) \<union> (L1; L3)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    32
unfolding lang_seq_def by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    33
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    34
lemma lang_seq_assoc:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    35
  shows "(L1 ; L2) ; L3 = L1 ; (L2 ; L3)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    36
by (simp add: lang_seq_def Collect_def mem_def expand_fun_eq)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    37
   (metis append_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    38
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    39
lemma lang_seq_minus:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    40
  shows "(L1; L2) - {[]} =
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    41
           (if [] \<in> L1 then L2 - {[]} else {}) \<union> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    42
           (if [] \<in> L2 then L1 - {[]} else {}) \<union> ((L1 - {[]}); (L2 - {[]}))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    43
apply(auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    44
apply(metis mem_def self_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    45
apply(metis mem_def self_append_conv2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    46
apply(metis mem_def self_append_conv2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    47
apply(metis mem_def self_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    48
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    49
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    50
section {* Kleene star for languages defined as least fixed point *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    51
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    52
inductive_set
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    53
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    54
  for L :: "string set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    55
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    56
  start[intro]: "[] \<in> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    57
| step[intro]:  "\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> s1@s2 \<in> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    58
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    59
lemma lang_star_empty:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    60
  shows "{}\<star> = {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    61
by (auto elim: Star.cases)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    62
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    63
lemma lang_star_cases:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    64
  shows "L\<star> =  {[]} \<union> L ; L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    65
proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    66
  { fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    67
    have "x \<in> L\<star> \<Longrightarrow> x \<in> {[]} \<union> L ; L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    68
      unfolding lang_seq_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    69
    by (induct rule: Star.induct) (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    70
  }
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    71
  then show "L\<star> \<subseteq> {[]} \<union> L ; L\<star>" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    72
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    73
  show "{[]} \<union> L ; L\<star> \<subseteq> L\<star>" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    74
    unfolding lang_seq_def by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    75
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    76
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    77
lemma lang_star_cases':
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    78
  shows "L\<star> =  {[]} \<union> L\<star> ; L"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    79
proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    80
  { fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    81
    have "x \<in> L\<star> \<Longrightarrow> x \<in> {[]} \<union> L\<star> ; L"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    82
      unfolding lang_seq_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    83
    apply (induct rule: Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    84
    apply simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    85
    apply simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    86
    apply (erule disjE)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    87
    apply (auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    88
    apply (erule exE | erule conjE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    89
    apply (rule disjI2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    90
    apply (rule_tac x = "s1 @ s1a" in exI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    91
    by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    92
  }
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    93
  then show "L\<star> \<subseteq> {[]} \<union> L\<star> ; L" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    94
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    95
  show "{[]} \<union> L\<star> ; L \<subseteq> L\<star>" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    96
    unfolding lang_seq_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    97
    apply auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    98
    apply (erule Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
    99
    apply auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   100
    apply (drule step[of _ _ "[]"])
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   101
    by (auto intro:start)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   102
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   103
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   104
lemma lang_star_simple:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   105
  shows "L \<subseteq> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   106
by (subst lang_star_cases)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   107
   (auto simp only: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   108
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   109
lemma lang_star_prop0_aux:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   110
  "s2 \<in> L\<star> \<Longrightarrow> \<forall> s1. s1 \<in> L \<longrightarrow> (\<exists> s3 s4. s3 \<in> L\<star> \<and> s4 \<in> L \<and> s1 @ s2 = s3 @ s4)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   111
apply (erule Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   112
apply (clarify, rule_tac x = "[]" in exI, rule_tac x = s1 in exI, simp add:start)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   113
apply (clarify, drule_tac x = s1 in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   114
apply (drule mp, simp, clarify)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   115
apply (rule_tac x = "s1a @ s3" in exI, rule_tac x = s4 in exI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   116
by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   117
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   118
lemma lang_star_prop0:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   119
  "\<lbrakk>s1 \<in> L; s2 \<in> L\<star>\<rbrakk> \<Longrightarrow> \<exists> s3 s4. s3 \<in> L\<star> \<and> s4 \<in> L \<and> s1 @ s2 = s3 @ s4" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   120
by (auto dest:lang_star_prop0_aux)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   121
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   122
lemma lang_star_prop1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   123
  assumes asm: "L1; L2 \<subseteq> L2" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   124
  shows "L1\<star>; L2 \<subseteq> L2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   125
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   126
  { fix s1 s2
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   127
    assume minor: "s2 \<in> L2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   128
    assume major: "s1 \<in> L1\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   129
    then have "s1@s2 \<in> L2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   130
    proof(induct rule: Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   131
      case start
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   132
      show "[]@s2 \<in> L2" using minor by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   133
    next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   134
      case (step s1 s1')
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   135
      have "s1 \<in> L1" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   136
      moreover
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   137
      have "s1'@s2 \<in> L2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   138
      ultimately have "s1@(s1'@s2) \<in> L1; L2" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   139
      with asm have "s1@(s1'@s2) \<in> L2" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   140
      then show "(s1@s1')@s2 \<in> L2" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   141
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   142
  } 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   143
  then show "L1\<star>; L2 \<subseteq> L2" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   144
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   145
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   146
lemma lang_star_prop2_aux:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   147
  "s2 \<in> L2\<star> \<Longrightarrow> \<forall> s1. s1 \<in> L1 \<and> L1 ; L2 \<subseteq> L1 \<longrightarrow> s1 @ s2 \<in> L1"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   148
apply (erule Star.induct, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   149
apply (clarify, drule_tac x = "s1a @ s1" in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   150
by (auto simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   151
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   152
lemma lang_star_prop2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   153
  "L1; L2 \<subseteq> L1 \<Longrightarrow> L1 ; L2\<star> \<subseteq> L1"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   154
by (auto dest!:lang_star_prop2_aux simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   155
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   156
lemma lang_star_seq_subseteq: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   157
  shows "L ; L\<star> \<subseteq> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   158
using lang_star_cases by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   159
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   160
lemma lang_star_double:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   161
  shows "L\<star>; L\<star> = L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   162
proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   163
  show "L\<star> ; L\<star> \<subseteq> L\<star>" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   164
    using lang_star_prop1 lang_star_seq_subseteq by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   165
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   166
  have "L\<star> \<subseteq> L\<star> \<union> L\<star>; (L; L\<star>)" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   167
  also have "\<dots> = L\<star>;{[]} \<union> L\<star>; (L; L\<star>)" by (simp add: lang_seq_empty)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   168
  also have "\<dots> = L\<star>; ({[]} \<union> L; L\<star>)" by (simp only: lang_seq_union)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   169
  also have "\<dots> = L\<star>; L\<star>" using lang_star_cases by simp 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   170
  finally show "L\<star> \<subseteq> L\<star> ; L\<star>" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   171
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   172
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   173
lemma lang_star_seq_subseteq': 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   174
  shows "L\<star>; L \<subseteq> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   175
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   176
  have "L \<subseteq> L\<star>" by (rule lang_star_simple)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   177
  then have "L\<star>; L \<subseteq> L\<star>; L\<star>" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   178
  then show "L\<star>; L \<subseteq> L\<star>" using lang_star_double by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   179
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   180
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   181
lemma
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   182
  shows "L\<star> \<subseteq> L\<star>\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   183
by (rule lang_star_simple)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   184
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   185
section {* tricky section  *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   186
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   187
lemma k1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   188
  assumes b: "s \<in> L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   189
  and a: "s \<noteq> []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   190
  shows "s \<in> (L - {[]}); L\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   191
using b a
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   192
apply(induct rule: Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   193
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   194
apply(case_tac "s1=[]")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   195
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   196
apply(simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   197
apply(blast)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   198
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   199
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   200
section {* (relies on lemma k1) *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   201
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   202
lemma zzz:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   203
  shows "{s. c#s \<in> L1\<star>} = {s. c#s \<in> L1} ; (L1\<star>)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   204
apply(auto simp add: lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   205
apply(drule k1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   206
apply(auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   207
apply(auto simp add: lang_seq_def)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   208
apply(rule_tac x="tl s1" in exI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   209
apply(rule_tac x="s2" in exI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   210
apply(auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   211
apply(auto simp add: Cons_eq_append_conv)[2]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   212
apply(drule lang_seq_append)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   213
apply(assumption)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   214
apply(rotate_tac 1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   215
apply(drule rev_subsetD)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   216
apply(rule lang_star_seq_subseteq)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   217
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   218
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   219
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   220
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   221
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   222
section {* regular expressions *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   223
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   224
datatype rexp =
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   225
  NULL
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   226
| EMPTY
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   227
| CHAR char
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   228
| SEQ rexp rexp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   229
| ALT rexp rexp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   230
| STAR rexp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   231
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   232
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   233
consts L:: "'a \<Rightarrow> string set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   234
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   235
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   236
  L_rexp :: "rexp \<Rightarrow> string set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   237
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   238
  "L_rexp (NULL) = {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   239
| "L_rexp (EMPTY) = {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   240
| "L_rexp (CHAR c) = {[c]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   241
| "L_rexp (SEQ r1 r2) = (L_rexp r1) ; (L_rexp r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   242
| "L_rexp (ALT r1 r2) = (L_rexp r1) \<union> (L_rexp r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   243
| "L_rexp (STAR r) = (L_rexp r)\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   244
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   245
defs (overloaded)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   246
  l_rexp_abs: "L rexp \<equiv> L_rexp rexp"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   247
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   248
declare L_rexp.simps [simp del] L_rexp.simps [folded l_rexp_abs, simp add]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   249
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   250
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   251
  Ls :: "rexp set \<Rightarrow> string set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   252
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   253
  "Ls R = (\<Union>r\<in>R. (L r))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   254
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   255
lemma Ls_union:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   256
  "Ls (R1 \<union> R2) = (Ls R1) \<union> (Ls R2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   257
unfolding Ls_def by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   258
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   259
text {* helper function for termination proofs *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   260
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   261
 Left :: "rexp \<Rightarrow> rexp"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   262
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   263
 "Left (SEQ r1 r2) = r1"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   264
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   265
text {* dagger function *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   266
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   267
function
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   268
  dagger :: "rexp \<Rightarrow> char \<Rightarrow> rexp list" ("_ \<dagger> _")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   269
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   270
  c1: "(NULL \<dagger> c) = []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   271
| c2: "(EMPTY) \<dagger> c = []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   272
| c3: "(CHAR c') \<dagger> c = (if c = c' then [EMPTY] else [])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   273
| c4: "(ALT r1 r2) \<dagger> c = r1 \<dagger> c @ r2 \<dagger> c"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   274
| c5: "(SEQ NULL r2) \<dagger> c = []" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   275
| c6: "(SEQ EMPTY r2) \<dagger> c = r2 \<dagger> c" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   276
| c7: "(SEQ (CHAR c') r2) \<dagger> c = (if c = c' then [r2] else [])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   277
| c8: "(SEQ (SEQ r11 r12) r2) \<dagger> c = (SEQ r11 (SEQ r12 r2)) \<dagger> c" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   278
| c9: "(SEQ (ALT r11 r12) r2) \<dagger> c = (SEQ r11 r2) \<dagger> c @ (SEQ r12 r2) \<dagger> c" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   279
| c10: "(SEQ (STAR r1) r2) \<dagger> c = r2 \<dagger> c @ [SEQ r' (SEQ (STAR r1) r2). r' \<leftarrow> r1 \<dagger> c]" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   280
| c11: "(STAR r) \<dagger> c = [SEQ r' (STAR r) .  r' \<leftarrow> r \<dagger> c]"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   281
by (pat_completeness) (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   282
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   283
termination dagger
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   284
  by (relation "measures [\<lambda>(r, c). size r, \<lambda>(r, c). size (Left r)]") (simp_all)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   285
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   286
lemma dagger_correctness:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   287
  "Ls (set r \<dagger> c) = {s. c#s \<in> L r}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   288
proof (induct rule: dagger.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   289
  case (1 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   290
  show "Ls (set NULL \<dagger> c) = {s. c#s \<in> L NULL}" by (simp add: Ls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   291
next  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   292
  case (2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   293
  show "Ls (set EMPTY \<dagger> c) = {s. c#s \<in> L EMPTY}" by (simp add: Ls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   294
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   295
  case (3 c' c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   296
  show "Ls (set CHAR c' \<dagger> c) = {s. c#s \<in> L (CHAR c')}" by (simp add: Ls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   297
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   298
  case (4 r1 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   299
  have ih1: "Ls (set r1 \<dagger> c) = {s. c#s \<in> L r1}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   300
  have ih2: "Ls (set r2 \<dagger> c) = {s. c#s \<in> L r2}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   301
  show "Ls (set ALT r1 r2 \<dagger> c) = {s. c#s \<in> L (ALT r1 r2)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   302
    by (simp add: Ls_union ih1 ih2 Collect_disj_eq)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   303
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   304
  case (5 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   305
  show "Ls (set SEQ NULL r2 \<dagger> c) = {s. c#s \<in> L (SEQ NULL r2)}" by (simp add: Ls_def lang_seq_null)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   306
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   307
  case (6 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   308
  have ih: "Ls (set r2 \<dagger> c) = {s. c#s \<in> L r2}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   309
  show "Ls (set SEQ EMPTY r2 \<dagger> c) = {s. c#s \<in> L (SEQ EMPTY r2)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   310
    by (simp add: ih lang_seq_empty)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   311
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   312
  case (7 c' r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   313
  show "Ls (set SEQ (CHAR c') r2 \<dagger> c) = {s. c#s \<in> L (SEQ (CHAR c') r2)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   314
    by (simp add: Ls_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   315
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   316
  case (8 r11 r12 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   317
  have ih: "Ls (set SEQ r11 (SEQ r12 r2) \<dagger> c) = {s. c#s \<in> L (SEQ r11 (SEQ r12 r2))}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   318
  show "Ls (set SEQ (SEQ r11 r12) r2 \<dagger> c) = {s. c#s \<in> L (SEQ (SEQ r11 r12) r2)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   319
    by (simp add: ih lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   320
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   321
  case (9 r11 r12 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   322
  have ih1: "Ls (set SEQ r11 r2 \<dagger> c) = {s. c#s \<in> L (SEQ r11 r2)}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   323
  have ih2: "Ls (set SEQ r12 r2 \<dagger> c) = {s. c#s \<in> L (SEQ r12 r2)}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   324
  show "Ls (set SEQ (ALT r11 r12) r2 \<dagger> c) = {s. c#s \<in> L (SEQ (ALT r11 r12) r2)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   325
    by (simp add: Ls_union ih1 ih2 lang_seq_union Collect_disj_eq)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   326
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   327
  case (10 r1 r2 c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   328
  have ih2: "Ls (set r2 \<dagger> c) = {s. c#s \<in> L r2}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   329
  have ih1: "Ls (set r1 \<dagger> c) = {s. c#s \<in> L r1}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   330
  have "Ls (set SEQ (STAR r1) r2 \<dagger> c) = Ls (set r2 \<dagger> c) \<union> (Ls (set r1 \<dagger> c); ((L r1)\<star> ; L r2))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   331
    by (auto simp add: lang_seq_def Ls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   332
  also have "\<dots> = {s. c#s \<in> L r2} \<union> ({s. c#s \<in> L r1} ; ((L r1)\<star> ; L r2))" using ih1 ih2 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   333
  also have "\<dots> = {s. c#s \<in> L r2} \<union> ({s. c#s \<in> L r1} ; (L r1)\<star>) ; L r2" by (simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   334
  also have "\<dots> = {s. c#s \<in> L r2} \<union> {s. c#s \<in> (L r1)\<star>} ; L r2" by (simp add: zzz)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   335
  also have "\<dots> = {s. c#s \<in> L r2} \<union> {s. c#s \<in> (L r1)\<star> ; L r2}" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   336
    by (auto simp add: lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   337
  also have "\<dots> = {s. c#s \<in> (L r1)\<star> ; L r2}" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   338
    by (force simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   339
  finally show "Ls (set SEQ (STAR r1) r2 \<dagger> c) = {s. c#s \<in> L (SEQ (STAR r1) r2)}" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   340
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   341
  case (11 r c)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   342
  have ih: "Ls (set r \<dagger> c) = {s. c#s \<in> L r}" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   343
  have "Ls (set (STAR r) \<dagger> c) =  Ls (set r \<dagger> c) ; (L r)\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   344
    by (auto simp add: lang_seq_def Ls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   345
  also have "\<dots> = {s. c#s \<in> L r} ;  (L r)\<star>" using ih by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   346
  also have "\<dots> = {s. c#s \<in> (L r)\<star>}" using zzz by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   347
  finally show "Ls (set (STAR r) \<dagger> c) = {s. c#s \<in> L (STAR r)}" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   348
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   349
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   350
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   351
text {* matcher function (based on the "list"-dagger function) *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   352
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   353
  first_True :: "bool list \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   354
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   355
  "first_True [] = False"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   356
| "first_True (x#xs) = (if x then True else first_True xs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   357
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   358
lemma not_first_True[simp]:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   359
  shows "(\<not>(first_True xs)) = (\<forall>x \<in> set xs. \<not>x)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   360
by (induct xs) (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   361
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   362
lemma first_True:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   363
  shows "(first_True xs) = (\<exists>x \<in> set xs. x)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   364
by (induct xs) (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   365
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   366
text {* matcher function *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   367
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   368
function
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   369
  matcher :: "rexp \<Rightarrow> string \<Rightarrow> bool" ("_ ! _")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   370
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   371
  "NULL ! s = False"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   372
| "EMPTY ! s = (s =[])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   373
| "CHAR c ! s = (s = [c])" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   374
| "ALT r1 r2 ! s = (r1 ! s \<or> r2 ! s)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   375
| "STAR r ! [] = True"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   376
| "STAR r ! c#s =  first_True [SEQ (r') (STAR r) ! s. r' \<leftarrow> r \<dagger> c]"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   377
| "SEQ r1 r2 ! [] = (r1 ! [] \<and> r2 ! [])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   378
| "SEQ NULL r2 ! (c#s) = False"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   379
| "SEQ EMPTY r2 ! (c#s) = (r2 ! c#s)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   380
| "SEQ (CHAR c') r2 ! (c#s) = (if c'=c then r2 ! s else False)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   381
| "SEQ (SEQ r11 r12) r2 ! (c#s) = (SEQ r11 (SEQ r12 r2) ! c#s)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   382
| "SEQ (ALT r11 r12) r2 ! (c#s) = ((SEQ r11 r2) ! (c#s) \<or> (SEQ r12 r2) ! (c#s))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   383
| "SEQ (STAR r1) r2 ! (c#s) = (r2 ! (c#s) \<or> first_True [SEQ r' (SEQ (STAR r1) r2) ! s. r' \<leftarrow> r1 \<dagger> c])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   384
by (pat_completeness) (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   385
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   386
termination matcher 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   387
  by(relation "measures [\<lambda>(r,s). length s, \<lambda>(r,s). size r, \<lambda>(r,s). size (Left r)]") (simp_all)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   388
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   389
text {* positive correctness of the matcher *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   390
lemma matcher1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   391
  shows "r ! s \<Longrightarrow> s \<in> L r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   392
proof (induct rule: matcher.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   393
  case (1 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   394
  have "NULL ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   395
  then show "s \<in> L NULL" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   396
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   397
  case (2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   398
  have "EMPTY ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   399
  then show "s \<in> L EMPTY" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   400
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   401
  case (3 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   402
  have "CHAR c ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   403
  then show "s \<in> L (CHAR c)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   404
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   405
  case (4 r1 r2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   406
  have ih1: "r1 ! s \<Longrightarrow> s \<in> L r1" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   407
  have ih2: "r2 ! s \<Longrightarrow> s \<in> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   408
  have "ALT r1 r2 ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   409
  with ih1 ih2 show "s \<in> L (ALT r1 r2)" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   410
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   411
  case (5 r)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   412
  have "STAR r ! []" by fact 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   413
  then show "[] \<in> L (STAR r)" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   414
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   415
  case (6 r c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   416
  have ih1: "\<And>rx. \<lbrakk>rx \<in> set r \<dagger> c; SEQ rx (STAR r) ! s\<rbrakk> \<Longrightarrow> s \<in> L (SEQ rx (STAR r))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   417
  have as: "STAR r ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   418
  then obtain r' where imp1: "r' \<in> set r \<dagger> c" and imp2: "SEQ r' (STAR r) ! s" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   419
    by (auto simp add: first_True)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   420
  from imp2 imp1 have "s \<in> L (SEQ r' (STAR r))" using ih1 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   421
  then have "s \<in> L r' ; (L r)\<star>" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   422
  then have "s \<in> Ls (set r \<dagger> c) ; (L r)\<star>" using imp1 by (auto simp add: Ls_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   423
  then have "s \<in> {s. c#s \<in> L r} ; (L r)\<star>" by (auto simp add: dagger_correctness)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   424
  then have "s \<in> {s. c#s \<in> (L r)\<star>}" by (simp add: zzz)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   425
  then have "c#s \<in> {[c]}; {s. c#s \<in> (L r)\<star>}" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   426
  then have "c#s \<in> (L r)\<star>" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   427
  then show "c#s \<in> L (STAR r)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   428
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   429
  case (7 r1 r2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   430
  have ih1: "r1 ! [] \<Longrightarrow> [] \<in> L r1" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   431
  have ih2: "r2 ! [] \<Longrightarrow> [] \<in> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   432
  have as: "SEQ r1 r2 ! []" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   433
  then have "r1 ! [] \<and> r2 ! []" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   434
  then show "[] \<in> L (SEQ r1 r2)" using ih1 ih2 by (simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   435
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   436
  case (8 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   437
  have "SEQ NULL r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   438
  then show "c#s \<in> L (SEQ NULL r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   439
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   440
  case (9 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   441
  have ih1: "r2 ! c#s \<Longrightarrow> c#s \<in> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   442
  have "SEQ EMPTY r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   443
  then show "c#s \<in> L (SEQ EMPTY r2)" using ih1 by (simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   444
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   445
  case (10 c' r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   446
  have ih1: "\<lbrakk>c' = c; r2 ! s\<rbrakk> \<Longrightarrow> s \<in> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   447
  have "SEQ (CHAR c') r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   448
  then show "c#s \<in> L (SEQ (CHAR c') r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   449
    using ih1 by (auto simp add: lang_seq_def split: if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   450
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   451
  case (11 r11 r12 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   452
  have ih1: "SEQ r11 (SEQ r12 r2) ! c#s \<Longrightarrow> c#s \<in> L (SEQ r11 (SEQ r12 r2))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   453
  have "SEQ (SEQ r11 r12) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   454
  then have "c#s \<in> L (SEQ r11 (SEQ r12 r2))" using ih1 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   455
  then show "c#s \<in> L (SEQ (SEQ r11 r12) r2)" by (simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   456
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   457
  case (12 r11 r12 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   458
  have ih1: "SEQ r11 r2 ! c#s \<Longrightarrow> c#s \<in> L (SEQ r11 r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   459
  have ih2: "SEQ r12 r2 ! c#s \<Longrightarrow> c#s \<in> L (SEQ r12 r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   460
  have "SEQ (ALT r11 r12) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   461
  then show "c#s \<in> L (SEQ (ALT r11 r12) r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   462
    using ih1 ih2 by (auto simp add: lang_seq_union)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   463
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   464
  case (13 r1 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   465
  have ih1: "r2 ! c#s \<Longrightarrow> c#s \<in> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   466
  have ih2: "\<And>r'. \<lbrakk>r' \<in> set r1 \<dagger> c; SEQ r' (SEQ (STAR r1) r2) ! s\<rbrakk> \<Longrightarrow> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   467
                         s \<in> L (SEQ r' (SEQ (STAR r1) r2))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   468
  have "SEQ (STAR r1) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   469
  then have "(r2 ! c#s) \<or> (\<exists>r' \<in> set r1 \<dagger> c. SEQ r' (SEQ (STAR r1) r2) ! s)"  by (auto simp add: first_True)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   470
  moreover
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   471
  { assume "r2 ! c#s"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   472
    with ih1 have "c#s \<in> L r2" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   473
    then have "c # s \<in> L r1\<star> ; L r2" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   474
      by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   475
    then have "c#s \<in> L (SEQ (STAR r1) r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   476
  }
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   477
  moreover
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   478
  { assume "\<exists>r' \<in> set r1 \<dagger> c. SEQ r' (SEQ (STAR r1) r2) ! s"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   479
    then obtain r' where imp1: "r' \<in> set r1 \<dagger> c" and imp2: "SEQ r' (SEQ (STAR r1) r2) ! s" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   480
    from imp2 imp1 have "s \<in> L (SEQ r' (SEQ (STAR r1) r2))" using ih2 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   481
    then have "s \<in> L r' ; ((L r1)\<star> ; L r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   482
    then have "s \<in> Ls (set r1 \<dagger> c) ; ((L r1)\<star> ; L r2)" using imp1 by (auto simp add: Ls_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   483
    then have "s \<in> {s. c#s \<in> L r1} ; ((L r1)\<star> ; L r2)" by (simp add: dagger_correctness)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   484
    then have "s \<in> ({s. c#s \<in> L r1} ; (L r1)\<star>) ; L r2" by (simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   485
    then have "s \<in> {s. c#s \<in> (L r1)\<star>} ; L r2" by (simp add: zzz)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   486
    then have "c#s \<in> {[c]}; ({s. c#s \<in> (L r1)\<star>}; L r2)" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   487
    then have "c#s \<in> ({[c]}; {s. c#s \<in> (L r1)\<star>}) ; L r2" by (simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   488
    then have "c#s \<in> (L r1)\<star>; L r2" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   489
    then have "c#s \<in> L (SEQ (STAR r1) r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   490
  }
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   491
  ultimately show "c#s \<in> L (SEQ (STAR r1) r2)" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   492
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   493
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   494
text {* negative correctness of the matcher *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   495
lemma matcher2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   496
  shows "\<not> r ! s \<Longrightarrow> s \<notin> L r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   497
proof (induct rule: matcher.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   498
  case (1 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   499
  have "\<not> NULL ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   500
  then show "s \<notin> L NULL" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   501
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   502
  case (2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   503
  have "\<not> EMPTY ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   504
  then show "s \<notin> L EMPTY" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   505
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   506
  case (3 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   507
  have "\<not> CHAR c ! s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   508
  then show "s \<notin> L (CHAR c)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   509
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   510
  case (4 r1 r2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   511
  have ih2: "\<not> r1 ! s \<Longrightarrow> s \<notin> L r1" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   512
  have ih4: "\<not> r2 ! s \<Longrightarrow> s \<notin> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   513
  have "\<not> ALT r1 r2 ! s" by fact 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   514
  then show "s \<notin> L (ALT r1 r2)" by (simp add: ih2 ih4)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   515
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   516
  case (5 r)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   517
  have "\<not> STAR r ! []" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   518
  then show "[] \<notin> L (STAR r)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   519
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   520
  case (6 r c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   521
  have ih: "\<And>rx. \<lbrakk>rx \<in> set r \<dagger> c; \<not>SEQ rx (STAR r) ! s\<rbrakk> \<Longrightarrow> s \<notin> L (SEQ rx (STAR r))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   522
  have as: "\<not> STAR r ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   523
  then have "\<forall>r'\<in> set r \<dagger> c. \<not> (SEQ r' (STAR r) ! s)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   524
  then have "\<forall>r'\<in> set r \<dagger> c. s \<notin> L (SEQ r' (STAR r))" using ih by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   525
  then have "\<forall>r'\<in> set r \<dagger> c. s \<notin> L r' ; ((L r)\<star>)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   526
  then have "s \<notin> (Ls (set r \<dagger> c)) ; ((L r)\<star>)" by (auto simp add: Ls_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   527
  then have "s \<notin> {s. c#s \<in> L r} ; ((L r)\<star>)" by (simp add: dagger_correctness)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   528
  then have "s \<notin> {s. c#s \<in> (L r)\<star>}" by (simp add: zzz)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   529
  then have "c#s \<notin> {[c]} ; {s. c#s \<in> (L r)\<star>}" by (auto simp add: lang_seq_assoc lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   530
  then have "c#s \<notin> (L r)\<star>" by (simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   531
  then show "c#s \<notin> L (STAR r)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   532
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   533
  case (7 r1 r2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   534
  have ih2: "\<not> r1 ! [] \<Longrightarrow> [] \<notin> L r1" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   535
  have ih4: "\<not> r2 ! [] \<Longrightarrow> [] \<notin> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   536
  have "\<not> SEQ r1 r2 ! []" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   537
  then have "\<not> r1 ! [] \<or> \<not> r2 ! []" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   538
  then show "[] \<notin> L (SEQ r1 r2)" using ih2 ih4 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   539
    by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   540
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   541
  case (8 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   542
  have "\<not> SEQ NULL r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   543
  then show "c#s \<notin> L (SEQ NULL r2)" by (simp add: lang_seq_null)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   544
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   545
  case (9 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   546
  have ih1: "\<not> r2 ! c#s \<Longrightarrow> c#s \<notin> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   547
  have "\<not> SEQ EMPTY r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   548
  then show "c#s \<notin> L (SEQ EMPTY r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   549
    using ih1 by (simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   550
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   551
  case (10 c' r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   552
  have ih2: "\<lbrakk>c' = c; \<not>r2 ! s\<rbrakk> \<Longrightarrow> s \<notin> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   553
  have "\<not> SEQ (CHAR c') r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   554
  then show "c#s \<notin> L (SEQ (CHAR c') r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   555
    using ih2 by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   556
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   557
  case (11 r11 r12 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   558
  have ih2: "\<not> SEQ r11 (SEQ r12 r2) ! c#s \<Longrightarrow> c#s \<notin> L (SEQ r11 (SEQ r12 r2))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   559
  have "\<not> SEQ (SEQ r11 r12) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   560
  then show "c#s \<notin> L (SEQ (SEQ r11 r12) r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   561
    using ih2 by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   562
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   563
  case (12 r11 r12 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   564
  have ih2: "\<not> SEQ r11 r2 ! c#s \<Longrightarrow> c#s \<notin> L (SEQ r11 r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   565
  have ih4: "\<not> SEQ r12 r2 ! c#s \<Longrightarrow> c#s \<notin> L (SEQ r12 r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   566
  have "\<not> SEQ (ALT r11 r12) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   567
  then show " c#s \<notin> L (SEQ (ALT r11 r12) r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   568
    using ih2 ih4 by (simp add: lang_seq_union)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   569
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   570
  case (13 r1 r2 c s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   571
  have ih1: "\<not>r2 ! c#s \<Longrightarrow> c#s \<notin> L r2" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   572
  have ih2: "\<And>rx. \<lbrakk>rx \<in> set r1 \<dagger> c; \<not> SEQ rx (SEQ (STAR r1) r2) ! s\<rbrakk> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   573
                   \<Longrightarrow> s \<notin> L (SEQ rx (SEQ (STAR r1) r2))" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   574
  have as: "\<not> SEQ (STAR r1) r2 ! c#s" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   575
  then have as1: "\<not>r2 ! c#s" and as2: "\<forall>r1'\<in>set r1 \<dagger> c. \<not> SEQ r1' (SEQ (STAR r1) r2) ! s" by simp_all
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   576
  from as1 have bs1: "c#s \<notin> L r2" using ih1 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   577
  from as2 have "\<forall>r1'\<in>set r1 \<dagger> c. \<not> SEQ r1' (SEQ (STAR r1) r2) ! s" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   578
  then have "\<forall>r1'\<in>set r1 \<dagger> c. s \<notin> L (SEQ r1' (SEQ (STAR r1) r2))" using ih2 by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   579
  then have "\<forall>r1'\<in>set r1 \<dagger> c. s \<notin> L r1'; ((L r1)\<star>; L r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   580
  then have "s \<notin> (Ls (set r1 \<dagger> c)) ; ((L r1)\<star>; L r2)" by (auto simp add: Ls_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   581
  then have "s \<notin> {s. c#s \<in> L r1} ; ((L r1)\<star>; L r2)" by (simp add: dagger_correctness)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   582
  then have "s \<notin> ({s. c#s \<in> L r1} ; (L r1)\<star>); L r2" by (simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   583
  then have "s \<notin> {s. c#s \<in> (L r1)\<star>}; L r2" by (simp add: zzz)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   584
  then have "c#s \<notin> {[c]}; ({s. c#s \<in> (L r1)\<star>}; L r2)" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   585
  then have "c#s \<notin> (L r1)\<star>; L r2" using bs1 by (auto simp add: lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   586
  then show "c#s \<notin> L (SEQ (STAR r1) r2)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   587
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   588
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   589
section {* Questions *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   590
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   591
text {*
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   592
  - Why was the key lemma k1 omitted; is there an easy, non-induction
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   593
    way for obtaining this property? 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   594
  - Why was False included in the definition of the STAR-clause in
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   595
    the matcher? Has this something to do with executing the code?
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   596
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   597
*}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   598
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   599
section {* Code *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   600
   
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   601
export_code dagger in SML module_name Dagger file - 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   602
export_code matcher in SML module_name Dagger file -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   603
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   604
section {* Examples *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   605
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   606
text {* since now everything is based on lists, the evaluation is quite fast *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   607
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   608
value "NULL ! []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   609
value "(CHAR (CHR ''a'')) ! [CHR ''a'']"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   610
value "((CHAR a) ! [a,a])"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   611
value "(STAR (CHAR a)) ! []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   612
value "(STAR (CHAR a)) ! [a,a]"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   613
value "(SEQ (CHAR (CHR ''a'')) (SEQ (STAR (CHAR (CHR ''b''))) (CHAR (CHR ''c'')))) ! ''abbbbc''"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   614
value "(SEQ (CHAR (CHR ''a'')) (SEQ (STAR (CHAR (CHR ''b''))) (CHAR (CHR ''c'')))) ! ''abbcbbc''"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   615
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   616
section {* Slind et al's matcher based on derivatives *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   617
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   618
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   619
 nullable :: "rexp \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   620
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   621
  "nullable (NULL) = False"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   622
| "nullable (EMPTY) = True"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   623
| "nullable (CHAR c) = False"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   624
| "nullable (ALT r1 r2) = ((nullable r1) \<or> (nullable r2))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   625
| "nullable (SEQ r1 r2) = ((nullable r1) \<and> (nullable r2))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   626
| "nullable (STAR r) = True"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   627
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   628
lemma nullable:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   629
  shows "([] \<in> L r) = nullable r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   630
by (induct r)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   631
   (auto simp add: lang_seq_def) 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   632
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   633
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   634
 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   635
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   636
  "der c (NULL) = NULL"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   637
| "der c (EMPTY) = NULL"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   638
| "der c (CHAR c') = (if c=c' then EMPTY else NULL)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   639
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   640
| "der c (SEQ r1 r2) = ALT (SEQ (der c r1) r2) (if nullable r1 then der c r2 else NULL)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   641
| "der c (STAR r) = SEQ (der c r) (STAR r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   642
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   643
lemma k2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   644
  assumes b: "s \<in> L1\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   645
  and a: "s \<noteq> []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   646
  shows "s \<in> (L1; (L1\<star>))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   647
using b a
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   648
apply(induct rule: Star.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   649
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   650
apply(case_tac "s1=[]")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   651
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   652
apply(simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   653
apply(blast)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   654
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   655
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   656
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   657
lemma der_correctness:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   658
  shows "(s \<in> L (der c r)) = ((c#s) \<in> L r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   659
proof (induct r arbitrary: s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   660
  case (NULL s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   661
  show "(s \<in> L (der c NULL)) = (c#s \<in> L NULL)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   662
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   663
  case (EMPTY s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   664
  show "(s \<in> L (der c EMPTY)) = (c#s \<in> L EMPTY)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   665
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   666
  case (CHAR c' s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   667
  show "(s \<in> L (der c (CHAR c'))) = (c#s \<in> L (CHAR c'))" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   668
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   669
  case (SEQ r1 r2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   670
  have ih1: "\<And>s. (s \<in> L (der c r1)) = (c#s \<in> L r1)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   671
  have ih2: "\<And>s. (s \<in> L (der c r2)) = (c#s \<in> L r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   672
  show "(s \<in> L (der c (SEQ r1 r2))) = (c#s \<in> L (SEQ r1 r2))" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   673
    using ih1 ih2
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   674
    by (auto simp add: nullable[symmetric] lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   675
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   676
  case (ALT r1 r2 s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   677
  have ih1: "\<And>s. (s \<in> L (der c r1)) = (c#s \<in> L r1)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   678
  have ih2: "\<And>s. (s \<in> L (der c r2)) = (c#s \<in> L r2)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   679
  show "(s \<in> L (der c (ALT r1 r2))) = (c#s \<in> L (ALT r1 r2))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   680
    using ih1 ih2 by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   681
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   682
  case (STAR r s)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   683
  have ih1: "\<And>s. (s \<in> L (der c r)) = (c#s \<in> L r)" by fact
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   684
  show "(s \<in> L (der c (STAR r))) = (c#s \<in> L (STAR r))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   685
    using ih1
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   686
    apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   687
    apply(auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   688
    apply(drule lang_seq_append)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   689
    apply(assumption)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   690
    apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   691
    apply(subst lang_star_cases)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   692
    apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   693
    thm k1
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   694
    apply(drule k2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   695
    apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   696
    apply(simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   697
    apply(erule exE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   698
    apply(erule conjE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   699
    apply(auto simp add: lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   700
    apply(drule k1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   701
    apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   702
    apply(simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   703
    apply(erule exE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   704
    apply(erule conjE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   705
    apply(auto simp add: lang_seq_def Cons_eq_append_conv)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   706
    done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   707
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   708
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   709
fun 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   710
 derivative :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   711
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   712
  "derivative [] r = r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   713
| "derivative (c#s) r = derivative s (der c r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   714
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   715
fun
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   716
  slind_matcher :: "rexp \<Rightarrow> string \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   717
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   718
  "slind_matcher r s = nullable (derivative s r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   719
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   720
lemma slind_matcher:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   721
  shows "slind_matcher r s = (s \<in> L r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   722
by (induct s arbitrary: r)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   723
   (auto simp add: nullable der_correctness)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   724
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   725
export_code slind_matcher in SML module_name Slind file - 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   726
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   727
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   728
(* ******************************************** now is the codes writen by chunhan ************************************* *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   729
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   730
section {* Arden's Lemma revised *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   731
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   732
lemma arden_aux1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   733
  assumes a: "X \<subseteq> X ; A \<union> B"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   734
  and     b: "[] \<notin> A"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   735
  shows      "x \<in> X \<Longrightarrow> x \<in> B ; A\<star>"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   736
apply (induct x taking:length rule:measure_induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   737
apply (subgoal_tac "x \<in> X ; A \<union> B")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   738
defer
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   739
using a
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   740
apply (auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   741
apply simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   742
apply (erule disjE)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   743
defer
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   744
apply (auto simp add:lang_seq_def) [1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   745
apply (subgoal_tac "\<exists> x1 x2. x = x1 @ x2 \<and> x1 \<in> X \<and> x2 \<in> A")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   746
defer
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   747
apply (auto simp add:lang_seq_def) [1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   748
apply (erule exE | erule conjE)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   749
apply simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   750
apply (drule_tac x = x1 in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   751
apply (simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   752
using b
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   753
apply -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   754
apply (auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   755
apply (subgoal_tac "x1 @ x2 \<in> (B ; A\<star>) ; A")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   756
defer
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   757
apply (auto simp add:lang_seq_def)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   758
by (metis Un_absorb1 lang_seq_assoc lang_seq_union(2) lang_star_double lang_star_simple mem_def sup1CI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   759
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   760
theorem ardens_revised:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   761
  assumes nemp: "[] \<notin> A"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   762
  shows "(X = X ; A \<union> B) \<longleftrightarrow> (X = B ; A\<star>)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   763
apply(rule iffI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   764
defer
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   765
apply(simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   766
apply(subst lang_star_cases')
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   767
apply(subst lang_seq_union)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   768
apply(simp add: lang_seq_empty)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   769
apply(simp add: lang_seq_assoc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   770
apply(auto)[1]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   771
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   772
  assume "X = X ; A \<union> B"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   773
  then have as1: "X ; A \<union> B \<subseteq> X" and as2: "X \<subseteq> X ; A \<union> B" by simp_all
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   774
  from as1 have a: "X ; A \<subseteq> X" and b: "B \<subseteq> X" by simp_all
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   775
  from b have "B; A\<star> \<subseteq> X ; A\<star>" by (auto simp add: lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   776
  moreover
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   777
  from a have "X ; A\<star> \<subseteq> X" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   778
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   779
by (rule lang_star_prop2)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   780
  ultimately have f1: "B ; A\<star> \<subseteq> X" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   781
  from as2 nemp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   782
  have f2: "X \<subseteq> B; A\<star>" using arden_aux1 by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   783
  from f1 f2 show "X = B; A\<star>" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   784
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   785
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   786
section {* equiv class' definition *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   787
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   788
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   789
  equiv_str :: "string \<Rightarrow> string set \<Rightarrow> string \<Rightarrow> bool" ("_ \<equiv>_\<equiv> _" [100, 100, 100] 100)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   790
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   791
  "x \<equiv>L'\<equiv> y \<longleftrightarrow> (\<forall>z. x@z \<in> L' \<longleftrightarrow> y@z \<in> L')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   792
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   793
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   794
  equiv_class :: "string \<Rightarrow> (string set) \<Rightarrow> string set" ("\<lbrakk>_\<rbrakk>_" [100, 100] 100)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   795
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   796
  "\<lbrakk>x\<rbrakk>L' \<equiv> {y. x \<equiv>L'\<equiv> y}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   797
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   798
text {* Chunhan modifies Q to Quo *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   799
definition  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   800
  quot :: "string set \<Rightarrow> (string set) \<Rightarrow> (string set) set" ("_ Quo _" [100, 100] 100)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   801
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   802
  "L' Quo R \<equiv> { \<lbrakk>x\<rbrakk>R | x. x \<in> L'}" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   803
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   804
lemma lang_eqs_union_of_eqcls: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   805
  "Lang = \<Union> {X. X \<in> (UNIV Quo Lang) \<and> (\<forall> x \<in> X. x \<in> Lang)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   806
proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   807
  show "Lang \<subseteq> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   808
  proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   809
    fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   810
    assume "x \<in> Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   811
    thus "x \<in> \<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   812
    proof (simp add:quot_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   813
      assume "(1)": "x \<in> Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   814
      show "\<exists>xa. (\<exists>x. xa = \<lbrakk>x\<rbrakk>Lang) \<and> (\<forall>x\<in>xa. x \<in> Lang) \<and> x \<in> xa" (is "\<exists>xa.?P xa")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   815
      proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   816
        have "?P (\<lbrakk>x\<rbrakk>Lang)" using "(1)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   817
          by (auto simp:equiv_class_def equiv_str_def dest: spec[where  x = "[]"])
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   818
        thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   819
      qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   820
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   821
  qed   
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   822
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   823
  show "\<Union>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<subseteq> Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   824
    by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   825
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   826
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   827
lemma empty_notin_CS: "{} \<notin> UNIV Quo Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   828
apply (clarsimp simp:quot_def equiv_class_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   829
by (rule_tac x = x in exI, auto simp:equiv_str_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   830
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   831
lemma no_two_cls_inters:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   832
  "\<lbrakk>X \<in> UNIV Quo Lang; Y \<in> UNIV Quo Lang; X \<noteq> Y\<rbrakk> \<Longrightarrow> X \<inter> Y = {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   833
by (auto simp:quot_def equiv_class_def equiv_str_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   834
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   835
text {* equiv_class transition *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   836
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   837
  CT :: "string set \<Rightarrow> char \<Rightarrow> string set \<Rightarrow> bool" ("_-_\<rightarrow>_" [99,99]99)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   838
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   839
  "X-c\<rightarrow>Y \<equiv> ((X;{[c]}) \<subseteq> Y)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   840
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   841
types t_equa_rhs = "(string set \<times> rexp) set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   842
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   843
types t_equa = "(string set \<times> t_equa_rhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   844
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   845
types t_equas = "t_equa set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   846
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   847
text {* "empty_rhs" generates "\<lambda>" for init-state, just like "\<lambda>" for final states in Brzozowski method. 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   848
        But if the init-state is "{[]}" ("\<lambda>" itself) then empty set is returned, see definition of "equation_rhs" *} 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   849
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   850
  empty_rhs :: "string set \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   851
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   852
  "empty_rhs X \<equiv> if ([] \<in> X) then {({[]}, EMPTY)} else {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   853
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   854
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   855
  folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   856
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   857
  "folds f z S \<equiv> SOME x. fold_graph f z S x"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   858
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   859
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   860
  equation_rhs :: "(string set) set \<Rightarrow> string set \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   861
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   862
  "equation_rhs CS X \<equiv> if (X = {[]}) then {({[]}, EMPTY)}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   863
                         else {(S, folds ALT NULL {CHAR c| c. S-c\<rightarrow>X} )| S. S \<in> CS} \<union> empty_rhs X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   864
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   865
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   866
  equations :: "(string set) set \<Rightarrow> t_equas"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   867
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   868
  "equations CS \<equiv> {(X, equation_rhs CS X) | X. X \<in> CS}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   869
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   870
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   871
  L_rhs :: "t_equa_rhs \<Rightarrow> string set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   872
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   873
  "L_rhs rhs \<equiv> {x. \<exists> X r. (X, r) \<in> rhs \<and> x \<in> X;(L r)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   874
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   875
defs (overloaded)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   876
  l_rhs_abs: "L rhs \<equiv> L_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   877
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   878
lemmas L_def = L_rhs_def [folded l_rhs_abs] L_rexp.simps (* ??? is this OK ?? *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   879
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   880
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   881
  distinct_rhs :: "t_equa_rhs \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   882
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   883
  "distinct_rhs rhs \<equiv> \<forall> X reg\<^isub>1 reg\<^isub>2. (X, reg\<^isub>1) \<in> rhs \<and> (X, reg\<^isub>2) \<in> rhs \<longrightarrow> reg\<^isub>1 = reg\<^isub>2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   884
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   885
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   886
  distinct_equas_rhs :: "t_equas \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   887
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   888
  "distinct_equas_rhs equas \<equiv> \<forall> X rhs. (X, rhs) \<in> equas \<longrightarrow> distinct_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   889
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   890
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   891
  distinct_equas :: "t_equas \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   892
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   893
  "distinct_equas equas \<equiv> \<forall> X rhs rhs'. (X, rhs) \<in> equas \<and> (X, rhs') \<in> equas \<longrightarrow> rhs = rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   894
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   895
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   896
  seq_rhs_r :: "t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   897
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   898
  "seq_rhs_r rhs r \<equiv> (\<lambda>(X, reg). (X, SEQ reg r)) ` rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   899
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   900
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   901
  del_x_paired :: "('a \<times> 'b) set \<Rightarrow> 'a \<Rightarrow> ('a \<times> 'b) set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   902
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   903
  "del_x_paired S x \<equiv> S - {X. X \<in> S \<and> fst X = x}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   904
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   905
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   906
  arden_variate :: "string set \<Rightarrow> rexp \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   907
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   908
  "arden_variate X r rhs \<equiv> seq_rhs_r (del_x_paired rhs X) (STAR r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   909
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   910
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   911
  no_EMPTY_rhs :: "t_equa_rhs \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   912
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   913
  "no_EMPTY_rhs rhs \<equiv> \<forall> X r. (X, r) \<in> rhs \<and> X \<noteq> {[]} \<longrightarrow> [] \<notin> L r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   914
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   915
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   916
  no_EMPTY_equas :: "t_equas \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   917
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   918
  "no_EMPTY_equas equas \<equiv> \<forall> X rhs. (X, rhs) \<in> equas \<longrightarrow> no_EMPTY_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   919
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   920
lemma fold_alt_null_eqs:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   921
  "finite rS \<Longrightarrow> x \<in> L (folds ALT NULL rS) = (\<exists> r \<in> rS. x \<in> L r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   922
apply (simp add:folds_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   923
apply (rule someI2_ex)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   924
apply (erule finite_imp_fold_graph)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   925
apply (erule fold_graph.induct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   926
by auto (*??? how do this be in Isar ?? *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   927
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   928
lemma seq_rhs_r_prop1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   929
  "L (seq_rhs_r rhs r) = (L rhs);(L r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   930
apply (rule set_ext, rule iffI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   931
apply (auto simp:L_def seq_rhs_r_def image_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   932
apply (rule_tac x = "s1 @ s1a" in exI, rule_tac x = "s2a" in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   933
apply (rule_tac x = a in exI, rule_tac x = b in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   934
apply (rule_tac x = s1 in exI, rule_tac x = s1a in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   935
apply (rule_tac x = X in exI, rule_tac x  = "SEQ ra r" in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   936
apply (rule conjI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   937
apply (rule_tac x = "(X, ra)" in bexI, simp+) 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   938
apply (rule_tac x = s1a in exI, rule_tac x = "s2a @ s2" in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   939
apply (simp add:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   940
by (rule_tac x = s2a in exI, rule_tac x = s2 in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   941
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   942
lemma del_x_paired_prop1:  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   943
  "\<lbrakk>distinct_rhs rhs; (X, r) \<in> rhs\<rbrakk> \<Longrightarrow> X ; L r \<union> L (del_x_paired rhs X) = L rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   944
apply (simp add:L_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   945
apply (rule set_ext, rule iffI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   946
apply (erule disjE, rule_tac x = X in exI, rule_tac x = r in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   947
apply (clarify, rule_tac x = Xa in exI, rule_tac x = ra in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   948
apply (clarsimp, drule_tac x = Xa in spec, drule_tac x = ra in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   949
apply (auto simp:distinct_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   950
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   951
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   952
lemma arden_variate_prop:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   953
  assumes "(X, rx) \<in> rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   954
  shows "(\<forall> Y. Y \<noteq> X \<longrightarrow> (\<exists> r. (Y, r) \<in> rhs) = (\<exists> r. (Y, r) \<in> (arden_variate X rx rhs)))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   955
proof (rule allI, rule impI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   956
  fix Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   957
  assume "(1)": "Y \<noteq> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   958
  show "(\<exists>r. (Y, r) \<in> rhs) = (\<exists>r. (Y, r) \<in> arden_variate X rx rhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   959
  proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   960
    assume "(1_1)": "\<exists>r. (Y, r) \<in> rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   961
    show "\<exists>r. (Y, r) \<in> arden_variate X rx rhs" (is "\<exists>r. ?P r")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   962
    proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   963
      from "(1_1)" obtain r where "(Y, r) \<in> rhs" ..
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   964
      hence "?P (SEQ r (STAR rx))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   965
      proof (simp add:arden_variate_def image_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   966
        have "(Y, r) \<in> rhs \<Longrightarrow> (Y, r) \<in> del_x_paired rhs X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   967
          by (auto simp:del_x_paired_def "(1)")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   968
        thus "(Y, r) \<in> rhs \<Longrightarrow> (Y, SEQ r (STAR rx)) \<in> seq_rhs_r (del_x_paired rhs X) (STAR rx)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   969
          by (auto simp:seq_rhs_r_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   970
      qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   971
      thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   972
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   973
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   974
    assume "(2_1)": "\<exists>r. (Y, r) \<in> arden_variate X rx rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   975
    thus "\<exists>r. (Y, r) \<in> rhs" (is "\<exists> r. ?P r")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   976
      by (auto simp:arden_variate_def del_x_paired_def seq_rhs_r_def image_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   977
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   978
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   979
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   980
text {*
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   981
  arden_variate_valid:  proves variation from "X = X;r + Y;ry + \<dots>" to "X = Y;(SEQ ry (STAR r)) + \<dots>" holds the law of "language of left equiv language of right" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   982
*}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   983
lemma arden_variate_valid:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   984
  assumes X_not_empty: "X \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   985
  and     l_eq_r:   "X = L rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   986
  and     dist: "distinct_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   987
  and     no_empty: "no_EMPTY_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   988
  and     self_contained: "(X, r) \<in> rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   989
  shows   "X = L (arden_variate X r rhs)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   990
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   991
  have "[] \<notin> L r" using no_empty X_not_empty self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   992
    by (auto simp:no_EMPTY_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   993
  hence ardens: "X = X;(L r) \<union> (L (del_x_paired rhs X)) \<longleftrightarrow> X = (L (del_x_paired rhs X)) ; (L r)\<star>" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   994
    by (rule ardens_revised)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   995
  have del_x: "X = X ; L r \<union> L (del_x_paired rhs X) \<longleftrightarrow> X = L rhs" using dist l_eq_r self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   996
    by (auto dest:del_x_paired_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   997
  show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   998
  proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
   999
    show "X \<subseteq> L (arden_variate X r rhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1000
    proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1001
      fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1002
      assume "(1_1)": "x \<in> X" with l_eq_r ardens del_x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1003
      show "x \<in> L (arden_variate X r rhs)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1004
        by (simp add:arden_variate_def seq_rhs_r_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1005
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1006
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1007
    show "L (arden_variate X r rhs) \<subseteq> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1008
    proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1009
      fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1010
      assume "(2_1)": "x \<in> L (arden_variate X r rhs)" with ardens del_x l_eq_r
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1011
      show "x \<in> X" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1012
        by (simp add:arden_variate_def seq_rhs_r_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1013
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1014
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1015
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1016
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1017
text {* merge_rhs {(X1, r1), (x2, r2}, (x4, r4), \<dots>} {(x1, r1'), (x3, r3'), \<dots>} = {(x1, ALT r1 r1'}, (x2, r2), (x3, r3'), (x4, r4), \<dots>} *}  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1018
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1019
  merge_rhs :: "t_equa_rhs \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1020
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1021
  "merge_rhs rhs rhs' \<equiv> {(X, r). (\<exists> r1 r2. ((X,r1) \<in> rhs \<and> (X, r2) \<in> rhs') \<and> r = ALT r1 r2)  \<or>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1022
                                 (\<exists> r1. (X, r1) \<in> rhs \<and> (\<not> (\<exists> r2. (X, r2) \<in> rhs')) \<and> r = r1) \<or>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1023
                                 (\<exists> r2. (X, r2) \<in> rhs' \<and> (\<not> (\<exists> r1. (X, r1) \<in> rhs)) \<and> r = r2)    }"                                  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1024
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1025
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1026
text {* rhs_subst rhs X=xrhs r: substitude all occurence of X in rhs((X,r) \<in> rhs) with xrhs *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1027
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1028
  rhs_subst :: "t_equa_rhs \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> rexp \<Rightarrow> t_equa_rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1029
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1030
  "rhs_subst rhs X xrhs r \<equiv> merge_rhs (del_x_paired rhs X) (seq_rhs_r xrhs r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1031
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1032
definition 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1033
  equas_subst_f :: "string set \<Rightarrow> t_equa_rhs \<Rightarrow> t_equa \<Rightarrow> t_equa"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1034
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1035
  "equas_subst_f X xrhs equa \<equiv> let (Y, rhs) = equa in
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1036
                                 if (\<exists> r. (X, r) \<in> rhs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1037
                                 then (Y, rhs_subst rhs X xrhs (SOME r. (X, r) \<in> rhs))
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1038
                                 else equa"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1039
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1040
definition
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1041
  equas_subst :: "t_equas \<Rightarrow> string set \<Rightarrow> t_equa_rhs \<Rightarrow> t_equas"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1042
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1043
  "equas_subst ES X xrhs \<equiv> del_x_paired (equas_subst_f X xrhs ` ES) X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1044
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1045
lemma lang_seq_prop1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1046
 "x \<in> X ; L r \<Longrightarrow> x \<in> X ; (L r \<union> L r')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1047
by (auto simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1048
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1049
lemma lang_seq_prop1':
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1050
  "x \<in> X; L r \<Longrightarrow> x \<in> X ; (L r' \<union> L r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1051
by (auto simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1052
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1053
lemma lang_seq_prop2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1054
  "x \<in> X; (L r \<union> L r') \<Longrightarrow> x \<in> X;L r \<or> x \<in> X;L r'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1055
by (auto simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1056
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1057
lemma merge_rhs_prop1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1058
  shows "L (merge_rhs rhs rhs') = L rhs \<union> L rhs' "
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1059
apply (auto simp add:merge_rhs_def L_def dest!:lang_seq_prop2 intro:lang_seq_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1060
apply (rule_tac x = X in exI, rule_tac x = r1 in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1061
apply (case_tac "\<exists> r2. (X, r2) \<in> rhs'")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1062
apply (clarify, rule_tac x = X in exI, rule_tac x = "ALT r r2" in exI, simp add:lang_seq_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1063
apply (rule_tac x = X in exI, rule_tac x = r in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1064
apply (case_tac "\<exists> r1. (X, r1) \<in> rhs")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1065
apply (clarify, rule_tac x = X in exI, rule_tac x = "ALT r1 r" in exI, simp add:lang_seq_prop1')
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1066
apply (rule_tac x = X in exI, rule_tac x = r in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1067
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1068
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1069
lemma no_EMPTY_rhss_imp_merge_no_EMPTY:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1070
  "\<lbrakk>no_EMPTY_rhs rhs; no_EMPTY_rhs rhs'\<rbrakk> \<Longrightarrow> no_EMPTY_rhs (merge_rhs rhs rhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1071
apply (simp add:no_EMPTY_rhs_def merge_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1072
apply (clarify, (erule conjE | erule exE | erule disjE)+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1073
by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1074
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1075
lemma distinct_rhs_prop:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1076
  "\<lbrakk>distinct_rhs rhs; (X, r1) \<in> rhs; (X, r2) \<in> rhs\<rbrakk> \<Longrightarrow> r1 = r2"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1077
by (auto simp:distinct_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1078
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1079
lemma merge_rhs_prop2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1080
  assumes dist_rhs: "distinct_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1081
  and     dist_rhs':"distinct_rhs rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1082
  shows "distinct_rhs (merge_rhs rhs rhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1083
apply (auto simp:merge_rhs_def distinct_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1084
using dist_rhs
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1085
apply (drule distinct_rhs_prop, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1086
using dist_rhs'
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1087
apply (drule distinct_rhs_prop, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1088
using dist_rhs
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1089
apply (drule distinct_rhs_prop, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1090
using dist_rhs'
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1091
apply (drule distinct_rhs_prop, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1092
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1093
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1094
lemma seq_rhs_r_holds_distinct: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1095
  "distinct_rhs rhs \<Longrightarrow> distinct_rhs (seq_rhs_r rhs r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1096
by (auto simp:distinct_rhs_def seq_rhs_r_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1097
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1098
lemma seq_rhs_r_prop0:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1099
  assumes l_eq_r: "X = L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1100
  shows "L (seq_rhs_r xrhs r) = X ; L r "
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1101
using l_eq_r
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1102
by (auto simp:seq_rhs_r_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1103
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1104
lemma rhs_subst_prop1:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1105
  assumes l_eq_r: "X = L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1106
  and     dist:  "distinct_rhs rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1107
  shows "(X, r) \<in> rhs \<Longrightarrow> L rhs = L (rhs_subst rhs X xrhs r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1108
apply (simp add:rhs_subst_def merge_rhs_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1109
using l_eq_r 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1110
apply (drule_tac r = r in seq_rhs_r_prop0, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1111
using dist
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1112
apply (auto dest:del_x_paired_prop1)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1113
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1114
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1115
lemma del_x_paired_holds_distinct_rhs:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1116
  "distinct_rhs rhs \<Longrightarrow> distinct_rhs (del_x_paired rhs x)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1117
by (auto simp:distinct_rhs_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1118
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1119
lemma rhs_subst_holds_distinct_rhs:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1120
  "\<lbrakk>distinct_rhs rhs; distinct_rhs xrhs\<rbrakk> \<Longrightarrow> distinct_rhs (rhs_subst rhs X xrhs r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1121
apply (drule_tac r = r and rhs = xrhs in seq_rhs_r_holds_distinct)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1122
apply (drule_tac x = X in del_x_paired_holds_distinct_rhs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1123
by (auto dest:merge_rhs_prop2[where rhs = "del_x_paired rhs X"] simp:rhs_subst_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1124
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1125
section {* myhill-nerode theorem *}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1126
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1127
definition left_eq_cls :: "t_equas \<Rightarrow> (string set) set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1128
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1129
  "left_eq_cls ES \<equiv> {X. \<exists> rhs. (X, rhs) \<in> ES} "
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1130
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1131
definition right_eq_cls :: "t_equas \<Rightarrow> (string set) set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1132
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1133
  "right_eq_cls ES \<equiv> {Y. \<exists> X rhs r. (X, rhs) \<in> ES \<and> (Y, r) \<in> rhs }"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1134
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1135
definition rhs_eq_cls :: "t_equa_rhs \<Rightarrow> (string set) set"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1136
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1137
  "rhs_eq_cls rhs \<equiv> {Y. \<exists> r. (Y, r) \<in> rhs}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1138
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1139
definition ardenable :: "t_equa \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1140
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1141
  "ardenable equa \<equiv> let (X, rhs) = equa in 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1142
                      distinct_rhs rhs \<and> no_EMPTY_rhs rhs \<and> X = L rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1143
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1144
text {*
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1145
  Inv: Invairance of the equation-system, during the decrease of the equation-system, Inv holds.
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1146
*}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1147
definition Inv :: "string set \<Rightarrow> t_equas \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1148
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1149
  "Inv X ES \<equiv> finite ES \<and> (\<exists> rhs. (X, rhs) \<in> ES) \<and> distinct_equas ES \<and> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1150
            (\<forall> X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs) \<and> X \<noteq> {} \<and> rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls ES))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1151
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1152
text {*
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1153
  TCon: Termination Condition of the equation-system decreasion.
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1154
*}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1155
definition TCon:: "'a set \<Rightarrow> bool"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1156
where
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1157
  "TCon ES \<equiv> card ES = 1"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1158
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1159
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1160
text {* 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1161
  The following is a iteration principle, and is the main framework for the proof:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1162
   1: We can form the initial equation-system using "equations" defined above, and prove it has invariance Inv by lemma "init_ES_satisfy_Inv";
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1163
   2: We can decrease the number of the equation-system using ardens_lemma_revised and substitution ("equas_subst", defined above), 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1164
        and prove it holds the property "step" in "wf_iter" by lemma "iteration_step"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1165
   and finally using property P and Q to prove the myhill-nerode theorem
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1166
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1167
*}
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1168
lemma wf_iter [rule_format]: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1169
  fixes f
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1170
  assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1171
  shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1172
proof(induct e rule: wf_induct 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1173
           [OF wf_inv_image[OF wf_less_than, where f = "f"]], clarify)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1174
  fix x 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1175
  assume h [rule_format]: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1176
    "\<forall>y. (y, x) \<in> inv_image less_than f \<longrightarrow> P y \<longrightarrow> (\<exists>e'. P e' \<and> Q e')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1177
    and px: "P x"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1178
  show "\<exists>e'. P e' \<and> Q e'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1179
  proof(cases "Q x")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1180
    assume "Q x" with px show ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1181
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1182
    assume nq: "\<not> Q x"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1183
    from step [OF px nq]
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1184
    obtain e' where pe': "P e'" and ltf: "(f e', f x) \<in> less_than" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1185
    show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1186
    proof(rule h)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1187
      from ltf show "(e', x) \<in> inv_image less_than f" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1188
	by (simp add:inv_image_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1189
    next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1190
      from pe' show "P e'" .
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1191
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1192
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1193
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1194
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1195
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1196
(* ********************************* BEGIN: proving the initial equation-system satisfies Inv **************************************** *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1197
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1198
lemma distinct_rhs_equations:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1199
  "(X, xrhs) \<in> equations (UNIV Quo Lang) \<Longrightarrow> distinct_rhs xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1200
by (auto simp: equations_def equation_rhs_def distinct_rhs_def empty_rhs_def dest:no_two_cls_inters)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1201
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1202
lemma every_nonempty_eqclass_has_strings:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1203
  "\<lbrakk>X \<in> (UNIV Quo Lang); X \<noteq> {[]}\<rbrakk> \<Longrightarrow> \<exists> clist. clist \<in> X \<and> clist \<noteq> []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1204
by (auto simp:quot_def equiv_class_def equiv_str_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1205
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1206
lemma every_eqclass_is_derived_from_empty:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1207
  assumes not_empty: "X \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1208
  shows "X \<in> (UNIV Quo Lang) \<Longrightarrow> \<exists> clist. {[]};{clist} \<subseteq> X \<and> clist \<noteq> []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1209
using not_empty
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1210
apply (drule_tac every_nonempty_eqclass_has_strings, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1211
by (auto intro:exI[where x = clist] simp:lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1212
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1213
lemma equiv_str_in_CS:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1214
  "\<lbrakk>clist\<rbrakk>Lang \<in> (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1215
by (auto simp:quot_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1216
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1217
lemma has_str_imp_defined_by_str:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1218
  "\<lbrakk>str \<in> X; X \<in> UNIV Quo Lang\<rbrakk> \<Longrightarrow> X = \<lbrakk>str\<rbrakk>Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1219
by (auto simp:quot_def equiv_class_def equiv_str_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1220
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1221
lemma every_eqclass_has_ascendent:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1222
  assumes has_str: "clist @ [c] \<in> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1223
  and     in_CS:   "X \<in> UNIV Quo Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1224
  shows "\<exists> Y. Y \<in> UNIV Quo Lang \<and> Y-c\<rightarrow>X \<and> clist \<in> Y" (is "\<exists> Y. ?P Y")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1225
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1226
  have "?P (\<lbrakk>clist\<rbrakk>Lang)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1227
  proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1228
    have "\<lbrakk>clist\<rbrakk>Lang \<in> UNIV Quo Lang"       
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1229
      by (simp add:quot_def, rule_tac x = clist in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1230
    moreover have "\<lbrakk>clist\<rbrakk>Lang-c\<rightarrow>X" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1231
    proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1232
      have "X = \<lbrakk>(clist @ [c])\<rbrakk>Lang" using has_str in_CS
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1233
        by (auto intro!:has_str_imp_defined_by_str)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1234
      moreover have "\<forall> sl. sl \<in> \<lbrakk>clist\<rbrakk>Lang \<longrightarrow> sl @ [c] \<in> \<lbrakk>(clist @ [c])\<rbrakk>Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1235
        by (auto simp:equiv_class_def equiv_str_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1236
      ultimately show ?thesis unfolding CT_def lang_seq_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1237
        by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1238
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1239
    moreover have "clist \<in> \<lbrakk>clist\<rbrakk>Lang" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1240
      by (auto simp:equiv_str_def equiv_class_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1241
    ultimately show "?P (\<lbrakk>clist\<rbrakk>Lang)" by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1242
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1243
  thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1244
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1245
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1246
lemma finite_charset_rS:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1247
  "finite {CHAR c |c. Y-c\<rightarrow>X}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1248
by (rule_tac A = UNIV and f = CHAR in finite_surj, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1249
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1250
lemma l_eq_r_in_equations:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1251
  assumes X_in_equas: "(X, xrhs) \<in> equations (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1252
  shows "X = L xrhs"    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1253
proof (cases "X = {[]}")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1254
  case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1255
  thus ?thesis using X_in_equas 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1256
    by (simp add:equations_def equation_rhs_def L_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1257
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1258
  case False 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1259
  show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1260
  proof 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1261
    show "X \<subseteq> L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1262
    proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1263
      fix x
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1264
      assume "(1)": "x \<in> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1265
      show "x \<in> L xrhs"          
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1266
      proof (cases "x = []")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1267
        assume empty: "x = []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1268
        hence "x \<in> L (empty_rhs X)" using "(1)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1269
          by (auto simp:empty_rhs_def L_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1270
        thus ?thesis using X_in_equas False empty "(1)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1271
          unfolding equations_def equation_rhs_def by (auto simp:L_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1272
      next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1273
        assume not_empty: "x \<noteq> []"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1274
        hence "\<exists> clist c. x = clist @ [c]" by (case_tac x rule:rev_cases, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1275
        then obtain clist c where decom: "x = clist @ [c]" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1276
        moreover have "\<And> Y. \<lbrakk>Y \<in> UNIV Quo Lang; Y-c\<rightarrow>X; clist \<in> Y\<rbrakk>\<Longrightarrow> [c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1277
        proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1278
          fix Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1279
          assume Y_is_eq_cl: "Y \<in> UNIV Quo Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1280
            and Y_CT_X: "Y-c\<rightarrow>X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1281
            and clist_in_Y: "clist \<in> Y"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1282
          with finite_charset_rS 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1283
          show "[c] \<in> L (folds ALT NULL {CHAR c |c. Y-c\<rightarrow>X})"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1284
            by (auto simp :fold_alt_null_eqs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1285
        qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1286
        hence "\<exists>Xa. Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1287
          using X_in_equas False not_empty "(1)" decom
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1288
          by (auto dest!:every_eqclass_has_ascendent simp:equations_def equation_rhs_def L_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1289
        then obtain Xa where "Xa \<in> UNIV Quo Lang \<and> clist @ [c] \<in> Xa ; L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1290
        hence "x \<in> L {(S, folds ALT NULL {CHAR c |c. S-c\<rightarrow>X}) |S. S \<in> UNIV Quo Lang}" using X_in_equas "(1)" decom
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1291
          by (auto simp add:L_def equations_def equation_rhs_def intro!:exI[where x = Xa])
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1292
        thus "x \<in> L xrhs" using X_in_equas False not_empty unfolding equations_def equation_rhs_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1293
          by (auto simp:L_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1294
      qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1295
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1296
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1297
    show "L xrhs \<subseteq> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1298
    proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1299
      fix x 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1300
      assume "(2)": "x \<in> L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1301
      have "(2_1)": "\<And> s1 s2 r Xa. \<lbrakk>s1 \<in> Xa; s2 \<in> L (folds ALT NULL {CHAR c |c. Xa-c\<rightarrow>X})\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1302
        using finite_charset_rS
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1303
        by (auto simp:CT_def lang_seq_def fold_alt_null_eqs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1304
      have "(2_2)": "\<And> s1 s2 Xa r.\<lbrakk>s1 \<in> Xa; s2 \<in> L r; (Xa, r) \<in> empty_rhs X\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> X"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1305
        by (simp add:empty_rhs_def split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1306
      show "x \<in> X" using X_in_equas False "(2)"         
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1307
        by (auto intro:"(2_1)" "(2_2)" simp:equations_def equation_rhs_def L_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1308
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1309
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1310
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1311
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1312
lemma finite_CT_chars:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1313
  "finite {CHAR c |c. Xa-c\<rightarrow>X}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1314
by (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1315
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1316
lemma no_EMPTY_equations:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1317
  "(X, xrhs) \<in> equations CS \<Longrightarrow> no_EMPTY_rhs xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1318
apply (clarsimp simp add:equations_def equation_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1319
apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1320
apply (subgoal_tac "finite {CHAR c |c. Xa-c\<rightarrow>X}", drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_CT_chars)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1321
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1322
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1323
lemma init_ES_satisfy_ardenable:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1324
  "(X, xrhs) \<in> equations (UNIV Quo Lang)  \<Longrightarrow> ardenable (X, xrhs)"  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1325
  unfolding ardenable_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1326
  by (auto intro:distinct_rhs_equations no_EMPTY_equations simp:l_eq_r_in_equations)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1327
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1328
lemma init_ES_satisfy_Inv:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1329
  assumes finite_CS: "finite (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1330
  and X_in_eq_cls: "X \<in> UNIV Quo Lang"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1331
  shows "Inv X (equations (UNIV Quo Lang))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1332
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1333
  have "finite (equations (UNIV Quo Lang))" using finite_CS
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1334
    by (auto simp:equations_def)    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1335
  moreover have "\<exists>rhs. (X, rhs) \<in> equations (UNIV Quo Lang)" using X_in_eq_cls 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1336
    by (simp add:equations_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1337
  moreover have "distinct_equas (equations (UNIV Quo Lang))" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1338
    by (auto simp:distinct_equas_def equations_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1339
  moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1340
                 rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equations (UNIV Quo Lang)))" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1341
    apply (simp add:left_eq_cls_def equations_def rhs_eq_cls_def equation_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1342
    by (auto simp:empty_rhs_def split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1343
  moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> X \<noteq> {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1344
    by (clarsimp simp:equations_def empty_notin_CS intro:classical)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1345
  moreover have "\<forall>X xrhs. (X, xrhs) \<in> equations (UNIV Quo Lang) \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1346
    by (auto intro!:init_ES_satisfy_ardenable)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1347
  ultimately show ?thesis by (simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1348
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1349
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1350
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1351
(* ********************************* END: proving the initial equation-system satisfies Inv **************************************** *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1352
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1353
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1354
(* ***************************** BEGIN: proving every equation-system's iteration step satisfies Inv ******************************* *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1355
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1356
lemma not_T_aux: "\<lbrakk>\<not> TCon (insert a A); x = a\<rbrakk>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1357
       \<Longrightarrow> \<exists>y. x \<noteq> y \<and> y \<in> insert a A "
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1358
apply (case_tac "insert a A = {a}")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1359
by (auto simp:TCon_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1360
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1361
lemma not_T_atleast_2[rule_format]:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1362
  "finite S \<Longrightarrow> \<forall> x. x \<in> S \<and> (\<not> TCon S)\<longrightarrow> (\<exists> y. x \<noteq> y \<and> y \<in> S)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1363
apply (erule finite.induct, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1364
apply (clarify, case_tac "x = a")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1365
by (erule not_T_aux, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1366
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1367
lemma exist_another_equa: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1368
  "\<lbrakk>\<not> TCon ES; finite ES; distinct_equas ES; (X, rhl) \<in> ES\<rbrakk> \<Longrightarrow> \<exists> Y yrhl. (Y, yrhl) \<in> ES \<and> X \<noteq> Y"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1369
apply (drule not_T_atleast_2, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1370
apply (clarsimp simp:distinct_equas_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1371
apply (drule_tac x= X in spec, drule_tac x = rhl in spec, drule_tac x = b in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1372
by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1373
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1374
lemma Inv_mono_with_lambda:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1375
  assumes Inv_ES: "Inv X ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1376
  and X_noteq_Y:  "X \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1377
  shows "Inv X (ES - {({[]}, yrhs)})"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1378
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1379
  have "finite (ES - {({[]}, yrhs)})" using Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1380
    by (simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1381
  moreover have "\<exists>rhs. (X, rhs) \<in> ES - {({[]}, yrhs)}" using Inv_ES X_noteq_Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1382
    by (simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1383
  moreover have "distinct_equas (ES - {({[]}, yrhs)})" using Inv_ES X_noteq_Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1384
    apply (clarsimp simp:Inv_def distinct_equas_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1385
    by (drule_tac x = Xa in spec, simp)    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1386
  moreover have "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1387
                          ardenable (X, xrhs) \<and> X \<noteq> {}" using Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1388
    by (clarify, simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1389
  moreover 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1390
  have "insert {[]} (left_eq_cls (ES - {({[]}, yrhs)})) = insert {[]} (left_eq_cls ES)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1391
    by (auto simp:left_eq_cls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1392
  hence "\<forall>X xrhs.(X, xrhs) \<in> ES - {({[]}, yrhs)} \<longrightarrow>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1393
                          rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (ES - {({[]}, yrhs)}))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1394
    using Inv_ES by (auto simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1395
  ultimately show ?thesis by (simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1396
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1397
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1398
lemma non_empty_card_prop:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1399
  "finite ES \<Longrightarrow> \<forall>e. e \<in> ES \<longrightarrow> card ES - Suc 0 < card ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1400
apply (erule finite.induct, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1401
apply (case_tac[!] "a \<in> A")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1402
by (auto simp:insert_absorb)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1403
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1404
lemma ardenable_prop:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1405
  assumes not_lambda: "Y \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1406
  and ardable: "ardenable (Y, yrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1407
  shows "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" (is "\<exists> yrhs'. ?P yrhs'")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1408
proof (cases "(\<exists> reg. (Y, reg) \<in> yrhs)")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1409
  case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1410
  thus ?thesis 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1411
  proof 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1412
    fix reg
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1413
    assume self_contained: "(Y, reg) \<in> yrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1414
    show ?thesis 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1415
    proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1416
      have "?P (arden_variate Y reg yrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1417
      proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1418
        have "Y = L (arden_variate Y reg yrhs)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1419
          using self_contained not_lambda ardable
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1420
          by (rule_tac arden_variate_valid, simp_all add:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1421
        moreover have "distinct_rhs (arden_variate Y reg yrhs)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1422
          using ardable 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1423
          by (auto simp:distinct_rhs_def arden_variate_def seq_rhs_r_def del_x_paired_def ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1424
        moreover have "rhs_eq_cls (arden_variate Y reg yrhs) = rhs_eq_cls yrhs - {Y}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1425
        proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1426
          have "\<And> rhs r. rhs_eq_cls (seq_rhs_r rhs r) = rhs_eq_cls rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1427
            apply (auto simp:rhs_eq_cls_def seq_rhs_r_def image_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1428
            by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "(x, ra)" in bexI, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1429
          moreover have "\<And> rhs X. rhs_eq_cls (del_x_paired rhs X) = rhs_eq_cls rhs - {X}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1430
            by (auto simp:rhs_eq_cls_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1431
          ultimately show ?thesis by (simp add:arden_variate_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1432
        qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1433
        ultimately show ?thesis by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1434
      qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1435
      thus ?thesis by (rule_tac x= "arden_variate Y reg yrhs" in exI, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1436
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1437
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1438
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1439
  case False
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1440
  hence "(2)": "rhs_eq_cls yrhs - {Y} = rhs_eq_cls yrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1441
    by (auto simp:rhs_eq_cls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1442
  show ?thesis 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1443
  proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1444
    have "?P yrhs" using False ardable "(2)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1445
      by (simp add:ardenable_def)      
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1446
    thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1447
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1448
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1449
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1450
lemma equas_subst_f_del_no_other:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1451
  assumes self_contained: "(Y, rhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1452
  shows "\<exists> rhs'. (Y, rhs') \<in> (equas_subst_f X xrhs ` ES)" (is "\<exists> rhs'. ?P rhs'")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1453
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1454
  have "\<exists> rhs'. equas_subst_f X xrhs (Y, rhs) = (Y, rhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1455
    by (auto simp:equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1456
  then obtain rhs' where "equas_subst_f X xrhs (Y, rhs) = (Y, rhs')" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1457
  hence "?P rhs'" unfolding image_def using self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1458
    by (auto intro:bexI[where x = "(Y, rhs)"])
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1459
  thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1460
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1461
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1462
lemma del_x_paired_del_only_x: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1463
  "\<lbrakk>X \<noteq> Y; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> (X, rhs) \<in> del_x_paired ES Y"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1464
by (auto simp:del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1465
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1466
lemma del_x_paired_del_only_x':
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1467
  "(X, rhs) \<in> del_x_paired ES Y \<Longrightarrow> X \<noteq> Y \<and> (X, rhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1468
by (auto simp:del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1469
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1470
lemma equas_subst_del_no_other:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1471
 "\<lbrakk>(X, rhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> (\<exists>rhs. (X, rhs) \<in> equas_subst ES Y rhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1472
unfolding equas_subst_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1473
apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1474
by (erule exE, drule del_x_paired_del_only_x, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1475
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1476
lemma equas_subst_holds_distinct:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1477
  "distinct_equas ES \<Longrightarrow> distinct_equas (equas_subst ES Y rhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1478
apply (clarsimp simp add:equas_subst_def distinct_equas_def del_x_paired_def equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1479
by (auto split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1480
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1481
lemma del_x_paired_dels: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1482
  "(X, rhs) \<in> ES \<Longrightarrow> {Y. Y \<in> ES \<and> fst Y = X} \<inter> ES \<noteq> {}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1483
by (auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1484
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1485
lemma del_x_paired_subset:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1486
  "(X, rhs) \<in> ES \<Longrightarrow> ES - {Y. Y \<in> ES \<and> fst Y = X} \<subset> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1487
apply (drule del_x_paired_dels)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1488
by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1489
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1490
lemma del_x_paired_card_less: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1491
  "\<lbrakk>finite ES; (X, rhs) \<in> ES\<rbrakk> \<Longrightarrow> card (del_x_paired ES X) < card ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1492
apply (simp add:del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1493
apply (drule del_x_paired_subset)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1494
by (auto intro:psubset_card_mono)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1495
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1496
lemma equas_subst_card_less:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1497
  "\<lbrakk>finite ES; (Y, yrhs) \<in> ES\<rbrakk> \<Longrightarrow> card (equas_subst ES Y rhs') < card ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1498
apply (simp add:equas_subst_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1499
apply (frule_tac h = "equas_subst_f Y rhs'" in finite_imageI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1500
apply (drule_tac f = "equas_subst_f Y rhs'" in Finite_Set.card_image_le)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1501
apply (drule_tac X = Y and xrhs = rhs' in equas_subst_f_del_no_other,erule exE)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1502
by (drule del_x_paired_card_less, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1503
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1504
lemma equas_subst_holds_distinct_rhs:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1505
  assumes   dist': "distinct_rhs yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1506
  and     history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1507
  and     X_in :  "(X, xrhs) \<in> equas_subst ES Y yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1508
  shows "distinct_rhs xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1509
using X_in history
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1510
apply (clarsimp simp:equas_subst_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1511
apply (drule_tac x = a in spec, drule_tac x = b in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1512
apply (simp add:ardenable_def equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1513
by (auto intro:rhs_subst_holds_distinct_rhs simp:dist' split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1514
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1515
lemma r_no_EMPTY_imp_seq_rhs_r_no_EMPTY:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1516
  "[] \<notin> L r \<Longrightarrow> no_EMPTY_rhs (seq_rhs_r rhs r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1517
by (auto simp:no_EMPTY_rhs_def seq_rhs_r_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1518
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1519
lemma del_x_paired_holds_no_EMPTY:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1520
  "no_EMPTY_rhs yrhs \<Longrightarrow> no_EMPTY_rhs (del_x_paired yrhs Y)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1521
by (auto simp:no_EMPTY_rhs_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1522
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1523
lemma rhs_subst_holds_no_EMPTY:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1524
  "\<lbrakk>no_EMPTY_rhs yrhs; (Y, r) \<in> yrhs; Y \<noteq> {[]}\<rbrakk> \<Longrightarrow> no_EMPTY_rhs (rhs_subst yrhs Y rhs' r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1525
apply (auto simp:rhs_subst_def intro!:no_EMPTY_rhss_imp_merge_no_EMPTY r_no_EMPTY_imp_seq_rhs_r_no_EMPTY del_x_paired_holds_no_EMPTY)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1526
by (auto simp:no_EMPTY_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1527
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1528
lemma equas_subst_holds_no_EMPTY:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1529
  assumes substor: "Y \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1530
  and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1531
  and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1532
  shows "no_EMPTY_rhs xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1533
proof-
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1534
  from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1535
    by (auto simp add:equas_subst_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1536
  then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1537
                       and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1538
  hence dist_zrhs: "distinct_rhs zrhs" using history
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1539
    by (auto simp:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1540
  show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1541
  proof (cases "\<exists> r. (Y, r) \<in> zrhs")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1542
    case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1543
    then obtain r where Y_in_zrhs: "(Y, r) \<in> zrhs" ..
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1544
    hence some: "(SOME r. (Y, r) \<in> zrhs) = r" using Z_in dist_zrhs
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1545
      by (auto simp:distinct_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1546
    hence "no_EMPTY_rhs (rhs_subst zrhs Y yrhs' r)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1547
      using substor Y_in_zrhs history Z_in
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1548
      by (rule_tac rhs_subst_holds_no_EMPTY, auto simp:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1549
    thus ?thesis using X_Z True some
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1550
      by (simp add:equas_subst_def equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1551
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1552
    case False
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1553
    hence "(X, xrhs) = (Z, zrhs)" using Z_in X_Z
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1554
      by (simp add:equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1555
    thus ?thesis using history Z_in
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1556
      by (auto simp:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1557
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1558
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1559
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1560
lemma equas_subst_f_holds_left_eq_right:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1561
  assumes substor: "Y = L rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1562
  and     history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> distinct_rhs xrhs \<and> X = L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1563
  and       subst: "(X, xrhs) = equas_subst_f Y rhs' (Z, zrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1564
  and     self_contained: "(Z, zrhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1565
  shows "X = L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1566
proof (cases "\<exists> r. (Y, r) \<in> zrhs")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1567
  case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1568
  from True obtain r where "(1)":"(Y, r) \<in> zrhs" ..
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1569
  show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1570
  proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1571
    from history self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1572
    have dist: "distinct_rhs zrhs" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1573
    hence "(SOME r. (Y, r) \<in> zrhs) = r" using self_contained "(1)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1574
      using distinct_rhs_def by (auto intro:some_equality)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1575
    moreover have "L zrhs = L (rhs_subst zrhs Y rhs' r)" using substor dist "(1)" self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1576
      by (rule_tac rhs_subst_prop1, auto simp:distinct_equas_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1577
    ultimately show ?thesis using subst history self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1578
      by (auto simp:equas_subst_f_def split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1579
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1580
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1581
  case False
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1582
  thus ?thesis using history subst self_contained
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1583
    by (auto simp:equas_subst_f_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1584
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1585
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1586
lemma equas_subst_holds_left_eq_right:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1587
  assumes history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1588
  and     substor: "Y = L rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1589
  and     X_in :  "(X, xrhs) \<in> equas_subst ES Y yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1590
  shows "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y rhs' \<longrightarrow> X = L xrhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1591
apply (clarsimp simp add:equas_subst_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1592
using substor
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1593
apply (drule_tac equas_subst_f_holds_left_eq_right)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1594
using history
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1595
by (auto simp:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1596
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1597
lemma equas_subst_holds_ardenable:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1598
  assumes substor: "Y = L yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1599
  and history: "\<forall>X xrhs. (X, xrhs) \<in> ES \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1600
  and X_in:"(X, xrhs) \<in> equas_subst ES Y yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1601
  and dist': "distinct_rhs yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1602
  and not_lambda: "Y \<noteq> {[]}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1603
  shows "ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1604
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1605
  have "distinct_rhs xrhs" using history X_in dist' 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1606
    by (auto dest:equas_subst_holds_distinct_rhs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1607
  moreover have "no_EMPTY_rhs xrhs" using history X_in not_lambda
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1608
    by (auto intro:equas_subst_holds_no_EMPTY)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1609
  moreover have "X = L xrhs" using history substor X_in
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1610
  by (auto dest: equas_subst_holds_left_eq_right)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1611
  ultimately show ?thesis using ardenable_def by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1612
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1613
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1614
lemma equas_subst_holds_cls_defined:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1615
  assumes         X_in: "(X, xrhs) \<in> equas_subst ES Y yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1616
  and           Inv_ES: "Inv X' ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1617
  and            subst: "(Y, yrhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1618
  and  cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1619
  shows "rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1620
proof-
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1621
  have tac: "\<lbrakk> A \<subseteq> B; C \<subseteq> D; E \<subseteq> A \<union> B\<rbrakk> \<Longrightarrow> E \<subseteq> B \<union> D" by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1622
  from X_in have "\<exists> (Z, zrhs) \<in> ES. (X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1623
    by (auto simp add:equas_subst_def del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1624
  then obtain Z zrhs where Z_in: "(Z, zrhs) \<in> ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1625
                       and X_Z: "(X, xrhs) = equas_subst_f Y yrhs' (Z, zrhs)" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1626
  hence "rhs_eq_cls zrhs \<subseteq> insert {[]} (left_eq_cls ES)" using Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1627
    by (auto simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1628
  moreover have "rhs_eq_cls yrhs' \<subseteq> insert {[]} (left_eq_cls ES) - {Y}" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1629
    using Inv_ES subst cls_holds_but_Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1630
    by (auto simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1631
  moreover have "rhs_eq_cls xrhs \<subseteq> rhs_eq_cls zrhs \<union> rhs_eq_cls yrhs' - {Y}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1632
    using X_Z cls_holds_but_Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1633
    apply (clarsimp simp add:equas_subst_f_def rhs_subst_def split:if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1634
    by (auto simp:rhs_eq_cls_def merge_rhs_def del_x_paired_def seq_rhs_r_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1635
  moreover have "left_eq_cls (equas_subst ES Y yrhs') = left_eq_cls ES - {Y}" using subst
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1636
    by (auto simp: left_eq_cls_def equas_subst_def del_x_paired_def equas_subst_f_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1637
             dest: equas_subst_f_del_no_other
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1638
             split: if_splits)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1639
  ultimately show ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1640
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1641
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1642
lemma iteration_step: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1643
  assumes Inv_ES: "Inv X ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1644
  and    not_T: "\<not> TCon ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1645
  shows "(\<exists> ES'. Inv X ES' \<and> (card ES', card ES) \<in> less_than)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1646
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1647
  from Inv_ES not_T have another: "\<exists>Y yrhs. (Y, yrhs) \<in> ES \<and> X \<noteq> Y" unfolding Inv_def
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1648
    by (clarify, rule_tac exist_another_equa[where X = X], auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1649
  then obtain Y yrhs where subst: "(Y, yrhs) \<in> ES" and not_X: " X \<noteq> Y" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1650
  show ?thesis (is "\<exists> ES'. ?P ES'")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1651
  proof (cases "Y = {[]}") 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1652
    case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1653
      --"in this situation, we pick a \"\<lambda>\" equation, thus directly remove it from the equation-system"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1654
    have "?P (ES - {(Y, yrhs)})" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1655
    proof 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1656
      show "Inv X (ES - {(Y, yrhs)})" using True not_X
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1657
        by (simp add:Inv_ES Inv_mono_with_lambda)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1658
    next 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1659
      show "(card (ES - {(Y, yrhs)}), card ES) \<in> less_than" using Inv_ES subst
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1660
        by (auto elim:non_empty_card_prop[rule_format] simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1661
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1662
    thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1663
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1664
    case False
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1665
      --"in this situation, we pick a equation and using ardenable to get a rhs without itself in it, then use equas_subst to form a new equation-system"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1666
    hence "\<exists> yrhs'. Y = L yrhs' \<and> distinct_rhs yrhs' \<and> rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" using subst Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1667
      by (auto intro:ardenable_prop simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1668
    then obtain yrhs' where Y'_l_eq_r: "Y = L yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1669
      and dist_Y': "distinct_rhs yrhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1670
      and cls_holds_but_Y: "rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1671
    hence "?P (equas_subst ES Y yrhs')"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1672
    proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1673
      have finite_del: "\<And> S x. finite S \<Longrightarrow> finite (del_x_paired S x)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1674
        apply (rule_tac A = "del_x_paired S x" in finite_subset)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1675
        by (auto simp:del_x_paired_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1676
      have "finite (equas_subst ES Y yrhs')" using Inv_ES 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1677
        by (auto intro!:finite_del simp:equas_subst_def Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1678
      moreover have "\<exists>rhs. (X, rhs) \<in> equas_subst ES Y yrhs'" using Inv_ES not_X
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1679
        by (auto intro:equas_subst_del_no_other simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1680
      moreover have "distinct_equas (equas_subst ES Y yrhs')" using Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1681
        by (auto intro:equas_subst_holds_distinct simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1682
      moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> ardenable (X, xrhs)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1683
        using Inv_ES dist_Y' False Y'_l_eq_r
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1684
        apply (clarsimp simp:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1685
        by (rule equas_subst_holds_ardenable, simp_all)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1686
      moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow> X \<noteq> {}" using Inv_ES
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1687
        by (clarsimp simp:equas_subst_def Inv_def del_x_paired_def equas_subst_f_def split:if_splits, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1688
      moreover have "\<forall>X xrhs. (X, xrhs) \<in> equas_subst ES Y yrhs' \<longrightarrow>
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1689
                               rhs_eq_cls xrhs \<subseteq> insert {[]} (left_eq_cls (equas_subst ES Y yrhs'))"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1690
        using Inv_ES subst cls_holds_but_Y
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1691
        apply (rule_tac impI | rule_tac allI)+
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1692
        by (erule equas_subst_holds_cls_defined, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1693
      moreover have "(card (equas_subst ES Y yrhs'), card ES) \<in> less_than"using Inv_ES subst
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1694
        by (simp add:equas_subst_card_less Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1695
      ultimately show "?P (equas_subst ES Y yrhs')" by (auto simp:Inv_def)      
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1696
    qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1697
    thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1698
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1699
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1700
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1701
(* ****************************** END: proving every equation-system's iteration step satisfies Inv ******************************* *)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1702
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1703
lemma iteration_conc: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1704
  assumes history: "Inv X ES"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1705
  shows "\<exists> ES'. Inv X ES' \<and> TCon ES'" (is "\<exists> ES'. ?P ES'")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1706
proof (cases "TCon ES")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1707
  case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1708
  hence "?P ES" using history by simp
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1709
  thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1710
next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1711
  case False  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1712
  thus ?thesis using history iteration_step
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1713
    by (rule_tac f = card in wf_iter, simp_all)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1714
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1715
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1716
lemma eqset_imp_iff': "A = B \<Longrightarrow> \<forall> x. x \<in> A \<longleftrightarrow> x \<in> B"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1717
apply (auto simp:mem_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1718
done
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1719
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1720
lemma set_cases2:
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1721
  "\<lbrakk>(A = {} \<Longrightarrow> R A); \<And> x. (A = {x}) \<Longrightarrow> R A; \<And> x y. \<lbrakk>x \<noteq> y; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> R A\<rbrakk> \<Longrightarrow> R A"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1722
apply (case_tac "A = {}", simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1723
by (case_tac "\<exists> x. A = {x}", clarsimp, blast)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1724
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1725
lemma rhs_aux:"\<lbrakk>distinct_rhs rhs; {Y. \<exists>r. (Y, r) \<in> rhs} = {X}\<rbrakk> \<Longrightarrow> (\<exists>r. rhs = {(X, r)})"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1726
apply (rule_tac A = rhs in set_cases2, simp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1727
apply (drule_tac x = X in eqset_imp_iff, clarsimp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1728
apply (drule eqset_imp_iff',clarsimp)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1729
apply (frule_tac x = a in spec, drule_tac x = aa in spec)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1730
by (auto simp:distinct_rhs_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1731
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1732
lemma every_eqcl_has_reg: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1733
  assumes finite_CS: "finite (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1734
  and X_in_CS: "X \<in> (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1735
  shows "\<exists> (reg::rexp). L reg = X" (is "\<exists> r. ?E r")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1736
proof-
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1737
  have "\<exists>ES'. Inv X ES' \<and> TCon ES'" using finite_CS X_in_CS
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1738
    by (auto intro:init_ES_satisfy_Inv iteration_conc)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1739
  then obtain ES' where Inv_ES': "Inv X ES'" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1740
                   and  TCon_ES': "TCon ES'" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1741
  from Inv_ES' TCon_ES' 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1742
  have "\<exists> rhs. ES' = {(X, rhs)}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1743
    apply (clarsimp simp:Inv_def TCon_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1744
    apply (rule_tac x = rhs in exI)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1745
    by (auto dest!:card_Suc_Diff1 simp:card_eq_0_iff)  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1746
  then obtain rhs where ES'_single_equa: "ES' = {(X, rhs)}" ..
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1747
  hence X_ardenable: "ardenable (X, rhs)" using Inv_ES'
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1748
    by (simp add:Inv_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1749
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1750
  from X_ardenable have X_l_eq_r: "X = L rhs"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1751
    by (simp add:ardenable_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1752
  hence rhs_not_empty: "rhs \<noteq> {}" using Inv_ES' ES'_single_equa
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1753
    by (auto simp:Inv_def ardenable_def L_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1754
  have rhs_eq_cls: "rhs_eq_cls rhs \<subseteq> {X, {[]}}"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1755
    using Inv_ES' ES'_single_equa
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1756
    by (auto simp:Inv_def ardenable_def left_eq_cls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1757
  have X_not_empty: "X \<noteq> {}" using Inv_ES' ES'_single_equa
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1758
    by (auto simp:Inv_def)    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1759
  show ?thesis
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1760
  proof (cases "X = {[]}")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1761
    case True
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1762
    hence "?E EMPTY" by (simp add:L_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1763
    thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1764
  next
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1765
    case False with  X_ardenable
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1766
    have "\<exists> rhs'. X = L rhs' \<and> rhs_eq_cls rhs' = rhs_eq_cls rhs - {X} \<and> distinct_rhs rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1767
      by (drule_tac ardenable_prop, auto)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1768
    then obtain rhs' where X_eq_rhs': "X = L rhs'"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1769
      and rhs'_eq_cls: "rhs_eq_cls rhs' = rhs_eq_cls rhs - {X}" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1770
      and rhs'_dist : "distinct_rhs rhs'" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1771
    have "rhs_eq_cls rhs' \<subseteq> {{[]}}" using rhs_eq_cls False rhs'_eq_cls rhs_not_empty 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1772
      by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1773
    hence "rhs_eq_cls rhs' = {{[]}}" using X_not_empty X_eq_rhs'
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1774
      by (auto simp:L_def rhs_eq_cls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1775
    hence "\<exists> r. rhs' = {({[]}, r)}" using rhs'_dist
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1776
      by (auto intro:rhs_aux simp:rhs_eq_cls_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1777
    then obtain r where "rhs' = {({[]}, r)}" ..
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1778
    hence "?E r" using X_eq_rhs' by (auto simp add:L_def lang_seq_def)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1779
    thus ?thesis by blast     
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1780
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1781
qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1782
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1783
theorem myhill_nerode: 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1784
  assumes finite_CS: "finite (UNIV Quo Lang)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1785
  shows   "\<exists> (reg::rexp). Lang = L reg" (is "\<exists> r. ?P r")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1786
proof -
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1787
  have has_r_each: "\<forall>C\<in>{X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists>(r::rexp). C = L r" using finite_CS
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1788
    by (auto dest:every_eqcl_has_reg)  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1789
  have "\<exists> (rS::rexp set). finite rS \<and> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1790
                          (\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> rS. C = L r) \<and> 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1791
                          (\<forall> r \<in> rS. \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r)" 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1792
       (is "\<exists> rS. ?Q rS")
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1793
  proof-
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1794
    have "\<And> C. C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang} \<Longrightarrow> C = L (SOME (ra::rexp). C = L ra)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1795
      using has_r_each
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1796
      apply (erule_tac x = C in ballE, erule_tac exE)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1797
      by (rule_tac a = r in someI2, simp+)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1798
    hence "?Q ((\<lambda> C. SOME r. C = L r) ` {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang})" using has_r_each
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1799
      using finite_CS by auto
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1800
    thus ?thesis by blast    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1801
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1802
  then obtain rS where finite_rS : "finite rS"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1803
    and has_r_each': "\<forall> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. \<exists> r \<in> (rS::rexp set). C = L r"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1804
    and has_cl_each: "\<forall> r \<in> (rS::rexp set). \<exists> C \<in> {X \<in> UNIV Quo Lang. \<forall>x\<in>X. x \<in> Lang}. C = L r" by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1805
  have "?P (folds ALT NULL rS)"
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1806
  proof
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1807
    show "Lang \<subseteq> L (folds ALT NULL rS)" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_r_each'
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1808
      apply (clarsimp simp:fold_alt_null_eqs) by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1809
  next 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1810
    show "L (folds ALT NULL rS) \<subseteq> Lang" using finite_rS lang_eqs_union_of_eqcls[of Lang] has_cl_each
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1811
      by (clarsimp simp:fold_alt_null_eqs)
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1812
  qed
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1813
  thus ?thesis by blast
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1814
qed 
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1815
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1816
end    
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1817
   
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1818
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1819
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1820
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1821
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1822
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1823
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1824
  
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1825
932f27fc6b55 added initial version by Chunhan
urbanc
parents:
diff changeset
  1826