author | Christian Urban <urbanc@in.tum.de> |
Wed, 02 Aug 2017 14:56:47 +0100 | |
changeset 190 | 312497c6d6b9 |
parent 1 | c4783e4ef43f |
permissions | -rw-r--r-- |
1
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory Happen_within |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main Moment |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
(* |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
lemma |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
fixes P :: "('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
and Q :: "('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
and k :: nat |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
and f :: "('a list) \<Rightarrow> nat" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
assumes "\<And> s t. \<lbrakk>P s; \<not> Q s; P (t@s); k < length t\<rbrakk> \<Longrightarrow> f (t@s) < f s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
shows "\<And> s t. \<lbrakk> P s; P(t @ s); f(s) * k < length t\<rbrakk> \<Longrightarrow> Q (t@s)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
sorry |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
*) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
text {* |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
The following two notions are introduced to improve the situation. |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
*} |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
definition all_future :: "(('a list) \<Rightarrow> bool) \<Rightarrow> (('a list) \<Rightarrow> bool) \<Rightarrow> ('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
where "all_future G R s = (\<forall> t. G (t@s) \<longrightarrow> R t)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
definition happen_within :: "(('a list) \<Rightarrow> bool) \<Rightarrow> (('a list) \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> ('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
where "happen_within G R k s = all_future G (\<lambda> t. k < length t \<longrightarrow> |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
(\<exists> i \<le> k. R (moment i t @ s) \<and> G (moment i t @ s))) s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
lemma happen_within_intro: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
fixes P :: "('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
and Q :: "('a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
and k :: nat |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
and f :: "('a list) \<Rightarrow> nat" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
assumes |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
lt_k: "0 < k" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
and step: "\<And> s. \<lbrakk>P s; \<not> Q s\<rbrakk> \<Longrightarrow> happen_within P (\<lambda> s'. f s' < f s) k s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
shows "\<And> s. P s \<Longrightarrow> happen_within P Q ((f s + 1) * k) s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
fix s |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
assume "P s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
thus "happen_within P Q ((f s + 1) * k) s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
proof(induct n == "f s + 1" arbitrary:s rule:nat_less_induct) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
fix s |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
assume ih [rule_format]: "\<forall>m<f s + 1. \<forall>x. m = f x + 1 \<longrightarrow> P x |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
\<longrightarrow> happen_within P Q ((f x + 1) * k) x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
and ps: "P s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
show "happen_within P Q ((f s + 1) * k) s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
proof(cases "Q s") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
{ fix t |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
from True and ps have "0 \<le> ((f s + 1)*k) \<and> Q (moment 0 t @ s) \<and> P (moment 0 t @ s)" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
hence "\<exists>i\<le>(f s + 1) * k. Q (moment i t @ s) \<and> P (moment i t @ s)" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
} thus ?thesis by (auto simp: happen_within_def all_future_def) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
from step [OF ps False] have kk: "happen_within P (\<lambda>s'. f s' < f s) k s" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
{ fix t |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
assume pts: "P (t @ s)" and ltk: "(f s + 1) * k < length t" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
from ltk have lt_k_lt: "k < length t" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
with kk pts obtain i |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
where le_ik: "i \<le> k" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
and lt_f: "f (moment i t @ s) < f s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
and p_m: "P (moment i t @ s)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
by (auto simp:happen_within_def all_future_def) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
from ih [of "f (moment i t @ s) + 1" "(moment i t @ s)", OF _ _ p_m] and lt_f |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
have hw: "happen_within P Q ((f (moment i t @ s) + 1) * k) (moment i t @ s)" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
have "(\<exists>j\<le>(f s + 1) * k. Q (moment j t @ s) \<and> P (moment j t @ s))" (is "\<exists> j. ?T j") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
let ?t = "restm i t" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
have eq_t: "t = ?t @ moment i t" by (simp add:moment_restm_s) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
have h1: "P (restm i t @ moment i t @ s)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
from pts and eq_t have "P ((restm i t @ moment i t) @ s)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
thus ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
moreover have h2: "(f (moment i t @ s) + 1) * k < length (restm i t)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
have h: "\<And> x y z. (x::nat) \<le> y \<Longrightarrow> x * z \<le> y * z" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
from lt_f have "(f (moment i t @ s) + 1) \<le> f s " by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
from h [OF this, of k] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
have "(f (moment i t @ s) + 1) * k \<le> f s * k" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
moreover from le_ik have "\<dots> \<le> ((f s) * k + k - i)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
moreover from le_ik lt_k_lt and ltk have "(f s) * k + k - i < length t - i" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
moreover have "length (restm i t) = length t - i" using length_restm by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
ultimately show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
from hw [unfolded happen_within_def all_future_def, rule_format, OF h1 h2] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
obtain m where le_m: "m \<le> (f (moment i t @ s) + 1) * k" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
and q_m: "Q (moment m ?t @ moment i t @ s)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
and p_m: "P (moment m ?t @ moment i t @ s)" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
have eq_mm: "moment m ?t @ moment i t @ s = (moment (m+i) t)@s" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
have "moment m (restm i t) @ moment i t = moment (m + i) t" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
using moment_plus_split by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
thus ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
let ?j = "m + i" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
have "?T ?j" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
have "m + i \<le> (f s + 1) * k" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
have h: "\<And> x y z. (x::nat) \<le> y \<Longrightarrow> x * z \<le> y * z" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
from lt_f have "(f (moment i t @ s) + 1) \<le> f s " by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
from h [OF this, of k] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
have "(f (moment i t @ s) + 1) * k \<le> f s * k" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
with le_m have "m \<le> f s * k" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
hence "m + i \<le> f s * k + i" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
with le_ik show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
moreover from eq_mm q_m have " Q (moment (m + i) t @ s)" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
moreover from eq_mm p_m have " P (moment (m + i) t @ s)" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
ultimately show ?thesis by blast |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
thus ?thesis by blast |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
} thus ?thesis by (simp add:happen_within_def all_future_def firstn.simps) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
end |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |