Test.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 24 May 2014 12:39:12 +0100
changeset 37 c820ac0f3088
parent 36 af38526275f8
child 38 c89013dca1aa
permissions -rw-r--r--
simplified RAG_acyclic proof
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 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Precedence_ord
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. *}
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
type_synonym cs = nat -- {* Type for critical sections (or critical resources). *}
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
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
definition cp :: "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
   102
  where "cp s \<equiv> cprec_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
   103
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  "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
   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
  "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
   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
  "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
   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
  "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
   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 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
   117
  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
   118
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
definition runing :: "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
   120
  where "runing s \<equiv> {th . th \<in> readys s \<and> cp s th = Max ((cp s) ` (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
   121
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
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
   123
  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
   124
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   125
abbreviation
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   126
  "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
   127
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
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
   129
  "holding s th = {cs . (Cs cs, Th th) \<in> 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
   130
unfolding holding_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
unfolding holds2_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
unfolding RAG2_def RAG_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
unfolding holds_def waits_def
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
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
   135
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
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
   137
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
  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
   139
| 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
   140
| 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
   141
| 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
   142
| 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
   143
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
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
   145
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  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
   147
| 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
   148
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
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
   150
  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
   151
  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
   152
  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
   153
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
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
   155
  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
   156
  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
   157
  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
   158
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
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
   160
  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
   161
  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
   162
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
   163
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
   164
apply(auto simp add: wq_def 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
   165
apply(auto simp add: wq_def Let_def RAG2_def RAG_def holds_def runing_def waits2_def waits_def readys_def)[1]
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
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
   167
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
   168
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
   169
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
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
   172
  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
   173
  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
   174
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
   175
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
   176
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
   177
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
   178
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
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
   181
  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
   182
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
   183
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
   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 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
   186
  "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
   187
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
   188
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
   189
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
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
   191
  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
   192
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
   193
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
   194
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
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
   196
  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
   197
  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
   198
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   199
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
   200
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
   201
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
lemma RAG_p2:
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   204
  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
   205
  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
   206
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   207
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
   208
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
   209
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   210
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
   211
by auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   212
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   213
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
   214
apply auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   215
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
   216
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
   217
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   218
lemma RAG_v1:
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   219
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
   220
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
   221
using assms
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   222
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
   223
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
   224
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   225
lemma RAG_v2:
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   226
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
   227
shows "RAG2 (V th cs # s) \<subseteq>
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   228
  RAG2 s - {(Cs cs, Th th)} - {(Th (next_to_run wts), Cs cs)} \<union> {(Cs cs, Th (next_to_run wts))}"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   229
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
   230
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
   231
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
   232
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
lemma waiting_unique:
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
  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
   235
  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
   236
  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
   237
  shows "cs1 = cs2"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
sorry
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
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
   241
  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
   242
  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
   243
  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
   244
  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
   245
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
   246
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
   247
  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
   248
  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
   249
  have ds: "(Cs cs, Th th) \<notin> (RAG2 s)\<^sup>+" 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
   250
  { assume a: "wq s cs = []" -- "case waiting queue is empty"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
    have "(Th th, Cs cs) \<notin> (RAG2 s)\<^sup>*"  
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
    proof
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
      assume "(Th th, Cs cs) \<in> (RAG2 s)\<^sup>*"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
      then have "(Th th, Cs cs) \<in> (RAG2 s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
      then obtain x where "(x, Cs cs) \<in> RAG2 s" using tranclD2 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
   256
      with a show False by (auto simp: RAG2_def RAG_def wq_def waits_def)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
    qed
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
    with acyclic_insert ac
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
    have "acyclic (RAG2 s \<union> {(Cs cs, Th th)})" by simp
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   260
    then have "acyclic (RAG2 (P th cs # s))" using RAG_p1[OF a] 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   261
      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
   262
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
  moreover
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
  { assume a: "wq s cs \<noteq> []" -- "case waiting queue is not empty"
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
    from ds have "(Cs cs, Th th) \<notin> (RAG2 s)\<^sup>*" by (metis node.distinct(1) rtranclD)
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
    with acyclic_insert ac 
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
    have "acyclic (RAG2 s \<union> {(Th th, Cs cs)})" by auto
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   268
    then have "acyclic (RAG2 (P th cs # s))" using RAG_p2[OF ds a] 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   269
      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
   270
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  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
   272
next    
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
  case (step_V 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
   274
  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
   275
  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
   276
  have rn: "th \<in> runing 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
   277
  have hd: "holds2 s th cs" by fact
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   278
  from hd have th_in: "th \<in> set (wq s cs)" and
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   279
               eq_hd: "th = hd (wq s cs)" unfolding holds2_def holds_def wq_def by auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   280
  then obtain wts where
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   281
    eq_wq: "wq s cs = th # wts" by (cases "wq s cs") (auto)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   282
  { assume "wts = []" -- "case no thread present to take over"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   283
    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
   284
    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
   285
    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
   286
    ultimately 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   287
    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
   288
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   289
  moreover
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   290
  { def nth \<equiv> "next_to_run wts"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   291
    assume aa: "wts \<noteq> []" -- "at least one thread present to take over"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   292
    with vt eq_wq 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   293
    have "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)} \<union> {(Cs cs, Th nth)}" 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   294
      unfolding nth_def by (rule_tac RAG_v2) (auto)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   295
    moreover 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   296
    have "acyclic (insert (Cs cs, Th nth) (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)}))" 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   297
    proof -
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   298
      have "acyclic (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)})" 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
   299
      moreover 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   300
      have "(Th nth, Cs cs) \<notin> (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)})\<^sup>+" 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   301
        proof 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   302
          assume "(Th nth, Cs cs) \<in> (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)})\<^sup>+"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   303
          then obtain z where a: "(Th nth, z) \<in> (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)})"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   304
            by (metis converse_tranclE)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   305
          then have "(Th nth, z) \<in> RAG2 s" by simp
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   306
          then obtain cs' where b: "z = Cs cs'" "(Th nth, Cs cs') \<in> RAG2 s"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   307
            unfolding RAG2_def RAG_def by auto
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   308
          then have "cs = cs'" 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   309
            apply(rule_tac waiting_unique[OF vt])
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   310
            using eq_wq aa
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   311
            apply(auto simp add: nth_def RAG2_def RAG_def waits2_def waits_def wq_def)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   312
            apply (metis (mono_tags, lifting) `\<And>thesis. (\<And>wts. wq s cs = th # wts \<Longrightarrow> thesis) \<Longrightarrow> thesis` distinct.simps(2) hd_in_set list.inject set_empty2 tfl_some vt wq_def wq_distinct)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   313
            by (metis (mono_tags, lifting) `\<And>thesis. (\<And>wts. wq s cs = th # wts \<Longrightarrow> thesis) \<Longrightarrow> thesis` distinct.simps(2) hd_in_set list.sel(1) set_empty2 tfl_some vt wq_def wq_distinct)            
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   314
         then show "False" using a b by simp
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   315
        qed
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   316
      then have "(Th nth, Cs cs) \<notin> (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)})\<^sup>*"
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   317
        by (metis node.distinct(1) rtranclD)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   318
      ultimately 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   319
      show "acyclic (insert (Cs cs, Th nth) (RAG2 s - {(Cs cs, Th th)} - {(Th nth, Cs cs)}))" 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   320
        by (simp add: acyclic_insert)
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   321
    qed
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   322
    ultimately 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
   323
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   324
  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
   325
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
   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
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331