Theory Basics_side
theory Basics_side
imports Main "HOL-Library.Finite_Map"
begin
unbundle lattice_syntax
subsection ‹Auxiliary Lemmas for Default Maps›
text‹The solver maintains a solver state to implement optimizations based on self-observation.
Among the data structures for the solver state are maps that return a default value for
non-existing keys. In the following, we define some helper functions and lemmas for these.›
definition fmlookup_default where
"fmlookup_default m d x = (case fmlookup m x of Some v ⇒ v | None ⇒ d)"
abbreviation slookup where
"slookup infl x ≡ set (fmlookup_default infl [] x)"
definition mlup where
"mlup σ x ≡ case σ x of Some v ⇒ v | None ⇒ ⊥"
definition fminsert where
"fminsert infl x y = fmupd x (y # (fmlookup_default infl [] x)) infl"
lemma set_fmlookup_default_cases:
assumes "y ∈ slookup infl x"
obtains (1) xs where "fmlookup infl x = Some xs" and "y ∈ set xs"
using assms that unfolding fmlookup_default_def
by (cases "fmlookup infl x"; auto)
lemma notin_fmlookup_default_cases:
assumes "y ∉ slookup infl x"
obtains (1) xs where "fmlookup infl x = Some xs" and "y ∉ set xs"
| (2) "fmlookup infl x = None"
using assms that unfolding fmlookup_default_def
by (cases "fmlookup infl x"; auto)
lemma slookup_helper[simp]:
assumes "fmlookup m x = Some ys"
and "y ∈ set ys"
shows "y ∈ slookup m x"
using assms(1,2) notin_fmlookup_default_cases by force
lemma lookup_implies_mlup:
assumes "σ x = σ' x'"
shows "mlup σ x = mlup σ' x'"
using assms
unfolding mlup_def fmlookup_default_def
by auto
lemma fmlookup_fminsert:
assumes "fmlookup_default infl [] x = xs"
shows "fmlookup (fminsert infl x y) x = Some (y # xs)"
proof(cases "fmlookup infl x")
case None
then show ?thesis using assms unfolding fmlookup_default_def fminsert_def by auto
next
case (Some a)
then show ?thesis using assms unfolding fmlookup_default_def fminsert_def by auto
qed
lemma fmlookup_fminsert':
obtains xs ys
where "fmlookup (fminsert infl x y) x = Some xs"
and "fmlookup_default infl [] x = ys" and "xs = y # ys"
using that fmlookup_fminsert
by fastforce
lemma fmlookup_default_drop_set:
"fmlookup_default (fmdrop_set A m) [] x = (if x ∉ A then fmlookup_default m [] x else [])"
by (simp add: fmlookup_default_def)
lemma mlup_eq_mupd_set:
assumes "x ∉ s"
and "∀y∈s. mlup σ y = mlup σ' y"
shows "∀y∈s. mlup σ y = mlup (σ'(x ↦ xd)) y"
using assms
by (simp add: mlup_def)
lemma slookup_fminsert_other: "z ≠ x ⟹ slookup (fminsert infl1 x y) z = slookup infl1 z"
unfolding fminsert_def fmlookup_default_def by auto
lemma slookup_fminsert_same: "slookup (fminsert infl1 x y) x = slookup infl1 x ∪ {y}"
unfolding fminsert_def fmlookup_default_def by auto
lemma slookup_fminsert: "slookup (fminsert infl x y) z =
(if x = z then slookup infl x ∪ {y} else slookup infl z)"
unfolding fminsert_def fmlookup_default_def by auto
subsection ‹Definitions for Strategy Trees with Side Effects›