src/HOL/Corec_Examples/Tests/GPV_Bare_Bones.thy
author wenzelm
Fri, 18 Aug 2017 20:47:47 +0200
changeset 66453 cc19f7ca2ed6
parent 62858 d72a6f9ee690
child 67399 eab6ce8368fa
permissions -rw-r--r--
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62858
d72a6f9ee690 tuned headers;
wenzelm
parents: 62726
diff changeset
     1
(*  Title:      HOL/Corec_Examples/Tests/GPV_Bare_Bones.thy
62696
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     2
    Author:     Andreas Lochbihler, ETH Zuerich
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     3
    Author:     Jasmin Blanchette, Inria, LORIA, MPII
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     4
    Copyright   2016
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     5
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     6
A bare bones version of generative probabilistic values (GPVs).
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     7
*)
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
     8
62726
5b2a7caa855b tuned examples
blanchet
parents: 62696
diff changeset
     9
section \<open>A Bare Bones Version of Generative Probabilistic Values (GPVs)\<close>
62696
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    10
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    11
theory GPV_Bare_Bones
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 62858
diff changeset
    12
imports "HOL-Library.BNF_Corec"
62696
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    13
begin
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    14
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    15
datatype 'a pmf = return_pmf 'a
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    16
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    17
type_synonym 'a spmf = "'a option pmf"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    18
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    19
abbreviation map_spmf :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a spmf \<Rightarrow> 'b spmf"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    20
where "map_spmf f \<equiv> map_pmf (map_option f)"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    21
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    22
abbreviation return_spmf :: "'a \<Rightarrow> 'a spmf"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    23
where "return_spmf x \<equiv> return_pmf (Some x)"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    24
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    25
datatype (generat_pures: 'a, generat_outs: 'b, generat_conts: 'c) generat =
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    26
  Pure (result: 'a)
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    27
| IO ("output": 'b) (continuation: "'c")
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    28
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    29
codatatype (results'_gpv: 'a, outs'_gpv: 'out, 'in) gpv =
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    30
  GPV (the_gpv: "('a, 'out, 'in \<Rightarrow> ('a, 'out, 'in) gpv) generat spmf")
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    31
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    32
codatatype ('a, 'call, 'ret, 'x) gpv' =
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    33
  GPV' (the_gpv': "('a, 'call, 'ret \<Rightarrow> ('a, 'call, 'ret, 'x) gpv') generat spmf")
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    34
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    35
consts bind_gpv' :: "('a, 'call, 'ret) gpv \<Rightarrow> ('a \<Rightarrow> ('b, 'call, 'ret, 'a) gpv') \<Rightarrow> ('b, 'call, 'ret, 'a) gpv'"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    36
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    37
definition bind_spmf :: "'a spmf \<Rightarrow> ('a \<Rightarrow> 'b spmf) \<Rightarrow> 'b spmf"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    38
where "bind_spmf x f = undefined x (\<lambda>a. case a of None \<Rightarrow> return_pmf None | Some a' \<Rightarrow> f a')"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    39
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    40
friend_of_corec bind_gpv'
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    41
where "bind_gpv' r f =
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    42
GPV' (map_spmf (map_generat id id (op \<circ> (case_sum id (\<lambda>r. bind_gpv' r f))))
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    43
      (bind_spmf (the_gpv r)
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    44
        (case_generat (\<lambda>x. map_spmf (map_generat id id (op \<circ> Inl)) (the_gpv' (f x)))
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    45
          (\<lambda>out c. return_spmf (IO out (\<lambda>input. Inr (c input)))))))"
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    46
  sorry
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    47
7325d8573fb8 added 'corec' examples and tests
blanchet
parents:
diff changeset
    48
end