src/HOL/IMP/Def_Init_Exp.thy
author haftmann
Fri, 15 Feb 2013 08:31:31 +0100
changeset 51143 0a2371e7ced3
parent 50161 4fc4237488ab
child 53015 a1119cf551e8
permissions -rw-r--r--
two target language numeral types: integer and natural, as replacement for code_numeral; former theory HOL/Library/Code_Numeral_Types replaces HOL/Code_Numeral; refined stack of theories implementing int and/or nat by target language numerals; reduced number of target language numeral types to exactly one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     2
50161
4fc4237488ab tuned names
nipkow
parents: 45212
diff changeset
     3
theory Def_Init_Exp
4fc4237488ab tuned names
nipkow
parents: 45212
diff changeset
     4
imports Vars
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     5
begin
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     6
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     7
subsection "Initialization-Sensitive Expressions Evaluation"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
     8
45212
e87feee00a4c renamed name -> vname
nipkow
parents: 45200
diff changeset
     9
type_synonym state = "vname \<Rightarrow> val option"
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    10
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    11
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    12
fun aval :: "aexp \<Rightarrow> state \<Rightarrow> val option" where
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    13
"aval (N i) s = Some i" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    14
"aval (V x) s = s x" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    15
"aval (Plus a\<^isub>1 a\<^isub>2) s =
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    16
  (case (aval a\<^isub>1 s, aval a\<^isub>2 s) of
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    17
     (Some i\<^isub>1,Some i\<^isub>2) \<Rightarrow> Some(i\<^isub>1+i\<^isub>2) | _ \<Rightarrow> None)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    18
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    19
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    20
fun bval :: "bexp \<Rightarrow> state \<Rightarrow> bool option" where
45200
1f1897ac7877 renamed B to Bc
nipkow
parents: 43158
diff changeset
    21
"bval (Bc v) s = Some v" |
43158
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    22
"bval (Not b) s = (case bval b s of None \<Rightarrow> None | Some bv \<Rightarrow> Some(\<not> bv))" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    23
"bval (And b\<^isub>1 b\<^isub>2) s = (case (bval b\<^isub>1 s, bval b\<^isub>2 s) of
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    24
  (Some bv\<^isub>1, Some bv\<^isub>2) \<Rightarrow> Some(bv\<^isub>1 & bv\<^isub>2) | _ \<Rightarrow> None)" |
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    25
"bval (Less a\<^isub>1 a\<^isub>2) s = (case (aval a\<^isub>1 s, aval a\<^isub>2 s) of
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    26
 (Some i\<^isub>1, Some i\<^isub>2) \<Rightarrow> Some(i\<^isub>1 < i\<^isub>2) | _ \<Rightarrow> None)"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    27
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    28
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    29
lemma aval_Some: "vars a \<subseteq> dom s \<Longrightarrow> \<exists> i. aval a s = Some i"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    30
by (induct a) auto
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    31
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    32
lemma bval_Some: "vars b \<subseteq> dom s \<Longrightarrow> \<exists> bv. bval b s = Some bv"
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    33
by (induct b) (auto dest!: aval_Some)
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    34
686fa0a0696e imported rest of new IMP
kleing
parents:
diff changeset
    35
end