thys2/ClosedFormsBounds.thy
author Chengsong
Fri, 11 Mar 2022 21:25:08 +0000
changeset 447 7fb1e3dd5ae6
parent 446 0a94fd47b792
child 448 3bc0f0069d06
permissions -rw-r--r--
closedformbounds
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     6
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     7
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     8
lemma alts_closed_form_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     9
"\<forall>r \<in> set rs. \<forall>s. rsize(rders_simp r s ) \<le> N \<Longrightarrow> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    10
rsize (rders_simp (RALTS rs ) s) \<le> max (Suc ( N * (card (sizeNregex N)))) (rsize (RALTS rs) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    11
  apply(induct s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    12
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    13
  apply(insert alts_closed_form_variant)
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
  sorry
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    20
lemma star_closed_form_bounded_by_rdistinct_list_estimate:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    21
  shows "rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    22
         (star_updates s r0 [[c]]) ) ))) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    23
        Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    24
         (star_updates s r0 [[c]]) ) {})  ) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    25
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    26
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    27
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    28
lemma distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    29
  shows "\<forall>r\<in> set rs. (rsize r ) \<le> N \<Longrightarrow> sum_list (map rsize (rdistinct rs {})) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    30
         (card (sizeNregex N))* N"
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
    31
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    32
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    33
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    34
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    35
lemma star_lambda_ders:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    36
  shows " \<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    37
    \<forall>r\<in>set (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) (star_updates s r0 [[c]])).
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    38
       rsize r \<le> Suc (N + rsize (RSTAR r0))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    39
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    40
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    41
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    42
lemma star_control_bounded:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    43
  shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>        
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    44
      (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    45
         (star_updates s r0 [[c]]) ) {})  ) ) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    46
(card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0)))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    47
"
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    48
  apply(subgoal_tac "\<forall>r \<in> set (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    49
         (star_updates s r0 [[c]]) ). (rsize r ) \<le> Suc (N + rsize (RSTAR r0))")
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    50
   prefer 2
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    51
  using star_lambda_ders apply blast
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    52
  using distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size by blast
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    53
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    54
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    55
lemma star_control_variant:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    56
  assumes "\<forall>s. rsize (rders_simp r0 s) \<le> N"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    57
  shows"Suc 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    58
      (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    59
          (star_updates list r0 [[a]])) {}))) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    60
\<le>  (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    61
  apply(subgoal_tac    "(sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    62
          (star_updates list r0 [[a]])) {}))) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    63
\<le>  ( (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) ")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    64
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    65
  using assms star_control_bounded apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    66
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    67
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    68
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    69
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    70
lemma star_closed_form_bounded:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    71
  shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    72
              rsize (rders_simp (RSTAR r0) s) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    73
max (   (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0)))))   (rsize (RSTAR r0))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    74
  apply(case_tac s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    75
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    76
  apply(subgoal_tac " rsize (rders_simp (RSTAR r0) (a # list)) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    77
rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list r0 [[a]]) ) )))") 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    78
   prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    79
  using star_closed_form apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    80
  apply(subgoal_tac "rsize (rsimp (
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    81
 RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list    r0 [[a]]) ) ))) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    82
\<le>         Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    83
         (star_updates list r0 [[a]]) ) {})  ) )")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    84
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    85
  using star_closed_form_bounded_by_rdistinct_list_estimate apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    86
  apply(subgoal_tac "Suc (sum_list 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    87
                 (map rsize
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    88
                   (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) (star_updates list r0 [[a]])) {}))) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    89
\<le>  (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0)))  ")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    90
  apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    91
  using star_control_variant by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    92
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    93
lemma alts_simp_ineq_unfold:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    94
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    95
  using rsimp_aalts_smaller by auto
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    96
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    97
lemma flts_has_no_zero:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    98
  shows "rdistinct (rflts rs) rset = rdistinct (rflts rs) (insert RZERO rset)"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
    99
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   100
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   101
lemma flts_vs_nflts:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   102
  shows "\<forall>r \<in> noalts_set. \<forall>xs. r \<noteq> RALTS xs
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   103
 \<and> (\<forall>a \<in> alts_set. \<exists>xs. a = RALTS xs \<and> set xs \<subseteq> corr_set)  
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   104
\<Longrightarrow> Suc (sum_list (map rsize (rdistinct ( rflts rs) (noalts_set \<union> corr_set)  )))
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   105
         \<le> Suc (sum_list (map rsize (rdistinct rs (noalts_set \<union> alts_set) )))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   106
  apply(induct rs arbitrary: noalts_set)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   107
   apply simp
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   108
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   109
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   110
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   111
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   112
lemma without_flts_ineq:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   113
  shows " Suc (sum_list (map rsize (rdistinct (rflts rs) {}) )) \<le> 
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   114
         Suc (sum_list (map rsize (rdistinct (    rs  ) {}  )))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   115
  by (metis empty_iff flts_vs_nflts sup_bot_left)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   116
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   117
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   118
lemma distinct_simp_ineq:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   119
  shows "Suc (sum_list (map rsize (rdistinct (map rsimp rs) {})))
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   120
    \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   121
  sorry
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   122
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   123
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   124
lemma alts_simp_control:
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   125
  shows "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   126
proof -
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   127
  have "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   128
    
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   129
    using alts_simp_ineq_unfold by auto
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   130
  then have "\<dots> \<le> Suc (sum_list (map rsize (rdistinct (map rsimp rs) {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   131
    using without_flts_ineq by blast
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   132
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   133
  show "rsize (rsimp (RALTS rs)) \<le> Suc (sum_list (map rsize (rdistinct rs {})))"
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   134
    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
   135
qed
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   136
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   137
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   138
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   139
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   140
lemma seq_list_estimate_control: shows 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   141
" rsize (rsimp (RALTS (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1))))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   142
           \<le> Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))"
447
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   143
  by(metis alts_simp_control)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   144
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   145
lemma rdistinct_equality1:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   146
  shows "a \<notin> ss \<Longrightarrow> rdistinct (a  # rs) ss = a # rdistinct rs (insert a ss) "
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   147
  by auto
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   148
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   149
lemma larger_acc_smaller_distinct_res0:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   150
  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
   151
  apply(induct rs arbitrary: ss SS)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   152
  apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   153
  apply(case_tac "a \<in> ss")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   154
   apply(subgoal_tac "a \<in> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   155
    apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   156
   apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   157
  apply(case_tac "a \<in> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   158
   apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   159
   apply(subgoal_tac "insert a ss \<subseteq> SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   160
    apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   161
  apply (simp add: trans_le_add2)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   162
  apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   163
  apply(simp)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   164
  apply(subgoal_tac "insert a ss \<subseteq> insert a SS")
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   165
   apply blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   166
  by blast
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   167
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   168
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   169
lemma larger_acc_smaller_distinct_res:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   170
  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
   171
  apply(subgoal_tac "ss \<subseteq> (insert a ss)")
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   172
   apply(rule larger_acc_smaller_distinct_res0)
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   173
   apply simp
7fb1e3dd5ae6 closedformbounds
Chengsong
parents: 446
diff changeset
   174
  by (simp add: subset_insertI)
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   175
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   176
lemma size_list_triangle1:
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   177
  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
   178
  by (simp add: larger_acc_smaller_distinct_res)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   179
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   180
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   181
lemma triangle_inequality_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   182
  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
   183
  apply(case_tac "a \<in> ss")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   184
   apply simp
446
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   185
  apply(subst rdistinct_equality1)
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   186
   apply simp
0a94fd47b792 before repair
Chengsong
parents: 445
diff changeset
   187
  using size_list_triangle1 by auto
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   188
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   189
lemma same_regex_property_after_map:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   190
  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
   191
  by auto
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   192
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   193
lemma same_property_after_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   194
  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
   195
  apply(induct Ss arbitrary: xset)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   196
   apply simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   197
  by auto
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   198
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   199
lemma same_regex_property_after_distinct:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   200
  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
   201
  apply(rule same_property_after_distinct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   202
  apply(rule same_regex_property_after_map)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   203
  by simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   204
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   205
lemma map_ders_is_list_of_ders:
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   206
  shows  "\<forall>s. rsize (rders_simp r2 s) \<le> N2 \<Longrightarrow>
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   207
\<forall>r \<in> set (rdistinct (map (rders_simp r2) Ss) {}). rsize r \<le> N2"
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   208
  apply(rule same_regex_property_after_distinct)
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   209
  by simp
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   210
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   211
lemma seq_estimate_bounded: 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   212
  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
   213
  shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   214
"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
   215
 Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))"
445
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   216
  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
   217
  (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   218
   apply force
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   219
  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
   220
                      (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
   221
  prefer 2
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   222
  using triangle_inequality_distinct apply blast
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   223
  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
   224
   apply(subgoal_tac "rsize (RSEQ (rders_simp r1 s) r2) \<le> Suc (N1 + rsize r2)")
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   225
    apply linarith
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   226
   apply (simp add: assms(1))
e072cfc2f2ee closedforms
Chengsong
parents: 444
diff changeset
   227
  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
   228
  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
   229
  using assms(2) map_ders_is_list_of_ders by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   230
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   231
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   232
lemma seq_closed_form_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   233
"\<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
   234
rsize (rders_simp (RSEQ r1 r2) s) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   235
max (Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))) (rsize (RSEQ r1 r2)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   236
  apply(case_tac s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   237
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   238
  apply(subgoal_tac " (rders_simp (RSEQ r1 r2) s) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   239
rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1))))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   240
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   241
  using seq_closed_form_variant apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   242
  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
   243
                    \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   244
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
   245
  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
   246
\<le> Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   247
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   248
  using seq_estimate_bounded apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   249
   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
   250
  using le_max_iff_disj apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   251
   apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   252
  using seq_list_estimate_control by presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   253
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   254
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   255
lemma rders_simp_bounded: shows
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   256
"\<exists>N. \<forall>s. rsize (rders_simp r s) \<le> N"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   257
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   258
       apply(rule_tac x = "Suc 0 " in exI)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   259
  using three_easy_cases0 apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   260
  using three_easy_cases1 apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   261
  using three_easy_casesC apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   262
  using seq_closed_form_bounded apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   263
  apply (metis alts_closed_form_bounded size_list_estimation')
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   264
  using star_closed_form_bounded by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   265
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   266
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   267
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   268
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   269
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   270
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   280
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   281
(*Obsolete materials*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   282
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   283
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   284
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   285
end