src/ZF/UNITY/State.thy
author haftmann
Mon, 20 Jul 2009 09:52:09 +0200
changeset 32078 1c14f77201d4
parent 26060 cd89870aa92f
child 32960 69916a850301
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/State.thy
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     2
    ID:         $Id$
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     3
    Author:     Sidi O Ehmety, Computer Laboratory
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     4
    Copyright   2001  University of Cambridge
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     5
12195
ed2893765a08 *** empty log message ***
ehmety
parents: 11479
diff changeset
     6
Formalizes UNITY-program states using dependent types so that:
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     7
 - variables are typed.
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     8
 - the state space is uniform, common to all defined programs.
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
     9
 - variables can be quantified over.
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    10
*)
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    11
14084
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    12
header{*UNITY Program States*}
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    13
26060
cd89870aa92f imports Main;
wenzelm
parents: 26056
diff changeset
    14
theory State imports Main begin
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    15
14084
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    16
consts var :: i
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    17
datatype var = Var("i \<in> list(nat)")
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    18
  type_intros  nat_subset_univ [THEN list_subset_univ, THEN subsetD]
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    19
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    20
consts
14084
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    21
  type_of :: "i=>i"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    22
  default_val :: "i=>i"
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    23
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    24
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    25
  "state == \<Pi> x \<in> var. cons(default_val(x), type_of(x))"
14084
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    26
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    27
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    28
  "st0 == \<lambda>x \<in> var. default_val(x)"
14046
6616e6c53d48 updating ZF-UNITY with Sidi's new material
paulson
parents: 12195
diff changeset
    29
  
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    30
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    31
  st_set  :: "i=>o"  where
14046
6616e6c53d48 updating ZF-UNITY with Sidi's new material
paulson
parents: 12195
diff changeset
    32
(* To prevent typing conditions like `A<=state' from
6616e6c53d48 updating ZF-UNITY with Sidi's new material
paulson
parents: 12195
diff changeset
    33
   being used in combination with the rules `constrains_weaken', etc. *)
6616e6c53d48 updating ZF-UNITY with Sidi's new material
paulson
parents: 12195
diff changeset
    34
  "st_set(A) == A<=state"
11479
697dcaaf478f new ZF/UNITY theory
paulson
parents:
diff changeset
    35
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    36
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 16417
diff changeset
    37
  st_compl :: "i=>i"  where
14046
6616e6c53d48 updating ZF-UNITY with Sidi's new material
paulson
parents: 12195
diff changeset
    38
  "st_compl(A) == state-A"
14084
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    39
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    40
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    41
lemma st0_in_state [simp,TC]: "st0 \<in> state"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    42
by (simp add: state_def st0_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    43
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    44
lemma st_set_Collect [iff]: "st_set({x \<in> state. P(x)})"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    45
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    46
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    47
lemma st_set_0 [iff]: "st_set(0)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    48
by (simp add: st_set_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    49
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    50
lemma st_set_state [iff]: "st_set(state)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    51
by (simp add: st_set_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    52
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    53
(* Union *)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    54
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    55
lemma st_set_Un_iff [iff]: "st_set(A Un B) <-> st_set(A) & st_set(B)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    56
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    57
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    58
lemma st_set_Union_iff [iff]: "st_set(Union(S)) <-> (\<forall>A \<in> S. st_set(A))"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    59
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    60
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    61
(* Intersection *)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    62
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    63
lemma st_set_Int [intro!]: "st_set(A) | st_set(B) ==> st_set(A Int B)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    64
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    65
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    66
lemma st_set_Inter [intro!]: 
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    67
   "(S=0) | (\<exists>A \<in> S. st_set(A)) ==> st_set(Inter(S))"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    68
apply (simp add: st_set_def Inter_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    69
done
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    70
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    71
(* Diff *)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    72
lemma st_set_DiffI [intro!]: "st_set(A) ==> st_set(A - B)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    73
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    74
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    75
lemma Collect_Int_state [simp]: "Collect(state,P) Int state = Collect(state,P)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    76
by auto
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    77
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    78
lemma state_Int_Collect [simp]: "state Int Collect(state,P) = Collect(state,P)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    79
by auto
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    80
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    81
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    82
(* Introduction and destruction rules for st_set *)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    83
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    84
lemma st_setI: "A <= state ==> st_set(A)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    85
by (simp add: st_set_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    86
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    87
lemma st_setD: "st_set(A) ==> A<=state"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    88
by (simp add: st_set_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    89
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    90
lemma st_set_subset: "[| st_set(A); B<=A |] ==> st_set(B)"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    91
by (simp add: st_set_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    92
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    93
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    94
lemma state_update_type: 
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    95
     "[| s \<in> state; x \<in> var; y \<in> type_of(x) |] ==> s(x:=y):state"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    96
apply (simp add: state_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    97
apply (blast intro: update_type)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    98
done
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
    99
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   100
lemma st_set_compl [simp]: "st_set(st_compl(A))"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   101
by (simp add: st_compl_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   102
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   103
lemma st_compl_iff [simp]: "x \<in> st_compl(A) <-> x \<in> state & x \<notin> A"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   104
by (simp add: st_compl_def)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   105
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   106
lemma st_compl_Collect [simp]:
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   107
     "st_compl({s \<in> state. P(s)}) = {s \<in> state. ~P(s)}"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   108
by (simp add: st_compl_def, auto)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   109
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   110
(*For using "disjunction" (union over an index set) to eliminate a variable.*)
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   111
lemma UN_conj_eq:
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   112
     "\<forall>d\<in>D. f(d) \<in> A ==> (\<Union>k\<in>A. {d\<in>D. P(d) & f(d) = k}) = {d\<in>D. P(d)}"
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   113
by blast
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   114
ccb48f3239f7 Removal of UNITY/UNITYMisc, moving its theorems elsewhere.
paulson
parents: 14046
diff changeset
   115
end