-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | DisCoCat implementation. -- -- An educational implementation of the DisCoCat framework. @package discokitty @version 0.1.0 -- | An implementation of the cups of the category of matrices over an -- arbitary semiring. In this module we call "vector space" to what would -- be more generally a module over a semiring. The representation is done -- using sparse vectors that do not include the elements of the basis -- whose element is zero. | module Discokitty.Models.Vectorspaces -- | A vector is given internally by a map representing the coefficients of -- each basis element. data Vectorspace u m Vector :: Map [u] m -> Vectorspace u m -- | Creates a sparse vector from a list of basis elements multiplied by -- scalars. sparse :: (Ord u, Eq u, Semiring m) => [([u], m)] -> Vectorspace u m fromList :: (Ord u, Eq u, Semiring m) => [([u], m)] -> Vectorspace u m -- | Creates a sparse vector from a map assigning a scalar to each base -- element. fromMap :: Map [u] m -> Vectorspace u m -- | Outputs a map assigning to each base element its coefficient. toMap :: Vectorspace u m -> Map [u] m class (Eq m, Ord m) => Semiring m plus :: Semiring m => m -> m -> m mult :: Semiring m => m -> m -> m zero :: Semiring m => m unit :: Semiring m => m instance (GHC.Show.Show m, GHC.Show.Show u) => GHC.Show.Show (Discokitty.Models.Vectorspaces.Vectorspace u m) instance Discokitty.Dimension.Dim (Discokitty.Models.Vectorspaces.Vectorspace u m) instance (GHC.Classes.Ord u, GHC.Classes.Eq u, Discokitty.Models.Vectorspaces.Semiring m) => Discokitty.HasCups.HasCups (Discokitty.Models.Vectorspaces.Vectorspace u m) -- | | module Discokitty.Models.Rel -- | A relation hom(1,a) is given by a subset of the universe with elements -- in a. We model this using the Data.Set library. data Rel u relation :: Ord u => [[u]] -> Rel u fromList :: Ord u => [[u]] -> Rel u toList :: Rel u -> [[u]] relCup :: Ord u => Int -> Rel u -> Rel u -> Rel u agrees :: Eq u => Int -> ([u], [u]) -> Maybe [u] instance GHC.Show.Show u => GHC.Show.Show (Discokitty.Models.Rel.Rel u) instance Discokitty.Dimension.Dim (Discokitty.Models.Rel.Rel u) instance GHC.Classes.Ord u => Discokitty.HasCups.HasCups (Discokitty.Models.Rel.Rel u) instance Discokitty.Dimension.Dim (Discokitty.Words.Words (Discokitty.Models.Rel.Rel u)) -- | This module allows us to obtain diagrams for our sentences. In order -- to obtain these, we define a monoidal category whose morphisms are -- diagrams and then implement a cup operation on that category that -- consists on wiring two of them together. We apply then the ideas of -- DisCoCat to words whose meanings are themselves diagrams, and just -- perform the necessary reductions. | module Discokitty.Models.Diagrams tikzDiagrams :: [Words m] -> String instance GHC.Show.Show Discokitty.Models.Diagrams.Schema instance GHC.Show.Show Discokitty.Models.Diagrams.Diagram instance GHC.Show.Show Discokitty.Models.Diagrams.Wire instance GHC.Show.Show Discokitty.Models.Diagrams.Node instance Discokitty.HasCups.HasCups Discokitty.Models.Diagrams.Schema instance GHC.Show.Show Discokitty.Models.Diagrams.Style -- | This module exports all basic modules of the Discokitty library. -- Please note that models and examples should be imported separately. module Discokitty class Dim a -- | In the meaning space, states can have a given number of output wires. -- This function takes an state and should output the number of output -- wires it has. dim :: Dim a => a -> Int class HasCups m -- | Given an integer, performs that number of cups between the two meaning -- spaces. In a monoidal category, this should be the composition of the -- tensor product of two states with a certain number of cups. cup :: HasCups m => Int -> m -> m -> m -- | Neutral element for the cup operation. This could be given by the -- identity morphism (state). cunit :: HasCups m => m -- | Lambek basic grammatical types. data Type N :: Type S :: Type L :: Type -> Type R :: Type -> Type -- | A Lambek pregroup type. type Lambek = [Type] -- | Checks if two Lambek types can be reduced a given number of steps. agreeOn :: Int -> Lambek -> Lambek -> Bool -- | A word is given by a meaning and a grammatical type. The Words type is -- parameterized over the meaning type. data Words m Words :: m -> Lambek -> String -> Words m [meaning] :: Words m -> m [grammar] :: Words m -> Lambek [text] :: Words m -> String -- | Concatenates a list of words outputting all possible grammatical -- reductions. sentence :: HasCups m => [Words m] -> [Words m] concatenate :: HasCups m => Words m -> Words m -> [Words m] -- | Empty word. Unit for concatenation of words. emptyWord :: HasCups m => Words m -- | Filters a list of words by grammatical type. (@@@) :: [Words m] -> Lambek -> [Words m] module Discokitty.Examples.LesJustesViterbi newtype Viterbi Viterbi :: Double -> Viterbi v :: Multiword (Vectorspace u Double) -> Multiword (Vectorspace u Viterbi) instance GHC.Classes.Ord Discokitty.Examples.LesJustesViterbi.Viterbi instance GHC.Num.Num Discokitty.Examples.LesJustesViterbi.Viterbi instance GHC.Show.Show Discokitty.Examples.LesJustesViterbi.Viterbi instance GHC.Classes.Eq Discokitty.Examples.LesJustesViterbi.Viterbi instance Discokitty.Models.Vectorspaces.Semiring Discokitty.Examples.LesJustesViterbi.Viterbi module Discokitty.Examples.LesJustesUniverse data Universe Universe :: Universe Yanek :: Universe Dora :: Universe Boris :: Universe Duke :: Universe Stepan :: Universe Nephew :: Universe Skouratov :: Universe Poet :: Universe Revolutionary :: Universe Terrorist :: Universe Saviour :: Universe Innocent :: Universe Tsarist :: Universe Alive :: Universe Life :: Universe Poetry :: Universe Chemistry :: Universe Propaganda :: Universe Bomb :: Universe IsTrue :: Universe IsFalse :: Universe IsRighteous :: Universe IsWrong :: Universe IsPlot :: Universe type UniverseN = [Universe] universe :: [Universe] -- | In the meaning space, states can have a given number of output wires. -- This function takes an state and should output the number of output -- wires it has. dim :: Dim a => a -> Int instance GHC.Classes.Ord Discokitty.Examples.LesJustesUniverse.Universe instance GHC.Enum.Enum Discokitty.Examples.LesJustesUniverse.Universe instance GHC.Enum.Bounded Discokitty.Examples.LesJustesUniverse.Universe instance GHC.Show.Show Discokitty.Examples.LesJustesUniverse.Universe instance GHC.Classes.Eq Discokitty.Examples.LesJustesUniverse.Universe instance Discokitty.Dimension.Dim Discokitty.Examples.LesJustesUniverse.UniverseN module Discokitty.Examples.LesJustesVector yanek' :: Words (Vectorspace Universe Double) dora' :: Words (Vectorspace Universe Double) likes' :: Words (Vectorspace Universe Double) combat' :: Words (Vectorspace Universe Double) is' :: Words (Vectorspace Universe Double) people' :: Semiring m => Words (Vectorspace Universe m) yanek :: Multiword (Vectorspace Universe Double) dora :: Multiword (Vectorspace Universe Double) likes :: Multiword (Vectorspace Universe Double) enjoy :: Multiword (Vectorspace Universe Double) is :: Multiword (Vectorspace Universe Double) people :: Multiword (Vectorspace Universe Double) combat :: Multiword (Vectorspace Universe Double) who :: Semiring m => Multiword (Vectorspace Universe m) basis :: Semiring m => Universe -> Multiword (Vectorspace Universe m) tsarist :: Semiring m => Multiword (Vectorspace Universe m) life :: Semiring m => Multiword (Vectorspace Universe m) propaganda :: Semiring m => Multiword (Vectorspace Universe m) poetry :: Semiring m => Multiword (Vectorspace Universe m) innocent :: Semiring m => Multiword (Vectorspace Universe m) terrorist :: Semiring m => Multiword (Vectorspace Universe m) revolutionary :: Semiring m => Multiword (Vectorspace Universe m) tsarists :: Multiword (Vectorspace Universe Double) revolutionaries :: Multiword (Vectorspace Universe Double) that :: Multiword (Vectorspace Universe Double) are :: Multiword (Vectorspace Universe Double) newtype Tropical Tropical :: Double -> Tropical instance GHC.Classes.Ord Discokitty.Examples.LesJustesVector.Tropical instance GHC.Num.Num Discokitty.Examples.LesJustesVector.Tropical instance GHC.Show.Show Discokitty.Examples.LesJustesVector.Tropical instance GHC.Classes.Eq Discokitty.Examples.LesJustesVector.Tropical instance Discokitty.Models.Vectorspaces.Semiring Discokitty.Examples.LesJustesVector.Tropical instance Discokitty.Models.Vectorspaces.Semiring GHC.Types.Double module Discokitty.Examples.LesJustesMain type RelU = Rel Universe yanek :: Words RelU attacks :: Words RelU duke :: Words RelU example2 :: [Words RelU] lnot :: Universe -> Words RelU rnot :: Universe -> Words RelU cnst :: Universe -> Words RelU kills :: Words RelU example3 :: [Words RelU] nephew :: Words RelU bomb :: Words RelU and' :: Words RelU example4a :: [Words RelU] using :: Words RelU with :: Multiword RelU yanek' :: Multiword RelU duke' :: Multiword RelU nephew' :: Multiword RelU bomb' :: Multiword RelU using' :: Multiword RelU and'' :: Multiword RelU attacks' :: Multiword RelU example5a :: Multiword RelU example5b :: Multiword RelU becomes :: Words RelU becomes' :: Multiword RelU revolutionary :: Multiword RelU kills''' :: Multiword RelU discarding' :: Multiword RelU he :: Multiword (Rel Universe) saviour :: Multiword (Rel Universe) terrorist :: Multiword (Rel Universe) alive :: Multiword (Rel Universe) is' :: Multiword (Rel Universe) (?) :: Multiword (Rel Universe) example6 :: Multiword RelU example7 :: Multiword RelU people :: Multiword RelU combat :: Multiword RelU enjoy :: Multiword RelU is_ :: Multiword RelU who :: Multiword RelU tsarist :: Multiword RelU tsarists :: Multiword RelU revolutionaries :: Multiword RelU example8 :: Multiword RelU example9 :: Multiword RelU life :: Multiword RelU propaganda :: Multiword RelU innocent :: Multiword RelU poetry :: Multiword RelU chemistry :: Multiword RelU example10 :: Multiword RelU example11 :: Multiword RelU module Discokitty.Examples.AliceAndBob data Universe Alice :: Universe Bob :: Universe IsTrue :: Universe IsFalse :: Universe type Term = Words (Rel Universe) alice :: Term bob :: Term loves :: Term example :: [Term] exampleDiagram :: String instance GHC.Show.Show Discokitty.Examples.AliceAndBob.Universe instance GHC.Classes.Ord Discokitty.Examples.AliceAndBob.Universe instance GHC.Classes.Eq Discokitty.Examples.AliceAndBob.Universe