Test.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 09 Jun 2014 16:01:28 +0100
changeset 41 66ed924aaa5c
parent 40 0781a2fc93f1
child 44 f676a68935a0
permissions -rw-r--r--
added another book that makes the error, some more proofs
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
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    77
lemma [simp]: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    78
  "(SOME q. distinct q \<and> q = []) = []"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    79
by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    80
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    81
lemma [simp]: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    82
  "(x \<in> set (SOME q. distinct q \<and> set q = set p)) = (x \<in> set p)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    83
apply(auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    84
apply (metis (mono_tags, lifting) List.finite_set finite_distinct_list some_eq_ex)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    85
by (metis (mono_tags, lifting) List.finite_set finite_distinct_list some_eq_ex)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    86
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    87
abbreviation
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    88
  "next_to_run ths \<equiv> hd (SOME q::thread list. distinct q \<and> set q = set ths)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    89
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
    90
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
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
    92
  where 
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 [] = (| 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
    94
| "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
    95
       (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
    96
          (|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
    97
|  "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
    98
       (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
    99
          (|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
   100
|  "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
   101
       (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
   102
          (|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
   103
|  "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
   104
       (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
   105
        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
   106
          (|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
   107
|  "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
   108
       (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
   109
        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
   110
          (|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
   111
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
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
   113
  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
   114
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   115
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
   116
  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
   117
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   118
abbreviation
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   119
  "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
   120
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  "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
   123
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  "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
   126
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
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  "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
   129
  
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
definition
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
  "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
   132
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   133
(* 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
   134
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
   135
  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
   136
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
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
   138
  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
   139
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   140
(* 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
   141
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
   142
  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
   143
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   144
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   145
lemma exists_distinct:
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   146
  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
   147
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
   148
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   149
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
   150
  "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
   151
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
   152
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
   153
36
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 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
   155
  "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
   156
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
   157
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
   158
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
   159
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
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
   161
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
  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
   163
| 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
   164
| 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
   165
| 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
   166
| 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
   167
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   168
(* 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
   169
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
   170
  where
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
  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
   172
| 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
   173
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
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
   175
  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
   176
  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
   177
  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
   178
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
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
   180
  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
   181
  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
   182
  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
   183
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   184
lemma wq_threads: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   185
  assumes vt: "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   186
  and h: "th \<in> set (wq s cs)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   187
  shows "th \<in> threads s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   188
using assms
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   189
apply(induct)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   190
apply(simp add: wq_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   191
apply(erule step.cases)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   192
apply(auto simp add: wq_def Let_def holding_def holds2_def holds_def waits2_def runing_def readys_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   193
apply(simp add: waits_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   194
apply(auto simp add: waits_def split: if_splits)[1]
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   195
apply(auto split: if_splits)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   196
apply(simp only: waits_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   197
by (metis insert_iff set_simps(2))
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   198
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   199
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   200
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   201
lemma Domain_RAG_threads:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   202
  assumes vt: "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   203
  and in_dom: "(Th th) \<in> Domain (RAG2 s)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   204
  shows "th \<in> threads s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   205
proof -
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   206
  from in_dom obtain n where "(Th th, n) \<in> RAG2 s" by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   207
  then obtain cs where "n = Cs cs" "(Th th, Cs cs) \<in> RAG2 s"  
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   208
    unfolding RAG2_def RAG_def by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   209
  then have "th \<in> set (wq s cs)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   210
    unfolding wq_def RAG_def RAG2_def waits_def by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   211
  with wq_threads [OF vt] show ?thesis .
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   212
qed
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   213
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   214
lemma dependants_threads:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   215
  assumes vt: "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   216
  shows "dependants2 s th \<subseteq> threads s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   217
proof
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   218
  fix th1 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   219
  assume "th1 \<in> dependants2 s th"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   220
  then have h: "(Th th1, Th th) \<in> (RAG2 s)\<^sup>+"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   221
    unfolding dependants2_def dependants_def RAG2_def by simp
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   222
  then have "Th th1 \<in> Domain ((RAG2 s)\<^sup>+)" unfolding Domain_def by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   223
  then have "Th th1 \<in> Domain (RAG2 s)" using trancl_domain by simp
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   224
  then show "th1 \<in> threads s" using vt by (rule_tac Domain_RAG_threads)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   225
qed
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   226
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   227
lemma finite_threads:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   228
  assumes vt: "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   229
  shows "finite (threads s)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   230
using vt by (induct) (auto elim: step.cases)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   231
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   232
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   233
section {* Distinctness of @{const wq} *}
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   234
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
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
   236
  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
   237
  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
   238
using assms
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   239
unfolding wq_def
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   240
apply(erule_tac step.cases)
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   241
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
   242
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
   243
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
   244
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
   245
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
   246
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
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
   249
  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
   250
  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
   251
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
   252
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
   253
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
   254
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
   255
done
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   258
section {* Single_Valuedness of @{const waits2}, @{const holds2}, @{const RAG2} *}
40
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
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
   261
  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
   262
  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
   263
  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
   264
  shows "cs1 = cs2"
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   265
using assms
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   266
apply(induct)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   267
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
   268
apply(erule step.cases)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   269
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
   270
 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
   271
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
   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 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
   274
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
   275
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   276
lemma single_valued_waits2:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   277
  assumes "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   278
  shows "single_valuedP (waits2 s)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   279
using assms
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   280
unfolding single_valued_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   281
by (metis Collect_splitD fst_eqD sndI waits2_unique)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   282
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   283
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
   284
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   285
  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
   286
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
   287
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   288
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
   289
  assumes "vt s"
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   290
  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
   291
using single_valued_waits2[OF assms] single_valued_holds2[OF assms] 
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   292
unfolding RAG2_def RAG_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   293
apply(rule_tac single_valued_union)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   294
unfolding holds2_def[symmetric] waits2_def[symmetric]
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   295
apply(rule single_valued_Collect)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   296
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   297
apply(simp add: inj_on_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   298
apply(rule single_valued_Collect)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   299
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   300
apply(simp add: inj_on_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   301
apply(auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   302
done
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   303
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   304
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   305
section {* Properties of @{const RAG2} under events *}
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   306
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   307
lemma RAG_Set [simp]: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   308
  shows "RAG2 (Set th prio # s) = RAG2 s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   309
unfolding RAG2_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   310
by (simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   311
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   312
lemma RAG_Create [simp]: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   313
  "RAG2 (Create th prio # s) = RAG2 s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   314
unfolding RAG2_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   315
by (simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   316
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   317
lemma RAG_Exit [simp]: 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   318
  shows "RAG2 (Exit th # s) = RAG2 s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   319
unfolding RAG2_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   320
by (simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   321
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   322
lemma RAG_P1:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   323
  assumes "wq s cs = []"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   324
  shows "RAG2 (P th cs # s) \<subseteq> RAG2 s \<union> {(Cs cs, Th th)}"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   325
using assms
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   326
unfolding  RAG2_def RAG_def wq_def Let_def waits_def holds_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   327
by (auto simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   328
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   329
lemma RAG_P2:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   330
  assumes "(Cs cs, Th th) \<notin> (RAG2 s)\<^sup>+" "wq s cs \<noteq> []"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   331
  shows "RAG2 (P th cs # s) \<subseteq> RAG2 s \<union> {(Th th, Cs cs)}"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   332
using assms
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   333
unfolding RAG2_def RAG_def wq_def Let_def waits_def holds_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   334
by (auto simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   335
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   336
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   337
lemma RAG_V1:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   338
assumes vt: "wq s cs = [th]"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   339
shows "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th)}"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   340
using assms
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   341
unfolding RAG2_def RAG_def waits_def holds_def wq_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   342
by (auto simp add: Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   343
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   344
lemma RAG_V2:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   345
assumes vt:"vt s" "wq s cs = th # wts \<and> wts \<noteq> []"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   346
shows "RAG2 (V th cs # s) \<subseteq>
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   347
  RAG2 s - {(Cs cs, Th th), (Th (next_to_run wts), Cs cs)} \<union> {(Cs cs, Th (next_to_run wts))}"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   348
unfolding RAG2_def RAG_def waits_def holds_def
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   349
using assms wq_distinct[OF vt(1), of"cs"]
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   350
by (auto simp add: Let_def wq_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   351
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   352
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   353
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   354
section {* Acyclicity of @{const RAG2} *}
36
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
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
   357
  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
   358
  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
   359
  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
   360
  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
   361
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
   362
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
   363
  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
   364
  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
   365
  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
   366
  { 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
   367
    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
   368
    proof (rule_tac notI)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   369
      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
   370
      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
   371
      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
   372
    qed
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   373
    with ac have "acyclic (RAG2 s \<union> {(Cs cs, Th th)})" by simp
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   374
    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
   375
      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
   376
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
  moreover
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   378
  { 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
   379
    from ac ds
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   380
    have "acyclic (RAG2 s \<union> {(Th th, Cs cs)})" by simp
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   381
    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
   382
      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
   383
  }
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
  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
   385
next    
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   386
  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
   387
  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
   388
  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
   389
  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
   390
  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
   391
  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
   392
  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
   393
  -- "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
   394
  { assume "wts = []" 
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   395
    with eq_wq have "wq s cs = [th]" by simp
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   396
    then have "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th)}" by (rule RAG_V1)
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   397
    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
   398
    ultimately 
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   399
    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
   400
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   401
  moreover
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   402
  -- "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
   403
  { 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
   404
    assume wq_not_empty: "wts \<noteq> []" 
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   405
    have "waits2 s nth cs" 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   406
      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
   407
      unfolding nth_def waits2_def waits_def wq_def[symmetric] by auto
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   408
    then have cs_in_RAG: "(Th nth, Cs cs) \<in> RAG2 s" 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   409
      unfolding RAG2_def RAG_def waits2_def by auto
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   410
    have "RAG2 (V th cs # s) \<subseteq> RAG2 s - {(Cs cs, Th th), (Th nth, Cs cs)} \<union> {(Cs cs, Th nth)}" 
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   411
      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
   412
    moreover 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   413
    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
   414
    proof -
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   415
      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
   416
      moreover 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   417
      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
   418
      proof (rule notI)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   419
        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
   420
        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
   421
          by (metis converse_tranclE)
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   422
        then have "(Th nth, z) \<in> RAG2 s" by simp
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   423
        then have "z = Cs cs" using cs_in_RAG single_valued_RAG2[OF vt]
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   424
          by (simp add: single_valued_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   425
        then show "False" using a by simp
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   426
      qed
37
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   427
      ultimately 
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   428
      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
   429
    qed
38
c89013dca1aa finished proof of acyclity
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   430
    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
   431
      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
   432
  }
c820ac0f3088 simplified RAG_acyclic proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   433
  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
   434
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
   435
af38526275f8 added a test theory for polishing teh proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   437
lemma finite_RAG:
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   438
  assumes "vt s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   439
  shows "finite (RAG2 s)"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   440
using assms
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   441
apply(induct)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   442
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
   443
apply(erule step.cases)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   444
apply(auto)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   445
apply(case_tac "wq sa cs = []")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   446
apply(rule finite_subset)
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   447
apply(rule RAG_P1)
39
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(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   450
apply(rule finite_subset)
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   451
apply(rule RAG_P2)
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   452
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   453
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   454
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   455
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
   456
apply(erule exE)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   457
apply(case_tac "wts = []")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   458
apply(rule finite_subset)
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   459
apply(rule RAG_V1)
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   460
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   461
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   462
apply(rule finite_subset)
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   463
apply(rule RAG_V2)
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   464
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   465
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   466
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   467
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
   468
apply(case_tac "wq sa cs") 
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   469
apply(auto)[2]
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   470
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
   471
done
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   472
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   473
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   474
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   475
lemma dchain_unique:
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   476
  assumes vt: "vt s"
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   477
  and th1_d: "(n, Th th1) \<in> (RAG2 s)^+"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   478
  and th1_r: "th1 \<in> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   479
  and th2_d: "(n, Th th2) \<in> (RAG2 s)^+"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   480
  and th2_r: "th2 \<in> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   481
  shows "th1 = th2"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   482
proof(rule ccontr)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   483
  assume neq: "th1 \<noteq> th2"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   484
   with single_valued_confluent2 [OF single_valued_RAG2 [OF vt]] th1_d th2_d
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   485
  have "(Th th1, Th th2) \<in> (RAG2 s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (RAG2 s)\<^sup>+" by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   486
  moreover
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   487
  { assume "(Th th1, Th th2) \<in> (RAG2 s)\<^sup>+"      
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   488
    then obtain n where dd: "(Th th1, n) \<in> RAG2 s" by (metis converse_tranclE)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   489
    then obtain cs where eq_n: "n = Cs cs"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   490
      unfolding RAG2_def RAG_def by (case_tac n) (auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   491
    from dd eq_n have "th1 \<notin> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   492
      unfolding RAG2_def RAG_def waits2_def readys_def by (auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   493
    with th1_r have "False" by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   494
  }
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   495
  moreover
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   496
  { assume "(Th th2, Th th1) \<in> (RAG2 s)\<^sup>+"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   497
    then obtain n where dd: "(Th th2, n) \<in> RAG2 s" by (metis converse_tranclE)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   498
    then obtain cs where eq_n: "n = Cs cs"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   499
      unfolding RAG2_def RAG_def by (case_tac n) (auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   500
    from dd eq_n have "th2 \<notin> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   501
      unfolding RAG2_def RAG_def waits2_def readys_def by (auto)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   502
    with th2_r have "False" by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   503
  }
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   504
  ultimately show "False" by metis
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   505
qed
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   506
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   507
lemma max_cpreceds_readys_threads:
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   508
  assumes vt: "vt s"
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   509
  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
   510
apply(case_tac "threads s = {}")
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   511
apply(simp add: readys_def)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   512
using vt
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   513
apply(induct)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   514
apply(simp)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   515
apply(erule step.cases)
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   516
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
   517
defer
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   518
defer
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   519
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
   520
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   521
lemma readys_Exit:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   522
  shows "readys (Exit th # s) \<subseteq> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   523
by (auto simp add: readys_def waits2_def Let_def)
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   524
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   525
lemma readys_Create:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   526
  shows "readys (Create th prio # s) \<subseteq> {th} \<union> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   527
by (auto simp add: readys_def waits2_def Let_def)
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   528
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   529
lemma readys_Set:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   530
  shows "readys (Set th prio # s) \<subseteq> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   531
by (auto simp add: readys_def waits2_def Let_def)
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   532
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   533
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   534
lemma readys_P:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   535
  shows "readys (P th cs # s) \<subseteq> readys s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   536
apply(auto simp add: readys_def waits2_def Let_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   537
apply(simp add: waits_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   538
apply(case_tac "csa = cs")
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   539
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   540
apply(drule_tac x="cs" in spec)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   541
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   542
apply (metis hd_append2 in_set_insert insert_Nil list.sel(1))
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   543
apply(drule_tac x="csa" in spec)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   544
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   545
done
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   546
41
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   547
lemma readys_V:
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   548
  shows "readys (V th cs # s) \<subseteq> readys s \<union> set (wq s cs)"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   549
apply(auto simp add: readys_def waits2_def waits_def Let_def wq_def)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   550
done
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   551
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   552
lemma 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   553
  assumes "vt s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   554
  shows "card (runing s) \<le> 1"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   555
proof (rule ccontr)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   556
  assume "\<not> card (runing s) \<le> 1"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   557
  then have "2 \<le> card (runing s)" by auto
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   558
  moreover 
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   559
  have "finite (runing s)" sorry
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   560
  ultimately obtain th1 th2 where "th1 \<noteq> th2" "th1 \<in> runing s" "th2 \<in> runing s"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   561
    by (auto simp add: numerals card_le_Suc_iff) (blast)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   562
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   563
  show "False"
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   564
apply(simp)
66ed924aaa5c added another book that makes the error, some more proofs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 40
diff changeset
   565
oops  
40
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   566
0781a2fc93f1 added a library about graphs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   567
39
7ea6b019ce24 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   568
end