(* Title: Global_Invariants.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "Global invariant proofs over sequential processes" theory Global_Invariants imports Seq_Invariants Aodv_Predicates Fresher Quality_Increases AWN.OAWN_Convert OAodv begin lemma other_quality_increases [elim]: assumes "other quality_increases I \ \'" shows "\j. quality_increases (\ j) (\' j)" using assms by (rule, clarsimp) (metis quality_increases_refl) lemma weaken_otherwith [elim]: fixes m assumes *: "otherwith P I (orecvmsg Q) \ \' a" and weakenP: "\\ m. P \ m \ P' \ m" and weakenQ: "\\ m. Q \ m \ Q' \ m" shows "otherwith P' I (orecvmsg Q') \ \' a" proof fix j assume "j\I" with * have "P (\ j) (\' j)" by auto thus "P' (\ j) (\' j)" by (rule weakenP) next from * have "orecvmsg Q \ a" by auto thus "orecvmsg Q' \ a" by rule (erule weakenQ) qed lemma oreceived_msg_inv: assumes other: "\\ \' m. \ P \ m; other Q {i} \ \' \ \ P \' m" and local: "\\ m. P \ m \ P (\(i := \ i\msg := m\)) m" shows "opaodv i \ (otherwith Q {i} (orecvmsg P), other Q {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:1} \ P \ (msg (\ i)))" proof (inv_cterms, intro impI) fix \ \' l assume "l = PAodv-:1 \ P \ (msg (\ i))" and "l = PAodv-:1" and "other Q {i} \ \'" from this(1-2) have "P \ (msg (\ i))" .. hence "P \' (msg (\ i))" using \other Q {i} \ \'\ by (rule other) moreover from \other Q {i} \ \'\ have "\' i = \ i" .. ultimately show "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 text \(Equivalent to) Proposition 7.27\ lemma local_quality_increases: "paodv i \\<^sub>A (recvmsg rreq_rrep_sn \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). quality_increases \ \')" proof (rule step_invariantI) fix s a s' assume sr: "s \ reachable (paodv i) (recvmsg rreq_rrep_sn)" and tr: "(s, a, s') \ trans (paodv i)" and rm: "recvmsg rreq_rrep_sn a" from sr have srTT: "s \ reachable (paodv i) TT" .. from route_tables_fresher sr tr rm have "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \dip\kD (rt \). rt \ \\<^bsub>dip\<^esub> rt \') (s, a, s')" by (rule step_invariantD) moreover from known_destinations_increase srTT tr TT_True have "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). kD (rt \) \ kD (rt \')) (s, a, s')" by (rule step_invariantD) moreover from sqns_increase srTT tr TT_True have "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \ip. sqn (rt \) ip \ sqn (rt \') ip) (s, a, s')" by (rule step_invariantD) ultimately show "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). quality_increases \ \') (s, a, s')" unfolding onll_def by auto qed lemmas olocal_quality_increases = open_seq_step_invariant [OF local_quality_increases initiali_aodv oaodv_trans aodv_trans, simplified seqll_onll_swap] lemma oquality_increases: "opaodv i \\<^sub>A (otherwith quality_increases {i} (orecvmsg (\_. rreq_rrep_sn)), other quality_increases {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \j. quality_increases (\ j) (\' j))" (is "_ \\<^sub>A (?S, _ \) _") proof (rule onll_ostep_invariantI, simp) fix \ p l a \' p' l' assume or: "(\, p) \ oreachable (opaodv i) ?S (other quality_increases {i})" and ll: "l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" and "?S \ \' a" and tr: "((\, p), a, (\', p')) \ oseqp_sos \\<^sub>A\<^sub>O\<^sub>D\<^sub>V i" and ll': "l' \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'" from this(1-3) have "orecvmsg (\_. rreq_rrep_sn) \ a" by (auto dest!: oreachable_weakenE [where QS="act (recvmsg rreq_rrep_sn)" and QU="other quality_increases {i}"] otherwith_actionD) with or have orw: "(\, p) \ oreachable (opaodv i) (act (recvmsg rreq_rrep_sn)) (other quality_increases {i})" by - (erule oreachable_weakenE, auto) with tr ll ll' and \orecvmsg (\_. rreq_rrep_sn) \ a\ have "quality_increases (\ i) (\' i)" by - (drule onll_ostep_invariantD [OF olocal_quality_increases], auto simp: seqll_def) with \?S \ \' a\ show "\j. quality_increases (\ j) (\' j)" by (auto dest!: otherwith_syncD) qed lemma rreq_rrep_nsqn_fresh_any_step_invariant: "opaodv i \\<^sub>A (act (recvmsg rreq_rrep_sn), other A {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (msg_fresh \) a)" proof (rule ostep_invariantI, simp del: act_simp) fix \ p a \' p' assume or: "(\, p) \ oreachable (opaodv i) (act (recvmsg rreq_rrep_sn)) (other A {i})" and "((\, p), a, (\', p')) \ oseqp_sos \\<^sub>A\<^sub>O\<^sub>D\<^sub>V i" and recv: "act (recvmsg rreq_rrep_sn) \ \' a" obtain l l' where "l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" and "l'\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'" by (metis aodv_ex_label) from \((\, p), a, (\', p')) \ oseqp_sos \\<^sub>A\<^sub>O\<^sub>D\<^sub>V i\ have tr: "((\, p), a, (\', p')) \ trans (opaodv i)" by simp have "anycast (rreq_rrep_fresh (rt (\ i))) a" proof - have "opaodv i \\<^sub>A (act (recvmsg rreq_rrep_sn), other A {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\((\, _), a, _). anycast (rreq_rrep_fresh (rt \)) a))" by (rule ostep_invariant_weakenE [OF open_seq_step_invariant [OF rreq_rrep_fresh_any_step_invariant initiali_aodv, simplified seqll_onll_swap]]) auto hence "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\((\, _), a, _). anycast (rreq_rrep_fresh (rt \)) a)) ((\, p), a, (\', p'))" using or tr recv by - (erule(4) ostep_invariantE) thus ?thesis using \l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and \l'\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'\ by auto qed moreover have "anycast (rerr_invalid (rt (\ i))) a" proof - have "opaodv i \\<^sub>A (act (recvmsg rreq_rrep_sn), other A {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\((\, _), a, _). anycast (rerr_invalid (rt \)) a))" by (rule ostep_invariant_weakenE [OF open_seq_step_invariant [OF rerr_invalid_any_step_invariant initiali_aodv, simplified seqll_onll_swap]]) auto hence "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\((\, _), a, _). anycast (rerr_invalid (rt \)) a)) ((\, p), a, (\', p'))" using or tr recv by - (erule(4) ostep_invariantE) thus ?thesis using \l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and \l'\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'\ by auto qed moreover have "anycast rreq_rrep_sn a" proof - from or tr recv have "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\(_, a, _). anycast rreq_rrep_sn a)) ((\, p), a, (\', p'))" by (rule ostep_invariantE [OF open_seq_step_invariant [OF rreq_rrep_sn_any_step_invariant initiali_aodv oaodv_trans aodv_trans, simplified seqll_onll_swap]]) thus ?thesis using \l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and \l'\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'\ by auto qed moreover have "anycast (\m. not_Pkt m \ msg_sender m = i) a" proof - have "opaodv i \\<^sub>A (act (recvmsg rreq_rrep_sn), other A {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seqll i (\((\, _), a, _). anycast (\m. not_Pkt m \ msg_sender m = i) a))" by (rule ostep_invariant_weakenE [OF open_seq_step_invariant [OF sender_ip_valid initiali_aodv, simplified seqll_onll_swap]]) auto thus ?thesis using or tr recv \l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and \l'\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p'\ by - (drule(3) onll_ostep_invariantD, auto) qed ultimately have "anycast (msg_fresh \) a" by (simp_all add: anycast_def del: msg_fresh split: seq_action.split_asm msg.split_asm) simp_all thus "onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (msg_fresh \) a) ((\, p), a, (\', p'))" by auto qed lemma oreceived_rreq_rrep_nsqn_fresh_inv: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:1} \ msg_fresh \ (msg (\ i)))" proof (rule oreceived_msg_inv) fix \ \' m assume *: "msg_fresh \ m" and "other quality_increases {i} \ \'" from this(2) have "\j. quality_increases (\ j) (\' j)" .. thus "msg_fresh \' m" using * .. next fix \ m assume "msg_fresh \ m" thus "msg_fresh (\(i := \ i\msg := m\)) m" proof (cases m) fix dests sip assume "m = Rerr dests sip" with \msg_fresh \ m\ show ?thesis by auto qed auto qed lemma oquality_increases_nsqn_fresh: "opaodv i \\<^sub>A (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \j. quality_increases (\ j) (\' j))" by (rule ostep_invariant_weakenE [OF oquality_increases]) auto lemma oosn_rreq: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seql i (\(\, l). l \ {PAodv-:4, PAodv-:5} \ {PRreq-:n |n. True} \ 1 \ osn \))" by (rule oinvariant_weakenE [OF open_seq_invariant [OF osn_rreq initiali_aodv]]) (auto simp: seql_onl_swap) lemma rreq_sip: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PAodv-:4, PAodv-:5, PRreq-:0, PRreq-:2} \ sip (\ i) \ oip (\ i)) \ oip (\ i) \ kD(rt (\ (sip (\ i)))) \ nsqn (rt (\ (sip (\ i)))) (oip (\ i)) \ osn (\ i) \ (nsqn (rt (\ (sip (\ i)))) (oip (\ i)) = osn (\ i) \ (hops (\ i) \ the (dhops (rt (\ (sip (\ i)))) (oip (\ i))) \ the (flag (rt (\ (sip (\ i)))) (oip (\ i))) = inv)))" (is "_ \ (?S, ?U \) _") proof (inv_cterms inv add: oseq_step_invariant_sterms [OF oquality_increases_nsqn_fresh aodv_wf oaodv_trans] onl_oinvariant_sterms [OF aodv_wf oreceived_rreq_rrep_nsqn_fresh_inv] onl_oinvariant_sterms [OF aodv_wf oosn_rreq] simp add: seqlsimp simp del: One_nat_def, rule impI) fix \ \' p l assume "(\, p) \ oreachable (opaodv i) ?S ?U" and "l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" and pre: "(l = PAodv-:4 \ l = PAodv-:5 \ l = PRreq-:0 \ l = PRreq-:2) \ sip (\ i) \ oip (\ i) \ oip (\ i) \ kD (rt (\ (sip (\ i)))) \ osn (\ i) \ nsqn (rt (\ (sip (\ i)))) (oip (\ i)) \ (nsqn (rt (\ (sip (\ i)))) (oip (\ i)) = osn (\ i) \ the (dhops (rt (\ (sip (\ i)))) (oip (\ i))) \ hops (\ i) \ the (flag (rt (\ (sip (\ i)))) (oip (\ i))) = inv)" and "other quality_increases {i} \ \'" and hyp: "(l=PAodv-:4 \ l=PAodv-:5 \ l=PRreq-:0 \ l=PRreq-:2) \ sip (\' i) \ oip (\' i)" (is "?labels \ sip (\' i) \ oip (\' i)") from this(4) have "\' i = \ i" .. with hyp have hyp': "?labels \ sip (\ i) \ oip (\ i)" by simp show "oip (\' i) \ kD (rt (\' (sip (\' i)))) \ osn (\' i) \ nsqn (rt (\' (sip (\' i)))) (oip (\' i)) \ (nsqn (rt (\' (sip (\' i)))) (oip (\' i)) = osn (\' i) \ the (dhops (rt (\' (sip (\' i)))) (oip (\' i))) \ hops (\' i) \ the (flag (rt (\' (sip (\' i)))) (oip (\' i))) = inv)" proof (cases "sip (\ i) = i") assume "sip (\ i) \ i" from \other quality_increases {i} \ \'\ have "quality_increases (\ (sip (\ i))) (\' (sip (\' i)))" by (rule otherE) (clarsimp simp: \sip (\ i) \ i\) moreover from \(\, p) \ oreachable (opaodv i) ?S ?U\ \l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and hyp have "1 \ osn (\' i)" by (auto dest!: onl_oinvariant_weakenD [OF oosn_rreq] simp add: seqlsimp \\' i = \ i\) moreover from \sip (\ i) \ i\ hyp' and pre have "oip (\' i) \ kD (rt (\ (sip (\ i)))) \ osn (\' i) \ nsqn (rt (\ (sip (\ i)))) (oip (\' i)) \ (nsqn (rt (\ (sip (\ i)))) (oip (\' i)) = osn (\' i) \ the (dhops (rt (\ (sip (\ i)))) (oip (\' i))) \ hops (\' i) \ the (flag (rt (\ (sip (\ i)))) (oip (\' i))) = inv)" by (auto simp: \\' i = \ i\) ultimately show ?thesis by (rule quality_increases_rreq_rrep_props) next assume "sip (\ i) = i" thus ?thesis using \\' i = \ i\ hyp and pre by auto qed qed (auto elim!: quality_increases_rreq_rrep_props') lemma odsn_rrep: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (seql i (\(\, l). l \ {PAodv-:6, PAodv-:7} \ {PRrep-:n|n. True} \ 1 \ dsn \))" by (rule oinvariant_weakenE [OF open_seq_invariant [OF dsn_rrep initiali_aodv]]) (auto simp: seql_onl_swap) lemma rrep_sip: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PAodv-:6, PAodv-:7, PRrep-:0, PRrep-:1} \ sip (\ i) \ dip (\ i)) \ dip (\ i) \ kD(rt (\ (sip (\ i)))) \ nsqn (rt (\ (sip (\ i)))) (dip (\ i)) \ dsn (\ i) \ (nsqn (rt (\ (sip (\ i)))) (dip (\ i)) = dsn (\ i) \ (hops (\ i) \ the (dhops (rt (\ (sip (\ i)))) (dip (\ i))) \ the (flag (rt (\ (sip (\ i)))) (dip (\ i))) = inv)))" (is "_ \ (?S, ?U \) _") proof (inv_cterms inv add: oseq_step_invariant_sterms [OF oquality_increases_nsqn_fresh aodv_wf oaodv_trans] onl_oinvariant_sterms [OF aodv_wf oreceived_rreq_rrep_nsqn_fresh_inv] onl_oinvariant_sterms [OF aodv_wf odsn_rrep] simp del: One_nat_def, rule impI) fix \ \' p l assume "(\, p) \ oreachable (opaodv i) ?S ?U" and "l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" and pre: "(l = PAodv-:6 \ l = PAodv-:7 \ l = PRrep-:0 \ l = PRrep-:1) \ sip (\ i) \ dip (\ i) \ dip (\ i) \ kD (rt (\ (sip (\ i)))) \ dsn (\ i) \ nsqn (rt (\ (sip (\ i)))) (dip (\ i)) \ (nsqn (rt (\ (sip (\ i)))) (dip (\ i)) = dsn (\ i) \ the (dhops (rt (\ (sip (\ i)))) (dip (\ i))) \ hops (\ i) \ the (flag (rt (\ (sip (\ i)))) (dip (\ i))) = inv)" and "other quality_increases {i} \ \'" and hyp: "(l=PAodv-:6 \ l=PAodv-:7 \ l=PRrep-:0 \ l=PRrep-:1) \ sip (\' i) \ dip (\' i)" (is "?labels \ sip (\' i) \ dip (\' i)") from this(4) have "\' i = \ i" .. with hyp have hyp': "?labels \ sip (\ i) \ dip (\ i)" by simp show "dip (\' i) \ kD (rt (\' (sip (\' i)))) \ dsn (\' i) \ nsqn (rt (\' (sip (\' i)))) (dip (\' i)) \ (nsqn (rt (\' (sip (\' i)))) (dip (\' i)) = dsn (\' i) \ the (dhops (rt (\' (sip (\' i)))) (dip (\' i))) \ hops (\' i) \ the (flag (rt (\' (sip (\' i)))) (dip (\' i))) = inv)" proof (cases "sip (\ i) = i") assume "sip (\ i) \ i" from \other quality_increases {i} \ \'\ have "quality_increases (\ (sip (\ i))) (\' (sip (\' i)))" by (rule otherE) (clarsimp simp: \sip (\ i) \ i\) moreover from \(\, p) \ oreachable (opaodv i) ?S ?U\ \l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and hyp have "1 \ dsn (\' i)" by (auto dest!: onl_oinvariant_weakenD [OF odsn_rrep] simp add: seqlsimp \\' i = \ i\) moreover from \sip (\ i) \ i\ hyp' and pre have "dip (\' i) \ kD (rt (\ (sip (\ i)))) \ dsn (\' i) \ nsqn (rt (\ (sip (\ i)))) (dip (\' i)) \ (nsqn (rt (\ (sip (\ i)))) (dip (\' i)) = dsn (\' i) \ the (dhops (rt (\ (sip (\ i)))) (dip (\' i))) \ hops (\' i) \ the (flag (rt (\ (sip (\ i)))) (dip (\' i))) = inv)" by (auto simp: \\' i = \ i\) ultimately show ?thesis by (rule quality_increases_rreq_rrep_props) next assume "sip (\ i) = i" thus ?thesis using \\' i = \ i\ hyp and pre by auto qed qed (auto simp add: seqlsimp elim!: quality_increases_rreq_rrep_props') lemma rerr_sip: "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:8, PAodv-:9, PRerr-:0, PRerr-:1} \ (\ripc\dom(dests (\ i)). ripc\kD(rt (\ (sip (\ i)))) \ the (dests (\ i) ripc) - 1 \ nsqn (rt (\ (sip (\ i)))) ripc))" (is "_ \ (?S, ?U \) _") proof - { fix dests rip sip rsn and \ \' :: "ip \ state" assume qinc: "\j. quality_increases (\ j) (\' j)" and *: "\rip\dom dests. rip \ kD (rt (\ sip)) \ the (dests rip) - 1 \ nsqn (rt (\ sip)) rip" and "dests rip = Some rsn" from this(3) have "rip\dom dests" by auto with * and \dests rip = Some rsn\ have "rip\kD(rt (\ sip))" and "rsn - 1 \ nsqn (rt (\ sip)) rip" by (auto dest!: bspec) from qinc have "quality_increases (\ sip) (\' sip)" .. have "rip \ kD(rt (\' sip)) \ rsn - 1 \ nsqn (rt (\' sip)) rip" proof from \rip\kD(rt (\ sip))\ and \quality_increases (\ sip) (\' sip)\ show "rip \ kD(rt (\' sip))" .. next from \rip\kD(rt (\ sip))\ and \quality_increases (\ sip) (\' sip)\ have "nsqn (rt (\ sip)) rip \ nsqn (rt (\' sip)) rip" .. with \rsn - 1 \ nsqn (rt (\ sip)) rip\ show "rsn - 1 \ nsqn (rt (\' sip)) rip" by (rule le_trans) qed } note partial = this show ?thesis by (inv_cterms inv add: oseq_step_invariant_sterms [OF oquality_increases_nsqn_fresh aodv_wf oaodv_trans] onl_oinvariant_sterms [OF aodv_wf oreceived_rreq_rrep_nsqn_fresh_inv] other_quality_increases other_localD simp del: One_nat_def, intro conjI) (clarsimp simp del: One_nat_def split: if_split_asm option.split_asm, erule(2) partial)+ qed lemma prerr_guard: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l = PRerr-:1 \ (\ip\dom(dests \). ip\vD(rt \) \ the (nhop (rt \) ip) = sip \ \ sqn (rt \) ip < the (dests \ ip))))" by (inv_cterms) (clarsimp split: option.split_asm if_split_asm) lemmas oaddpreRT_welldefined = open_seq_invariant [OF addpreRT_welldefined initiali_aodv oaodv_trans aodv_trans, simplified seql_onl_swap, THEN oinvariant_anyact] lemmas odests_vD_inc_sqn = open_seq_invariant [OF dests_vD_inc_sqn initiali_aodv oaodv_trans aodv_trans, simplified seql_onl_swap, THEN oinvariant_anyact] lemmas oprerr_guard = open_seq_invariant [OF prerr_guard initiali_aodv oaodv_trans aodv_trans, simplified seql_onl_swap, THEN oinvariant_anyact] text \Proposition 7.28\ lemma seq_compare_next_hop': "opaodv i \ (otherwith quality_increases {i} (orecvmsg msg_fresh), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip. let nhip = the (nhop (rt (\ i)) dip) in dip \ kD(rt (\ i)) \ nhip \ dip \ dip \ kD(rt (\ nhip)) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ nhip)) dip)" (is "_ \ (?S, ?U \) _") proof - { fix nhop and \ \' :: "ip \ state" assume pre: "\dip\kD(rt (\ i)). nhop dip \ dip \ dip\kD(rt (\ (nhop dip))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (nhop dip))) dip" and qinc: "\j. quality_increases (\ j) (\' j)" have "\dip\kD(rt (\ i)). nhop dip \ dip \ dip\kD(rt (\' (nhop dip))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\' (nhop dip))) dip" proof (intro ballI impI) fix dip assume "dip\kD(rt (\ i))" and "nhop dip \ dip" with pre have "dip\kD(rt (\ (nhop dip)))" and "nsqn (rt (\ i)) dip \ nsqn (rt (\ (nhop dip))) dip" by auto from qinc have qinc_nhop: "quality_increases (\ (nhop dip)) (\' (nhop dip))" .. with \dip\kD(rt (\ (nhop dip)))\ have "dip\kD (rt (\' (nhop dip)))" .. moreover have "nsqn (rt (\ i)) dip \ nsqn (rt (\' (nhop dip))) dip" proof - from \dip\kD(rt (\ (nhop dip)))\ qinc_nhop have "nsqn (rt (\ (nhop dip))) dip \ nsqn (rt (\' (nhop dip))) dip" .. with \nsqn (rt (\ i)) dip \ nsqn (rt (\ (nhop dip))) dip\ show ?thesis by simp qed ultimately show "dip\kD(rt (\' (nhop dip))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\' (nhop dip))) dip" .. qed } note basic = this { fix nhop and \ \' :: "ip \ state" assume pre: "\dip\kD(rt (\ i)). nhop dip \ dip \ dip\kD(rt (\ (nhop dip))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (nhop dip))) dip" and ndest: "\ripc\dom (dests (\ i)). ripc \ kD (rt (\ (sip (\ i)))) \ the (dests (\ i) ripc) - 1 \ nsqn (rt (\ (sip (\ i)))) ripc" and issip: "\ip\dom (dests (\ i)). nhop ip = sip (\ i)" and qinc: "\j. quality_increases (\ j) (\' j)" have "\dip\kD(rt (\ i)). nhop dip \ dip \ dip \ kD (rt (\' (nhop dip))) \ nsqn (invalidate (rt (\ i)) (dests (\ i))) dip \ nsqn (rt (\' (nhop dip))) dip" proof (intro ballI impI) fix dip assume "dip\kD(rt (\ i))" and "nhop dip \ dip" with pre and qinc have "dip\kD(rt (\' (nhop dip)))" and "nsqn (rt (\ i)) dip \ nsqn (rt (\' (nhop dip))) dip" by (auto dest!: basic) have "nsqn (invalidate (rt (\ i)) (dests (\ i))) dip \ nsqn (rt (\' (nhop dip))) dip" proof (cases "dip\dom (dests (\ i))") assume "dip\dom (dests (\ i))" with \dip\kD(rt (\ i))\ obtain dsn where "dests (\ i) dip = Some dsn" by auto with \dip\kD(rt (\ i))\ have "nsqn (invalidate (rt (\ i)) (dests (\ i))) dip = dsn - 1" by (rule nsqn_invalidate_eq) moreover have "dsn - 1 \ nsqn (rt (\' (nhop dip))) dip" proof - from \dests (\ i) dip = Some dsn\ have "the (dests (\ i) dip) = dsn" by simp with ndest and \dip\dom (dests (\ i))\ have "dip \ kD (rt (\ (sip (\ i))))" "dsn - 1 \ nsqn (rt (\ (sip (\ i)))) dip" by auto moreover from issip and \dip\dom (dests (\ i))\ have "nhop dip = sip (\ i)" .. ultimately have "dip \ kD (rt (\ (nhop dip)))" and "dsn - 1 \ nsqn (rt (\ (nhop dip))) dip" by auto with qinc show "dsn - 1 \ nsqn (rt (\' (nhop dip))) dip" by simp (metis kD_nsqn_quality_increases_trans) qed ultimately show ?thesis by simp next assume "dip \ dom (dests (\ i))" with \dip\kD(rt (\ i))\ have "nsqn (invalidate (rt (\ i)) (dests (\ i))) dip = nsqn (rt (\ i)) dip" by (rule nsqn_invalidate_other) with \nsqn (rt (\ i)) dip \ nsqn (rt (\' (nhop dip))) dip\ show ?thesis by simp qed with \dip\kD(rt (\' (nhop dip)))\ show "dip \ kD (rt (\' (nhop dip))) \ nsqn (invalidate (rt (\ i)) (dests (\ i))) dip \ nsqn (rt (\' (nhop dip))) dip" .. qed } note basic_prerr = this { fix \ \' :: "ip \ state" assume a1: "\dip\kD(rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\ (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (the (nhop (rt (\ i)) dip)))) dip" and a2: "\j. quality_increases (\ j) (\' j)" have "\dip\kD(rt (\ i)). the (nhop (update (rt (\ i)) (sip (\ i)) (0, unk, val, Suc 0, sip (\ i), {})) dip) \ dip \ dip\kD(rt (\' (the (nhop (update (rt (\ i)) (sip (\ i)) (0, unk, val, Suc 0, sip (\ i), {})) dip)))) \ nsqn (update (rt (\ i)) (sip (\ i)) (0, unk, val, Suc 0, sip (\ i), {})) dip \ nsqn (rt (\' (the (nhop (update (rt (\ i)) (sip (\ i)) (0, unk, val, Suc 0, sip (\ i), {})) dip)))) dip" (is "\dip\kD(rt (\ i)). ?P dip") proof fix dip assume "dip\kD(rt (\ i))" with a1 and a2 have "the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\' (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\' (the (nhop (rt (\ i)) dip)))) dip" by - (drule(1) basic, auto) thus "?P dip" by (cases "dip = sip (\ i)") auto qed } note nhop_update_sip = this { fix \ \' oip sip osn hops assume pre: "\dip\kD (rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\ (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (the (nhop (rt (\ i)) dip)))) dip" and qinc: "\j. quality_increases (\ j) (\' j)" and *: "sip \ oip \ oip\kD(rt (\ sip)) \ osn \ nsqn (rt (\ sip)) oip \ (nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops \ the (flag (rt (\ sip)) oip) = inv)" from pre and qinc have pre': "\dip\kD (rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\' (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\' (the (nhop (rt (\ i)) dip)))) dip" by (rule basic) have "(the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) oip) \ oip \ oip\kD(rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) oip)))) \ nsqn (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) oip \ nsqn (rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) oip)))) oip)" (is "?nhop_not_oip \ ?oip_in_kD \ ?nsqn_le_nsqn") proof (rule, split update_rt_split_asm) assume "rt (\ i) = update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})" and "the (nhop (rt (\ i)) oip) \ oip" with pre' show "?oip_in_kD \ ?nsqn_le_nsqn" by auto next assume rtnot: "rt (\ i) \ update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})" and notoip: ?nhop_not_oip with * qinc have ?oip_in_kD by auto moreover with * pre qinc rtnot notoip have ?nsqn_le_nsqn by simp (metis kD_nsqn_quality_increases_trans) ultimately show "?oip_in_kD \ ?nsqn_le_nsqn" .. qed } note update1 = this { fix \ \' oip sip osn hops assume pre: "\dip\kD (rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\ (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (the (nhop (rt (\ i)) dip)))) dip" and qinc: "\j. quality_increases (\ j) (\' j)" and *: "sip \ oip \ oip\kD(rt (\ sip)) \ osn \ nsqn (rt (\ sip)) oip \ (nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops \ the (flag (rt (\ sip)) oip) = inv)" from pre and qinc have pre': "\dip\kD (rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip\kD(rt (\' (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\' (the (nhop (rt (\ i)) dip)))) dip" by (rule basic) have "\dip\kD(rt (\ i)). the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip) \ dip \ dip\kD(rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip)))) \ nsqn (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip \ nsqn (rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip)))) dip" (is "\dip\kD(rt (\ i)). _ \ ?dip_in_kD dip \ ?nsqn_le_nsqn dip") proof (intro ballI impI, split update_rt_split_asm) fix dip assume "dip\kD(rt (\ i))" and "the (nhop (rt (\ i)) dip) \ dip" and "rt (\ i) = update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})" with pre' show "?dip_in_kD dip \ ?nsqn_le_nsqn dip" by simp next fix dip assume "dip\kD(rt (\ i))" and notdip: "the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip) \ dip" and rtnot: "rt (\ i) \ update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})" show "?dip_in_kD dip \ ?nsqn_le_nsqn dip" proof (cases "dip = oip") assume "dip \ oip" with pre' \dip\kD(rt (\ i))\ notdip show ?thesis by clarsimp next assume "dip = oip" with rtnot qinc \dip\kD(rt (\ i))\ notdip * have "?dip_in_kD dip" by simp (metis kD_quality_increases) moreover from \dip = oip\ rtnot qinc \dip\kD(rt (\ i))\ notdip * have "?nsqn_le_nsqn dip" by simp (metis kD_nsqn_quality_increases_trans) ultimately show ?thesis .. qed qed } note update2 = this have "opaodv i \ (?S, ?U \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip \ kD(rt (\ i)). the (nhop (rt (\ i)) dip) \ dip \ dip \ kD(rt (\ (the (nhop (rt (\ i)) dip)))) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ (the (nhop (rt (\ i)) dip)))) dip)" by (inv_cterms inv add: oseq_step_invariant_sterms [OF oquality_increases_nsqn_fresh aodv_wf oaodv_trans] onl_oinvariant_sterms [OF aodv_wf oaddpreRT_welldefined] onl_oinvariant_sterms [OF aodv_wf odests_vD_inc_sqn] onl_oinvariant_sterms [OF aodv_wf oprerr_guard] onl_oinvariant_sterms [OF aodv_wf rreq_sip] onl_oinvariant_sterms [OF aodv_wf rrep_sip] onl_oinvariant_sterms [OF aodv_wf rerr_sip] other_quality_increases other_localD solve: basic basic_prerr simp add: seqlsimp nsqn_invalidate nhop_update_sip simp del: One_nat_def) (rule conjI, erule(2) update1, erule(2) update2)+ thus ?thesis unfolding Let_def by auto qed text \Proposition 7.30\ lemmas okD_unk_or_atleast_one = open_seq_invariant [OF kD_unk_or_atleast_one initiali_aodv, simplified seql_onl_swap] lemmas ozero_seq_unk_hops_one = open_seq_invariant [OF zero_seq_unk_hops_one initiali_aodv, simplified seql_onl_swap] lemma oreachable_fresh_okD_unk_or_atleast_one: fixes dip assumes "(\, p) \ oreachable (opaodv i) (otherwith ((=)) {i} (orecvmsg (\\ m. msg_fresh \ m \ msg_zhops m))) (other quality_increases {i})" and "dip\kD(rt (\ i))" shows "\\<^sub>3(the (rt (\ i) dip)) = unk \ 1 \ \\<^sub>2(the (rt (\ i) dip))" (is "?P dip") proof - have "\l. l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" by (metis aodv_ex_label) with assms(1) have "\dip\kD (rt (\ i)). ?P dip" by - (drule oinvariant_weakenD [OF okD_unk_or_atleast_one [OF oaodv_trans aodv_trans]], auto dest!: otherwith_actionD onlD simp: seqlsimp) with \dip\kD(rt (\ i))\ show ?thesis by simp qed lemma oreachable_fresh_ozero_seq_unk_hops_one: fixes dip assumes "(\, p) \ oreachable (opaodv i) (otherwith ((=)) {i} (orecvmsg (\\ m. msg_fresh \ m \ msg_zhops m))) (other quality_increases {i})" and "dip\kD(rt (\ i))" shows "sqn (rt (\ i)) dip = 0 \ sqnf (rt (\ i)) dip = unk \ the (dhops (rt (\ i)) dip) = 1 \ the (nhop (rt (\ i)) dip) = dip" (is "?P dip") proof - have "\l. l\labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" by (metis aodv_ex_label) with assms(1) have "\dip\kD (rt (\ i)). ?P dip" by - (drule oinvariant_weakenD [OF ozero_seq_unk_hops_one [OF oaodv_trans aodv_trans]], auto dest!: onlD otherwith_actionD simp: seqlsimp) with \dip\kD(rt (\ i))\ show ?thesis by simp qed lemma seq_nhop_quality_increases': shows "opaodv i \ (otherwith ((=)) {i} (orecvmsg (\\ m. msg_fresh \ m \ msg_zhops m)), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip. let nhip = the (nhop (rt (\ i)) dip) in dip \ vD (rt (\ i)) \ vD (rt (\ nhip)) \ nhip \ dip \ (rt (\ i)) \\<^bsub>dip\<^esub> (rt (\ nhip)))" (is "_ \ (?S i, _ \) _") proof - have weaken: "\p I Q R P. p \ (otherwith quality_increases I (orecvmsg Q), other quality_increases I \) P \ p \ (otherwith ((=)) I (orecvmsg (\\ m. Q \ m \ R \ m)), other quality_increases I \) P" by auto { fix i a and \ \' :: "ip \ state" assume a1: "\dip. dip\vD(rt (\ i)) \ dip\vD(rt (\ (the (nhop (rt (\ i)) dip)))) \ (the (nhop (rt (\ i)) dip)) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" and ow: "?S i \ \' a" have "\dip. dip\vD(rt (\ i)) \ dip\vD (rt (\' (the (nhop (rt (\ i)) dip)))) \ (the (nhop (rt (\ i)) dip)) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\ i)) dip)))" proof clarify fix dip assume a2: "dip\vD(rt (\ i))" and a3: "dip\vD (rt (\' (the (nhop (rt (\ i)) dip))))" and a4: "(the (nhop (rt (\ i)) dip)) \ dip" from ow have "\j. j \ i \ \ j = \' j" by auto show "rt (\ i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\ i)) dip)))" proof (cases "(the (nhop (rt (\ i)) dip)) = i") assume "(the (nhop (rt (\ i)) dip)) = i" with \dip \ vD(rt (\ i))\ have "dip \ vD(rt (\ (the (nhop (rt (\ i)) dip))))" by simp with a1 a2 a4 have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" by simp with \(the (nhop (rt (\ i)) dip)) = i\ have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ i)" by simp hence False by simp thus ?thesis .. next assume "(the (nhop (rt (\ i)) dip)) \ i" with \\j. j \ i \ \ j = \' j\ have *: "\ (the (nhop (rt (\ i)) dip)) = \' (the (nhop (rt (\ i)) dip))" by simp with \dip\vD (rt (\' (the (nhop (rt (\ i)) dip))))\ have "dip\vD (rt (\ (the (nhop (rt (\ i)) dip))))" by simp with a1 a2 a4 have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" by simp with * show ?thesis by simp qed qed } note basic = this { fix \ \' a dip sip i assume a1: "\dip. dip\vD(rt (\ i)) \ dip\vD(rt (\ (the (nhop (rt (\ i)) dip)))) \ the (nhop (rt (\ i)) dip) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" and ow: "?S i \ \' a" have "\dip. dip\vD(update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) \ dip\vD(rt (\' (the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip)))) \ the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip) \ dip \ update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {}) \\<^bsub>dip\<^esub> rt (\' (the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip)))" proof clarify fix dip assume a2: "dip\vD (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {}))" and a3: "dip\vD(rt (\' (the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip))))" and a4: "the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip) \ dip" show "update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {}) \\<^bsub>dip\<^esub> rt (\' (the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip)))" proof (cases "dip = sip") assume "dip = sip" with \the (nhop (update (rt (\ i)) sip (0, unk, val, Suc 0, sip, {})) dip) \ dip\ have False by simp thus ?thesis .. next assume [simp]: "dip \ sip" from a2 have "dip\vD(rt (\ i)) \ dip = sip" by (rule vD_update_val) with \dip \ sip\ have "dip\vD(rt (\ i))" by simp moreover from a3 have "dip\vD(rt (\' (the (nhop (rt (\ i)) dip))))" by simp moreover from a4 have "the (nhop (rt (\ i)) dip) \ dip" by simp ultimately have "rt (\ i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\ i)) dip)))" using a1 ow by - (drule(1) basic, simp) with \dip \ sip\ show ?thesis by - (erule rt_strictly_fresher_update_other, simp) qed qed } note update_0_unk = this { fix \ a \' nhop assume pre: "\dip. dip\vD(rt (\ i)) \ dip\vD(rt (\ (nhop dip))) \ nhop dip \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (nhop dip))" and ow: "?S i \ \' a" have "\dip. dip \ vD (invalidate (rt (\ i)) (dests (\ i))) \ dip \ vD (rt (\' (nhop dip))) \ nhop dip \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\' (nhop dip))" proof clarify fix dip assume "dip\vD(invalidate (rt (\ i)) (dests (\ i)))" and "dip\vD(rt (\' (nhop dip)))" and "nhop dip \ dip" from this(1) have "dip\vD (rt (\ i))" by (clarsimp dest!: vD_invalidate_vD_not_dests) moreover from ow have "\j. j \ i \ \ j = \' j" by auto ultimately have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ (nhop dip))" using pre \dip \ vD (rt (\' (nhop dip)))\ \nhop dip \ dip\ by metis with \\j. j \ i \ \ j = \' j\ show "rt (\ i) \\<^bsub>dip\<^esub> rt (\' (nhop dip))" by (metis rt_strictly_fresher_irefl) qed } note invalidate = this { fix \ a \' dip oip osn sip hops i assume pre: "\dip. dip \ vD (rt (\ i)) \ dip \ vD (rt (\ (the (nhop (rt (\ i)) dip)))) \ the (nhop (rt (\ i)) dip) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" and ow: "?S i \ \' a" and "Suc 0 \ osn" and a6: "sip \ oip \ oip \ kD (rt (\ sip)) \ osn \ nsqn (rt (\ sip)) oip \ (nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops \ the (flag (rt (\ sip)) oip) = inv)" and after: "\' i = \ i\rt := update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})\" have "\dip. dip \ vD (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) \ dip \ vD (rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip)))) \ the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip) \ dip \ update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {}) \\<^bsub>dip\<^esub> rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip)))" proof clarify fix dip assume a2: "dip\vD(update (rt (\ i)) oip (osn, kno, val, Suc (hops), sip, {}))" and a3: "dip\vD(rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip))))" and a4: "the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip) \ dip" from ow have a5: "\j. j \ i \ \ j = \' j" by auto show "update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {}) \\<^bsub>dip\<^esub> rt (\' (the (nhop (update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {})) dip)))" (is "?rt1 \\<^bsub>dip\<^esub> ?rt2 dip") proof (cases "?rt1 = rt (\ i)") assume nochange [simp]: "update (rt (\ i)) oip (osn, kno, val, Suc hops, sip, {}) = rt (\ i)" from after have "\' i = \ i" by simp with a5 have "\j. \ j = \' j" by metis from a2 have "dip\vD (rt (\ i))" by simp moreover from a3 have "dip\vD(rt (\ (the (nhop (rt (\ i)) dip))))" using nochange and \\j. \ j = \' j\ by clarsimp moreover from a4 have "the (nhop (rt (\ i)) dip) \ dip" by simp ultimately have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" using pre by simp hence "rt (\ i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\ i)) dip)))" using \\j. \ j = \' j\ by simp thus "?thesis" by simp next assume change: "?rt1 \ rt (\ i)" from after a2 have "dip\kD(rt (\' i))" by auto show ?thesis proof (cases "dip = oip") assume "dip \ oip" with a2 have "dip\vD (rt (\ i))" by auto moreover with a3 a5 after and \dip \ oip\ have "dip\vD(rt (\ (the (nhop (rt (\ i)) dip))))" by simp metis moreover from a4 and \dip \ oip\ have "the (nhop (rt (\ i)) dip) \ dip" by simp ultimately have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" using pre by simp with after and a5 and \dip \ oip\ show ?thesis by simp (metis rt_strictly_fresher_update_other rt_strictly_fresher_irefl) next assume "dip = oip" with a4 and change have "sip \ oip" by simp with a6 have "oip\kD(rt (\ sip))" and "osn \ nsqn (rt (\ sip)) oip" by auto from a3 change \dip = oip\ have "oip\vD(rt (\' sip))" by simp hence "the (flag (rt (\' sip)) oip) = val" by simp from \oip\kD(rt (\ sip))\ have "osn < nsqn (rt (\' sip)) oip \ (osn = nsqn (rt (\' sip)) oip \ the (dhops (rt (\' sip)) oip) \ hops)" proof assume "oip\vD(rt (\ sip))" hence "the (flag (rt (\ sip)) oip) = val" by simp with a6 \sip \ oip\ have "nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops" by simp show ?thesis proof (cases "sip = i") assume "sip \ i" with a5 have "\ sip = \' sip" by simp with \osn \ nsqn (rt (\ sip)) oip\ and \nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops\ show ?thesis by auto next \ \alternative to using @{text sip_not_ip}\ assume [simp]: "sip = i" have "?rt1 = rt (\ i)" proof (rule update_cases_kD, simp_all) from \Suc 0 \ osn\ show "0 < osn" by simp next from \oip\kD(rt (\ sip))\ and \sip = i\ show "oip\kD(rt (\ i))" by simp next assume "sqn (rt (\ i)) oip < osn" also from \osn \ nsqn (rt (\ sip)) oip\ have "... \ nsqn (rt (\ i)) oip" by simp also have "... \ sqn (rt (\ i)) oip" by (rule nsqn_sqn) finally have "sqn (rt (\ i)) oip < sqn (rt (\ i)) oip" . hence False by simp thus "(\a. if a = oip then Some (osn, kno, val, Suc hops, i, \\<^sub>7 (the (rt (\ i) oip))) else rt (\ i) a) = rt (\ i)" .. next assume "sqn (rt (\ i)) oip = osn" and "Suc hops < the (dhops (rt (\ i)) oip)" from this(1) and \oip \ vD (rt (\ sip))\ have "nsqn (rt (\ i)) oip = osn" by simp with \nsqn (rt (\ sip)) oip = osn \ the (dhops (rt (\ sip)) oip) \ hops\ have "the (dhops (rt (\ i)) oip) \ hops" by simp with \Suc hops < the (dhops (rt (\ i)) oip)\ have False by simp thus "(\a. if a = oip then Some (osn, kno, val, Suc hops, i, \\<^sub>7 (the (rt (\ i) oip))) else rt (\ i) a) = rt (\ i)" .. next assume "the (flag (rt (\ i)) oip) = inv" with \the (flag (rt (\ sip)) oip) = val\ have False by simp thus "(\a. if a = oip then Some (osn, kno, val, Suc hops, i, \\<^sub>7 (the (rt (\ i) oip))) else rt (\ i) a) = rt (\ i)" .. next from \oip\kD(rt (\ sip))\ show "(\a. if a = oip then Some (the (rt (\ i) oip)) else rt (\ i) a) = rt (\ i)" by (auto dest!: kD_Some) qed with change have False .. thus ?thesis .. qed next assume "oip\iD(rt (\ sip))" with \the (flag (rt (\' sip)) oip) = val\ and a5 have "sip = i" by (metis f.distinct(1) iD_flag_is_inv) from \oip\iD(rt (\ sip))\ have "the (flag (rt (\ sip)) oip) = inv" by auto with \sip = i\ \Suc 0 \ osn\ change after \oip\kD(rt (\ sip))\ have "nsqn (rt (\ sip)) oip < nsqn (rt (\' sip)) oip" unfolding update_def by (clarsimp split: option.split_asm if_split_asm) (auto simp: sqn_def) with \osn \ nsqn (rt (\ sip)) oip\ have "osn < nsqn (rt (\' sip)) oip" by simp thus ?thesis .. qed thus ?thesis proof assume osnlt: "osn < nsqn (rt (\' sip)) oip" from \dip\kD(rt (\' i))\ and \dip = oip\ have "dip \ kD (?rt1)" by simp moreover from a3 have "dip \ kD(?rt2 dip)" by simp moreover have "nsqn ?rt1 dip < nsqn (?rt2 dip) dip" proof - have "nsqn ?rt1 oip = osn" by (simp add: \dip = oip\ nsqn_update_changed_kno_val [OF change [THEN not_sym]]) also have "... < nsqn (rt (\' sip)) oip" using osnlt . also have "... = nsqn (?rt2 oip) oip" by (simp add: change) finally show ?thesis using \dip = oip\ by simp qed ultimately show ?thesis by (rule rt_strictly_fresher_ltI) next assume osneq: "osn = nsqn (rt (\' sip)) oip \ the (dhops (rt (\' sip)) oip) \ hops" have "oip\kD(?rt1)" by simp moreover from a3 \dip = oip\ have "oip\kD(?rt2 oip)" by simp moreover have "nsqn ?rt1 oip = nsqn (?rt2 oip) oip" proof - from osneq have "osn = nsqn (rt (\' sip)) oip" .. also have "osn = nsqn ?rt1 oip" by (simp add: \dip = oip\ nsqn_update_changed_kno_val [OF change [THEN not_sym]]) also have "nsqn (rt (\' sip)) oip = nsqn (?rt2 oip) oip" by (simp add: change) finally show ?thesis . qed moreover have "\\<^sub>5(the (?rt2 oip oip)) < \\<^sub>5(the (?rt1 oip))" proof - from osneq have "the (dhops (rt (\' sip)) oip) \ hops" .. moreover from \oip \ vD (rt (\' sip))\ have "oip\kD(rt (\' sip))" by auto ultimately have "\\<^sub>5(the (rt (\' sip) oip)) \ hops" by (auto simp add: proj5_eq_dhops) also from change after have "hops < \\<^sub>5(the (rt (\' i) oip))" by (simp add: proj5_eq_dhops) (metis dhops_update_changed lessI) finally have "\\<^sub>5(the (rt (\' sip) oip)) < \\<^sub>5(the (rt (\' i) oip))" . with change after show ?thesis by simp qed ultimately have "?rt1 \\<^bsub>oip\<^esub> ?rt2 oip" by (rule rt_strictly_fresher_eqI) with \dip = oip\ show ?thesis by simp qed qed qed qed } note rreq_rrep_update = this have "opaodv i \ (otherwith ((=)) {i} (orecvmsg (\\ m. msg_fresh \ m \ msg_zhops m)), other quality_increases {i} \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip. dip \ vD (rt (\ i)) \ vD (rt (\ (the (nhop (rt (\ i)) dip)))) \ the (nhop (rt (\ i)) dip) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip))))" proof (inv_cterms inv add: onl_oinvariant_sterms [OF aodv_wf rreq_sip [THEN weaken]] onl_oinvariant_sterms [OF aodv_wf rrep_sip [THEN weaken]] onl_oinvariant_sterms [OF aodv_wf rerr_sip [THEN weaken]] onl_oinvariant_sterms [OF aodv_wf oosn_rreq [THEN weaken]] onl_oinvariant_sterms [OF aodv_wf odsn_rrep [THEN weaken]] onl_oinvariant_sterms [OF aodv_wf oaddpreRT_welldefined] solve: basic update_0_unk invalidate rreq_rrep_update simp add: seqlsimp) fix \ \' p l assume or: "(\, p) \ oreachable (opaodv i) (?S i) (other quality_increases {i})" and "other quality_increases {i} \ \'" and ll: "l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" and pre: "\dip. dip\vD (rt (\ i)) \ dip\vD(rt (\ (the (nhop (rt (\ i)) dip)))) \ the (nhop (rt (\ i)) dip) \ dip \ rt (\ i) \\<^bsub>dip\<^esub> rt (\ (the (nhop (rt (\ i)) dip)))" from this(1-2) have or': "(\', p) \ oreachable (opaodv i) (?S i) (other quality_increases {i})" by - (rule oreachable_other') from or and ll have next_hop: "\dip. let nhip = the (nhop (rt (\ i)) dip) in dip \ kD(rt (\ i)) \ nhip \ dip \ dip \ kD(rt (\ nhip)) \ nsqn (rt (\ i)) dip \ nsqn (rt (\ nhip)) dip" by (auto dest!: onl_oinvariant_weakenD [OF seq_compare_next_hop']) from or and ll have unk_hops_one: "\dip\kD (rt (\ i)). sqn (rt (\ i)) dip = 0 \ sqnf (rt (\ i)) dip = unk \ the (dhops (rt (\ i)) dip) = 1 \ the (nhop (rt (\ i)) dip) = dip" by (auto dest!: onl_oinvariant_weakenD [OF ozero_seq_unk_hops_one [OF oaodv_trans aodv_trans]] otherwith_actionD simp: seqlsimp) from \other quality_increases {i} \ \'\ have "\' i = \ i" by auto hence "quality_increases (\ i) (\' i)" by auto with \other quality_increases {i} \ \'\ have "\j. quality_increases (\ j) (\' j)" by - (erule otherE, metis singleton_iff) show "\dip. dip \ vD (rt (\' i)) \ dip \ vD (rt (\' (the (nhop (rt (\' i)) dip)))) \ the (nhop (rt (\' i)) dip) \ dip \ rt (\' i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\' i)) dip)))" proof clarify fix dip assume "dip\vD(rt (\' i))" and "dip\vD(rt (\' (the (nhop (rt (\' i)) dip))))" and "the (nhop (rt (\' i)) dip) \ dip" from this(1) and \\' i = \ i\ have "dip\vD(rt (\ i))" and "dip\kD(rt (\ i))" by auto from \the (nhop (rt (\' i)) dip) \ dip\ and \\' i = \ i\ have "the (nhop (rt (\ i)) dip) \ dip" (is "?nhip \ _") by simp with \dip\kD(rt (\ i))\ and next_hop have "dip\kD(rt (\ (?nhip)))" and nsqns: "nsqn (rt (\ i)) dip \ nsqn (rt (\ ?nhip)) dip" by (auto simp: Let_def) have "0 < sqn (rt (\ i)) dip" proof (rule neq0_conv [THEN iffD1, OF notI]) assume "sqn (rt (\ i)) dip = 0" with \dip\kD(rt (\ i))\ and unk_hops_one have "?nhip = dip" by simp with \?nhip \ dip\ show False .. qed also have "... = nsqn (rt (\ i)) dip" by (rule vD_nsqn_sqn [OF \dip\vD(rt (\ i))\, THEN sym]) also have "... \ nsqn (rt (\ ?nhip)) dip" by (rule nsqns) also have "... \ sqn (rt (\ ?nhip)) dip" by (rule nsqn_sqn) finally have "0 < sqn (rt (\ ?nhip)) dip" . have "rt (\ i) \\<^bsub>dip\<^esub> rt (\' ?nhip)" proof (cases "dip\vD(rt (\ ?nhip))") assume "dip\vD(rt (\ ?nhip))" with pre \dip\vD(rt (\ i))\ and \?nhip \ dip\ have "rt (\ i) \\<^bsub>dip\<^esub> rt (\ ?nhip)" by auto moreover from \\j. quality_increases (\ j) (\' j)\ have "quality_increases (\ ?nhip) (\' ?nhip)" .. ultimately show ?thesis using \dip\kD(rt (\ ?nhip))\ by (rule strictly_fresher_quality_increases_right) next assume "dip\vD(rt (\ ?nhip))" with \dip\kD(rt (\ ?nhip))\ have "dip\iD(rt (\ ?nhip))" .. hence "the (flag (rt (\ ?nhip)) dip) = inv" by auto have "nsqn (rt (\ i)) dip \ nsqn (rt (\ ?nhip)) dip" by (rule nsqns) also from \dip\iD(rt (\ ?nhip))\ have "... = sqn (rt (\ ?nhip)) dip - 1" .. also have "... < sqn (rt (\' ?nhip)) dip" proof - from \\j. quality_increases (\ j) (\' j)\ have "quality_increases (\ ?nhip) (\' ?nhip)" .. hence "\ip. sqn (rt (\ ?nhip)) ip \ sqn (rt (\' ?nhip)) ip" by auto hence "sqn (rt (\ ?nhip)) dip \ sqn (rt (\' ?nhip)) dip" .. with \0 < sqn (rt (\ ?nhip)) dip\ show ?thesis by auto qed also have "... = nsqn (rt (\' ?nhip)) dip" proof (rule vD_nsqn_sqn [THEN sym]) from \dip\vD(rt (\' (the (nhop (rt (\' i)) dip))))\ and \\' i = \ i\ show "dip\vD(rt (\' ?nhip))" by simp qed finally have "nsqn (rt (\ i)) dip < nsqn (rt (\' ?nhip)) dip" . moreover from \dip\vD(rt (\' (the (nhop (rt (\' i)) dip))))\ and \\' i = \ i\ have "dip\kD(rt (\' ?nhip))" by auto ultimately show "rt (\ i) \\<^bsub>dip\<^esub> rt (\' ?nhip)" using \dip\kD(rt (\ i))\ by - (rule rt_strictly_fresher_ltI) qed with \\' i = \ i\ show "rt (\' i) \\<^bsub>dip\<^esub> rt (\' (the (nhop (rt (\' i)) dip)))" by simp qed qed thus ?thesis unfolding Let_def . qed lemma seq_nhop_quality_increases: shows "opaodv i \ (otherwith ((=)) {i} (orecvmsg (\\ m. msg_fresh \ m \ msg_zhops m)), other quality_increases {i} \) global (\\. \dip. let nhip = the (nhop (rt (\ i)) dip) in dip \ vD (rt (\ i)) \ vD (rt (\ nhip)) \ nhip \ dip \ (rt (\ i)) \\<^bsub>dip\<^esub> (rt (\ nhip)))" by (rule oinvariant_weakenE [OF seq_nhop_quality_increases']) (auto dest!: onlD) end