Add Data.Tensor

I should have done this earlier, but I forgot to.
This commit is contained in:
Kiana Sheibani 2023-03-06 10:57:36 -05:00
parent cf38f4a07e
commit cbebb74423
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 66 additions and 1 deletions

62
Data/Tensor.idr Normal file
View file

@ -0,0 +1,62 @@
module Data.Tensor
%default total
public export
record Isomorphism a b where
constructor MkIso
fwd : a -> b
bwd : b -> a
public export
interface Bifunctor ten => Associative ten where
assoc : Isomorphism (a `ten` (b `ten` c)) ((a `ten` b) `ten` c)
public export
interface Bifunctor ten => Symmetric ten where
swap : a `ten` b -> b `ten` a
public export
interface Associative ten => Tensor ten i | ten where
unitl : Isomorphism (i `ten` a) a
unitr : Isomorphism (a `ten` i) a
export
Associative Pair where
assoc = MkIso (\(x,(y,z)) => ((x,y),z)) (\((x,y),z) => (x,(y,z)))
export
Symmetric Pair where
swap = Builtin.swap
export
Tensor Pair () where
unitl = MkIso snd ((),)
unitr = MkIso fst (,())
export
Associative Either where
assoc = MkIso f b
where
f : forall a,b,c. Either a (Either b c) -> Either (Either a b) c
f (Left x) = Left (Left x)
f (Right (Left x)) = Left (Right x)
f (Right (Right x)) = Right x
b : forall a,b,c. Either (Either a b) c -> Either a (Either b c)
b (Left (Left x)) = Left x
b (Left (Right x)) = Right (Left x)
b (Right x) = Right (Right x)
export
Symmetric Either where
swap = either Right Left
Tensor Either Void where
unitl = MkIso (either absurd id) Right
unitr = MkIso (either id absurd) Left

View file

@ -6,4 +6,7 @@ license = "MIT"
readme = "README.md" readme = "README.md"
modules = Data.Profunctor.Types modules = Data.Tensor,
Data.Profunctor.Types,
Data.Profunctor.Functor,
Data.Profunctor.Strong