{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE RecursiveDo #-}
module Proarrow.Tools.SMC.Examples
( swapT
, applyT
, curryT
, rotT
, traceT
, loopT
, loopCC
, snakeT
, combineDualT
, distT
, swapEitherT
, bothWaysT
, dniT
, dneT
, bindT
, contraT
, parSwapT
, weakDistT
, matMulT
, traceIdxT
, hadamardT
, snakeDualT
) where
import Proarrow.Category.Monoidal (Monoidal (..), SymMonoidal)
import Proarrow.Category.Monoidal.Closed (Closed (..))
import Proarrow.Category.Monoidal.CompactClosed (CompactClosed (..))
import Proarrow.Category.Monoidal.Dialogue (Dialogue (..), Par)
import Proarrow.Category.Monoidal.Distributive (Distributive (..))
import Proarrow.Category.Monoidal.Hypergraph (Frobenius)
import Proarrow.Category.Monoidal.StarAutonomous (StarAutonomous (..))
import Proarrow.Category.Monoidal.Strength (TracedMonoidal)
import Proarrow.Colimit.BinaryCoproduct (HasBinaryCoproducts (..))
import Proarrow.Core (CategoryOf (..))
import Proarrow.Limit.BinaryProduct (HasBinaryProducts (..))
import Proarrow.Tools.SMC
import Proarrow.Tools.SMC qualified as SMC
swapT :: forall {k} (a :: k) b. (SymMonoidal k, Ob a, Ob b) => a ** b ~> b ** a
swapT :: forall {k} (a :: k) (b :: k).
(SymMonoidal k, Ob a, Ob b) =>
(a ** b) ~> (b ** a)
swapT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :** F b) \(TermP (~>) 3 '[ '(1, F a)] (F a)
a, TermP
(~>)
(1 + (2 + PSize (TermP (~>) 3 '[ '(1, F a)] (F a))))
'[ '(2, F b)]
(F b)
b) -> (TermP
(~>)
(1 + (2 + PSize (TermP (~>) 3 '[ '(1, F a)] (F a))))
'[ '(2, F b)]
(F b)
b, TermP (~>) 3 '[ '(1, F a)] (F a)
a)
applyT :: forall {k} (a :: k) b. (Closed k, SymMonoidal k, Ob a, Ob b) => (a ~~> b) ** a ~> b
applyT :: forall {k} (a :: k) (b :: k).
(Closed k, SymMonoidal k, Ob a, Ob b) =>
((a ~~> b) ** a) ~> b
applyT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @((F a :-> F b) :** F a) (\TermP
(~>) 1 '[ '(0, (F a :-> F b) :** F a)] ((F a :-> F b) :** F a)
p -> TermP
(~>) 1 '[ '(0, (F a :-> F b) :** F a)] ((F a :-> F b) :** F a)
-> (TermP (~>) 3 '[ '(1, F a :-> F b)] (F a :-> F b)
-> TermP (~>) 3 '[ '(1 + 1, F a)] (F a)
-> TermP
(~>) (1 + 2) (Union '[ '(1, F a :-> F b)] '[ '(2, F a)]) (F b))
-> TermP (~>) 1 (Union '[] '[ '(0, (F a :-> F b) :** F a)]) (F b)
forall {k} (d :: Nat) (g :: Ctx k) (g' :: Ctx k) (r1 :: Ctx k)
(r :: Ctx k) (a :: SYN k) (b :: SYN k) (c :: SYN k) (da :: Nat)
(db :: Nat) (p :: CAT k).
(Promonad p, MonoidalProfunctor p, KnownObj a, KnownObj b,
BindVar (d + 1) b g' r1, BindVar d a r1 r, Merge r g) =>
TermP p d g (a :** b)
-> (TermP p da '[ '(d, a)] a
-> TermP p db '[ '(d + 1, b)] b -> TermP p (d + 2) g' c)
-> TermP p d (Union r g) c
split TermP
(~>) 1 '[ '(0, (F a :-> F b) :** F a)] ((F a :-> F b) :** F a)
p (\TermP (~>) 3 '[ '(1, F a :-> F b)] (F a :-> F b)
f TermP (~>) 3 '[ '(1 + 1, F a)] (F a)
x -> TermP (~>) 3 '[ '(1, F a :-> F b)] (F a :-> F b)
f TermP (~>) 3 '[ '(1, F a :-> F b)] (F a :-> F b)
-> TermP (~>) 3 '[ '(1 + 1, F a)] (F a)
-> TermP
(~>) (1 + 2) (Union '[ '(1, F a :-> F b)] '[ '(2, F a)]) (F b)
forall {k} (p :: CAT k) f x r.
(Apply p f x r, Closed k, MonoidalProfunctor p) =>
f -> x -> r
! TermP (~>) 3 '[ '(1 + 1, F a)] (F a)
x))
curryT :: forall {k} (a :: k) b. (Closed k, SymMonoidal k, Ob a, Ob b) => a ~> b ~~> a ** b
curryT :: forall {k} (a :: k) (b :: k).
(Closed k, SymMonoidal k, Ob a, Ob b) =>
a ~> (b ~~> (a ** b))
curryT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a) @(F b :-> F a :** F b) (\TermP
(~>)
(2 + PSize (TermP (~>) 2 '[ '(1, F b)] (F b)))
'[ '(0, F a)]
(F a)
x -> (TermP (~>) 2 '[ '(1, F b)] (F b)
-> (TermP
(~>)
(2 + PSize (TermP (~>) 2 '[ '(1, F b)] (F b)))
'[ '(0, F a)]
(F a),
TermP (~>) 2 '[ '(1, F b)] (F b)))
-> TermP
(~>)
(1
+ PSize
(TermP
(~>)
(2 + PSize (TermP (~>) 2 '[ '(1, F b)] (F b)))
'[ '(0, F a)]
(F a)))
'[ '(0, F a)]
(F b :-> (F a :** F b))
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) (b :: SYN k) t
cont.
(Closed k, Binds (~>) d r a b t cont) =>
(t -> cont) -> Term d r (a :-> b)
lam (TermP
(~>)
(2 + PSize (TermP (~>) 2 '[ '(1, F b)] (F b)))
'[ '(0, F a)]
(F a)
x,))
rotT :: forall {k} (a :: k) b c. (SymMonoidal k, Ob a, Ob b, Ob c) => a ** b ** c ~> b ** c ** a
rotT :: forall {k} (a :: k) (b :: k) (c :: k).
(SymMonoidal k, Ob a, Ob b, Ob c) =>
((a ** b) ** c) ~> ((b ** c) ** a)
rotT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :** F b :** F c) \(TermP (~>) 5 '[ '(3, F a)] (F a)
a, TermP
(~>)
(1
+ ((2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a))))
+ PSize
(TermP
(~>)
(1 + (2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a)))))
'[ '(2, F c)]
(F c))))
'[ '(4, F b)]
(F b)
b, TermP
(~>)
(1 + (2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a)))))
'[ '(2, F c)]
(F c)
c) -> (TermP
(~>)
(1
+ ((2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a))))
+ PSize
(TermP
(~>)
(1 + (2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a)))))
'[ '(2, F c)]
(F c))))
'[ '(4, F b)]
(F b)
b, TermP
(~>)
(1 + (2 + (2 + PSize (TermP (~>) 5 '[ '(3, F a)] (F a)))))
'[ '(2, F c)]
(F c)
c, TermP (~>) 5 '[ '(3, F a)] (F a)
a)
traceT :: forall {k} (a :: k) b u. (TracedMonoidal k, Ob a, Ob b, Ob u) => (a ** u ~> b ** u) -> a ~> b
traceT :: forall {k} (a :: k) (b :: k) (u :: k).
(TracedMonoidal k, Ob a, Ob b, Ob u) =>
((a ** u) ~> (b ** u)) -> a ~> b
traceT (a ** u) ~> (b ** u)
h = (TermP (~>) 1 '[ '(0, F a)] (F a)
-> TermP
(~>)
(1 + PSize (TermP (~>) 1 '[ '(0, F a)] (F a)))
(Union
(Minus
'[ '(1, F b)]
(Union
(Vars k (TermP (~>) 1 '[ '(2, F u)] (F u)))
(Vars k (TermP (~>) (ZonkAny 7) '[ '(1, F b)] (F b)))))
(Minus
(Union '[] (Union '[ '(0, F a)] '[ '(2, F u)]))
(Union
(Vars k (TermP (~>) 1 '[ '(2, F u)] (F u)))
(Vars k (TermP (~>) (ZonkAny 7) '[ '(1, F b)] (F b))))))
(F b))
-> a ~> b
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) 1 '[ '(0, F a)] (F a)
a -> SMC.do
rec (b, u) <- lift @(F a :** F u) @(F b :** F u) h (a, u)
b
loopT :: forall {k} (a :: k) b u. (TracedMonoidal k, Ob a, Ob b, Ob u) => (a ** u ~> b ** u) -> a ~> b
loopT :: forall {k} (a :: k) (b :: k) (u :: k).
(TracedMonoidal k, Ob a, Ob b, Ob u) =>
((a ** u) ~> (b ** u)) -> a ~> b
loopT (a ** u) ~> (b ** u)
h = (TermP (~>) (ZonkAny 4) '[ '(0, F a)] (F a)
-> TermP
(~>)
(1 + PSize (TermP (~>) (ZonkAny 4) '[ '(0, F a)] (F a)))
'[ '(0, F a)]
(F b))
-> a ~> b
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) (ZonkAny 4) '[ '(0, F a)] (F a)
a -> forall {k} {p :: k +-> k} (u :: SYN k) (b :: SYN k) (d :: Nat)
(r :: Ctx k) t cont.
(Costrong Tensor p, SymMonoidal k, KnownObj b,
Binds p d r u (b :** u) t cont) =>
(t -> cont) -> TermP p d r b
forall (u :: SYN k) (b :: SYN k) (d :: Nat) (r :: Ctx k) t cont.
(Costrong Tensor (~>), SymMonoidal k, KnownObj b,
Binds (~>) d r u (b :** u) t cont) =>
(t -> cont) -> TermP (~>) d r b
loop @(F u) @(F b) \TermP (~>) (ZonkAny 5) '[ '(1, F u)] (F u)
u -> TermP
(~>)
(ZonkAny 6)
(Union '[ '(0, F a)] '[ '(1, F u)])
(F (Interp (F b :** F u)))
-> TermP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 5) '[ '(1, F u)] (F u)))
(Union '[ '(0, F a)] '[ '(1, F u)])
(F b :** F u)
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (d' :: Nat)
(g :: Ctx k) (p :: CAT k).
(Interp a ~ Interp b) =>
TermP p d g a -> TermP p d' g b
recast ((a ** u) ~> (b ** u)
Interp (F a :** F u) ~> Interp (F b :** F u)
h (Interp (F a :** F u) ~> Interp (F b :** F u))
-> (TermP (~>) (ZonkAny 4) '[ '(0, F a)] (F a),
TermP (~>) (ZonkAny 5) '[ '(1, F u)] (F u))
-> TermP
(~>)
(ZonkAny 6)
(Union '[ '(0, F a)] '[ '(1, F u)])
(F (Interp (F b :** F u)))
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< (TermP (~>) (ZonkAny 4) '[ '(0, F a)] (F a)
a, TermP (~>) (ZonkAny 5) '[ '(1, F u)] (F u)
u))
loopCC :: forall {k} (a :: k) b u. (CompactClosed k, Ob a, Ob b, Ob u) => (a ** u ~> b ** u) -> a ~> b
loopCC :: forall {k} (a :: k) (b :: k) (u :: k).
(CompactClosed k, Ob a, Ob b, Ob u) =>
((a ** u) ~> (b ** u)) -> a ~> b
loopCC (a ** u) ~> (b ** u)
h = (TermP (~>) 3 '[ '(0, F a)] (F a)
-> TermP
(~>)
(1 + PSize (TermP (~>) 3 '[ '(0, F a)] (F a)))
'[ '(0, F a)]
(F b))
-> a ~> b
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) 3 '[ '(0, F a)] (F a)
a -> SMC.do
(u, u') <- TermP (~>) 1 '[] (F u :** Not (F u))
forall {k} {p :: CAT k} (a :: SYN k) (d :: Nat).
(CompactClosed k, Promonad p, KnownObj a) =>
TermP p d '[] (a :** Not a)
produce
(b, v) <- lift @(F a :** F u) @(F b :** F u) h (a, u)
() <- annihilate u' v
b
snakeT :: forall {k} (a :: k). (CompactClosed k, Ob a) => a ~> a
snakeT :: forall {k} (a :: k). (CompactClosed k, Ob a) => a ~> a
snakeT = (TermP (~>) 3 '[ '(0, F a)] (F a)
-> TermP (~>) 1 '[ '(0, F a)] (F a))
-> a ~> a
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) 3 '[ '(0, F a)] (F a)
x -> SMC.do
(a, a') <- TermP (~>) 1 '[] (F a :** Not (F a))
forall {k} {p :: CAT k} (a :: SYN k) (d :: Nat).
(CompactClosed k, Promonad p, KnownObj a) =>
TermP p d '[] (a :** Not a)
produce
() <- annihilate a' x
a
combineDualT :: forall {k} (a :: k) b. (CompactClosed k, Ob a, Ob b) => Dual a ** Dual b ~> Dual (a ** b)
combineDualT :: forall {k} (a :: k) (b :: k).
(CompactClosed k, Ob a, Ob b) =>
(Dual a ** Dual b) ~> Dual (a ** b)
combineDualT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(Not (F a) :** Not (F b)) @(Not (F a :** F b)) \(ConsumerP (~>) 7 '[ '(1, Not (F a))] (F a)
da, ConsumerP (~>) 7 '[ '(2, Not (F b))] (F b)
db) -> SMC.do
(ab, ab') <- TermP (~>) 3 '[] ((F a :** F b) :** Not (F a :** F b))
forall {k} {p :: CAT k} (a :: SYN k) (d :: Nat).
(CompactClosed k, Promonad p, KnownObj a) =>
TermP p d '[] (a :** Not a)
produce
(a, b) <- ab
() <- annihilate da a
() <- annihilate db b
ab'
distT
:: forall {k} (a :: k) b c. (Distributive k, SymMonoidal k, Ob a, Ob b, Ob c) => a ** (b || c) ~> (a ** b) || (a ** c)
distT :: forall {k} (a :: k) (b :: k) (c :: k).
(Distributive k, SymMonoidal k, Ob a, Ob b, Ob c) =>
(a ** (b || c)) ~> ((a ** b) || (a ** c))
distT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :** (F b :|| F c)) \(TermP (~>) 4 '[ '(1, F a)] (F a)
a, TermP (~>) 3 '[ '(2, F b :|| F c)] (F b :|| F c)
bc) ->
if TermP (~>) 3 '[ '(2, F b :|| F c)] (F b :|| F c)
bc
then \TermP (~>) 4 '[ '(3, F b)] (F b)
b -> TermP (~>) 4 (Union '[ '(1, F a)] '[ '(3, F b)]) (F a :** F b)
-> TermP
(~>)
4
(Union '[ '(1, F a)] '[ '(3, F b)])
((F a :** F b) :|| (F a :** F c))
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k)
(p :: k +-> k).
(Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) =>
TermP p d g a -> TermP p d g (a :|| b)
inl (TermP (~>) 4 '[ '(1, F a)] (F a)
a TermP (~>) 4 '[ '(1, F a)] (F a)
-> TermP (~>) 4 '[ '(3, F b)] (F b)
-> TermP (~>) 4 (Union '[ '(1, F a)] '[ '(3, F b)]) (F a :** F b)
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 4 '[ '(3, F b)] (F b)
b)
else \TermP (~>) 4 '[ '(3, F c)] (F c)
c -> TermP (~>) 4 (Union '[ '(1, F a)] '[ '(3, F c)]) (F a :** F c)
-> TermP
(~>)
4
(Union '[ '(1, F a)] '[ '(3, F c)])
((F a :** F b) :|| (F a :** F c))
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k)
(p :: k +-> k).
(Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) =>
TermP p d g b -> TermP p d g (a :|| b)
inr (TermP (~>) 4 '[ '(1, F a)] (F a)
a TermP (~>) 4 '[ '(1, F a)] (F a)
-> TermP (~>) 4 '[ '(3, F c)] (F c)
-> TermP (~>) 4 (Union '[ '(1, F a)] '[ '(3, F c)]) (F a :** F c)
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 4 '[ '(3, F c)] (F c)
c)
swapEitherT :: forall {k} (a :: k) b. (Distributive k, SymMonoidal k, Ob a, Ob b) => a || b ~> b || a
swapEitherT :: forall {k} (a :: k) (b :: k).
(Distributive k, SymMonoidal k, Ob a, Ob b) =>
(a || b) ~> (b || a)
swapEitherT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :|| F b) \TermP (~>) 1 '[ '(0, F a :|| F b)] (F a :|| F b)
x -> TermP (~>) 1 '[ '(0, F a :|| F b)] (F a :|| F b)
-> (TermP (~>) 2 '[ '(1, F a)] (F a)
-> TermP (~>) 2 '[ '(1, F a)] (F b :|| F a))
-> (TermP (~>) 2 '[ '(1, F b)] (F b)
-> TermP (~>) 2 '[ '(1, F b)] (F b :|| F a))
-> TermP
(~>) 1 (Union (Union '[] '[]) '[ '(0, F a :|| F b)]) (F b :|| F a)
forall {k} (a :: SYN k) (b :: SYN k) (c :: SYN k) (d :: Nat)
(g :: Ctx k) (r1 :: Ctx k) (r2 :: Ctx k) t1 cont1 t2 cont2
(s :: SYN k) (p :: CAT k).
(Distributive k, Promonad p, DistributiveProfunctor p, Sum s a b,
KnownObj a, KnownObj b, Binds p d r1 a c t1 cont1,
Binds p d r2 b c t2 cont2, Thin (Union r1 r2) r1,
Thin (Union r1 r2) r2, Merge (Union r1 r2) g) =>
TermP p d g s
-> (t1 -> cont1)
-> (t2 -> cont2)
-> TermP p d (Union (Union r1 r2) g) c
caseOf TermP (~>) 1 '[ '(0, F a :|| F b)] (F a :|| F b)
x (\TermP (~>) 2 '[ '(1, F a)] (F a)
a -> TermP (~>) 2 '[ '(1, F a)] (F a)
-> TermP (~>) 2 '[ '(1, F a)] (F b :|| F a)
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k)
(p :: k +-> k).
(Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) =>
TermP p d g b -> TermP p d g (a :|| b)
inr TermP (~>) 2 '[ '(1, F a)] (F a)
a) (\TermP (~>) 2 '[ '(1, F b)] (F b)
b -> TermP (~>) 2 '[ '(1, F b)] (F b)
-> TermP (~>) 2 '[ '(1, F b)] (F b :|| F a)
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k)
(p :: k +-> k).
(Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) =>
TermP p d g a -> TermP p d g (a :|| b)
inl TermP (~>) 2 '[ '(1, F b)] (F b)
b)
bothWaysT
:: forall {k} (a :: k) b. (SymMonoidal k, HasBinaryProducts k, Ob a, Ob b) => a ** b ~> (a ** b) && (b ** a)
bothWaysT :: forall {k} (a :: k) (b :: k).
(SymMonoidal k, HasBinaryProducts k, Ob a, Ob b) =>
(a ** b) ~> ((a ** b) && (b ** a))
bothWaysT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :** F b) \(TermP (~>) 3 '[ '(1, F a)] (F a)
x, TermP (~>) 3 '[ '(2, F b)] (F b)
y) -> (TermP (~>) 3 '[ '(1, F a)] (F a)
x TermP (~>) 3 '[ '(1, F a)] (F a)
-> TermP (~>) 3 '[ '(2, F b)] (F b)
-> TermP (~>) 3 (Union '[ '(1, F a)] '[ '(2, F b)]) (F a :** F b)
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 3 '[ '(2, F b)] (F b)
y) TermP (~>) 3 (Union '[ '(1, F a)] '[ '(2, F b)]) (F a :** F b)
-> Term 3 (Union '[ '(2, F b)] '[ '(1, F a)]) (F b :** F a)
-> TermP
(~>)
3
(Union
(Union '[ '(1, F a)] '[ '(2, F b)])
(Union '[ '(2, F b)] '[ '(1, F a)]))
((F a :** F b) :&& (F b :** F a))
forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(HasBinaryProducts k, Thin (Union g1 g2) g1,
Thin (Union g1 g2) g2) =>
Term d g1 a -> Term d g2 b -> Term d (Union g1 g2) (a :&& b)
`with` (TermP (~>) 3 '[ '(2, F b)] (F b)
y TermP (~>) 3 '[ '(2, F b)] (F b)
-> TermP (~>) 3 '[ '(1, F a)] (F a)
-> Term 3 (Union '[ '(2, F b)] '[ '(1, F a)]) (F b :** F a)
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 3 '[ '(1, F a)] (F a)
x)
dniT :: forall {k} (a :: k). (Dialogue k, Ob a) => a ~> Dual (Dual a)
dniT :: forall {k} (a :: k). (Dialogue k, Ob a) => a ~> Dual (Dual a)
dniT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a) @(Up (F a)) \TermP (~>) 2 '[ '(0, F a)] (F a)
x -> (ConsumerP (~>) 2 '[ '(1, Not (F a))] (F a)
-> CommandP (~>) 2 (Union '[ '(1, Not (F a))] '[ '(0, F a)]))
-> TermP (~>) 1 '[ '(0, F a)] (Up (F a))
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) t cont.
(Dialogue k, Binds (~>) d r a (Not I) t cont) =>
(t -> cont) -> Term d r (Not a)
cont (TermP (~>) 2 '[ '(0, F a)] (F a)
x TermP (~>) 2 '[ '(0, F a)] (F a)
-> ConsumerP (~>) 2 '[ '(1, Not (F a))] (F a)
-> CommandP (~>) 2 (Union '[ '(1, Not (F a))] '[ '(0, F a)])
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(Dialogue k, MonoidalProfunctor p, KnownObj a, Merge g2 g1) =>
TermP p d g1 a -> ConsumerP p d g2 a -> CommandP p d (Union g2 g1)
|>)
dneT :: forall {k} (a :: k). (StarAutonomous k, Ob a) => Dual (Dual a) ~> a
dneT :: forall {k} (a :: k). (StarAutonomous k, Ob a) => Dual (Dual a) ~> a
dneT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(Up (F a)) @(F a) \TermP (~>) 1 '[ '(0, Up (F a))] (Up (F a))
nn -> TermP (~>) 1 '[ '(0, Up (F a))] (Up (F a))
-> TermP (~>) 1 '[ '(0, Up (F a))] (F a)
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g :: Ctx k).
(StarAutonomous k, Profunctor p, KnownObj a) =>
TermP p d g (Up a) -> TermP p d g a
classical TermP (~>) 1 '[ '(0, Up (F a))] (Up (F a))
nn
bindT :: forall {k} (a :: k) b. (Dialogue k, Ob a, Ob b) => (a ~> Dual (Dual b)) -> Dual (Dual a) ~> Dual (Dual b)
bindT :: forall {k} (a :: k) (b :: k).
(Dialogue k, Ob a, Ob b) =>
(a ~> Dual (Dual b)) -> Dual (Dual a) ~> Dual (Dual b)
bindT a ~> Dual (Dual b)
f = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(Up (F a)) @(Up (F b)) \TermP (~>) 1 '[ '(0, Up (F a))] (Up (F a))
m -> SMC.do
x <- TermP (~>) 1 '[ '(0, Up (F a))] (Up (F a))
m
f -< x
contraT :: forall {k} (a :: k) b. (Dialogue k, Ob a, Ob b) => (a ~> b) -> Dual b ~> Dual a
contraT :: forall {k} (a :: k) (b :: k).
(Dialogue k, Ob a, Ob b) =>
(a ~> b) -> Dual b ~> Dual a
contraT a ~> b
f = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(Not (F b)) @(Not (F a)) \ConsumerP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
'[ '(0, Not (F b))]
(F b)
nb -> (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)
-> CommandP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
(Union '[ '(0, Not (F b))] '[ '(1, F a)]))
-> TermP (~>) 1 '[ '(0, Not (F b))] (Not (F a))
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) t cont.
(Dialogue k, Binds (~>) d r a (Not I) t cont) =>
(t -> cont) -> Term d r (Not a)
cont \TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)
x -> ConsumerP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
'[ '(0, Not (F b))]
(F b)
-> TermP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
'[ '(1, F a)]
(F b)
-> CommandP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
(Union '[ '(0, Not (F b))] '[ '(1, F a)])
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(Dialogue k, MonoidalProfunctor p, KnownObj a, Merge g1 g2) =>
ConsumerP p d g1 a -> TermP p d g2 a -> CommandP p d (Union g1 g2)
cut ConsumerP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
'[ '(0, Not (F b))]
(F b)
nb (a ~> b
Interp (F a) ~> b
f (Interp (F a) ~> b)
-> TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)
-> TermP
(~>)
(2 + PSize (TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)))
'[ '(1, F a)]
(F b)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) (ZonkAny 2) '[ '(1, F a)] (F a)
x)
parSwapT :: forall {k} (a :: k) b. (Dialogue k, Ob a, Ob b) => Par a b ~> Par b a
parSwapT :: forall {k} (a :: k) (b :: k).
(Dialogue k, Ob a, Ob b) =>
Par a b ~> Par b a
parSwapT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :## F b) @(F b :## F a) \ConsumerP (~>) 4 '[ '(0, F a :## F b)] (Not (F a) :** Not (F b))
p -> ((TermP (~>) 4 '[ '(2, Not (F b))] (Not (F b)),
TermP (~>) 4 '[ '(3, Not (F a))] (Not (F a)))
-> CommandP
(~>)
4
(Union
'[ '(0, F a :## F b)]
(Union '[ '(3, Not (F a))] '[ '(2, Not (F b))])))
-> TermP (~>) 1 '[ '(0, F a :## F b)] (F b :## F a)
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) t cont.
(Dialogue k, Binds (~>) d r a (Not I) t cont) =>
(t -> cont) -> Term d r (Not a)
cont \(TermP (~>) 4 '[ '(2, Not (F b))] (Not (F b))
kb, TermP (~>) 4 '[ '(3, Not (F a))] (Not (F a))
ka) -> TermP (~>) 4 '[ '(3, Not (F a))] (Not (F a))
ka TermP (~>) 4 '[ '(3, Not (F a))] (Not (F a))
-> TermP (~>) 4 '[ '(2, Not (F b))] (Not (F b))
-> TermP
(~>)
4
(Union '[ '(3, Not (F a))] '[ '(2, Not (F b))])
(Not (F a) :** Not (F b))
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 4 '[ '(2, Not (F b))] (Not (F b))
kb TermP
(~>)
4
(Union '[ '(3, Not (F a))] '[ '(2, Not (F b))])
(Not (F a) :** Not (F b))
-> ConsumerP (~>) 4 '[ '(0, F a :## F b)] (Not (F a) :** Not (F b))
-> CommandP
(~>)
4
(Union
'[ '(0, F a :## F b)]
(Union '[ '(3, Not (F a))] '[ '(2, Not (F b))]))
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(Dialogue k, MonoidalProfunctor p, KnownObj a, Merge g2 g1) =>
TermP p d g1 a -> ConsumerP p d g2 a -> CommandP p d (Union g2 g1)
|> ConsumerP (~>) 4 '[ '(0, F a :## F b)] (Not (F a) :** Not (F b))
p
weakDistT
:: forall {k} (a :: k) b c
. (Dialogue k, Ob a, Ob b, Ob c)
=> a ** Par b c ~> Par (a ** b) c
weakDistT :: forall {k} (a :: k) (b :: k) (c :: k).
(Dialogue k, Ob a, Ob b, Ob c) =>
(a ** Par b c) ~> Par (a ** b) c
weakDistT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(F a :** (F b :## F c)) @((F a :** F b) :## F c) \(TermP (~>) 7 '[ '(1, F a)] (F a)
a, ConsumerP (~>) 6 '[ '(2, F b :## F c)] (Not (F b) :** Not (F c))
bc) ->
((ConsumerP (~>) 7 '[ '(4, Not (F a :** F b))] (F a :** F b),
TermP (~>) 6 '[ '(5, Not (F c))] (Not (F c)))
-> CommandP
(~>)
6
(Union
'[ '(2, F b :## F c)]
(Union
'[ '(4, Not (F a :** F b)), '(1, F a)] '[ '(5, Not (F c))])))
-> TermP
(~>) 3 '[ '(2, F b :## F c), '(1, F a)] ((F a :** F b) :## F c)
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) t cont.
(Dialogue k, Binds (~>) d r a (Not I) t cont) =>
(t -> cont) -> Term d r (Not a)
cont \(ConsumerP (~>) 7 '[ '(4, Not (F a :** F b))] (F a :** F b)
kab, TermP (~>) 6 '[ '(5, Not (F c))] (Not (F c))
kc) -> (TermP (~>) 7 '[ '(6, F b)] (F b)
-> CommandP
(~>)
7
(Union
'[ '(4, Not (F a :** F b))] (Union '[ '(1, F a)] '[ '(6, F b)])))
-> TermP (~>) 6 '[ '(4, Not (F a :** F b)), '(1, F a)] (Not (F b))
forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) t cont.
(Dialogue k, Binds (~>) d r a (Not I) t cont) =>
(t -> cont) -> Term d r (Not a)
cont (\TermP (~>) 7 '[ '(6, F b)] (F b)
b -> TermP (~>) 7 '[ '(1, F a)] (F a)
a TermP (~>) 7 '[ '(1, F a)] (F a)
-> TermP (~>) 7 '[ '(6, F b)] (F b)
-> TermP (~>) 7 (Union '[ '(1, F a)] '[ '(6, F b)]) (F a :** F b)
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 7 '[ '(6, F b)] (F b)
b TermP (~>) 7 (Union '[ '(1, F a)] '[ '(6, F b)]) (F a :** F b)
-> ConsumerP (~>) 7 '[ '(4, Not (F a :** F b))] (F a :** F b)
-> CommandP
(~>)
7
(Union
'[ '(4, Not (F a :** F b))] (Union '[ '(1, F a)] '[ '(6, F b)]))
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(Dialogue k, MonoidalProfunctor p, KnownObj a, Merge g2 g1) =>
TermP p d g1 a -> ConsumerP p d g2 a -> CommandP p d (Union g2 g1)
|> ConsumerP (~>) 7 '[ '(4, Not (F a :** F b))] (F a :** F b)
kab) TermP (~>) 6 '[ '(4, Not (F a :** F b)), '(1, F a)] (Not (F b))
-> TermP (~>) 6 '[ '(5, Not (F c))] (Not (F c))
-> TermP
(~>)
6
(Union '[ '(4, Not (F a :** F b)), '(1, F a)] '[ '(5, Not (F c))])
(Not (F b) :** Not (F c))
forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k)
(b :: SYN k) (p :: CAT k).
(MonoidalProfunctor p, Merge g1 g2) =>
TermP p d g1 a
-> TermP p d g2 b -> TermP p d (Union g1 g2) (a :** b)
** TermP (~>) 6 '[ '(5, Not (F c))] (Not (F c))
kc TermP
(~>)
6
(Union '[ '(4, Not (F a :** F b)), '(1, F a)] '[ '(5, Not (F c))])
(Not (F b) :** Not (F c))
-> ConsumerP (~>) 6 '[ '(2, F b :## F c)] (Not (F b) :** Not (F c))
-> CommandP
(~>)
6
(Union
'[ '(2, F b :## F c)]
(Union '[ '(4, Not (F a :** F b)), '(1, F a)] '[ '(5, Not (F c))]))
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(Dialogue k, MonoidalProfunctor p, KnownObj a, Merge g2 g1) =>
TermP p d g1 a -> ConsumerP p d g2 a -> CommandP p d (Union g2 g1)
|> ConsumerP (~>) 6 '[ '(2, F b :## F c)] (Not (F b) :** Not (F c))
bc
matMulT :: forall {k} (a :: k) b c. (SymMonoidal k, Frobenius b, Frobenius c, Ob a) => (a ~> b) -> (b ~> c) -> a ~> c
matMulT :: forall {k} (a :: k) (b :: k) (c :: k).
(SymMonoidal k, Frobenius b, Frobenius c, Ob a) =>
(a ~> b) -> (b ~> c) -> a ~> c
matMulT a ~> b
f b ~> c
g = (TermP (~>) (ZonkAny 1) '[ '(0, F a)] (F a)
-> TermP
(~>)
(1 + PSize (TermP (~>) (ZonkAny 1) '[ '(0, F a)] (F a)))
'[ '(0, F a)]
(F c))
-> a ~> c
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) (ZonkAny 1) '[ '(0, F a)] (F a)
i -> forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (r :: Ctx k)
(b :: SYN k) t cont.
(Profunctor p, Frobenius (Interp a), Binds p d r a b t cont) =>
(t -> cont) -> TermP p d r b
forall (a :: SYN k) (d :: Nat) (r :: Ctx k) (b :: SYN k) t cont.
(Profunctor (~>), Frobenius (Interp a),
Binds (~>) d r a b t cont) =>
(t -> cont) -> TermP (~>) d r b
sumOver @(F c) \TermP (~>) 3 '[ '(1, F c)] (F c)
k -> forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (r :: Ctx k)
(b :: SYN k) t cont.
(Profunctor p, Frobenius (Interp a), Binds p d r a b t cont) =>
(t -> cont) -> TermP p d r b
forall (a :: SYN k) (d :: Nat) (r :: Ctx k) (b :: SYN k) t cont.
(Profunctor (~>), Frobenius (Interp a),
Binds (~>) d r a b t cont) =>
(t -> cont) -> TermP (~>) d r b
sumOver @(F b) \TermP (~>) 3 '[ '(2, F b)] (F b)
j ->
TermP (~>) 3 '[ '(0, F a)] (F b)
-> TermP (~>) 3 '[ '(2, F b)] (F b)
-> TermP (~>) 3 (Union '[ '(0, F a)] '[ '(2, F b)]) I
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(MonoidalProfunctor p, Frobenius (Interp a), KnownObj a,
Merge g1 g2) =>
TermP p d g1 a -> TermP p d g2 a -> TermP p d (Union g1 g2) I
delta (a ~> b
Interp (F a) ~> b
f (Interp (F a) ~> b)
-> TermP (~>) (ZonkAny 1) '[ '(0, F a)] (F a)
-> TermP (~>) 3 '[ '(0, F a)] (F b)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) (ZonkAny 1) '[ '(0, F a)] (F a)
i) TermP (~>) 3 '[ '(2, F b)] (F b)
j TermP (~>) 3 (Union '[ '(0, F a)] '[ '(2, F b)]) I
-> TermP (~>) 3 (Union '[ '(2, F b)] '[ '(1, F c)]) I
-> TermP
(~>)
3
(Union
(Union '[ '(0, F a)] '[ '(2, F b)])
(Union '[ '(2, F b)] '[ '(1, F c)]))
I
forall {k} {p :: k +-> k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k)
(a :: SYN k) (s :: SYN k) t.
(MonoidalProfunctor p, KnownObj a, Merge g1 g2, Interp s ~ Unit,
ToTerm p t d g1 s) =>
t -> TermP p d g2 a -> TermP p d (Union g1 g2) a
*^ TermP (~>) 3 '[ '(2, F b)] (F c)
-> TermP (~>) 3 '[ '(1, F c)] (F c)
-> TermP (~>) 3 (Union '[ '(2, F b)] '[ '(1, F c)]) I
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(MonoidalProfunctor p, Frobenius (Interp a), KnownObj a,
Merge g1 g2) =>
TermP p d g1 a -> TermP p d g2 a -> TermP p d (Union g1 g2) I
delta (b ~> c
Interp (F b) ~> c
g (Interp (F b) ~> c)
-> TermP (~>) 3 '[ '(2, F b)] (F b)
-> TermP (~>) 3 '[ '(2, F b)] (F c)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) 3 '[ '(2, F b)] (F b)
j) TermP (~>) 3 '[ '(1, F c)] (F c)
k TermP
(~>)
3
(Union
(Union '[ '(0, F a)] '[ '(2, F b)])
(Union '[ '(2, F b)] '[ '(1, F c)]))
I
-> TermP (~>) 3 '[ '(1, F c)] (F c)
-> TermP
(~>)
3
(Union
(Union
(Union '[ '(0, F a)] '[ '(2, F b)])
(Union '[ '(2, F b)] '[ '(1, F c)]))
'[ '(1, F c)])
(F c)
forall {k} {p :: k +-> k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k)
(a :: SYN k) (s :: SYN k) t.
(MonoidalProfunctor p, KnownObj a, Merge g1 g2, Interp s ~ Unit,
ToTerm p t d g1 s) =>
t -> TermP p d g2 a -> TermP p d (Union g1 g2) a
*^ TermP (~>) 3 '[ '(1, F c)] (F c)
k
traceIdxT :: forall {k} (a :: k). (SymMonoidal k, Frobenius a) => (a ~> a) -> Unit ~> (Unit :: k)
traceIdxT :: forall {k} (a :: k).
(SymMonoidal k, Frobenius a) =>
(a ~> a) -> Unit ~> Unit
traceIdxT a ~> a
f = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @I \() -> forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (r :: Ctx k)
(b :: SYN k) t cont.
(Profunctor p, Frobenius (Interp a), Binds p d r a b t cont) =>
(t -> cont) -> TermP p d r b
forall (a :: SYN k) (d :: Nat) (r :: Ctx k) (b :: SYN k) t cont.
(Profunctor (~>), Frobenius (Interp a),
Binds (~>) d r a b t cont) =>
(t -> cont) -> TermP (~>) d r b
sumOver @(F a) \TermP (~>) 2 '[ '(1, F a)] (F a)
i -> TermP (~>) 2 '[ '(1, F a)] (F a)
-> TermP (~>) 2 '[ '(1, F a)] (F a)
-> TermP (~>) 2 (Union '[ '(1, F a)] '[ '(1, F a)]) I
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(MonoidalProfunctor p, Frobenius (Interp a), KnownObj a,
Merge g1 g2) =>
TermP p d g1 a -> TermP p d g2 a -> TermP p d (Union g1 g2) I
delta (a ~> a
Interp (F a) ~> a
f (Interp (F a) ~> a)
-> TermP (~>) 2 '[ '(1, F a)] (F a)
-> TermP (~>) 2 '[ '(1, F a)] (F a)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) 2 '[ '(1, F a)] (F a)
i) TermP (~>) 2 '[ '(1, F a)] (F a)
i
hadamardT :: forall {k} (a :: k) b. (SymMonoidal k, Frobenius a, Frobenius b) => (a ~> b) -> (a ~> b) -> a ~> b
hadamardT :: forall {k} (a :: k) (b :: k).
(SymMonoidal k, Frobenius a, Frobenius b) =>
(a ~> b) -> (a ~> b) -> a ~> b
hadamardT a ~> b
f a ~> b
g = (TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
-> TermP
(~>)
(1 + PSize (TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)))
'[ '(0, F a)]
(F b))
-> a ~> b
forall {k} (a :: k) (b :: k) t cont.
(Monoidal k, Binds (~>) 0 '[] (F a) (F b) t cont) =>
(t -> cont) -> a ~> b
toSMC1 \TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
i -> forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (r :: Ctx k)
(b :: SYN k) t cont.
(Profunctor p, Frobenius (Interp a), Binds p d r a b t cont) =>
(t -> cont) -> TermP p d r b
forall (a :: SYN k) (d :: Nat) (r :: Ctx k) (b :: SYN k) t cont.
(Profunctor (~>), Frobenius (Interp a),
Binds (~>) d r a b t cont) =>
(t -> cont) -> TermP (~>) d r b
sumOver @(F b) \TermP (~>) 2 '[ '(1, F b)] (F b)
j ->
TermP (~>) 2 '[ '(0, F a)] (F b)
-> TermP (~>) 2 '[ '(1, F b)] (F b)
-> TermP (~>) 2 (Union '[ '(0, F a)] '[ '(1, F b)]) I
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(MonoidalProfunctor p, Frobenius (Interp a), KnownObj a,
Merge g1 g2) =>
TermP p d g1 a -> TermP p d g2 a -> TermP p d (Union g1 g2) I
delta (a ~> b
Interp (F a) ~> b
f (Interp (F a) ~> b)
-> TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
-> TermP (~>) 2 '[ '(0, F a)] (F b)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
i) TermP (~>) 2 '[ '(1, F b)] (F b)
j TermP (~>) 2 (Union '[ '(0, F a)] '[ '(1, F b)]) I
-> TermP (~>) 2 (Union '[ '(0, F a)] '[ '(1, F b)]) I
-> TermP
(~>)
2
(Union
(Union '[ '(0, F a)] '[ '(1, F b)])
(Union '[ '(0, F a)] '[ '(1, F b)]))
I
forall {k} {p :: k +-> k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k)
(a :: SYN k) (s :: SYN k) t.
(MonoidalProfunctor p, KnownObj a, Merge g1 g2, Interp s ~ Unit,
ToTerm p t d g1 s) =>
t -> TermP p d g2 a -> TermP p d (Union g1 g2) a
*^ TermP (~>) 2 '[ '(0, F a)] (F b)
-> TermP (~>) 2 '[ '(1, F b)] (F b)
-> TermP (~>) 2 (Union '[ '(0, F a)] '[ '(1, F b)]) I
forall {k} {p :: k +-> k} (a :: SYN k) (d :: Nat) (g1 :: Ctx k)
(g2 :: Ctx k).
(MonoidalProfunctor p, Frobenius (Interp a), KnownObj a,
Merge g1 g2) =>
TermP p d g1 a -> TermP p d g2 a -> TermP p d (Union g1 g2) I
delta (a ~> b
Interp (F a) ~> b
g (Interp (F a) ~> b)
-> TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
-> TermP (~>) 2 '[ '(0, F a)] (F b)
forall {k} (a :: SYN k) (b :: k) t (p :: CAT k) (d :: Nat)
(g :: Ctx k).
(Promonad p, BuildTuple p t g a) =>
p (Interp a) b -> t -> TermP p d g (F b)
-< TermP (~>) (ZonkAny 0) '[ '(0, F a)] (F a)
i) TermP (~>) 2 '[ '(1, F b)] (F b)
j TermP
(~>)
2
(Union
(Union '[ '(0, F a)] '[ '(1, F b)])
(Union '[ '(0, F a)] '[ '(1, F b)]))
I
-> TermP (~>) 2 '[ '(1, F b)] (F b)
-> TermP
(~>)
2
(Union
(Union
(Union '[ '(0, F a)] '[ '(1, F b)])
(Union '[ '(0, F a)] '[ '(1, F b)]))
'[ '(1, F b)])
(F b)
forall {k} {p :: k +-> k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k)
(a :: SYN k) (s :: SYN k) t.
(MonoidalProfunctor p, KnownObj a, Merge g1 g2, Interp s ~ Unit,
ToTerm p t d g1 s) =>
t -> TermP p d g2 a -> TermP p d (Union g1 g2) a
*^ TermP (~>) 2 '[ '(1, F b)] (F b)
j
snakeDualT :: forall {k} (a :: k). (CompactClosed k, Ob a) => Dual a ~> Dual a
snakeDualT :: forall {k} (a :: k). (CompactClosed k, Ob a) => Dual a ~> Dual a
snakeDualT = forall {k} (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
forall (a :: SYN k) (b :: SYN k) t cont.
(Monoidal k, Binds (~>) 0 '[] a b t cont) =>
(t -> cont) -> Interp a ~> Interp b
toSMC @(Not (F a)) \ConsumerP (~>) 3 '[ '(0, Not (F a))] (F a)
x -> SMC.do
(a, a') <- TermP (~>) 1 '[] (F a :** Not (F a))
forall {k} {p :: CAT k} (a :: SYN k) (d :: Nat).
(CompactClosed k, Promonad p, KnownObj a) =>
TermP p d '[] (a :** Not a)
produce
() <- annihilate x a
a'