section‹Functional interpretation for the abstract implementation› theory Middle_Impl imports Abstract_Impl Pointer_Map begin
text‹For the lack of a better name, the suffix mi stands for middle-implementation.
relects that this ``implementation'' is neither entirely abstract,
has it been made fully concrete: the data structures are decided, but not their implementations.›
lemma prod_split3: "P (case p of (x, xa, xaa) ==> f x xa xaa) = (∀x1 x2 x3. p = (x1, x2, x3) ⟶ P (f x1 x2 x3))" by(simp split: prod.splits)
lemma IfI: "(c ==> P x) ==> (¬c ==> P y) ==> P (if c then x else y)"by simp lemma fstsndI: "x = (a,b) ==> fst x = a ∧ snd x = b"by simp thm nat.split lemma Rmi_g_2_split: "P (Rmi_g n x m) = ((x = Falseif ⟶ P (Rmi_g n x m)) ∧ (x = Trueif ⟶ P (Rmi_g n x m)) ∧ (∀vs ts es. x = IF vs ts es ⟶ P (Rmi_g n x m)))" by(cases x;simp)
lemma rmigeq: "Rmi_g ni1 n1 s ==> Rmi_g ni2 n2 s ==> ni1 = ni2 ==> n1 = n2" proof(induction ni1 n1 s arbitrary: n2 ni2 rule: Rmi_g.induct, goal_cases) case (3 n v t e bdd n2 ni2) note goal3 = 3 note1 = goal3(1,2) have2: "Rmi_g (fst (snd (pm_pth (dpm bdd) n))) t bdd""Rmi_g (snd (snd (pm_pth (dpm bdd) n))) e bdd"using goal3(3) by(clarsimp)+ note mIH = 1(1)[OF _ _ 2(1) _ refl] 1(2)[OF _ _ 2(2) _ refl] obtain v2 t2 e2 where v2: "n2 = IF v2 t2 e2"using Rmi_g.simps(4,6) goal3(3-5) by(cases n2) blast+ thus ?caseusing goal3(3-4) by(clarsimp simp add: v2 goal3(5)[symmetric] mIH) qed (rename_tac n2 ni2, (case_tac n2; clarsimp))+
lemma rmigneq: "bdd_sane s ==> Rmi_g ni1 n1 s ==> Rmi_g ni2 n2 s ==> ni1 ≠ ni2 ==> n1 ≠ n2" proof(induction ni1 n1 s arbitrary: n2 ni2 rule: Rmi_g.induct, goal_cases) case1thus ?caseby (metis Rmi_g.simps(6) old.nat.exhaust) next case2thus ?caseby (metis Rmi_g.simps(4,8) old.nat.exhaust) next case (3 n v t e bdd n2 ni2) note goal3 = 3 let ?bddpth = "pm_pth (dpm bdd)" note1 = goal3(1,2)[OF prod.collapse prod.collapse] have2: "Rmi_g (fst (snd (?bddpth n))) t bdd""Rmi_g (snd (snd (?bddpth n))) e bdd"using goal3(4) by(clarsimp)+ note mIH = 1(1)[OF goal3(3) 2(1)] 1(2)[OF goal3(3) 2(2)] show ?caseproof(cases "0 < ni2", case_tac "1 < ni2") case False hence e: "ni2 = 0"by simp with goal3(5) have"n2 = Falseif"using rmigeq by auto (* honestly, I'm puzzled how this works\<dots> *) thus ?thesis by simp next case True moreoverassume3: "¬ 1 < ni2" ultimatelyhave"ni2 = 1"by simp with goal3(5) have"n2 = Trueif"using rmigeq by auto thus ?thesis by simp next assume3: "1 < ni2" thenobtain ni2s where [simp]: "ni2 = Suc (Suc ni2s)"unfolding One_nat_def using less_imp_Suc_add by blast obtain v2 t2 e2 where v2[simp]: "n2 = IF v2 t2 e2"using goal3(5) by(cases "(ni2, n2, bdd)" rule: Rmi_g.cases) clarsimp+ have4: "Rmi_g (fst (snd (?bddpth ni2s))) t2 bdd""Rmi_g (snd (snd (?bddpth ni2s))) e2 bdd"using goal3(5) by clarsimp+ show ?caseunfolding v2 proof(cases "fst (snd (?bddpth n)) = fst (snd (?bddpth ni2s))",
case_tac "snd (snd (?bddpth n)) = snd (snd (?bddpth ni2s))",
case_tac "v = v2") have ne: "ni2s ≠ n"using goal3(6) by simp have ib: "pointermap_p_valid n (dpm bdd)""pointermap_p_valid ni2s (dpm bdd)"using Rmi_g.simps(3) goal3(4,5) by simp_all assume goal1: "fst (snd (pm_pth (dpm bdd) n)) = fst (snd (pm_pth (dpm bdd) ni2s))" "snd (snd (pm_pth (dpm bdd) n)) = snd (snd (pm_pth (dpm bdd) ni2s))" "v = v2" hence"?bddpth n = ?bddpth ni2s"unfolding prod_eq_iff using goal3(4) goal3(5) by auto with goal3(3) ne have False unfolding bdd_sane_def using pth_eq_iff_index_eq[OF _ ib] by simp thus"IF v t e ≠ IF v2 t2 e2" .. qed (simp_all add: mIH(1)[OF 4(1)] mIH(2)[OF 4(2)]) qed qed simp_all
lemma ifmi_les_hlp: "pointermap_sane (dpm s) ==> pointermap_getmk (v, ni1, ni2) (dpm s) = (x1, dpm s') ==> Rmi_g nia n s ==> Rmi_g nia n s'" proof(induction nia n s rule: Rmi_g.induct, goal_cases) case (3 n v t e bdd) note goal3 = 3 obtain x1a x2a where pth[simp]: "pm_pth (dpm bdd) n = (v, x1a, x2a)"using goal3(5) by force have pth'[simp]: "pm_pth (dpm s') n = (v, x1a, x2a)"unfolding pth[symmetric] using goal3(4,5) by (meson Rmi_g.simps(3) pointermap_p_pth_inv) note mIH = goal3(1,2)[OF pth[symmetric] refl goal3(3,4)] from goal3(5) show ?case unfolding Rmi_g.simps using pointermap_p_valid_inv[OF _ goal3(4)] mIH by(simp split: prod.splits) qed simp_all lemma ifmi_les: assumes"bdd_sane s" assumes"ifmi v ni1 ni2 s = (ni, s')" shows"mi_pre.les s s'" using assms by(clarsimp simp: bdd_sane_def comp_def apfst_def map_prod_def mi_pre.les_def Rmi_def ifmi_les_hlp split: if_splits prod.splits)
lemma ifmi_notouch_dcl: "ifmi v ni1 ni2 s = (ni, s') ==> dcl s' = dcl s" by(clarsimp split: if_splits prod.splits)
lemma ifmi_modification_validI: assumes sane: "bdd_sane s" assumes ifm: "ifmi v ni1 ni2 s = (ni, s')" assumes vld: "bdd_node_valid s n" shows"bdd_node_valid s' n" proof(cases "ni1 = ni2") case True with ifm vld show ?thesis by simp next case False
{ fix b from ifm have"(n, b) ∈ Rmi s ==> (n, b) ∈ Rmi s'" by(induction n b _ rule: Rmi_g.induct) (auto dest: pointermap_p_pth_inv pointermap_p_valid_inv simp: apfst_def map_prod_def False Rmi_def split: prod.splits)
} thus ?thesis using vld unfolding bdd_node_valid_def by blast qed
definition"tmi' s ≡ do {oassert (bdd_sane s); Some (tmi s)}" definition"fmi' s ≡ do {oassert (bdd_sane s); Some (fmi s)}" definition"ifmi' v ni1 ni2 s ≡ do {oassert (bdd_sane s ∧ bdd_node_valid s ni1 ∧bdd_node_valid s ni2); Some (ifmi v ni1 ni2 s)}"
lemma ifmi'_spec: "[bdd_sane s; bdd_node_valid s ni1; bdd_node_valid s ni2]==> ospec (ifmi' v ni1 ni2 s) (λr. r = ifmi v ni1 ni2 s)" unfolding ifmi'_defby(simp split: Option.bind_splits) lemma ifmi'_ifmi: "[bdd_sane s; bdd_node_valid s ni1; bdd_node_valid s ni2]==> ifmi' v ni1 ni2 s = Some (ifmi v ni1 ni2 s)" unfolding ifmi'_defby(simp split: Option.bind_splits)
definition"destrmi' ni s ≡ do {oassert (bdd_sane s ∧ bdd_node_valid s ni); Some (destrmi ni s)}"
lemma destrmi_someD: "destrmi' e bdd = Some x ==> bdd_sane bdd ∧ bdd_node_valid bdd e" by(simp add: destrmi'_def split: Option.bind_splits)
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.