Theory Qmsg

(*  Title:       Qmsg.thy
    License:     BSD 2-Clause. See LICENSE.
    Author:      Timothy Bourke
*)

section "Model the standard queuing model"

theory Qmsg
imports AWN_SOS_Labels AWN_Invariants
begin

text ‹Define the queue process›

fun ΓQMSG :: "('m list, 'm, unit, unit label) seqp_env"
where
  "ΓQMSG () = labelled () (receive(λmsg msgs. msgs @ [msg]). call(())
            msgs. msgs  []
               (send(λmsgs. hd msgs).
                 (msgs. tl msgs call(())
                   receive(λmsg msgs. tl msgs @ [msg]). call(()))
               receive(λmsg msgs. msgs @ [msg]). call(())))"

definition σQMSG :: "(('m::msg) list × ('m list, 'm, unit, unit label) seqp) set"
where "σQMSG  {([], ΓQMSG ())}"

abbreviation qmsg
  :: "(('m::msg) list × ('m list, 'm, unit, unit label) seqp, 'm seq_action) automaton"
where
  "qmsg   init = σQMSG, trans = seqp_sos ΓQMSG "

declare ΓQMSG.simps [simp del, code del]
lemmas ΓQMSG_simps [simp, code] = ΓQMSG.simps [simplified]

lemma σQMSG_not_empty [simp, intro]: "σQMSG  {}"
  unfolding σQMSG_def by simp

lemma σQMSG_exists [simp]: "qmsg q. (qmsg, q)  σQMSG"
  unfolding σQMSG_def by simp

lemma qmsg_wf [simp]: "wellformed ΓQMSG"
  by (rule wf_no_direct_calls) auto

lemmas qmsg_labels_not_empty [simp] = labels_not_empty [OF qmsg_wf]

lemma qmsg_control_within [simp]: "control_within ΓQMSG (init qmsg)"
  unfolding σQMSG_def by (rule control_withinI) (auto simp del: ΓQMSG_simps)

lemma qmsg_simple_labels [simp]: "simple_labels ΓQMSG"
  unfolding simple_labels_def by auto

lemma qmsg_trans: "trans qmsg = seqp_sos ΓQMSG"
  by simp

lemma σQMSG_labels [simp]: "(ξ, q)  σQMSG   labels ΓQMSG q = {()-:0}"
  unfolding σQMSG_def by simp

lemma qmsg_proc_cases [dest]:
  fixes p pn
  shows "p  ctermsl (ΓQMSG pn)  p  ctermsl (ΓQMSG ())"
  by simp

declare
  ΓQMSG_simps [cterms_env]
  qmsg_proc_cases [ctermsl_cases]
  seq_invariant_ctermsI [OF qmsg_wf qmsg_control_within qmsg_simple_labels qmsg_trans, cterms_intros]
  seq_step_invariant_ctermsI [OF qmsg_wf qmsg_control_within qmsg_simple_labels qmsg_trans, cterms_intros]

end