Theory Computability

section ‹Generic Computability›

theory Computability
imports HOLCF HOLCFUtils
begin

text ‹
Shivers proves the computability of the abstract semantics functions only by generic and slightly simplified example. This theory contains the abstract treatment in Section 4.4.3. Later, we will work out the details apply this to \<aPR>›.
›

subsection ‹Non-branching case›

text ‹

After the following lemma (which could go into @{theory HOL.Set_Interval}), we show Shivers' Theorem 10. This says that the least fixed point of the equation
\[
f\ x = g\ x \cup f\ (r\ x)
\]
is given by 
\[
f\ x = \bigcup_{i\ge 0} g\ (r^i\ x).
\]

The proof follows the standard proof of showing an equality involving a fixed point: First we show that the right hand side fulfills the above equation and then show that our solution is less than any other solution to that equation.
›

lemma insert_greaterThan:
  "insert (n::nat) {n<..} = {n..}"
by auto

lemma theorem10:
  fixes g :: "'a::cpo  'b::type set" and r :: "'a  'a"
  shows "fix(Λ f x. gx  f(rx)) = (Λ x. (i. g(rix)))"
proof(induct rule:fix_eqI[OF cfun_eqI cfun_belowI, case_names fp least])
case (fp x)
  have "gx  (i. g(ri(rx))) = g(r0x)  (i. g(rSuc ix))"
    by (simp add: iterate_Suc2 del: iterate_Suc)
  also have " = g(r0x)  (i{0<..}. g(rix))"
    using less_iff_Suc_add by auto
  also have "  = (iinsert 0 {0<..}. g(rix))"
    by simp
  also have "... = (i. g(rix))"
    by (simp only: insert_greaterThan atLeast_0 )
  finally
  show ?case by auto
next
case (least f x)
  hence expand: "x. fx = (gx  f(rx))" by (auto simp:cfun_eq_iff)
  { fix n
    have "fx = (i{..n}. g(rix))  f(rSuc nx)"
    proof(induct n)
      case 0 thus ?case by (auto simp add:expand[of x])
      case (Suc n)
      then have "fx = (i{..n}. g(rix))  f(rSuc nx)" by simp
      also have " = (i{..n}. g(rix))
                  g(rSuc nx)  f(rSuc (Suc n)x)"
             by(subst expand[of "rSuc nx"], auto)
      also have " = (iinsert (Suc n) {..n}. g(rix))  f(rSuc (Suc n)x)"
             by auto
      also have " = (i{..Suc n}. g(rix))  f(rSuc (Suc n)x)"
             by (simp add:atMost_Suc)
      finally show ?case .
    qed
  } note fin = this
  have "(i. g(rix))  fx"
    proof(rule UN_least)
      fix i
      show "g(rix)  fx"
      using fin[of i] by auto
    qed
  thus ?case
    apply (subst sqsubset_is_subset) by auto
qed

subsection ‹Branching case›

text ‹
Actually, our functions are more complicated than the one above: The abstract semantics functions recurse with multiple arguments. So we have to handle a recursive equation of the kind
\[
f\ x = g\ x \cup \bigcup_{a \in R\ x} f\ r.
\]
By moving to the power-set relatives of our function, e.g.
\[
{\uline g}Y = \bigcup_{a\in A} g\ a \quad \text{and} {\uline R}Y = \bigcup_{a\in R} R\ a
\]
the equation becomes
\[
{\uline f}Y ={\uline g}Y \cup {\uline f}\ ({\uline R}Y)
\]
(which is shown in Lemma 11) and we can apply Theorem 10 to obtain Theorem 12.

We define the power-set relative for a function together with some properties.
›

definition powerset_lift :: "('a::cpo  'b::type set)  'a set  'b set" ("ps")
  where "psf = (Λ S. (yS . fy))"

lemma powerset_lift_singleton[simp]:
  "psf{x} = fx"
unfolding powerset_lift_def by simp

lemma powerset_lift_union[simp]:
  "psf(A  B) = psfA  psfB"
unfolding powerset_lift_def by auto

lemma UNION_commute:"(xA. yB . P x y) = (yB. xA . P x y)"
  by auto

lemma powerset_lift_UNION:
  "(xS. psg(A x)) = psg(xS. A x)"
unfolding powerset_lift_def by auto

lemma powerset_lift_iterate_UNION:
  "(xS. (psg)i(A x)) = (psg)i(xS. A x)"
by (induct i, auto simp add:powerset_lift_UNION)

lemmas powerset_distr = powerset_lift_UNION powerset_lift_iterate_UNION


text ‹
Lemma 11 shows that if a function satisfies the relation with the branching $R$, its power-set function satisfies the powerset variant of the equation.

›

lemma lemma11:
  fixes f :: "'a  'b set" and g :: "'a  'b set" and R :: "'a  'a set"
  assumes "x. fx = gx  (yRx. fy)"
  shows "psfS = psgS  psf(psRS)"
proof-
  have "psfS = (xS . fx)" unfolding powerset_lift_def by auto
  also have " = (xS . gx  (yRx. fy))" apply (subst assms) by simp
  also have " = psgS  psf(psRS)" by (auto simp add:powerset_lift_def)
  finally
  show ?thesis .
qed

text ‹
Theorem 10 as it will be used in Theorem 12.
›
lemmas theorem10ps = theorem10[of "psg" "psr"] for g r

text ‹
Now we can show Lemma 12: If $F$ is the least solution to the recursive power-set equation, then $x \mapsto F\ {x}$ is the least solution to the equation with branching $R$.

We fix the type variable 'a› to be a discrete cpo, as otherwise $x \mapsto \{x\}$ is not continuous.
›

(* discrete_cpo, otherwise x ↦ {x} not continuous *)
lemma theorem12':
  fixes g :: "'a::discrete_cpo  'b::type set" and R :: "'a  'a set"
  assumes F_fix: "F = fix(Λ F x. psgx  F(psRx))"
  shows "fix(Λ f x. gx  (yRx. fy)) = (Λ x. F{x})"
proof(induct rule:fix_eqI[OF cfun_eqI cfun_belowI, case_names fp least])
have F_union: "F = (Λ x. i. psg((psR)ix))"
  using F_fix by(simp)(rule theorem10ps)
case (fp x)
   have "gx  (x'Rx. F{x'}) = psg{x}  F(psR{x})"
    unfolding powerset_lift_singleton
    by (auto simp add: powerset_distr UNION_commute F_union)
  also have " = F{x}"
    by (subst (2) fix_eq4[OF F_fix], auto)
  finally show ?case by simp
next
case (least f' x)
  hence expand: "f' = (Λ x. gx  (yRx. f'y))" by simp
  have "psf' = (Λ S. psgS  psf'(psRS))"
    by (subst expand, rule cfun_eqI, auto simp add:powerset_lift_def)
  hence "(Λ F. Λ x. psgx  F(psRx))(psf') = psf'" by simp
  from fix_least[OF this] and F_fix
  have  "F  psf'"  by simp
  hence  "F{x}  psf'{x}"
    by (subst (asm)cfun_below_iff, auto simp del:powerset_lift_singleton)
  thus ?case by (auto simp add:sqsubset_is_subset)
qed

lemma theorem12:
  fixes g :: "'a::discrete_cpo  'b::type set" and R :: "'a  'a set"
  shows "fix(Λ f x. gx  (yRx. fy))x =  psg(i.((psR)i{x}))"
  by(subst theorem12'[OF theorem10ps[THEN sym]], auto simp add:powerset_distr)

end