thys2/ClosedFormsBounds.thy
author Chengsong
Sat, 12 Mar 2022 14:04:57 +0000
changeset 449 09d7cd8e5ef8
parent 448 3bc0f0069d06
child 450 dabd25e8e4e9
permissions -rw-r--r--
more
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     1
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     2
theory ClosedFormsBounds
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     3
  imports "GeneralRegexBound" "ClosedForms"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     4
begin
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     5
449
Chengsong
parents: 448
diff changeset
     6
lemma alts_ders_lambda_shape_ders:
Chengsong
parents: 448
diff changeset
     7
  shows "\<forall>r \<in> set (map (\<lambda>r. rders_simp r ( s)) rs ). \<exists>r1 \<in> set rs. r = rders_simp r1 s"
Chengsong
parents: 448
diff changeset
     8
  by (simp add: image_iff)
Chengsong
parents: 448
diff changeset
     9
Chengsong
parents: 448
diff changeset
    10
Chengsong
parents: 448
diff changeset
    11
Chengsong
parents: 448
diff changeset
    12
lemma rlist_bound:
Chengsong
parents: 448
diff changeset
    13
  shows "\<forall>r \<in> set rs. rsize r \<le> N \<Longrightarrow> sum_list (map rsize rs) \<le> N * (length rs)"
Chengsong
parents: 448
diff changeset
    14
  apply(induct rs)
Chengsong
parents: 448
diff changeset
    15
  apply simp
Chengsong
parents: 448
diff changeset
    16
  by simp
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    17
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    18
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    19
lemma alts_closed_form_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    20
"\<forall>r \<in> set rs. \<forall>s. rsize(rders_simp r s ) \<le> N \<Longrightarrow> 
449
Chengsong
parents: 448
diff changeset
    21
rsize (rders_simp (RALTS rs ) s) \<le> max (Suc ( N * (length rs))) (rsize (RALTS rs) )"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    22
  apply(induct s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    23
  apply simp
449
Chengsong
parents: 448
diff changeset
    24
  apply(subst alts_closed_form_variant)
Chengsong
parents: 448
diff changeset
    25
   apply force
Chengsong
parents: 448
diff changeset
    26
  apply(subgoal_tac "rsize (rsimp (RALTS (map (\<lambda>r. rders_simp r (a # s)) rs))) \<le> rsize ( (RALTS (map (\<lambda>r. rders_simp r (a # s)) rs)))")
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    27
   prefer 2
449
Chengsong
parents: 448
diff changeset
    28
  using rsimp_mono apply presburger
Chengsong
parents: 448
diff changeset
    29
  apply(subgoal_tac "rsize (RALTS (map (\<lambda>r. rders_simp r (a # s)) rs)) =
Chengsong
parents: 448
diff changeset
    30
                     Suc (sum_list  (map rsize (map (\<lambda>r. rders_simp r (a # s)) rs)))")
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    31
  prefer 2
449
Chengsong
parents: 448
diff changeset
    32
  using rsize.simps(4) apply blast
Chengsong
parents: 448
diff changeset
    33
  apply(subgoal_tac "sum_list (map rsize (map (\<lambda>r. rders_simp r (a # s)) rs )) \<le> N *  (length rs) ")
Chengsong
parents: 448
diff changeset
    34
   apply linarith
Chengsong
parents: 448
diff changeset
    35
  apply(subgoal_tac "\<forall>r \<in> set (map (\<lambda>r. rders_simp r (a # s)) rs ). rsize r \<le> N")
Chengsong
parents: 448
diff changeset
    36
  prefer 2
Chengsong
parents: 448
diff changeset
    37
  apply(subgoal_tac "\<forall>r \<in> set (map (\<lambda>r. rders_simp r (a # s)) rs ). \<exists>r1 \<in> set rs. r = rders_simp r1 (a # s)")
Chengsong
parents: 448
diff changeset
    38
  prefer 2
Chengsong
parents: 448
diff changeset
    39
  using alts_ders_lambda_shape_ders apply presburger
Chengsong
parents: 448
diff changeset
    40
   apply metis
Chengsong
parents: 448
diff changeset
    41
  apply(frule rlist_bound)
Chengsong
parents: 448
diff changeset
    42
  by fastforce
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    43
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    44
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    45
lemma alts_simp_ineq_unfold:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    46
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    47
  using rsimp_aalts_smaller by auto
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    48
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    49
lemma flts_has_no_zero:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    50
  shows "rdistinct (rflts rs) rset = rdistinct (rflts rs) (insert RZERO rset)"
449
Chengsong
parents: 448
diff changeset
    51
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    52
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    53
449
Chengsong
parents: 448
diff changeset
    54
lemma not_mentioned_elem_distinct:
Chengsong
parents: 448
diff changeset
    55
  shows "r \<noteq> a \<Longrightarrow> (r \<in> set (rdistinct rs {})) = (r \<in> set (rdistinct rs {a}))"
Chengsong
parents: 448
diff changeset
    56
  sorry
Chengsong
parents: 448
diff changeset
    57
Chengsong
parents: 448
diff changeset
    58
Chengsong
parents: 448
diff changeset
    59
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    60
lemma flts_vs_nflts:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    61
  shows "\<forall>r \<in> noalts_set. \<forall>xs. r \<noteq> RALTS xs
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    62
 \<and> (\<forall>a \<in> alts_set. \<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set)  
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    63
\<Longrightarrow> Suc (sum_list (map rsize (rdistinct ( rflts rs) (noalts_set \<union> corr_set)  )))
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    64
         \<le> Suc (sum_list (map rsize (rdistinct rs (noalts_set \<union> alts_set) )))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    65
  apply(induct rs arbitrary: noalts_set)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    66
   apply simp
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    67
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    68
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    69
449
Chengsong
parents: 448
diff changeset
    70
lemma distinct_simp_ineq_general:
Chengsong
parents: 448
diff changeset
    71
  shows "rsimp ` no_simp = has_simp \<Longrightarrow>Suc (sum_list (map rsize (rdistinct (map rsimp rs) has_simp)))
Chengsong
parents: 448
diff changeset
    72
    \<le> Suc (sum_list (map rsize (rdistinct rs no_simp)))"
Chengsong
parents: 448
diff changeset
    73
Chengsong
parents: 448
diff changeset
    74
  sorry
Chengsong
parents: 448
diff changeset
    75
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    76
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    77
lemma without_flts_ineq:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    78
  shows " Suc (sum_list (map rsize (rdistinct (rflts rs) {}) )) \<le> 
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    79
         Suc (sum_list (map rsize (rdistinct (    rs  ) {}  )))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    80
  by (metis empty_iff flts_vs_nflts sup_bot_left)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    81
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    82
448
Chengsong
parents: 447
diff changeset
    83
Chengsong
parents: 447
diff changeset
    84
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    85
lemma distinct_simp_ineq:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    86
  shows "Suc (sum_list (map rsize (rdistinct (map rsimp rs) {})))
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    87
    \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
448
Chengsong
parents: 447
diff changeset
    88
  
Chengsong
parents: 447
diff changeset
    89
  using distinct_simp_ineq_general by blast
Chengsong
parents: 447
diff changeset
    90
  
Chengsong
parents: 447
diff changeset
    91
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    92
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    93
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    94
lemma alts_simp_control:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    95
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    96
proof -
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    97
  have "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    98
    
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    99
    using alts_simp_ineq_unfold by auto
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   100
  then have "\<dots> \<le> Suc (sum_list (map rsize (rdistinct (map rsimp rs) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   101
    using without_flts_ineq by blast
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   102
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   103
  show "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   104
    by (meson \<open>Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {}))) \<le> Suc (sum_list (map rsize (rdistinct (map rsimp rs) {})))\<close> \<open>rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))\<close> distinct_simp_ineq order_trans)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   105
qed
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   106
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   107
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   108
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   109
lemma rdistinct_equality1:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   110
  shows "a \<notin> ss \<Longrightarrow> rdistinct (a  # rs) ss = a # rdistinct rs (insert a ss) "
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   111
  by auto
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   112
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   113
lemma larger_acc_smaller_distinct_res0:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   114
  shows " ss \<subseteq> SS \<Longrightarrow> sum_list (map rsize (rdistinct rs SS)) \<le> sum_list (map rsize (rdistinct rs ss))"
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   115
  apply(induct rs arbitrary: ss SS)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   116
  apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   117
  apply(case_tac "a \<in> ss")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   118
   apply(subgoal_tac "a \<in> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   119
    apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   120
   apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   121
  apply(case_tac "a \<in> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   122
   apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   123
   apply(subgoal_tac "insert a ss \<subseteq> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   124
    apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   125
  apply (simp add: trans_le_add2)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   126
  apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   127
  apply(simp)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   128
  apply(subgoal_tac "insert a ss \<subseteq> insert a SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   129
   apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   130
  by blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   131
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   132
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   133
lemma larger_acc_smaller_distinct_res:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   134
  shows " (sum_list (map rsize (rdistinct rs ss))) \<ge> (sum_list (map rsize (rdistinct rs (insert a ss))))"
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   135
  apply(subgoal_tac "ss \<subseteq> (insert a ss)")
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   136
   apply(rule larger_acc_smaller_distinct_res0)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   137
   apply simp
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   138
  by (simp add: subset_insertI)
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   139
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   140
lemma size_list_triangle1:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   141
  shows  "sum_list (map rsize (a # (rdistinct as ss))) \<ge> rsize a + sum_list (map rsize (rdistinct as (insert a ss)))"
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   142
  by (simp add: larger_acc_smaller_distinct_res)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   143
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   144
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   145
lemma triangle_inequality_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   146
  shows "sum_list (map rsize (rdistinct (a # rs) ss)) \<le> rsize a + (sum_list (map rsize (rdistinct rs ss)))"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   147
  apply(case_tac "a \<in> ss")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   148
   apply simp
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   149
  apply(subst rdistinct_equality1)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   150
   apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   151
  using size_list_triangle1 by auto
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   152
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   153
lemma same_regex_property_after_map:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   154
  shows "\<forall>s. P (f r2 s) \<Longrightarrow> \<forall>r \<in> set  (map (f r2) Ss). P r"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   155
  by auto
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   156
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   157
lemma same_property_after_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   158
  shows " \<forall>r \<in> set  (map (f r2) Ss). P r \<Longrightarrow> \<forall>r \<in> set (rdistinct (map (f r2) Ss) xset). P r"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   159
  apply(induct Ss arbitrary: xset)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   160
   apply simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   161
  by auto
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   162
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   163
lemma same_regex_property_after_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   164
  shows "\<forall>s. P (f r2 s) \<Longrightarrow> \<forall>r \<in> set (rdistinct (map (f r2) Ss) xset). P r"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   165
  apply(rule same_property_after_distinct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   166
  apply(rule same_regex_property_after_map)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   167
  by simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   168
449
Chengsong
parents: 448
diff changeset
   169
Chengsong
parents: 448
diff changeset
   170
Chengsong
parents: 448
diff changeset
   171
lemma Sum_cons:
Chengsong
parents: 448
diff changeset
   172
  shows "distinct (a # as) \<Longrightarrow> \<Sum> (set ((a::nat) # as)) =  a + \<Sum> (set  as)"
Chengsong
parents: 448
diff changeset
   173
  by simp
Chengsong
parents: 448
diff changeset
   174
Chengsong
parents: 448
diff changeset
   175
Chengsong
parents: 448
diff changeset
   176
lemma distinct_list_sizeNregex_bounded:
Chengsong
parents: 448
diff changeset
   177
  shows "distinct rs \<and> (\<forall> r \<in> (set rs). rsize r \<le> N) \<Longrightarrow> sum_list (map rsize rs) \<le> N * length rs"
Chengsong
parents: 448
diff changeset
   178
  apply(induct rs)
Chengsong
parents: 448
diff changeset
   179
   apply simp
Chengsong
parents: 448
diff changeset
   180
  by simp
Chengsong
parents: 448
diff changeset
   181
Chengsong
parents: 448
diff changeset
   182
Chengsong
parents: 448
diff changeset
   183
lemma distinct_list_size_len_bounded:
Chengsong
parents: 448
diff changeset
   184
  shows "distinct rs \<and> (\<forall>r \<in> set rs. rsize r \<le> N) \<and> length rs \<le> lrs \<Longrightarrow> sum_list (map rsize rs) \<le> lrs * N "
Chengsong
parents: 448
diff changeset
   185
  by (metis distinct_list_sizeNregex_bounded dual_order.trans mult.commute mult_le_mono1)
Chengsong
parents: 448
diff changeset
   186
Chengsong
parents: 448
diff changeset
   187
Chengsong
parents: 448
diff changeset
   188
Chengsong
parents: 448
diff changeset
   189
lemma rdistinct_same_set:
Chengsong
parents: 448
diff changeset
   190
  shows "(r \<in> set rs) =  (r \<in> set (rdistinct rs {}))"
Chengsong
parents: 448
diff changeset
   191
  apply(induct rs)
Chengsong
parents: 448
diff changeset
   192
   apply simp
Chengsong
parents: 448
diff changeset
   193
  apply(case_tac "a \<in> set rs")
Chengsong
parents: 448
diff changeset
   194
  apply(case_tac "r = a")
Chengsong
parents: 448
diff changeset
   195
    apply (simp)
Chengsong
parents: 448
diff changeset
   196
  apply (simp add: not_mentioned_elem_distinct)
Chengsong
parents: 448
diff changeset
   197
  using not_mentioned_elem_distinct by fastforce
Chengsong
parents: 448
diff changeset
   198
Chengsong
parents: 448
diff changeset
   199
Chengsong
parents: 448
diff changeset
   200
Chengsong
parents: 448
diff changeset
   201
lemma distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size:
Chengsong
parents: 448
diff changeset
   202
  shows "\<forall>r\<in> set rs. (rsize r ) \<le> N \<Longrightarrow> sum_list (map rsize (rdistinct rs {})) \<le>
Chengsong
parents: 448
diff changeset
   203
         (card (sizeNregex N))* N"
Chengsong
parents: 448
diff changeset
   204
  apply(subgoal_tac "distinct (rdistinct rs {})")
Chengsong
parents: 448
diff changeset
   205
  prefer 2
Chengsong
parents: 448
diff changeset
   206
  using rdistinct_does_the_job apply blast
Chengsong
parents: 448
diff changeset
   207
  apply(subgoal_tac "length (rdistinct rs {}) \<le> card (sizeNregex N)")
Chengsong
parents: 448
diff changeset
   208
  apply(rule distinct_list_size_len_bounded)
Chengsong
parents: 448
diff changeset
   209
   apply(rule conjI)+
Chengsong
parents: 448
diff changeset
   210
    apply simp
Chengsong
parents: 448
diff changeset
   211
   apply(rule conjI)
Chengsong
parents: 448
diff changeset
   212
  apply (meson rdistinct_same_set)
Chengsong
parents: 448
diff changeset
   213
   apply blast
Chengsong
parents: 448
diff changeset
   214
  apply(subgoal_tac "\<forall>r \<in> set (rdistinct rs {}). rsize r \<le> N")
Chengsong
parents: 448
diff changeset
   215
  prefer 2
Chengsong
parents: 448
diff changeset
   216
   apply (meson rdistinct_same_set)
Chengsong
parents: 448
diff changeset
   217
  apply(subgoal_tac "length (rdistinct rs {}) = card (set (rdistinct rs {}))")
Chengsong
parents: 448
diff changeset
   218
  prefer 2
Chengsong
parents: 448
diff changeset
   219
  using set_related_list apply blast
Chengsong
parents: 448
diff changeset
   220
  apply(simp only:)
Chengsong
parents: 448
diff changeset
   221
  by (metis card_mono finite_size_n mem_Collect_eq sizeNregex_def subset_code(1))
Chengsong
parents: 448
diff changeset
   222
Chengsong
parents: 448
diff changeset
   223
Chengsong
parents: 448
diff changeset
   224
Chengsong
parents: 448
diff changeset
   225
Chengsong
parents: 448
diff changeset
   226
Chengsong
parents: 448
diff changeset
   227
Chengsong
parents: 448
diff changeset
   228
lemma star_closed_form_bounded_by_rdistinct_list_estimate:
Chengsong
parents: 448
diff changeset
   229
  shows "rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
Chengsong
parents: 448
diff changeset
   230
         (star_updates s r0 [[c]]) ) ))) \<le>
Chengsong
parents: 448
diff changeset
   231
        Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
Chengsong
parents: 448
diff changeset
   232
         (star_updates s r0 [[c]]) ) {})  ) )"
Chengsong
parents: 448
diff changeset
   233
  by (metis alts_simp_control )
Chengsong
parents: 448
diff changeset
   234
Chengsong
parents: 448
diff changeset
   235
Chengsong
parents: 448
diff changeset
   236
Chengsong
parents: 448
diff changeset
   237
Chengsong
parents: 448
diff changeset
   238
lemma star_lambda_form:
Chengsong
parents: 448
diff changeset
   239
  shows "\<forall> r \<in> set (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) ls). 
Chengsong
parents: 448
diff changeset
   240
        \<exists>s2. r = RSEQ (rders_simp r0 s2) (RSTAR r0) "
Chengsong
parents: 448
diff changeset
   241
  by (meson ex_map_conv)
Chengsong
parents: 448
diff changeset
   242
Chengsong
parents: 448
diff changeset
   243
Chengsong
parents: 448
diff changeset
   244
lemma star_lambda_ders:
Chengsong
parents: 448
diff changeset
   245
  shows " \<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
Chengsong
parents: 448
diff changeset
   246
    \<forall>r\<in>set (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) (star_updates s r0 [[c]])).
Chengsong
parents: 448
diff changeset
   247
       rsize r \<le> Suc (N + rsize (RSTAR r0))"
Chengsong
parents: 448
diff changeset
   248
  apply(insert star_lambda_form)
Chengsong
parents: 448
diff changeset
   249
  apply(simp)
Chengsong
parents: 448
diff changeset
   250
  done
Chengsong
parents: 448
diff changeset
   251
Chengsong
parents: 448
diff changeset
   252
Chengsong
parents: 448
diff changeset
   253
Chengsong
parents: 448
diff changeset
   254
Chengsong
parents: 448
diff changeset
   255
lemma star_control_bounded:
Chengsong
parents: 448
diff changeset
   256
  shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>        
Chengsong
parents: 448
diff changeset
   257
      (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
Chengsong
parents: 448
diff changeset
   258
         (star_updates s r0 [[c]]) ) {})  ) ) \<le> 
Chengsong
parents: 448
diff changeset
   259
(card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0)))
Chengsong
parents: 448
diff changeset
   260
"
Chengsong
parents: 448
diff changeset
   261
  apply(subgoal_tac "\<forall>r \<in> set (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
Chengsong
parents: 448
diff changeset
   262
         (star_updates s r0 [[c]]) ). (rsize r ) \<le> Suc (N + rsize (RSTAR r0))")
Chengsong
parents: 448
diff changeset
   263
   prefer 2
Chengsong
parents: 448
diff changeset
   264
  using star_lambda_ders apply blast
Chengsong
parents: 448
diff changeset
   265
  using distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size by blast
Chengsong
parents: 448
diff changeset
   266
Chengsong
parents: 448
diff changeset
   267
Chengsong
parents: 448
diff changeset
   268
lemma star_control_variant:
Chengsong
parents: 448
diff changeset
   269
  assumes "\<forall>s. rsize (rders_simp r0 s) \<le> N"
Chengsong
parents: 448
diff changeset
   270
  shows"Suc 
Chengsong
parents: 448
diff changeset
   271
      (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) 
Chengsong
parents: 448
diff changeset
   272
          (star_updates list r0 [[a]])) {}))) 
Chengsong
parents: 448
diff changeset
   273
\<le>  (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) "
Chengsong
parents: 448
diff changeset
   274
  apply(subgoal_tac    "(sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) 
Chengsong
parents: 448
diff changeset
   275
          (star_updates list r0 [[a]])) {}))) 
Chengsong
parents: 448
diff changeset
   276
\<le>  ( (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) ")
Chengsong
parents: 448
diff changeset
   277
  prefer 2
Chengsong
parents: 448
diff changeset
   278
  using assms star_control_bounded apply presburger
Chengsong
parents: 448
diff changeset
   279
  by simp
Chengsong
parents: 448
diff changeset
   280
Chengsong
parents: 448
diff changeset
   281
Chengsong
parents: 448
diff changeset
   282
Chengsong
parents: 448
diff changeset
   283
lemma star_closed_form_bounded:
Chengsong
parents: 448
diff changeset
   284
  shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
Chengsong
parents: 448
diff changeset
   285
              rsize (rders_simp (RSTAR r0) s) \<le> 
Chengsong
parents: 448
diff changeset
   286
max (   (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0)))))   (rsize (RSTAR r0))"
Chengsong
parents: 448
diff changeset
   287
  apply(case_tac s)
Chengsong
parents: 448
diff changeset
   288
  apply simp
Chengsong
parents: 448
diff changeset
   289
  apply(subgoal_tac " rsize (rders_simp (RSTAR r0) (a # list)) = 
Chengsong
parents: 448
diff changeset
   290
rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list r0 [[a]]) ) )))") 
Chengsong
parents: 448
diff changeset
   291
   prefer 2
Chengsong
parents: 448
diff changeset
   292
  using star_closed_form apply presburger
Chengsong
parents: 448
diff changeset
   293
  apply(subgoal_tac "rsize (rsimp (
Chengsong
parents: 448
diff changeset
   294
 RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list    r0 [[a]]) ) ))) 
Chengsong
parents: 448
diff changeset
   295
\<le>         Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
Chengsong
parents: 448
diff changeset
   296
         (star_updates list r0 [[a]]) ) {})  ) )")
Chengsong
parents: 448
diff changeset
   297
  prefer 2
Chengsong
parents: 448
diff changeset
   298
  using star_closed_form_bounded_by_rdistinct_list_estimate apply presburger
Chengsong
parents: 448
diff changeset
   299
  apply(subgoal_tac "Suc (sum_list 
Chengsong
parents: 448
diff changeset
   300
                 (map rsize
Chengsong
parents: 448
diff changeset
   301
                   (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) (star_updates list r0 [[a]])) {}))) 
Chengsong
parents: 448
diff changeset
   302
\<le>  (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0)))  ")
Chengsong
parents: 448
diff changeset
   303
  apply auto[1]
Chengsong
parents: 448
diff changeset
   304
  using star_control_variant by blast
Chengsong
parents: 448
diff changeset
   305
Chengsong
parents: 448
diff changeset
   306
Chengsong
parents: 448
diff changeset
   307
lemma seq_list_estimate_control: shows 
Chengsong
parents: 448
diff changeset
   308
" rsize (rsimp (RALTS (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1))))
Chengsong
parents: 448
diff changeset
   309
           \<le> Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))"
Chengsong
parents: 448
diff changeset
   310
  by(metis alts_simp_control)
Chengsong
parents: 448
diff changeset
   311
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   312
lemma map_ders_is_list_of_ders:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   313
  shows  "\<forall>s. rsize (rders_simp r2 s) \<le> N2 \<Longrightarrow>
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   314
\<forall>r \<in> set (rdistinct (map (rders_simp r2) Ss) {}). rsize r \<le> N2"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   315
  apply(rule same_regex_property_after_distinct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   316
  by simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   317
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   318
lemma seq_estimate_bounded: 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   319
  assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1" and "\<forall>s. rsize (rders_simp r2 s) \<le> N2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   320
  shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
"Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
 Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))"
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   323
  apply(subgoal_tac " (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   324
  (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   325
   apply force
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   326
  apply(subgoal_tac " (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   327
                      (rsize (RSEQ (rders_simp r1 s) r2)) + (sum_list (map rsize (rdistinct (map (rders_simp r2) (vsuf s r1)) {})) )")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   328
  prefer 2
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   329
  using triangle_inequality_distinct apply blast
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   330
  apply(subgoal_tac " sum_list (map rsize (rdistinct (map (rders_simp r2) (vsuf s r1)) {})) \<le> N2 * card (sizeNregex N2) ")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   331
   apply(subgoal_tac "rsize (RSEQ (rders_simp r1 s) r2) \<le> Suc (N1 + rsize r2)")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   332
    apply linarith
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   333
   apply (simp add: assms(1))
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   334
  apply(subgoal_tac "\<forall>r \<in> set (rdistinct (map (rders_simp r2) (vsuf s r1)) {}). rsize r \<le> N2")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   335
  apply (metis (no_types, opaque_lifting) assms(2) distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size ex_map_conv mult.commute)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   336
  using assms(2) map_ders_is_list_of_ders by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   337
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   338
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   339
lemma seq_closed_form_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   340
"\<lbrakk>\<forall>s. rsize (rders_simp r1 s) \<le> N1 ; \<forall>s. rsize (rders_simp r2 s) \<le> N2\<rbrakk> \<Longrightarrow>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   341
rsize (rders_simp (RSEQ r1 r2) s) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   342
max (Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))) (rsize (RSEQ r1 r2)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   343
  apply(case_tac s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   344
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   345
  apply(subgoal_tac " (rders_simp (RSEQ r1 r2) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1))))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
  using seq_closed_form_variant apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
  apply(subgoal_tac "rsize (rsimp (RALTS (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1))))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
                    \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   352
  apply(subgoal_tac "Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   353
\<le> Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   354
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
  using seq_estimate_bounded apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
   apply(subgoal_tac "rsize (rders_simp (RSEQ r1 r2) s) \<le> Suc (Suc (N1 + rsize r2) + N2 * card (sizeNregex N2))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
  using le_max_iff_disj apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
   apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   359
  using seq_list_estimate_control by presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
lemma rders_simp_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
"\<exists>N. \<forall>s. rsize (rders_simp r s) \<le> N"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
       apply(rule_tac x = "Suc 0 " in exI)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
  using three_easy_cases0 apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
  using three_easy_cases1 apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
  using three_easy_casesC apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   369
  using seq_closed_form_bounded apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   370
  apply (metis alts_closed_form_bounded size_list_estimation')
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   371
  using star_closed_form_bounded by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   372
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   373
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   374
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   377
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   379
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   380
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   382
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   383
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   384
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   385
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
(*Obsolete materials*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   390
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   391
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   392
end