| author | paulson <lp15@cam.ac.uk> | 
| Wed, 31 Jul 2024 18:47:05 +0100 | |
| changeset 80651 | 2cffa664482d | 
| parent 69597 | ff784d5a5bfb | 
| permissions | -rw-r--r-- | 
| 2570 | 1 | (* Specification of the following loop back device | 
| 2 | ||
| 3 | ||
| 17291 | 4 | g | 
| 2570 | 5 | -------------------- | 
| 6 | | ------- | | |
| 7 | x | | | | y | |
| 17291 | 8 | ------|---->| |------| -----> | 
| 2570 | 9 | | z | f | z | | 
| 10 | | -->| |--- | | |
| 11 | | | | | | | | |
| 12 | | | ------- | | | |
| 13 | | | | | | |
| 14 | | <-------------- | | |
| 17291 | 15 | | | | 
| 2570 | 16 | -------------------- | 
| 17 | ||
| 18 | ||
| 19 | First step: Notation in Agent Network Description Language (ANDL) | |
| 20 | ----------------------------------------------------------------- | |
| 21 | ||
| 22 | agent f | |
| 17291 | 23 |         input  channel i1:'b i2: ('b,'c) tc
 | 
| 24 |         output channel o1:'c o2: ('b,'c) tc
 | |
| 2570 | 25 | is | 
| 17291 | 26 | Rf(i1,i2,o1,o2) (left open in the example) | 
| 2570 | 27 | end f | 
| 28 | ||
| 29 | agent g | |
| 17291 | 30 | input channel x:'b | 
| 31 | output channel y:'c | |
| 2570 | 32 | is network | 
| 35916 | 33 | (y,z) = f$(x,z) | 
| 2570 | 34 | end network | 
| 35 | end g | |
| 36 | ||
| 37 | ||
| 38 | Remark: the type of the feedback depends at most on the types of the input and | |
| 39 | output of g. (No type miracles inside g) | |
| 40 | ||
| 41 | Second step: Translation of ANDL specification to HOLCF Specification | |
| 42 | --------------------------------------------------------------------- | |
| 43 | ||
| 44 | Specification of agent f ist translated to predicate is_f | |
| 45 | ||
| 17291 | 46 | is_f :: ('b stream * ('b,'c) tc stream ->
 | 
| 47 |                 'c stream * ('b,'c) tc stream) => bool
 | |
| 2570 | 48 | |
| 17291 | 49 | is_f f = !i1 i2 o1 o2. | 
| 35916 | 50 | f$(i1,i2) = (o1,o2) --> Rf(i1,i2,o1,o2) | 
| 2570 | 51 | |
| 52 | Specification of agent g is translated to predicate is_g which uses | |
| 53 | predicate is_net_g | |
| 54 | ||
| 55 | is_net_g :: ('b stream * ('b,'c) tc stream -> 'c stream * ('b,'c) tc stream) =>
 | |
| 17291 | 56 | 'b stream => 'c stream => bool | 
| 2570 | 57 | |
| 17291 | 58 | is_net_g f x y = | 
| 35916 | 59 | ? z. (y,z) = f$(x,z) & | 
| 60 | !oy hz. (oy,hz) = f$(x,hz) --> z << hz | |
| 2570 | 61 | |
| 62 | ||
| 63 | is_g :: ('b stream -> 'c stream) => bool
 | |
| 64 | ||
| 10835 | 65 | is_g g = ? f. is_f f & (!x y. g$x = y --> is_net_g f x y | 
| 17291 | 66 | |
| 2570 | 67 | Third step: (show conservativity) | 
| 68 | ----------- | |
| 69 | ||
| 70 | Suppose we have a model for the theory TH1 which contains the axiom | |
| 71 | ||
| 17291 | 72 | ? f. is_f f | 
| 2570 | 73 | |
| 74 | In this case there is also a model for the theory TH2 that enriches TH1 by | |
| 75 | axiom | |
| 76 | ||
| 17291 | 77 | ? g. is_g g | 
| 2570 | 78 | |
| 79 | The result is proved by showing that there is a definitional extension | |
| 80 | that extends TH1 by a definition of g. | |
| 81 | ||
| 82 | ||
| 83 | We define: | |
| 84 | ||
| 17291 | 85 | def_g g = | 
| 86 | (? f. is_f f & | |
| 35916 | 87 | g = (LAM x. fst (f$(x,fix$(LAM k. snd (f$(x,k)))))) ) | 
| 17291 | 88 | |
| 2570 | 89 | Now we prove: | 
| 90 | ||
| 17291 | 91 | (? f. is_f f ) --> (? g. is_g g) | 
| 2570 | 92 | |
| 93 | using the theorems | |
| 94 | ||
| 17291 | 95 | loopback_eq) def_g = is_g (real work) | 
| 2570 | 96 | |
| 17291 | 97 | L1) (? f. is_f f ) --> (? g. def_g g) (trivial) | 
| 2570 | 98 | |
| 99 | *) | |
| 100 | ||
| 17291 | 101 | theory Focus_ex | 
| 66453 
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
 wenzelm parents: 
63549diff
changeset | 102 | imports "HOLCF-Library.Stream" | 
| 17291 | 103 | begin | 
| 2570 | 104 | |
| 17291 | 105 | typedecl ('a, 'b) tc
 | 
| 55381 | 106 | axiomatization where tc_arity: "OFCLASS(('a::pcpo, 'b::pcpo) tc, pcop_class)"
 | 
| 107 | instance tc :: (pcpo, pcpo) pcpo by (rule tc_arity) | |
| 2570 | 108 | |
| 25135 
4f8176c940cf
modernized specifications ('definition', 'axiomatization');
 wenzelm parents: 
21404diff
changeset | 109 | axiomatization | 
| 63549 | 110 |   Rf :: "('b stream * ('b,'c) tc stream * 'c stream * ('b,'c) tc stream) \<Rightarrow> bool"
 | 
| 2570 | 111 | |
| 19763 | 112 | definition | 
| 63549 | 113 |   is_f :: "('b stream * ('b,'c) tc stream \<rightarrow> 'c stream * ('b,'c) tc stream) \<Rightarrow> bool" where
 | 
| 114 | "is_f f \<longleftrightarrow> (\<forall>i1 i2 o1 o2. f\<cdot>(i1, i2) = (o1, o2) \<longrightarrow> Rf (i1, i2, o1, o2))" | |
| 2570 | 115 | |
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19763diff
changeset | 116 | definition | 
| 63549 | 117 |   is_net_g :: "('b stream * ('b,'c) tc stream \<rightarrow> 'c stream * ('b,'c) tc stream) \<Rightarrow>
 | 
| 118 | 'b stream \<Rightarrow> 'c stream \<Rightarrow> bool" where | |
| 119 | "is_net_g f x y \<equiv> (\<exists>z. | |
| 120 | (y, z) = f\<cdot>(x,z) \<and> | |
| 121 | (\<forall>oy hz. (oy, hz) = f\<cdot>(x, hz) \<longrightarrow> z << hz))" | |
| 2570 | 122 | |
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19763diff
changeset | 123 | definition | 
| 63549 | 124 |   is_g :: "('b stream \<rightarrow> 'c stream) \<Rightarrow> bool" where
 | 
| 125 | "is_g g \<equiv> (\<exists>f. is_f f \<and> (\<forall>x y. g\<cdot>x = y \<longrightarrow> is_net_g f x y))" | |
| 2570 | 126 | |
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19763diff
changeset | 127 | definition | 
| 63549 | 128 |   def_g :: "('b stream \<rightarrow> 'c stream) => bool" where
 | 
| 129 | "def_g g \<equiv> (\<exists>f. is_f f \<and> g = (LAM x. fst (f\<cdot>(x, fix\<cdot>(LAM k. snd (f\<cdot>(x, k)))))))" | |
| 17291 | 130 | |
| 19742 | 131 | |
| 132 | (* first some logical trading *) | |
| 133 | ||
| 134 | lemma lemma1: | |
| 63549 | 135 | "is_g g \<longleftrightarrow> | 
| 136 | (\<exists>f. is_f(f) \<and> (\<forall>x.(\<exists>z. (g\<cdot>x,z) = f\<cdot>(x,z) \<and> (\<forall>w y. (y, w) = f\<cdot>(x, w) \<longrightarrow> z << w))))" | |
| 19763 | 137 | apply (simp add: is_g_def is_net_g_def) | 
| 19742 | 138 | apply fast | 
| 139 | done | |
| 140 | ||
| 141 | lemma lemma2: | |
| 63549 | 142 | "(\<exists>f. is_f f \<and> (\<forall>x. (\<exists>z. (g\<cdot>x, z) = f\<cdot>(x, z) \<and> (\<forall>w y. (y, w) = f\<cdot>(x,w) \<longrightarrow> z << w)))) \<longleftrightarrow> | 
| 143 | (\<exists>f. is_f f \<and> (\<forall>x. \<exists>z. | |
| 144 | g\<cdot>x = fst (f\<cdot>(x, z)) \<and> | |
| 145 | z = snd (f\<cdot>(x, z)) \<and> | |
| 146 | (\<forall>w y. (y, w) = f\<cdot>(x, w) \<longrightarrow> z << w)))" | |
| 19742 | 147 | apply (rule iffI) | 
| 148 | apply (erule exE) | |
| 149 | apply (rule_tac x = "f" in exI) | |
| 150 | apply (erule conjE)+ | |
| 151 | apply (erule conjI) | |
| 152 | apply (intro strip) | |
| 153 | apply (erule allE) | |
| 154 | apply (erule exE) | |
| 155 | apply (rule_tac x = "z" in exI) | |
| 156 | apply (erule conjE)+ | |
| 157 | apply (rule conjI) | |
| 158 | apply (rule_tac [2] conjI) | |
| 159 | prefer 3 apply (assumption) | |
| 160 | apply (drule sym) | |
| 40028 | 161 | apply (simp) | 
| 19742 | 162 | apply (drule sym) | 
| 40028 | 163 | apply (simp) | 
| 19742 | 164 | apply (erule exE) | 
| 165 | apply (rule_tac x = "f" in exI) | |
| 166 | apply (erule conjE)+ | |
| 167 | apply (erule conjI) | |
| 168 | apply (intro strip) | |
| 169 | apply (erule allE) | |
| 170 | apply (erule exE) | |
| 171 | apply (rule_tac x = "z" in exI) | |
| 172 | apply (erule conjE)+ | |
| 173 | apply (rule conjI) | |
| 174 | prefer 2 apply (assumption) | |
| 35916 | 175 | apply (rule prod_eqI) | 
| 176 | apply simp | |
| 177 | apply simp | |
| 19742 | 178 | done | 
| 179 | ||
| 63549 | 180 | lemma lemma3: "def_g g \<longrightarrow> is_g g" | 
| 69597 | 181 | apply (tactic \<open>simp_tac (put_simpset HOL_ss \<^context> | 
| 62175 | 182 |   addsimps [@{thm def_g_def}, @{thm lemma1}, @{thm lemma2}]) 1\<close>)
 | 
| 19742 | 183 | apply (rule impI) | 
| 184 | apply (erule exE) | |
| 185 | apply (rule_tac x = "f" in exI) | |
| 186 | apply (erule conjE)+ | |
| 187 | apply (erule conjI) | |
| 188 | apply (intro strip) | |
| 63549 | 189 | apply (rule_tac x = "fix\<cdot>(LAM k. snd (f\<cdot>(x, k)))" in exI) | 
| 19742 | 190 | apply (rule conjI) | 
| 40028 | 191 | apply (simp) | 
| 35916 | 192 | apply (rule prod_eqI, simp, simp) | 
| 19742 | 193 | apply (rule trans) | 
| 194 | apply (rule fix_eq) | |
| 195 | apply (simp (no_asm)) | |
| 196 | apply (intro strip) | |
| 197 | apply (rule fix_least) | |
| 198 | apply (simp (no_asm)) | |
| 199 | apply (erule exE) | |
| 200 | apply (drule sym) | |
| 201 | back | |
| 202 | apply simp | |
| 203 | done | |
| 204 | ||
| 63549 | 205 | lemma lemma4: "is_g g \<longrightarrow> def_g g" | 
| 69597 | 206 | apply (tactic \<open>simp_tac (put_simpset HOL_ss \<^context> | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
41413diff
changeset | 207 |   delsimps (@{thms HOL.ex_simps} @ @{thms HOL.all_simps})
 | 
| 62175 | 208 |   addsimps [@{thm lemma1}, @{thm lemma2}, @{thm def_g_def}]) 1\<close>)
 | 
| 19742 | 209 | apply (rule impI) | 
| 210 | apply (erule exE) | |
| 211 | apply (rule_tac x = "f" in exI) | |
| 212 | apply (erule conjE)+ | |
| 213 | apply (erule conjI) | |
| 40002 
c5b5f7a3a3b1
new theorem names: fun_below_iff, fun_belowI, cfun_eq_iff, cfun_eqI, cfun_below_iff, cfun_belowI
 huffman parents: 
39159diff
changeset | 214 | apply (rule cfun_eqI) | 
| 19742 | 215 | apply (erule_tac x = "x" in allE) | 
| 216 | apply (erule exE) | |
| 217 | apply (erule conjE)+ | |
| 63549 | 218 | apply (subgoal_tac "fix\<cdot>(LAM k. snd (f\<cdot>(x, k))) = z") | 
| 19742 | 219 | apply simp | 
| 63549 | 220 | apply (subgoal_tac "\<forall>w y. f\<cdot>(x, w) = (y, w) \<longrightarrow> z << w") | 
| 19742 | 221 | apply (rule fix_eqI) | 
| 222 | apply simp | |
| 63549 | 223 | apply (subgoal_tac "f\<cdot>(x, za) = (fst (f\<cdot>(x, za)), za)") | 
| 19742 | 224 | apply fast | 
| 35916 | 225 | apply (rule prod_eqI, simp, simp) | 
| 19742 | 226 | apply (intro strip) | 
| 227 | apply (erule allE)+ | |
| 228 | apply (erule mp) | |
| 229 | apply (erule sym) | |
| 230 | done | |
| 231 | ||
| 232 | (* now we assemble the result *) | |
| 233 | ||
| 234 | lemma loopback_eq: "def_g = is_g" | |
| 235 | apply (rule ext) | |
| 236 | apply (rule iffI) | |
| 237 | apply (erule lemma3 [THEN mp]) | |
| 238 | apply (erule lemma4 [THEN mp]) | |
| 239 | done | |
| 240 | ||
| 241 | lemma L2: | |
| 63549 | 242 |   "(\<exists>f. is_f (f::'b stream * ('b,'c) tc stream \<rightarrow> 'c stream * ('b,'c) tc stream)) \<longrightarrow>
 | 
| 243 | (\<exists>g. def_g (g::'b stream \<rightarrow> 'c stream))" | |
| 19763 | 244 | apply (simp add: def_g_def) | 
| 19742 | 245 | done | 
| 246 | ||
| 247 | theorem conservative_loopback: | |
| 63549 | 248 |   "(\<exists>f. is_f (f::'b stream * ('b,'c) tc stream \<rightarrow> 'c stream * ('b,'c) tc stream)) \<longrightarrow>
 | 
| 249 | (\<exists>g. is_g (g::'b stream \<rightarrow> 'c stream))" | |
| 19742 | 250 | apply (rule loopback_eq [THEN subst]) | 
| 251 | apply (rule L2) | |
| 252 | done | |
| 2570 | 253 | |
| 254 | end |