author | wenzelm |
Wed, 28 Dec 2022 12:30:18 +0100 | |
changeset 76798 | 69d8d16c5612 |
parent 67406 | 23307fd33906 |
child 80914 | d97fdabd9e2b |
permissions | -rw-r--r-- |
58889 | 1 |
section "Constant Folding" |
54297 | 2 |
|
44070 | 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 |
||
54296 | 7 |
subsection "Semantic Equivalence up to a Condition" |
8 |
||
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
9 |
type_synonym assn = "state \<Rightarrow> bool" |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
10 |
|
44070 | 11 |
definition |
52021
59963cda805a
explicitly state equivalence relation for sim; tweak syntax of sem_equiv
kleing
parents:
48909
diff
changeset
|
12 |
equiv_up_to :: "assn \<Rightarrow> com \<Rightarrow> com \<Rightarrow> bool" ("_ \<Turnstile> _ \<sim> _" [50,0,10] 50) |
44070 | 13 |
where |
52121 | 14 |
"(P \<Turnstile> c \<sim> c') = (\<forall>s s'. P s \<longrightarrow> (c,s) \<Rightarrow> s' \<longleftrightarrow> (c',s) \<Rightarrow> s')" |
44070 | 15 |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
16 |
definition |
52021
59963cda805a
explicitly state equivalence relation for sim; tweak syntax of sem_equiv
kleing
parents:
48909
diff
changeset
|
17 |
bequiv_up_to :: "assn \<Rightarrow> bexp \<Rightarrow> bexp \<Rightarrow> bool" ("_ \<Turnstile> _ <\<sim>> _" [50,0,10] 50) |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
18 |
where |
52121 | 19 |
"(P \<Turnstile> b <\<sim>> b') = (\<forall>s. P s \<longrightarrow> bval b s = bval b' s)" |
44070 | 20 |
|
21 |
lemma equiv_up_to_True: |
|
22 |
"((\<lambda>_. True) \<Turnstile> c \<sim> c') = (c \<sim> c')" |
|
23 |
by (simp add: equiv_def equiv_up_to_def) |
|
24 |
||
25 |
lemma equiv_up_to_weaken: |
|
26 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (\<And>s. P' s \<Longrightarrow> P s) \<Longrightarrow> P' \<Turnstile> c \<sim> c'" |
|
27 |
by (simp add: equiv_up_to_def) |
|
28 |
||
29 |
lemma equiv_up_toI: |
|
30 |
"(\<And>s s'. P s \<Longrightarrow> (c, s) \<Rightarrow> s' = (c', s) \<Rightarrow> s') \<Longrightarrow> P \<Turnstile> c \<sim> c'" |
|
31 |
by (unfold equiv_up_to_def) blast |
|
32 |
||
33 |
lemma equiv_up_toD1: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
34 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (c, s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> (c', s) \<Rightarrow> s'" |
44070 | 35 |
by (unfold equiv_up_to_def) blast |
36 |
||
37 |
lemma equiv_up_toD2: |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
38 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> (c', s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> (c, s) \<Rightarrow> s'" |
44070 | 39 |
by (unfold equiv_up_to_def) blast |
40 |
||
41 |
||
42 |
lemma equiv_up_to_refl [simp, intro!]: |
|
43 |
"P \<Turnstile> c \<sim> c" |
|
44 |
by (auto simp: equiv_up_to_def) |
|
45 |
||
46 |
lemma equiv_up_to_sym: |
|
47 |
"(P \<Turnstile> c \<sim> c') = (P \<Turnstile> c' \<sim> c)" |
|
48 |
by (auto simp: equiv_up_to_def) |
|
49 |
||
45218 | 50 |
lemma equiv_up_to_trans: |
44070 | 51 |
"P \<Turnstile> c \<sim> c' \<Longrightarrow> P \<Turnstile> c' \<sim> c'' \<Longrightarrow> P \<Turnstile> c \<sim> c''" |
52 |
by (auto simp: equiv_up_to_def) |
|
53 |
||
54 |
||
55 |
lemma bequiv_up_to_refl [simp, intro!]: |
|
56 |
"P \<Turnstile> b <\<sim>> b" |
|
57 |
by (auto simp: bequiv_up_to_def) |
|
58 |
||
59 |
lemma bequiv_up_to_sym: |
|
60 |
"(P \<Turnstile> b <\<sim>> b') = (P \<Turnstile> b' <\<sim>> b)" |
|
61 |
by (auto simp: bequiv_up_to_def) |
|
62 |
||
45218 | 63 |
lemma bequiv_up_to_trans: |
44070 | 64 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P \<Turnstile> b' <\<sim>> b'' \<Longrightarrow> P \<Turnstile> b <\<sim>> b''" |
65 |
by (auto simp: bequiv_up_to_def) |
|
66 |
||
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
67 |
lemma bequiv_up_to_subst: |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
68 |
"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
|
69 |
by (simp add: bequiv_up_to_def) |
44070 | 70 |
|
71 |
||
47818 | 72 |
lemma equiv_up_to_seq: |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
73 |
"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
|
74 |
(\<And>s s'. (c,s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> Q s') \<Longrightarrow> |
52046
bc01725d7918
replaced `;' by `;;' to disambiguate syntax; unexpected slight increase in build time
nipkow
parents:
52021
diff
changeset
|
75 |
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
|
76 |
by (clarsimp simp: equiv_up_to_def) blast |
44070 | 77 |
|
55598 | 78 |
lemma equiv_up_to_while_lemma_weak: |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
79 |
shows "(d,s) \<Rightarrow> s' \<Longrightarrow> |
44070 | 80 |
P \<Turnstile> b <\<sim>> b' \<Longrightarrow> |
55598 | 81 |
P \<Turnstile> c \<sim> c' \<Longrightarrow> |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
82 |
(\<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
|
83 |
P s \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
84 |
d = WHILE b DO c \<Longrightarrow> |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
85 |
(WHILE b' DO c', s) \<Rightarrow> s'" |
45015 | 86 |
proof (induction rule: big_step_induct) |
44070 | 87 |
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
|
88 |
hence IH: "P s2 \<Longrightarrow> (WHILE b' DO c', s2) \<Rightarrow> s3" by auto |
44070 | 89 |
from WhileTrue.prems |
90 |
have "P \<Turnstile> b <\<sim>> b'" by simp |
|
67406 | 91 |
with \<open>bval b s1\<close> \<open>P s1\<close> |
44070 | 92 |
have "bval b' s1" by (simp add: bequiv_up_to_def) |
93 |
moreover |
|
94 |
from WhileTrue.prems |
|
55598 | 95 |
have "P \<Turnstile> c \<sim> c'" by simp |
67406 | 96 |
with \<open>bval b s1\<close> \<open>P s1\<close> \<open>(c, s1) \<Rightarrow> s2\<close> |
44070 | 97 |
have "(c', s1) \<Rightarrow> s2" by (simp add: equiv_up_to_def) |
98 |
moreover |
|
99 |
from WhileTrue.prems |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
100 |
have "\<And>s s'. (c,s) \<Rightarrow> s' \<Longrightarrow> P s \<Longrightarrow> bval b s \<Longrightarrow> P s'" by simp |
67406 | 101 |
with \<open>P s1\<close> \<open>bval b s1\<close> \<open>(c, s1) \<Rightarrow> s2\<close> |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
102 |
have "P s2" by simp |
44070 | 103 |
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
|
104 |
ultimately |
44070 | 105 |
show ?case by blast |
106 |
next |
|
107 |
case WhileFalse |
|
108 |
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
|
109 |
qed (fastforce simp: equiv_up_to_def bequiv_up_to_def)+ |
44070 | 110 |
|
55598 | 111 |
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
|
112 |
assumes b: "P \<Turnstile> b <\<sim>> b'" |
55598 | 113 |
assumes c: "P \<Turnstile> c \<sim> c'" |
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
proof - |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
117 |
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
|
118 |
|
55598 | 119 |
from c b have c': "P \<Turnstile> c' \<sim> c" by (simp add: equiv_up_to_sym) |
48909
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 I |
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
|
55598 | 125 |
note equiv_up_to_while_lemma_weak [OF _ b c] |
126 |
equiv_up_to_while_lemma_weak [OF _ b' c'] |
|
48909
b2dea007e55e
remove Hoare dependency from Fold.thy
Gerwin Klein <gerwin.klein@nicta.com.au>
parents:
47818
diff
changeset
|
127 |
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
|
128 |
qed |
44070 | 129 |
|
130 |
lemma equiv_up_to_if_weak: |
|
131 |
"P \<Turnstile> b <\<sim>> b' \<Longrightarrow> P \<Turnstile> c \<sim> c' \<Longrightarrow> P \<Turnstile> d \<sim> d' \<Longrightarrow> |
|
132 |
P \<Turnstile> IF b THEN c ELSE d \<sim> IF b' THEN c' ELSE d'" |
|
55598 | 133 |
by (auto simp: bequiv_up_to_def equiv_up_to_def) |
44070 | 134 |
|
135 |
lemma equiv_up_to_if_True [intro!]: |
|
136 |
"(\<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
|
137 |
by (auto simp: equiv_up_to_def) |
44070 | 138 |
|
139 |
lemma equiv_up_to_if_False [intro!]: |
|
140 |
"(\<And>s. P s \<Longrightarrow> \<not> bval b s) \<Longrightarrow> P \<Turnstile> IF b THEN c1 ELSE c2 \<sim> c2" |
|
141 |
by (auto simp: equiv_up_to_def) |
|
142 |
||
143 |
lemma equiv_up_to_while_False [intro!]: |
|
144 |
"(\<And>s. P s \<Longrightarrow> \<not> bval b s) \<Longrightarrow> P \<Turnstile> WHILE b DO c \<sim> SKIP" |
|
145 |
by (auto simp: equiv_up_to_def) |
|
146 |
||
45200 | 147 |
lemma while_never: "(c, s) \<Rightarrow> u \<Longrightarrow> c \<noteq> WHILE (Bc True) DO c'" |
44070 | 148 |
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
|
149 |
|
44070 | 150 |
lemma equiv_up_to_while_True [intro!,simp]: |
45200 | 151 |
"P \<Turnstile> WHILE Bc True DO c \<sim> WHILE Bc True DO SKIP" |
44070 | 152 |
unfolding equiv_up_to_def |
153 |
by (blast dest: while_never) |
|
154 |
||
155 |
||
44261 | 156 |
end |