Skip to content

Commit 8b9b009

Browse files
committed
Add SFun module
1 parent 7a56dee commit 8b9b009

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
25+
trace : {n} SFunType A B State State Vec A n Vec B n
26+
trace f s [] = []
27+
trace f s (a ∷ as) = let (s , b) = f (s , a) in b ∷ trace f s as
28+
29+
take-trace : {f : SFunType A B State} {s m n} {as : Vec A (n + m)}
30+
take n (trace f s as) ≡ trace f s (take n as)
31+
take-trace {n = zero} = refl
32+
take-trace {n = suc _} {_ ∷ _} = cong (_ ∷_) take-trace
33+
34+
-- implicit state
35+
record SFunⁱ (A B : Type) : Type where
36+
field
37+
fun : {n} Vec A n Vec B n
38+
take-fun : {m n} {as : Vec A (m + n)} take m (fun as) ≡ fun (take m as)
39+
40+
fun₁ : A B
41+
fun₁ a = head (fun [ a ])
42+
43+
-- the function on traces after making one fixed step
44+
apply₁ : A SFunⁱ A B
45+
apply₁ a = record { fun = λ as tail (fun (a ∷ as)) ; take-fun = {!!} }
46+
47+
eval : SFunᵉ A B SFunⁱ A B
48+
eval f = let open SFunᵉ f in record { fun = trace fun init ; take-fun = take-trace }
49+
50+
resume : SFunⁱ A B SFunᵉ A B
51+
resume f = record
52+
{ init = f
53+
; fun = λ where (g , a) SFunⁱ.apply₁ g a , SFunⁱ.fun₁ g a
54+
}
55+
56+
_≈ⁱ_ : SFunⁱ A B SFunⁱ A B Type
57+
f ≈ⁱ g = let open SFunⁱ in {n} fun f {n} ≗ fun g {n}
58+
59+
open SFunⁱ
60+
≈ⁱ-ind : {f g : SFunⁱ A B} a fun₁ f a ≡ fun₁ g a apply₁ f a ≈ⁱ apply₁ g a f ≈ⁱ g
61+
≈ⁱ-ind = {!!}
62+
63+
_≈ᵉ_ : SFunᵉ A B SFunᵉ A B Type
64+
f ≈ᵉ g = eval f ≈ⁱ eval g
65+
66+
resume∘eval≡id : {f : SFunᵉ A B} resume (eval f) ≈ᵉ f
67+
resume∘eval≡id {f = f} {n} as = {!!}

0 commit comments

Comments
 (0)