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