src/HOL/UNITY/Deadlock.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
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     2
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     3
(*** Deadlock examples from section 5.6 ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     4
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     5
(*Trivial, two-process case*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     6
goalw thy [constrains_def, stable_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
    "!!Acts. [| constrains Acts (A Int B) A;  constrains Acts (B Int A) B |] \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
\           ==> stable Acts (A Int B)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    11
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    12
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
goal thy "{i. i < Suc n} = insert n {i. i < n}";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
by (blast_tac (claset() addSEs [less_SucE] addIs [less_SucI]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
qed "Collect_less_Suc_insert";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    18
goal thy "{i. i <= Suc n} = insert (Suc n) {i. i <= n}";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
by (blast_tac (claset() addSEs [le_SucE] addIs [le_SucI]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
qed "Collect_le_Suc_insert";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
(*a simplification step*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
goal thy "(INT i:{i. i <= n}. A(Suc i) Int A i) = \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
\         (INT i:{i. i <= Suc n}. A i)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Collect_le_Suc_insert])));
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
by (blast_tac (claset() addEs [le_SucE] addSEs [equalityE]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    29
qed "Collect_le_Int_equals";
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
(*Dual of the required property.  Converse inclusion fails.*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
goal thy "(UN i:{i. i < n}. A i) Int Compl (A n) <=  \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
\         (UN i:{i. i < n}. (A i) Int Compl (A(Suc i)))";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
by (simp_tac (simpset() addsimps [Collect_less_Suc_insert]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    39
qed "UN_Int_Compl_subset";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
(*Converse inclusion fails.*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
goal thy "(INT i:{i. i < n}. Compl(A i) Un A (Suc i))  <= \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
\         (INT i:{i. i < n}. Compl(A i)) Un A n";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
by (asm_simp_tac (simpset() addsimps [Collect_less_Suc_insert]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
qed "INT_Un_Compl_subset";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
(*Specialized rewriting*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
goal thy "A 0 Int (Compl (A n) Int \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
\                  (INT i:{i. i < n}. Compl(A i) Un A (Suc i))) = {}";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    55
by (blast_tac (claset() addIs [gr0I]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
		        addDs [impOfSubs INT_Un_Compl_subset]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
val lemma = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
(*Reverse direction makes it harder to invoke the ind hyp*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
goal thy "(INT i:{i. i <= n}. A i) = \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
\         A 0 Int (INT i:{i. i < n}. Compl(A i) Un A(Suc i))";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
by (induct_tac "n" 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
by (Asm_simp_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
by (asm_simp_tac
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    65
    (simpset() addsimps (Int_ac @
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
			 [Int_Un_distrib, Int_Un_distrib2, lemma,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
			  Collect_less_Suc_insert, Collect_le_Suc_insert])) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
qed "INT_le_equals_Int";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
goal thy "(INT i:{i. i <= Suc n}. A i) = \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
\         A 0 Int (INT i:{i. i <= n}. Compl(A i) Un A(Suc i))";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
by (simp_tac (simpset() addsimps [le_eq_less_Suc RS sym, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
				  INT_le_equals_Int]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    74
qed "INT_le_Suc_equals_Int";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    75
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    76
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    77
(*The final deadlock example*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    78
val [zeroprem, allprem] = goalw thy [stable_def]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    79
    "[| constrains Acts (A 0 Int A (Suc n)) (A 0);  \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    80
\       ALL i:{i. i <= n}. constrains Acts (A(Suc i) Int A i) \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    81
\                                         (Compl(A i) Un A(Suc i)) |] \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    82
\    ==> stable Acts (INT i:{i. i <= Suc n}. A i)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    83
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    84
by (rtac ([zeroprem, allprem RS ball_constrains_INT] MRS 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    85
    constrains_Int RS constrains_weaken) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    86
by (simp_tac (simpset() addsimps [Collect_le_Int_equals, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    87
				  Int_assoc, INT_absorb]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    88
by (simp_tac (simpset() addsimps ([INT_le_Suc_equals_Int])) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    89
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    90