thys2/GeneralRegexBound.thy
author Chengsong
Thu, 29 Sep 2022 14:05:42 +0100
changeset 606 99b530103464
parent 451 7a016eeb118d
permissions -rw-r--r--
new
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     1
theory GeneralRegexBound imports 
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
     2
"BasicIdentities" 
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     3
begin
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     4
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     5
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     6
lemma non_zero_size:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     7
  shows "rsize r \<ge> Suc 0"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     8
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     9
  apply auto done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    10
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    11
corollary size_geq1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    12
  shows "rsize r \<ge> 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    13
  by (simp add: non_zero_size)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    14
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    15
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    16
definition SEQ_set where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    17
  "SEQ_set A n \<equiv> {RSEQ r1 r2 | r1 r2. r1 \<in> A \<and> r2 \<in> A \<and> rsize r1 + rsize r2 \<le> n}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    18
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    19
definition SEQ_set_cartesian where
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    20
"SEQ_set_cartesian A  = {RSEQ r1 r2 | r1 r2. r1 \<in> A \<and> r2 \<in> A}"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    21
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    22
definition ALT_set where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    23
"ALT_set A n \<equiv> {RALTS rs | rs. set rs \<subseteq> A \<and> sum_list (map rsize rs) \<le> n}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    24
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    25
definition ALTs_set
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    26
  where
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    27
  "ALTs_set A n \<equiv> {RALTS rs | rs. \<forall>r \<in> set rs. r \<in> A \<and> sum_list (map rsize rs) \<le> n}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    28
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    29
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    30
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    31
lemma alts_set_2defs:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    32
  shows "ALT_set A n = ALTs_set A n"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    33
  apply(subgoal_tac "ALT_set A n \<subseteq> ALTs_set A n")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    34
   apply(subgoal_tac "ALTs_set A n \<subseteq> ALT_set A n")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    35
    apply auto[1]
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    36
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    37
  using ALT_set_def ALTs_set_def apply fastforce
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    38
  apply(subgoal_tac "\<forall>r \<in> ALTs_set A n. r \<in> ALT_set A n")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    39
   apply blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    40
  apply(rule ballI)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    41
  apply(subgoal_tac "\<exists>rs. r = RALTS rs \<and> sum_list (map rsize rs) \<le> n")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    42
   prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    43
  using ALTs_set_def apply fastforce
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    44
  apply(erule exE)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    45
  apply(subgoal_tac "set rs \<subseteq> A")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    46
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    47
  apply (simp add: ALTs_set_def subsetI)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    48
  using ALT_set_def by blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    49
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    50
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    51
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    52
definition
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    53
  "sizeNregex N \<equiv> {r. rsize r \<le> N}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    54
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    55
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    56
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    57
lemma sizenregex_induct1:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    58
  "sizeNregex (Suc n) = (({RZERO, RONE} \<union> {RCHAR c| c. True}) 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    59
                       \<union> (RSTAR ` sizeNregex n) \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    60
                         (SEQ_set (sizeNregex n) n)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    61
                       \<union>  (ALTs_set (sizeNregex n) n))"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    62
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    63
        apply(case_tac x)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    64
             apply(auto simp add: SEQ_set_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    65
  using sizeNregex_def apply force
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    66
  using sizeNregex_def apply auto[1]
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    67
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    68
         apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    69
         apply (simp add: ALTs_set_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    70
  apply (metis imageI list.set_map member_le_sum_list order_trans)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    71
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    72
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    73
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    74
  using sizeNregex_def apply force
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    75
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    76
  apply (simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    77
  apply (simp add: ALTs_set_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    78
  apply(simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    79
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    80
  using ex_in_conv by fastforce
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    81
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    82
lemma sizeN_inclusion:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    83
  shows "sizeNregex n   \<subseteq> sizeNregex (Suc n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    84
  by (simp add: Collect_mono sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    85
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    86
lemma ralts_nil_in_altset:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    87
  shows " RALTS [] \<in> ALT_set (sizeNregex n) n "
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    88
  using ALT_set_def by auto
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    89
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    90
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    91
lemma sizenregex_induct:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    92
  shows "sizeNregex (Suc n) = sizeNregex n \<union> {RZERO, RONE, RALTS []} \<union> {RCHAR c| c. True} \<union>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    93
SEQ_set ( sizeNregex n) n \<union> ALT_set (sizeNregex n) n \<union> (RSTAR ` (sizeNregex n))"
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    94
  apply(subgoal_tac "sizeNregex (Suc n) =  {RZERO, RONE, RALTS []} \<union> {RCHAR c| c. True} \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    95
SEQ_set ( sizeNregex n) n \<union> ALT_set (sizeNregex n) n \<union> (RSTAR ` (sizeNregex n))")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    96
  using sizeN_inclusion apply blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    97
  apply(subgoal_tac " {RZERO, RONE, RALTS []} \<union> {RCHAR c |c. True} \<union> SEQ_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    98
    ALT_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
    99
    RSTAR ` sizeNregex n =  (({RZERO, RONE} \<union> {RCHAR c| c. True}) 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   100
                       \<union> (RSTAR ` sizeNregex n) \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   101
                         (SEQ_set (sizeNregex n) n)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   102
                       \<union>  (ALTs_set (sizeNregex n) n))")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   103
  using sizenregex_induct1 apply presburger
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   104
  apply(subgoal_tac "{RZERO, RONE} \<union> {RCHAR c |c. True} \<union> SEQ_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   105
    ALT_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   106
    RSTAR ` sizeNregex n =
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   107
    {RZERO, RONE} \<union> {RCHAR c |c. True} \<union> RSTAR ` sizeNregex n \<union> SEQ_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   108
    ALTs_set (sizeNregex n) n ")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   109
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   110
  using alts_set_2defs apply auto[1]
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   111
  apply(subgoal_tac " {RZERO, RONE, RALTS []} \<union> {RCHAR c |c. True} \<union> SEQ_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   112
    ALT_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   113
    RSTAR ` sizeNregex n = 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   114
 {RZERO, RONE} \<union> {RCHAR c |c. True} \<union> SEQ_set (sizeNregex n) n \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   115
    (insert (RALTS []) (ALT_set (sizeNregex n) n)) \<union>
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   116
    RSTAR ` sizeNregex n")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   117
  prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   118
  apply fastforce
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   119
  by (simp add: insert_absorb ralts_nil_in_altset)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   120
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   121
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   122
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   123
lemma s4:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   124
  "SEQ_set A n \<subseteq> SEQ_set_cartesian A"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   125
  using SEQ_set_cartesian_def SEQ_set_def by fastforce
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   126
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   127
lemma s5:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   128
  "finite A \<Longrightarrow> finite (SEQ_set_cartesian A)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   129
  apply(subgoal_tac "SEQ_set_cartesian A = (\<lambda>(x1, x2). RSEQ x1 x2) ` (A \<times> A)")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   130
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   131
  unfolding SEQ_set_cartesian_def
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   132
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   133
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   134
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   135
thm size_list_def
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   136
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   137
definition ALTs_set_length
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   138
  where
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   139
  "ALTs_set_length A n l \<equiv> {RALTS rs | rs. \<forall>r \<in> set rs. r \<in> A 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   140
                                      \<and> sum_list (map rsize rs) \<le> n 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   141
                                      \<and> length rs \<le> l}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   142
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   143
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   144
definition ALTs_set_length2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   145
  where
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   146
  "ALTs_set_length2 A l \<equiv> {RALTS rs | rs. \<forall>r \<in> set rs. r \<in> A \<and> length rs \<le> l}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   147
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   148
definition set_length2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   149
  where
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   150
  "set_length2 A l \<equiv> {rs. \<forall>r \<in> set rs. r \<in> A \<and> length rs \<le> l}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   151
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   152
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   153
lemma r000: 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   154
  shows "ALTs_set_length A n l \<subseteq> ALTs_set_length2 A l"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   155
  apply(auto simp add: ALTs_set_length2_def ALTs_set_length_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   156
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   157
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   158
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   159
lemma r02: 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   160
  shows "set_length2 A 0 \<subseteq> {[]}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   161
  apply(auto simp add: set_length2_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   162
  apply(case_tac x)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   163
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   164
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   165
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   166
lemma r03:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   167
  shows "set_length2 A (Suc n) \<subseteq> 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   168
          {[]} \<union> (\<lambda>(h, t). h # t) ` (A \<times> (set_length2 A n))"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   169
  apply(auto simp add: set_length2_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   170
  apply(case_tac x)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   171
   apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   172
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   173
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   174
lemma r1:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   175
  assumes "finite A" 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   176
  shows "finite (set_length2 A n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   177
  using assms
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   178
  apply(induct n)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   179
  apply(rule finite_subset)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   180
    apply(rule r02)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   181
   apply(simp)    
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   182
  apply(rule finite_subset)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   183
   apply(rule r03)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   184
  apply(simp)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   185
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   186
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   187
lemma size_sum_more_than_len:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   188
  shows "sum_list (map rsize rs) \<ge> length rs"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   189
  apply(induct rs)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   190
   apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   191
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   192
  apply(subgoal_tac "rsize a \<ge> 1")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   193
   apply linarith
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   194
  using size_geq1 by auto
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   195
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   196
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   197
lemma sum_list_len:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   198
  shows " sum_list (map rsize rs) \<le> n \<Longrightarrow> length rs \<le> n"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   199
  by (meson order.trans size_sum_more_than_len)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   200
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   201
  
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   202
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   203
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   204
lemma t2:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   205
  shows "ALTs_set A n \<subseteq> ALTs_set_length A n n"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   206
  unfolding ALTs_set_length_def ALTs_set_def
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   207
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   208
  using sum_list_len by blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   209
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   210
  
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   211
thm ALTs_set_def
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   212
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   213
lemma s8_aux:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   214
  assumes "finite A" 
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   215
  shows "finite (ALTs_set_length A n n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   216
proof -
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   217
  have "finite A" by fact
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   218
  then have "finite (set_length2 A n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   219
    by (simp add: r1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   220
  moreover have "(RALTS ` (set_length2 A n)) = ALTs_set_length2 A n"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   221
    unfolding ALTs_set_length2_def set_length2_def
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   222
    by (auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   223
  ultimately have "finite (ALTs_set_length2 A n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   224
    by (metis finite_imageI)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   225
  then show ?thesis
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   226
    by (metis infinite_super r000)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   227
qed
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   228
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   229
lemma s1:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   230
  shows "{r::rrexp . rsize r = 1} = ({RZERO, RONE, RALTS []} \<union> {RCHAR c| c. True})"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   231
  apply(auto)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   232
  apply(case_tac x)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   233
  apply(simp_all)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   234
    apply (metis One_nat_def Suc_n_not_le_n size_geq1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   235
  apply (metis One_nat_def Suc_n_not_le_n ex_in_conv set_empty2 size_geq1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   236
  by (metis not_one_le_zero size_geq1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   237
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   238
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   239
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   240
lemma char_finite:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   241
  shows "finite  {RCHAR c |c. True}"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   242
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   243
  apply(subgoal_tac "finite (RCHAR ` (UNIV::char set))")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   244
   prefer 2
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   245
   apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   246
  by (simp add: full_SetCompr_eq)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   247
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   248
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   249
lemma finite_size_n:
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   250
  shows
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   251
  "finite (sizeNregex n)"
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   252
  apply(induct n)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   253
   apply(simp add: sizeNregex_def)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   254
  apply (metis (mono_tags, lifting) not_finite_existsD not_one_le_zero size_geq1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   255
  apply(subst sizenregex_induct1)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   256
  apply(simp only: finite_Un)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   257
  apply(rule conjI)+
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   258
      apply(simp)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   259
  using char_finite apply blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   260
    apply(simp)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   261
   apply(rule finite_subset)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   262
    apply(rule s4)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   263
   apply(rule s5)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   264
   apply(simp)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   265
  apply(rule finite_subset)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   266
   apply(rule t2)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   267
  apply(rule s8_aux)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   268
  apply(simp)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   269
  done
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   270
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   271
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   272
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   273
lemma chars_finite:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
  shows "finite (RCHAR ` (UNIV::(char set)))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
  apply(simp)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
thm full_SetCompr_eq 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   280
lemma size1finite:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   281
  shows "finite (sizeNregex (Suc 0))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   282
  apply(subst sizenregex_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   283
  apply(subst finite_Un)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   284
  apply(subgoal_tac "sizeNregex 0 = {}")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   285
  apply(rule conjI)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   286
  apply (metis Collect_empty_eq finite.emptyI non_zero_size not_less_eq_eq sizeNregex_def)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   287
      apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   288
      apply (simp add: full_SetCompr_eq)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   289
  apply (simp add: SEQ_set_def)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   290
    apply (simp add: ALT_set_def)  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   291
   apply(simp add: full_SetCompr_eq)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   292
  using non_zero_size not_less_eq_eq sizeNregex_def by fastforce
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   293
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   294
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   295
lemma three_easy_cases0: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   296
"rsize (rders_simp RZERO s) \<le> Suc 0"
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   297
  apply(induct s)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   298
   apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   299
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   300
  done
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   301
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   302
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   303
lemma three_easy_cases1: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   304
"rsize (rders_simp RONE s) \<le> Suc 0"
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   305
    apply(induct s)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   306
   apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   307
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   308
  using three_easy_cases0 by auto
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   309
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   310
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   311
lemma three_easy_casesC: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   312
"rsize (rders_simp (RCHAR c) s) \<le> Suc 0"
451
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   313
  apply(induct s)
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   314
   apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   315
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   316
  apply(case_tac " a = c")
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   317
  using three_easy_cases1 apply blast
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   318
  apply simp
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   319
  using three_easy_cases0 by force
7a016eeb118d finiteness
Chengsong
parents: 444
diff changeset
   320
  
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   323
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   324
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   325
end
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   326