262
|
1 |
theory Moment
|
|
2 |
imports Main
|
|
3 |
begin
|
|
4 |
|
|
5 |
fun firstn :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
6 |
where
|
|
7 |
"firstn 0 s = []" |
|
|
8 |
"firstn (Suc n) [] = []" |
|
|
9 |
"firstn (Suc n) (e#s) = e#(firstn n s)"
|
|
10 |
|
|
11 |
fun restn :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
12 |
where "restn n s = rev (firstn (length s - n) (rev s))"
|
|
13 |
|
|
14 |
definition moment :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
15 |
where "moment n s = rev (firstn n (rev s))"
|
|
16 |
|
|
17 |
definition restm :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
18 |
where "restm n s = rev (restn n (rev s))"
|
|
19 |
|
|
20 |
definition from_to :: "nat \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
21 |
where "from_to i j s = firstn (j - i) (restn i s)"
|
|
22 |
|
|
23 |
definition down_to :: "nat \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
|
|
24 |
where "down_to j i s = rev (from_to i j (rev s))"
|
|
25 |
|
|
26 |
(*
|
|
27 |
value "down_to 6 2 [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]"
|
|
28 |
value "from_to 2 6 [0, 1, 2, 3, 4, 5, 6, 7]"
|
|
29 |
*)
|
|
30 |
|
|
31 |
lemma length_eq_elim_l: "\<lbrakk>length xs = length ys; xs@us = ys@vs\<rbrakk> \<Longrightarrow> xs = ys \<and> us = vs"
|
|
32 |
by auto
|
|
33 |
|
|
34 |
lemma length_eq_elim_r: "\<lbrakk>length us = length vs; xs@us = ys@vs\<rbrakk> \<Longrightarrow> xs = ys \<and> us = vs"
|
|
35 |
by simp
|
|
36 |
|
|
37 |
lemma firstn_nil [simp]: "firstn n [] = []"
|
|
38 |
by (cases n, simp+)
|
|
39 |
|
|
40 |
(*
|
|
41 |
value "from_to 0 2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] @
|
|
42 |
from_to 2 5 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
|
|
43 |
*)
|
|
44 |
|
|
45 |
lemma firstn_le: "\<And> n s'. n \<le> length s \<Longrightarrow> firstn n (s@s') = firstn n s"
|
|
46 |
proof (induct s, simp)
|
|
47 |
fix a s n s'
|
|
48 |
assume ih: "\<And>n s'. n \<le> length s \<Longrightarrow> firstn n (s @ s') = firstn n s"
|
|
49 |
and le_n: " n \<le> length (a # s)"
|
|
50 |
show "firstn n ((a # s) @ s') = firstn n (a # s)"
|
|
51 |
proof(cases n, simp)
|
|
52 |
fix k
|
|
53 |
assume eq_n: "n = Suc k"
|
|
54 |
with le_n have "k \<le> length s" by auto
|
|
55 |
from ih [OF this] and eq_n
|
|
56 |
show "firstn n ((a # s) @ s') = firstn n (a # s)" by auto
|
|
57 |
qed
|
|
58 |
qed
|
|
59 |
|
|
60 |
lemma firstn_ge [simp]: "\<And>n. length s \<le> n \<Longrightarrow> firstn n s = s"
|
|
61 |
proof(induct s, simp)
|
|
62 |
fix a s n
|
|
63 |
assume ih: "\<And>n. length s \<le> n \<Longrightarrow> firstn n s = s"
|
|
64 |
and le: "length (a # s) \<le> n"
|
|
65 |
show "firstn n (a # s) = a # s"
|
|
66 |
proof(cases n)
|
|
67 |
assume eq_n: "n = 0" with le show ?thesis by simp
|
|
68 |
next
|
|
69 |
fix k
|
|
70 |
assume eq_n: "n = Suc k"
|
|
71 |
with le have le_k: "length s \<le> k" by simp
|
|
72 |
from ih [OF this] have "firstn k s = s" .
|
|
73 |
from eq_n and this
|
|
74 |
show ?thesis by simp
|
|
75 |
qed
|
|
76 |
qed
|
|
77 |
|
|
78 |
lemma firstn_eq [simp]: "firstn (length s) s = s"
|
|
79 |
by simp
|
|
80 |
|
|
81 |
lemma firstn_restn_s: "(firstn n (s::'a list)) @ (restn n s) = s"
|
|
82 |
proof(induct n arbitrary:s, simp)
|
|
83 |
fix n s
|
|
84 |
assume ih: "\<And>t. firstn n (t::'a list) @ restn n t = t"
|
|
85 |
show "firstn (Suc n) (s::'a list) @ restn (Suc n) s = s"
|
|
86 |
proof(cases s, simp)
|
|
87 |
fix x xs
|
|
88 |
assume eq_s: "s = x#xs"
|
|
89 |
show "firstn (Suc n) s @ restn (Suc n) s = s"
|
|
90 |
proof -
|
|
91 |
have "firstn (Suc n) s @ restn (Suc n) s = x # (firstn n xs @ restn n xs)"
|
|
92 |
proof -
|
|
93 |
from eq_s have "firstn (Suc n) s = x # firstn n xs" by simp
|
|
94 |
moreover have "restn (Suc n) s = restn n xs"
|
|
95 |
proof -
|
|
96 |
from eq_s have "restn (Suc n) s = rev (firstn (length xs - n) (rev xs @ [x]))" by simp
|
|
97 |
also have "\<dots> = restn n xs"
|
|
98 |
proof -
|
|
99 |
have "(firstn (length xs - n) (rev xs @ [x])) = (firstn (length xs - n) (rev xs))"
|
|
100 |
by(rule firstn_le, simp)
|
|
101 |
hence "rev (firstn (length xs - n) (rev xs @ [x])) =
|
|
102 |
rev (firstn (length xs - n) (rev xs))" by simp
|
|
103 |
also have "\<dots> = rev (firstn (length (rev xs) - n) (rev xs))" by simp
|
|
104 |
finally show ?thesis by simp
|
|
105 |
qed
|
|
106 |
finally show ?thesis by simp
|
|
107 |
qed
|
|
108 |
ultimately show ?thesis by simp
|
|
109 |
qed with ih eq_s show ?thesis by simp
|
|
110 |
qed
|
|
111 |
qed
|
|
112 |
qed
|
|
113 |
|
|
114 |
lemma moment_restm_s: "(restm n s)@(moment n s) = s"
|
336
|
115 |
by (metis firstn_restn_s moment_def restm_def rev_append rev_rev_ident)
|
262
|
116 |
|
|
117 |
declare restn.simps [simp del] firstn.simps[simp del]
|
|
118 |
|
|
119 |
lemma length_firstn_ge: "length s \<le> n \<Longrightarrow> length (firstn n s) = length s"
|
336
|
120 |
by (metis firstn_ge)
|
262
|
121 |
|
|
122 |
lemma length_firstn_le: "n \<le> length s \<Longrightarrow> length (firstn n s) = n"
|
|
123 |
proof(induct n arbitrary:s, simp add:firstn.simps)
|
|
124 |
case (Suc k)
|
|
125 |
assume ih: "\<And>s. k \<le> length (s::'a list) \<Longrightarrow> length (firstn k s) = k"
|
|
126 |
and le: "Suc k \<le> length s"
|
|
127 |
show ?case
|
|
128 |
proof(cases s)
|
|
129 |
case Nil
|
|
130 |
from Nil and le show ?thesis by auto
|
|
131 |
next
|
|
132 |
case (Cons x xs)
|
|
133 |
from le and Cons have "k \<le> length xs" by simp
|
|
134 |
from ih [OF this] have "length (firstn k xs) = k" .
|
|
135 |
moreover from Cons have "length (firstn (Suc k) s) = Suc (length (firstn k xs))"
|
|
136 |
by (simp add:firstn.simps)
|
|
137 |
ultimately show ?thesis by simp
|
|
138 |
qed
|
|
139 |
qed
|
|
140 |
|
|
141 |
lemma app_firstn_restn:
|
|
142 |
fixes s1 s2
|
|
143 |
shows "s1 = firstn (length s1) (s1 @ s2) \<and> s2 = restn (length s1) (s1 @ s2)"
|
336
|
144 |
by (metis append_eq_conv_conj firstn_ge firstn_le firstn_restn_s le_refl)
|
262
|
145 |
lemma length_moment_le:
|
|
146 |
fixes k s
|
|
147 |
assumes le_k: "k \<le> length s"
|
|
148 |
shows "length (moment k s) = k"
|
336
|
149 |
by (metis assms length_firstn_le length_rev moment_def)
|
262
|
150 |
|
|
151 |
lemma app_moment_restm:
|
|
152 |
fixes s1 s2
|
|
153 |
shows "s1 = restm (length s2) (s1 @ s2) \<and> s2 = moment (length s2) (s1 @ s2)"
|
336
|
154 |
by (metis app_firstn_restn length_rev moment_def restm_def rev_append rev_rev_ident)
|
262
|
155 |
|
|
156 |
lemma length_moment_ge:
|
|
157 |
fixes k s
|
|
158 |
assumes le_k: "length s \<le> k"
|
|
159 |
shows "length (moment k s) = (length s)"
|
336
|
160 |
by (metis assms firstn_ge length_rev moment_def)
|
262
|
161 |
|
|
162 |
lemma length_firstn: "(length (firstn n s) = length s) \<or> (length (firstn n s) = n)"
|
336
|
163 |
by (metis length_firstn_ge length_firstn_le nat_le_linear)
|
262
|
164 |
|
|
165 |
lemma firstn_conc:
|
|
166 |
fixes m n
|
|
167 |
assumes le_mn: "m \<le> n"
|
|
168 |
shows "firstn m s = firstn m (firstn n s)"
|
|
169 |
proof(cases "m \<le> length s")
|
|
170 |
case True
|
|
171 |
have "s = (firstn n s) @ (restn n s)" by (simp add:firstn_restn_s)
|
|
172 |
hence "firstn m s = firstn m \<dots>" by simp
|
|
173 |
also have "\<dots> = firstn m (firstn n s)"
|
|
174 |
proof -
|
|
175 |
from length_firstn [of n s]
|
|
176 |
have "m \<le> length (firstn n s)"
|
|
177 |
proof
|
|
178 |
assume "length (firstn n s) = length s" with True show ?thesis by simp
|
|
179 |
next
|
|
180 |
assume "length (firstn n s) = n " with le_mn show ?thesis by simp
|
|
181 |
qed
|
|
182 |
from firstn_le [OF this, of "restn n s"]
|
|
183 |
show ?thesis .
|
|
184 |
qed
|
|
185 |
finally show ?thesis by simp
|
|
186 |
next
|
|
187 |
case False
|
|
188 |
from False and le_mn have "length s \<le> n" by simp
|
|
189 |
from firstn_ge [OF this] show ?thesis by simp
|
|
190 |
qed
|
|
191 |
|
|
192 |
lemma restn_conc:
|
|
193 |
fixes i j k s
|
|
194 |
assumes eq_k: "j + i = k"
|
|
195 |
shows "restn k s = restn j (restn i s)"
|
336
|
196 |
by (metis app_moment_restm append_take_drop_id assms drop_drop length_drop moment_def restn.simps)
|
262
|
197 |
|
|
198 |
(*
|
|
199 |
value "down_to 2 0 [5, 4, 3, 2, 1, 0]"
|
|
200 |
value "moment 2 [5, 4, 3, 2, 1, 0]"
|
|
201 |
*)
|
|
202 |
|
|
203 |
lemma from_to_firstn: "from_to 0 k s = firstn k s"
|
|
204 |
by (simp add:from_to_def restn.simps)
|
|
205 |
|
|
206 |
lemma moment_app [simp]:
|
336
|
207 |
assumes ile: "i \<le> length s"
|
262
|
208 |
shows "moment i (s'@s) = moment i s"
|
336
|
209 |
by (metis assms firstn_le length_rev moment_def rev_append)
|
262
|
210 |
|
|
211 |
lemma moment_eq [simp]: "moment (length s) (s'@s) = s"
|
336
|
212 |
by (metis app_moment_restm)
|
262
|
213 |
|
|
214 |
lemma moment_ge [simp]: "length s \<le> n \<Longrightarrow> moment n s = s"
|
|
215 |
by (unfold moment_def, simp)
|
|
216 |
|
|
217 |
lemma moment_zero [simp]: "moment 0 s = []"
|
|
218 |
by (simp add:moment_def firstn.simps)
|
|
219 |
|
|
220 |
lemma p_split_gen:
|
|
221 |
"\<lbrakk>Q s; \<not> Q (moment k s)\<rbrakk> \<Longrightarrow>
|
|
222 |
(\<exists> i. i < length s \<and> k \<le> i \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
|
|
223 |
proof (induct s, simp)
|
|
224 |
fix a s
|
|
225 |
assume ih: "\<lbrakk>Q s; \<not> Q (moment k s)\<rbrakk>
|
|
226 |
\<Longrightarrow> \<exists>i<length s. k \<le> i \<and> \<not> Q (moment i s) \<and> (\<forall>i'>i. Q (moment i' s))"
|
|
227 |
and nq: "\<not> Q (moment k (a # s))" and qa: "Q (a # s)"
|
|
228 |
have le_k: "k \<le> length s"
|
|
229 |
proof -
|
|
230 |
{ assume "length s < k"
|
|
231 |
hence "length (a#s) \<le> k" by simp
|
|
232 |
from moment_ge [OF this] and nq and qa
|
|
233 |
have "False" by auto
|
|
234 |
} thus ?thesis by arith
|
|
235 |
qed
|
|
236 |
have nq_k: "\<not> Q (moment k s)"
|
|
237 |
proof -
|
|
238 |
have "moment k (a#s) = moment k s"
|
|
239 |
proof -
|
|
240 |
from moment_app [OF le_k, of "[a]"] show ?thesis by simp
|
|
241 |
qed
|
|
242 |
with nq show ?thesis by simp
|
|
243 |
qed
|
|
244 |
show "\<exists>i<length (a # s). k \<le> i \<and> \<not> Q (moment i (a # s)) \<and> (\<forall>i'>i. Q (moment i' (a # s)))"
|
|
245 |
proof -
|
|
246 |
{ assume "Q s"
|
|
247 |
from ih [OF this nq_k]
|
|
248 |
obtain i where lti: "i < length s"
|
|
249 |
and nq: "\<not> Q (moment i s)"
|
|
250 |
and rst: "\<forall>i'>i. Q (moment i' s)"
|
|
251 |
and lki: "k \<le> i" by auto
|
|
252 |
have ?thesis
|
|
253 |
proof -
|
|
254 |
from lti have "i < length (a # s)" by auto
|
|
255 |
moreover have " \<not> Q (moment i (a # s))"
|
|
256 |
proof -
|
|
257 |
from lti have "i \<le> (length s)" by simp
|
|
258 |
from moment_app [OF this, of "[a]"]
|
|
259 |
have "moment i (a # s) = moment i s" by simp
|
|
260 |
with nq show ?thesis by auto
|
|
261 |
qed
|
|
262 |
moreover have " (\<forall>i'>i. Q (moment i' (a # s)))"
|
|
263 |
proof -
|
|
264 |
{
|
|
265 |
fix i'
|
|
266 |
assume lti': "i < i'"
|
|
267 |
have "Q (moment i' (a # s))"
|
|
268 |
proof(cases "length (a#s) \<le> i'")
|
|
269 |
case True
|
|
270 |
from True have "moment i' (a#s) = a#s" by simp
|
|
271 |
with qa show ?thesis by simp
|
|
272 |
next
|
|
273 |
case False
|
|
274 |
from False have "i' \<le> length s" by simp
|
|
275 |
from moment_app [OF this, of "[a]"]
|
|
276 |
have "moment i' (a#s) = moment i' s" by simp
|
|
277 |
with rst lti' show ?thesis by auto
|
|
278 |
qed
|
|
279 |
} thus ?thesis by auto
|
|
280 |
qed
|
|
281 |
moreover note lki
|
|
282 |
ultimately show ?thesis by auto
|
|
283 |
qed
|
|
284 |
} moreover {
|
|
285 |
assume ns: "\<not> Q s"
|
|
286 |
have ?thesis
|
|
287 |
proof -
|
|
288 |
let ?i = "length s"
|
|
289 |
have "\<not> Q (moment ?i (a#s))"
|
|
290 |
proof -
|
|
291 |
have "?i \<le> length s" by simp
|
|
292 |
from moment_app [OF this, of "[a]"]
|
|
293 |
have "moment ?i (a#s) = moment ?i s" by simp
|
|
294 |
moreover have "\<dots> = s" by simp
|
|
295 |
ultimately show ?thesis using ns by auto
|
|
296 |
qed
|
|
297 |
moreover have "\<forall> i' > ?i. Q (moment i' (a#s))"
|
|
298 |
proof -
|
|
299 |
{ fix i'
|
|
300 |
assume "i' > ?i"
|
|
301 |
hence "length (a#s) \<le> i'" by simp
|
|
302 |
from moment_ge [OF this]
|
|
303 |
have " moment i' (a # s) = a # s" .
|
|
304 |
with qa have "Q (moment i' (a#s))" by simp
|
|
305 |
} thus ?thesis by auto
|
|
306 |
qed
|
|
307 |
moreover have "?i < length (a#s)" by simp
|
|
308 |
moreover note le_k
|
|
309 |
ultimately show ?thesis by auto
|
|
310 |
qed
|
|
311 |
} ultimately show ?thesis by auto
|
|
312 |
qed
|
|
313 |
qed
|
|
314 |
|
|
315 |
lemma p_split:
|
|
316 |
"\<And> s Q. \<lbrakk>Q s; \<not> Q []\<rbrakk> \<Longrightarrow>
|
|
317 |
(\<exists> i. i < length s \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
|
|
318 |
proof -
|
|
319 |
fix s Q
|
|
320 |
assume qs: "Q s" and nq: "\<not> Q []"
|
|
321 |
from nq have "\<not> Q (moment 0 s)" by simp
|
|
322 |
from p_split_gen [of Q s 0, OF qs this]
|
|
323 |
show "(\<exists> i. i < length s \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
|
|
324 |
by auto
|
|
325 |
qed
|
|
326 |
|
|
327 |
lemma moment_plus:
|
|
328 |
"Suc i \<le> length s \<Longrightarrow> moment (Suc i) s = (hd (moment (Suc i) s)) # (moment i s)"
|
|
329 |
proof(induct s, simp+)
|
|
330 |
fix a s
|
|
331 |
assume ih: "Suc i \<le> length s \<Longrightarrow> moment (Suc i) s = hd (moment (Suc i) s) # moment i s"
|
|
332 |
and le_i: "i \<le> length s"
|
|
333 |
show "moment (Suc i) (a # s) = hd (moment (Suc i) (a # s)) # moment i (a # s)"
|
|
334 |
proof(cases "i= length s")
|
|
335 |
case True
|
|
336 |
hence "Suc i = length (a#s)" by simp
|
|
337 |
with moment_eq have "moment (Suc i) (a#s) = a#s" by auto
|
|
338 |
moreover have "moment i (a#s) = s"
|
|
339 |
proof -
|
|
340 |
from moment_app [OF le_i, of "[a]"]
|
|
341 |
and True show ?thesis by simp
|
|
342 |
qed
|
|
343 |
ultimately show ?thesis by auto
|
|
344 |
next
|
|
345 |
case False
|
|
346 |
from False and le_i have lti: "i < length s" by arith
|
|
347 |
hence les_i: "Suc i \<le> length s" by arith
|
|
348 |
show ?thesis
|
|
349 |
proof -
|
|
350 |
from moment_app [OF les_i, of "[a]"]
|
|
351 |
have "moment (Suc i) (a # s) = moment (Suc i) s" by simp
|
|
352 |
moreover have "moment i (a#s) = moment i s"
|
|
353 |
proof -
|
|
354 |
from lti have "i \<le> length s" by simp
|
|
355 |
from moment_app [OF this, of "[a]"] show ?thesis by simp
|
|
356 |
qed
|
|
357 |
moreover note ih [OF les_i]
|
|
358 |
ultimately show ?thesis by auto
|
|
359 |
qed
|
|
360 |
qed
|
|
361 |
qed
|
|
362 |
|
|
363 |
lemma from_to_conc:
|
|
364 |
fixes i j k s
|
|
365 |
assumes le_ij: "i \<le> j"
|
|
366 |
and le_jk: "j \<le> k"
|
|
367 |
shows "from_to i j s @ from_to j k s = from_to i k s"
|
|
368 |
proof -
|
|
369 |
let ?ris = "restn i s"
|
|
370 |
have "firstn (j - i) (restn i s) @ firstn (k - j) (restn j s) =
|
|
371 |
firstn (k - i) (restn i s)" (is "?x @ ?y = ?z")
|
|
372 |
proof -
|
|
373 |
let "firstn (k-j) ?u" = "?y"
|
|
374 |
let ?rst = " restn (k - j) (restn (j - i) ?ris)"
|
|
375 |
let ?rst' = "restn (k - i) ?ris"
|
|
376 |
have "?u = restn (j-i) ?ris"
|
|
377 |
proof(rule restn_conc)
|
|
378 |
from le_ij show "j - i + i = j" by simp
|
|
379 |
qed
|
|
380 |
hence "?x @ ?y = ?x @ firstn (k-j) (restn (j-i) ?ris)" by simp
|
|
381 |
moreover have "firstn (k - j) (restn (j - i) (restn i s)) @ ?rst =
|
|
382 |
restn (j-i) ?ris" by (simp add:firstn_restn_s)
|
|
383 |
ultimately have "?x @ ?y @ ?rst = ?x @ (restn (j-i) ?ris)" by simp
|
|
384 |
also have "\<dots> = ?ris" by (simp add:firstn_restn_s)
|
|
385 |
finally have "?x @ ?y @ ?rst = ?ris" .
|
|
386 |
moreover have "?z @ ?rst = ?ris"
|
|
387 |
proof -
|
|
388 |
have "?z @ ?rst' = ?ris" by (simp add:firstn_restn_s)
|
|
389 |
moreover have "?rst' = ?rst"
|
|
390 |
proof(rule restn_conc)
|
|
391 |
from le_ij le_jk show "k - j + (j - i) = k - i" by auto
|
|
392 |
qed
|
|
393 |
ultimately show ?thesis by simp
|
|
394 |
qed
|
|
395 |
ultimately have "?x @ ?y @ ?rst = ?z @ ?rst" by simp
|
|
396 |
thus ?thesis by auto
|
|
397 |
qed
|
|
398 |
thus ?thesis by (simp only:from_to_def)
|
|
399 |
qed
|
|
400 |
|
|
401 |
lemma down_to_conc:
|
|
402 |
fixes i j k s
|
|
403 |
assumes le_ij: "i \<le> j"
|
|
404 |
and le_jk: "j \<le> k"
|
|
405 |
shows "down_to k j s @ down_to j i s = down_to k i s"
|
336
|
406 |
by (metis down_to_def from_to_conc le_ij le_jk rev_append)
|
262
|
407 |
|
|
408 |
lemma restn_ge:
|
|
409 |
fixes s k
|
|
410 |
assumes le_k: "length s \<le> k"
|
|
411 |
shows "restn k s = []"
|
336
|
412 |
by (metis assms diff_is_0_eq moment_def moment_zero restn.simps)
|
262
|
413 |
|
|
414 |
lemma from_to_ge: "length s \<le> k \<Longrightarrow> from_to k j s = []"
|
336
|
415 |
by (metis firstn_nil from_to_def restn_ge)
|
262
|
416 |
|
|
417 |
(*
|
|
418 |
value "from_to 2 5 [0, 1, 2, 3, 4]"
|
|
419 |
value "restn 2 [0, 1, 2, 3, 4]"
|
|
420 |
*)
|
|
421 |
|
|
422 |
lemma from_to_restn:
|
|
423 |
fixes k j s
|
|
424 |
assumes le_j: "length s \<le> j"
|
|
425 |
shows "from_to k j s = restn k s"
|
336
|
426 |
by (metis app_moment_restm append_Nil2 append_take_drop_id assms diff_is_0_eq' drop_take firstn_restn_s from_to_def length_drop moment_def moment_zero restn.simps)
|
262
|
427 |
|
|
428 |
lemma down_to_moment: "down_to k 0 s = moment k s"
|
336
|
429 |
by (metis down_to_def from_to_firstn moment_def)
|
262
|
430 |
|
|
431 |
lemma down_to_restm:
|
|
432 |
assumes le_s: "length s \<le> j"
|
|
433 |
shows "down_to j k s = restm k s"
|
336
|
434 |
by (metis assms down_to_def from_to_restn length_rev restm_def)
|
262
|
435 |
|
|
436 |
lemma moment_split: "moment (m+i) s = down_to (m+i) i s @down_to i 0 s"
|
336
|
437 |
by (metis down_to_conc down_to_moment le0 le_add1 nat_add_commute)
|
262
|
438 |
|
|
439 |
lemma length_restn: "length (restn i s) = length s - i"
|
336
|
440 |
by (metis diff_le_self length_firstn_le length_rev restn.simps)
|
262
|
441 |
|
|
442 |
lemma length_from_to_in:
|
|
443 |
fixes i j s
|
|
444 |
assumes le_ij: "i \<le> j"
|
|
445 |
and le_j: "j \<le> length s"
|
|
446 |
shows "length (from_to i j s) = j - i"
|
336
|
447 |
by (metis diff_le_mono from_to_def le_j length_firstn_le length_restn)
|
262
|
448 |
|
|
449 |
lemma firstn_restn_from_to: "from_to i (m + i) s = firstn m (restn i s)"
|
336
|
450 |
by (metis diff_add_inverse2 from_to_def)
|
262
|
451 |
|
|
452 |
lemma down_to_moment_restm:
|
|
453 |
fixes m i s
|
|
454 |
shows "down_to (m + i) i s = moment m (restm i s)"
|
|
455 |
by (simp add:firstn_restn_from_to down_to_def moment_def restm_def)
|
|
456 |
|
|
457 |
lemma moment_plus_split:
|
|
458 |
fixes m i s
|
|
459 |
shows "moment (m + i) s = moment m (restm i s) @ moment i s"
|
336
|
460 |
by (metis down_to_moment down_to_moment_restm moment_split)
|
262
|
461 |
|
|
462 |
lemma length_restm: "length (restm i s) = length s - i"
|
336
|
463 |
by (metis length_restn length_rev restm_def)
|
262
|
464 |
|
|
465 |
end |