Theories/Myhill_1.thy
author urbanc
Thu, 26 May 2011 18:39:36 +0000
changeset 163 b11573852f7c
parent 149 e122cb146ecc
permissions -rw-r--r--
a few more literature places
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
149
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     1
theory Myhill_1
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     2
imports Main Folds Regular
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     3
        "~~/src/HOL/Library/While_Combinator" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     4
begin
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     5
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     6
section {* Direction @{text "finite partition \<Rightarrow> regular language"} *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     7
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     8
lemma Pair_Collect[simp]:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
     9
  shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    10
by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    11
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    12
text {* Myhill-Nerode relation *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    13
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    14
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    15
  str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    16
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    17
  "\<approx>A \<equiv> {(x, y).  (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    18
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    19
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    20
  finals :: "lang \<Rightarrow> lang set"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    21
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    22
  "finals A \<equiv> {\<approx>A `` {s} | s . s \<in> A}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    23
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    24
lemma lang_is_union_of_finals: 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    25
  shows "A = \<Union> finals A"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    26
unfolding finals_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    27
unfolding Image_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    28
unfolding str_eq_rel_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    29
by (auto) (metis append_Nil2)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    30
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    31
lemma finals_in_partitions:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    32
  shows "finals A \<subseteq> (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    33
unfolding finals_def quotient_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    34
by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    35
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    36
section {* Equational systems *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    37
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    38
text {* The two kinds of terms in the rhs of equations. *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    39
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    40
datatype rhs_trm = 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    41
   Lam "rexp"            (* Lambda-marker *)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    42
 | Trn "lang" "rexp"     (* Transition *)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    43
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    44
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    45
overloading L_rhs_trm \<equiv> "L:: rhs_trm \<Rightarrow> lang"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    46
begin
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    47
  fun L_rhs_trm:: "rhs_trm \<Rightarrow> lang"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    48
  where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    49
    "L_rhs_trm (Lam r) = L r" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    50
  | "L_rhs_trm (Trn X r) = X ;; L r"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    51
end
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    52
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    53
overloading L_rhs \<equiv> "L:: rhs_trm set \<Rightarrow> lang"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    54
begin
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    55
   fun L_rhs:: "rhs_trm set \<Rightarrow> lang"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    56
   where 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    57
     "L_rhs rhs = \<Union> (L ` rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    58
end
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    59
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    60
lemma L_rhs_set:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    61
  shows "L {Trn X r | r. P r} = \<Union>{L (Trn X r) | r. P r}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    62
by (auto simp del: L_rhs_trm.simps)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    63
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    64
lemma L_rhs_union_distrib:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    65
  fixes A B::"rhs_trm set"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    66
  shows "L A \<union> L B = L (A \<union> B)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    67
by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    68
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    69
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    70
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    71
text {* Transitions between equivalence classes *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    72
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    73
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    74
  transition :: "lang \<Rightarrow> char \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    75
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    76
  "Y \<Turnstile>c\<Rightarrow> X \<equiv> Y ;; {[c]} \<subseteq> X"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    77
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    78
text {* Initial equational system *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    79
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    80
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    81
  "Init_rhs CS X \<equiv>  
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    82
      if ([] \<in> X) then 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    83
          {Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    84
      else 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    85
          {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    86
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    87
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    88
  "Init CS \<equiv> {(X, Init_rhs CS X) | X.  X \<in> CS}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    89
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    90
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    91
section {* Arden Operation on equations *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    92
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    93
fun 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    94
  Append_rexp :: "rexp \<Rightarrow> rhs_trm \<Rightarrow> rhs_trm"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    95
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    96
  "Append_rexp r (Lam rexp)   = Lam (SEQ rexp r)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    97
| "Append_rexp r (Trn X rexp) = Trn X (SEQ rexp r)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    98
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
    99
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   100
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   101
  "Append_rexp_rhs rhs rexp \<equiv> (Append_rexp rexp) ` rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   102
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   103
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   104
  "Arden X rhs \<equiv> 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   105
     Append_rexp_rhs (rhs - {Trn X r | r. Trn X r \<in> rhs}) (STAR (\<Uplus> {r. Trn X r \<in> rhs}))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   106
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   107
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   108
section {* Substitution Operation on equations *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   109
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   110
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   111
  "Subst rhs X xrhs \<equiv> 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   112
        (rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> (Append_rexp_rhs xrhs (\<Uplus> {r. Trn X r \<in> rhs}))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   113
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   114
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   115
  Subst_all :: "(lang \<times> rhs_trm set) set \<Rightarrow> lang \<Rightarrow> rhs_trm set \<Rightarrow> (lang \<times> rhs_trm set) set"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   116
where
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   117
  "Subst_all ES X xrhs \<equiv> {(Y, Subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   118
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   119
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   120
  "Remove ES X xrhs \<equiv> 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   121
      Subst_all  (ES - {(X, xrhs)}) X (Arden X xrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   122
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   123
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   124
section {* While-combinator *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   125
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   126
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   127
  "Iter X ES \<equiv> (let (Y, yrhs) = SOME (Y, yrhs). (Y, yrhs) \<in> ES \<and> X \<noteq> Y
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   128
                in Remove ES Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   129
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   130
lemma IterI2:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   131
  assumes "(Y, yrhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   132
  and     "X \<noteq> Y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   133
  and     "\<And>Y yrhs. \<lbrakk>(Y, yrhs) \<in> ES; X \<noteq> Y\<rbrakk> \<Longrightarrow> Q (Remove ES Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   134
  shows "Q (Iter X ES)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   135
unfolding Iter_def using assms
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   136
by (rule_tac a="(Y, yrhs)" in someI2) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   137
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   138
abbreviation
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   139
  "Cond ES \<equiv> card ES \<noteq> 1"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   140
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   141
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   142
  "Solve X ES \<equiv> while Cond (Iter X) ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   143
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   144
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   145
section {* Invariants *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   146
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   147
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   148
  "distinctness ES \<equiv> 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   149
     \<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   150
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   151
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   152
  "soundness ES \<equiv> \<forall>(X, rhs) \<in> ES. X = L rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   153
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   154
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   155
  "ardenable rhs \<equiv> (\<forall> Y r. Trn Y r \<in> rhs \<longrightarrow> [] \<notin> L r)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   156
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   157
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   158
  "ardenable_all ES \<equiv> \<forall>(X, rhs) \<in> ES. ardenable rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   159
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   160
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   161
  "finite_rhs ES \<equiv> \<forall>(X, rhs) \<in> ES. finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   162
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   163
lemma finite_rhs_def2:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   164
  "finite_rhs ES = (\<forall> X rhs. (X, rhs) \<in> ES \<longrightarrow> finite rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   165
unfolding finite_rhs_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   166
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   167
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   168
  "rhss rhs \<equiv> {X | X r. Trn X r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   169
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   170
definition
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   171
  "lhss ES \<equiv> {Y | Y yrhs. (Y, yrhs) \<in> ES}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   172
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   173
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   174
  "validity ES \<equiv> \<forall>(X, rhs) \<in> ES. rhss rhs \<subseteq> lhss ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   175
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   176
lemma rhss_union_distrib:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   177
  shows "rhss (A \<union> B) = rhss A \<union> rhss B"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   178
by (auto simp add: rhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   179
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   180
lemma lhss_union_distrib:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   181
  shows "lhss (A \<union> B) = lhss A \<union> lhss B"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   182
by (auto simp add: lhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   183
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   184
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   185
definition 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   186
  "invariant ES \<equiv> finite ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   187
                \<and> finite_rhs ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   188
                \<and> soundness ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   189
                \<and> distinctness ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   190
                \<and> ardenable_all ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   191
                \<and> validity ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   192
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   193
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   194
lemma invariantI:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   195
  assumes "soundness ES" "finite ES" "distinctness ES" "ardenable_all ES" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   196
          "finite_rhs ES" "validity ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   197
  shows "invariant ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   198
using assms by (simp add: invariant_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   199
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   200
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   201
subsection {* The proof of this direction *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   202
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   203
lemma finite_Trn:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   204
  assumes fin: "finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   205
  shows "finite {r. Trn Y r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   206
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   207
  have "finite {Trn Y r | Y r. Trn Y r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   208
    by (rule rev_finite_subset[OF fin]) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   209
  then have "finite ((\<lambda>(Y, r). Trn Y r) ` {(Y, r) | Y r. Trn Y r \<in> rhs})"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   210
    by (simp add: image_Collect)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   211
  then have "finite {(Y, r) | Y r. Trn Y r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   212
    by (erule_tac finite_imageD) (simp add: inj_on_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   213
  then show "finite {r. Trn Y r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   214
    by (erule_tac f="snd" in finite_surj) (auto simp add: image_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   215
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   216
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   217
lemma finite_Lam:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   218
  assumes fin: "finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   219
  shows "finite {r. Lam r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   220
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   221
  have "finite {Lam r | r. Lam r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   222
    by (rule rev_finite_subset[OF fin]) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   223
  then show "finite {r. Lam r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   224
    apply(simp add: image_Collect[symmetric])
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   225
    apply(erule finite_imageD)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   226
    apply(auto simp add: inj_on_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   227
    done
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   228
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   229
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   230
lemma rhs_trm_soundness:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   231
  assumes finite:"finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   232
  shows "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   233
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   234
  have "finite {r. Trn X r \<in> rhs}" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   235
    by (rule finite_Trn[OF finite]) 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   236
  then show "L ({Trn X r| r. Trn X r \<in> rhs}) = X ;; (L (\<Uplus>{r. Trn X r \<in> rhs}))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   237
    by (simp only: L_rhs_set L_rhs_trm.simps) (auto simp add: Seq_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   238
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   239
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   240
lemma lang_of_append_rexp:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   241
  "L (Append_rexp r rhs_trm) = L rhs_trm ;; L r"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   242
by (induct rule: Append_rexp.induct)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   243
   (auto simp add: seq_assoc)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   244
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   245
lemma lang_of_append_rexp_rhs:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   246
  "L (Append_rexp_rhs rhs r) = L rhs ;; L r"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   247
unfolding Append_rexp_rhs_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   248
by (auto simp add: Seq_def lang_of_append_rexp)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   249
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   250
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   251
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   252
subsubsection {* Intialization *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   253
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   254
lemma defined_by_str:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   255
  assumes "s \<in> X" "X \<in> UNIV // \<approx>A" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   256
  shows "X = \<approx>A `` {s}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   257
using assms
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   258
unfolding quotient_def Image_def str_eq_rel_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   259
by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   260
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   261
lemma every_eqclass_has_transition:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   262
  assumes has_str: "s @ [c] \<in> X"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   263
  and     in_CS:   "X \<in> UNIV // \<approx>A"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   264
  obtains Y where "Y \<in> UNIV // \<approx>A" and "Y ;; {[c]} \<subseteq> X" and "s \<in> Y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   265
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   266
  def Y \<equiv> "\<approx>A `` {s}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   267
  have "Y \<in> UNIV // \<approx>A" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   268
    unfolding Y_def quotient_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   269
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   270
  have "X = \<approx>A `` {s @ [c]}" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   271
    using has_str in_CS defined_by_str by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   272
  then have "Y ;; {[c]} \<subseteq> X" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   273
    unfolding Y_def Image_def Seq_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   274
    unfolding str_eq_rel_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   275
    by clarsimp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   276
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   277
  have "s \<in> Y" unfolding Y_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   278
    unfolding Image_def str_eq_rel_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   279
  ultimately show thesis using that by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   280
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   281
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   282
lemma l_eq_r_in_eqs:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   283
  assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   284
  shows "X = L rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   285
proof 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   286
  show "X \<subseteq> L rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   287
  proof
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   288
    fix x
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   289
    assume in_X: "x \<in> X"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   290
    { assume empty: "x = []"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   291
      then have "x \<in> L rhs" using X_in_eqs in_X
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   292
	unfolding Init_def Init_rhs_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   293
        by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   294
    }
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   295
    moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   296
    { assume not_empty: "x \<noteq> []"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   297
      then obtain s c where decom: "x = s @ [c]"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   298
	using rev_cases by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   299
      have "X \<in> UNIV // \<approx>A" using X_in_eqs unfolding Init_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   300
      then obtain Y where "Y \<in> UNIV // \<approx>A" "Y ;; {[c]} \<subseteq> X" "s \<in> Y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   301
        using decom in_X every_eqclass_has_transition by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   302
      then have "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // \<approx>A \<and> Y \<Turnstile>c\<Rightarrow> X}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   303
        unfolding transition_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   304
	using decom by (force simp add: Seq_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   305
      then have "x \<in> L rhs" using X_in_eqs in_X
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   306
	unfolding Init_def Init_rhs_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   307
    }
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   308
    ultimately show "x \<in> L rhs" by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   309
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   310
next
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   311
  show "L rhs \<subseteq> X" using X_in_eqs
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   312
    unfolding Init_def Init_rhs_def transition_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   313
    by auto 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   314
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   315
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   316
lemma test:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   317
  assumes X_in_eqs: "(X, rhs) \<in> Init (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   318
  shows "X = \<Union> (L `  rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   319
using assms l_eq_r_in_eqs by (simp)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   320
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   321
lemma finite_Init_rhs: 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   322
  assumes finite: "finite CS"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   323
  shows "finite (Init_rhs CS X)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   324
proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   325
  def S \<equiv> "{(Y, c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   326
  def h \<equiv> "\<lambda> (Y, c). Trn Y (CHAR c)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   327
  have "finite (CS \<times> (UNIV::char set))" using finite by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   328
  then have "finite S" using S_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   329
    by (rule_tac B = "CS \<times> UNIV" in finite_subset) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   330
  moreover have "{Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X} = h ` S"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   331
    unfolding S_def h_def image_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   332
  ultimately
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   333
  have "finite {Trn Y (CHAR c) |Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}" by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   334
  then show "finite (Init_rhs CS X)" unfolding Init_rhs_def transition_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   335
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   336
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   337
lemma Init_ES_satisfies_invariant:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   338
  assumes finite_CS: "finite (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   339
  shows "invariant (Init (UNIV // \<approx>A))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   340
proof (rule invariantI)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   341
  show "soundness (Init (UNIV // \<approx>A))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   342
    unfolding soundness_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   343
    using l_eq_r_in_eqs by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   344
  show "finite (Init (UNIV // \<approx>A))" using finite_CS
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   345
    unfolding Init_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   346
  show "distinctness (Init (UNIV // \<approx>A))"     
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   347
    unfolding distinctness_def Init_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   348
  show "ardenable_all (Init (UNIV // \<approx>A))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   349
    unfolding ardenable_all_def Init_def Init_rhs_def ardenable_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   350
   by auto 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   351
  show "finite_rhs (Init (UNIV // \<approx>A))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   352
    using finite_Init_rhs[OF finite_CS]
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   353
    unfolding finite_rhs_def Init_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   354
  show "validity (Init (UNIV // \<approx>A))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   355
    unfolding validity_def Init_def Init_rhs_def rhss_def lhss_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   356
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   357
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   358
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   359
subsubsection {* Interation step *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   360
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   361
lemma Arden_keeps_eq:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   362
  assumes l_eq_r: "X = L rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   363
  and not_empty: "ardenable rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   364
  and finite: "finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   365
  shows "X = L (Arden X rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   366
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   367
  def A \<equiv> "L (\<Uplus>{r. Trn X r \<in> rhs})"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   368
  def b \<equiv> "{Trn X r | r. Trn X r \<in> rhs}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   369
  def B \<equiv> "L (rhs - b)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   370
  have not_empty2: "[] \<notin> A" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   371
    using finite_Trn[OF finite] not_empty
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   372
    unfolding A_def ardenable_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   373
  have "X = L rhs" using l_eq_r by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   374
  also have "\<dots> = L (b \<union> (rhs - b))" unfolding b_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   375
  also have "\<dots> = L b \<union> B" unfolding B_def by (simp only: L_rhs_union_distrib)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   376
  also have "\<dots> = X ;; A \<union> B"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   377
    unfolding b_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   378
    unfolding rhs_trm_soundness[OF finite]
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   379
    unfolding A_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   380
    by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   381
  finally have "X = X ;; A \<union> B" . 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   382
  then have "X = B ;; A\<star>"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   383
    by (simp add: arden[OF not_empty2])
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   384
  also have "\<dots> = L (Arden X rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   385
    unfolding Arden_def A_def B_def b_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   386
    by (simp only: lang_of_append_rexp_rhs L_rexp.simps)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   387
  finally show "X = L (Arden X rhs)" by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   388
qed 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   389
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   390
lemma Append_keeps_finite:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   391
  "finite rhs \<Longrightarrow> finite (Append_rexp_rhs rhs r)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   392
by (auto simp:Append_rexp_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   393
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   394
lemma Arden_keeps_finite:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   395
  "finite rhs \<Longrightarrow> finite (Arden X rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   396
by (auto simp:Arden_def Append_keeps_finite)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   397
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   398
lemma Append_keeps_nonempty:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   399
  "ardenable rhs \<Longrightarrow> ardenable (Append_rexp_rhs rhs r)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   400
apply (auto simp:ardenable_def Append_rexp_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   401
by (case_tac x, auto simp:Seq_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   402
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   403
lemma nonempty_set_sub:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   404
  "ardenable rhs \<Longrightarrow> ardenable (rhs - A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   405
by (auto simp:ardenable_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   406
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   407
lemma nonempty_set_union:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   408
  "\<lbrakk>ardenable rhs; ardenable rhs'\<rbrakk> \<Longrightarrow> ardenable (rhs \<union> rhs')"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   409
by (auto simp:ardenable_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   410
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   411
lemma Arden_keeps_nonempty:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   412
  "ardenable rhs \<Longrightarrow> ardenable (Arden X rhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   413
by (simp only:Arden_def Append_keeps_nonempty nonempty_set_sub)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   414
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   415
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   416
lemma Subst_keeps_nonempty:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   417
  "\<lbrakk>ardenable rhs; ardenable xrhs\<rbrakk> \<Longrightarrow> ardenable (Subst rhs X xrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   418
by (simp only: Subst_def Append_keeps_nonempty nonempty_set_union nonempty_set_sub)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   419
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   420
lemma Subst_keeps_eq:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   421
  assumes substor: "X = L xrhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   422
  and finite: "finite rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   423
  shows "L (Subst rhs X xrhs) = L rhs" (is "?Left = ?Right")
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   424
proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   425
  def A \<equiv> "L (rhs - {Trn X r | r. Trn X r \<in> rhs})"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   426
  have "?Left = A \<union> L (Append_rexp_rhs xrhs (\<Uplus>{r. Trn X r \<in> rhs}))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   427
    unfolding Subst_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   428
    unfolding L_rhs_union_distrib[symmetric]
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   429
    by (simp add: A_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   430
  moreover have "?Right = A \<union> L ({Trn X r | r. Trn X r \<in> rhs})"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   431
  proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   432
    have "rhs = (rhs - {Trn X r | r. Trn X r \<in> rhs}) \<union> ({Trn X r | r. Trn X r \<in> rhs})" by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   433
    thus ?thesis 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   434
      unfolding A_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   435
      unfolding L_rhs_union_distrib
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   436
      by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   437
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   438
  moreover have "L (Append_rexp_rhs xrhs (\<Uplus>{r. Trn X r \<in> rhs})) = L ({Trn X r | r. Trn X r \<in> rhs})" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   439
    using finite substor by (simp only: lang_of_append_rexp_rhs rhs_trm_soundness)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   440
  ultimately show ?thesis by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   441
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   442
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   443
lemma Subst_keeps_finite_rhs:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   444
  "\<lbrakk>finite rhs; finite yrhs\<rbrakk> \<Longrightarrow> finite (Subst rhs Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   445
by (auto simp: Subst_def Append_keeps_finite)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   446
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   447
lemma Subst_all_keeps_finite:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   448
  assumes finite: "finite ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   449
  shows "finite (Subst_all ES Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   450
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   451
  def eqns \<equiv> "{(X::lang, rhs) |X rhs. (X, rhs) \<in> ES}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   452
  def h \<equiv> "\<lambda>(X::lang, rhs). (X, Subst rhs Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   453
  have "finite (h ` eqns)" using finite h_def eqns_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   454
  moreover 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   455
  have "Subst_all ES Y yrhs = h ` eqns" unfolding h_def eqns_def Subst_all_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   456
  ultimately
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   457
  show "finite (Subst_all ES Y yrhs)" by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   458
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   459
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   460
lemma Subst_all_keeps_finite_rhs:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   461
  "\<lbrakk>finite_rhs ES; finite yrhs\<rbrakk> \<Longrightarrow> finite_rhs (Subst_all ES Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   462
by (auto intro:Subst_keeps_finite_rhs simp add:Subst_all_def finite_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   463
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   464
lemma append_rhs_keeps_cls:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   465
  "rhss (Append_rexp_rhs rhs r) = rhss rhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   466
apply (auto simp:rhss_def Append_rexp_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   467
apply (case_tac xa, auto simp:image_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   468
by (rule_tac x = "SEQ ra r" in exI, rule_tac x = "Trn x ra" in bexI, simp+)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   469
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   470
lemma Arden_removes_cl:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   471
  "rhss (Arden Y yrhs) = rhss yrhs - {Y}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   472
apply (simp add:Arden_def append_rhs_keeps_cls)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   473
by (auto simp:rhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   474
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   475
lemma lhss_keeps_cls:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   476
  "lhss (Subst_all ES Y yrhs) = lhss ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   477
by (auto simp:lhss_def Subst_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   478
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   479
lemma Subst_updates_cls:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   480
  "X \<notin> rhss xrhs \<Longrightarrow> 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   481
      rhss (Subst rhs X xrhs) = rhss rhs \<union> rhss xrhs - {X}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   482
apply (simp only:Subst_def append_rhs_keeps_cls rhss_union_distrib)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   483
by (auto simp:rhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   484
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   485
lemma Subst_all_keeps_validity:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   486
  assumes sc: "validity (ES \<union> {(Y, yrhs)})"        (is "validity ?A")
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   487
  shows "validity (Subst_all ES Y (Arden Y yrhs))"  (is "validity ?B")
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   488
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   489
  { fix X xrhs'
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   490
    assume "(X, xrhs') \<in> ?B"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   491
    then obtain xrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   492
      where xrhs_xrhs': "xrhs' = Subst xrhs Y (Arden Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   493
      and X_in: "(X, xrhs) \<in> ES" by (simp add:Subst_all_def, blast)    
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   494
    have "rhss xrhs' \<subseteq> lhss ?B"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   495
    proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   496
      have "lhss ?B = lhss ES" by (auto simp add:lhss_def Subst_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   497
      moreover have "rhss xrhs' \<subseteq> lhss ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   498
      proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   499
        have "rhss xrhs' \<subseteq>  rhss xrhs \<union> rhss (Arden Y yrhs) - {Y}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   500
        proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   501
          have "Y \<notin> rhss (Arden Y yrhs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   502
            using Arden_removes_cl by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   503
          thus ?thesis using xrhs_xrhs' by (auto simp:Subst_updates_cls)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   504
        qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   505
        moreover have "rhss xrhs \<subseteq> lhss ES \<union> {Y}" using X_in sc
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   506
          apply (simp only:validity_def lhss_union_distrib)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   507
          by (drule_tac x = "(X, xrhs)" in bspec, auto simp:lhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   508
        moreover have "rhss (Arden Y yrhs) \<subseteq> lhss ES \<union> {Y}" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   509
          using sc 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   510
          by (auto simp add:Arden_removes_cl validity_def lhss_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   511
        ultimately show ?thesis by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   512
      qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   513
      ultimately show ?thesis by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   514
    qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   515
  } thus ?thesis by (auto simp only:Subst_all_def validity_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   516
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   517
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   518
lemma Subst_all_satisfies_invariant:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   519
  assumes invariant_ES: "invariant (ES \<union> {(Y, yrhs)})"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   520
  shows "invariant (Subst_all ES Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   521
proof (rule invariantI)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   522
  have Y_eq_yrhs: "Y = L yrhs" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   523
    using invariant_ES by (simp only:invariant_def soundness_def, blast)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   524
   have finite_yrhs: "finite yrhs" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   525
    using invariant_ES by (auto simp:invariant_def finite_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   526
  have nonempty_yrhs: "ardenable yrhs" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   527
    using invariant_ES by (auto simp:invariant_def ardenable_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   528
  show "soundness (Subst_all ES Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   529
  proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   530
    have "Y = L (Arden Y yrhs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   531
      using Y_eq_yrhs invariant_ES finite_yrhs
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   532
      using finite_Trn[OF finite_yrhs]
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   533
      apply(rule_tac Arden_keeps_eq)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   534
      apply(simp_all)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   535
      unfolding invariant_def ardenable_all_def ardenable_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   536
      apply(auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   537
      done
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   538
    thus ?thesis using invariant_ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   539
      unfolding invariant_def finite_rhs_def2 soundness_def Subst_all_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   540
      by (auto simp add: Subst_keeps_eq simp del: L_rhs.simps)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   541
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   542
  show "finite (Subst_all ES Y (Arden Y yrhs))" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   543
    using invariant_ES by (simp add:invariant_def Subst_all_keeps_finite)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   544
  show "distinctness (Subst_all ES Y (Arden Y yrhs))" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   545
    using invariant_ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   546
    unfolding distinctness_def Subst_all_def invariant_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   547
  show "ardenable_all (Subst_all ES Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   548
  proof - 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   549
    { fix X rhs
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   550
      assume "(X, rhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   551
      hence "ardenable rhs"  using invariant_ES  
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   552
        by (auto simp add:invariant_def ardenable_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   553
      with nonempty_yrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   554
      have "ardenable (Subst rhs Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   555
        by (simp add:nonempty_yrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   556
               Subst_keeps_nonempty Arden_keeps_nonempty)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   557
    } thus ?thesis by (auto simp add:ardenable_all_def Subst_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   558
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   559
  show "finite_rhs (Subst_all ES Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   560
  proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   561
    have "finite_rhs ES" using invariant_ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   562
      by (simp add:invariant_def finite_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   563
    moreover have "finite (Arden Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   564
    proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   565
      have "finite yrhs" using invariant_ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   566
        by (auto simp:invariant_def finite_rhs_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   567
      thus ?thesis using Arden_keeps_finite by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   568
    qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   569
    ultimately show ?thesis 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   570
      by (simp add:Subst_all_keeps_finite_rhs)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   571
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   572
  show "validity (Subst_all ES Y (Arden Y yrhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   573
    using invariant_ES Subst_all_keeps_validity by (simp add:invariant_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   574
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   575
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   576
lemma Remove_in_card_measure:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   577
  assumes finite: "finite ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   578
  and     in_ES: "(X, rhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   579
  shows "(Remove ES X rhs, ES) \<in> measure card"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   580
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   581
  def f \<equiv> "\<lambda> x. ((fst x)::lang, Subst (snd x) X (Arden X rhs))"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   582
  def ES' \<equiv> "ES - {(X, rhs)}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   583
  have "Subst_all ES' X (Arden X rhs) = f ` ES'" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   584
    apply (auto simp: Subst_all_def f_def image_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   585
    by (rule_tac x = "(Y, yrhs)" in bexI, simp+)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   586
  then have "card (Subst_all ES' X (Arden X rhs)) \<le> card ES'"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   587
    unfolding ES'_def using finite by (auto intro: card_image_le)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   588
  also have "\<dots> < card ES" unfolding ES'_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   589
    using in_ES finite by (rule_tac card_Diff1_less)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   590
  finally show "(Remove ES X rhs, ES) \<in> measure card" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   591
    unfolding Remove_def ES'_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   592
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   593
    
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   594
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   595
lemma Subst_all_cls_remains: 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   596
  "(X, xrhs) \<in> ES \<Longrightarrow> \<exists> xrhs'. (X, xrhs') \<in> (Subst_all ES Y yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   597
by (auto simp: Subst_all_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   598
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   599
lemma card_noteq_1_has_more:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   600
  assumes card:"Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   601
  and e_in: "(X, xrhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   602
  and finite: "finite ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   603
  shows "\<exists>(Y, yrhs) \<in> ES. (X, xrhs) \<noteq> (Y, yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   604
proof-
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   605
  have "card ES > 1" using card e_in finite 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   606
    by (cases "card ES") (auto) 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   607
  then have "card (ES - {(X, xrhs)}) > 0"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   608
    using finite e_in by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   609
  then have "(ES - {(X, xrhs)}) \<noteq> {}" using finite by (rule_tac notI, simp)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   610
  then show "\<exists>(Y, yrhs) \<in> ES. (X, xrhs) \<noteq> (Y, yrhs)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   611
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   612
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   613
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   614
lemma iteration_step_measure:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   615
  assumes Inv_ES: "invariant ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   616
  and    X_in_ES: "(X, xrhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   617
  and    Cnd:     "Cond ES "
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   618
  shows "(Iter X ES, ES) \<in> measure card"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   619
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   620
  have fin: "finite ES" using Inv_ES unfolding invariant_def by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   621
  then obtain Y yrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   622
    where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   623
    using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   624
  then have "(Y, yrhs) \<in> ES " "X \<noteq> Y"  
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   625
    using X_in_ES Inv_ES unfolding invariant_def distinctness_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   626
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   627
  then show "(Iter X ES, ES) \<in> measure card" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   628
  apply(rule IterI2)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   629
  apply(rule Remove_in_card_measure)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   630
  apply(simp_all add: fin)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   631
  done
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   632
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   633
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   634
lemma iteration_step_invariant:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   635
  assumes Inv_ES: "invariant ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   636
  and    X_in_ES: "(X, xrhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   637
  and    Cnd: "Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   638
  shows "invariant (Iter X ES)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   639
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   640
  have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   641
  then obtain Y yrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   642
    where Y_in_ES: "(Y, yrhs) \<in> ES" and not_eq: "(X, xrhs) \<noteq> (Y, yrhs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   643
    using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   644
  then have "(Y, yrhs) \<in> ES" "X \<noteq> Y" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   645
    using X_in_ES Inv_ES unfolding invariant_def distinctness_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   646
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   647
  then show "invariant (Iter X ES)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   648
  proof(rule IterI2)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   649
    fix Y yrhs
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   650
    assume h: "(Y, yrhs) \<in> ES" "X \<noteq> Y"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   651
    then have "ES - {(Y, yrhs)} \<union> {(Y, yrhs)} = ES" by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   652
    then show "invariant (Remove ES Y yrhs)" unfolding Remove_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   653
      using Inv_ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   654
      by (rule_tac Subst_all_satisfies_invariant) (simp) 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   655
  qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   656
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   657
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   658
lemma iteration_step_ex:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   659
  assumes Inv_ES: "invariant ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   660
  and    X_in_ES: "(X, xrhs) \<in> ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   661
  and    Cnd: "Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   662
  shows "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   663
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   664
  have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   665
  then obtain Y yrhs 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   666
    where "(Y, yrhs) \<in> ES" "(X, xrhs) \<noteq> (Y, yrhs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   667
    using Cnd X_in_ES by (drule_tac card_noteq_1_has_more) (auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   668
  then have "(Y, yrhs) \<in> ES " "X \<noteq> Y"  
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   669
    using X_in_ES Inv_ES unfolding invariant_def distinctness_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   670
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   671
  then show "\<exists>xrhs'. (X, xrhs') \<in> (Iter X ES)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   672
  apply(rule IterI2)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   673
  unfolding Remove_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   674
  apply(rule Subst_all_cls_remains)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   675
  using X_in_ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   676
  apply(auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   677
  done
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   678
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   679
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   680
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   681
subsubsection {* Conclusion of the proof *}
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   682
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   683
lemma Solve:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   684
  assumes fin: "finite (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   685
  and     X_in: "X \<in> (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   686
  shows "\<exists>rhs. Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)} \<and> invariant {(X, rhs)}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   687
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   688
  def Inv \<equiv> "\<lambda>ES. invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   689
  have "Inv (Init (UNIV // \<approx>A))" unfolding Inv_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   690
      using fin X_in by (simp add: Init_ES_satisfies_invariant, simp add: Init_def)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   691
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   692
  { fix ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   693
    assume inv: "Inv ES" and crd: "Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   694
    then have "Inv (Iter X ES)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   695
      unfolding Inv_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   696
      by (auto simp add: iteration_step_invariant iteration_step_ex) }
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   697
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   698
  { fix ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   699
    assume inv: "Inv ES" and not_crd: "\<not>Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   700
    from inv obtain rhs where "(X, rhs) \<in> ES" unfolding Inv_def by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   701
    moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   702
    from not_crd have "card ES = 1" by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   703
    ultimately 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   704
    have "ES = {(X, rhs)}" by (auto simp add: card_Suc_eq) 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   705
    then have "\<exists>rhs'. ES = {(X, rhs')} \<and> invariant {(X, rhs')}" using inv
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   706
      unfolding Inv_def by auto }
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   707
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   708
    have "wf (measure card)" by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   709
  moreover
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   710
  { fix ES
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   711
    assume inv: "Inv ES" and crd: "Cond ES"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   712
    then have "(Iter X ES, ES) \<in> measure card"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   713
      unfolding Inv_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   714
      apply(clarify)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   715
      apply(rule_tac iteration_step_measure)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   716
      apply(auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   717
      done }
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   718
  ultimately 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   719
  show "\<exists>rhs. Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)} \<and> invariant {(X, rhs)}" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   720
    unfolding Solve_def by (rule while_rule)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   721
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   722
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   723
lemma every_eqcl_has_reg:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   724
  assumes finite_CS: "finite (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   725
  and X_in_CS: "X \<in> (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   726
  shows "\<exists>r::rexp. X = L r" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   727
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   728
  from finite_CS X_in_CS 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   729
  obtain xrhs where Inv_ES: "invariant {(X, xrhs)}"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   730
    using Solve by metis
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   731
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   732
  def A \<equiv> "Arden X xrhs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   733
  have "rhss xrhs \<subseteq> {X}" using Inv_ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   734
    unfolding validity_def invariant_def rhss_def lhss_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   735
    by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   736
  then have "rhss A = {}" unfolding A_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   737
    by (simp add: Arden_removes_cl)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   738
  then have eq: "{Lam r | r. Lam r \<in> A} = A" unfolding rhss_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   739
    by (auto, case_tac x, auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   740
  
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   741
  have "finite A" using Inv_ES unfolding A_def invariant_def finite_rhs_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   742
    using Arden_keeps_finite by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   743
  then have fin: "finite {r. Lam r \<in> A}" by (rule finite_Lam)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   744
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   745
  have "X = L xrhs" using Inv_ES unfolding invariant_def soundness_def
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   746
    by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   747
  then have "X = L A" using Inv_ES 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   748
    unfolding A_def invariant_def ardenable_all_def finite_rhs_def 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   749
    by (rule_tac Arden_keeps_eq) (simp_all add: finite_Trn)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   750
  then have "X = L {Lam r | r. Lam r \<in> A}" using eq by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   751
  then have "X = L (\<Uplus>{r. Lam r \<in> A})" using fin by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   752
  then show "\<exists>r::rexp. X = L r" by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   753
qed
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   754
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   755
lemma bchoice_finite_set:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   756
  assumes a: "\<forall>x \<in> S. \<exists>y. x = f y" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   757
  and     b: "finite S"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   758
  shows "\<exists>ys. (\<Union> S) = \<Union>(f ` ys) \<and> finite ys"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   759
using bchoice[OF a] b
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   760
apply(erule_tac exE)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   761
apply(rule_tac x="fa ` S" in exI)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   762
apply(auto)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   763
done
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   764
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   765
theorem Myhill_Nerode1:
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   766
  assumes finite_CS: "finite (UNIV // \<approx>A)"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   767
  shows   "\<exists>r::rexp. A = L r"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   768
proof -
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   769
  have fin: "finite (finals A)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   770
    using finals_in_partitions finite_CS by (rule finite_subset)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   771
  have "\<forall>X \<in> (UNIV // \<approx>A). \<exists>r::rexp. X = L r" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   772
    using finite_CS every_eqcl_has_reg by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   773
  then have a: "\<forall>X \<in> finals A. \<exists>r::rexp. X = L r"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   774
    using finals_in_partitions by auto
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   775
  then obtain rs::"rexp set" where "\<Union> (finals A) = \<Union>(L ` rs)" "finite rs"
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   776
    using fin by (auto dest: bchoice_finite_set)
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   777
  then have "A = L (\<Uplus>rs)" 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   778
    unfolding lang_is_union_of_finals[symmetric] by simp
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   779
  then show "\<exists>r::rexp. A = L r" by blast
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   780
qed 
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   781
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   782
e122cb146ecc added the most current versions of the theories.
urbanc
parents:
diff changeset
   783
end