src/HOL/UNITY/Common.ML
author nipkow
Mon, 20 Jul 1998 16:04:53 +0200
changeset 5162 53e505c6019c
parent 5111 8f4b72f0c15d
child 5240 bbcd79ef7cf2
permissions -rw-r--r--
Added simproc list_eq.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/Common
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
Common Meeting Time example from Misra (1994)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
The state is identified with the one variable in existence.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
From Misra, "A Logic for Concurrent Programming" (1994), sections 5.1 and 13.1.
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
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
open Common;
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
(*Misra's property CMT4: t exceeds no common meeting time*)
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    17
Goal "[| ALL m. constrains Acts {m} (maxfg m); n: common |] \
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    18
\     ==> stable Acts (atMost n)";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
by (dres_inst_tac [("P", "%t. t<=n")] elimination_sing 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
by (asm_full_simp_tac
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
    (simpset() addsimps [atMost_def, stable_def, common_def, maxfg_def,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
			 constrains_def, le_max_iff_disj]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
by (Clarify_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
by (dtac bspec 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
by (assume_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
by (blast_tac (claset() addSEs [subsetCE]
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
			addIs [order_eq_refl, fmono, gmono, le_trans]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
qed "common_stable";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    29
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    30
Goal "[| ALL m. constrains Acts {m} (maxfg m); n: common |] \
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    31
\     ==> reachable ({0},Acts) <= atMost n";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    32
by (rtac strongest_invariant 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
by (asm_simp_tac (simpset() addsimps [common_stable]) 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
by (simp_tac (simpset() addsimps [atMost_def]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
qed "common_invariant";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
(*** Some programs that implement the safety property above ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    39
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
(*This one is just Skip*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    41
Goal "constrains {id} {m} (maxfg m)";
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
by (simp_tac (simpset() addsimps [constrains_def, maxfg_def, le_max_iff_disj,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
				  fasc, gasc]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
(*This one is  t := ftime t || t := gtime t    really needs Skip too*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    47
Goal "constrains {range(%t.(t,ftime t)), range(%t.(t,gtime t))} \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
\                    {m} (maxfg m)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
by (simp_tac (simpset() addsimps [constrains_def, maxfg_def, 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
				  le_max_iff_disj]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
(*This one is  t := max (ftime t) (gtime t)    really needs Skip too*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    55
Goal "constrains {range(%t.(t, max (ftime t) (gtime t)))} \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
\                    {m} (maxfg m)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
by (simp_tac (simpset() addsimps [constrains_def, maxfg_def]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
by (Blast_tac 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
(*This one is  t := t+1 if t <max (ftime t) (gtime t) *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    62
Goalw [constrains_def, maxfg_def] 
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
    "constrains { {(t, Suc t) | t. t < max (ftime t) (gtime t)} } \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
\               {m} (maxfg m)";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    65
by (blast_tac (claset() addIs [Suc_leI]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
(*It remans to prove that they satisfy CMT3': t does not decrease,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
  and that CMT3' implies that t stops changing once common(t) holds.*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
(*** Progress under weak fairness ***)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    74
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    75
Addsimps [atMost_Int_atLeast];
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    76
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    77
Goal
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    78
    "[| ALL m. constrains Acts {m} (maxfg m); \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    79
\               ALL m: lessThan n. leadsTo Acts {m} (greaterThan m); \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    80
\               n: common;  id: Acts |]  \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    81
\            ==> leadsTo Acts (atMost n) common";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    82
by (rtac leadsTo_weaken_R 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    83
by (res_inst_tac [("f","%x. x"), ("l", "n")] greaterThan_bounded_induct 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    84
by (ALLGOALS Asm_simp_tac);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    85
by (rtac subset_refl 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    86
by (blast_tac (claset() addDs [PSP_stable2] 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    87
                        addIs [common_stable, leadsTo_weaken_R]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    88
val lemma = result();
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    89
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    90
(*The "ALL m: Compl common" form echoes CMT6.*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4776
diff changeset
    91
Goal
5111
8f4b72f0c15d Uncurried functions LeadsTo and reach
paulson
parents: 5069
diff changeset
    92
    "[| ALL m. constrains Acts {m} (maxfg m); \
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    93
\               ALL m: Compl common. leadsTo Acts {m} (greaterThan m); \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    94
\               n: common;  id: Acts |]  \
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    95
\            ==> leadsTo Acts (atMost (LEAST n. n: common)) common";
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    96
by (rtac lemma 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    97
by (ALLGOALS Asm_simp_tac);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    98
by (etac LeastI 2);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    99
by (blast_tac (claset() addSDs [not_less_Least]) 1);
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
   100
qed "leadsTo_common";