cs2200
Types of grammar:
- Right linear
- Context free
- unrestricted
Types of machine models:
- finite memory: finite automata, regex
- finite memory with stack: pushdown automata
- unrestricted: turing machines, post systems, λ calculus etc.
There is a one to one correspondence for the numberings above.
Gödel’s incompleteness theorem: No matter how strong a deductive system is, there are always statements that are true but unprovable.
Strings and Sets
Decision problem is a function that has a one bit output: true or false, 1 or 0.
To completely specify a decision problem, specify a set of possible inputs, and the subset for which the output is true.
Encoding the input of a decision problem as a fixed finite length string is possible over some fixed finite alphabet.
A finite alphabet is any finite set. A finite length string is a sequence of the elements.
Set ops for two sets:
- Union
- Intersection
- Complement over set of all strings: Basically, it depends on the set of all strings that is chosen and hence this is often written as to emphasize this.
- Concatenation of two sets: .
Set ops on one set:
- asterate A* of a set.
- A+ of a set. .
States and transitions
A state of a system gives all the relevant information of a system, like a snapshot. Transitions are changes of states.
If both are finite, then the system is called a finite state transition system. We model them using finite automata.
Deterministic Finite Automata
Formally,
- Q is the finite set of states.
- is the finite set of the input alphabet.
- is the transition function that takes the current state and the input character as the inputs and gives the next state as the output.
- s is the start state.
- F is the finite subset of Q that are acceptable as the final states.
To extend the character input to a string, we define inductively as follows:
Where is a string, is a character, and is the empty input.
These can also be translated to the finite state machines discussed here.
A string is accepted by an automation if
A set or a language accepted by is the set of all strings accepted by some automata , also called . Any subset of is said to be regular if it is accepted by some automaton .
Any finite subset of is regular (brute-force all strings).
Proof that union of two regular languages is regular:
Let DFA 1 be and DFA 2 be
The final automata has the cartesian product of the two sets of states as the set of states (Q), and the delta is also from to . The set of final states is . Also,
Proof the the complement of a regular language is also regular:
All accepted final states become non-accepted, while all non-accepted final states become accepted.
Proof that the intersection of two regular languages is also regular:
Using set properties (De Morgan’s Law), or instead follow the proof of union and replace the final set with .
Non-deterministic Finite Automata
A finite automata where the next state is not necessarily determined by the current state, and the input symbol. It is effectively in a state of guessing.
To show that an automata accepts a set , we argue that there exists a lucky sequence of guesses that lead from the start state to an accept state when the end of is reached, but for any string outside the set, it is impossible.
Formally,
- Q is the finite set of states.
- is the finite set of the input alphabet.
- is the transition function that takes the current state and the input character as the inputs and gives the next state as the output. In this case, there are possible outputs, instead of the possible outputs in case of DFA. Each output corresponds to a unique element in the power set of .
- S is the subset of acceptable states called the start states.
- F is the finite subset of Q that are acceptable as the final states.
To define the acceptance, we use the following rules:
Instead of the usual one state, we have the input to be a subset of the possible state for .
Acceptance happens when satisfies
Proof for Deterministic and Non-deterministic Finite Automata being equivalent:
- First we prove that
Induction on |y|:
For |y| = 0, it is trivially true from the above equations.
Assume for |y| ≤ n,
- Second, the function commutes with the set union, i.e.,
Induction on |x|:
For |x| = 0, it is trivially true.
Assume for |x| ≤ n.
Now the following two automata can be shown to accept the same set.
To create a minimal DFA from an NFA, check the decision tree for the NFA and do a BFS, stopping when you don’t get any new states.
transition
This has an slip that allows the state to transition without reading any input symbol.
Proof that transition NFA’s have an equivalent NFA with just one start state and no transitions.
Defn: closure: The set of all states that a state can reach on an transition.
Define a new transition function such that the states attained by the state with transitions further take one symbol.
For an NFA to be converted to a regular NFA, we define
where is the closure of q.
The final states
Everything else remains the same.
Pattern Matching
- for each , matched by only.
- , matched by the empty string.
- , matched by nothing.
- #, matched by any symbol in .
- , matched by anything in .
Combining patterns
- matches if matches either of those.
- matches if matches both of them.
- matches if matches followed by .
- matches if it doesn’t match .
- matches and the same way as regex.
NOTE:
accepts 010101
accepts 000000 or 111111 but only strings of one symbol
For any pattern , we define to be the language that matches the pattern .
Any regular language can have countably infinite representations in form of patterns.
Theorem: If is a regular expression, then is regular.
Proof: Check for each possible case and all of them can be decomposed into a combination of the above situations.
It is always possible to remove the complement in a regular expression.
DFAs to Regex
- State elimination
- Keep remaining states
- Replace transitions with transitions labelled as regex.
- while true
Class
Theorem: Set of all C Programs is countable.
Proof:
Represent the ascii source code in binary. Then it will be a subset of and that is bijective with the natural numbers (). It is also obviously infinite.
Hilbert’s Entscheidungs Problem: Given a mathematical statement, is it derivable from the axioms?
Defn: A language over an alphabet is a subset of .
Theorem: The cardinality of all the languages over some alphabet is uncountably infinite, i.e., .
Proof:
Cantor’s argument:
Set of all languages =
input | 0 | 1 | 00 | |
---|---|---|---|---|
f() | 1 | 0 | 0 | 1 |
f(0) | 1 | 0 | 0 | 0 |
f(1) | 0 | 0 | 0 | 0 |
f(01) | 1 | 1 | 0 | 1 |
The entries in the table tell whether that particular element is present in the subset is gotten from the result or not.
Take the diagonal and bit flip all bits. It will differ from all the strings in the table by atleast one bit.
Go to top till Deterministic Finite Automata along with a few examples of languages based on the problem.
Limits of DFAs
- DFAs have finite memory.
- They can also only read one symbol at a time from left to right.
For instance, there is no way of constructing a DFA that can accept .
Similarly, there is no DFA that can accept the language
Important Proof
If is regular, where , then is also regular.
Proof:
Let the DFA be . We define the NFA as follows:
where
Pumping Lemma
Let be a regular language. , s.t. s.t. and , s.t. s.t. .
Proof: s.t. .
Set
Let s.t. &
. We define
Consider the sequence
s.t. in the sequence (by PHP).
Define
An analogy with a 2 player game:
Prover: I’ll give you a number k
Spoiler: I’ll find x, y, z such that the concatenation is in the language with length of y > k
Prover: I’ll split y into u, v, w where v is non-empty.
Spoiler: I’ll find an i > 0 such that the pumping lemma string doesn’t belong in the DFA. If I do that, I’ll win. And L will not be regular.
An alternate way to prove that a language is not regular.
Suppose you take a DFA for the language. We take an infinite set of strings such that all of them go to a different state. Then it’s obvious that the DFA cannot be finite and hence, it is not a DFA.
Example:
We claim that any two strings in reach a different state.
Proof:
If this wasn’t true then both the strings will be accepted, which is impossible according to the language.
Distinguishability
Defn: Let be a language. Two strings are said to be distinguishable by if s.t. and .
Defn: A set is distinguishable if and and are distinguishable.
Theorem: Let be a regular language and be a distinguishable set. For any DFA accepting , .
Myhill-Nerode Relations
An equivalence relation over a language is said to be a Myhill-Nerode relation if
- is a right congruence, i.e., if , then .
- is a refinement of , i.e., if then .
- is of finite index.
If is regular and accepts M, then is a Myhill-Nerode relation. It is trivial to see why this is the case.
We define to be the equivalence relation gotten when any two strings end up in the same equivalence class in the language accepted by i.e. .
We define to be the equivalence relation gotten when any two strings and s.t. .
Theorem: Let be an MH relation over .
Then .
Proof:
Minimizing DFAs and Isomorphism
Let and
Let be a bijection such that the following hold:
Theorem: If and are two minimal automatas then they are isomorphic.
Proof:
We define the function to be
Algorithm to minimize the DFA:
States are equivalent if
This is clearly an equivalence relation for the states.
Show that the Myhill-Nerode relation of the Quotient Automata is a superset of the other. Hence the quotient automata is the minimal one.
Algorithm:
Mark any two pairs of states that are clearly not equivalent (one of them is a final state, other is not).
Repeat until no new pairs are marked
If s.t. for some , are marked then mark
Go to pattern matching
Context free languages
Productions: A kind of statement that tells you substitution rule.
Non-terminal strings are strings that can be replaced using productions.
Terminals are ones that can’t be further replaced.
Therefore, CFG is a 4 tuple that is defined using
- is the set of non-terminals (RHS in any production).
- set of terminals
- set of production girls
- start symbol
E.g.
- A string is derivable from if there is a production rule to substitute a non-terminal in and get .
- A string in is known as a sentential form if it is derivable from S.
- A string in is a sentence if it is derivable from .
Example: Dyck language (balanced parentheses)
[[][[]][[]]] is in L but []] is not
Theorem: For a regular language , there exists grammar s.t.
Construction:
Further proof:
if then goes to
Base case: then
then productions
induct on the length of the derivation
Ambiguous CFGs
These are those for which there are more than one parse trees. It is ambiguous if it has more than one leftmost derivation. Use multiple rules to resolve amiguousness.
However some languages are inherently ambiguous.
basically no possible grammar can make it unambiguous.
Closure properties
Closed under union, concatenation, kleene closure.
NOT CLOSED under intersection and complementation.
Chomsky Normal form
A CFG G is in CNF if every production is of the form or
CNF grammars do not generate
-
Remove
- For every production , add
-
Remove
- with
First remove all the productions as they give more unit productions.
Then remove all unit productions.
This gives the minimum size grammar in CNF.
Pumping Lemma
This is based on the fact that (almost) all languages are convertible to CNF. If we have a path from the root node to a leaf node in the parse tree that is greater than , i.e., where is the length of the string and is the number of non-terminals in the productions.
By PHP, we can clearly see that a symbol is going to be repeated. So we can repeat the entire length in the path, and the parse tree will still be valid. This is the pumping we do.
For every CFL s.t. s.t. s.t. with and s.t. .
Contrapositive form:
If s.t. with and s.t. , s.t. then L is not context—free.
Prover and Spoiler:
-
Prover picks k > 0
-
Spoiler chooses the string
-
Prover chooses a split that he wants
-
Spoiler finds the i for which pumped string is outside the language.
Parsing Algorithms for CFGs — Cocke Kasami Younger
Assumptions: G is in CNF
Goal: Given , check if
s.t. for some
Try out all possible choices of and check if and match. This is done recursively.
Push Down Automata (non-deterministic)
Basically and NFA with a stack and a stack alphabet.
These are in the order = start state, alphabet of the string, alphabet of the stack (string alphabet + non-terminals), transition function, initial state of the stack, and the final states.
If then we read from the string, pop from the stack, and push all of
If Read nothing but do the pushing and the popping.
Acceptance happens when it reaches a final state on reading the entire string.
Alternatively, empty stack acceptance happens when the string becomes empty and makes the stack empty as well.
Converting CFGs to PDAs
Define
For a production , add stack transition
Add transition
Add transition
This PDA obviously accepts the CFG using empty staack acceptance as a basis.
Converting from PDAs to CFGs
TL;DR: Absolute pain in the ass
If you have a PDA with a single state that accepts using an empty stack:
If then add the production
Nothing pushed on the stack case needs to be handled separately.
To convert a general PDA with a single final state to a PDA that accepts with the empty stack:
Let
We define
Here
Over here, both the Q’s are guesses for us, and we keep on guessing the entire sequence of things that are happening and put it on the stack. So we have an exponential number of items pushed onto the stack.
Suppose you are at state with on the input string and the contents on the top of the stack were . You transition to and the stack is now . For each of those you add a guess to the new PDA stack with surrounding states and so on upto . Here is equal to .
Effective Computability
Multiple notions of effective computability:
- calculus
- recursive functions
- Turing Machines
Church Turing thesis: Any physically reaslisable computationally device can be simulated by a Turing machine.
Turing Machines
These are in the order state, string alphabet, tape alphabet, left end of the tape, blank symbol on the tape, transition, accept state and reject state.
where the first parentheses denotes the current state and the current symbol under the tape.
The right parentheses tells you the next state to go to, and the symbol to be written, and whether to move left or right.
Constraints:
- If you are on the left delimiter of the tape you can only move to the right.
- If you are on the accept/reject states, you are stuck there.
Configurations of a Turing Machine: . These are, in order, current state, tape content, and the position of the tape head.
- Initial contents are
- Acceptance happens when
- Rejection happens when
An accepted language by a turing machine is called recursively enumerable (re). If it is a total turing machine then it is called recursive.
A total turing machine is one that eithers accepts a string or rejects a string. There is no string on which it never accepts and never rejects. (Basically loops forever on the tape)
A Multi tape turing machine, as it sounds, is a Turing Machine with multiple tapes. It is also possible to simulate a multi tape turing machine using a Turing Machine with a single tape.
Rough outline of how it happens:
- The number of tapes is , and the number of states is , and the size of the alphabet is .
- Our new Turing Machine has pre filled tape cells.
- The tape alphabet is also enlarged similarly.
- The characters are now encoded in the new tape in such a way that it contains all possible combinations of the first tape characters in index 0, second tape characters in index 1, and so on.
- Finally, in a transition, it sweeps across the entire tape and finds where the character is.
- Once that happens, the tape head sweeps backwards to update the letters that were updated.
A Universal Turing Machine has 3 tapes, one for the encoding of the TM it is trying to simulate, one for the tape of TM it is simulating, and one to store the states and positions of said turing machines.
Theorem: a universal TM
Membership Problem: Given a TM and , check if accepts .
The language of this problem is r.e. (this is a fact).
Halting Problem: Check if halts on .
The language of this problem is r.e. (this is a fact).
Property: If is both r.e. and co-r.e., then it is recursive. (co-r.e. means complement is recursive)
Proof: Simulate both on a single turing machine. Whichever accepts, halt and accept/reject accordingly.
Enumeration Machines
These have no input, there is no need to halt, one work tape and one output tape, there is a special print state that prints the contents of the output tape, clears it and then exits the state.
A language is r.e. iff there exists an E.M. for it. This is equivalent to a time sharing simulation of M.
Undecidability and Diagonalization
Theorem(Turing): HP is not recursive.
Let be the Turing Machine that is encoded by the string . If no such thing exists, then let it be the trivial TM accepting everything.
This way, we get a list of turing machines. Let us assume that this is the complete list of turing machines.
Now consider a 2D matrix containing strings in the row header and TMs in the column header. The cell says H if the machine halts on the string and L if it loops forever. If our assumption that the list of turing machines being complete is true, then we can always do this table.
Suppose there is a universal Turing machine that halts and accepts if halts on and halts and rejects if loops on .
Consider a universal machine that takes input and runs on . If rejects the input then accepts it and if accepts it then goes into a loop.
If halts on rejects loops on . This implies that differs from each row of the table at the diagonal. However the list contained every Turing Machine in existence, so the assumption that the table entries are determinable is wrong.
Reductions
If a problem is solvable by making a subroutine call to another problem , we say that the problem is reducible to another problem .
Basically all the following are equivalent:
-
if B is True: A is True else: A is False
-
is reducible to
-
-
can be solved by a subroutine call to
Many-one reductions can be used to prove that something is not recognizable (or vice-versa). In that case only one subroutine call is allowed and the result has to be passed as-is by the outer machine.
In case you are generating a description of a machine from the input machine, the function that you use to generate the description must be computable and total.
Also, if , then .
Turing reductions are more lax in their rules, allowing multiple subroutine calls and modifying the output. However, they can only be used to demonstrate recursiveness (or the lack of it).
Examples of undecidable problems
Given a TM and a string , decide if accepts .
Proof:
Create a turing machine that takes input and decides whether accepts .
Create a machine that does the opposite of what does when given input
with the input will cause a contradiction.
Therefore cannot exist.
Undecidability of the Halting Problem using Reduction from TM acceptance
Proof:
If tell you that it halts, then we can run the simulation in a universal turing machine and see the acceptance. If tells you that it doesn’t halt, then you can say no for acceptance. Therefore, if the halting problem is solvable, then the acceptance problem is also solvable. But we know for a fact that acceptance problem isn’t solvable.
Check if a language of a turing machine is empty being undecidable
Proof:
We modify the machine and create a machine .
If is empty, then it returns false. If is non-empty, then it checks if is in the language or not.
We use the description of to feed into the checker for that checks if the language is empty or not. Inverting the output of the checker can give us the output of the checker of Acceptance problem.
Note that the checker for need not necessarily run the machine description. It only deduces that based on some heuristics that are not our concern. We do not have to find the machine that does that, only prove it does not exist. For which we assume the contrary.
Check if a a language of a turing machine is regular or not being undecidable
Proof:
We have a machine that decides whether a TM description is regular or not.
We need to create a machine that decides whether the input will be accepted or not.
We create from and runs on and gives us “true” if the input to , i.e. has the form else it gives “true” if gives “true” on .
Carefully observe what this is doing. When accepts , its language is , otherwise it is . So the regular language decider will give “true” if accepts and “false” otherwise.
We feed this description of to the decider and use the output as the output of .
Proof of two machines having equal languages being undecidable
Suppose a decider for the above problem exists. It takes and gives “true” if they are equal. Run it with where rejects everything and is the input to the decider of the empty language problem will solve the empty language problem.