src/HOL/IMP/Def_Ass_Exp.thy
author huffman
Thu Aug 11 09:11:15 2011 -0700 (2011-08-11)
changeset 44165 d26a45f3c835
parent 43158 686fa0a0696e
child 45200 1f1897ac7877
permissions -rw-r--r--
remove lemma stupid_ext
kleing@43158
     1
(* Author: Tobias Nipkow *)
kleing@43158
     2
kleing@43158
     3
theory Def_Ass_Exp imports Vars
kleing@43158
     4
begin
kleing@43158
     5
kleing@43158
     6
subsection "Initialization-Sensitive Expressions Evaluation"
kleing@43158
     7
kleing@43158
     8
type_synonym val = "int"
kleing@43158
     9
type_synonym state = "name \<Rightarrow> val option"
kleing@43158
    10
kleing@43158
    11
kleing@43158
    12
fun aval :: "aexp \<Rightarrow> state \<Rightarrow> val option" where
kleing@43158
    13
"aval (N i) s = Some i" |
kleing@43158
    14
"aval (V x) s = s x" |
kleing@43158
    15
"aval (Plus a\<^isub>1 a\<^isub>2) s =
kleing@43158
    16
  (case (aval a\<^isub>1 s, aval a\<^isub>2 s) of
kleing@43158
    17
     (Some i\<^isub>1,Some i\<^isub>2) \<Rightarrow> Some(i\<^isub>1+i\<^isub>2) | _ \<Rightarrow> None)"
kleing@43158
    18
kleing@43158
    19
kleing@43158
    20
fun bval :: "bexp \<Rightarrow> state \<Rightarrow> bool option" where
kleing@43158
    21
"bval (B bv) s = Some bv" |
kleing@43158
    22
"bval (Not b) s = (case bval b s of None \<Rightarrow> None | Some bv \<Rightarrow> Some(\<not> bv))" |
kleing@43158
    23
"bval (And b\<^isub>1 b\<^isub>2) s = (case (bval b\<^isub>1 s, bval b\<^isub>2 s) of
kleing@43158
    24
  (Some bv\<^isub>1, Some bv\<^isub>2) \<Rightarrow> Some(bv\<^isub>1 & bv\<^isub>2) | _ \<Rightarrow> None)" |
kleing@43158
    25
"bval (Less a\<^isub>1 a\<^isub>2) s = (case (aval a\<^isub>1 s, aval a\<^isub>2 s) of
kleing@43158
    26
 (Some i\<^isub>1, Some i\<^isub>2) \<Rightarrow> Some(i\<^isub>1 < i\<^isub>2) | _ \<Rightarrow> None)"
kleing@43158
    27
kleing@43158
    28
kleing@43158
    29
lemma aval_Some: "vars a \<subseteq> dom s \<Longrightarrow> \<exists> i. aval a s = Some i"
kleing@43158
    30
by (induct a) auto
kleing@43158
    31
kleing@43158
    32
lemma bval_Some: "vars b \<subseteq> dom s \<Longrightarrow> \<exists> bv. bval b s = Some bv"
kleing@43158
    33
by (induct b) (auto dest!: aval_Some)
kleing@43158
    34
kleing@43158
    35
end