| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Tools.SMC.Examples
Description
Examples of Proarrow.Tools.SMC. They are compiled at k = , where the result
can be run.Type
Synopsis
- swapT :: forall {k} (a :: k) (b :: k). (SymMonoidal k, Ob a, Ob b) => (a ** b) ~> (b ** a)
- applyT :: forall {k} (a :: k) (b :: k). (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))
- rotT :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> ((b ** c) ** a)
- traceT :: forall {k} (a :: k) (b :: k) (u :: k). (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
- loopCC :: forall {k} (a :: k) (b :: k) (u :: k). (CompactClosed k, Ob a, Ob b, Ob u) => ((a ** u) ~> (b ** u)) -> a ~> b
- snakeT :: forall {k} (a :: k). (CompactClosed k, Ob a) => a ~> a
- combineDualT :: forall {k} (a :: k) (b :: k). (CompactClosed k, Ob a, Ob b) => (Dual a ** Dual b) ~> Dual (a ** b)
- 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))
- swapEitherT :: forall {k} (a :: k) (b :: k). (Distributive k, SymMonoidal k, Ob a, Ob 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))
- dniT :: forall {k} (a :: k). (Dialogue k, Ob a) => a ~> Dual (Dual a)
- dneT :: forall {k} (a :: k). (StarAutonomous k, Ob a) => Dual (Dual a) ~> a
- bindT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => (a ~> Dual (Dual b)) -> Dual (Dual a) ~> Dual (Dual b)
- contraT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => (a ~> b) -> Dual b ~> Dual a
- parSwapT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => Par a b ~> Par b a
- 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
- matMulT :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Frobenius b, Frobenius c, Ob a) => (a ~> b) -> (b ~> c) -> a ~> c
- traceIdxT :: forall {k} (a :: k). (SymMonoidal k, Frobenius a) => (a ~> a) -> (Unit :: k) ~> (Unit :: k)
- hadamardT :: forall {k} (a :: k) (b :: k). (SymMonoidal k, Frobenius a, Frobenius b) => (a ~> b) -> (a ~> b) -> a ~> b
- snakeDualT :: forall {k} (a :: k). (CompactClosed k, Ob a) => Dual a ~> Dual a
Documentation
swapT :: forall {k} (a :: k) (b :: k). (SymMonoidal k, Ob a, Ob b) => (a ** b) ~> (b ** a) Source Github #
Swap a tensor.
>>>import Prelude (Bool (..))>>>swapT @Bool @Bool (True, False)(False,True)
applyT :: forall {k} (a :: k) (b :: k). (Closed k, SymMonoidal k, Ob a, Ob b) => ((a ~~> b) ** a) ~> b Source Github #
Apply a function to an argument, both in a tensor.
>>>import Prelude (Bool (..), not)>>>applyT @Bool @Bool (not, True)False
curryT :: forall {k} (a :: k) (b :: k). (Closed k, SymMonoidal k, Ob a, Ob b) => a ~> (b ~~> (a ** b)) Source Github #
Curry the tensor.
>>>import Prelude (Bool (..))>>>curryT @Bool @Bool True False(True,False)
rotT :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> ((b ** c) ** a) Source Github #
Rotate a triple, with a triple pattern.
>>>import Prelude (Bool (..), Int)>>>rotT @Int @Bool @Int ((1, True), 2)((True,2),1)
traceT :: forall {k} (a :: k) (b :: k) (u :: k). (TracedMonoidal k, Ob a, Ob b, Ob u) => ((a ** u) ~> (b ** u)) -> a ~> b Source Github #
Trace out u with a rec block. In Type the trace is a lazy fixed point.
>>>import Prelude (Int, take)>>>traceT @Int @[Int] @[Int] (\(a, u) -> (take 3 u, a : u)) 1[1,1,1]
loopT :: forall {k} (a :: k) (b :: k) (u :: k). (TracedMonoidal k, Ob a, Ob b, Ob u) => ((a ** u) ~> (b ** u)) -> a ~> b Source Github #
Trace out u with loop.
>>>import Prelude (Int, take)>>>loopT @Int @[Int] @[Int] (\(a, u) -> (take 3 u, a : u)) 1[1,1,1]
loopCC :: forall {k} (a :: k) (b :: k) (u :: k). (CompactClosed k, Ob a, Ob b, Ob u) => ((a ** u) ~> (b ** u)) -> a ~> b Source Github #
A trace from the duality alone, so for any compact closed category: feed u in along one
end of a new pair and join its new value with the other end.
snakeT :: forall {k} (a :: k). (CompactClosed k, Ob a) => a ~> a Source Github #
A snake: create a pair, join its dual with the input, and continue with the other end. By the zigzag law it is the identity. The input is older than the pair, so it sits to the left of it, and the join needs a swap.
combineDualT :: forall {k} (a :: k) (b :: k). (CompactClosed k, Ob a, Ob b) => (Dual a ** Dual b) ~> Dual (a ** b) Source Github #
The inverse of distribDual: make a pair for a ** b, and annihilate the two halves of its
plain end with the given duals.
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)) Source Github #
The tensor distributes over the coproduct: the shared a goes to whichever branch is taken.
>>>import Prelude (Bool (..), Char, Either (..), Int)>>>distT @Int @Bool @Char (1, Left True)Left (1,True)
swapEitherT :: forall {k} (a :: k) (b :: k). (Distributive k, SymMonoidal k, Ob a, Ob b) => (a || b) ~> (b || a) Source Github #
Swap a coproduct, with nothing to share.
>>>import Prelude (Bool (..), Either (..), Int)>>>swapEitherT @Int @Bool (Left 1)Right 1
bothWaysT :: forall {k} (a :: k) (b :: k). (SymMonoidal k, HasBinaryProducts k, Ob a, Ob b) => (a ** b) ~> ((a ** b) && (b ** a)) Source Github #
A pair both as it is and swapped: the second alternative takes the pair apart.
>>>import Prelude (Bool (..), Int)>>>bothWaysT @Int @Bool (1, True)((1,True),(True,1))
dniT :: forall {k} (a :: k). (Dialogue k, Ob a) => a ~> Dual (Dual a) Source Github #
Double negation introduction: a consumer of a consumer of a hands it the a. This is
ret, written out.
dneT :: forall {k} (a :: k). (StarAutonomous k, Ob a) => Dual (Dual a) ~> a Source Github #
Double negation elimination, the classical direction: a computation is its value. Binding its
consumer with cont and cutting would only give the computation back.
bindT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => (a ~> Dual (Dual b)) -> Dual (Dual a) ~> Dual (Dual b) Source Github #
Sequencing: run the input computation, and continue with f on its value. In a category with
this is the bind of the continuation monad.Dual a = a ~~> r
contraT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => (a ~> b) -> Dual b ~> Dual a Source Github #
Contraposition: a consumer of b consumes a through f.
parSwapT :: forall {k} (a :: k) (b :: k). (Dialogue k, Ob a, Ob b) => Par a b ~> Par b a Source Github #
Par is symmetric: bind both outputs and hand them to the input the other way round. This is
parSwap.
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 Source Github #
Linear (weak) distributivity, a ⊗ (b ⅋ c) ⊸ (a ⊗ b) ⅋ c: the b the input emits is paired
with a and sent to the first output, and its c goes to the second. This is
weakDistL.
matMulT :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Frobenius b, Frobenius c, Ob a) => (a ~> b) -> (b ~> c) -> a ~> c Source Github #
Composition in index notation, as matrix multiplication: the entry at i and k is the sum over
j of the entries of f and g. It is g . f.
traceIdxT :: forall {k} (a :: k). (SymMonoidal k, Frobenius a) => (a ~> a) -> (Unit :: k) ~> (Unit :: k) Source Github #
The trace in index notation: the sum of the diagonal entries.
hadamardT :: forall {k} (a :: k) (b :: k). (SymMonoidal k, Frobenius a, Frobenius b) => (a ~> b) -> (a ~> b) -> a ~> b Source Github #
The entrywise product of two morphisms: two boxes that produce the same index.
snakeDualT :: forall {k} (a :: k). (CompactClosed k, Ob a) => Dual a ~> Dual a Source Github #
The snake on the dual: join the input with the first end of a new pair, and continue with the second. Here the wires meet in the order they come, so no swap is needed.