theory Finalise_R

lemma m_next:
  "m p = Some (CTE cap node) \<Longrightarrow>
  \<exists>cap' node'. n p = Some (CTE cap' node') \<and>
              (if p = slot
               then mdbNext node' = 0
               else if p = mdbPrev s_node
               then mdbNext node' = mdbNext s_node
               else mdbNext node' = mdbNext node)" apply (subgoal_tac "p \<noteq> 0") prefer 2 apply clarsimp apply (cases "p = slot") apply (clarsimp simp: n_def modify_map_if) apply (cases "p = mdbPrev s_node") apply (simp add: n_def modify_map_if) apply simp apply (simp add: n_def modify_map_if) apply (cases "mdbNext s_node = p") apply fastforce apply fastforce done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. m p = Some (CTE cap node) \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (2 subgoals):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node)
 2. m p = Some (CTE cap node) \<Longrightarrow> p \<noteq> 0 proof (prove)
goal (2 subgoals):
 1. m p = Some (CTE cap node) \<Longrightarrow> p \<noteq> 0
 2. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (2 subgoals):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p = slot\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node)
 2. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (2 subgoals):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p = mdbPrev s_node\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node)
 2. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> (if p = slot then mdbNext node' = 0 else if p = mdbPrev s_node then mdbNext node' = mdbNext s_node else mdbNext node' = mdbNext node) proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node\<rbrakk> \<Longrightarrow> \<exists>cap' node'. n p = Some (CTE cap' node') \<and> mdbNext node' = mdbNext node proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node\<rbrakk> \<Longrightarrow> \<exists>cap' node'. (mdbNext s_node = p \<longrightarrow> cap = cap' \<and> mdbFirstBadged_update (\<lambda>_. mdbFirstBadged node \<or> mdbFirstBadged s_node) (mdbPrev_update (\<lambda>_. mdbPrev s_node) node) = node' \<and> mdbNext node' = mdbNext node) \<and> (mdbNext s_node \<noteq> p \<longrightarrow> cap' = cap \<and> node' = node \<and> mdbNext node' = mdbNext node) proof (prove)
goal (2 subgoals):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node; mdbNext s_node = p\<rbrakk> \<Longrightarrow> \<exists>cap' node'. (mdbNext s_node = p \<longrightarrow> cap = cap' \<and> mdbFirstBadged_update (\<lambda>_. mdbFirstBadged node \<or> mdbFirstBadged s_node) (mdbPrev_update (\<lambda>_. mdbPrev s_node) node) = node' \<and> mdbNext node' = mdbNext node) \<and> (mdbNext s_node \<noteq> p \<longrightarrow> cap' = cap \<and> node' = node \<and> mdbNext node' = mdbNext node)
 2. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node; mdbNext s_node \<noteq> p\<rbrakk> \<Longrightarrow> \<exists>cap' node'. (mdbNext s_node = p \<longrightarrow> cap = cap' \<and> mdbFirstBadged_update (\<lambda>_. mdbFirstBadged node \<or> mdbFirstBadged s_node) (mdbPrev_update (\<lambda>_. mdbPrev s_node) node) = node' \<and> mdbNext node' = mdbNext node) \<and> (mdbNext s_node \<noteq> p \<longrightarrow> cap' = cap \<and> node' = node \<and> mdbNext node' = mdbNext node) proof (prove)
goal (1 subgoal):
 1. \<lbrakk>m p = Some (CTE cap node); p \<noteq> 0; p \<noteq> slot; p \<noteq> mdbPrev s_node; mdbNext s_node \<noteq> p\<rbrakk> \<Longrightarrow> \<exists>cap' node'. (mdbNext s_node = p \<longrightarrow> cap = cap' \<and> mdbFirstBadged_update (\<lambda>_. mdbFirstBadged node \<or> mdbFirstBadged s_node) (mdbPrev_update (\<lambda>_. mdbPrev s_node) node) = node' \<and> mdbNext node' = mdbNext node) \<and> (mdbNext s_node \<noteq> p \<longrightarrow> cap' = cap \<and> node' = node \<and> mdbNext node' = mdbNext node) proof (prove)
goal:
No subgoals!