Decision Problems
The algorithm must terminate for all inputs. If there is no such algorithm, L is undecidable.
Optimization problems can be encoded into decision problems: for example, to find the length of shortest path, simply check if there a path with length less than
There are uncountably many languages over the alphabet:
Every decidable language is also semi-decidable: if no is outputted, just pass it through to an endless loop.
Some undecidable languages are semi-decidable.
If
Algorithms correspond to a function
NB: Functions on numbers can be encoded using binary (otherwise, the alphabet would be infinite).
Semi-decidable:
-
: is computable iff there is an algorithm that outputs and terminates for all inputs - Partial function:
or undefined - Partially computable if there is an algorithm that outputs
whenever is defined
Turing Machines
- Extension of finite automata
- Infinite tape: cells that store a symbol
- Machine has read/write head over one cell on the tape
- Finite automaton portion of the Turing machine called the finite control
- Transitions may depend on the symbol under the head
- Transitions may change the symbol under the head
- The machine halts as soon as it reaches the accept or reject state
Where:
-
is the set of states -
is the input alphabet, which cannot contain the blank symbol -
is the tape alphabet; - That is, the input alphabet is a subset of the tape alphabet
-
is the blank symbol
-
is the start state -
is the accept state -
, is the reject state -
is the transition function:
The TM operates as follows:
- Input is placed on the tape - all other cells are set to blank
- Starts with head over the first input symbol
- If
is in state with symbol under the head, is consulted - Tape head moves in direction
: (left), (right), or (none) - Transitions in the format
, where is the symbol that should be under the head for the transition to occur, is the symbol it is replaced with, and is the direction the head should move in - Blank symbols can be introduced and removed
Notes:
-
is deterministic -
may or may not halt -
is total if accepts all inputs -
can be used to accept a language (ignoring tape contents), or to compute a function
Configuration
Storing the current state of the Turing machine:
-
is the current state -
is the tape contents to the left of the head -
is the tape contents under and to the right of the head
Since only one cell on the tape can be modified at a time, a configuration relation can be used to describe transitions. e.g. where
-
accepts if -
rejects w if -
is total if it halts on all inputs -
- A language is semi-decidable if it is a language generated by a Turing machine
- A language is decidable if it is a language generated by a total Turing machine
Notes:
-
computes a partial function : -
if where - The function is partially computable if it is defined by a Turing machine
- The function is computable if it is defined by a total Turing machine
Computation Models
There are many computation models e.g. TMs with multiple tapes, pushdown automata with two stacks etc. Many of these are equivalent: they accept the same languages and compute the same functions.
Church-Turing thesis: the intuitively computable functions (that is, that humans can compute - hard to formalize) are those partially computable by a Turing machine.
Chomsky Hierarchy
Where:
-
is the non-terminal set -
is the terminal set, disjoint from -
is a finite set of productions -
is the start symbol, a non-terminal
Different grammars are obtained by restricting the form of each production
- Type-0 (general):
- That is, the number of terminals and non-terminals on the LHS is bigger than
- That is, the number of terminals and non-terminals on the LHS is bigger than
- Type-1 (context-sensitive):
- LHS can’t be smaller than the RHS
- Type-2 (context-free):
- The LHS is a non-terminal
- Type-3 (regular): x$ \in N, y \in \Sigma \cup \Sigma N$
- The LHS is non-terminal, and the RHS non-terminal, or a non-terminal followed by a terminal
Notes:
- For type-1 and type-3 grammars, the
string is not covered - As you go to more general grammars, everything gets more difficult (e.g. membership problem exponential for type-1, impossible for type-0)
- Type-1 languages are closed under the complement operator
- Type-1 languages are defined by a linearly space-bounded non-deterministic automata
- The amount of tape that can be used is some multiple of the input size
- Every type-1 language is decidable
| Grammar | Language | Automata |
|---|---|---|
| Type-0 | General/Recursively Enumerable | Turing Machine (or NTM) |
| Type-1 | Context-sensitive | Linearly space-bounded non-deterministic automata |
| Type-2 | Context-free | Push-down automata (not deterministic PDA) |
| Type-3 | Regular | Deterministic-Finite Automata (or NFA) |
Undecidability
Programs can be the input of other programs e.g. compiler takes a program as input, Python interpreter.
Special Halting Problem
The following, called the special halting problem, is undecidable:
Thus, the SHP is the set of all programs which, when given itself as input, halts.
Proof
- If the SHP is decidable,
for a total TM - That is,
is a total TM that checks if a given TM halts when given itself as an input
- That is,
- Construct a TM
that is like , except that it goes into an endless loop if accepts - Thus,
halts when given itself as input. Why? -
rejects -
-
does not halt on
-
def M_SHP(program_str):
return True if exec(program_str)(program_str) halts else False
def M_dash(program_str):
if M_SHP(program_str):
while True:
continue
return False
M_dash(as_string(M_dash))
# If false is returned, then it does not halt so it cannot have returned false
# If it does not terminate, then it must halt, but it cannot have halted
# Hence, M_SHP cannot exist
Halting Problem
Assume there is some total TM which determines if some program given some arbitrary string terminates. If this is possible, solving the special halting problem is trivial - just pass the specific input of
Some other undecidable languages:
- If problem halts on empty tape
- If two TMs are equivalent
- If TM enters a given state
- If the language generated by a given TM is a subset of some arbitrary se (as long as it is not the empty or universal set)
Complexity Classes
Running times of programs:
Function
The program can be solved efficiently if it can be solved in polynomial time. These languages are in the complexity class
- Shortest path between two nodes in a graph
- Every CFL
-
- Deterministic primality testing
Non-Deterministic Turing Machine (NTM)
-
is the number of steps in the longest transition sequence -
- Non-deterministic polynomial time is the complexity class denoted by
-
, but does ? - An NTM can guess the output and then verify its correctness in polynomial time
Some problems known to be in
- Does a graph contain a path that visits every vertex exactly once?
- Hamilton path problem
- Given sets of integers
and an integer , is there a subset of that sums to - Partitioning a list of integers such that the sums of the two subsets are equal
- Satisfiability formula: given logic formula with Boolean variables and operations, can it be true?
Problem Complexity
Compare problem complexities by reducing one to another:
-
is polynomial-time reducible to : if there is a function that runs in polynomial time that maps every input in to every input in - Thus, if
, and , then
NP-Complete Problems
- Must be
- Must be
-hard -
If these two conditions are met, then every other
Showing that a problem is
The satisfiability problem (SAT) was the first problem shown to be
- There is an NTM for the problem running in polynomial time
- Every problem in
-
- So 3-SAT is also
-complete
- So 3-SAT is also
-
- So CLIQUE is also
-complete
- So CLIQUE is also
-
Hence, there is a tree of reductions.
CLIQUE
Finding the largest subset of the graph that is complete - all pairs of nodes are connected.
SAT
Given logic formula:
Output: can the variables be set such that the formula evaluates to true?
On a NTM, guess and verify:
- Evaluating the formula once for some given set of variables: linear time
- Use NTM to transition variables between 0 and 1 and generate all possible combinations
- Choices are possible; there is no set implementation for how the choices are picked
3-SAT
Limit the structure of logic formulas using Conjunctive Normal Form (CNF):
Every formula can be converted into CNF.
If the distributivity rule is used in highly nested formulas there is exponential blow-up as each use of it causes duplication: thus, it cannot be used.
S-SAT
Given formula in CNF with exactly 3 literals per clause:
- Push down negations using de Morgan/double negation
- New variable
for each inner node (non-literal) in the syntax tree - Require
, root node to be true -
to be true -
to be true -
- Require
- Rewrite the equivalences as clauses:
-
- Use definitions of
and to convert them into clauses:
-
- Expand short clauses with new variables
- If
-
- So now there are three variables
- If
Result is in 3-CNF, obtained in polynomial time, is satisfiable if and only if the original formula is satisfiable.