444
|
1 |
|
|
2 |
theory ClosedFormsBounds
|
|
3 |
imports "GeneralRegexBound" "ClosedForms"
|
|
4 |
begin
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
lemma alts_closed_form_bounded: shows
|
|
9 |
"\<forall>r \<in> set rs. \<forall>s. rsize(rders_simp r s ) \<le> N \<Longrightarrow>
|
|
10 |
rsize (rders_simp (RALTS rs ) s) \<le> max (Suc ( N * (card (sizeNregex N)))) (rsize (RALTS rs) )"
|
|
11 |
apply(induct s)
|
|
12 |
apply simp
|
|
13 |
apply(insert alts_closed_form_variant)
|
|
14 |
|
|
15 |
|
|
16 |
sorry
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
lemma star_closed_form_bounded_by_rdistinct_list_estimate:
|
|
21 |
shows "rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
|
|
22 |
(star_updates s r0 [[c]]) ) ))) \<le>
|
|
23 |
Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
|
|
24 |
(star_updates s r0 [[c]]) ) {}) ) )"
|
|
25 |
|
|
26 |
sorry
|
|
27 |
|
|
28 |
lemma distinct_list_rexp_up_to_certain_size_bouded_by_set_enumerating_up_to_that_size:
|
|
29 |
shows "\<forall>r\<in> set rs. (rsize r ) \<le> N \<Longrightarrow> sum_list (map rsize (rdistinct rs {})) \<le>
|
|
30 |
(card (sizeNregex N))* N"
|
445
|
31 |
|
444
|
32 |
sorry
|
|
33 |
|
|
34 |
|
|
35 |
lemma star_control_bounded:
|
|
36 |
shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
|
|
37 |
(sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
|
|
38 |
(star_updates s r0 [[c]]) ) {}) ) ) \<le>
|
|
39 |
(card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0)))
|
|
40 |
"
|
|
41 |
sorry
|
|
42 |
|
|
43 |
lemma star_control_variant:
|
|
44 |
assumes "\<forall>s. rsize (rders_simp r0 s) \<le> N"
|
|
45 |
shows"Suc
|
|
46 |
(sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
|
|
47 |
(star_updates list r0 [[a]])) {})))
|
|
48 |
\<le> (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) "
|
|
49 |
apply(subgoal_tac "(sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0))
|
|
50 |
(star_updates list r0 [[a]])) {})))
|
|
51 |
\<le> ( (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) ")
|
|
52 |
prefer 2
|
|
53 |
using assms star_control_bounded apply presburger
|
|
54 |
by simp
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
lemma star_closed_form_bounded:
|
|
59 |
shows "\<forall>s. rsize (rders_simp r0 s) \<le> N \<Longrightarrow>
|
|
60 |
rsize (rders_simp (RSTAR r0) s) \<le>
|
|
61 |
max ( (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * (Suc (N + rsize (RSTAR r0))))) (rsize (RSTAR r0))"
|
|
62 |
apply(case_tac s)
|
|
63 |
apply simp
|
|
64 |
apply(subgoal_tac " rsize (rders_simp (RSTAR r0) (a # list)) =
|
|
65 |
rsize (rsimp ( RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list r0 [[a]]) ) )))")
|
|
66 |
prefer 2
|
|
67 |
using star_closed_form apply presburger
|
|
68 |
apply(subgoal_tac "rsize (rsimp (
|
|
69 |
RALTS ( (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) ) (star_updates list r0 [[a]]) ) )))
|
|
70 |
\<le> Suc (sum_list (map rsize (rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0) )
|
|
71 |
(star_updates list r0 [[a]]) ) {}) ) )")
|
|
72 |
prefer 2
|
|
73 |
using star_closed_form_bounded_by_rdistinct_list_estimate apply presburger
|
|
74 |
apply(subgoal_tac "Suc (sum_list
|
|
75 |
(map rsize
|
|
76 |
(rdistinct (map (\<lambda>s1. RSEQ (rders_simp r0 s1) (RSTAR r0)) (star_updates list r0 [[a]])) {})))
|
|
77 |
\<le> (Suc (card (sizeNregex (Suc (N + rsize (RSTAR r0))))) * Suc (N + rsize (RSTAR r0))) ")
|
|
78 |
apply auto[1]
|
|
79 |
using star_control_variant by blast
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
lemma seq_list_estimate_control: shows
|
|
87 |
" rsize (rsimp (RALTS (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1))))
|
|
88 |
\<le> Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))"
|
|
89 |
|
|
90 |
sorry
|
|
91 |
|
446
|
92 |
lemma rdistinct_equality1:
|
|
93 |
shows "a \<notin> ss \<Longrightarrow> rdistinct (a # rs) ss = a # rdistinct rs (insert a ss) "
|
|
94 |
by auto
|
|
95 |
|
|
96 |
lemma larger_acc_smaller_distinct_res0:
|
|
97 |
shows " ss \<subseteq> SS \<Longrightarrow> sum_list (map rsize (rdistinct rs SS)) \<le> sum_list (map rsize (rdistinct rs ss))"
|
|
98 |
apply(induct rs arbitrary: ss SS)
|
|
99 |
apply simp
|
|
100 |
apply(case_tac "a \<in> ss")
|
|
101 |
apply(subgoal_tac "a \<in> SS")
|
|
102 |
apply simp
|
|
103 |
apply blast
|
|
104 |
apply(case_tac "a \<in> SS")
|
|
105 |
apply simp
|
|
106 |
apply(subgoal_tac "insert a ss \<subseteq> SS")
|
|
107 |
apply simp
|
|
108 |
apply (simp add: trans_le_add2)
|
|
109 |
apply blast
|
|
110 |
apply(simp)
|
|
111 |
apply(subgoal_tac "insert a ss \<subseteq> insert a SS")
|
|
112 |
apply blast
|
|
113 |
by blast
|
|
114 |
|
|
115 |
|
|
116 |
lemma larger_acc_smaller_distinct_res:
|
|
117 |
shows " (sum_list (map rsize (rdistinct rs ss))) \<ge> (sum_list (map rsize (rdistinct rs (insert a ss))))"
|
|
118 |
sorry
|
|
119 |
|
|
120 |
lemma size_list_triangle1:
|
|
121 |
shows "sum_list (map rsize (a # (rdistinct as ss))) \<ge> rsize a + sum_list (map rsize (rdistinct as (insert a ss)))"
|
|
122 |
by (simp add: larger_acc_smaller_distinct_res)
|
|
123 |
|
|
124 |
|
445
|
125 |
lemma triangle_inequality_distinct:
|
|
126 |
shows "sum_list (map rsize (rdistinct (a # rs) ss)) \<le> rsize a + (sum_list (map rsize (rdistinct rs ss)))"
|
|
127 |
apply(case_tac "a \<in> ss")
|
|
128 |
apply simp
|
446
|
129 |
apply(subst rdistinct_equality1)
|
|
130 |
apply simp
|
|
131 |
using size_list_triangle1 by auto
|
445
|
132 |
|
|
133 |
lemma same_regex_property_after_map:
|
|
134 |
shows "\<forall>s. P (f r2 s) \<Longrightarrow> \<forall>r \<in> set (map (f r2) Ss). P r"
|
|
135 |
by auto
|
|
136 |
|
|
137 |
lemma same_property_after_distinct:
|
|
138 |
shows " \<forall>r \<in> set (map (f r2) Ss). P r \<Longrightarrow> \<forall>r \<in> set (rdistinct (map (f r2) Ss) xset). P r"
|
|
139 |
apply(induct Ss arbitrary: xset)
|
|
140 |
apply simp
|
|
141 |
by auto
|
|
142 |
|
|
143 |
lemma same_regex_property_after_distinct:
|
|
144 |
shows "\<forall>s. P (f r2 s) \<Longrightarrow> \<forall>r \<in> set (rdistinct (map (f r2) Ss) xset). P r"
|
|
145 |
apply(rule same_property_after_distinct)
|
|
146 |
apply(rule same_regex_property_after_map)
|
|
147 |
by simp
|
|
148 |
|
|
149 |
lemma map_ders_is_list_of_ders:
|
|
150 |
shows "\<forall>s. rsize (rders_simp r2 s) \<le> N2 \<Longrightarrow>
|
|
151 |
\<forall>r \<in> set (rdistinct (map (rders_simp r2) Ss) {}). rsize r \<le> N2"
|
|
152 |
apply(rule same_regex_property_after_distinct)
|
|
153 |
by simp
|
|
154 |
|
444
|
155 |
lemma seq_estimate_bounded:
|
|
156 |
assumes "\<forall>s. rsize (rders_simp r1 s) \<le> N1" and "\<forall>s. rsize (rders_simp r2 s) \<le> N2"
|
|
157 |
shows
|
|
158 |
"Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
|
|
159 |
Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))"
|
445
|
160 |
apply(subgoal_tac " (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
|
|
161 |
(Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
|
|
162 |
apply force
|
|
163 |
apply(subgoal_tac " (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {}))) \<le>
|
|
164 |
(rsize (RSEQ (rders_simp r1 s) r2)) + (sum_list (map rsize (rdistinct (map (rders_simp r2) (vsuf s r1)) {})) )")
|
|
165 |
prefer 2
|
|
166 |
using triangle_inequality_distinct apply blast
|
|
167 |
apply(subgoal_tac " sum_list (map rsize (rdistinct (map (rders_simp r2) (vsuf s r1)) {})) \<le> N2 * card (sizeNregex N2) ")
|
|
168 |
apply(subgoal_tac "rsize (RSEQ (rders_simp r1 s) r2) \<le> Suc (N1 + rsize r2)")
|
|
169 |
apply linarith
|
|
170 |
apply (simp add: assms(1))
|
|
171 |
apply(subgoal_tac "\<forall>r \<in> set (rdistinct (map (rders_simp r2) (vsuf s r1)) {}). rsize r \<le> N2")
|
|
172 |
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)
|
|
173 |
using assms(2) map_ders_is_list_of_ders by blast
|
444
|
174 |
|
|
175 |
|
|
176 |
lemma seq_closed_form_bounded: shows
|
|
177 |
"\<lbrakk>\<forall>s. rsize (rders_simp r1 s) \<le> N1 ; \<forall>s. rsize (rders_simp r2 s) \<le> N2\<rbrakk> \<Longrightarrow>
|
|
178 |
rsize (rders_simp (RSEQ r1 r2) s) \<le>
|
|
179 |
max (Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))) (rsize (RSEQ r1 r2)) "
|
|
180 |
apply(case_tac s)
|
|
181 |
apply simp
|
|
182 |
apply(subgoal_tac " (rders_simp (RSEQ r1 r2) s) =
|
|
183 |
rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # (map (rders_simp r2) (vsuf s r1))))")
|
|
184 |
prefer 2
|
|
185 |
using seq_closed_form_variant apply blast
|
|
186 |
apply(subgoal_tac "rsize (rsimp (RALTS (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1))))
|
|
187 |
\<le>
|
|
188 |
Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))")
|
|
189 |
apply(subgoal_tac "Suc (sum_list (map rsize (rdistinct (RSEQ (rders_simp r1 s) r2 # map (rders_simp r2) (vsuf s r1)) {})))
|
|
190 |
\<le> Suc (Suc (N1 + (rsize r2)) + (N2 * card (sizeNregex N2)))")
|
|
191 |
prefer 2
|
|
192 |
using seq_estimate_bounded apply blast
|
|
193 |
apply(subgoal_tac "rsize (rders_simp (RSEQ r1 r2) s) \<le> Suc (Suc (N1 + rsize r2) + N2 * card (sizeNregex N2))")
|
|
194 |
using le_max_iff_disj apply blast
|
|
195 |
apply auto[1]
|
|
196 |
using seq_list_estimate_control by presburger
|
|
197 |
|
|
198 |
|
|
199 |
lemma rders_simp_bounded: shows
|
|
200 |
"\<exists>N. \<forall>s. rsize (rders_simp r s) \<le> N"
|
|
201 |
apply(induct r)
|
|
202 |
apply(rule_tac x = "Suc 0 " in exI)
|
|
203 |
using three_easy_cases0 apply force
|
|
204 |
using three_easy_cases1 apply blast
|
|
205 |
using three_easy_casesC apply blast
|
|
206 |
using seq_closed_form_bounded apply blast
|
|
207 |
apply (metis alts_closed_form_bounded size_list_estimation')
|
|
208 |
using star_closed_form_bounded by blast
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
(*Obsolete materials*)
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
end
|