Theory Predicate_Compile

Up to index of Isabelle/HOL/ex

theory Predicate_Compile
imports Complex_Main Code_Index Lattice_Syntax
uses predicate_compile.ML

theory Predicate_Compile
imports Complex_Main Code_Index Lattice_Syntax
uses "predicate_compile.ML"
begin

setup {* Predicate_Compile.setup *}

primrec "next" :: "('a Predicate.pred => ('a × 'a Predicate.pred) option)
  => 'a Predicate.seq => ('a × 'a Predicate.pred) option" where
    "next yield Predicate.Empty = None"
  | "next yield (Predicate.Insert x P) = Some (x, P)"
  | "next yield (Predicate.Join P xq) = (case yield P
   of None => next yield xq | Some (x, Q) => Some (x, Predicate.Seq (λ_. Predicate.Join Q xq)))"

ML {*
let
  fun yield (@{code Predicate.Seq} f) = @{code next} yield (f ())
in
  yield @{code "⊥ :: 'a Predicate.pred"} (*replace bottom with sequence to evaluate*)
end
*}

fun anamorph :: "('b => ('a × 'b) option) => index => 'b => 'a list × 'b" where
  "anamorph f k x = (if k = 0 then ([], x)
    else case f x of None => ([], x) | Some (v, y) => let (vs, z) = anamorph f (k - 1) y in (v # vs, z))"

ML {*
let
  fun yield (@{code Predicate.Seq} f) = @{code next} yield (f ())
  fun yieldn k = @{code anamorph} yield k
in
  yieldn 0 (*replace with number of elements to retrieve*)
    @{code "⊥ :: 'a Predicate.pred"} (*replace bottom with sequence to evaluate*)
end
*}

end