src/HOL/Statespace/StateFun.thy
author haftmann
Sun Oct 08 22:28:22 2017 +0200 (23 months ago)
changeset 66816 212a3334e7da
parent 63167 0909deb8059b
permissions -rw-r--r--
more fundamental definition of div and mod on int
wenzelm@41959
     1
(*  Title:      HOL/Statespace/StateFun.thy
schirmer@25171
     2
    Author:     Norbert Schirmer, TU Muenchen
schirmer@25171
     3
*)
schirmer@25171
     4
wenzelm@63167
     5
section \<open>State Space Representation as Function \label{sec:StateFun}\<close>
schirmer@25171
     6
schirmer@25171
     7
theory StateFun imports DistinctTreeProver 
schirmer@25171
     8
begin
schirmer@25171
     9
schirmer@25171
    10
wenzelm@63167
    11
text \<open>The state space is represented as a function from names to
schirmer@25171
    12
values. We neither fix the type of names nor the type of values. We
schirmer@25171
    13
define lookup and update functions and provide simprocs that simplify
schirmer@25171
    14
expressions containing these, similar to HOL-records.
schirmer@25171
    15
schirmer@25171
    16
The lookup and update function get constructor/destructor functions as
schirmer@25171
    17
parameters. These are used to embed various HOL-types into the
schirmer@25171
    18
abstract value type. Conceptually the abstract value type is a sum of
schirmer@25171
    19
all types that we attempt to store in the state space.
schirmer@25171
    20
schirmer@25171
    21
The update is actually generalized to a map function. The map supplies
schirmer@25171
    22
better compositionality, especially if you think of nested state
wenzelm@63167
    23
spaces.\<close> 
schirmer@25171
    24
haftmann@35416
    25
definition K_statefun :: "'a \<Rightarrow> 'b \<Rightarrow> 'a" where "K_statefun c x \<equiv> c"
schirmer@25171
    26
schirmer@25171
    27
lemma K_statefun_apply [simp]: "K_statefun c x = c"
schirmer@25171
    28
  by (simp add: K_statefun_def)
schirmer@25171
    29
schirmer@25171
    30
lemma K_statefun_comp [simp]: "(K_statefun c \<circ> f) = K_statefun c"
wenzelm@44762
    31
  by (rule ext) (simp add: comp_def)
schirmer@25171
    32
schirmer@25171
    33
lemma K_statefun_cong [cong]: "K_statefun c x = K_statefun c x"
schirmer@25171
    34
  by (rule refl)
schirmer@25171
    35
wenzelm@38838
    36
definition lookup :: "('v \<Rightarrow> 'a) \<Rightarrow> 'n \<Rightarrow> ('n \<Rightarrow> 'v) \<Rightarrow> 'a"
wenzelm@35114
    37
  where "lookup destr n s = destr (s n)"
schirmer@25171
    38
wenzelm@38838
    39
definition update ::
schirmer@25171
    40
  "('v \<Rightarrow> 'a1) \<Rightarrow> ('a2 \<Rightarrow> 'v) \<Rightarrow> 'n \<Rightarrow> ('a1 \<Rightarrow> 'a2) \<Rightarrow> ('n \<Rightarrow> 'v) \<Rightarrow> ('n \<Rightarrow> 'v)"
wenzelm@35114
    41
  where "update destr constr n f s = s(n := constr (f (destr (s n))))"
schirmer@25171
    42
schirmer@25171
    43
lemma lookup_update_same:
schirmer@25171
    44
  "(\<And>v. destr (constr v) = v) \<Longrightarrow> lookup destr n (update destr constr n f s) = 
schirmer@25171
    45
         f (destr (s n))"  
schirmer@25171
    46
  by (simp add: lookup_def update_def)
schirmer@25171
    47
schirmer@25171
    48
lemma lookup_update_id_same:
schirmer@25171
    49
  "lookup destr n (update destr' id n (K_statefun (lookup id n s')) s) =                  
schirmer@25171
    50
     lookup destr n s'"  
schirmer@25171
    51
  by (simp add: lookup_def update_def)
schirmer@25171
    52
schirmer@25171
    53
lemma lookup_update_other:
schirmer@25171
    54
  "n\<noteq>m \<Longrightarrow> lookup destr n (update destr' constr m f s) = lookup destr n s"  
schirmer@25171
    55
  by (simp add: lookup_def update_def)
schirmer@25171
    56
schirmer@25171
    57
schirmer@25171
    58
lemma id_id_cancel: "id (id x) = x" 
schirmer@25171
    59
  by (simp add: id_def)
schirmer@25171
    60
  
wenzelm@45358
    61
lemma destr_contstr_comp_id: "(\<And>v. destr (constr v) = v) \<Longrightarrow> destr \<circ> constr = id"
schirmer@25171
    62
  by (rule ext) simp
schirmer@25171
    63
schirmer@25171
    64
schirmer@25171
    65
schirmer@25171
    66
lemma block_conj_cong: "(P \<and> Q) = (P \<and> Q)"
schirmer@25171
    67
  by simp
schirmer@25171
    68
wenzelm@45358
    69
lemma conj1_False: "P \<equiv> False \<Longrightarrow> (P \<and> Q) \<equiv> False"
schirmer@25171
    70
  by simp
schirmer@25171
    71
wenzelm@45358
    72
lemma conj2_False: "Q \<equiv> False \<Longrightarrow> (P \<and> Q) \<equiv> False"
schirmer@25171
    73
  by simp
schirmer@25171
    74
wenzelm@45358
    75
lemma conj_True: "P \<equiv> True \<Longrightarrow> Q \<equiv> True \<Longrightarrow> (P \<and> Q) \<equiv> True"
schirmer@25171
    76
  by simp
schirmer@25171
    77
wenzelm@45358
    78
lemma conj_cong: "P \<equiv> P' \<Longrightarrow> Q \<equiv> Q' \<Longrightarrow> (P \<and> Q) \<equiv> (P' \<and> Q')"
schirmer@25171
    79
  by simp
schirmer@25171
    80
schirmer@25171
    81
schirmer@25171
    82
lemma update_apply: "(update destr constr n f s x) = 
schirmer@25171
    83
     (if x=n then constr (f (destr (s n))) else s x)"
schirmer@25171
    84
  by (simp add: update_def)
schirmer@25171
    85
schirmer@25171
    86
lemma ex_id: "\<exists>x. id x = y"
schirmer@25171
    87
  by (simp add: id_def)
schirmer@25171
    88
schirmer@25171
    89
lemma swap_ex_eq: 
schirmer@25171
    90
  "\<exists>s. f s = x \<equiv> True \<Longrightarrow>
schirmer@25171
    91
   \<exists>s. x = f s \<equiv> True"
schirmer@25171
    92
  apply (rule eq_reflection)
schirmer@25171
    93
  apply auto
schirmer@25171
    94
  done
schirmer@25171
    95
schirmer@25171
    96
lemmas meta_ext = eq_reflection [OF ext]
schirmer@25171
    97
schirmer@25171
    98
(* This lemma only works if the store is welltyped:
schirmer@25171
    99
    "\<exists>x.  s ''n'' = (c x)" 
schirmer@25171
   100
   or in general when c (d x) = x,
schirmer@25171
   101
     (for example: c=id and d=id)
schirmer@25171
   102
 *)
schirmer@25171
   103
lemma "update d c n (K_statespace (lookup d n s)) s = s"
schirmer@25171
   104
  apply (simp add: update_def lookup_def)
schirmer@25171
   105
  apply (rule ext)
schirmer@25171
   106
  apply simp
schirmer@25171
   107
  oops
schirmer@25171
   108
nipkow@62390
   109
end