src/HOL/Predicate_Compile_Examples/Examples.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 66453 cc19f7ca2ed6
child 67443 3abf6a722518
permissions -rw-r--r--
more robust sorted_entries;
bulwahn@39655
     1
theory Examples
wenzelm@66453
     2
imports Main "HOL-Library.Predicate_Compile_Alternative_Defs"
bulwahn@39655
     3
begin
bulwahn@39655
     4
krauss@42208
     5
declare [[values_timeout = 480.0]]
krauss@42187
     6
wenzelm@63167
     7
section \<open>Formal Languages\<close>
bulwahn@39655
     8
wenzelm@63167
     9
subsection \<open>General Context Free Grammars\<close>
bulwahn@39655
    10
wenzelm@63167
    11
text \<open>a contribution by Aditi Barthwal\<close>
bulwahn@39655
    12
blanchet@58310
    13
datatype ('nts,'ts) symbol = NTS 'nts
bulwahn@39655
    14
                            | TS 'ts
bulwahn@39655
    15
bulwahn@39655
    16
                            
blanchet@58310
    17
datatype ('nts,'ts) rule = rule 'nts "('nts,'ts) symbol list"
bulwahn@39655
    18
wenzelm@42463
    19
type_synonym ('nts,'ts) grammar = "('nts,'ts) rule set * 'nts"
bulwahn@39655
    20
bulwahn@39655
    21
fun rules :: "('nts,'ts) grammar => ('nts,'ts) rule set"
bulwahn@39655
    22
where
bulwahn@39655
    23
  "rules (r, s) = r"
bulwahn@39655
    24
bulwahn@39655
    25
definition derives 
bulwahn@39655
    26
where
bulwahn@39655
    27
"derives g = { (lsl,rsl). \<exists>s1 s2 lhs rhs. 
bulwahn@39655
    28
                         (s1 @ [NTS lhs] @ s2 = lsl) \<and>
bulwahn@39655
    29
                         (s1 @ rhs @ s2) = rsl \<and>
bulwahn@39655
    30
                         (rule lhs rhs) \<in> fst g }"
bulwahn@39655
    31
wenzelm@52666
    32
definition derivesp ::
wenzelm@52666
    33
  "(('nts, 'ts) rule => bool) * 'nts => ('nts, 'ts) symbol list => ('nts, 'ts) symbol list => bool"
haftmann@45970
    34
where
haftmann@45970
    35
  "derivesp g = (\<lambda> lhs rhs. (lhs, rhs) \<in> derives (Collect (fst g), snd g))"
haftmann@45970
    36
 
haftmann@45970
    37
lemma [code_pred_def]:
haftmann@45970
    38
  "derivesp g = (\<lambda> lsl rsl. \<exists>s1 s2 lhs rhs. 
haftmann@45970
    39
                         (s1 @ [NTS lhs] @ s2 = lsl) \<and>
haftmann@45970
    40
                         (s1 @ rhs @ s2) = rsl \<and>
haftmann@45970
    41
                         (fst g) (rule lhs rhs))"
haftmann@45970
    42
unfolding derivesp_def derives_def by auto
haftmann@45970
    43
bulwahn@39655
    44
abbreviation "example_grammar == 
bulwahn@39655
    45
({ rule ''S'' [NTS ''A'', NTS ''B''],
bulwahn@39655
    46
   rule ''S'' [TS ''a''],
bulwahn@39655
    47
  rule ''A'' [TS ''b'']}, ''S'')"
bulwahn@39655
    48
haftmann@45970
    49
definition "example_rules == 
haftmann@45970
    50
(%x. x = rule ''S'' [NTS ''A'', NTS ''B''] \<or>
haftmann@45970
    51
   x = rule ''S'' [TS ''a''] \<or>
haftmann@45970
    52
  x = rule ''A'' [TS ''b''])"
bulwahn@39655
    53
bulwahn@39655
    54
haftmann@45970
    55
code_pred [inductify, skip_proof] derivesp .
haftmann@45970
    56
haftmann@45970
    57
thm derivesp.equation
bulwahn@39655
    58
haftmann@45970
    59
definition "testp = (% rhs. derivesp (example_rules, ''S'') [NTS ''S''] rhs)"
bulwahn@39655
    60
haftmann@45970
    61
code_pred (modes: o \<Rightarrow> bool) [inductify] testp .
haftmann@45970
    62
thm testp.equation
bulwahn@39655
    63
haftmann@45970
    64
values "{rhs. testp rhs}"
haftmann@45970
    65
haftmann@45970
    66
declare rtranclp.intros(1)[code_pred_def] converse_rtranclp_into_rtranclp[code_pred_def]
bulwahn@39655
    67
haftmann@45970
    68
code_pred [inductify] rtranclp .
bulwahn@39655
    69
haftmann@45970
    70
definition "test2 = (\<lambda> rhs. rtranclp (derivesp (example_rules, ''S'')) [NTS ''S''] rhs)"
bulwahn@39655
    71
bulwahn@39655
    72
code_pred [inductify, skip_proof] test2 .
bulwahn@39655
    73
bulwahn@39655
    74
values "{rhs. test2 rhs}"
bulwahn@39655
    75
wenzelm@63167
    76
subsection \<open>Some concrete Context Free Grammars\<close>
bulwahn@39655
    77
blanchet@58310
    78
datatype alphabet = a | b
bulwahn@39655
    79
wenzelm@53015
    80
inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where
wenzelm@53015
    81
  "[] \<in> S\<^sub>1"
wenzelm@53015
    82
| "w \<in> A\<^sub>1 \<Longrightarrow> b # w \<in> S\<^sub>1"
wenzelm@53015
    83
| "w \<in> B\<^sub>1 \<Longrightarrow> a # w \<in> S\<^sub>1"
wenzelm@53015
    84
| "w \<in> S\<^sub>1 \<Longrightarrow> a # w \<in> A\<^sub>1"
wenzelm@53015
    85
| "w \<in> S\<^sub>1 \<Longrightarrow> b # w \<in> S\<^sub>1"
wenzelm@53015
    86
| "\<lbrakk>v \<in> B\<^sub>1; v \<in> B\<^sub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>1"
bulwahn@39655
    87
wenzelm@53015
    88
code_pred [inductify] S\<^sub>1p .
wenzelm@53015
    89
code_pred [random_dseq inductify] S\<^sub>1p .
wenzelm@53015
    90
thm S\<^sub>1p.equation
wenzelm@53015
    91
thm S\<^sub>1p.random_dseq_equation
bulwahn@39655
    92
wenzelm@53015
    93
values [random_dseq 5, 5, 5] 5 "{x. S\<^sub>1p x}"
bulwahn@39655
    94
wenzelm@53015
    95
inductive_set S\<^sub>2 and A\<^sub>2 and B\<^sub>2 where
wenzelm@53015
    96
  "[] \<in> S\<^sub>2"
wenzelm@53015
    97
| "w \<in> A\<^sub>2 \<Longrightarrow> b # w \<in> S\<^sub>2"
wenzelm@53015
    98
| "w \<in> B\<^sub>2 \<Longrightarrow> a # w \<in> S\<^sub>2"
wenzelm@53015
    99
| "w \<in> S\<^sub>2 \<Longrightarrow> a # w \<in> A\<^sub>2"
wenzelm@53015
   100
| "w \<in> S\<^sub>2 \<Longrightarrow> b # w \<in> B\<^sub>2"
wenzelm@53015
   101
| "\<lbrakk>v \<in> B\<^sub>2; v \<in> B\<^sub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>2"
bulwahn@39655
   102
wenzelm@53015
   103
code_pred [random_dseq inductify] S\<^sub>2p .
wenzelm@53015
   104
thm S\<^sub>2p.random_dseq_equation
wenzelm@53015
   105
thm A\<^sub>2p.random_dseq_equation
wenzelm@53015
   106
thm B\<^sub>2p.random_dseq_equation
bulwahn@39655
   107
wenzelm@53015
   108
values [random_dseq 5, 5, 5] 10 "{x. S\<^sub>2p x}"
bulwahn@39655
   109
wenzelm@53015
   110
inductive_set S\<^sub>3 and A\<^sub>3 and B\<^sub>3 where
wenzelm@53015
   111
  "[] \<in> S\<^sub>3"
wenzelm@53015
   112
| "w \<in> A\<^sub>3 \<Longrightarrow> b # w \<in> S\<^sub>3"
wenzelm@53015
   113
| "w \<in> B\<^sub>3 \<Longrightarrow> a # w \<in> S\<^sub>3"
wenzelm@53015
   114
| "w \<in> S\<^sub>3 \<Longrightarrow> a # w \<in> A\<^sub>3"
wenzelm@53015
   115
| "w \<in> S\<^sub>3 \<Longrightarrow> b # w \<in> B\<^sub>3"
wenzelm@53015
   116
| "\<lbrakk>v \<in> B\<^sub>3; w \<in> B\<^sub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>3"
bulwahn@39655
   117
wenzelm@53015
   118
code_pred [inductify, skip_proof] S\<^sub>3p .
wenzelm@53015
   119
thm S\<^sub>3p.equation
bulwahn@39655
   120
wenzelm@53015
   121
values 10 "{x. S\<^sub>3p x}"
bulwahn@39655
   122
wenzelm@53015
   123
inductive_set S\<^sub>4 and A\<^sub>4 and B\<^sub>4 where
wenzelm@53015
   124
  "[] \<in> S\<^sub>4"
wenzelm@53015
   125
| "w \<in> A\<^sub>4 \<Longrightarrow> b # w \<in> S\<^sub>4"
wenzelm@53015
   126
| "w \<in> B\<^sub>4 \<Longrightarrow> a # w \<in> S\<^sub>4"
wenzelm@53015
   127
| "w \<in> S\<^sub>4 \<Longrightarrow> a # w \<in> A\<^sub>4"
wenzelm@53015
   128
| "\<lbrakk>v \<in> A\<^sub>4; w \<in> A\<^sub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^sub>4"
wenzelm@53015
   129
| "w \<in> S\<^sub>4 \<Longrightarrow> b # w \<in> B\<^sub>4"
wenzelm@53015
   130
| "\<lbrakk>v \<in> B\<^sub>4; w \<in> B\<^sub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>4"
bulwahn@39655
   131
wenzelm@53015
   132
code_pred (expected_modes: o => bool, i => bool) S\<^sub>4p .
bulwahn@39655
   133
bulwahn@39655
   134
hide_const a b
bulwahn@39655
   135
wenzelm@63167
   136
section \<open>Semantics of programming languages\<close>
bulwahn@39655
   137
wenzelm@63167
   138
subsection \<open>IMP\<close>
bulwahn@39655
   139
wenzelm@42463
   140
type_synonym var = nat
wenzelm@42463
   141
type_synonym state = "int list"
bulwahn@39655
   142
blanchet@58310
   143
datatype com =
bulwahn@39655
   144
  Skip |
bulwahn@39655
   145
  Ass var "state => int" |
bulwahn@39655
   146
  Seq com com |
bulwahn@39655
   147
  IF "state => bool" com com |
bulwahn@39655
   148
  While "state => bool" com
bulwahn@39655
   149
bulwahn@39655
   150
inductive exec :: "com => state => state => bool" where
bulwahn@39655
   151
"exec Skip s s" |
bulwahn@39655
   152
"exec (Ass x e) s (s[x := e(s)])" |
bulwahn@39655
   153
"exec c1 s1 s2 ==> exec c2 s2 s3 ==> exec (Seq c1 c2) s1 s3" |
bulwahn@39655
   154
"b s ==> exec c1 s t ==> exec (IF b c1 c2) s t" |
bulwahn@39655
   155
"~b s ==> exec c2 s t ==> exec (IF b c1 c2) s t" |
bulwahn@39655
   156
"~b s ==> exec (While b c) s s" |
bulwahn@39655
   157
"b s1 ==> exec c s1 s2 ==> exec (While b c) s2 s3 ==> exec (While b c) s1 s3"
bulwahn@39655
   158
bulwahn@39655
   159
code_pred exec .
bulwahn@39655
   160
bulwahn@39655
   161
values "{t. exec
bulwahn@39655
   162
 (While (%s. s!0 > 0) (Seq (Ass 0 (%s. s!0 - 1)) (Ass 1 (%s. s!1 + 1))))
bulwahn@39655
   163
 [3,5] t}"
bulwahn@39655
   164
wenzelm@63167
   165
subsection \<open>Lambda\<close>
bulwahn@39655
   166
blanchet@58310
   167
datatype type =
bulwahn@39655
   168
    Atom nat
bulwahn@39655
   169
  | Fun type type    (infixr "\<Rightarrow>" 200)
bulwahn@39655
   170
blanchet@58310
   171
datatype dB =
bulwahn@39655
   172
    Var nat
bulwahn@39655
   173
  | App dB dB (infixl "\<degree>" 200)
bulwahn@39655
   174
  | Abs type dB
bulwahn@39655
   175
bulwahn@39655
   176
primrec
bulwahn@39655
   177
  nth_el :: "'a list \<Rightarrow> nat \<Rightarrow> 'a option" ("_\<langle>_\<rangle>" [90, 0] 91)
bulwahn@39655
   178
where
bulwahn@39655
   179
  "[]\<langle>i\<rangle> = None"
bulwahn@39655
   180
| "(x # xs)\<langle>i\<rangle> = (case i of 0 \<Rightarrow> Some x | Suc j \<Rightarrow> xs \<langle>j\<rangle>)"
bulwahn@39655
   181
bulwahn@39655
   182
inductive nth_el' :: "'a list \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> bool"
bulwahn@39655
   183
where
bulwahn@39655
   184
  "nth_el' (x # xs) 0 x"
bulwahn@39655
   185
| "nth_el' xs i y \<Longrightarrow> nth_el' (x # xs) (Suc i) y"
bulwahn@39655
   186
bulwahn@39655
   187
inductive typing :: "type list \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ : _" [50, 50, 50] 50)
bulwahn@39655
   188
  where
bulwahn@39655
   189
    Var [intro!]: "nth_el' env x T \<Longrightarrow> env \<turnstile> Var x : T"
bulwahn@39655
   190
  | Abs [intro!]: "T # env \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs T t : (T \<Rightarrow> U)"
bulwahn@39655
   191
  | App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U"
bulwahn@39655
   192
bulwahn@39655
   193
primrec
bulwahn@39655
   194
  lift :: "[dB, nat] => dB"
bulwahn@39655
   195
where
bulwahn@39655
   196
    "lift (Var i) k = (if i < k then Var i else Var (i + 1))"
bulwahn@39655
   197
  | "lift (s \<degree> t) k = lift s k \<degree> lift t k"
bulwahn@39655
   198
  | "lift (Abs T s) k = Abs T (lift s (k + 1))"
bulwahn@39655
   199
bulwahn@39655
   200
primrec
bulwahn@39655
   201
  subst :: "[dB, dB, nat] => dB"  ("_[_'/_]" [300, 0, 0] 300)
bulwahn@39655
   202
where
bulwahn@39655
   203
    subst_Var: "(Var i)[s/k] =
bulwahn@39655
   204
      (if k < i then Var (i - 1) else if i = k then s else Var i)"
bulwahn@39655
   205
  | subst_App: "(t \<degree> u)[s/k] = t[s/k] \<degree> u[s/k]"
bulwahn@39655
   206
  | subst_Abs: "(Abs T t)[s/k] = Abs T (t[lift s 0 / k+1])"
bulwahn@39655
   207
bulwahn@39655
   208
inductive beta :: "[dB, dB] => bool"  (infixl "\<rightarrow>\<^sub>\<beta>" 50)
bulwahn@39655
   209
  where
bulwahn@39655
   210
    beta [simp, intro!]: "Abs T s \<degree> t \<rightarrow>\<^sub>\<beta> s[t/0]"
bulwahn@39655
   211
  | appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u"
bulwahn@39655
   212
  | appR [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> u \<degree> s \<rightarrow>\<^sub>\<beta> u \<degree> t"
bulwahn@39655
   213
  | abs [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> Abs T s \<rightarrow>\<^sub>\<beta> Abs T t"
bulwahn@39655
   214
bulwahn@39655
   215
code_pred (expected_modes: i => i => o => bool, i => i => i => bool) typing .
bulwahn@39655
   216
thm typing.equation
bulwahn@39655
   217
bulwahn@39655
   218
code_pred (modes: i => i => bool,  i => o => bool as reduce') beta .
bulwahn@39655
   219
thm beta.equation
bulwahn@39655
   220
bulwahn@39655
   221
values "{x. App (Abs (Atom 0) (Var 0)) (Var 1) \<rightarrow>\<^sub>\<beta> x}"
bulwahn@39655
   222
bulwahn@39655
   223
definition "reduce t = Predicate.the (reduce' t)"
bulwahn@39655
   224
bulwahn@39655
   225
value "reduce (App (Abs (Atom 0) (Var 0)) (Var 1))"
bulwahn@39655
   226
bulwahn@39655
   227
code_pred [dseq] typing .
bulwahn@39655
   228
code_pred [random_dseq] typing .
bulwahn@39655
   229
bulwahn@39655
   230
values [random_dseq 1,1,5] 10 "{(\<Gamma>, t, T). \<Gamma> \<turnstile> t : T}"
bulwahn@39655
   231
wenzelm@63167
   232
subsection \<open>A minimal example of yet another semantics\<close>
bulwahn@39655
   233
wenzelm@63167
   234
text \<open>thanks to Elke Salecker\<close>
bulwahn@39655
   235
wenzelm@42463
   236
type_synonym vname = nat
wenzelm@42463
   237
type_synonym vvalue = int
wenzelm@63167
   238
type_synonym var_assign = "vname \<Rightarrow> vvalue"  \<comment>"variable assignment"
bulwahn@39655
   239
blanchet@58310
   240
datatype ir_expr = 
bulwahn@39655
   241
  IrConst vvalue
bulwahn@39655
   242
| ObjAddr vname
bulwahn@39655
   243
| Add ir_expr ir_expr
bulwahn@39655
   244
blanchet@58310
   245
datatype val =
bulwahn@39655
   246
  IntVal  vvalue
bulwahn@39655
   247
bulwahn@39655
   248
record  configuration =
bulwahn@39655
   249
  Env :: var_assign
bulwahn@39655
   250
bulwahn@39655
   251
inductive eval_var ::
bulwahn@39655
   252
  "ir_expr \<Rightarrow> configuration \<Rightarrow> val \<Rightarrow> bool"
bulwahn@39655
   253
where
bulwahn@39655
   254
  irconst: "eval_var (IrConst i) conf (IntVal i)"
bulwahn@39655
   255
| objaddr: "\<lbrakk> Env conf n = i \<rbrakk> \<Longrightarrow> eval_var (ObjAddr n) conf (IntVal i)"
wenzelm@52666
   256
| plus: "\<lbrakk> eval_var l conf (IntVal vl); eval_var r conf (IntVal vr) \<rbrakk> \<Longrightarrow>
wenzelm@52666
   257
    eval_var (Add l r) conf (IntVal (vl+vr))"
bulwahn@39655
   258
bulwahn@39655
   259
bulwahn@39655
   260
code_pred eval_var .
bulwahn@39655
   261
thm eval_var.equation
bulwahn@39655
   262
bulwahn@39655
   263
values "{val. eval_var (Add (IrConst 1) (IrConst 2)) (| Env = (\<lambda>x. 0)|) val}"
bulwahn@39655
   264
wenzelm@63167
   265
subsection \<open>Another semantics\<close>
bulwahn@39655
   266
wenzelm@63167
   267
type_synonym name = nat \<comment>"For simplicity in examples"
wenzelm@42463
   268
type_synonym state' = "name \<Rightarrow> nat"
bulwahn@39655
   269
blanchet@58310
   270
datatype aexp = N nat | V name | Plus aexp aexp
bulwahn@39655
   271
bulwahn@39655
   272
fun aval :: "aexp \<Rightarrow> state' \<Rightarrow> nat" where
bulwahn@39655
   273
"aval (N n) _ = n" |
bulwahn@39655
   274
"aval (V x) st = st x" |
wenzelm@53015
   275
"aval (Plus e\<^sub>1 e\<^sub>2) st = aval e\<^sub>1 st + aval e\<^sub>2 st"
bulwahn@39655
   276
blanchet@58310
   277
datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp
bulwahn@39655
   278
bulwahn@39655
   279
primrec bval :: "bexp \<Rightarrow> state' \<Rightarrow> bool" where
bulwahn@39655
   280
"bval (B b) _ = b" |
bulwahn@39655
   281
"bval (Not b) st = (\<not> bval b st)" |
bulwahn@39655
   282
"bval (And b1 b2) st = (bval b1 st \<and> bval b2 st)" |
wenzelm@53015
   283
"bval (Less a\<^sub>1 a\<^sub>2) st = (aval a\<^sub>1 st < aval a\<^sub>2 st)"
bulwahn@39655
   284
blanchet@58310
   285
datatype
bulwahn@39655
   286
  com' = SKIP 
bulwahn@39655
   287
      | Assign name aexp         ("_ ::= _" [1000, 61] 61)
bulwahn@39655
   288
      | Semi   com'  com'          ("_; _"  [60, 61] 60)
bulwahn@39655
   289
      | If     bexp com' com'     ("IF _ THEN _ ELSE _"  [0, 0, 61] 61)
bulwahn@39655
   290
      | While  bexp com'         ("WHILE _ DO _"  [0, 61] 61)
bulwahn@39655
   291
bulwahn@39655
   292
inductive
bulwahn@39655
   293
  big_step :: "com' * state' \<Rightarrow> state' \<Rightarrow> bool" (infix "\<Rightarrow>" 55)
bulwahn@39655
   294
where
bulwahn@39655
   295
  Skip:    "(SKIP,s) \<Rightarrow> s"
bulwahn@39655
   296
| Assign:  "(x ::= a,s) \<Rightarrow> s(x := aval a s)"
bulwahn@39655
   297
wenzelm@53015
   298
| Semi:    "(c\<^sub>1,s\<^sub>1) \<Rightarrow> s\<^sub>2  \<Longrightarrow>  (c\<^sub>2,s\<^sub>2) \<Rightarrow> s\<^sub>3  \<Longrightarrow> (c\<^sub>1;c\<^sub>2, s\<^sub>1) \<Rightarrow> s\<^sub>3"
bulwahn@39655
   299
wenzelm@53015
   300
| IfTrue:  "bval b s  \<Longrightarrow>  (c\<^sub>1,s) \<Rightarrow> t  \<Longrightarrow>  (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \<Rightarrow> t"
wenzelm@53015
   301
| IfFalse: "\<not>bval b s  \<Longrightarrow>  (c\<^sub>2,s) \<Rightarrow> t  \<Longrightarrow>  (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \<Rightarrow> t"
bulwahn@39655
   302
bulwahn@39655
   303
| WhileFalse: "\<not>bval b s \<Longrightarrow> (WHILE b DO c,s) \<Rightarrow> s"
wenzelm@53015
   304
| WhileTrue:  "bval b s\<^sub>1  \<Longrightarrow>  (c,s\<^sub>1) \<Rightarrow> s\<^sub>2  \<Longrightarrow>  (WHILE b DO c, s\<^sub>2) \<Rightarrow> s\<^sub>3
wenzelm@53015
   305
               \<Longrightarrow> (WHILE b DO c, s\<^sub>1) \<Rightarrow> s\<^sub>3"
bulwahn@39655
   306
bulwahn@39655
   307
code_pred big_step .
bulwahn@39655
   308
bulwahn@39655
   309
thm big_step.equation
bulwahn@39655
   310
bulwahn@42094
   311
definition list :: "(nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a list" where
bulwahn@42094
   312
  "list s n = map s [0 ..< n]"
bulwahn@42094
   313
eberlm@66283
   314
values [expected "{[42::nat, 43]}"] "{list s 2|s. (SKIP, nth [42, 43]) \<Rightarrow> s}"
bulwahn@42094
   315
bulwahn@42094
   316
wenzelm@63167
   317
subsection \<open>CCS\<close>
bulwahn@39655
   318
wenzelm@63167
   319
text\<open>This example formalizes finite CCS processes without communication or
wenzelm@63167
   320
recursion. For simplicity, labels are natural numbers.\<close>
bulwahn@39655
   321
blanchet@58310
   322
datatype proc = nil | pre nat proc | or proc proc | par proc proc
bulwahn@39655
   323
bulwahn@39655
   324
inductive step :: "proc \<Rightarrow> nat \<Rightarrow> proc \<Rightarrow> bool" where
bulwahn@39655
   325
"step (pre n p) n p" |
bulwahn@39655
   326
"step p1 a q \<Longrightarrow> step (or p1 p2) a q" |
bulwahn@39655
   327
"step p2 a q \<Longrightarrow> step (or p1 p2) a q" |
bulwahn@39655
   328
"step p1 a q \<Longrightarrow> step (par p1 p2) a (par q p2)" |
bulwahn@39655
   329
"step p2 a q \<Longrightarrow> step (par p1 p2) a (par p1 q)"
bulwahn@39655
   330
bulwahn@39655
   331
code_pred step .
bulwahn@39655
   332
bulwahn@39655
   333
inductive steps where
bulwahn@39655
   334
"steps p [] p" |
bulwahn@39655
   335
"step p a q \<Longrightarrow> steps q as r \<Longrightarrow> steps p (a#as) r"
bulwahn@39655
   336
bulwahn@39655
   337
code_pred steps .
bulwahn@39655
   338
bulwahn@39655
   339
values 3 
bulwahn@39655
   340
 "{as . steps (par (or (pre 0 nil) (pre 1 nil)) (pre 2 nil)) as (par nil nil)}"
bulwahn@39655
   341
bulwahn@39655
   342
values 5
bulwahn@39655
   343
 "{as . steps (par (or (pre 0 nil) (pre 1 nil)) (pre 2 nil)) as (par nil nil)}"
bulwahn@39655
   344
bulwahn@39655
   345
values 3 "{(a,q). step (par nil nil) a q}"
bulwahn@39655
   346
bulwahn@39655
   347
bulwahn@39655
   348
end
bulwahn@39655
   349