Difference between revisions of "PFP Homework 2"
(Created page with "= Automatons II = Usually, a finite automaton defined as: <math>(Q, \Sigma, \delta, q_0, F)</math> where Q represents states, next is input alphabet, then transitions (<math>...") |
|||
| Line 21: | Line 21: | ||
ex2 :: Automaton | ex2 :: Automaton | ||
ex2 = (3, "ab", [(0,'a',1), (0,'a',0), (0,'b',0), (1,'b',2)], 0, [2]) | ex2 = (3, "ab", [(0,'a',1), (0,'a',0), (0,'b',0), (1,'b',2)], 0, [2]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | <syntaxhighlight lang="Haskell"> | ||
| + | data RegExpr = Epsilon | ||
| + | | Symbol Char | ||
| + | | Iteration RegExpr | ||
| + | | Concat RegExpr RegExpr | ||
| + | | Alter RegExpr RegExpr deriving (Eq, Show) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 17:27, 10 October 2023
Automatons II
Usually, a finite automaton defined as: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle (Q, \Sigma, \delta, q_0, F)} where Q represents states, next is input alphabet, then transitions (Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle Q \times \Sigma \rightarrow Q} ), Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q_0} is starting state and finally there is a set of final states.
In our case, a finite automaton is represented by types:
type Transition = (Int, Char, Int)
type Automaton = (Int, String, [Transition], Int, [Int])
where:
- first number
Ndefines number of states - states will be coded by integer numbers in interval Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle <0, N)} ; - second element is a string containing the input symbols - you can safely assume; it contains no duplicities;
- third is a list defining the trasition function - elementary transition is a triple
(q1, a, q2)representing a transition: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q_1 \times a \rightarrow q_2} ; - Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q_0} is a number from interval Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle <0, N)} ;
- finally, there is a list of number representing possible states that are final in defined automaton.
As examples we can use following automatons:
ex1 :: Automaton
ex1 = (3, "ab", [(0,'a',1), (0,'b',0), (1,'a',1), (1,'b',2), (2,'a',1), (2,'b',0)], 0, [2],)
ex2 :: Automaton
ex2 = (3, "ab", [(0,'a',1), (0,'a',0), (0,'b',0), (1,'b',2)], 0, [2])
data RegExpr = Epsilon
| Symbol Char
| Iteration RegExpr
| Concat RegExpr RegExpr
| Alter RegExpr RegExpr deriving (Eq, Show)
Your task will be to create three functions:
- First function checks if a given finite automaton is a deterministic finite automaton.
isDeterministic:: Automaton -> Bool
ghci>isDeterministic ex1
True
ghci>isDeterministic ex2
False