thys/Exercises.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 09 Feb 2022 11:21:28 +0000
changeset 425 14c558ae0b09
parent 362 e51c9a67a68d
child 641 cf7a5c863831
permissions -rw-r--r--
updated paper
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"
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 318
diff changeset
    12
| "zeroable (CH c) \<longleftrightarrow> False"
259
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"
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 318
diff changeset
    27
| "atmostempty (CH c) \<longleftrightarrow> False"
259
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"
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 318
diff changeset
    40
| "somechars (CH c) \<longleftrightarrow> True"
259
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
318
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
    53
  apply(auto)
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
    54
  by (metis Star_decomp hd_Cons_tl list.distinct(1))
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
lemma atmostempty_correctness_aux:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    57
  shows "atmostempty r \<longleftrightarrow> \<not> somechars r"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
apply(induct r)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
apply(auto simp add: zeroable_correctness nullable_correctness somechars_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
lemma atmostempty_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    64
  shows "atmostempty r \<longleftrightarrow> L r \<subseteq> {[]}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
by(auto simp add: atmostempty_correctness_aux somechars_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
fun
283
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    68
 leastsinglechar :: "rexp \<Rightarrow> bool"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    69
where
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    70
  "leastsinglechar (ZERO) \<longleftrightarrow> False"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    71
| "leastsinglechar (ONE) \<longleftrightarrow> False"
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 318
diff changeset
    72
| "leastsinglechar (CH c) \<longleftrightarrow> True"
283
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    73
| "leastsinglechar (ALT r1 r2) \<longleftrightarrow> leastsinglechar r1 \<or> leastsinglechar r2"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    74
| "leastsinglechar (SEQ r1 r2) \<longleftrightarrow> 
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    75
      (if (zeroable r1 \<or> zeroable r2) then False
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    76
       else ((nullable r1 \<and> leastsinglechar r2) \<or> (nullable r2 \<and> leastsinglechar r1)))"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    77
| "leastsinglechar (STAR r) \<longleftrightarrow> leastsinglechar r"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    78
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    79
lemma leastsinglechar_correctness:
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    80
  "leastsinglechar r \<longleftrightarrow> (\<exists>c. [c] \<in> L r)"
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    81
  apply(induct r)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    82
  apply(simp)
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
  prefer 2
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    86
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    87
  apply(blast)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    88
  prefer 2
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    89
  apply(simp)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    90
  using Star.step Star_decomp apply fastforce
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    91
  apply(simp add: Sequ_def zeroable_correctness nullable_correctness)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    92
  by (metis append_Nil append_is_Nil_conv butlast_append butlast_snoc)
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    93
c4d821c6309d updated
Christian Urban <urbanc@in.tum.de>
parents: 282
diff changeset
    94
fun
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
    95
 infinitestrings :: "rexp \<Rightarrow> bool"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  "infinitestrings (ZERO) = False"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
| "infinitestrings (ONE) = False"
362
e51c9a67a68d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 318
diff changeset
    99
| "infinitestrings (CH c) = False"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   100
| "infinitestrings (ALT r1 r2) = (infinitestrings r1 \<or> infinitestrings r2)"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   101
| "infinitestrings (SEQ r1 r2) \<longleftrightarrow> 
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   102
      (\<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
   103
| "infinitestrings (STAR r) = (\<not> atmostempty r)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
282
bfab5aded21d updated
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   105
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
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
lemma Star_atmostempty:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   110
  assumes "A \<subseteq> {[]}"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   111
  shows "A\<star> \<subseteq> {[]}"
318
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   112
  using assms
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   113
  using Star_decomp concat_eq_Nil_conv empty_iff insert_iff subsetI subset_singletonD 
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   114
  apply(auto)
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   115
proof -
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   116
  fix x :: "char list"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   117
  assume a1: "x \<in> A\<star>"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   118
  assume "\<And>c x A. c # x \<in> A\<star> \<Longrightarrow> \<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   119
  then have f2: "\<forall>cs C c. \<exists>csa. c # csa \<in> C \<or> c # cs \<notin> C\<star>"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   120
    by auto
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   121
  obtain cc :: "char list \<Rightarrow> char" and ccs :: "char list \<Rightarrow> char list" where
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   122
    "\<And>cs. cs = [] \<or> cc cs # ccs cs = cs"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   123
    by (metis (no_types) list.exhaust)
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   124
  then show "x = []"
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   125
    using f2 a1 by (metis assms empty_iff insert_iff list.distinct(1) subset_singletonD)
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   126
qed
43e070803c1c updated
Christian Urban <urbanc@in.tum.de>
parents: 283
diff changeset
   127
  
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
lemma Star_empty_string_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   130
  shows "finite ({[]}\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
using Star_atmostempty infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
lemma Star_empty_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   134
  shows "finite ({}\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
using Star_atmostempty infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
lemma Star_concat_replicate:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   138
  assumes "s \<in> A"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   139
  shows "concat (replicate n s) \<in> A\<star>"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
using assms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
by (induct n) (auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
lemma concat_replicate_inj:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   145
  assumes "concat (replicate n s) = concat (replicate m s)" "s \<noteq> []"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  shows "n = m"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
using assms
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
apply(induct n arbitrary: m)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
apply(case_tac m)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
apply(clarify)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
apply(simp only: replicate.simps concat.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
by simp
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
lemma A0:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   158
  assumes "finite (A ;; B)" "B \<noteq> {}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
  shows "finite A"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   160
apply(subgoal_tac "\<exists>s. s \<in> B")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
apply(erule exE)
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   162
apply(subgoal_tac "finite {s1 @ s |s1. s1 \<in> A}")
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   163
apply(rule_tac f="\<lambda>s1. s1 @ s" in finite_imageD)
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
apply(simp add: image_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
apply(smt Collect_cong)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
apply(simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
apply(rule_tac B="A ;; B" in finite_subset)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
using assms(2) by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
lemma A1:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   173
  assumes "finite (A ;; B)" "A \<noteq> {}"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
  shows "finite B"
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   175
apply(subgoal_tac "\<exists>s. s \<in> A")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
apply(erule exE)
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   177
apply(subgoal_tac "finite {s @ s1 |s1. s1 \<in> B}")
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   178
apply(rule_tac f="\<lambda>s1. s @ s1" in finite_imageD)
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
apply(simp add: image_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
apply(smt Collect_cong)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
apply(simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
apply(rule_tac B="A ;; B" in finite_subset)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
using assms(2) by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
lemma Sequ_Prod_finite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   188
  assumes "A \<noteq> {}" "B \<noteq> {}"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   189
  shows "finite (A ;; B) \<longleftrightarrow> (finite (A \<times> B))"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
apply(rule finite_cartesian_product)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
apply(erule A0)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
apply(rule assms(2))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
apply(erule A1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
apply(simp add: Sequ_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
apply(rule finite_image_set2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
apply(drule finite_cartesian_productD1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
apply(rule assms(2))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
apply(drule finite_cartesian_productD2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
apply(rule assms(1))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
lemma Star_non_empty_string_infinite:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   208
  assumes "s \<in> A" " s \<noteq> []"
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   209
  shows "infinite (A\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
proof -
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   211
  have "inj (\<lambda>n. concat (replicate n s))" 
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  using assms(2) concat_replicate_inj
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
    by(auto simp add: inj_on_def)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  moreover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
  have "infinite (UNIV::nat set)" by simp
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  ultimately
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   217
  have "infinite ((\<lambda>n. concat (replicate n s)) ` UNIV)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
   by (simp add: range_inj_infinite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  moreover
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   220
  have "((\<lambda>n. concat (replicate n s)) ` UNIV) \<subseteq> (A\<star>)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
    using Star_concat_replicate assms(1) by auto
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   222
  ultimately show "infinite (A\<star>)" 
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  using infinite_super by auto
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
qed
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
lemma infinitestrings_correctness:
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   227
  shows "infinitestrings r \<longleftrightarrow> infinite (L r)"
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
apply(induct r)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
apply(simp add: zeroable_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
apply(erule disjE)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
apply(subst Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
using finite_cartesian_productD2 apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
apply(subst Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
using finite_cartesian_productD1 apply blast
259
78dd6bca5627 updated
Christian Urban <urbanc@in.tum.de>
parents: 258
diff changeset
   239
apply(subgoal_tac "L r1 \<noteq> {} \<and> L r2 \<noteq> {}")
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
prefer 2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
apply(auto simp add: Sequ_def)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
apply(subst (asm) Sequ_Prod_finite)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
apply(auto)[2]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
apply(simp add: atmostempty_correctness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
apply(rule iffI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
apply (metis Star_empty_finite Star_empty_string_finite subset_singletonD)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
using Star_non_empty_string_infinite apply blast
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
260
160d0b08471c updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
   251
unused_thms
258
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
end