equal
deleted
inserted
replaced
2 imports Main "~~/src/HOL/Library/Predicate_Compile_Alternative_Defs" |
2 imports Main "~~/src/HOL/Library/Predicate_Compile_Alternative_Defs" |
3 begin |
3 begin |
4 |
4 |
5 declare [[values_timeout = 480.0]] |
5 declare [[values_timeout = 480.0]] |
6 |
6 |
7 section {* Formal Languages *} |
7 section \<open>Formal Languages\<close> |
8 |
8 |
9 subsection {* General Context Free Grammars *} |
9 subsection \<open>General Context Free Grammars\<close> |
10 |
10 |
11 text {* a contribution by Aditi Barthwal *} |
11 text \<open>a contribution by Aditi Barthwal\<close> |
12 |
12 |
13 datatype ('nts,'ts) symbol = NTS 'nts |
13 datatype ('nts,'ts) symbol = NTS 'nts |
14 | TS 'ts |
14 | TS 'ts |
15 |
15 |
16 |
16 |
71 |
71 |
72 code_pred [inductify, skip_proof] test2 . |
72 code_pred [inductify, skip_proof] test2 . |
73 |
73 |
74 values "{rhs. test2 rhs}" |
74 values "{rhs. test2 rhs}" |
75 |
75 |
76 subsection {* Some concrete Context Free Grammars *} |
76 subsection \<open>Some concrete Context Free Grammars\<close> |
77 |
77 |
78 datatype alphabet = a | b |
78 datatype alphabet = a | b |
79 |
79 |
80 inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where |
80 inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where |
81 "[] \<in> S\<^sub>1" |
81 "[] \<in> S\<^sub>1" |
131 |
131 |
132 code_pred (expected_modes: o => bool, i => bool) S\<^sub>4p . |
132 code_pred (expected_modes: o => bool, i => bool) S\<^sub>4p . |
133 |
133 |
134 hide_const a b |
134 hide_const a b |
135 |
135 |
136 section {* Semantics of programming languages *} |
136 section \<open>Semantics of programming languages\<close> |
137 |
137 |
138 subsection {* IMP *} |
138 subsection \<open>IMP\<close> |
139 |
139 |
140 type_synonym var = nat |
140 type_synonym var = nat |
141 type_synonym state = "int list" |
141 type_synonym state = "int list" |
142 |
142 |
143 datatype com = |
143 datatype com = |
160 |
160 |
161 values "{t. exec |
161 values "{t. exec |
162 (While (%s. s!0 > 0) (Seq (Ass 0 (%s. s!0 - 1)) (Ass 1 (%s. s!1 + 1)))) |
162 (While (%s. s!0 > 0) (Seq (Ass 0 (%s. s!0 - 1)) (Ass 1 (%s. s!1 + 1)))) |
163 [3,5] t}" |
163 [3,5] t}" |
164 |
164 |
165 subsection {* Lambda *} |
165 subsection \<open>Lambda\<close> |
166 |
166 |
167 datatype type = |
167 datatype type = |
168 Atom nat |
168 Atom nat |
169 | Fun type type (infixr "\<Rightarrow>" 200) |
169 | Fun type type (infixr "\<Rightarrow>" 200) |
170 |
170 |
227 code_pred [dseq] typing . |
227 code_pred [dseq] typing . |
228 code_pred [random_dseq] typing . |
228 code_pred [random_dseq] typing . |
229 |
229 |
230 values [random_dseq 1,1,5] 10 "{(\<Gamma>, t, T). \<Gamma> \<turnstile> t : T}" |
230 values [random_dseq 1,1,5] 10 "{(\<Gamma>, t, T). \<Gamma> \<turnstile> t : T}" |
231 |
231 |
232 subsection {* A minimal example of yet another semantics *} |
232 subsection \<open>A minimal example of yet another semantics\<close> |
233 |
233 |
234 text {* thanks to Elke Salecker *} |
234 text \<open>thanks to Elke Salecker\<close> |
235 |
235 |
236 type_synonym vname = nat |
236 type_synonym vname = nat |
237 type_synonym vvalue = int |
237 type_synonym vvalue = int |
238 type_synonym var_assign = "vname \<Rightarrow> vvalue" --"variable assignment" |
238 type_synonym var_assign = "vname \<Rightarrow> vvalue" \<comment>"variable assignment" |
239 |
239 |
240 datatype ir_expr = |
240 datatype ir_expr = |
241 IrConst vvalue |
241 IrConst vvalue |
242 | ObjAddr vname |
242 | ObjAddr vname |
243 | Add ir_expr ir_expr |
243 | Add ir_expr ir_expr |
260 code_pred eval_var . |
260 code_pred eval_var . |
261 thm eval_var.equation |
261 thm eval_var.equation |
262 |
262 |
263 values "{val. eval_var (Add (IrConst 1) (IrConst 2)) (| Env = (\<lambda>x. 0)|) val}" |
263 values "{val. eval_var (Add (IrConst 1) (IrConst 2)) (| Env = (\<lambda>x. 0)|) val}" |
264 |
264 |
265 subsection {* Another semantics *} |
265 subsection \<open>Another semantics\<close> |
266 |
266 |
267 type_synonym name = nat --"For simplicity in examples" |
267 type_synonym name = nat \<comment>"For simplicity in examples" |
268 type_synonym state' = "name \<Rightarrow> nat" |
268 type_synonym state' = "name \<Rightarrow> nat" |
269 |
269 |
270 datatype aexp = N nat | V name | Plus aexp aexp |
270 datatype aexp = N nat | V name | Plus aexp aexp |
271 |
271 |
272 fun aval :: "aexp \<Rightarrow> state' \<Rightarrow> nat" where |
272 fun aval :: "aexp \<Rightarrow> state' \<Rightarrow> nat" where |
319 (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc |
319 (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc |
320 (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0) |
320 (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0) |
321 )))))))))))))))))))))))))))))))))))))))))]}"] "{list s 2|s. (SKIP, nth [42, 43]) \<Rightarrow> s}" |
321 )))))))))))))))))))))))))))))))))))))))))]}"] "{list s 2|s. (SKIP, nth [42, 43]) \<Rightarrow> s}" |
322 |
322 |
323 |
323 |
324 subsection {* CCS *} |
324 subsection \<open>CCS\<close> |
325 |
325 |
326 text{* This example formalizes finite CCS processes without communication or |
326 text\<open>This example formalizes finite CCS processes without communication or |
327 recursion. For simplicity, labels are natural numbers. *} |
327 recursion. For simplicity, labels are natural numbers.\<close> |
328 |
328 |
329 datatype proc = nil | pre nat proc | or proc proc | par proc proc |
329 datatype proc = nil | pre nat proc | or proc proc | par proc proc |
330 |
330 |
331 inductive step :: "proc \<Rightarrow> nat \<Rightarrow> proc \<Rightarrow> bool" where |
331 inductive step :: "proc \<Rightarrow> nat \<Rightarrow> proc \<Rightarrow> bool" where |
332 "step (pre n p) n p" | |
332 "step (pre n p) n p" | |