src/HOL/UNITY/Mutex.ML
author paulson
Thu, 02 Jul 1998 16:53:55 +0200
changeset 5111 8f4b72f0c15d
parent 5069 3ea049f7979d
child 5232 e5a7cdd07ea5
permissions -rw-r--r--
Uncurried functions LeadsTo and reach Deleted leading parameters thanks to new Goal command
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     1
(*  Title:      HOL/UNITY/Mutex
4776
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
Based on "A Family of 2-Process Mutual Exclusion Algorithms" by J Misra
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
open Mutex;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    11
val cmd_defs = [mutex_def, cmd0_def, cmd1u_def, cmd1v_def, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    12
		cmd2_def, cmd3_def, cmd4_def];
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    14
Goalw [mutex_def] "id : mutex";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
by (Simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
qed "id_in_mutex";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
AddIffs [id_in_mutex];
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    18
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
(** Constrains/Ensures tactics: NEED TO BE GENERALIZED OVER ALL PROGRAMS **)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
(*proves "constrains" properties when the program is specified*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
val constrains_tac = 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
   SELECT_GOAL
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
      (EVERY [rtac constrainsI 1,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
	      rewtac mutex_def,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
	      REPEAT_FIRST (eresolve_tac [insertE, emptyE]),
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
	      rewrite_goals_tac cmd_defs,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    29
	      ALLGOALS (SELECT_GOAL Auto_tac)]);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    30
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    31
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    32
(*proves "ensures" properties when the program is specified*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
fun ensures_tac sact = 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
    SELECT_GOAL
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
      (EVERY [REPEAT (resolve_tac [LeadsTo_Basis, leadsTo_Basis, ensuresI] 1),
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
	      res_inst_tac [("act", sact)] transient_mem 2,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
	      Simp_tac 2,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
	      constrains_tac 1,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    39
	      rewrite_goals_tac cmd_defs,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
	      Auto_tac]);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
(*The booleans p, u, v are always either 0 or 1*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    44
Goalw [stable_def, boolVars_def]
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
    "stable mutex boolVars";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
by (auto_tac (claset() addSEs [less_SucE], simpset()));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
qed "stable_boolVars";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    50
Goal "reachable (MInit,mutex) <= boolVars";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
by (rtac strongest_invariant 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
by (rtac stable_boolVars 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
by (rewrite_goals_tac [MInit_def, boolVars_def]);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    55
qed "reachable_subset_boolVars";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
val reachable_subset_boolVars' = 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
    rewrite_rule [boolVars_def] reachable_subset_boolVars;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    60
Goalw [stable_def, invariant_def]
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
    "stable mutex (invariant 0 UU MM)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
qed "stable_invar_0um";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    65
Goalw [stable_def, invariant_def]
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
    "stable mutex (invariant 1 VV NN)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
qed "stable_invar_1vn";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    70
Goalw [MInit_def, invariant_def] "MInit <= invariant 0 UU MM";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
qed "MInit_invar_0um";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    74
Goalw [MInit_def, invariant_def] "MInit <= invariant 1 VV NN";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    75
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    76
qed "MInit_invar_1vn";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    77
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    78
(*The intersection is an invariant of the system*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    79
Goal "reachable (MInit,mutex) <= invariant 0 UU MM Int invariant 1 VV NN";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    80
by (simp_tac (simpset() addsimps
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    81
	      [strongest_invariant, Int_greatest, stable_Int, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    82
	       stable_invar_0um, stable_invar_1vn, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    83
	       MInit_invar_0um,MInit_invar_1vn]) 1); 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    84
qed "reachable_subset_invariant";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    85
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    86
val reachable_subset_invariant' = 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    87
    rewrite_rule [invariant_def] reachable_subset_invariant;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    88
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    89
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    90
(*The safety property (mutual exclusion) follows from the claimed invar_s*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    91
Goalw [invariant_def]
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    92
    "{s. s MM = 3 & s NN = 3} <= \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    93
\    Compl (invariant 0 UU MM Int invariant 1 VV NN)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    94
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    95
val lemma = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    96
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    97
Goal "{s. s MM = 3 & s NN = 3} <= Compl (reachable (MInit,mutex))";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    98
by (rtac ([lemma, reachable_subset_invariant RS Compl_anti_mono] MRS subset_trans) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    99
qed "mutual_exclusion";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   100
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   101
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   102
(*The bad invariant FAILS in cmd1v*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
   103
Goalw [stable_def, bad_invariant_def]
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   104
    "stable mutex (bad_invariant 0 UU MM)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   105
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   106
by (trans_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   107
by (safe_tac (claset() addSEs [le_SucE]));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   108
by (Asm_full_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   109
(*Resulting state: n=1, p=false, m=4, u=false.  
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   110
  Execution of cmd1v (the command of process v guarded by n=1) sets p:=true,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   111
  violating the invariant!*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   112
(*Check that subgoals remain: proof failed.*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   113
getgoal 1;  
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   114
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   115
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   116
(*** Progress for U ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   117
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
   118
Goalw [unless_def] "unless mutex {s. s MM=2} {s. s MM=3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   119
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   120
qed "U_F0";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   121
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   122
Goal "LeadsTo(MInit,mutex) {s. s MM=1} {s. s PP = s VV & s MM = 2}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   123
by (rtac leadsTo_imp_LeadsTo 1);   (*makes the proof much faster*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   124
by (ensures_tac "cmd1u" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   125
qed "U_F1";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   126
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   127
Goal "LeadsTo(MInit,mutex) {s. s PP = 0 & s MM = 2} {s. s MM = 3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   128
by (cut_facts_tac [reachable_subset_invariant'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   129
by (ensures_tac "cmd2 0 MM" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   130
qed "U_F2";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   131
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   132
Goalw [mutex_def] "LeadsTo(MInit,mutex) {s. s MM = 3} {s. s PP = 1}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   133
by (rtac leadsTo_imp_LeadsTo 1); 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   134
by (res_inst_tac [("B", "{s. s MM = 4}")] leadsTo_Trans 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   135
by (ensures_tac "cmd4 1 MM" 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   136
by (ensures_tac "cmd3 UU MM" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   137
qed "U_F3";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   138
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   139
Goal "LeadsTo(MInit,mutex) {s. s MM = 2} {s. s PP = 1}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   140
by (rtac ([LeadsTo_weaken_L, subset_refl RS subset_imp_LeadsTo] 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   141
	  MRS LeadsTo_Diff) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   142
by (rtac ([U_F2, U_F3] MRS LeadsTo_Trans) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   143
by (cut_facts_tac [reachable_subset_boolVars'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   144
by (auto_tac (claset() addSEs [less_SucE], simpset()));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   145
val lemma2 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   146
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   147
Goal "LeadsTo(MInit,mutex) {s. s MM = 1} {s. s PP = 1}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   148
by (rtac ([U_F1 RS LeadsTo_weaken_R, lemma2] MRS LeadsTo_Trans) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   149
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   150
val lemma1 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   151
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   152
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   153
Goal "LeadsTo(MInit,mutex) {s. 1 <= s MM & s MM <= 3} {s. s PP = 1}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   154
by (simp_tac (simpset() addsimps [le_Suc_eq, conj_disj_distribL] 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   155
	                addcongs [rev_conj_cong]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   156
by (simp_tac (simpset() addsimps [Collect_disj_eq, LeadsTo_Un_distrib,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   157
				  lemma1, lemma2, U_F3] ) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   158
val lemma123 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   159
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   160
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   161
(*Misra's F4*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   162
Goal "LeadsTo(MInit,mutex) {s. s UU = 1} {s. s PP = 1}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   163
by (rtac LeadsTo_weaken_L 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   164
by (rtac lemma123 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   165
by (cut_facts_tac [reachable_subset_invariant'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   166
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   167
qed "u_leadsto_p";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   168
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   169
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   170
(*** Progress for V ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   171
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   172
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
   173
Goalw [unless_def] "unless mutex {s. s NN=2} {s. s NN=3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   174
by (constrains_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   175
qed "V_F0";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   176
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   177
Goal "LeadsTo(MInit,mutex) {s. s NN=1} {s. s PP = 1 - s UU & s NN = 2}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   178
by (rtac leadsTo_imp_LeadsTo 1);   (*makes the proof much faster*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   179
by (ensures_tac "cmd1v" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   180
qed "V_F1";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   181
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   182
Goal "LeadsTo(MInit,mutex) {s. s PP = 1 & s NN = 2} {s. s NN = 3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   183
by (cut_facts_tac [reachable_subset_invariant'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   184
by (ensures_tac "cmd2 1 NN" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   185
qed "V_F2";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   186
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   187
Goalw [mutex_def] "LeadsTo(MInit,mutex) {s. s NN = 3} {s. s PP = 0}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   188
by (rtac leadsTo_imp_LeadsTo 1); 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   189
by (res_inst_tac [("B", "{s. s NN = 4}")] leadsTo_Trans 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   190
by (ensures_tac "cmd4 0 NN" 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   191
by (ensures_tac "cmd3 VV NN" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   192
qed "V_F3";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   193
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   194
Goal "LeadsTo(MInit,mutex) {s. s NN = 2} {s. s PP = 0}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   195
by (rtac ([LeadsTo_weaken_L, subset_refl RS subset_imp_LeadsTo] 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   196
	  MRS LeadsTo_Diff) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   197
by (rtac ([V_F2, V_F3] MRS LeadsTo_Trans) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   198
by (cut_facts_tac [reachable_subset_boolVars'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   199
by (auto_tac (claset() addSEs [less_SucE], simpset()));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   200
val lemma2 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   201
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   202
Goal "LeadsTo(MInit,mutex) {s. s NN = 1} {s. s PP = 0}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   203
by (rtac ([V_F1 RS LeadsTo_weaken_R, lemma2] MRS LeadsTo_Trans) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   204
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   205
val lemma1 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   206
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   207
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   208
Goal "LeadsTo(MInit,mutex) {s. 1 <= s NN & s NN <= 3} {s. s PP = 0}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   209
by (simp_tac (simpset() addsimps [le_Suc_eq, conj_disj_distribL] 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   210
	                addcongs [rev_conj_cong]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   211
by (simp_tac (simpset() addsimps [Collect_disj_eq, LeadsTo_Un_distrib,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   212
				  lemma1, lemma2, V_F3] ) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   213
val lemma123 = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   214
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   215
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   216
(*Misra's F4*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   217
Goal "LeadsTo(MInit,mutex) {s. s VV = 1} {s. s PP = 0}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   218
by (rtac LeadsTo_weaken_L 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   219
by (rtac lemma123 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   220
by (cut_facts_tac [reachable_subset_invariant'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   221
by Auto_tac;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   222
qed "v_leadsto_not_p";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   223
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   224
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   225
(** Absence of starvation **)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   226
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   227
(*Misra's F6*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   228
Goal "LeadsTo(MInit,mutex) {s. s MM = 1} {s. s MM = 3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   229
by (rtac LeadsTo_Un_duplicate 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   230
by (rtac LeadsTo_cancel2 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   231
by (rtac U_F2 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   232
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   233
by (stac Un_commute 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   234
by (rtac LeadsTo_Un_duplicate 1);
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   235
by (rtac ([v_leadsto_not_p, U_F0] MRS R_PSP_unless RSN(2, LeadsTo_cancel2)) 1);
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   236
by (rtac (U_F1 RS LeadsTo_weaken_R) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   237
by (cut_facts_tac [reachable_subset_boolVars'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   238
by (auto_tac (claset() addSEs [less_SucE], simpset()));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   239
qed "m1_leadsto_3";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   240
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   241
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   242
(*The same for V*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
   243
Goal "LeadsTo(MInit,mutex) {s. s NN = 1} {s. s NN = 3}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   244
by (rtac LeadsTo_Un_duplicate 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   245
by (rtac LeadsTo_cancel2 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   246
by (rtac V_F2 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   247
by (simp_tac (simpset() addsimps [Collect_conj_eq] ) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   248
by (stac Un_commute 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   249
by (rtac LeadsTo_Un_duplicate 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   250
by (rtac ([u_leadsto_p, V_F0] MRS R_PSP_unless  RSN(2, LeadsTo_cancel2)) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   251
by (rtac (V_F1 RS LeadsTo_weaken_R) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   252
by (cut_facts_tac [reachable_subset_boolVars'] 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   253
by (auto_tac (claset() addSEs [less_SucE], simpset()));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   254
qed "n1_leadsto_3";