Difference between revisions of "PFP Homework 1"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
= Automatons =  
 
= Automatons =  
Usually, a finite automaton defined as: <math>(Q, \Sigma, \delta, q_0, F)</math> where Q represents a states, next is input aplhabet, then transitions, <math>q_0</math> is starting state and finaly there is a set on finite states.
+
Usually, a finite automaton defined as: <math>(Q, \Sigma, \delta, q_0, F)</math> where Q represents a states, next is input aplhabet, then transitions (<math>Q \mult \Sigma \rightarrow q</math>, <math>q_0</math> is starting state and finaly there is a set of final states.
  
 
In our case, an finite automaton is represented by types:
 
In our case, an finite automaton is represented by types:
 
<syntaxhighlight lang="Haskell">
 
<syntaxhighlight lang="Haskell">
 
type Transition = (Int, Char, Int)
 
type Transition = (Int, Char, Int)
type Automaton = (Int, String, [Int], Int, [Transition ])
+
type Automaton = (Int, String, [Transition], Int, [Int])
 
</syntaxhighlight>
 
</syntaxhighlight>
 
where:
 
where:
 
* first number <code>N</code> defines number of states - states will be coded by integer numbers in interval <math><0, N)</math>;
 
* first number <code>N</code> defines number of states - states will be coded by integer numbers in interval <math><0, N)</math>;
 
* second element is a string containing the input symbols - you can safely assume, it contains no duplicities.
 
* 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 (
 
where states are coded with numbers from 0 to n
 
where states are coded with numbers from 0 to n
  

Revision as of 12:10, 10 October 2023

Automatons

Usually, a finite automaton defined as: where Q represents a states, next is input aplhabet, then transitions (Failed to parse (unknown function "\mult"): {\displaystyle Q \mult \Sigma \rightarrow q} , is starting state and finaly there is a set of final states.

In our case, an finite automaton is represented by types:

type Transition = (Int, Char, Int)
type Automaton = (Int, String, [Transition], Int, [Int])

where:

  • first number N defines number of states - states will be coded by integer numbers in interval ;
  • 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 (

where states are coded with numbers from 0 to n

ex1 :: Automaton 
ex1 = (3, [0], [2], "ab", [(0,'a',1), (0,'b',0), (1,'a',1), (1,'b',2), (2,'a',1), (2,'b',0)])

ex2 :: Automaton 
ex2 = (3, [0], [2], "ab", [(0,'a',1), (0,'a',0), (0,'b',0), (1,'b',2)])
  • Create a function, that sorts an array using quicksort algorithm quicksort. Inside, you must use the mutable array STArray.
quickSort :: Array Int Int -> Array Int Int
ghci> elems $ quickSort $  listArray (0,5) [8,4,9,6,7,1] 
[1,4,6,7,8,9]