thys/Exercises.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 21 Aug 2018 14:14:19 +0100
changeset 291 25b7d6bfd294
parent 283 c4d821c6309d
child 318 43e070803c1c
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
     1
theory Exercises
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents: 260
diff changeset
     2
  imports Spec "~~/src/HOL/Library/Infinite_Set"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
260
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
     5
section {* Some Fun Facts *}
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
fun
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
     8
 zeroable :: "rexp \<Rightarrow> bool"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
where
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    10
  "zeroable (ZERO) \<longleftrightarrow> True"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    11
| "zeroable (ONE) \<longleftrightarrow> False"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    12
| "zeroable (CHAR c) \<longleftrightarrow> False"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    13
| "zeroable (ALT r1 r2) \<longleftrightarrow> zeroable r1 \<and> zeroable r2"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    14
| "zeroable (SEQ r1 r2) \<longleftrightarrow> zeroable r1 \<or> zeroable r2"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    15
| "zeroable (STAR r) \<longleftrightarrow> False"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
lemma zeroable_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    18
  shows "zeroable r \<longleftrightarrow> L r = {}"
260
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    19
by(induct r)(auto simp add: Sequ_def)
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    20
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
fun
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    23
 atmostempty :: "rexp \<Rightarrow> bool"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
where
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    25
  "atmostempty (ZERO) \<longleftrightarrow> True"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    26
| "atmostempty (ONE) \<longleftrightarrow> True"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    27
| "atmostempty (CHAR c) \<longleftrightarrow> False"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    28
| "atmostempty (ALT r1 r2) \<longleftrightarrow> atmostempty r1 \<and> atmostempty r2"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    29
| "atmostempty (SEQ r1 r2) \<longleftrightarrow> 
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    30
     zeroable r1 \<or> zeroable r2 \<or> (atmostempty r1 \<and> atmostempty r2)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
| "atmostempty (STAR r) = atmostempty r"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
283
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    33
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    34
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
fun
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    36
 somechars :: "rexp \<Rightarrow> bool"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
where
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    38
  "somechars (ZERO) \<longleftrightarrow> False"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    39
| "somechars (ONE) \<longleftrightarrow> False"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    40
| "somechars (CHAR c) \<longleftrightarrow> True"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    41
| "somechars (ALT r1 r2) \<longleftrightarrow> somechars r1 \<or> somechars r2"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    42
| "somechars (SEQ r1 r2) \<longleftrightarrow> 
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    43
      (\<not> zeroable r1 \<and> somechars r2) \<or> (\<not> zeroable r2 \<and> somechars r1) \<or> 
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    44
      (somechars r1 \<and> nullable r2) \<or> (somechars r2 \<and> nullable r1)"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    45
| "somechars (STAR r) \<longleftrightarrow> somechars r"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
lemma somechars_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    48
  shows "somechars r \<longleftrightarrow> (\<exists>s. s \<noteq> [] \<and> s \<in> L r)"
260
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    49
apply(induct r)
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    50
apply(simp_all add: zeroable_correctness nullable_correctness Sequ_def)
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    51
using Nil_is_append_conv apply blast
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    52
apply blast
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    53
apply(auto)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    54
using Star_cstring
283
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    55
  by (metis concat_eq_Nil_conv) 
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
lemma atmostempty_correctness_aux:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    58
  shows "atmostempty r \<longleftrightarrow> \<not> somechars r"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
apply(induct r)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
apply(auto simp add: zeroable_correctness nullable_correctness somechars_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
lemma atmostempty_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    65
  shows "atmostempty r \<longleftrightarrow> L r \<subseteq> {[]}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
by(auto simp add: atmostempty_correctness_aux somechars_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
fun
283
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    69
 leastsinglechar :: "rexp \<Rightarrow> bool"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    70
where
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    71
  "leastsinglechar (ZERO) \<longleftrightarrow> False"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    72
| "leastsinglechar (ONE) \<longleftrightarrow> False"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    73
| "leastsinglechar (CHAR c) \<longleftrightarrow> True"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    74
| "leastsinglechar (ALT r1 r2) \<longleftrightarrow> leastsinglechar r1 \<or> leastsinglechar r2"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    75
| "leastsinglechar (SEQ r1 r2) \<longleftrightarrow> 
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    76
      (if (zeroable r1 \<or> zeroable r2) then False
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    77
       else ((nullable r1 \<and> leastsinglechar r2) \<or> (nullable r2 \<and> leastsinglechar r1)))"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    78
| "leastsinglechar (STAR r) \<longleftrightarrow> leastsinglechar r"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    79
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    80
lemma leastsinglechar_correctness:
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    81
  "leastsinglechar r \<longleftrightarrow> (\<exists>c. [c] \<in> L r)"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    82
  apply(induct r)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    83
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    84
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    85
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    86
  prefer 2
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    87
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    88
  apply(blast)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    89
  prefer 2
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    90
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    91
  using Star.step Star_decomp apply fastforce
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    92
  apply(simp add: Sequ_def zeroable_correctness nullable_correctness)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    93
  by (metis append_Nil append_is_Nil_conv butlast_append butlast_snoc)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    94
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    95
fun
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    96
 infinitestrings :: "rexp \<Rightarrow> bool"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  "infinitestrings (ZERO) = False"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
| "infinitestrings (ONE) = False"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
| "infinitestrings (CHAR c) = False"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   101
| "infinitestrings (ALT r1 r2) = (infinitestrings r1 \<or> infinitestrings r2)"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   102
| "infinitestrings (SEQ r1 r2) \<longleftrightarrow> 
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   103
      (\<not> zeroable r1 \<and> infinitestrings r2) \<or> (\<not> zeroable r2 \<and> infinitestrings r1)"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   104
| "infinitestrings (STAR r) = (\<not> atmostempty r)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
282
bfab5aded21d updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   106
bfab5aded21d updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   107
bfab5aded21d updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   108
bfab5aded21d updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   109
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
lemma Star_atmostempty:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   111
  assumes "A \<subseteq> {[]}"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   112
  shows "A\<star> \<subseteq> {[]}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
using assms
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   114
using Star_cstring concat_eq_Nil_conv empty_iff insert_iff subsetI subset_singletonD by fastforce
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
lemma Star_empty_string_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   117
  shows "finite ({[]}\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
using Star_atmostempty infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
lemma Star_empty_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   121
  shows "finite ({}\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
using Star_atmostempty infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
lemma Star_concat_replicate:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   125
  assumes "s \<in> A"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   126
  shows "concat (replicate n s) \<in> A\<star>"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
using assms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
by (induct n) (auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
lemma concat_replicate_inj:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   132
  assumes "concat (replicate n s) = concat (replicate m s)" "s \<noteq> []"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  shows "n = m"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
using assms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
apply(induct n arbitrary: m)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
apply(case_tac m)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
apply(clarify)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
apply(simp only: replicate.simps concat.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
by simp
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
lemma A0:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   145
  assumes "finite (A ;; B)" "B \<noteq> {}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  shows "finite A"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   147
apply(subgoal_tac "\<exists>s. s \<in> B")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
apply(erule exE)
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   149
apply(subgoal_tac "finite {s1 @ s |s1. s1 \<in> A}")
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   150
apply(rule_tac f="\<lambda>s1. s1 @ s" in finite_imageD)
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
apply(simp add: image_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
apply(smt Collect_cong)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
apply(simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
apply(rule_tac B="A ;; B" in finite_subset)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
using assms(2) by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
lemma A1:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   160
  assumes "finite (A ;; B)" "A \<noteq> {}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  shows "finite B"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   162
apply(subgoal_tac "\<exists>s. s \<in> A")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
apply(erule exE)
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   164
apply(subgoal_tac "finite {s @ s1 |s1. s1 \<in> B}")
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   165
apply(rule_tac f="\<lambda>s1. s @ s1" in finite_imageD)
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
apply(simp add: image_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
apply(smt Collect_cong)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
apply(simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
apply(rule_tac B="A ;; B" in finite_subset)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
using assms(2) by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
lemma Sequ_Prod_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   175
  assumes "A \<noteq> {}" "B \<noteq> {}"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   176
  shows "finite (A ;; B) \<longleftrightarrow> (finite (A \<times> B))"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
apply(rule finite_cartesian_product)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
apply(erule A0)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
apply(rule assms(2))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
apply(erule A1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
apply(simp add: Sequ_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
apply(rule finite_image_set2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
apply(drule finite_cartesian_productD1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
apply(rule assms(2))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
apply(drule finite_cartesian_productD2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
lemma Star_non_empty_string_infinite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   195
  assumes "s \<in> A" " s \<noteq> []"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   196
  shows "infinite (A\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
proof -
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   198
  have "inj (\<lambda>n. concat (replicate n s))" 
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
  using assms(2) concat_replicate_inj
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
    by(auto simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
  moreover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
  have "infinite (UNIV::nat set)" by simp
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
  ultimately
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   204
  have "infinite ((\<lambda>n. concat (replicate n s)) ` UNIV)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
   by (simp add: range_inj_infinite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
  moreover
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   207
  have "((\<lambda>n. concat (replicate n s)) ` UNIV) \<subseteq> (A\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
    using Star_concat_replicate assms(1) by auto
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   209
  ultimately show "infinite (A\<star>)" 
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  using infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
qed
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
lemma infinitestrings_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   214
  shows "infinitestrings r \<longleftrightarrow> infinite (L r)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
apply(induct r)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
apply(simp add: zeroable_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
apply(erule disjE)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
apply(subst Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
using finite_cartesian_productD2 apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
apply(subst Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
using finite_cartesian_productD1 apply blast
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   226
apply(subgoal_tac "L r1 \<noteq> {} \<and> L r2 \<noteq> {}")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
prefer 2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
apply(subst (asm) Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
apply(simp add: atmostempty_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
apply (metis Star_empty_finite Star_empty_string_finite subset_singletonD)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
using Star_non_empty_string_infinite apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
260
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
   238
unused_thms
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
end