thys/Chap03.thy
author Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
Mon, 26 Jan 2015 15:41:16 +0000
changeset 50 c603b27083f3
child 51 3810b37511cb
permissions -rw-r--r--
fahad's experiments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     1
theory Chap03
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     2
imports Main
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     3
begin
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     4
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     5
lemma "\<lbrakk> xs @ zs = ys @ xs; [] @ xs = [] @ [] \<rbrakk> \<Longrightarrow> ys = zs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     6
apply simp
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     7
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     8
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
     9
lemma "\<forall> x. f x = g (f (g x)) \<Longrightarrow> f [] = f [] @ []"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    10
apply (simp (no_asm))
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    11
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    12
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    13
definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    14
"xor A B \<equiv> (A \<and> \<not>B) \<or> (\<not>A \<and> B)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    15
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    16
lemma "xor A (\<not>A)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    17
apply(simp only: xor_def)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    18
apply(simp add: xor_def)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    19
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    20
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    21
lemma "(let xs = [] in xs@ys@xs) = ys"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    22
apply(simp only: Let_def)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    23
apply(simp add: Let_def)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    24
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    25
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    26
(* 3.1.8 Conditioal Simplification Rules  *)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    27
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    28
lemma hd_Cons_tl: "xs \<noteq> [] \<Longrightarrow> hd xs # tl xs = xs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    29
using [[simp_trace=true]]
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    30
apply(case_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    31
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    32
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    33
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    34
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    35
lemma "xs \<noteq> [] \<Longrightarrow> hd(rev xs) # tl(rev xs) = rev xs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    36
apply(case_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    37
using [[simp_trace=true]]
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    38
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    39
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    40
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    41
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    42
(* 3.1.9 Automatic Case Splits  *)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    43
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    44
lemma "\<forall> xs. if xs = [] then rev xs = [] else rev xs \<noteq> []"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    45
apply(split split_if)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    46
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    47
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    48
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    49
lemma "(case xs of [] \<Rightarrow> zs | y#ys \<Rightarrow> y#(ys@zs)) = xs@zs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    50
apply(split list.split)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    51
apply(simp split: list.split)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    52
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    53
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    54
lemma "if xs = [] then ys \<noteq> [] else ys = [] \<Longrightarrow> xs @ ys \<noteq> []"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    55
apply(split split_if_asm)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    56
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    57
apply(auto)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    58
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    59
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    60
(* 3.2 Induction Heuristics  *)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    61
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    62
primrec itrev :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    63
"itrev [] ys = ys" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    64
"itrev (x#xs) ys = itrev xs (x#ys)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    65
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    66
lemma "itrev xs [] = rev xs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    67
apply(induct_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    68
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    69
apply(auto)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    70
oops
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    71
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    72
lemma "itrev xs ys = rev xs @ ys"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    73
apply(induct_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    74
apply(simp_all)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    75
oops
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    76
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    77
lemma "\<forall> ys. itrev xs ys = rev xs @ ys"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    78
apply(induct_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    79
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    80
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    81
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    82
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    83
primrec add1 :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    84
"add1 m 0 = m" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    85
"add1 m (Suc n) = add1 (Suc m) n"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    86
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    87
value "add1 1 3"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    88
value "1 + 3"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    89
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    90
lemma abc [simp]: "add1 m 0 = m"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    91
apply(induction m)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    92
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    93
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    94
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    95
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    96
lemma abc2 "add1 m n = m+n"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    97
apply(induction n)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    98
apply(auto)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
    99
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   100
oops
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   101
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   102
(* 3.3 Case Study: Compiling Expressions  *)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   103
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   104
type_synonym 'v binop = "'v \<Rightarrow> 'v \<Rightarrow> 'v"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   105
datatype ('a, 'v)expr = 
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   106
  Cex 'v
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   107
| Vex 'a
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   108
| Bex "'v binop" "('a,'v)expr" "('a,'v)expr"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   109
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   110
primrec "value" :: "('a,'v)expr \<Rightarrow> ('a \<Rightarrow> 'v) \<Rightarrow> 'v" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   111
"value (Cex v) env = v" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   112
"value (Vex a) env = env a" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   113
"value (Bex f e1 e2) env = f (value e1 env) (value e2 env)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   114
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   115
datatype ('a,'v)instr = 
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   116
  Const 'v
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   117
| Load 'a
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   118
| Apply "'v binop"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   119
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   120
primrec exec :: "('a,'v)instr list \<Rightarrow> ('a\<Rightarrow>'v) \<Rightarrow> 'v list \<Rightarrow> 'v list" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   121
"exec [] s vs = vs" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   122
"exec (i#is) s vs = (case i of
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   123
    Const v \<Rightarrow> exec is s (v#vs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   124
  | Load a \<Rightarrow> exec is s ((s a)#vs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   125
  | Apply f \<Rightarrow> exec is s ((f (hd vs) (hd(tl vs)))#(tl(tl vs))))"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   126
  
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   127
primrec compile :: "('a,'v)expr \<Rightarrow> ('a,'v)instr list" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   128
"compile (Cex v) = [Const v]" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   129
"compile (Vex a) = [Load a]" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   130
"compile (Bex f e1 e2) = (compile e2) @ (compile e1) @ [Apply f]"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   131
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   132
theorem "exec (compile e) s [] = [value e s]"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   133
(*the theorem needs to be generalized*)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   134
oops
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   135
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   136
(*more generalized theorem*)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   137
theorem "\<forall> vs. exec (compile e) s vs = (value e s) # vs"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   138
apply(induct_tac e)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   139
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   140
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   141
oops
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   142
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   143
lemma exec_app[simp]: "\<forall> vs. exec (xs@ys) s vs = exec ys s (exec xs s vs)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   144
apply(induct_tac xs)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   145
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   146
apply(simp)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   147
apply(simp split: instr.split)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   148
done
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   149
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   150
(* 2.5.6 Case Study: Boolean Expressions *)
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   151
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   152
datatype boolex = Const bool | Var nat | Neg boolex
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   153
| And boolex boolex
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   154
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   155
primrec "value2" :: "boolex \<Rightarrow> (nat \<Rightarrow> bool) \<Rightarrow> bool" where
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   156
"value2 (Const b)  env = b" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   157
"value2 (Var x)    env = env x" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   158
"value2 (Neg b)    env = (\<not> value2 b env)" |
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   159
"value2 (And b c)  env = (value2 b env \<and> value2 c env)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   160
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   161
value "Const true"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   162
value "Suc(Suc(0))"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   163
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   164
'b::Const = "true"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   165
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   166
value "value2 (Const true) (env = true)"
c603b27083f3 fahad's experiments
Fahad Ausaf <fahad.ausaf@kcl.ac.uk>
parents:
diff changeset
   167