17 "program \<equiv> {<init, acts, allowed>: |
17 "program \<equiv> {<init, acts, allowed>: |
18 Pow(state) * Pow(Pow(state*state)) * Pow(Pow(state*state)). |
18 Pow(state) * Pow(Pow(state*state)) * Pow(Pow(state*state)). |
19 id(state) \<in> acts \<and> id(state) \<in> allowed}" |
19 id(state) \<in> acts \<and> id(state) \<in> allowed}" |
20 |
20 |
21 definition |
21 definition |
22 mk_program :: "[i,i,i]=>i" where |
22 mk_program :: "[i,i,i]\<Rightarrow>i" where |
23 \<comment> \<open>The definition yields a program thanks to the coercions |
23 \<comment> \<open>The definition yields a program thanks to the coercions |
24 init \<inter> state, acts \<inter> Pow(state*state), etc.\<close> |
24 init \<inter> state, acts \<inter> Pow(state*state), etc.\<close> |
25 "mk_program(init, acts, allowed) \<equiv> |
25 "mk_program(init, acts, allowed) \<equiv> |
26 <init \<inter> state, cons(id(state), acts \<inter> Pow(state*state)), |
26 <init \<inter> state, cons(id(state), acts \<inter> Pow(state*state)), |
27 cons(id(state), allowed \<inter> Pow(state*state))>" |
27 cons(id(state), allowed \<inter> Pow(state*state))>" |
30 SKIP :: i (\<open>\<bottom>\<close>) where |
30 SKIP :: i (\<open>\<bottom>\<close>) where |
31 "SKIP \<equiv> mk_program(state, 0, Pow(state*state))" |
31 "SKIP \<equiv> mk_program(state, 0, Pow(state*state))" |
32 |
32 |
33 (* Coercion from anything to program *) |
33 (* Coercion from anything to program *) |
34 definition |
34 definition |
35 programify :: "i=>i" where |
35 programify :: "i\<Rightarrow>i" where |
36 "programify(F) \<equiv> if F \<in> program then F else SKIP" |
36 "programify(F) \<equiv> if F \<in> program then F else SKIP" |
37 |
37 |
38 definition |
38 definition |
39 RawInit :: "i=>i" where |
39 RawInit :: "i\<Rightarrow>i" where |
40 "RawInit(F) \<equiv> fst(F)" |
40 "RawInit(F) \<equiv> fst(F)" |
41 |
41 |
42 definition |
42 definition |
43 Init :: "i=>i" where |
43 Init :: "i\<Rightarrow>i" where |
44 "Init(F) \<equiv> RawInit(programify(F))" |
44 "Init(F) \<equiv> RawInit(programify(F))" |
45 |
45 |
46 definition |
46 definition |
47 RawActs :: "i=>i" where |
47 RawActs :: "i\<Rightarrow>i" where |
48 "RawActs(F) \<equiv> cons(id(state), fst(snd(F)))" |
48 "RawActs(F) \<equiv> cons(id(state), fst(snd(F)))" |
49 |
49 |
50 definition |
50 definition |
51 Acts :: "i=>i" where |
51 Acts :: "i\<Rightarrow>i" where |
52 "Acts(F) \<equiv> RawActs(programify(F))" |
52 "Acts(F) \<equiv> RawActs(programify(F))" |
53 |
53 |
54 definition |
54 definition |
55 RawAllowedActs :: "i=>i" where |
55 RawAllowedActs :: "i\<Rightarrow>i" where |
56 "RawAllowedActs(F) \<equiv> cons(id(state), snd(snd(F)))" |
56 "RawAllowedActs(F) \<equiv> cons(id(state), snd(snd(F)))" |
57 |
57 |
58 definition |
58 definition |
59 AllowedActs :: "i=>i" where |
59 AllowedActs :: "i\<Rightarrow>i" where |
60 "AllowedActs(F) \<equiv> RawAllowedActs(programify(F))" |
60 "AllowedActs(F) \<equiv> RawAllowedActs(programify(F))" |
61 |
61 |
62 |
62 |
63 definition |
63 definition |
64 Allowed :: "i =>i" where |
64 Allowed :: "i \<Rightarrow>i" where |
65 "Allowed(F) \<equiv> {G \<in> program. Acts(G) \<subseteq> AllowedActs(F)}" |
65 "Allowed(F) \<equiv> {G \<in> program. Acts(G) \<subseteq> AllowedActs(F)}" |
66 |
66 |
67 definition |
67 definition |
68 initially :: "i=>i" where |
68 initially :: "i\<Rightarrow>i" where |
69 "initially(A) \<equiv> {F \<in> program. Init(F)\<subseteq>A}" |
69 "initially(A) \<equiv> {F \<in> program. Init(F)\<subseteq>A}" |
70 |
70 |
71 definition "constrains" :: "[i, i] => i" (infixl \<open>co\<close> 60) where |
71 definition "constrains" :: "[i, i] \<Rightarrow> i" (infixl \<open>co\<close> 60) where |
72 "A co B \<equiv> {F \<in> program. (\<forall>act \<in> Acts(F). act``A\<subseteq>B) \<and> st_set(A)}" |
72 "A co B \<equiv> {F \<in> program. (\<forall>act \<in> Acts(F). act``A\<subseteq>B) \<and> st_set(A)}" |
73 \<comment> \<open>the condition \<^term>\<open>st_set(A)\<close> makes the definition slightly |
73 \<comment> \<open>the condition \<^term>\<open>st_set(A)\<close> makes the definition slightly |
74 stronger than the HOL one\<close> |
74 stronger than the HOL one\<close> |
75 |
75 |
76 definition unless :: "[i, i] => i" (infixl \<open>unless\<close> 60) where |
76 definition unless :: "[i, i] \<Rightarrow> i" (infixl \<open>unless\<close> 60) where |
77 "A unless B \<equiv> (A - B) co (A \<union> B)" |
77 "A unless B \<equiv> (A - B) co (A \<union> B)" |
78 |
78 |
79 definition |
79 definition |
80 stable :: "i=>i" where |
80 stable :: "i\<Rightarrow>i" where |
81 "stable(A) \<equiv> A co A" |
81 "stable(A) \<equiv> A co A" |
82 |
82 |
83 definition |
83 definition |
84 strongest_rhs :: "[i, i] => i" where |
84 strongest_rhs :: "[i, i] \<Rightarrow> i" where |
85 "strongest_rhs(F, A) \<equiv> \<Inter>({B \<in> Pow(state). F \<in> A co B})" |
85 "strongest_rhs(F, A) \<equiv> \<Inter>({B \<in> Pow(state). F \<in> A co B})" |
86 |
86 |
87 definition |
87 definition |
88 invariant :: "i => i" where |
88 invariant :: "i \<Rightarrow> i" where |
89 "invariant(A) \<equiv> initially(A) \<inter> stable(A)" |
89 "invariant(A) \<equiv> initially(A) \<inter> stable(A)" |
90 |
90 |
91 (* meta-function composition *) |
91 (* meta-function composition *) |
92 definition |
92 definition |
93 metacomp :: "[i=>i, i=>i] => (i=>i)" (infixl \<open>comp\<close> 65) where |
93 metacomp :: "[i\<Rightarrow>i, i\<Rightarrow>i] \<Rightarrow> (i\<Rightarrow>i)" (infixl \<open>comp\<close> 65) where |
94 "f comp g \<equiv> %x. f(g(x))" |
94 "f comp g \<equiv> \<lambda>x. f(g(x))" |
95 |
95 |
96 definition |
96 definition |
97 pg_compl :: "i=>i" where |
97 pg_compl :: "i\<Rightarrow>i" where |
98 "pg_compl(X)\<equiv> program - X" |
98 "pg_compl(X)\<equiv> program - X" |
99 |
99 |
100 text\<open>SKIP\<close> |
100 text\<open>SKIP\<close> |
101 lemma SKIP_in_program [iff,TC]: "SKIP \<in> program" |
101 lemma SKIP_in_program [iff,TC]: "SKIP \<in> program" |
102 by (force simp add: SKIP_def program_def mk_program_def) |
102 by (force simp add: SKIP_def program_def mk_program_def) |