author | haftmann |
Fri, 15 Feb 2013 08:31:31 +0100 | |
changeset 51143 | 0a2371e7ced3 |
parent 48909 | b2dea007e55e |
child 52021 | 59963cda805a |
permissions | -rw-r--r-- |
44070 | 1 |
header "Semantic Equivalence up to a Condition" |
2 |
||
3 |
theory Sem_Equiv |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
4 |
imports Big_Step |
44070 | 5 |
begin |
6 |
||
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
7 |
type_synonym assn = "state \<Rightarrow> bool" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
8 |
|
44070 | 9 |
definition |
10 |
equiv_up_to :: "assn \<Rightarrow> com \<Rightarrow> com \<Rightarrow> bool" ("_ \<Turnstile> _ \<sim> _" [60,0,10] 60) |
|
11 |
where |
|
12 |
"P \<Turnstile> c \<sim> c' \<equiv> \<forall>s s'. P s \<longrightarrow> (c,s) \<Rightarrow> s' \<longleftrightarrow> (c',s) \<Rightarrow> s'" |
|
13 |
||
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
14 |
definition |
44070 | 15 |
bequiv_up_to :: "assn \<Rightarrow> bexp \<Rightarrow> bexp \<Rightarrow> bool" ("_ \<Turnstile> _ <\<sim>> _" [60,0,10] 60) |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
16 |
where |
44070 | 17 |
"P \<Turnstile> b <\<sim>> b' \<equiv> \<forall>s. P s \<longrightarrow> bval b s = bval b' s" |
18 |
||
19 |
lemma equiv_up_to_True: |
|
20 |
"((\<lambda>_. True) \<Turnstile> c \<sim> c') = (c \<sim> c')" |
|
21 |
by (simp add: equiv_def equiv_up_to_def) |
|
22 |
||
23 |
lemma equiv_up_to_weaken: |
|
24 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (\<And>s. P' s \<Longrightarrow> P s) \<Longrightarrow> P' \<Turnstile> c \<sim> c'" |
|
25 |
by (simp add: equiv_up_to_def) |
|
26 |
||
27 |
lemma equiv_up_toI: |
|
28 |
"(\<And>s s'. P s \<Longrightarrow> (c, s) \<Rightarrow> s' = (c', s) \<Rightarrow> s') \<Longrightarrow> P \<Turnstile> c \<sim> c'" |
|
29 |
by (unfold equiv_up_to_def) blast |
|
30 |
||
31 |
lemma equiv_up_toD1: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
32 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (c, s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> (c', s) \<Rightarrow> s'" |
44070 | 33 |
by (unfold equiv_up_to_def) blast |
34 |
||
35 |
lemma equiv_up_toD2: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
36 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (c', s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> (c, s) \<Rightarrow> s'" |
44070 | 37 |
by (unfold equiv_up_to_def) blast |
38 |
||
39 |
||
40 |
lemma equiv_up_to_refl [simp, intro!]: |
|
41 |
"P \<Turnstile> c \<sim> c" |
|
42 |
by (auto simp: equiv_up_to_def) |
|
43 |
||
44 |
lemma equiv_up_to_sym: |
|
45 |
"(P \<Turnstile> c \<sim> c') = (P \<Turnstile> c' \<sim> c)" |
|
46 |
by (auto simp: equiv_up_to_def) |
|
47 |
||
45218 | 48 |
lemma equiv_up_to_trans: |
44070 | 49 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> P \<Turnstile> c' \<sim> c'' \<Longrightarrow> P \<Turnstile> c \<sim> c''" |
50 |
by (auto simp: equiv_up_to_def) |
|
51 |
||
52 |
||
53 |
lemma bequiv_up_to_refl [simp, intro!]: |
|
54 |
"P \<Turnstile> b <\<sim>> b" |
|
55 |
by (auto simp: bequiv_up_to_def) |
|
56 |
||
57 |
lemma bequiv_up_to_sym: |
|
58 |
"(P \<Turnstile> b <\<sim>> b') = (P \<Turnstile> b' <\<sim>> b)" |
|
59 |
by (auto simp: bequiv_up_to_def) |
|
60 |
||
45218 | 61 |
lemma bequiv_up_to_trans: |
44070 | 62 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P \<Turnstile> b' <\<sim>> b'' \<Longrightarrow> P \<Turnstile> b <\<sim>> b''" |
63 |
by (auto simp: bequiv_up_to_def) |
|
64 |
||
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
65 |
lemma bequiv_up_to_subst: |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
66 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P s \<Longrightarrow> bval b s = bval b' s" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
67 |
by (simp add: bequiv_up_to_def) |
44070 | 68 |
|
69 |
||
47818 | 70 |
lemma equiv_up_to_seq: |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
71 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> Q \<Turnstile> d \<sim> d' \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
72 |
(\<And>s s'. (c,s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> Q s') \<Longrightarrow> |
44070 | 73 |
P \<Turnstile> (c; d) \<sim> (c'; d')" |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
74 |
by (clarsimp simp: equiv_up_to_def) blast |
44070 | 75 |
|
76 |
lemma equiv_up_to_while_lemma: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
77 |
shows "(d,s) \<Rightarrow> s' \<Longrightarrow> |
44070 | 78 |
P \<Turnstile> b <\<sim>> b' \<Longrightarrow> |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
79 |
(\<lambda>s. P s \<and> bval b s) \<Turnstile> c \<sim> c' \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
80 |
(\<And>s s'. (c, s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b s \<Longrightarrow> P s') \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
81 |
P s \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
82 |
d = WHILE b DO c \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
83 |
(WHILE b' DO c', s) \<Rightarrow> s'" |
45015 | 84 |
proof (induction rule: big_step_induct) |
44070 | 85 |
case (WhileTrue b s1 c s2 s3) |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
86 |
hence IH: "P s2 \<Longrightarrow> (WHILE b' DO c', s2) \<Rightarrow> s3" by auto |
44070 | 87 |
from WhileTrue.prems |
88 |
have "P \<Turnstile> b <\<sim>> b'" by simp |
|
89 |
with `bval b s1` `P s1` |
|
90 |
have "bval b' s1" by (simp add: bequiv_up_to_def) |
|
91 |
moreover |
|
92 |
from WhileTrue.prems |
|
93 |
have "(\<lambda>s. P s \<and> bval b s) \<Turnstile> c \<sim> c'" by simp |
|
94 |
with `bval b s1` `P s1` `(c, s1) \<Rightarrow> s2` |
|
95 |
have "(c', s1) \<Rightarrow> s2" by (simp add: equiv_up_to_def) |
|
96 |
moreover |
|
97 |
from WhileTrue.prems |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
98 |
have "\<And>s s'. (c,s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b s \<Longrightarrow> P s'" by simp |
44070 | 99 |
with `P s1` `bval b s1` `(c, s1) \<Rightarrow> s2` |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
100 |
have "P s2" by simp |
44070 | 101 |
hence "(WHILE b' DO c', s2) \<Rightarrow> s3" by (rule IH) |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
102 |
ultimately |
44070 | 103 |
show ?case by blast |
104 |
next |
|
105 |
case WhileFalse |
|
106 |
thus ?case by (auto simp: bequiv_up_to_def) |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
107 |
qed (fastforce simp: equiv_up_to_def bequiv_up_to_def)+ |
44070 | 108 |
|
109 |
lemma bequiv_context_subst: |
|
110 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> (P s \<and> bval b s) = (P s \<and> bval b' s)" |
|
111 |
by (auto simp: bequiv_up_to_def) |
|
112 |
||
113 |
lemma equiv_up_to_while: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
114 |
assumes b: "P \<Turnstile> b <\<sim>> b'" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
115 |
assumes c: "(\<lambda>s. P s \<and> bval b s) \<Turnstile> c \<sim> c'" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
116 |
assumes I: "\<And>s s'. (c, s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b s \<Longrightarrow> P s'" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
117 |
shows "P \<Turnstile> WHILE b DO c \<sim> WHILE b' DO c'" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
118 |
proof - |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
119 |
from b have b': "P \<Turnstile> b' <\<sim>> b" by (simp add: bequiv_up_to_sym) |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
120 |
|
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
121 |
from c b have c': "(\<lambda>s. P s \<and> bval b' s) \<Turnstile> c' \<sim> c" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
122 |
by (simp add: equiv_up_to_sym bequiv_context_subst) |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
123 |
|
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
124 |
from I |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
125 |
have I': "\<And>s s'. (c', s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b' s \<Longrightarrow> P s'" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
126 |
by (auto dest!: equiv_up_toD1 [OF c'] simp: bequiv_up_to_subst [OF b']) |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
127 |
|
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
128 |
note equiv_up_to_while_lemma [OF _ b c] |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
129 |
equiv_up_to_while_lemma [OF _ b' c'] |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
130 |
thus ?thesis using I I' by (auto intro!: equiv_up_toI) |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
131 |
qed |
44070 | 132 |
|
133 |
lemma equiv_up_to_while_weak: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
134 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P \<Turnstile> c \<sim> c' \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
135 |
(\<And>s s'. (c, s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b s \<Longrightarrow> P s') \<Longrightarrow> |
44070 | 136 |
P \<Turnstile> WHILE b DO c \<sim> WHILE b' DO c'" |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
137 |
by (fastforce elim!: equiv_up_to_while equiv_up_to_weaken) |
44070 | 138 |
|
139 |
lemma equiv_up_to_if: |
|
44261 | 140 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> (\<lambda>s. P s \<and> bval b s) \<Turnstile> c \<sim> c' \<Longrightarrow> (\<lambda>s. P s \<and> \<not>bval b s) \<Turnstile> d \<sim> d' \<Longrightarrow> |
44070 | 141 |
P \<Turnstile> IF b THEN c ELSE d \<sim> IF b' THEN c' ELSE d'" |
142 |
by (auto simp: bequiv_up_to_def equiv_up_to_def) |
|
143 |
||
144 |
lemma equiv_up_to_if_weak: |
|
145 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P \<Turnstile> c \<sim> c' \<Longrightarrow> P \<Turnstile> d \<sim> d' \<Longrightarrow> |
|
146 |
P \<Turnstile> IF b THEN c ELSE d \<sim> IF b' THEN c' ELSE d'" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44261
diff
changeset
|
147 |
by (fastforce elim!: equiv_up_to_if equiv_up_to_weaken) |
44070 | 148 |
|
149 |
lemma equiv_up_to_if_True [intro!]: |
|
150 |
"(\<And>s. P s \<Longrightarrow> bval b s) \<Longrightarrow> P \<Turnstile> IF b THEN c1 ELSE c2 \<sim> c1" |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
151 |
by (auto simp: equiv_up_to_def) |
44070 | 152 |
|
153 |
lemma equiv_up_to_if_False [intro!]: |
|
154 |
"(\<And>s. P s \<Longrightarrow> \<not> bval b s) \<Longrightarrow> P \<Turnstile> IF b THEN c1 ELSE c2 \<sim> c2" |
|
155 |
by (auto simp: equiv_up_to_def) |
|
156 |
||
157 |
lemma equiv_up_to_while_False [intro!]: |
|
158 |
"(\<And>s. P s \<Longrightarrow> \<not> bval b s) \<Longrightarrow> P \<Turnstile> WHILE b DO c \<sim> SKIP" |
|
159 |
by (auto simp: equiv_up_to_def) |
|
160 |
||
45200 | 161 |
lemma while_never: "(c, s) \<Rightarrow> u \<Longrightarrow> c \<noteq> WHILE (Bc True) DO c'" |
44070 | 162 |
by (induct rule: big_step_induct) auto |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
163 |
|
44070 | 164 |
lemma equiv_up_to_while_True [intro!,simp]: |
45200 | 165 |
"P \<Turnstile> WHILE Bc True DO c \<sim> WHILE Bc True DO SKIP" |
44070 | 166 |
unfolding equiv_up_to_def |
167 |
by (blast dest: while_never) |
|
168 |
||
169 |
||
44261 | 170 |
end |