theory Toy imports Main AWN_Main Qmsg_Lifting begin
subsection"Messages used in the protocol"
datatype msg =
Pkt data ip
| Newpkt data ip
instantiation msg :: msg begin definition newpkt_def [simp]: "newpkt ≡ λ(d,did). Newpkt d did" definition eq_newpkt_def: "eq_newpkt m ≡ case m of Newpkt d did ==> True | _ ==>False"
instanceby intro_classes (simp add: eq_newpkt_def) end
lemma clear_locals_but_not_globals [simp]: "id (clear_locals ξ) = id ξ" "no (clear_locals ξ) = no ξ" "nhid (clear_locals ξ) = nhid ξ" unfolding clear_locals_def by auto
definition is_newpkt where"is_newpkt ξ ≡ case msg ξ of Newpkt data did ==> { ξ(num := data) } | _ ==> {}"
definition is_pkt where"is_pkt ξ ≡ case msg ξ of Pkt num' sid' ==> { ξ( num := num', sid := sid' ) } | _ ==> {}"
lemmas is_msg_defs =
is_pkt_def is_newpkt_def
lemma is_msg_inv_id [simp]: "ξ' ∈ is_pkt ξ ==> id ξ' = id ξ" "ξ' ∈ is_newpkt ξ ==> id ξ' = id ξ" unfolding is_msg_defs by (cases "msg ξ", clarsimp+)+
lemma all_nos_inc: shows"optoy i ⊨A (otherwith nos_inc {i} S, other nos_inc {i} →) onll ΓTOY (λ((σ, _), a, (σ', _)). (∀j. nos_inc (σ j) (σ' j)))" proof - have *: "∧σ σ' a. [ otherwith nos_inc {i} S σ σ' a; no (σ i) ≤ no (σ' i) ] ==>∀j. no (σ j) ≤ no (σ' j)" by (auto dest!: otherwith_syncD) show ?thesis by (inv_cterms
inv add: oseq_step_invariant_sterms [OF oseq_nos_incs [THEN oinvariant_step_anyact]
toy_wf otoy_trans]
simp add: seqllsimp) (auto elim!: *) qed
lemma oreceived_msg_inv: assumes other: "∧σ σ' m. [ P σ m; other Q {i} σ σ' ]==> P σ' m" andlocal: "∧σ m. P σ m ==> P (σ(i := σ i(msg := m))) m" shows"optoy i ⊨ (otherwith Q {i} (orecvmsg P), other Q {i} →) onl ΓTOY (λ(σ, l). l ∈ {PToy-:1} ⟶ P σ (msg (σ i)))" proof (inv_cterms, intro impI) fix σ σ' l assume"l = PToy-:1 ⟶ P σ (msg (σ i))" and"l = PToy-:1" and"other Q {i} σ σ'" from this(1-2) have"P σ (msg (σ i))" .. hence"P σ' (msg (σ i))"using‹other Q {i} σ σ'› by (rule other) moreoverfrom‹other Q {i} σ σ'›have"σ' i = σ i" .. ultimatelyshow"P σ' (msg (σ' i))"by simp next fix σ σ' msg assume"otherwith Q {i} (orecvmsg P) σ σ' (receive msg)" and"σ' i = σ i(msg := msg)" from this(1) have"P σ msg" and"∀j. j≠i ⟶ Q (σ j) (σ' j)"by auto from this(1) have"P (σ(i := σ i(msg := msg))) msg"by (rule local) thus"P σ' msg" proof (rule other) from‹σ' i = σ i(msg := msg)›and‹∀j. j≠i ⟶ Q (σ j) (σ' j)› show"other Q {i} (σ(i := σ i(msg := msg))) σ'" by - (rule otherI, auto) qed qed
lemma msg_ok_other_nos_inc [elim]: assumes"msg_ok σ m" and"other nos_inc {i} σ σ'" shows"msg_ok σ' m" proof (cases m) fix num sid assume"m = Pkt num sid" with‹msg_ok σ m›have"num ≤ no (σ sid)"by simp alsofrom‹other nos_inc {i} σ σ'›have"no (σ sid) ≤ no (σ' sid)" by (rule otherE) (metis eq_iff nos_incD) finallyhave"num ≤ no (σ' sid)" . with‹m = Pkt num sid›show ?thesis by simp qed simp
lemma msg_ok_no_leq_no [simp, elim]: assumes"msg_ok σ m" and"∀j. no (σ j) ≤ no (σ' j)" shows"msg_ok σ' m" using assms(1) proof (cases m) fix num sid assume"m = Pkt num sid" with‹msg_ok σ m›have"num ≤ no (σ sid)"by simp alsofrom‹∀j. no (σ j) ≤ no (σ' j)›have"no (σ sid) ≤ no (σ' sid)" by simp finallyhave"num ≤ no (σ' sid)" . with‹m = Pkt num sid›show ?thesis by simp qed (simp add: assms(1))
lemma oreceived_msg_ok: "optoy i ⊨ (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) onl ΓTOY (λ(σ, l). l∈{PToy-:1..} ⟶ msg_ok σ (msg (σ i)))"
(is"_ ⊨ (?S, ?U →) _") proof (inv_cterms inv add: oseq_step_invariant_sterms [OF all_nos_inc toy_wf otoy_trans],
intro impI, elim impE) fix σ σ' assume"msg_ok σ (msg (σ i))" and other: "other nos_inc {i} σ σ'" moreoverfrom other have"msg (σ' i) = msg (σ i)" by (clarsimp elim!: otherE) ultimatelyshow"msg_ok σ' (msg (σ' i))" by (auto) next fix p l σ a q l' σ' pp p' m assume a1: "(σ', p') ∈ oreachable (optoy i) ?S ?U" and a2: "PToy-:1 ∈ labels ΓTOY p'" and a3: "σ' i = σ i(msg := m)" have inv: "optoy i ⊨ (?S, ?U →) onl ΓTOY (λ(σ, l). l ∈ {PToy-:1} ⟶ msg_ok σ (msg (σ i)))" proof (rule oreceived_msg_inv) fix σ σ' m assume"msg_ok σ m" and"other nos_inc {i} σ σ'" thus"msg_ok σ' m" .. next fix σ m assume"msg_ok σ m" thus"msg_ok (σ(i := σ i(msg := m))) m" by (cases m) auto qed from a1 a2 a3 show"msg_ok σ' m" by (clarsimp dest!: oinvariantD [OF inv] onlD) qed simp
lemma is_pkt_handler_num_leq_no: shows"optoy i ⊨ (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) onl ΓTOY (λ(σ, l). l∈{PToy-:6..PToy-:10} ⟶ num (σ i) ≤ no (σ (sid (σ i))))" proof -
{ fix σ σ' assume"∀j. no (σ j) ≤ no (σ' j)" and"num (σ i) ≤ no (σ (sid (σ i)))" have"num (σ i) ≤ no (σ' (sid (σ i)))" proof - note‹num (σ i) ≤ no (σ (sid (σ i)))› alsofrom‹∀j. no (σ j) ≤ no (σ' j)›have"no (σ (sid (σ i))) ≤ no (σ' (sid (σ i)))" by auto finallyshow ?thesis . qed
} note solve_step = this show ?thesis proof (inv_cterms inv add: oseq_step_invariant_sterms [OF all_nos_inc toy_wf otoy_trans]
onl_oinvariant_sterms [OF toy_wf oreceived_msg_ok]
solve: solve_step, intro impI, elim impE) fix σ σ' assume *: "num (σ i) ≤ no (σ (sid (σ i)))" and"other nos_inc {i} σ σ'" from this(2) obtain"∀i∈{i}. σ' i = σ i" and"∀j. j ∉ {i} ⟶ nos_inc (σ j) (σ' j)" .. show"num (σ' i) ≤ no (σ' (sid (σ' i)))" proof (cases "sid (σ i) = i") assume"sid (σ i) = i" with * ‹∀i∈{i}. σ' i = σ i› show ?thesis by simp next assume"sid (σ i) ≠ i" with‹∀j. j ∉ {i} ⟶ nos_inc (σ j) (σ' j)› have"no (σ (sid (σ i))) ≤ no (σ' (sid (σ i)))"by simp with * ‹∀i∈{i}. σ' i = σ i› show ?thesis by simp qed next fix p l σ a q l' σ' pp p' assume"msg_ok σ (msg (σ i))" and"∀j. no (σ j) ≤ no (σ' j)" and"σ' i ∈ is_pkt (σ i)" show"num (σ' i) ≤ no (σ' (sid (σ' i)))" proof (cases "msg (σ i)") fix num' sid' assume"msg (σ i) = Pkt num' sid'" with‹σ' i ∈ is_pkt (σ i)›obtain"num (σ' i) = num'" and"sid (σ' i) = sid'" unfolding is_pkt_def by auto with‹msg (σ i) = Pkt num' sid'›and‹msg_ok σ (msg (σ i))› have"num (σ' i) ≤ no (σ (sid (σ' i)))" by simp alsofrom‹∀j. no (σ j) ≤ no (σ' j)›have"no (σ (sid (σ' i))) ≤ no (σ' (sid (σ' i)))" .. finallyshow ?thesis . next fix num' sid' assume"msg (σ i) = Newpkt num' sid'" with‹σ' i ∈ is_pkt (σ i)›have False unfolding is_pkt_def by simp thus ?thesis .. qed qed qed
lemma oseq_bigger_than_next: shows"optoy i ⊨ (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) global (λσ. no (σ i) ≤ no (σ (nhid (σ i))))"
(is"_ ⊨ (?S, ?U →) ?P") proof - have nhidinv: "optoy i ⊨ (?S, ?U →) onl ΓTOY (λ(σ, l). l∈{PToy-:2..PToy-:8} ⟶ nhid (σ i) = id (σ i))" by (rule oinvariant_weakenE [OF oseq_nhid_eq_id]) (auto simp: seqlsimp) have idinv: "optoy i ⊨ (?S, ?U →) onl ΓTOY (λ(σ, l). id (σ i) = i)" by (rule oinvariant_weakenE [OF oseq_id_constant]) (auto simp: seqlsimp)
{ fix σ σ' a assume"no (σ i) ≤ no (σ (nhid (σ i)))" and"∀j. nos_inc (σ j) (σ' j)" note this(1) alsofrom‹∀j. nos_inc (σ j) (σ' j)›have"no (σ (nhid (σ i))) ≤ no (σ' (nhid (σ i)))" by auto finallyhave"no (σ i) ≤ no (σ' (nhid (σ i)))" ..
} note * = this have"optoy i ⊨ (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) onl ΓTOY (λ(σ, l). no (σ i) ≤ no (σ (nhid (σ i))))" proof (inv_cterms
inv add: onl_oinvariant_sterms [OF toy_wf oseq_no_leq_num [THEN oinvariant_anyact]]
oseq_step_invariant_sterms [OF all_nos_inc toy_wf otoy_trans]
onl_oinvariant_sterms [OF toy_wf is_pkt_handler_num_leq_no]
onl_oinvariant_sterms [OF toy_wf nhidinv]
onl_oinvariant_sterms [OF toy_wf idinv]
simp add: seqlsimp seqllsimp
simp del: nos_inc_simp
solve: *) fix σ p l assume"(σ, p) ∈ σOTOY" thus"no (σ i) ≤ no (σ (nhid (σ i)))" by (simp add: σOTOY_def) next fix σ σ' p l assume or: "(σ, p) ∈ oreachable (optoy i) ?S ?U" and"l ∈ labels ΓTOY p" and"no (σ i) ≤ no (σ (nhid (σ i)))" and"other nos_inc {i} σ σ'" show"no (σ' i) ≤ no (σ' (nhid (σ' i)))" proof (cases "nhid (σ' i) = i") assume"nhid (σ' i) = i" with‹no (σ i) ≤ no (σ (nhid (σ i)))›show ?thesis by simp next assume"nhid (σ' i) ≠ i" moreoverfrom‹other nos_inc {i} σ σ'› [THEN other_localD] have"σ' i = σ i" by simp ultimatelyhave"no (σ (nhid (σ i))) ≤ no (σ' (nhid (σ' i)))" using‹other nos_inc {i} σ σ'›and‹σ' i = σ i›by (auto) with‹no (σ i) ≤ no (σ (nhid (σ i)))›and‹σ' i = σ i›show ?thesis by simp qed next fix p l σ a q l' σ' pp p' assume"no (σ i) ≤ num (σ i)" and"num (σ i) ≤ no (σ (sid (σ i)))" and"∀j. nos_inc (σ j) (σ' j)" from this(1-2) have"no (σ i) ≤ no (σ (sid (σ i)))" by (rule le_trans) alsofrom‹∀j. nos_inc (σ j) (σ' j)› have"no (σ (sid (σ i))) ≤ no (σ' (sid (σ i)))" by auto finallyshow"no (σ i) ≤ no (σ' (sid (σ i)))" .. qed thus ?thesis by (rule oinvariant_weakenE)
(auto simp: onl_def) qed
lemma anycast_weakenE [elim]: assumes"anycast P a" and"∧m. P m ==> Q m" shows"anycast Q a" using assms unfolding anycast_def by (auto split: seq_action.split)
lemma oseq_msg_ok: "optoy i ⊨A (act TT, other U {i} →) globala (λ(σ, a, _). anycast (msg_ok σ) a)" by (rule ostep_invariant_weakenE [OF open_seq_step_invariant
[OF seq_msg_ok initiali_toy otoy_trans toy_trans, simplified seql_onl_swap]])
(auto simp: seqllsimp dest!: onllD elim!: anycast_weakenE intro!: msg_okI)
subsection"Lifting"
lemma opar_bigger_than_next: shows"optoy i ⟨⟨ qmsg ⊨ (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) global (λσ. no (σ i) ≤ no (σ (nhid (σ i))))" proof (rule lift_into_qmsg [OF oseq_bigger_than_next]) fix σ σ' m assume"∀j. nos_inc (σ j) (σ' j)" and"msg_ok σ m" from this(2) show"msg_ok σ' m" proof (cases m, simp only: msg_ok_Pkt) fix num' sid' assume"num' ≤ no (σ sid')" alsofrom‹∀j. nos_inc (σ j) (σ' j)›have"no (σ sid') ≤ no (σ' sid')" by simp finallyshow"num' ≤ no (σ' sid')" . qed simp next show"optoy i ⊨A (otherwith nos_inc {i} (orecvmsg msg_ok), other nos_inc {i} →) globala (λ(σ, _, σ'). nos_inc (σ i) (σ' i))" by (rule ostep_invariant_weakenE [OF open_seq_step_invariant
[OF seq_nos_incs initiali_toy otoy_trans toy_trans]])
(auto simp: seqllsimp dest!: onllD) qed simp
lemma onode_bigger_than_next: "⟨i : optoy i ⟨⟨ qmsg : Ri⟩o ⊨ (otherwith nos_inc {i} (oarrivemsg msg_ok), other nos_inc {i} →) global (λσ. no (σ i) ≤ no (σ (nhid (σ i))))" by (rule node_lift [OF opar_bigger_than_next])
lemma opnet_bigger_than_next: "opnet (λi. optoy i ⟨⟨ qmsg) n ⊨ (otherwith nos_inc (net_tree_ips n) (oarrivemsg msg_ok), other nos_inc (net_tree_ips n) →) global (λσ. ∀i∈net_tree_ips n. no (σ i) ≤ no (σ (nhid (σ i))))" proof (rule pnet_lift [OF onode_bigger_than_next]) fix i Ri have"⟨i : optoy i ⟨⟨ qmsg : Ri⟩o⊨A (λσ _. oarrivemsg msg_ok σ, other (λ_ _. True) {i} →) globala (λ(σ, a, _). castmsg (msg_ok σ) a)" proof (rule node_lift_anycast_statelessassm) have"optoy i ⊨A (λσ _. orecvmsg (λ_ _. True) σ, other (λ_ _. True) {i} →) globala (λ(σ, a, _). anycast (msg_ok σ) a)" by (rule ostep_invariant_weakenE [OF oseq_msg_ok]) auto hence"optoy i ⟨⟨ qmsg ⊨A (λσ _. orecvmsg (λ_ _. True) σ, other (λ_ _. True) {i} →) globala (λ(σ, a, _). anycast (msg_ok σ) a)" by (rule lift_step_into_qmsg_statelessassm) auto thus"optoy i ⟨⟨ qmsg ⊨A (λσ _. orecvmsg msg_ok σ, other (λ_ _. True) {i} →) globala (λ(σ, a, _). anycast (msg_ok σ) a)" by (rule ostep_invariant_weakenE) auto qed thus"⟨i : optoy i ⟨⟨ qmsg : Ri⟩o⊨A (λσ _. oarrivemsg msg_ok σ, other nos_inc {i} →) globala (λ(σ, a, _). castmsg (msg_ok σ) a)" by (rule ostep_invariant_weakenE) auto next fix i Ri show"⟨i : optoy i ⟨⟨ qmsg : Ri⟩o⊨A (λσ _. oarrivemsg msg_ok σ, other nos_inc {i} →) globala (λ(σ, a, σ'). a ≠ τ ∧ (∀d. a ≠ i:deliver(d)) ⟶ nos_inc (σ i) (σ' i))" by (rule ostep_invariant_weakenE [OF node_local_nos_inc]) auto next fix i R show"⟨i : optoy i ⟨⟨ qmsg : R⟩o⊨A (λσ _. oarrivemsg msg_ok σ, other nos_inc {i} →) globala (λ(σ, a, σ'). a = τ ∨ (∃d. a = i:deliver(d)) ⟶ nos_inc (σ i) (σ' i))" by (rule ostep_invariant_weakenE [OF node_local_nos_inc]) auto qed simp_all
lemma ocnet_bigger_than_next: "oclosed (opnet (λi. optoy i ⟨⟨ qmsg) n) ⊨ (λ_ _ _. True, other nos_inc (net_tree_ips n) →) global (λσ. ∀i∈net_tree_ips n. no (σ i) ≤ no (σ (nhid (σ i))))" proof (rule inclosed_closed) show"opnet (λi. optoy i ⟨⟨ qmsg) n ⊨ (otherwith (=) (net_tree_ips n) inoclosed, other nos_inc (net_tree_ips n) →) global (λσ. ∀i∈net_tree_ips n. no (σ i) ≤ no (σ (nhid (σ i))))" proof (rule oinvariant_weakenE [OF opnet_bigger_than_next]) fix s s':: "nat ==> state"and a :: "msg node_action" assume"otherwith (=) (net_tree_ips n) inoclosed s s' a" thus"otherwith nos_inc (net_tree_ips n) (oarrivemsg msg_ok) s s' a" proof (rule otherwithE, intro otherwithI) assume"inoclosed s a" and"∀j. j ∉ net_tree_ips n ⟶ s j = s' j" and"otherwith ((=)) (net_tree_ips n) inoclosed s s' a" thus"oarrivemsg msg_ok s a" by (cases a) auto qed auto qed simp qed
subsection"Transfer"
definition
initmissing :: "(nat ==> state option) × 'a ==> (nat ==> state) × 'a" where "initmissing σ = (λi. case (fst σ) i of None ==> toy_init i | Some s ==> s, snd σ)"
lemma not_in_net_ips_fst_init_missing [simp]: assumes"i ∉ net_ips σ" shows"fst (initmissing (netgmap fst σ)) i = toy_init i" using assms unfolding initmissing_def by simp
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.