NFA and DFA algorithms visualized using Haskell
Find a file
2019-11-29 23:21:12 +00:00
app Clean up and fix compilation error 2019-11-01 09:44:27 +00:00
resources Update images to match visualisation changes 2019-11-01 00:11:54 +00:00
src/Rextra Make project compile with --pedantic again 2019-11-29 23:21:12 +00:00
test Create new project with stack 2019-10-21 11:43:55 +00:00
.gitignore Change project name 2019-10-28 13:48:28 +00:00
automata.txt Add notes 2019-11-29 20:21:40 +00:00
LICENSE Prepare files for making repository public 2019-10-31 19:33:43 +00:00
package.yaml Prepare files for making repository public 2019-10-31 19:33:43 +00:00
README.md Make visualisations look more like wiki examples 2019-10-31 23:55:38 +00:00
Setup.hs Create new project with stack 2019-10-21 11:43:55 +00:00
stack.yaml Create new project with stack 2019-10-21 11:43:55 +00:00
stack.yaml.lock Do some basic setup 2019-10-21 11:58:32 +00:00
todo.txt Add notes 2019-11-29 20:21:40 +00:00

rextra

At the moment, rextra can display DFAs and NFAs using Graphviz, convert between NFAs and DFAs, and minimize DFAs.

The representation of DFAs and NFAs assumes an infinite alphabet:

  • DFA states always contain a default transition (marked with * in the visualisations), which is taken if the current token doesn't appear in any of the other transitions.

  • NFA transitions either apply to a set of tokens, or to all tokens except a specified set. In the visualisation, the character Σ denotes the alphabet of tokens.

Example NFA-to-DFA conversion

This example ghci session converts the NFA shown on the wikipedia article about the powerset construction into a DFA, using the aforementioned powerset construction.

>>> Just a = nfa [ (1,[(only "0",2)],[3]), (2,[(only "1",2),(only "1",4)],[]), (3,[(only "0",4)],[2]), (4,[(only "0",3)],[]) ] (1::Int) [3,4]
>>> saveDotAsPng "nfa.png" $ nfaToDot a

>>> saveDotAsPng "dfa.png" $ dfaToDotWithTokens "01" $ nfaToDfa a

Example DFA minimization

This example ghci session minimizes the DFA shown on the wikipedia article about DFA minimization.

>>> Just a = dfa [ ("a",[('1',"c")],"b"), ("b",[('1',"d")],"a"), ("c",[('1',"f")],"e"), ("d",[('1',"f")],"e"), ("e",[('1',"f")],"e"), ("f",[],"f") ] "a" ["c","d","e"]
>>> saveDotAsPng "dfa.png" $ dfaToDotWithTokens "01" a

>>> saveDotAsPng "dfa_minimized.png" $ dfaToDotWithTokens "01" $ minimizeDfa a