-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An implementation of Turing Machine and Automaton -- -- An implementation of Turing Machine and Automaton for language theory @package turingMachine @version 1.0.0.0 -- | Auxiliar Functions module Data.Helper -- | Union of set monad unionsFold :: (Ord a, Foldable t) => t (Set a) -> Set a -- | Size of a set, with large integers setGenericSize :: (Ord a) => Set a -> Integer -- | Simple Label-State function, have an isomorphism with Maybe but order -- are diferent module Data.Label -- | Machine states are only a label, maybe a letter data Label a -- | State constructor Q :: a -> Label a -- | Error state QE :: Label a -- | Final label state represent a set of states which elements put end to -- computation type Final a = Set (Label a) -- | Tells if a label state is a error state isError :: (Eq a) => Label a -> Bool -- | Tells if a label state is final terminal :: (Ord a) => Final a -> Label a -> Bool -- | Alias for a set of lalbel states type SetLabel a = Set (Label a) -- | Alias for a label state of a set of label states type LabelSS a = Label (SetLabel a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Label.Label a) instance GHC.Show.Show a => GHC.Show.Show (Data.Label.Label a) instance GHC.Base.Functor Data.Label.Label instance GHC.Base.Applicative Data.Label.Label instance GHC.Base.Monad Data.Label.Label instance GHC.Enum.Enum a => GHC.Enum.Enum (Data.Label.Label a) instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Data.Label.Label a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Label.Label a) instance GHC.Base.Monoid a => GHC.Base.Monoid (Data.Label.Label a) instance Data.Foldable.Foldable Data.Label.Label -- | Cardinal definitions module Data.Numerable -- | All sets can be one and only one: -- --
-- >>> let autFin = F delta (Set.fromList [Q 0]) (Q 0) --F :: (Delta a) -> (Final a) -> (Label a) -> FiniteA a -- |
-- >>> let autFinN = FN deltaN (Set.fromList [Q 0]) (Q 0) --FN :: (NDelta a) -> (Final a) -> (Label a) -> FiniteA a -- | Executes a automaton over a word -- --
-- >>> checkString autFin "1010010101101010" -- True -- -- >>> checkString autFin "1010010101101010001010101010" -- False --checkString :: (Ord a) => FiniteA a -> Wd -> Bool -- | Transducer function type Lambda1 a = (:*>:) a () Symbol -- | Transducer function with output at transition type Lambda2 a = (:*>:) a Symbol Symbol -- | Transducer Autmaton, both types: -- --
-- >>> let delta = liftDelta [(0,'0',0),(0,'1',1),(1,'0',1),(1,'1',0)] --liftDelta :: (Ord a) => [(a, Symbol, a)] -> Delta a -- | Lift a list of 3-tuples to a non deterministic delta -- --
-- >>> let deltaN = liftNDelta [(0,'0',[0]),(0,'1',[1]),(1,'0',[1]),(1,'1',[0])] --liftNDelta :: (Ord a) => [(a, Symbol, [a])] -> NDelta a -- | Lift simple transducer function liftL1 :: (Ord a) => [(a, Symbol)] -> Lambda1 a -- | Lift second transducer function liftL2 :: (Ord a) => [(a, Symbol, Symbol)] -> Lambda2 a -- | Minimaize a delta for some finite automaton. Gets a delta with all -- reachable states from initial state. reachableDelta :: (Ord a) => FiniteA a -> FiniteA a -- | Delete redundant states and their transitions, if a state is -- equivalent to another then is redundant, two state are equivalent if -- they are undistinguisahbles. distinguishableDelta :: (Ord a) => FiniteA a -> FiniteA a -- | Minimize a finite automaton, -- --
-- >>> let delta = liftD [(0,"(",'Z',0,"IZ"),(0,"",'Z',0,""),(0,"(",'I',0,"II"),(0,")",'I',0,"")]
--
liftDelta :: Ord a => [(a, Wd, Symbol, a, Wd)] -> Delta a
nextDTuple :: Ord a => Delta a -> Key a -> (Label a, Wd)
-- | Stack machine only needs a delta, an init state and an initial symbol.
--
-- This works for empty stack and final state acceptor
data StackA a
Stack :: Delta a -> Label a -> Final a -> Symbol -> StackA a
[getDelta] :: StackA a -> Delta a
[getInitState] :: StackA a -> Label a
[getFinal] :: StackA a -> Final a
[getInitSymbol] :: StackA a -> Symbol
nextState :: (Ord a) => Delta a -> Wd -> State (Wd, Label a) (Label a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Math.Model.Automaton.Stack.StackA a)
instance GHC.Show.Show a => GHC.Show.Show (Math.Model.Automaton.Stack.StackA a)
-- | Turing machine abstaction
module Math.Model.Turing
class Ways a
oposite :: Ways a => a -> a
data LRS
-- | Left move
L :: LRS
-- | No move
S :: LRS
-- | Right move
R :: LRS
data FW
Dw :: FW
Lf :: FW
Rt :: FW
Up :: FW
type Delta a b c = (:->:) a b (b, c)
type MDelta a b c = (:->:) a [b] ([b], [c])
liftD :: (Ord a, Ord b) => [(a, b, a, b, c)] -> Delta a b c
liftMD :: (Ord a, Ord b) => [(a, [b], a, [b], [c])] -> MDelta a b c
liftDAux :: (Ord a, Ord b) => [(a, b, a, b, c)] -> (:->:) a b (b, c)
class (Applicative t) => Tapeable t a
getHead :: Tapeable t a => t a -> a
liftTape :: (Tapeable t a, (Monoid (t a))) => [a] -> t a
newtype MultiTape t a
MT :: [t a] -> MultiTape t a
getMHead :: (Tapeable t a) => MultiTape t a -> [a]
liftMTape :: (Tapeable t a, Monoid (t a)) => [a] -> MultiTape t a
class (Tapeable t b, Ways w) => TuringM t b w
moveHead :: (TuringM t b w, (Monoid b)) => w -> t b -> t b
data Model a b c
[TS] :: (Ways c) => Delta a b c -> Label a -> Final a -> Model a b c
data MultiModel a b c
[MTS] :: (Ways c) => MDelta a b c -> Label a -> [Final a] -> MultiModel a b c
instance GHC.Enum.Bounded Math.Model.Turing.FW
instance GHC.Classes.Eq Math.Model.Turing.FW
instance GHC.Show.Show Math.Model.Turing.FW
instance GHC.Enum.Bounded Math.Model.Turing.LRS
instance GHC.Classes.Ord Math.Model.Turing.LRS
instance GHC.Classes.Eq Math.Model.Turing.LRS
instance GHC.Show.Show Math.Model.Turing.LRS
instance Math.Model.Turing.Ways Math.Model.Turing.FW
instance Math.Model.Turing.Ways Math.Model.Turing.LRS
-- | Two ways turing machine
module Math.Model.Turing.TwoWays
data Tape a
T :: [a] -> a -> [a] -> Tape a
-- | -- >>> let tapeLifted = (liftTape "word")::Tape Symbol -- -- >>> tapeLifted -- T "" 'w' "ord" --instance GHC.Classes.Eq a => GHC.Classes.Eq (Math.Model.Turing.TwoWays.Tape a) instance GHC.Show.Show a => GHC.Show.Show (Math.Model.Turing.TwoWays.Tape a) instance GHC.Base.Functor Math.Model.Turing.TwoWays.Tape instance GHC.Base.Applicative Math.Model.Turing.TwoWays.Tape instance (GHC.Classes.Eq s, GHC.Base.Monoid s) => GHC.Base.Monoid (Math.Model.Turing.TwoWays.Tape s) instance Math.Model.Turing.Tapeable Math.Model.Turing.TwoWays.Tape Data.Sigma.Symbol instance Math.Model.Turing.Tapeable Math.Model.Turing.TwoWays.Tape [Data.Sigma.Symbol] instance Math.Model.Turing.TuringM Math.Model.Turing.TwoWays.Tape Data.Sigma.Symbol Math.Model.Turing.LRS instance Math.Model.Turing.TuringM Math.Model.Turing.TwoWays.Tape [Data.Sigma.Symbol] Math.Model.Turing.LRS -- | Four ways turing machine module Math.Model.Turing.FourWays data Tracks a Track :: [Tape a] -> (Tape a) -> [Tape a] -> Tracks a instance GHC.Classes.Eq a => GHC.Classes.Eq (Math.Model.Turing.FourWays.Tracks a) instance GHC.Show.Show a => GHC.Show.Show (Math.Model.Turing.FourWays.Tracks a) instance GHC.Base.Functor Math.Model.Turing.FourWays.Tracks instance GHC.Base.Applicative Math.Model.Turing.FourWays.Tracks instance (GHC.Classes.Eq s, GHC.Base.Monoid s) => GHC.Base.Monoid (Math.Model.Turing.FourWays.Tracks s) instance Math.Model.Turing.Tapeable Math.Model.Turing.FourWays.Tracks Data.Sigma.Symbol instance Math.Model.Turing.TuringM Math.Model.Turing.FourWays.Tracks Data.Sigma.Symbol Math.Model.Turing.FW instance Math.Model.Turing.TuringM Math.Model.Turing.TwoWays.Tape Data.Sigma.Symbol Math.Model.Turing.FW