src/HOL/UNITY/Token.ML
author paulson
Fri, 03 Apr 1998 12:34:33 +0200
changeset 4776 1f9362e769c1
child 5069 3ea049f7979d
permissions -rw-r--r--
New UNITY theory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/Token
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     2
    ID:         $Id$
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     4
    Copyright   1998  University of Cambridge
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     5
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     6
The Token Ring.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
From Misra, "A Logic for Concurrent Programming" (1994), sections 5.2 and 13.2.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    11
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    12
open Token;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
val Token_defs = [WellTyped_def, Token_def, HasTok_def, H_def, E_def, T_def];
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
AddIffs [N_positive, skip];
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    18
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
goalw thy [HasTok_def] "!!i. [| s: HasTok i; s: HasTok j |] ==> i=j";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
qed "HasToK_partition";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
goalw thy Token_defs "!!s. s : WellTyped ==> (s ~: E i) = (s : H i | s : T i)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
by (Simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
by (exhaust_tac "s (Suc i)" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
qed "not_E_eq";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    29
(** We should be able to prove WellTyped as a separate Invariant.  Then
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    30
    the Invariant rule should let us assume that the initial
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    31
    state is reachable, and therefore contained in any Invariant.  Then
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    32
    we'd not have to mention WellTyped in the statement of this theorem.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
**)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
goalw thy [stable_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
    "stable Acts (WellTyped Int {s. s : E i --> s : HasTok i})";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
by (rtac (stable_WT RS stable_constrains_Int) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
by (cut_facts_tac [TR2,TR4,TR5] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    39
by (asm_full_simp_tac (simpset() addsimps [constrains_def]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
by (REPEAT_FIRST (rtac ballI ORELSE' (dtac bspec THEN' assume_tac)));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
by (auto_tac (claset(), simpset() addsimps [not_E_eq]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
by (case_tac "xa : HasTok i" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
by (auto_tac (claset(), simpset() addsimps [H_def, E_def, T_def]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
qed "token_stable";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
(*This proof is in the "massaging" style and is much faster! *)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
goalw thy [stable_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
    "stable Acts (WellTyped Int (Compl(E i) Un (HasTok i)))";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
by (rtac (stable_WT RS stable_constrains_Int) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
by (rtac constrains_weaken 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
by (rtac ([[TR2, TR4] MRS constrains_Un, TR5] MRS constrains_Un) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
by (auto_tac (claset(), simpset() addsimps [not_E_eq]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [H_def, E_def, T_def])));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
qed "token_stable";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    55
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
(*** Progress under weak fairness ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
goalw thy [nodeOrder_def] "wf(nodeOrder j)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
by (rtac (wf_less_than RS wf_inv_image RS wf_subset) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
qed"wf_nodeOrder";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
    goal thy "!!m. [| m<n; Suc m ~= n |] ==> Suc(m) < n";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    65
    by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
    by (blast_tac (claset() addEs [less_asym, less_SucE]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
    qed "Suc_lessI";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
goalw thy [nodeOrder_def, next_def, inv_image_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
    "!!x. [| i<N; j<N |] ==> ((next i, i) : nodeOrder j) = (i ~= j)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
by (auto_tac (claset(),
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
	      simpset() addsimps [Suc_lessI, mod_Suc, mod_less, mod_geq]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
by (dtac sym 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    74
(*The next two lines...**)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    75
by (REPEAT (eres_inst_tac [("P", "?a<N")] rev_mp 1));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    76
by (etac ssubst 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    77
(*were with the previous version of asm_full_simp_tac...
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    78
  by (rotate_tac ~1 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    79
*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    80
by (asm_full_simp_tac (simpset() addsimps [eq_sym_conv, mod_Suc, mod_less]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    81
by (subgoal_tac "(j + N - i) = Suc (j + N - Suc i)" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    82
by (asm_simp_tac (simpset() addsimps [Suc_diff_Suc, less_imp_le, Suc_leI, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    83
                                      diff_add_assoc]) 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    84
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    85
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq, mod_Suc]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    86
(*including less_asym here would slow things down*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    87
by (auto_tac (claset() delrules [notI], 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    88
              simpset() addsimps [diff_add_assoc2, Suc_leI,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    89
                                  less_imp_diff_less, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    90
                                  mod_less, mod_geq, nat_neq_iff]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    91
by (REPEAT (blast_tac (claset() addEs [less_asym]) 3));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    92
by (asm_simp_tac (simpset() addsimps [less_imp_diff_less,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    93
				      Suc_diff_n RS sym]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    94
by (asm_simp_tac (simpset() addsimps [add_diff_less, mod_less]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    95
by (etac subst 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    96
by (asm_simp_tac (simpset() addsimps [add_diff_less]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    97
qed "nodeOrder_eq";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    98
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    99
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   100
(*From "A Logic for Concurrent Programming", but not used in Chapter 4.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   101
  Note the use of case_tac.  Reasoning about leadsTo takes practice!*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   102
goal thy
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   103
 "!!i. [| i<N; j<N |] ==> \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   104
\      leadsTo Acts (HasTok i) ({s. (Token s, i) : nodeOrder j} Un HasTok j)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   105
by (case_tac "i=j" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   106
by (blast_tac (claset() addIs [subset_imp_leadsTo]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   107
by (rtac (TR7 RS leadsTo_weaken_R) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   108
by (Clarify_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   109
by (asm_full_simp_tac (simpset() addsimps [HasTok_def, nodeOrder_eq]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   110
qed "TR7_nodeOrder";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   111
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   112
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   113
(*Chapter 4 variant, the one actually used below.*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   114
goal thy
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   115
 "!!i. [| i<N; j<N; i~=j |] ==> \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   116
\      leadsTo Acts (HasTok i) {s. (Token s, i) : nodeOrder j}";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   117
by (rtac (TR7 RS leadsTo_weaken_R) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   118
by (Clarify_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   119
by (asm_full_simp_tac (simpset() addsimps [HasTok_def, nodeOrder_eq]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   120
qed "TR7_aux";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   121
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   122
goal thy "({s. Token s < N} Int Token -`` {m}) = \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   123
\         (if m<N then Token -`` {m} else {})";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   124
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   125
val Token_lemma = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   126
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   127
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   128
(*Misra's TR9: the token reaches an arbitrary node*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   129
goal thy
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   130
 "!!i. j<N ==> leadsTo Acts {s. Token s < N} (HasTok j)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   131
by (rtac leadsTo_weaken_R 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   132
by (res_inst_tac [("I", "Compl{j}"), ("f", "Token"), ("B", "{}")]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   133
     (wf_nodeOrder RS bounded_induct) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   134
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Token_lemma, vimage_Diff,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   135
						HasTok_def])));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   136
by (Blast_tac 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   137
by (Clarify_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   138
by (rtac (TR7_aux RS leadsTo_weaken) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   139
by (ALLGOALS (asm_simp_tac (simpset() addsimps [nodeOrder_def, HasTok_def])));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   140
by (ALLGOALS Blast_tac);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   141
qed "leadsTo_j";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   142
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   143
(*Misra's TR8: a hungry process eventually eats*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   144
goal thy "!!i. j<N ==> leadsTo Acts ({s. Token s < N} Int H j) (E j)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   145
by (rtac (leadsTo_cancel1 RS leadsTo_Un_duplicate) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   146
by (rtac TR6 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   147
by (rtac leadsTo_weaken_R 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   148
by (rtac ([leadsTo_j, TR3] MRS PSP) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   149
by (ALLGOALS Blast_tac);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   150
qed "Token_progress";