prio/ExtGG.thy
changeset 298 f2e0d031a395
parent 290 6a6d0bd16035
child 302 06241c45cb17
equal deleted inserted replaced
297:0a4be67ea7f8 298:f2e0d031a395
    27   apply (drule_tac th_in_ne)
    27   apply (drule_tac th_in_ne)
    28   by (unfold preced_def, auto intro: birth_time_lt)
    28   by (unfold preced_def, auto intro: birth_time_lt)
    29 
    29 
    30 locale highest_gen =
    30 locale highest_gen =
    31   fixes s th prio tm
    31   fixes s th prio tm
    32   assumes vt_s: "vt step s"
    32   assumes vt_s: "vt s"
    33   and threads_s: "th \<in> threads s"
    33   and threads_s: "th \<in> threads s"
    34   and highest: "preced th s = Max ((cp s)`threads s)"
    34   and highest: "preced th s = Max ((cp s)`threads s)"
    35   and preced_th: "preced th s = Prc prio tm"
    35   and preced_th: "preced th s = Prc prio tm"
    36 
    36 
    37 context highest_gen
    37 context highest_gen
    86 
    86 
    87 end
    87 end
    88 
    88 
    89 locale extend_highest_gen = highest_gen + 
    89 locale extend_highest_gen = highest_gen + 
    90   fixes t 
    90   fixes t 
    91   assumes vt_t: "vt step (t@s)"
    91   assumes vt_t: "vt (t@s)"
    92   and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
    92   and create_low: "Create th' prio' \<in> set t \<Longrightarrow> prio' \<le> prio"
    93   and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
    93   and set_diff_low: "Set th' prio' \<in> set t \<Longrightarrow> th' \<noteq> th \<and> prio' \<le> prio"
    94   and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
    94   and exit_diff: "Exit th' \<in> set t \<Longrightarrow> th' \<noteq> th"
    95 
    95 
    96 lemma step_back_vt_app: 
    96 lemma step_back_vt_app: 
    97   assumes vt_ts: "vt cs (t@s)" 
    97   assumes vt_ts: "vt (t@s)" 
    98   shows "vt cs s"
    98   shows "vt s"
    99 proof -
    99 proof -
   100   from vt_ts show ?thesis
   100   from vt_ts show ?thesis
   101   proof(induct t)
   101   proof(induct t)
   102     case Nil
   102     case Nil
   103     from Nil show ?case by auto
   103     from Nil show ?case by auto
   104   next
   104   next
   105     case (Cons e t)
   105     case (Cons e t)
   106     assume ih: " vt cs (t @ s) \<Longrightarrow> vt cs s"
   106     assume ih: " vt (t @ s) \<Longrightarrow> vt s"
   107       and vt_et: "vt cs ((e # t) @ s)"
   107       and vt_et: "vt ((e # t) @ s)"
   108     show ?case
   108     show ?case
   109     proof(rule ih)
   109     proof(rule ih)
   110       show "vt cs (t @ s)"
   110       show "vt (t @ s)"
   111       proof(rule step_back_vt)
   111       proof(rule step_back_vt)
   112         from vt_et show "vt cs (e # t @ s)" by simp
   112         from vt_et show "vt (e # t @ s)" by simp
   113       qed
   113       qed
   114     qed
   114     qed
   115   qed
   115   qed
   116 qed
   116 qed
   117 
   117 
   125   by (unfold highest_gen_def, auto dest:step_back_vt_app)
   125   by (unfold highest_gen_def, auto dest:step_back_vt_app)
   126 
   126 
   127 lemma ind [consumes 0, case_names Nil Cons, induct type]:
   127 lemma ind [consumes 0, case_names Nil Cons, induct type]:
   128   assumes 
   128   assumes 
   129     h0: "R []"
   129     h0: "R []"
   130   and h2: "\<And> e t. \<lbrakk>vt step (t@s); step (t@s) e; 
   130   and h2: "\<And> e t. \<lbrakk>vt (t@s); step (t@s) e; 
   131                     extend_highest_gen s th prio tm t; 
   131                     extend_highest_gen s th prio tm t; 
   132                     extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
   132                     extend_highest_gen s th prio tm (e#t); R t\<rbrakk> \<Longrightarrow> R (e#t)"
   133   shows "R t"
   133   shows "R t"
   134 proof -
   134 proof -
   135   from vt_t extend_highest_gen_axioms show ?thesis
   135   from vt_t extend_highest_gen_axioms show ?thesis
   136   proof(induct t)
   136   proof(induct t)
   137     from h0 show "R []" .
   137     from h0 show "R []" .
   138   next
   138   next
   139     case (Cons e t')
   139     case (Cons e t')
   140     assume ih: "\<lbrakk>vt step (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
   140     assume ih: "\<lbrakk>vt (t' @ s); extend_highest_gen s th prio tm t'\<rbrakk> \<Longrightarrow> R t'"
   141       and vt_e: "vt step ((e # t') @ s)"
   141       and vt_e: "vt ((e # t') @ s)"
   142       and et: "extend_highest_gen s th prio tm (e # t')"
   142       and et: "extend_highest_gen s th prio tm (e # t')"
   143     from vt_e and step_back_step have stp: "step (t'@s) e" by auto
   143     from vt_e and step_back_step have stp: "step (t'@s) e" by auto
   144     from vt_e and step_back_vt have vt_ts: "vt step (t'@s)" by auto
   144     from vt_e and step_back_vt have vt_ts: "vt (t'@s)" by auto
   145     show ?case
   145     show ?case
   146     proof(rule h2 [OF vt_ts stp _ _ _ ])
   146     proof(rule h2 [OF vt_ts stp _ _ _ ])
   147       show "R t'"
   147       show "R t'"
   148       proof(rule ih)
   148       proof(rule ih)
   149         from et show ext': "extend_highest_gen s th prio tm t'"
   149         from et show ext': "extend_highest_gen s th prio tm t'"
   150           by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
   150           by (unfold extend_highest_gen_def extend_highest_gen_axioms_def, auto dest:step_back_vt)
   151       next
   151       next
   152         from vt_ts show "vt step (t' @ s)" .
   152         from vt_ts show "vt (t' @ s)" .
   153       qed
   153       qed
   154     next
   154     next
   155       from et show "extend_highest_gen s th prio tm (e # t')" .
   155       from et show "extend_highest_gen s th prio tm (e # t')" .
   156     next
   156     next
   157       from et show ext': "extend_highest_gen s th prio tm t'"
   157       from et show ext': "extend_highest_gen s th prio tm t'"
   262     proof -
   262     proof -
   263       have "Max (?f ` ?A) = Max(insert (?f thread) (?f ` (threads (t@s))))"
   263       have "Max (?f ` ?A) = Max(insert (?f thread) (?f ` (threads (t@s))))"
   264         by (unfold eq_e, simp)
   264         by (unfold eq_e, simp)
   265       moreover have "\<dots> = max (?f thread) (Max (?f ` (threads (t@s))))"
   265       moreover have "\<dots> = max (?f thread) (Max (?f ` (threads (t@s))))"
   266       proof(rule Max_insert)
   266       proof(rule Max_insert)
   267         from Cons have "vt step (t @ s)" by auto
   267         from Cons have "vt (t @ s)" by auto
   268         from finite_threads[OF this]
   268         from finite_threads[OF this]
   269         show "finite (?f ` (threads (t@s)))" by simp
   269         show "finite (?f ` (threads (t@s)))" by simp
   270       next
   270       next
   271         from h' show "(?f ` (threads (t@s))) \<noteq> {}" by auto
   271         from h' show "(?f ` (threads (t@s))) \<noteq> {}" by auto
   272       qed
   272       qed
   308     ultimately show ?thesis by (auto simp:max_def)
   308     ultimately show ?thesis by (auto simp:max_def)
   309   qed
   309   qed
   310 next
   310 next
   311     case (Exit thread)
   311     case (Exit thread)
   312     assume eq_e: "e = Exit thread"
   312     assume eq_e: "e = Exit thread"
   313     from Cons have vt_e: "vt step (e#(t @ s))" by auto
   313     from Cons have vt_e: "vt (e#(t @ s))" by auto
   314     from Cons and eq_e have stp: "step (t@s) (Exit thread)" by auto
   314     from Cons and eq_e have stp: "step (t@s) (Exit thread)" by auto
   315     from stp have thread_ts: "thread \<in> threads (t @ s)"
   315     from stp have thread_ts: "thread \<in> threads (t @ s)"
   316       by(cases, unfold runing_def readys_def, auto)
   316       by(cases, unfold runing_def readys_def, auto)
   317     from Cons have "extend_highest_gen s th prio tm (e # t)" by auto
   317     from Cons have "extend_highest_gen s th prio tm (e # t)" by auto
   318     from extend_highest_gen.exit_diff[OF this] and eq_e
   318     from extend_highest_gen.exit_diff[OF this] and eq_e
   351             from Cons
   351             from Cons
   352             have "?t = Max ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))" 
   352             have "?t = Max ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))" 
   353               (is "?t = Max (?g ` ?B)") by simp
   353               (is "?t = Max (?g ` ?B)") by simp
   354             moreover have "?g thread \<le> \<dots>"
   354             moreover have "?g thread \<le> \<dots>"
   355             proof(rule Max_ge)
   355             proof(rule Max_ge)
   356               have "vt step (t@s)" by fact
   356               have "vt (t@s)" by fact
   357               from finite_threads [OF this]
   357               from finite_threads [OF this]
   358               show "finite (?g ` ?B)" by simp
   358               show "finite (?g ` ?B)" by simp
   359             next
   359             next
   360               from thread_ts
   360               from thread_ts
   361               show "?g thread \<in> (?g ` ?B)" by auto
   361               show "?g thread \<in> (?g ` ?B)" by auto
   426               show "preced th1 (t @ s) \<in> (\<lambda>th'. preced th' (t @ s)) ` threads (t @ s)"
   426               show "preced th1 (t @ s) \<in> (\<lambda>th'. preced th' (t @ s)) ` threads (t @ s)"
   427                 by simp
   427                 by simp
   428             next
   428             next
   429               show "finite ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))"
   429               show "finite ((\<lambda>th'. preced th' (t @ s)) ` threads (t @ s))"
   430               proof -
   430               proof -
   431                 from Cons have "vt step (t @ s)" by auto
   431                 from Cons have "vt (t @ s)" by auto
   432                 from finite_threads[OF this] show ?thesis by auto
   432                 from finite_threads[OF this] show ?thesis by auto
   433               qed
   433               qed
   434             qed
   434             qed
   435             ultimately show ?thesis by auto
   435             ultimately show ?thesis by auto
   436           qed
   436           qed
   599     [OF this, OF in_thread neq_th' not_holding]
   599     [OF this, OF in_thread neq_th' not_holding]
   600     have not_runing: "th' \<notin> runing (t @ s)" .
   600     have not_runing: "th' \<notin> runing (t @ s)" .
   601     show ?case
   601     show ?case
   602     proof(cases e)
   602     proof(cases e)
   603       case (V thread cs)
   603       case (V thread cs)
   604       from Cons and V have vt_v: "vt step (V thread cs#(t@s))" by auto
   604       from Cons and V have vt_v: "vt (V thread cs#(t@s))" by auto
   605 
   605 
   606       show ?thesis
   606       show ?thesis
   607       proof -
   607       proof -
   608         from Cons and V have "step (t@s) (V thread cs)" by auto
   608         from Cons and V have "step (t@s) (V thread cs)" by auto
   609         hence neq_th': "thread \<noteq> th'"
   609         hence neq_th': "thread \<noteq> th'"
   727       obtain e where
   727       obtain e where
   728         eq_me: "moment (Suc(i+k)) t = e#(moment (i+k) t)"
   728         eq_me: "moment (Suc(i+k)) t = e#(moment (i+k) t)"
   729         by blast
   729         by blast
   730       from red_moment[of "Suc(i+k)"]
   730       from red_moment[of "Suc(i+k)"]
   731       and eq_me have "extend_highest_gen s th prio tm (e # moment (i + k) t)" by simp
   731       and eq_me have "extend_highest_gen s th prio tm (e # moment (i + k) t)" by simp
   732       hence vt_e: "vt step (e#(moment (i + k) t)@s)"
   732       hence vt_e: "vt (e#(moment (i + k) t)@s)"
   733         by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
   733         by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
   734                           highest_gen_def, auto)
   734                           highest_gen_def, auto)
   735       have not_runing': "th' \<notin>  runing (moment (i + k) t @ s)"
   735       have not_runing': "th' \<notin>  runing (moment (i + k) t @ s)"
   736       proof -
   736       proof -
   737         show "th' \<notin> runing (moment (i + k) t @ s)"
   737         show "th' \<notin> runing (moment (i + k) t @ s)"
   845   from lt_its have "Suc i \<le> length t" by auto
   845   from lt_its have "Suc i \<le> length t" by auto
   846   from moment_head[OF this] obtain e where 
   846   from moment_head[OF this] obtain e where 
   847    eq_me: "moment (Suc i) t = e # moment i t" by blast
   847    eq_me: "moment (Suc i) t = e # moment i t" by blast
   848   from red_moment[of "Suc i"] and eq_me
   848   from red_moment[of "Suc i"] and eq_me
   849   have "extend_highest_gen s th prio tm (e # moment i t)" by simp
   849   have "extend_highest_gen s th prio tm (e # moment i t)" by simp
   850   hence vt_e: "vt step (e#(moment i t)@s)"
   850   hence vt_e: "vt (e#(moment i t)@s)"
   851     by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
   851     by (unfold extend_highest_gen_def extend_highest_gen_axioms_def 
   852       highest_gen_def, auto)
   852       highest_gen_def, auto)
   853   from step_back_step[OF this] have stp_i: "step (moment i t @ s) e" .
   853   from step_back_step[OF this] have stp_i: "step (moment i t @ s) e" .
   854   from post[rule_format, of "Suc i"] and eq_me 
   854   from post[rule_format, of "Suc i"] and eq_me 
   855   have not_in': "th' \<in> threads (e # moment i t@s)" by auto
   855   have not_in': "th' \<in> threads (e # moment i t@s)" by auto
   856   from create_pre[OF stp_i pre this] 
   856   from create_pre[OF stp_i pre this] 
   857   obtain prio where eq_e: "e = Create th' prio" .
   857   obtain prio where eq_e: "e = Create th' prio" .
   858   have "cntP (moment i t@s) th' = cntV (moment i t@s) th'"
   858   have "cntP (moment i t@s) th' = cntV (moment i t@s) th'"
   859   proof(rule cnp_cnv_eq)
   859   proof(rule cnp_cnv_eq)
   860     from step_back_vt [OF vt_e] 
   860     from step_back_vt [OF vt_e] 
   861     show "vt step (moment i t @ s)" .
   861     show "vt (moment i t @ s)" .
   862   next
   862   next
   863     from eq_e and stp_i 
   863     from eq_e and stp_i 
   864     have "step (moment i t @ s) (Create th' prio)" by simp
   864     have "step (moment i t @ s) (Create th' prio)" by simp
   865     thus "th' \<notin> threads (moment i t @ s)" by (cases, simp)
   865     thus "th' \<notin> threads (moment i t @ s)" by (cases, simp)
   866   qed
   866   qed