author | zhangx |
Thu, 14 Jan 2016 00:55:54 +0800 | |
changeset 74 | 83ba2d8c859a |
parent 73 | b0054fb0d1ce |
child 75 | 2aa37de77f31 |
permissions | -rw-r--r-- |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory Moment |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
5 |
definition moment :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list" |
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
6 |
where "moment n s = rev (take n (rev s))" |
67 | 7 |
|
70
92ca2410b3d9
further simplificaton of Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
69
diff
changeset
|
8 |
value "moment 3 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9::int]" |
92ca2410b3d9
further simplificaton of Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
69
diff
changeset
|
9 |
value "moment 2 [5, 4, 3, 2, 1, 0::int]" |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
|
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
11 |
(* |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
lemma length_moment_le: |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
assumes le_k: "k \<le> length s" |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
shows "length (moment k s) = k" |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
15 |
using le_k unfolding moment_def by auto |
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
16 |
*) |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
|
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
18 |
(* |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
lemma length_moment_ge: |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
assumes le_k: "length s \<le> k" |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
shows "length (moment k s) = (length s)" |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
22 |
using assms unfolding moment_def by simp |
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
23 |
*) |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
|
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
lemma moment_app [simp]: |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
26 |
assumes ile: "i \<le> length s" |
70
92ca2410b3d9
further simplificaton of Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
69
diff
changeset
|
27 |
shows "moment i (s' @ s) = moment i s" |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
28 |
using assms unfolding moment_def by simp |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
|
70
92ca2410b3d9
further simplificaton of Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
69
diff
changeset
|
30 |
lemma moment_eq [simp]: "moment (length s) (s' @ s) = s" |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
31 |
unfolding moment_def by simp |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
|
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
lemma moment_ge [simp]: "length s \<le> n \<Longrightarrow> moment n s = s" |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
by (unfold moment_def, simp) |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
|
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
lemma moment_zero [simp]: "moment 0 s = []" |
69
1dc801552dfd
simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
67
diff
changeset
|
37 |
by (simp add:moment_def) |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
|
74 | 39 |
lemma least_idx: |
40 |
assumes "Q (i::nat)" |
|
41 |
obtains j where "j \<le> i" "Q j" "\<forall> k < j. \<not> Q k" |
|
42 |
using assms |
|
43 |
by (metis ex_least_nat_le le0 not_less0) |
|
44 |
||
45 |
lemma duration_idx: |
|
46 |
assumes "\<not> Q (i::nat)" |
|
47 |
and "Q j" |
|
48 |
and "i \<le> j" |
|
49 |
obtains k where "i \<le> k" "k < j" "\<not> Q k" "\<forall> i'. k < i' \<and> i' \<le> j \<longrightarrow> Q i'" |
|
50 |
proof - |
|
51 |
let ?Q = "\<lambda> t. t \<le> j \<and> \<not> Q (j - t)" |
|
52 |
have "?Q (j - i)" using assms by (simp add: assms(1)) |
|
53 |
from least_idx [of ?Q, OF this] |
|
54 |
obtain l |
|
55 |
where h: "l \<le> j - i" "\<not> Q (j - l)" "\<forall>k<l. \<not> (k \<le> j \<and> \<not> Q (j - k))" |
|
56 |
by metis |
|
57 |
let ?k = "j - l" |
|
58 |
have "i \<le> ?k" using assms(3) h(1) by linarith |
|
59 |
moreover have "?k < j" by (metis assms(2) diff_le_self h(2) le_neq_implies_less) |
|
60 |
moreover have "\<not> Q ?k" by (simp add: h(2)) |
|
61 |
moreover have "\<forall> i'. ?k < i' \<and> i' \<le> j \<longrightarrow> Q i'" |
|
62 |
by (metis diff_diff_cancel diff_le_self diff_less_mono2 h(3) |
|
63 |
less_imp_diff_less not_less) |
|
64 |
ultimately show ?thesis using that by metis |
|
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
qed |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
|
74 | 67 |
lemma p_split_gen: |
68 |
assumes "Q s" |
|
69 |
and "\<not> Q (moment k s)" |
|
70 |
shows "(\<exists> i. i < length s \<and> k \<le> i \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))" |
|
71 |
proof(cases "k \<le> length s") |
|
72 |
case True |
|
73 |
let ?Q = "\<lambda> t. Q (moment t s)" |
|
74 |
have "?Q (length s)" using assms(1) by simp |
|
75 |
from duration_idx[of ?Q, OF assms(2) this True] |
|
76 |
obtain i where h: "k \<le> i" "i < length s" "\<not> Q (moment i s)" |
|
77 |
"\<forall>i'. i < i' \<and> i' \<le> length s \<longrightarrow> Q (moment i' s)" by metis |
|
78 |
moreover have "(\<forall> i' > i. Q (moment i' s))" using h(4) assms(1) not_less |
|
79 |
by fastforce |
|
80 |
ultimately show ?thesis by metis |
|
81 |
qed (insert assms, auto) |
|
82 |
||
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
lemma p_split: |
74 | 84 |
assumes qs: "Q s" |
85 |
and nq: "\<not> Q []" |
|
86 |
shows "(\<exists> i. i < length s \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))" |
|
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
proof - |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
from nq have "\<not> Q (moment 0 s)" by simp |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
from p_split_gen [of Q s 0, OF qs this] |
74 | 90 |
show ?thesis by auto |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
qed |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
|
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
93 |
lemma moment_Suc_tl: |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
94 |
assumes "Suc i \<le> length s" |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
95 |
shows "tl (moment (Suc i) s) = moment i s" |
74 | 96 |
using assms |
97 |
by (simp add:moment_def rev_take, |
|
98 |
metis Suc_diff_le diff_Suc_Suc drop_Suc tl_drop) |
|
73 | 99 |
|
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
100 |
lemma moment_plus: |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
101 |
assumes "Suc i \<le> length s" |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
102 |
shows "(moment (Suc i) s) = (hd (moment (Suc i) s)) # (moment i s)" |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
103 |
proof - |
73 | 104 |
have "(moment (Suc i) s) \<noteq> []" using assms |
105 |
by (simp add:moment_def rev_take) |
|
71
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
106 |
hence "(moment (Suc i) s) = (hd (moment (Suc i) s)) # tl (moment (Suc i) s)" |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
107 |
by auto |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
108 |
with moment_Suc_tl[OF assms] |
04caf0ccb3ae
some small change
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
70
diff
changeset
|
109 |
show ?thesis by metis |
0
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
qed |
110247f9d47e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
|
35
92f61f6a0fe7
added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
0
diff
changeset
|
112 |
end |
70
92ca2410b3d9
further simplificaton of Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
69
diff
changeset
|
113 |