Test.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 03 Jun 2014 15:00:12 +0100
changeset 40 0781a2fc93f1
parent 39 7ea6b019ce24
child 41 66ed924aaa5c
permissions -rw-r--r--
added a library about graphs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Test 
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
     2
imports Precedence_ord Graphs
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
type_synonym thread = nat -- {* Type for thread identifiers. *}
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
type_synonym priority = nat  -- {* Type for priorities. *}
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
     7
type_synonym cs = nat -- {* Type for critical sections (or resources). *}
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
datatype event = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  Create thread priority 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
| Exit thread 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
| P thread cs 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
| V thread cs 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
| Set thread priority 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
type_synonym state = "event list"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
fun threads :: "state \<Rightarrow> thread set"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  where 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  "threads [] = {}" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
| "threads (Create th prio#s) = {th} \<union> threads s" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
| "threads (Exit th # s) = (threads s) - {th}" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
| "threads (_#s) = threads s" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
fun priority :: "thread \<Rightarrow> state \<Rightarrow> priority"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  "priority th [] = 0" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
| "priority th (Create th' prio#s) = (if th' = th then prio else priority th s)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
| "priority th (Set th' prio#s) = (if th' = th then prio else priority th s)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
| "priority th (_#s) = priority th s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
fun last_set :: "thread \<Rightarrow> state \<Rightarrow> nat"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  "last_set th [] = 0" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
| "last_set th ((Create th' prio)#s) = (if (th = th') then length s else last_set th s)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
| "last_set th ((Set th' prio)#s) = (if (th = th') then length s else last_set th s)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
| "last_set th (_#s) = last_set th s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
definition preced :: "thread \<Rightarrow> state \<Rightarrow> precedence"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  where "preced th s \<equiv> Prc (priority th s) (last_set th s)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  "holds wq th cs \<equiv> th \<in> set (wq cs) \<and> th = hd (wq cs)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  "waits wq th cs \<equiv> th \<in> set (wq cs) \<and> th \<noteq> hd (wq cs)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
datatype node = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  Th "thread" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
| Cs "cs" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  "RAG wq \<equiv> {(Th th, Cs cs) | th cs. waits wq th cs} \<union> {(Cs cs, Th th) | cs th. holds wq th cs}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  "dependants wq th \<equiv> {th' . (Th th', Th th) \<in> (RAG wq)^+}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
record schedule_state = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  wq_fun :: "cs \<Rightarrow> thread list" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  cprec_fun :: "thread \<Rightarrow> precedence" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
definition cpreced :: "(cs \<Rightarrow> thread list) \<Rightarrow> state \<Rightarrow> thread \<Rightarrow> precedence"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
  where 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
  "cpreced wq s th \<equiv> Max ({preced th s} \<union> {preced th' s | th'. th' \<in> dependants wq th})"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
abbreviation
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  "all_unlocked \<equiv> \<lambda>_::cs. ([]::thread list)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
abbreviation 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  "initial_cprec \<equiv> \<lambda>_::thread. Prc 0 0"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
abbreviation
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  "release qs \<equiv> case qs of
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
             [] => [] 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
    75
          |  (_ # qs) => SOME q. distinct q \<and> set q = set qs"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
fun schs :: "state \<Rightarrow> schedule_state"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
  where 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  "schs [] = (| wq_fun = \<lambda> cs. [],  cprec_fun = (\<lambda>_. Prc 0 0) |)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
| "schs (Create th prio # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
       (let wq = wq_fun (schs s) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
          (|wq_fun = wq, cprec_fun = cpreced wq (Create th prio # s)|))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
|  "schs (Exit th # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
       (let wq = wq_fun (schs s) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
          (|wq_fun = wq, cprec_fun = cpreced wq (Exit th # s)|))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
|  "schs (Set th prio # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
       (let wq = wq_fun (schs s) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
          (|wq_fun = wq, cprec_fun = cpreced wq (Set th prio # s)|))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
|  "schs (P th cs # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
       (let wq = wq_fun (schs s) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
        let new_wq = wq(cs := (wq cs @ [th])) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
          (|wq_fun = new_wq, cprec_fun = cpreced new_wq (P th cs # s)|))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
|  "schs (V th cs # s) = 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
       (let wq = wq_fun (schs s) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
        let new_wq = wq(cs := release (wq cs)) in
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
          (|wq_fun = new_wq, cprec_fun = cpreced new_wq (V th cs # s)|))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
definition wq :: "state \<Rightarrow> cs \<Rightarrow> thread list" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  where "wq s = wq_fun (schs s)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   101
definition cpreced2 :: "state \<Rightarrow> thread \<Rightarrow> precedence"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   102
  where "cpreced2 s \<equiv> cprec_fun (schs s)"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   103
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   104
abbreviation
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   105
  "cpreceds2 s ths \<equiv> {cpreced2 s th | th. th \<in> ths}"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
  "holds2 s \<equiv> holds (wq_fun (schs s))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  "waits2 s \<equiv> waits (wq_fun (schs s))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
  "RAG2 s \<equiv> RAG (wq_fun (schs s))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  "dependants2 s \<equiv> dependants (wq_fun (schs s))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   119
(* ready -> is a thread that is not waiting for any resource *) 
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
definition readys :: "state \<Rightarrow> thread set"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  where "readys s \<equiv> {th . th \<in> threads s \<and> (\<forall> cs. \<not> waits2 s th cs)}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
definition runing :: "state \<Rightarrow> thread set"
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   124
  where "runing s \<equiv> {th . th \<in> readys s \<and> cpreced2 s th = Max (cpreceds2 s (readys s))}"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   126
(* all resources a thread hols in a state *)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
definition holding :: "state \<Rightarrow> thread \<Rightarrow> cs set"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  where "holding s th \<equiv> {cs . holds2 s th cs}"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   130
abbreviation
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   131
  "next_to_run ths \<equiv> hd (SOME q::thread list. distinct q \<and> set q = set ths)"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   132
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   133
lemma exists_distinct:
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   134
  obtains ys where "distinct ys" "set ys = set xs"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   135
by (metis List.finite_set finite_distinct_list)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   136
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   137
lemma next_to_run_set [simp]:
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   138
  "wts \<noteq> [] \<Longrightarrow> next_to_run wts \<in> set wts"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   139
apply(rule exists_distinct[of wts])
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   140
by (metis (mono_tags, lifting) hd_in_set set_empty some_eq_ex)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   141
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
lemma holding_RAG: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  "holding s th = {cs . (Cs cs, Th th) \<in> RAG2 s}"
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   144
unfolding holding_def RAG2_def RAG_def
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   145
unfolding holds2_def holds_def waits_def
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
inductive step :: "state \<Rightarrow> event \<Rightarrow> bool"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
  step_Create: "\<lbrakk>th \<notin> threads s\<rbrakk> \<Longrightarrow> step s (Create th prio)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
| step_Exit: "\<lbrakk>th \<in> runing s; holding s th = {}\<rbrakk> \<Longrightarrow> step s (Exit th)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
| step_P: "\<lbrakk>th \<in> runing s;  (Cs cs, Th th)  \<notin> (RAG2 s)^+\<rbrakk> \<Longrightarrow> step s (P th cs)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
| step_V: "\<lbrakk>th \<in> runing s;  holds2 s th cs\<rbrakk> \<Longrightarrow> step s (V th cs)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
| step_Set: "\<lbrakk>th \<in> runing s\<rbrakk> \<Longrightarrow> step s (Set th prio)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   156
(* valid states *)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
inductive vt :: "state \<Rightarrow> bool"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  vt_nil[intro]: "vt []" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
| vt_cons[intro]: "\<lbrakk>vt s; step s e\<rbrakk> \<Longrightarrow> vt (e#s)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
lemma runing_ready: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
  shows "runing s \<subseteq> readys s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
  unfolding runing_def readys_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
  by auto 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
lemma readys_threads:
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
  shows "readys s \<subseteq> threads s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
  unfolding readys_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
  by auto
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
lemma wq_distinct_step: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
  assumes "step s e" "distinct (wq s cs)" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
  shows "distinct (wq (e # s) cs)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
using assms
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   176
unfolding wq_def
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
apply(induct)
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   178
apply(auto simp add: RAG2_def RAG_def Let_def)[1]
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   179
apply(auto simp add: wq_def Let_def RAG2_def RAG_def holds_def runing_def waits2_def waits_def readys_def)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
apply(auto split: list.split)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
apply(rule someI2)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
apply(auto)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
lemma wq_distinct: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
  assumes "vt s" 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
  shows "distinct (wq s cs)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
using assms
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
apply(induct)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
apply(simp add: wq_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
apply(simp add: wq_distinct_step)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
lemma RAG_set_unchanged[simp]: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  shows "RAG2 (Set th prio # s) = RAG2 s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
unfolding RAG2_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
by (simp add: Let_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
lemma RAG_create_unchanged[simp]: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
  "RAG2 (Create th prio # s) = RAG2 s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
unfolding RAG2_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
by (simp add: Let_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
lemma RAG_exit_unchanged[simp]: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  shows "RAG2 (Exit th # s) = RAG2 s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
unfolding RAG2_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
by (simp add: Let_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
lemma RAG_p1:
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
  assumes "wq s cs = []"
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   211
  shows "RAG2 (P th cs # s) \<subseteq> RAG2 s \<union> {(Cs cs, Th th)}"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   212
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   213
unfolding  RAG2_def RAG_def wq_def Let_def waits_def holds_def
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   214
by (auto simp add: Let_def)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   215
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
lemma RAG_p2:
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   218
  assumes "(Cs cs, Th th) \<notin> (RAG2 s)\<^sup>+" "wq s cs \<noteq> []"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   219
  shows "RAG2 (P th cs # s) \<subseteq> RAG2 s \<union> {(Th th, Cs cs)}"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   220
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   221
unfolding RAG2_def RAG_def wq_def Let_def waits_def holds_def
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   222
by (auto simp add: Let_def)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   223
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   224
lemma [simp]: "(SOME q. distinct q \<and> q = []) = []"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   225
by auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   226
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   227
lemma [simp]: "(x \<in> set (SOME q. distinct q \<and> set q = set p)) = (x \<in> set p)"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   228
apply auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   229
apply (metis (mono_tags, lifting) List.finite_set finite_distinct_list some_eq_ex)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   230
by (metis (mono_tags, lifting) List.finite_set finite_distinct_list some_eq_ex)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   232
lemma RAG_v1:
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   233
assumes vt: "wq s cs = [th]"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   234
shows "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th)}"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   235
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   236
unfolding RAG2_def RAG_def waits_def holds_def wq_def
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   237
by (auto simp add: Let_def)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   239
lemma RAG_v2:
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   240
assumes vt:"vt s" "wq s cs = th # wts \<and> wts \<noteq> []"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   241
shows "RAG2 (V th cs # s) \<subseteq>
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   242
  RAG2 s - {(Cs cs, Th th), (Th (next_to_run wts), Cs cs)} \<union> {(Cs cs, Th (next_to_run wts))}"
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   243
unfolding RAG2_def RAG_def waits_def holds_def
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   244
using assms wq_distinct[OF vt(1), of"cs"]
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   245
by (auto simp add: Let_def wq_def)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   247
(*
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   248
lemma single_valued_waits2:
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   249
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   250
  shows "single_valuedP (waits2 s)"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   251
using assms
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   252
apply(induct)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   253
apply(simp add: waits2_def waits_def)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   254
apply(erule step.cases)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   255
apply(auto simp add: Let_def waits2_def)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   256
unfolding single_valued_def waits2_def waits_def
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   257
apply(auto)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   258
*)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   259
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   260
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   261
lemma waits2_unique:
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  assumes "vt s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
  and "waits2 s th cs1"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
  and "waits2 s th cs2"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  shows "cs1 = cs2"
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   266
using assms
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   267
apply(induct)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   268
apply(simp add: waits2_def waits_def)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   269
apply(erule step.cases)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   270
apply(auto simp add: Let_def waits2_def waits_def holds_def RAG2_def RAG_def 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   271
 readys_def runing_def split: if_splits)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   272
apply (metis Nil_is_append_conv hd_append2 list.distinct(1) split_list)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   273
apply (metis Nil_is_append_conv hd_append2 list.distinct(1) split_list)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   274
apply (metis distinct.simps(2) distinct_length_2_or_more list.sel(1) wq_def wq_distinct)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   275
by (metis (full_types, hide_lams) distinct.simps(2) distinct_length_2_or_more list.sel(1) wq_def wq_distinct)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   276
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   277
lemma single_valued_holds2:
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   278
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   279
  shows "single_valuedP (\<lambda>cs th. holds2 s th cs)"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   280
unfolding single_valued_def holds2_def holds_def by simp
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   281
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   282
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   283
lemma holds2_unique: 
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   284
  assumes "holds2 s th1 cs"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   285
  and      "holds2 s th2 cs"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   286
  shows "th1 = th2"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   287
using assms
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   288
unfolding holds2_def holds_def by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   289
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   290
lemma single_valued_waits2:
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   291
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   292
  shows "single_valuedP (waits2 s)"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   293
by (metis (erased, hide_lams) assms mem_Collect_eq old.prod.case single_valued_def waits2_unique)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   294
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   295
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   296
(* was unique_RAG2 *)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   297
lemma single_valued_RAG2:
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   298
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   299
  shows "single_valued (RAG2 s)"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   300
using single_valued_waits2[OF assms] single_valued_holds2[OF assms] 
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   301
unfolding RAG2_def RAG_def 
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   302
unfolding single_valued_def
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   303
unfolding holds2_def waits2_def 
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   304
by auto 
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
lemma acyclic_RAG_step: 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
  assumes vt: "vt s"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
  and     stp: "step s e"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
  and     ac: "acyclic (RAG2 s)"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
  shows "acyclic (RAG2 (e # s))"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
using stp vt ac
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
proof (induct)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  case (step_P th s cs)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  have ac: "acyclic (RAG2 s)" by fact
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
  have ds: "(Cs cs, Th th) \<notin> (RAG2 s)\<^sup>+" by fact
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   316
  { assume wq_empty: "wq s cs = []" -- "case waiting queue is empty"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   317
    then have "(Th th, Cs cs) \<notin> (RAG2 s)\<^sup>+"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   318
    proof (rule_tac notI)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   319
      assume "(Th th, Cs cs) \<in> (RAG2 s)\<^sup>+"
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
      then obtain x where "(x, Cs cs) \<in> RAG2 s" using tranclD2 by metis 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   321
      with wq_empty show False by (auto simp: RAG2_def RAG_def wq_def waits_def)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
    qed
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   323
    with ac have "acyclic (RAG2 s \<union> {(Cs cs, Th th)})" by simp
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   324
    then have "acyclic (RAG2 (P th cs # s))" using RAG_p1[OF wq_empty] 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   325
      by (rule acyclic_subset)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
  moreover
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   328
  { assume wq_not_empty: "wq s cs \<noteq> []" -- "case waiting queue is not empty"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   329
    from ac ds
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   330
    have "acyclic (RAG2 s \<union> {(Th th, Cs cs)})" by simp
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   331
    then have "acyclic (RAG2 (P th cs # s))" using RAG_p2[OF ds wq_not_empty] 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   332
      by (rule acyclic_subset)
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
  ultimately show "acyclic (RAG2 (P th cs # s))" by metis
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
next    
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   336
  case (step_V th s cs) -- "case for release of a lock" 
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
  have vt: "vt s" by fact
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
  have ac: "acyclic (RAG2 s)" by fact
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  have hd: "holds2 s th cs" by fact
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   340
  from vt have wq_distinct:"distinct (wq s cs)" by (rule wq_distinct)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   341
  from hd have "th \<in> set (wq s cs)" "th = hd (wq s cs)" unfolding holds2_def holds_def wq_def by auto
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   342
  then obtain wts where eq_wq: "wq s cs = th # wts"  by (cases "wq s cs") (auto)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   343
  -- "case no thread present in the waiting queue to take over"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   344
  { assume "wts = []" 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   345
    with eq_wq have "wq s cs = [th]" by simp
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   346
    then have "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th)}" by (rule RAG_v1)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   347
    moreover have "acyclic (RAG2 s - {(Cs cs, Th th)})" using ac by (auto intro: acyclic_subset)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   348
    ultimately 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   349
    have "acyclic (RAG2 (V th cs # s))" by (auto intro: acyclic_subset)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   350
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   351
  moreover
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   352
  -- "at least one thread present to take over"
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   353
  { def nth \<equiv> "next_to_run wts"
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   354
    assume wq_not_empty: "wts \<noteq> []" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   355
    have waits2_cs: "waits2 s nth cs" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   356
      using eq_wq wq_not_empty wq_distinct
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   357
      unfolding nth_def waits2_def waits_def wq_def[symmetric] by auto
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   358
    have "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)} \<union> {(Cs cs, Th nth)}" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   359
      unfolding nth_def using  vt wq_not_empty eq_wq by (rule_tac RAG_v2) (auto)
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   360
    moreover 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   361
    have "acyclic (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)} \<union> {(Cs cs, Th nth)})" 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   362
    proof -
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   363
      have "acyclic (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)})" using ac by (auto intro: acyclic_subset)
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   364
      moreover 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   365
      have "(Th nth, Cs cs) \<notin> (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)})\<^sup>+" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   366
      proof (rule notI)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   367
        assume "(Th nth, Cs cs) \<in> (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)})\<^sup>+"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   368
        then obtain z where a: "(Th nth, z) \<in> (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)})"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   369
          by (metis converse_tranclE)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   370
        then have "(Th nth, z) \<in> RAG2 s" by simp
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   371
        then obtain cs' where b: "z = Cs cs'" "(Th nth, Cs cs') \<in> RAG2 s"
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   372
          unfolding RAG2_def RAG_def by auto
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   373
        moreover 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   374
        have "waits2 s nth cs'" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   375
          using b(2) unfolding RAG2_def RAG_def waits2_def by simp
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   376
        ultimately have "cs = cs'" 
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   377
          by (rule_tac waits2_unique[OF vt waits2_cs])
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   378
        then show "False" using a b(1) by simp
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   379
      qed
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   380
      ultimately 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   381
      show "acyclic (RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)} \<union> {(Cs cs, Th nth) })" by simp
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   382
    qed
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   383
    ultimately have "acyclic (RAG2 (V th cs # s))" 
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   384
      by (rule_tac acyclic_subset)
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   385
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   386
  ultimately show "acyclic (RAG2 (V th cs # s))" by metis
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
qed (simp_all)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   390
lemma finite_RAG:
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   391
  assumes "vt s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   392
  shows "finite (RAG2 s)"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   393
using assms
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   394
apply(induct)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   395
apply(simp add: RAG2_def RAG_def waits_def holds_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   396
apply(erule step.cases)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   397
apply(auto)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   398
apply(case_tac "wq sa cs = []")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   399
apply(rule finite_subset)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   400
apply(rule RAG_p1)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   401
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   402
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   403
apply(rule finite_subset)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   404
apply(rule RAG_p2)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   405
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   406
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   407
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   408
apply(subgoal_tac "\<exists>wts. wq sa cs = th # wts")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   409
apply(erule exE)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   410
apply(case_tac "wts = []")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   411
apply(rule finite_subset)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   412
apply(rule RAG_v1)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   413
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   414
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   415
apply(rule finite_subset)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   416
apply(rule RAG_v2)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   417
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   418
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   419
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   420
apply(subgoal_tac "th \<in> set (wq sa cs) \<and> th = hd (wq sa cs)") 
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   421
apply(case_tac "wq sa cs") 
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   422
apply(auto)[2]
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   423
apply(auto simp add: holds2_def holds_def wq_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   424
done
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   425
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   426
lemma wq_threads: 
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   427
  assumes vt: "vt s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   428
  and h: "th \<in> set (wq s cs)"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   429
  shows "th \<in> threads s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   430
using assms
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   431
apply(induct)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   432
apply(simp add: wq_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   433
apply(erule step.cases)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   434
apply(auto simp add: wq_def Let_def holding_def holds2_def holds_def waits2_def runing_def readys_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   435
apply(simp add: waits_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   436
apply(auto simp add: waits_def split: if_splits)[1]
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   437
apply(auto split: if_splits)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   438
apply(simp only: waits_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   439
by (metis insert_iff set_simps(2))
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   440
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   441
lemma max_cpreceds_readys_threads:
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   442
  assumes vt: "vt s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   443
  shows "Max (cpreceds2 s (readys s)) = Max (cpreceds2 s (threads s))"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   444
apply(case_tac "threads s = {}")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   445
apply(simp add: readys_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   446
using vt
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   447
apply(induct)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   448
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   449
apply(erule step.cases)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   450
apply(auto simp add: readys_def waits2_def waits_def Let_def holding_def runing_def holds2_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   451
defer
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   452
defer
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   453
oops
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   456
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   457
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   458
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   459
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   460
lemma dchain_unique:
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   461
  assumes vt: "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   462
  and th1_d: "(n, Th th1) \<in> (RAG2 s)^+"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   463
  and th1_r: "th1 \<in> readys s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   464
  and th2_d: "(n, Th th2) \<in> (RAG2 s)^+"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   465
  and th2_r: "th2 \<in> readys s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   466
  shows "th1 = th2"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   467
proof(rule ccontr)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   468
  assume neq: "th1 \<noteq> th2"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   469
  hence "Th th1 \<noteq> Th th2" by simp
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   470
  from unique_chain [OF _ th1_d th2_d this] and single_valued_RAG2 [OF vt]
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   471
  have "(Th th1, Th th2) \<in> (RAG2 s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG2 s)\<^sup>+" 
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   472
    unfolding single_valued_def by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   473
  then show "False"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   474
  proof
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   475
    assume "(Th th1, Th th2) \<in> (RAG2 s)\<^sup>+"      
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   476
    from trancl_split [OF this]
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   477
    obtain n where dd: "(Th th1, n) \<in> RAG2 s" by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   478
    then obtain cs where eq_n: "n = Cs cs"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   479
      unfolding RAG2_def RAG_def by (case_tac n) (auto)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   480
    from dd eq_n have "th1 \<notin> readys s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   481
      unfolding RAG2_def RAG_def waits2_def readys_def by (auto)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   482
    with th1_r show ?thesis by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   483
  next
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   484
    assume "(Th th2, Th th1) \<in> (RAG2 s)\<^sup>+"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   485
    from trancl_split [OF this]
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   486
    obtain n where dd: "(Th th2, n) \<in> RAG2 s" by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   487
    then obtain cs where eq_n: "n = Cs cs"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   488
      unfolding RAG2_def RAG_def by (case_tac n) (auto)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   489
    from dd eq_n have "th2 \<notin> readys s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   490
      unfolding RAG2_def RAG_def waits2_def readys_def by (auto)
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   491
    with th2_r show ?thesis by auto
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   492
  qed
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   493
qed
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   494
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   495
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   496
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   497
end