src/ZF/UNITY/AllocBase.thy
changeset 60770 240563fbf41d
parent 58871 c399ae4b836f
child 61395 4f8c2c4a0a8c
equal deleted inserted replaced
60769:cf7f3465eaf1 60770:240563fbf41d
     1 (*  Title:      ZF/UNITY/AllocBase.thy
     1 (*  Title:      ZF/UNITY/AllocBase.thy
     2     Author:     Sidi O Ehmety, Cambridge University Computer Laboratory
     2     Author:     Sidi O Ehmety, Cambridge University Computer Laboratory
     3     Copyright   2001  University of Cambridge
     3     Copyright   2001  University of Cambridge
     4 *)
     4 *)
     5 
     5 
     6 section{*Common declarations for Chandy and Charpentier's Allocator*}
     6 section\<open>Common declarations for Chandy and Charpentier's Allocator\<close>
     7 
     7 
     8 theory AllocBase imports Follows MultisetSum Guar begin
     8 theory AllocBase imports Follows MultisetSum Guar begin
     9 
     9 
    10 abbreviation (input)
    10 abbreviation (input)
    11   tokbag   :: i  (* tokbags could be multisets...or any ordered type?*)
    11   tokbag   :: i  (* tokbags could be multisets...or any ordered type?*)
    17   Nclients :: i  (* Number of clients *)
    17   Nclients :: i  (* Number of clients *)
    18 where
    18 where
    19   NbT_pos: "NbT \<in> nat-{0}" and
    19   NbT_pos: "NbT \<in> nat-{0}" and
    20   Nclients_pos: "Nclients \<in> nat-{0}"
    20   Nclients_pos: "Nclients \<in> nat-{0}"
    21   
    21   
    22 text{*This function merely sums the elements of a list*}
    22 text\<open>This function merely sums the elements of a list\<close>
    23 consts tokens :: "i =>i"
    23 consts tokens :: "i =>i"
    24        item :: i (* Items to be merged/distributed *)
    24        item :: i (* Items to be merged/distributed *)
    25 primrec 
    25 primrec 
    26   "tokens(Nil) = 0"
    26   "tokens(Nil) = 0"
    27   "tokens (Cons(x,xs)) = x #+ tokens(xs)"
    27   "tokens (Cons(x,xs)) = x #+ tokens(xs)"
    30 primrec
    30 primrec
    31   "bag_of(Nil)    = 0"
    31   "bag_of(Nil)    = 0"
    32   "bag_of(Cons(x,xs)) = {#x#} +# bag_of(xs)"
    32   "bag_of(Cons(x,xs)) = {#x#} +# bag_of(xs)"
    33 
    33 
    34 
    34 
    35 text{*Definitions needed in Client.thy.  We define a recursive predicate
    35 text\<open>Definitions needed in Client.thy.  We define a recursive predicate
    36 using 0 and 1 to code the truth values.*}
    36 using 0 and 1 to code the truth values.\<close>
    37 consts all_distinct0 :: "i=>i"
    37 consts all_distinct0 :: "i=>i"
    38 primrec
    38 primrec
    39   "all_distinct0(Nil) = 1"
    39   "all_distinct0(Nil) = 1"
    40   "all_distinct0(Cons(a, l)) =
    40   "all_distinct0(Cons(a, l)) =
    41      (if a \<in> set_of_list(l) then 0 else all_distinct0(l))"
    41      (if a \<in> set_of_list(l) then 0 else all_distinct0(l))"
    43 definition
    43 definition
    44   all_distinct  :: "i=>o"  where
    44   all_distinct  :: "i=>o"  where
    45    "all_distinct(l) == all_distinct0(l)=1"
    45    "all_distinct(l) == all_distinct0(l)=1"
    46   
    46   
    47 definition  
    47 definition  
    48   state_of :: "i =>i" --{* coersion from anyting to state *}  where
    48   state_of :: "i =>i" --\<open>coersion from anyting to state\<close>  where
    49    "state_of(s) == if s \<in> state then s else st0"
    49    "state_of(s) == if s \<in> state then s else st0"
    50 
    50 
    51 definition
    51 definition
    52   lift :: "i =>(i=>i)" --{* simplifies the expression of programs*}  where
    52   lift :: "i =>(i=>i)" --\<open>simplifies the expression of programs\<close>  where
    53    "lift(x) == %s. s`x"
    53    "lift(x) == %s. s`x"
    54 
    54 
    55 text{* function to show that the set of variables is infinite *}
    55 text\<open>function to show that the set of variables is infinite\<close>
    56 consts
    56 consts
    57   nat_list_inj :: "i=>i"
    57   nat_list_inj :: "i=>i"
    58   var_inj      :: "i=>i"
    58   var_inj      :: "i=>i"
    59 
    59 
    60 primrec
    60 primrec
    67 definition
    67 definition
    68   nat_var_inj  :: "i=>i"  where
    68   nat_var_inj  :: "i=>i"  where
    69   "nat_var_inj(n) == Var(nat_list_inj(n))"
    69   "nat_var_inj(n) == Var(nat_list_inj(n))"
    70 
    70 
    71 
    71 
    72 subsection{*Various simple lemmas*}
    72 subsection\<open>Various simple lemmas\<close>
    73 
    73 
    74 lemma Nclients_NbT_gt_0 [simp]: "0 < Nclients & 0 < NbT"
    74 lemma Nclients_NbT_gt_0 [simp]: "0 < Nclients & 0 < NbT"
    75 apply (cut_tac Nclients_pos NbT_pos)
    75 apply (cut_tac Nclients_pos NbT_pos)
    76 apply (auto intro: Ord_0_lt)
    76 apply (auto intro: Ord_0_lt)
    77 done
    77 done
   125 lemma tokens_append [simp]: 
   125 lemma tokens_append [simp]: 
   126 "[| xs\<in>list(A); ys\<in>list(A) |] ==> tokens(xs@ys) = tokens(xs) #+ tokens(ys)"
   126 "[| xs\<in>list(A); ys\<in>list(A) |] ==> tokens(xs@ys) = tokens(xs) #+ tokens(ys)"
   127 apply (induct_tac "xs", auto)
   127 apply (induct_tac "xs", auto)
   128 done
   128 done
   129 
   129 
   130 subsection{*The function @{term bag_of}*}
   130 subsection\<open>The function @{term bag_of}\<close>
   131 
   131 
   132 lemma bag_of_type [simp,TC]: "l\<in>list(A) ==>bag_of(l)\<in>Mult(A)"
   132 lemma bag_of_type [simp,TC]: "l\<in>list(A) ==>bag_of(l)\<in>Mult(A)"
   133 apply (induct_tac "l")
   133 apply (induct_tac "l")
   134 apply (auto simp add: Mult_iff_multiset)
   134 apply (auto simp add: Mult_iff_multiset)
   135 done
   135 done
   166 lemma mono_bag_of [simp]: 
   166 lemma mono_bag_of [simp]: 
   167      "mono1(list(A), prefix(A), Mult(A), MultLe(A,r), bag_of)"
   167      "mono1(list(A), prefix(A), Mult(A), MultLe(A,r), bag_of)"
   168 by (auto simp add:  mono1_def bag_of_type)
   168 by (auto simp add:  mono1_def bag_of_type)
   169 
   169 
   170 
   170 
   171 subsection{*The function @{term msetsum}*}
   171 subsection\<open>The function @{term msetsum}\<close>
   172 
   172 
   173 lemmas nat_into_Fin = eqpoll_refl [THEN [2] Fin_lemma]
   173 lemmas nat_into_Fin = eqpoll_refl [THEN [2] Fin_lemma]
   174 
   174 
   175 lemma list_Int_length_Fin: "l \<in> list(A) ==> C \<inter> length(l) \<in> Fin(length(l))"
   175 lemma list_Int_length_Fin: "l \<in> list(A) ==> C \<inter> length(l) \<in> Fin(length(l))"
   176 apply (drule length_type)
   176 apply (drule length_type)
   270 lemma part_ord_Lt [simp]: "part_ord(nat, Lt)"
   270 lemma part_ord_Lt [simp]: "part_ord(nat, Lt)"
   271 apply (unfold part_ord_def Lt_def irrefl_def trans_on_def)
   271 apply (unfold part_ord_def Lt_def irrefl_def trans_on_def)
   272 apply (auto intro: lt_trans)
   272 apply (auto intro: lt_trans)
   273 done
   273 done
   274 
   274 
   275 subsubsection{*The function @{term all_distinct}*}
   275 subsubsection\<open>The function @{term all_distinct}\<close>
   276 
   276 
   277 lemma all_distinct_Nil [simp]: "all_distinct(Nil)"
   277 lemma all_distinct_Nil [simp]: "all_distinct(Nil)"
   278 by (unfold all_distinct_def, auto)
   278 by (unfold all_distinct_def, auto)
   279 
   279 
   280 lemma all_distinct_Cons [simp]: 
   280 lemma all_distinct_Cons [simp]: 
   282       (a\<in>set_of_list(l) \<longrightarrow> False) & (a \<notin> set_of_list(l) \<longrightarrow> all_distinct(l))"
   282       (a\<in>set_of_list(l) \<longrightarrow> False) & (a \<notin> set_of_list(l) \<longrightarrow> all_distinct(l))"
   283 apply (unfold all_distinct_def)
   283 apply (unfold all_distinct_def)
   284 apply (auto elim: list.cases)
   284 apply (auto elim: list.cases)
   285 done
   285 done
   286 
   286 
   287 subsubsection{*The function @{term state_of}*}
   287 subsubsection\<open>The function @{term state_of}\<close>
   288 
   288 
   289 lemma state_of_state: "s\<in>state ==> state_of(s)=s"
   289 lemma state_of_state: "s\<in>state ==> state_of(s)=s"
   290 by (unfold state_of_def, auto)
   290 by (unfold state_of_def, auto)
   291 declare state_of_state [simp]
   291 declare state_of_state [simp]
   292 
   292