
Theory of Computation
Tags | Computer scienceMathScience |
---|---|
Created | |
Updated |

Resources
Introducing video courses
Name | Tags |
---|---|
Michael Sipser. 18.404J Theory of Computation. Fall 2020. Massachusetts Institute of Technology: MIT OpenCourseWare, https://ocw.mit.edu . License: Creative Commons BY-NC-SA |
Introducing books
History
Name | Tags |
---|---|
Machines, Languages, and Computation at MIT | Peter J. DenningTheoretical Models of Computationanecdotes |
Strings and Languages
Definitions.
Alphabet. Any non-empty finite set. We generally use either capital Greek letters , or uppercase letters to designate alphabets.
Symbol. The members of an Alphabet.
Examples:
String over an alphabet. A finite sequence of symbols from that alphabet.
Length of a string. If is a string over , the length of , written , is the number of symbols that it contains. Some authors prefer to use for indicating some characteristic applied on .
Empty string.
Language. Set of strings. We generally use upper-case letters to designate languages.
Lexicographic ordering.
1. Shorter strings precede longer strings.
2. The first symbol in the alphabet precedes the next symbol.
Regular operations.
Let be languages:
Union:
Concatenation:
Kleene star: , note always.
Kleene plus:
Example. Let and
Worked examples
Models of computation
https://cs.brown.edu/people/jsavage/book/pdfs/ModelsOfComputation_Chapter4.pdf
Grammar
Interpreter
Formal grammar is a tool for syntax, not semantics.
Vocabulary
Grammar. A grammar is a 4-tuple
where is a finite set of objects called variables,
is a finite set of objects, disjoint from , called terminal symbols, in short terminals,
is a special symbol called the start variable,
is a finite set of rules, called production rules, with each rule being a variable a string of variables and terminals.
BNF. A particular form of notation for grammar (Backus-Naur form).
CNF. A particular form of notation for grammar (Chomsky normal form).
Language generated by . Let be a grammar. Then the set
is the language generated by G.
Production rules. If production rules are of the form
where , . The production rules are applied in the following manner: Given a string
Rule | Application | Result |
| | |
We say that derives o that is derived from .
A rule can be used whenever it’s applicable.
If
we say that derives and write
. The * indicates an unspecified number of steps (including zero).
Chomsky normal form (CNF) example
, ,
Backus–Naur form (BNF) example
, ,
Grammar Hierarchy
Set view

Table view
Grammar type | Grammar accepted | Language Accepted | Automaton | Production rule form |
Type 0. These are the most general. | Free or unrestricted grammars | Recursively enumerable language | Turing Machine | , where both u and v are arbitrary strings of symbols in V, with u non-null. |
Type 1 | Context-sensitive grammars | Context-sensitive language | Linear-bounded automaton | where ,, and are arbitrary strings of symbols in , with non-null, and a single nonterminal. In other words, in a particular context. |
Type 2 | Context-free grammars | Context-free language | Pushdown automaton | , where is an arbitrary string of symbols in , and is a single nonterminal. i.e. regardless of context. |
Type 3. These grammars are the most limited in terms of expressive power. | Regular grammars | Regular language | Finite-state automaton | , (right-regular grammar), (left-regular grammar), , where and are nonterminals and is a terminal. Regular grammar is either right-linear grammar or left-linear grammar, but not both. Mixing left-regular and right-regular rules are the context-free grammar. |
https://www.cs.utexas.edu/users/novak/cs343283.html
Classification
- Acceptors
- Transducers
- Generators (also called sequencers)
https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/40342.pdf
Worked examples
Steps to convert regular expressions directly to regular grammars and vice versa

FAQ
Are axioms in math equivalent to production rules in unrestricted grammars?
how could a CFG hold an unrestricted grammar (UG), which is turing complete?
https://stackoverflow.com/questions/61952877/chomsky-hierarchy-examples-with-real-languages?rq=1
Notes and references
[1] M. Johnson, “Formal Grammars Handout written,” 2012 [Online]. Available: https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/080 Formal Grammars.pdf. [Accessed: 28-Feb-2022]
Finite automata
Finite automata and their probabilistic counterpart Markov chains. Finite Automaton (FA) or Finite-State Machine. An automaton (Automata in plural).
- The computer is complex, instead, we use an idealized computer called a computational model.
- A finite automaton:

We feed the input string to the machine , the processing proceeds as follows:
- Start in state .
- Read 1, follow the transition from to .
- Read 1, follow the transition from to .
- Accept because is in an accept state at the end of the input.
The formal definition of a deterministic finite automaton (DFA)
A finite automaton is a 5-tuple where
- is a finite set called the states,
- is a finite set called the alphabet,
- is the transition function,
- is the start state, and
- is the set accept states, they are sometimes called final states.
The formal definition of a nondeterministic finite automaton (NFA)
A finite automaton is a 5-tuple where
- is a finite set called the states,
- is a finite set called the alphabet,
- is the transition function (P is a power set),
- is the start state, and
- is the set accept states, they are sometimes called final states.
Converting NFAs to DFAs
delta = {
'state1': {
'symbol1': {'state1', 'state2',...}
}
}
# BFS
NFAToDFA(NFA)
FAQ
What is the difference between finite automata and finite state machines?
Pattern Matching
https://www.seas.upenn.edu/~lee/10cis541/lecs/EFSM-Code-Generation-v4-1x2.pdf
Automata and Grammar
Regular expressions to Automata
- Generalized nondeterministic finite automaton.
def convert_to_regular_rxpression(G):
if G.number_of_states == 2:
return
- Solving right-linear equation by Arden’s rule.