src/HOL/UNITY/Deadlock.ML
author paulson
Tue, 15 Sep 1998 15:04:07 +0200
changeset 5490 85855f65d0c6
parent 5232 e5a7cdd07ea5
child 5502 da4d0444ea85
permissions -rw-r--r--
From Compl(A) to -A
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5232
e5a7cdd07ea5 Tidied; uses records
paulson
parents: 5111
diff changeset
     1
(*  Title:      HOL/UNITY/Deadlock
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     2
    ID:         $Id$
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     4
    Copyright   1998  University of Cambridge
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     5
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     6
Deadlock examples from section 5.6 of 
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     7
    Misra, "A Logic for Concurrent Programming", 1994
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
     8
*)
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
(*Trivial, two-process case*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    11
Goalw [constrains_def, stable_def]
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    12
    "[| constrains Acts (A Int B) A;  constrains Acts (B Int A) B |] \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
\           ==> stable Acts (A Int B)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    18
Goal "{i. i < Suc n} = insert n {i. i < n}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
by (blast_tac (claset() addSEs [less_SucE] addIs [less_SucI]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
qed "Collect_less_Suc_insert";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    23
Goal "{i. i <= Suc n} = insert (Suc n) {i. i <= n}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
by (blast_tac (claset() addSEs [le_SucE] addIs [le_SucI]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
qed "Collect_le_Suc_insert";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
(*a simplification step*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    29
Goal "(INT i:{i. i <= n}. A(Suc i) Int A i) = \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    30
\         (INT i:{i. i <= Suc n}. A i)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    31
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    32
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Collect_le_Suc_insert])));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
by (blast_tac (claset() addEs [le_SucE] addSEs [equalityE]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
qed "Collect_le_Int_equals";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
(*Dual of the required property.  Converse inclusion fails.*)
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    38
Goal "(UN i:{i. i < n}. A i) Int -(A n) <=  \
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    39
\         (UN i:{i. i < n}. (A i) Int -(A(Suc i)))";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
by (simp_tac (simpset() addsimps [Collect_less_Suc_insert]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
qed "UN_Int_Compl_subset";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
(*Converse inclusion fails.*)
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    48
Goal "(INT i:{i. i < n}. -A i Un A (Suc i))  <= \
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    49
\         (INT i:{i. i < n}. -A i) Un A n";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
by (asm_simp_tac (simpset() addsimps [Collect_less_Suc_insert]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
qed "INT_Un_Compl_subset";
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
(*Specialized rewriting*)
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    58
Goal "A 0 Int (-(A n) Int (INT i:{i. i < n}. -A i Un A (Suc i))) = {}";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
by (blast_tac (claset() addIs [gr0I]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
		        addDs [impOfSubs INT_Un_Compl_subset]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
val lemma = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
(*Reverse direction makes it harder to invoke the ind hyp*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    64
Goal "(INT i:{i. i <= n}. A i) = \
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    65
\         A 0 Int (INT i:{i. i < n}. -A i Un A(Suc i))";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
by (asm_simp_tac
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
    (simpset() addsimps (Int_ac @
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
			 [Int_Un_distrib, Int_Un_distrib2, lemma,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
			  Collect_less_Suc_insert, Collect_le_Suc_insert])) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
qed "INT_le_equals_Int";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    74
Goal "(INT i:{i. i <= Suc n}. A i) = \
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    75
\         A 0 Int (INT i:{i. i <= n}. -A i Un A(Suc i))";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    76
by (simp_tac (simpset() addsimps [le_eq_less_Suc RS sym, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    77
				  INT_le_equals_Int]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    78
qed "INT_le_Suc_equals_Int";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    79
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    80
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    81
(*The final deadlock example*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    82
val [zeroprem, allprem] = goalw thy [stable_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    83
    "[| constrains Acts (A 0 Int A (Suc n)) (A 0);  \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    84
\       ALL i:{i. i <= n}. constrains Acts (A(Suc i) Int A i) \
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5232
diff changeset
    85
\                                         (-A i Un A(Suc i)) |] \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    86
\    ==> stable Acts (INT i:{i. i <= Suc n}. A i)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    87
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    88
by (rtac ([zeroprem, allprem RS ball_constrains_INT] MRS 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    89
    constrains_Int RS constrains_weaken) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    90
by (simp_tac (simpset() addsimps [Collect_le_Int_equals, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    91
				  Int_assoc, INT_absorb]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    92
by (simp_tac (simpset() addsimps ([INT_le_Suc_equals_Int])) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    93
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    94