Skip to content

Commit 402eeb5

Browse files
committed
Add SFun module
1 parent 7a56dee commit 402eeb5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{-# OPTIONS --safe #-}
2+
module CategoricalCrypto.SFun where
3+
4+
open import Level renaming (zero to ℓ0)
5+
6+
open import abstract-set-theory.Prelude hiding (id; _∘_; _⊗_; lookup; Dec; ⊤; ⊥; Functor; Bifunctor; [_]; head; tail; _++_; take)
7+
import abstract-set-theory.Prelude as P
8+
open import Data.Vec hiding (init)
9+
open import Data.Nat using (_+_)
10+
11+
-- M = id, Maybe, Powerset (relation), Giry (probability)
12+
-- SFunType A B S = S × A → M (S × B)
13+
SFunType : Type Type Type Type
14+
SFunType A B S = S × A S × B
15+
16+
-- explicit state
17+
record SFunᵉ (A B : Type) : Type₁ where
18+
field
19+
State : Type
20+
init : State
21+
fun : SFunType A B State
22+
23+
private variable A B C D State : Type
24+
m n :
25+
26+
trace : SFunType A B State State Vec A n Vec B n
27+
trace f s [] = []
28+
trace f s (a ∷ as) = let (s , b) = f (s , a) in b ∷ trace f s as
29+
30+
take-trace : {f : SFunType A B State} {s} {as : Vec A (n + m)}
31+
take n (trace f s as) ≡ trace f s (take n as)
32+
take-trace {n = zero} = refl
33+
take-trace {n = suc _} {as = _ ∷ _} = cong (_ ∷_) take-trace
34+
35+
-- implicit state
36+
record SFunⁱ (A B : Type) : Type where
37+
field
38+
fun : Vec A n Vec B n
39+
take-fun : {as : Vec A (m + n)} take m (fun as) ≡ fun (take m as)
40+
41+
fun₁ : A B
42+
fun₁ a = head (fun [ a ])
43+
44+
-- the function on traces after making one fixed step
45+
apply₁ : A SFunⁱ A B
46+
apply₁ a = record { fun = λ as tail (fun (a ∷ as)) ; take-fun = {!!} }
47+
48+
eval : SFunᵉ A B SFunⁱ A B
49+
eval f = let open SFunᵉ f in record { fun = trace fun init ; take-fun = take-trace }
50+
51+
resume : SFunⁱ A B SFunᵉ A B
52+
resume f = record
53+
{ init = f
54+
; fun = λ where (g , a) SFunⁱ.apply₁ g a , SFunⁱ.fun₁ g a
55+
}
56+
57+
_≈ⁱ_ : SFunⁱ A B SFunⁱ A B Type
58+
f ≈ⁱ g = let open SFunⁱ in {n} fun f {n} ≗ fun g {n}
59+
60+
open SFunⁱ
61+
≈ⁱ-ind : {f g : SFunⁱ A B} a fun₁ f a ≡ fun₁ g a apply₁ f a ≈ⁱ apply₁ g a f ≈ⁱ g
62+
≈ⁱ-ind = {!!}
63+
64+
_≈ᵉ_ : SFunᵉ A B SFunᵉ A B Type
65+
f ≈ᵉ g = eval f ≈ⁱ eval g
66+
67+
resume∘eval≡id : {f : SFunᵉ A B} resume (eval f) ≈ᵉ f
68+
resume∘eval≡id {f = f} {n} as = {!!}

0 commit comments

Comments
 (0)