Attic/More_Regular_Set.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 12 Sep 2013 10:34:11 +0200
changeset 385 e5e32faa2446
parent 203 5d724fe0e096
permissions -rw-r--r--
updated to new Isabelle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
203
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     1
(* Author: Christian Urban, Xingyuan Zhang, Chunhan Wu *)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     2
theory More_Regular_Set
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     3
imports "Regular_Exp" "Folds"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     4
begin
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     5
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     6
text {* Some properties of operator @{text "@@"}. *}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     7
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     8
notation 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
     9
  conc (infixr "\<cdot>" 100) and
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    10
  star ("_\<star>" [101] 102)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    11
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    12
lemma star_decom: 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    13
  assumes a: "x \<in> A\<star>" "x \<noteq> []"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    14
  shows "\<exists>a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    15
using a
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    16
by (induct rule: star_induct) (blast)+
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    17
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    18
lemma conc_pow_comm:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    19
  shows "A \<cdot> (A ^^ n) = (A ^^ n) \<cdot> A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    20
by (induct n) (simp_all add: conc_assoc[symmetric])
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    21
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    22
lemma conc_star_comm:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    23
  shows "A \<cdot> A\<star> = A\<star> \<cdot> A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    24
unfolding star_def conc_pow_comm conc_UNION_distrib
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    25
by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    26
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    27
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    28
text {* Two lemmas about the length of strings in @{text "A \<up> n"} *}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    29
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    30
lemma pow_length:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    31
  assumes a: "[] \<notin> A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    32
  and     b: "s \<in> A ^^ Suc n"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    33
  shows "n < length s"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    34
using b
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    35
proof (induct n arbitrary: s)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    36
  case 0
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    37
  have "s \<in> A ^^ Suc 0" by fact
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    38
  with a have "s \<noteq> []" by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    39
  then show "0 < length s" by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    40
next
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    41
  case (Suc n)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    42
  have ih: "\<And>s. s \<in> A ^^ Suc n \<Longrightarrow> n < length s" by fact
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    43
  have "s \<in> A ^^ Suc (Suc n)" by fact
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    44
  then obtain s1 s2 where eq: "s = s1 @ s2" and *: "s1 \<in> A" and **: "s2 \<in> A ^^ Suc n"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    45
    by (auto simp add: conc_def)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    46
  from ih ** have "n < length s2" by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    47
  moreover have "0 < length s1" using * a by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    48
  ultimately show "Suc n < length s" unfolding eq 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    49
    by (simp only: length_append)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    50
qed
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    51
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    52
lemma conc_pow_length:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    53
  assumes a: "[] \<notin> A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    54
  and     b: "s \<in> B \<cdot> (A ^^ Suc n)"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    55
  shows "n < length s"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    56
proof -
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    57
  from b obtain s1 s2 where eq: "s = s1 @ s2" and *: "s2 \<in> A ^^ Suc n"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    58
    by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    59
  from * have " n < length s2" by (rule pow_length[OF a])
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    60
  then show "n < length s" using eq by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    61
qed
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    62
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    63
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    64
section {* A modified version of Arden's lemma *}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    65
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    66
text {*  A helper lemma for Arden *}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    67
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    68
lemma arden_helper:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    69
  assumes eq: "X = X \<cdot> A \<union> B"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    70
  shows "X = X \<cdot> (A ^^ Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A ^^ m))"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    71
proof (induct n)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    72
  case 0 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    73
  show "X = X \<cdot> (A ^^ Suc 0) \<union> (\<Union>(m::nat)\<in>{0..0}. B \<cdot> (A ^^ m))"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    74
    using eq by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    75
next
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    76
  case (Suc n)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    77
  have ih: "X = X \<cdot> (A ^^ Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A ^^ m))" by fact
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    78
  also have "\<dots> = (X \<cdot> A \<union> B) \<cdot> (A ^^ Suc n) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A ^^ m))" using eq by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    79
  also have "\<dots> = X \<cdot> (A ^^ Suc (Suc n)) \<union> (B \<cdot> (A ^^ Suc n)) \<union> (\<Union>m\<in>{0..n}. B \<cdot> (A ^^ m))"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    80
    by (simp add: conc_Un_distrib conc_assoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    81
  also have "\<dots> = X \<cdot> (A ^^ Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B \<cdot> (A ^^ m))"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    82
    by (auto simp add: le_Suc_eq)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    83
  finally show "X = X \<cdot> (A ^^ Suc (Suc n)) \<union> (\<Union>m\<in>{0..Suc n}. B \<cdot> (A ^^ m))" .
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    84
qed
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    85
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    86
theorem arden:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    87
  assumes nemp: "[] \<notin> A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    88
  shows "X = X \<cdot> A \<union> B \<longleftrightarrow> X = B \<cdot> A\<star>"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    89
proof
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    90
  assume eq: "X = B \<cdot> A\<star>"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    91
  have "A\<star> = {[]} \<union> A\<star> \<cdot> A" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    92
    unfolding conc_star_comm[symmetric]
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    93
    by(metis Un_commute star_unfold_left)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    94
  then have "B \<cdot> A\<star> = B \<cdot> ({[]} \<union> A\<star> \<cdot> A)"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    95
    by metis
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    96
  also have "\<dots> = B \<union> B \<cdot> (A\<star> \<cdot> A)"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    97
    unfolding conc_Un_distrib by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    98
  also have "\<dots> = B \<union> (B \<cdot> A\<star>) \<cdot> A" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
    99
    by (simp only: conc_assoc)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   100
  finally show "X = X \<cdot> A \<union> B" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   101
    using eq by blast 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   102
next
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   103
  assume eq: "X = X \<cdot> A \<union> B"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   104
  { fix n::nat
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   105
    have "B \<cdot> (A ^^ n) \<subseteq> X" using arden_helper[OF eq, of "n"] by auto }
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   106
  then have "B \<cdot> A\<star> \<subseteq> X" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   107
    unfolding conc_def star_def UNION_def by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   108
  moreover
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   109
  { fix s::"'a list"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   110
    obtain k where "k = length s" by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   111
    then have not_in: "s \<notin> X \<cdot> (A ^^ Suc k)" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   112
      using conc_pow_length[OF nemp] by blast
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   113
    assume "s \<in> X"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   114
    then have "s \<in> X \<cdot> (A ^^ Suc k) \<union> (\<Union>m\<in>{0..k}. B \<cdot> (A ^^ m))"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   115
      using arden_helper[OF eq, of "k"] by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   116
    then have "s \<in> (\<Union>m\<in>{0..k}. B \<cdot> (A ^^ m))" using not_in by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   117
    moreover
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   118
    have "(\<Union>m\<in>{0..k}. B \<cdot> (A ^^ m)) \<subseteq> (\<Union>n. B \<cdot> (A ^^ n))" by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   119
    ultimately 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   120
    have "s \<in> B \<cdot> A\<star>" 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   121
      unfolding conc_Un_distrib star_def by auto }
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   122
  then have "X \<subseteq> B \<cdot> A\<star>" by auto
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   123
  ultimately 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   124
  show "X = B \<cdot> A\<star>" by simp
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   125
qed
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   126
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   127
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   128
text {* Plus-combination for a set of regular expressions *}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   129
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   130
abbreviation
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   131
  Setalt  ("\<Uplus>_" [1000] 999) 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   132
where
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   133
  "\<Uplus>A \<equiv> folds Plus Zero A"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   134
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   135
text {* 
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   136
  For finite sets, @{term Setalt} is preserved under @{term lang}.
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   137
*}
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   138
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   139
lemma folds_alt_simp [simp]:
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   140
  fixes rs::"('a rexp) set"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   141
  assumes a: "finite rs"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   142
  shows "lang (\<Uplus>rs) = \<Union> (lang ` rs)"
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   143
unfolding folds_def
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   144
apply(rule set_eqI)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   145
apply(rule someI2_ex)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   146
apply(rule_tac finite_imp_fold_graph[OF a])
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   147
apply(erule fold_graph.induct)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   148
apply(auto)
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   149
done
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   150
5d724fe0e096 changes according to afp-submission
urbanc
parents:
diff changeset
   151
end