ΘρϵηΠατπ

The Set of All Possible Finite Tuples
Suppose that X is a set, then we denote the set of all possible finite tuples as X=n0Xn
The Set of All Strings Over a Finite Alphabet Is Countable
TODO: Add the content for the proposition here.
There are only |X|n possible strings of length n therefore the above is a countable union of finite sets and thus countable.

Note that in the context of computers we will usually refer to tuples as strings, so instead of writing something like (0,1,2,3,4) we instead just write "01234" to represent the same thing.

Finite Automaton
A finite automaton is a 5-tuple Q,Σ,δ,q0,F,I where
  1. Q is a finite set called the states
  2. Σ is a finite set called the alphabet
  3. I=Σ is the set of possible inputs
  4. δ:Q×ΣQ is a finite set called the transition function
  5. q0Q is the start state
  6. FQ is the set of accept states

Note that when k=0 then we get () as a possible input, which it the empty tuple, we denote this as ϵ.

Machine
A machine is a finite automaton.
Output of a Finite Automaton on an Input
Suppose that M is a machine and a=(a1,,ak) is a finite sequence of elements from MΣ then we define the following:
  • if 1nk then on=δ(on1,an)
  • o0=q0
and define the output of M after processing a as ok which is denoted by out(M,a)
Compute Sequence of an Input for a Finite Automaton
Suppose that M is a machine and a=(a1,,ak) is a finite sequence of elements from MΣ, then we define its compute sequence as compseq(M,a)=(o0,o1,,ok) and note that |compseq(M,a)|=|a|+1
A Finite Automaton Accepts an Input
Suppose that M is a machine and a=(a1,,ak) is a finite sequence of elements from MΣ then we say that M accepts a iff: out(M,a)MF
A Finite Automaton Rejects an Input
Suppose that M is a machine and a=(a1,,ak) is a finite sequence of elements from MΣ then we say that M accepts a iff it does not accept it, and we write acc(M,a)
Language
A language L is simply a set of tuples.
Language Legible for a Machine
Suppose that M is a finite automaton, and that L is a language, we say that L is legible for M is LMI.

If a langauge is not legible by a particlular machine, then there will exists an input x in the language such that out(M,x) is not well defined, thus in those cases we cannot say much about the language.

Language of a Finite Automaton
lang(M)={aMI:acc(M,a)}
A Finite Automaton Models a Language
Given a legible language A for M, we say that M models A iff A=lang(M)
DFA That Recognizes Everything Except 11 and 111
Give a state diagram of a DFA that regonizes the following language over the alphabet Σ={0,1} {wΣ:w{11,111}}

We claim that the following DFA works:

q₁ q₂ q₃ q₄ q₅ 1 1 1 0 0 0 0 0, 1
DFA That Regonizes Only 0 and the Empty String
Give a state diagram of a DFA that regonizes the following language over the alphabet Σ={0,1} {0,ϵ}
q₁ q₂ q₃ 0 0, 1 1 0, 1
Dfa That Recognizes Even Number of Zeros or Exactly Two 1s
Give a state diagram of a DFA that regonizes the following language over the alphabet Σ={0,1} {walltup(Σ):even(count(w,0))count(w,1)=2}
q₂ q₄ q₆ q₁ q₃ q₅ q₈ q₇ 1 1 1 0 1 1 1 0 0 0 0 0 0 0 1 1
Regular Language
Suppose that L is a language, then we say that it is regular iff there exists a finite automaton M that recognizes it. We denote this by reg(L), in symbols that is: reg(L)M,lang(M)=L
Concatenation of Two Languages
AB={concat(x,y):xA,yB}
Concatenation of Languages Is Associative
(AB)C=A(BC)
TODO: Add the proof here.
Star of a Language
A={concat(x1,,xk):k0,xiA}

Note that when k=0 then an empty concatenation is defined as ϵ so that the star of any lanuage will always contain ϵ.

Nondeterministic Finite Automaton
A nondeterministic finite automaton is a 6-tuple Q,Σ,δ,q0,F,I where
  1. Q is a finite set called the states
  2. Σ is a finite set called the alphabet
  3. I={(a1,,ak):k0,aiΣ} is the set of possible inputs
  4. δ:Q×ΣϵP(Q) is the transition function
  5. q0Q is the start state
  6. FQ is the set of accept states

A NFA is shorthand for the above, to differentiate we call a finite automaton as a DFA where the D stands for deterministic. Additionally sometimes when drawing these out, then you'll notice that sometimes for a given state there is not an arrow for each character in the alphabet, whenever this is the case it means that δ(q,a)= which means that there is no transition from starting at q and reading a, this means that an NFA can get "stuck" this is when it is not possible for the NFA to read in the next state in any possible context.

Multiple State Transition Function
Given an NFA N, cΣN and any RQN we define the following overloaded function: δ(R,c)=rRδ(r,c)

One visual that helps me remember the above is like you're trakcing the whereabouts of multiple trains in a subway station, you want to get on one of the trains as fast as possible, so you see what stations they'll be at next, so you can get on at the nearest station, tha above takes in the collection of train stations they're at now, and tells you where they'll be next.

Epsilon Reachable States
Suppose that N is an NFA and RQN then we define the set of reachable states from R by travelling along 0 or more epsilon arrows by: ϵ(R)

Note that ϵ(AB)=ϵ(A)ϵ(B) and that ϵ(R)R

Epsilon Reachable Multiple State Transition Function
Given an NFA N, cΣN and any RQN we define δϵ(R,c)=ϵ(δ(R,a))
Every DFA Is an NFA
Every DFA can trivially be converted to an equivalent NFA
Suppose we have a DFA, then construct an NFA as follows
  • Q=Q
  • Q=Q
  • Σ=Σ
  • Σ=Σ
  • δ(q,a)={δ(q,a)}
  • q0=

Then given a string sΣ then by induction we can prove that |compseq(D,s)|=|compseq(N,s)| and for any valid k1 compseq(D,s)k=compseq(N,s)k, thus out(D,s)=out(N,s) so we can conclude that so acc(D,s)acc(N,s) showing that lang(D)=lang(N)

Conversion of an NFA to a DFA
Convert the following NFA to a DFA: 1 2 3 e a a, b b a
As per the conversion process, we set Q=𝒫(Q), and then for any RQ and cΣ we define our transition function by δϵ(R).
  • δϵ({1,2},a)=ϵ({1,3})={1,2,3}
  • δϵ({1,2},b)=ϵ()=
  • δϵ({1,2,3},a)={1,2,3}
  • δϵ({1,2,3},b)=ϵ({2,3})={2,3}
  • δϵ({2,3},a)=ϵ({1,2})={1,2}
  • δϵ({2,3},b)={2,3}
  • δϵ(,a)==δϵ(,b)

Note that we could analyze what it does to other states, but they will not be reachable in the final diagram and thus can be removed, this is true because we explored the graph starting at the root following the BFS algorithm which we know will entirely explore all reachable states, thus here is the final simplified NFA:

{1,2} {1, 2, 3} {} {2, 3} a b a, b a b b a
Every Language Modelled by a DFA Is Modelled by an NFA
As per title.
Since for every DFA, there is a trivial conversion to an equivalent NFA, then if a language L is modelled by some DFA D, so that lang(D)=L then since given our eqiuvalent NFA N which is to say that lang(N)=lang(D) then we conclude that lang(N)=L showing that N models L .
Machine
A machine is a DFA or a NFA
Two Machines Are Equivalent
We say that M1,M2 are equivalent iff lang(M1)=lang(M2)
Every Language Recognized by an NFA Is Recognized by a DFA
As per title.
TODO: Add the proof here.
A Language Is Regular Iff There Is an NFA That Recognizes It
reg(A)N,lang(N)=A

Suppose that there exists an NFA N such that rec(N,A), then by the above theorem there exists some DFA D such that rec(D,A) therefore reg(A) .

The other direction is simpler since reg(A) then there exists some DFA D such that rec(D,A) but a DFA is an NFA so then we've shown that there is some NFA that recognizes A as needed.

Because this is true it means that a language is regular iff there is an NFA or DFA which recognizes it.

Regular Languages Are Recognized Under Intersection
Suppose that reg(A) and reg(B) then reg(AB)
This is simply true beucase ABA,B therefore both machines will recognize a subset of a language they already recognize.
Regular Languages Are Closed Under Union
Suppose that reg(A) and reg(B) then reg(AB)
TODO: Add the proof here.
Regular Languages Are Closed Under Concatenation
Suppose that reg(A) and reg(B) then reg(AB)
TODO: Add the proof here.
Regular Languages Are Closed Under the Star Operation
Suppose that reg(A) then reg(A)
TODO: Add the proof here.
Regular Languages Are Closed Under Complementation
reg(A)reg(ΣL)
TODO: Add the proof here.
Regular Languages Are Closed Under Intersection
reg(A)reg(B)reg(AB)
TODO: Add the proof here.
Reversal of a Lanuage
Suppose that A is a language, then we define the reverse of the language by A={rev(a):aA}
Regular Languages Are Closed Under Reversal
reg(A)reg(A)
TODO: Add the proof here.
Homomorphism From One Alphabet to Strings Over Another
A homomorphism from one alphabet to strings over another is a function f:ΣΓ from one alphabet to strings over another alphabet. We can extend f to operate on strings by defining f(w)= f(w1)f(w2)f(wn), where w=w1w2wn and each wiΣ. We further extend f to operate on languages by defining f(A)={f(w)|wA}, for any language A.

It was defined as above to allow you to map single characters from an alpabet to strings of another to be more general from the get go, but you can certainly have homomorphisms from characters of one alphabet to characters of another alphabet just the same.

Regular Languages Are Closed Under Homomorphism
Suppose that f is a homomorphism, then reg(A)reg(f(A))
TODO: Add the proof here.
Regular Languages Are Closed Under the Inverse Image of a Homomorphism
Suppose that f is a homomorphism, then reg(A)reg(f1(A))
TODO: Add the proof here.
Regular Languages Are Closed Under Perfect Shuffle
For languages A and B, let the perfect shuffle of A and B be the language perfectshuffle(A,B) defined as: {w|w=a1b1akbk where a1akA and b1bkB each ai,biΣ} Show that reg(A)reg(B)reg(perfectshuffle(A,B))

Instead of making an explicit construction we will instead use the fact that regular languages are closed under intersection and homomorphisms to prove that the shuffle is regular.

But now if we consider X=left1(A), then where the last condition a1anA comes about because we require that left((a1,b1)(an,bn))=left(a1an,b1bn)=a1anA Note that since left is a homomorphism and reg(A) then we have reg(left1(A)) equivalently reg(X)

Analgously we find that Y=right1(B)={(a1,b1)(an,bn):n0,(ai,bi)Σ×Σ s.t. b1bnB} is regular. Now since we have XY={(a1,b1)(an,bn):n0,(ai,bi)Σ×Σ s.t. a1anA,b1bnB} Then the homomorphism unpack:(Σ×Σ)Σ defined as unpack((a,b))=ab (it is a homomorphism, because unpack((a,b)(c,d))=acbd and you can check the rest), is interesting because it threads them one by one, so that unpack(XY)=perfectshuffle(A,B) Since we know that reg(X) and reg(Y) and that regular languages are closed under homomorphism and intersection we conclude that perfectshuffle(A,B) is regular.

The Language of Binary Digits Divisible by a Constant Is Regular
Suppose that n1, then the language Cn={x:x is a binary number such that ,n|x} is regular.

Before we continue we cast away two trivial cases, when n=1, then since every number is divisible by 1, then we construct a trivial DFA with one state which is the accept state and all arrows point back towards itself. The case of n=2 can also be disposed of quite quickly as we can construct a two state dfa, where we start in the accept state, and if we read a one, we got to or stay in the non-accept state, if we read a zero we go back and stay inside the accept state, this will work because our DFA reads from left to right, and the last digit of a binary number is at the right, and a binary number is odd iff the last digit is one, therefore this DFA would only ever be in the non-accept state if the last read digit is one, as needed.

We construct a DFA as follows, we have states q0,q1,,qn1 where qi will be the state when the currently read in binary number b has remainder i mod n that is b % n=i , to make this claim true, we define our transition function as follows δ(qj,0)=q(2j) % n and δ(qj,1)=q(2j+1) % n

We do this because when we read the next binary number it pushes all previous number one power higher (ie multiply by two), and then based on if that new digit is one or zero it adds on as well.

Note that given a number k1 then its true that (ak+b) % n=((a % n)(k % n)+b % n) % n, since in this case we know that n3 and actually a=2 and b{0,1} then a % n=a and b % n=b so we have (2k+b) % n=(2(k % n)+b) % n

This shows that the remainder of multiplying k by 2 and then either adding 0 or 1 is the same as multiplying k % n by 2 and then adding 0 or 1, by induction this property holds when iterated, thus this shows that our construction of the transition function actually satisfies the claim that qi is the state when the currently read in binary number b has remainder i mod n, therefore after reading the entire number if it has remainder r mod n the DFA will be on state qr thus by only making q0 the accept state our DFA is correct, and so Cn is regular.

Regular Expression
We say that a language R is a regular expression over an alphabet Σ if R equals to:
  • {a} for some a in the alphabet Σ
  • {ϵ}
  • The union of two regular expressions R1,R2, denoted by (R1R2)
  • The concatentation of two regular expressions R1,R2 denoted by (R1R2)
  • The star of a regular expression R1 denoted by (R1)
The Set of All Regexes Over an Alphabet
Suppose that Σ is an alphabet, then we denote all possible regexes over Σ as RX(Σ)
Regular Expression Shorthand
Suppose that R1,RkRX(Σ) , then we develop the following shorthand to write out regular expressions easier:
  • (R1R2Rk)=R1R2Rk
A Regular Expression Is a Regular Language
For any language L: LRX(Σ)reg(L)

Given a regular expression LRX(Σ) we show that there is an NFA N that models L thus showing that L would be regular.

Since the definition of a regular language is recursive by nature we split cases on the possibilities and complete the proof using structural induction.

The first case is if R={a} for aΣ, if that's the case then a two state NFA N with a start state on the left, and an accept state on the right, with a single transition when the letter a is read will work, as lang(N)={a}. Formally we have N=({q1,q2},Σ,δ,q1,{q2}) where δ(q1,a)={q2} and δ(r,b)= for rq1 or ba

If R={ϵ} then N=({q1},Σ,δ,q1,{q1}) with δ(r,b)= for any r,b, then lang(N)={ϵ}

If R= then N=({q},Σ,δ,q,) with δ(r,b)= for any r,b

Now by structural induction suppose that R1,R2RX(Σ) such that reg(R1) and reg(R2).

If R=R1R2 then since regular languages are closed under union, we have that reg(R).

If R=R1R2, since regular languages are closed under concatenation then reg(R)

If R=R1, since regular languages are closed under the star operation then reg(R)

Thus by structural induction we can conclude that the statement holds true.

Generlized Nondeterministic Finite Automaton
A generalized nondeterministic finite automaton is a 6-tuple Q,Σ,δ,q0,F,I where
  1. Q is a finite set called the states
  2. Σ is a finite set called the alphabet
  3. I={(a1,,ak):k0,aiΣ} is the set of possible inputs
  4. δ:(E{qaccept})×(Q{qstart})RX(Σ) is the transition function
  5. qstartQ is the start state
  6. qacceptQ is the accept state
For Every Dfa There Is an Equivalent Gnfa
TODO: Add the content for the lemma here.
TODO: Add the proof here.
The Language of Any GNFA Equals Some Regular Expression
For any GNFA G, there exists some LRX(Σ) such that lang(G)=L
TODO: Add the proof here.
If a Language Is Regular Then It Is a Regular Expression
Suppose that L is a language over Σ, then reg(L)LRX(Σ)
TODO: Add the proof here.
A Language Is Regular Iff It Equals a Regular Expression
Let Σ be an alphabet, and let L be a language over that alphabet, then reg(L)RRX(Σ),L=R
TODO: Add the proof here.
Pumping
If reg(A) then there exists p1 such that if sA such that |s|p there exists x,y,z such that s=xyz where
  1. for every i0 we have xyizA
  2. |y|>0
  3. |xy|p

Let M=(Q,Σ,δ,q1,F) be a DFA recognizing A then we set p=|Q|. Now suppose that sA such that |s|p, since |compseq(M,s)|=|s|+1 then we know that |compseq(M,s)|>p, so that by the pigeonhole principle there must exist a duplicated state qdcompseq(M,s).

Thus compseq(M,s)=(q0,,qb,qd,qd,,qk) where we note that qkF as rec(M,L), so now let s=xyz where qd is the first instance of the duplicate compseq(M,x)=(q0,,qd) for y the part between the duplicates: compseq(M,y,qd)=(qd,,qd) for z the part after the duplicate: compseq(M,z,qd)=(qd,,qk)

Now we claim that the three properties hold true, for the first property let i0 and so if i=0, then we know that we're looking at the string xz which is accepted as compseq(M,xz)=concat(compseq(M,x),compseq(M,z,qd)[1:]) because on the sequence on the right ends in a accept state. Whenever i1 then in a similar manner compseq(M,xyiz)=concat(compseq(M,x),(compseq(M,y,qd)[1:])i,compseq(M,z,qd)[1:]) for the same reason, the sequence on the right ends in an accept state, so the first property holds true.

The reason why |y|>0 is because in order to move to another state you must process a character, since we encounter qd twice, it means that we must read at least one character to do this.

We know that it's guarenteed that within the first p+1 states there must be a repeated state due to the pigeon hole principle, and add to our assumptions that qd is the first repetition in the sequence, then we know that

Pumping for Non-Regularity

While the pumping lemma gives us a characterization about strings of regular languages it also provides us a way of determining when something is not regular, for example if we wanted to show that a language was not regular, we would assume for the sake of contradiction that it was regular and thus there would exists some p such that any string of length greaer or equal to p would have the three properties.

Thus we can obtain our contradiction by constructing a string of length greater than p which does not satisfy all the conditions. Most of the time condition one provides the most flexibility, because if we choose our input string in a smart way, then ew cna raise y to a power which creates a string which is no longer part of the input language. This is a common technique to prove that a language is not regular.

Pumping Lemma Choice of DFA
If reg(A) and any DFA D recognizing A with p states, such that then for any sA with |s|p there exists x,y,z such that s=xyz where
  • for every i0 we have xyizA
  • |y|>0
  • |xy|p
TODO: Add the proof here.
For Any k There Is a Binary Language and a DFA With K States That Recognizes It, but No DFA With K - 1 States That Recognizes It
For every k2 there exists a language Ak{0,1} and a DFA with k states that recognizes it, but no DFA with k1 states that recognizes it.

Let k2 and consider the language given by Ak={s{0,1}:substr(0k1,s)} that is the set of strings that have 0 ^ \left( k - 1 \right) ParseError: Got function '\left' with no arguments as superscript at position 5: 0 ^ \̲l̲e̲f̲t̲( k - 1 \right) as a substring.

Clearly there is a DFA with k states which recognizes this language, the DFA constructed by having k states all in a line, with the last state being an accept state, and chained together with arrows which allow movement when reading a 0, and sent back to the initial state whenever a 1 is read, the only way to get to the end state is to read in k1 consecutive zeros, which is the exact condition on having 0k1 as a substring.

On the other hand if we assume for the sake of contradiction that there was a DFA C with k1 states which could recognize Ak there will be a problem. Since Ak is a subset of a regular language then it is regular, thus using the above corollary from the pumping lemma, since C is a DFA with k1 states that recognizes Ak and 0k1 is a string with length greater or equal to k1 then by the pumping lemma there exists x,y,z such that 0k1=xyz, along with the three properties.

By the second property we know that |y|0 therefore y=0j for some j1 and that which implies xz=0k1j simply because when all three are concatentated together we must get 0k1, but then based on the first property we have that xyizAk for any i0 so specifically if we choose i=0 then we know that xzAk but this is a problem because xz=0k1j and j1 so that xz is a sequence of m zeros where m<k1 but clearly 0k1 could not be a substring of this, therefore xzAk, this is a contradiction, therefore no such DFA must exist.

TODO come back to the above later on

In english the above lemma is saying that whenever you have a regular language, there is a threshold wherein given a string in length exceeding that threshold then it can be decomposed in into three pieces such that the middle piece can be duplicated over and over, and the string remains part of that regular language (under two other small conditions).

Rotational Closure of a Language
RC(A)={yx:xyA}

Intuitively this is allowing you to split an string in A and then glue it the other way around.

The Rotational Closure Only Applies Once
RC(A)=RC(RC(A))

Note that since for any xA we have ϵxA therefore xϵ=xRC(A) showing that ARC(A), moreover that holds in general for any set A, so therefore we have RC(A)RC(RC(A))

Now suppose that aRC(RC(A)) and we want to prove that aRC(A). By assumption we know that if a=yx then xyRC(A) if that's true then we can split that string and glue it in reverse order and it would have to be an element of A, there are a few cases, that is xyRC(A) iff

  1. xy=xaxby and xbyxaA
  2. xy=xyayb and ybxyaA
If 1 holds true then we can "undo" it because xaxby=xyRC(A) as needed, similarly if 2 holds true we can also say that xyaybRC(A) in either case we've shown that a=xyRC(A) thus we have both inclusions so the sets are equal.

Regular Languages Are Closed Under Rotaitional Closure
reg(A)reg(RC(A))

Since reg(A) then there is a DFA D that recognizes A, we first come up with an idea for a single string and show how to extend it to all strings.

Given the string aRC(A) then we know that it means that a=xy for some x,yΣ where xyA, since L(D)=A then we know that xy is accepted by D, therefore after reading x the DFA D will be at some state q1 and then after reading y it should end up in an accept state.

We construct an NFA by extending the DFA by running the DFA from q1 (since a DFA is an NFA this is fine), once we get to the accepting state add an epsilon transition back to the start state of the DFA and continue running the logic of the DFA, if the NFA ends back at at state q1 after reading y this would only be true if xyA=L(D).

To generalize this to work for all possible strings we allow any state to take the place of q1 , to allow the NFA to start and end at q1 we duplicate our DFA once for each state and add epslion transitions for each accepting state back to the start state, then to finish the generalization we have our start state and provide an epslion transition to all of the other states.

Context Free Grammar
A context-free grammar is a 4-tuple (V,Σ,R,S) sucht that
  • V is a finite set called the variables
  • Σ is a finite set, disjoint from V called the terminals
  • R is a tuple of the form (v,Y) where vV and Y=(y1,,yn) is a sequence of elements from (VΣ) which is notated by vy1|y2||yn
  • An SV which is the start variable
Application of a Rule to a Variable
Suppose that YVΣ and a rule R=Yy1|y2||yn, then we define app(R,x)={{y1,,yn,x} if x=Y{x} otherwise

Note that if a rule matches we also allow for app, to not do anything by adding in x to the set it evaluates to.

One Layer Productions of a Rule
Suppose X(VΣ) where X=(x1,,xk) and we have a rule Ry1|y2||yn, we define olprod(R,X)=app(R,xi)××app(R,xk) and note that olprod(R,X):(VΣ)(VΣ)

Note that we have ABCDolprod(XA|B|C|D,XXXX), but sometimes we want to only allow one rule to be applied at a time.

The above definition captures all the possible strings that you can produce given a string in your CFG and then applying a specific rule. We now overload the noatation to show all possible productions using all rules for a specific string:

One Layer Productions for All Rules
Suppose X(VΣ) with rules R1,,Rn, then we define olprod({R1,,Rn},X)=i=1nolprod(Ri,X)

Now we have to generalize this definition to be able to recursively apply onto a string, and not just one layer

Productions of a String
Suppose X(VΣ) for a CFG with rules R , then we define via function composition prod(X)=i=1olprodi(X,R)
Language of a Context Free Grammar
lang(C)=prod(S)Σ

Note that this implies that for any xlang(C) there is at least one sequence of rules R1,,Rk such that xolprod(Rk,olprod(Rk1olprod(R1,S)),)

Note that sometimes productions can result in strings which are not all terminal symbols, therefore a language of a CFG are those productions which are entirely terminal symbols.

Note that sometimes we will want to be able to count the number of steps required to derive a string from a CFG, in that case it can be hard to deduce how many steps would be required to make the derivation because so many characters could change in of the one layer productions, so we instroduce the yields of a rule, which only allow one character to change

One Layer Yields of a Rule
ylds(R,x)={yolprod(R,x)hamdist(x,y)=1}

Note that we may use ylds instead of olprod and receive the same langauge.

Derivation
A derivation is a string that is produced by a sequence of yields.
A Language Is Context Free
We say that a given language L is context free if there is some CFG C such that lang(C)=L and we write cf(L)
Context Free Languages Are Closed Under Union
cf(A)cf(B)cf(AB)

Since cf(A) and cf(B), then we have CFGs CA and CB such that lang(CA)=A and lang(CB)=B. We construct a new CFG C such that lang(C)=AB, we do so by first differentiating varibles in each grammar for A and B, we do so by subscripting each variable with A,B respectively, and then setting our variables as the union of the the variables in both, and also unioning the rules in both, then we tack on one rule which is SSA|SB.

proof that this actually generates what we expect.

Star Is Context Free
Suppose that A is finite, then A is context free.
We define the following CFG C
  • V={S}
  • Σ=A
  • Since A is finite, then A={a1,a2,,ak} and then we define the single rule: Sa1S|a2S||akS|ϵ

Now given any element xA then x=(af(1),af(j)) for some function f and some j thus by sequentially picking the associated rule of the form Saf(i), then then using the epsilon rule, we've shown that Alang(C)

The other direction is obvious since lang(C)=prod(S)AA

Context Free Grammar for the Language of Binary Strings Whcich Start and End With the Same Character
Construct a CFG C such that lang(C)={w{0,1}:s[0]=s[1]} Note that 0,1 are in the above language
We construct C
  • Σ={0,1}
  • We take inspiration from the CFG which generates the star, and introduce one extra rule
    • S0X0|1X1|0|1
    • X0X|1X|ϵ

We claim that lang(C) is the desired set, so suppose that s is a string in the desired set, and if it is any of {0,1} it is immediately in the generated langugae by rule 1. Otherwise it is a string of the form 0z0 or 1z1, where z{0,1} and we proved previously that that rule X alone will generate {0,1} then we know that the second rule will match z as needed. We've just shown that any string from the desired set is in the language.

Now if we instead suppose that we have any xlang(C), then we have to show that its in the desired set, since lang(C)=prod(S){0,1} then any element in there is produced by starting with the first rule and then any sequence of rules, but rule one, automatically guarentees that the first and last character are the same as any subsequent rules cannot modify the first and last character of the string so therefore lang(C) is a subset of the desired set, showing that the two sets are equal as required.

For Every Dfa There Is an Equivalent Cfg
Suppose that D is a DFA, then there exists a CFG C such that lang(D)=lang(C)

Make a variable Ri for each state qi in the DFA. Add the rule RiaRj to the CFG if δ(qi,a)=qj is a transition in the DFA. Add the rule Riϵ if qi is an accept state of the DFA. Make R0 the start variable of the grammaer, where q0 is the start state of the machine.

Chomsky Normal Form
A CFG is in Chomsky normal form if every rule is of the form
  • ABC
  • Aa
  • Sϵ
Where A,B,CV{S} and aΣ, and we write cnf(C)
Every Context Free Language is Equivalent to a Context Free Language in Chomsky Normal Form
For every CFG C there exists a CFG B such that cnf(B) and lang(C)=lang(B)

We lay out an iterative process which constructs a new grammar in Chomsky Normal form as follows:

We first define our set of rules R0=R×{T,F} to be the original set of rules, where T means we've processed the rule and F means we haven't. We first add a new start variable S0 and the rule S0S, ie R1=R0{((S0,S),T)} where S was the original start variable.

Now for each element in Ri of the form ((vϵ),F), then we get all rules of the form ((v2A),F) where vA then we add the rules olprod((vϵ),A) and remove ((v,ϵ),F). On each iteration the number of epsilon rules goes down by one, thus after a finite number of iterations there will be no more epsilon rules of the form (vϵ,F) although there may be epsilon rules of the form ((vϵ),T) which is ok.

Next we remove all rules of the form (vw,F) which are rules which map a variable to a variable, we do so by finding all rules of the form (wW,_) and add the rule (vW), unless this rule was previoulsy removed (TODO define the removed set)

Finally we convert all the remaining rules to the proper form, the remaining possibilities of rules that need conversion are rules

  • vW where W(VΣ),|W|3
  • vxy where x,yΣ

For the first case since W=(w1,,wk) where k3

For the second case we just replce the terminals with rules pointint to them.

Chomsky Conversion
Consider the following grammar:
  • ABAB|B|ϵ
  • B00|ϵ
find an equivalent grammar in Chomsky Normal form.
Our initial rules are:
  • AABA
  • AB
  • Aϵ
  • B00
  • Bϵ
we start by removing Bϵ based on the conversion algorithm tue rules of interested are AB,AABA, now we have (note that olprod are all the "one layer" productions of a rule against a string) olprod(Bϵ,B)={B,ϵ} and olprod(Bϵ,ABA)={ABA,AA} Thus the rule AB becomes AB|ϵ and the rule AABA becomes AABA|AA thus the current set of rules are
  • AABA
  • AB
  • Aϵ
  • AAA
  • B00

Now we remove the rule Aϵ the rules of interest are AABA and AAA we have: olprod(Aϵ,ABA)={ABA,BA,AB,B} and olprod(Aϵ,AA)={AA,A,ϵ} so the current set of rules becomes

  • AABA
  • AAB
  • ABA
  • AB
  • AAA
  • B00
note that the rule AA was not added as it does nothing, and the rule Aϵ was not added as it was removed previously

Since all epsilon rules have been eliminated we start remove variable to variable rules, we start with the rule AB the only rule of interest is B00 then our rules become

  • S0A|ϵ
  • ABAB|BA|AB|00|BB
  • B00

Another unit rule is S0A, the rules thus this generates

  • S0BAB|BA|AB|00|BB|ϵ
  • ABAB|BA|AB|00|BB
  • B00

Since B00 is of the form vxy where x,yΣ then we replace it with the rules

  • S0BAB|BA|AB|00|BB|ϵ
  • ABAB|BA|AB|00|BB
  • BUU
  • U0

Now the last two rules that need simplification are S0BAB and ABAB, as per the conversion procedure we replace the rule S0BAB with S0BW1 W1AB, and similarly we replace the rule ABAB with ABW2 and W2AB, but note that the rules for W1 and W2 are the same, and thus can be joined into the single rule W1AB yielding

  • S0BW1|BA|AB|UU|BB|ϵ
  • ABW1|BA|AB|UU|BB
  • W1AB
  • BUU
  • U0
For Any Context Free Grammar in Normal Form There Are Exactly 2n - 1 Steps Are Required for Any Derivation
If G is a CFG in Chomsky normal form, then for any wlang(G) of length n1, exactly 2n1 steps are required for any derivation of w

Since G is in normal form, then there may be a rule of S0ϵ, if that's the case then this rule could only ever derive a string of length zero, that is ϵ, since we only care about strings of length greater or equal to one, then that implies that the rule S0ϵ can never be used to deduce a string of length greater or equal to one.

Thus only rules used must be of the form vv1v2 or vt where tΣ. Note that every rule of the form vt will never modify the length of a string of an intermediate string, and the rule vv1v2 will always extend the length of the intermediate string by 1 each time it is applied.

Thus if we are able to derive a string of length n and a derivation always starts with a single variable S0 then a rule of the form vv1v2 must be used n1 times to have a string of length n, additionally since the rule of the form vv1v2 only introduces variables and never any terminal symbols, then we will require the rule vt to be used n times to convert each of the n variables produced by vv1v2, thus there will be exactly 2n1 steps in any derivation for a string of length n.

Pushdown Automaton
A pushdown automaton is a 6-tuple Q,Σ,Γ,δ,q0,F where Q,Σ,Γ and F are all finite sets and
  1. Q is the set of states
  2. Σ is input alphabet
  3. Γ is the stack alphabet
  4. δ:Q×Σϵ×Γϵ𝒫(Q×Γϵ) is the transition function
  5. q0Q is the start state
  6. FQ is the set of accept states

A Pushdown Automata Accepts an Input
Given an input w=(w1,,wm) where wiΣϵ we say that the push down automata P accepts w if there exists a sequence of states r0,rmQ and stack history strings h0,h1,hmΓ such that:
  • r0=q0 and s0=ϵ
  • i{0,,m1} we have (ri+1,b)δ(ri,wi+1,a) where si=at and si+1=bt for some a,bΓϵ and tΓ
  • rmF

We define the following notation for the transition function of a pushdown automata:

If you are at a state, and one of the outgoing rules is a,bc, then if bϵ and the top of the stack is not b then this rule cannot be used. If b=ϵ, then the rule can be used.

Similar to an NFA, when we write out a PDA, if there are no arrows for a particular, state, character, stack character pair, then this means that it maps to the empty set. If you get to a point where there are no possible outgoing rules to be used, then the PDA is said to be stuck, and that line of execution terminates.

Push Down Automata That Models the Language of Binary Strings Which Start and End With the Same Character
As per title.
q₀ q₁ q₂ 0, ε -> ε 1, ε -> ε 0, ε -> 0 0, 0 -> ε 1, 1 -> ε 1, ε -> 1 0, ε -> ε 1, ε -> ε

The above PDA works because the bottom path will accept the string 0,1, and going through the top path reads the first character and pushes it into the stack, then non-determinism kicks in and it will read some number of ccharacters from the input without pushing anything to the stack, in one of paths of non-determinism there will be one where all but one character is read from the input, then the last transition will read a character and attempt to pop off a that character from the stack, if that occurs it ends up in the terminal state, if there were any more characters to read, then since there are no subsequent states the path would terminate, thus this implies that the only way a string could get accepted by this PDA if it starts and ends with the same character.

Note that we could also model this "termination behavior" discussed above by pushing the dollar sign on, and then having a trasition that takes it off the stack.

Pushdown Automata That Models the Language of Binary Strings of Odd Length With a Zero in the Middle
As per title.
q₀ q₁ q₂ q₃ ε, ε -> $ 0, ε -> ε ε, $ -> ε 1, ε -> 1 0, ε -> 0 {0, 1}, {0, 1} -> ε

The second half of this PDA reads an input, and removes whatever character is on the top of the stack over and over non-deterministically, since there are no outgoing transitions from the terminal state, then a string is only accepted if it is entirely read by the non-determinism, additionally the fact that there is a dollar sign transition to the last state means that the stack must also be emptied by the time we get to the state before the terminal state.

If less than half the string |s|2 is read during the first part of the PDA, then the stack will become empty before all the characters are read, causing the string to not be accept, similarly if more than half the string is read during the first part of the PDA, then the stack will not have the dollar sign when we get to the terminal state.

Therefore if a string is accept it must be that exactly that half the string is read during the first part of the PDA. Now note that there is a transition which reads 0 but does nothing to the stack, this implies that exactly half the characters must be read during the first half of the PDA, and then in the second half of the PDA it will read a character and pop a character off the stack, which will make sure that the number of characters in the first half will equal the number of characters in the second half, showing that it accepts all strings of odd length with 0 in the middle.

The Half Zero Hash Sandwhiches Are Non-regular
The language L = \left\{ 0 ^ { k } # 0 ^ { 2k } : k \in \mathbb{ N } _0 \right\} ParseError: Expected '\right', got '#' at position 23: …ft\{ 0 ^ { k } #̲ 0 ^ { 2k } : k… is not regular

Suppose for the sake of contradiction that this language was regular, therefore there is some p1 sucht that the properties hold true, if we consider the string 0 ^ { p } # 0 ^ { 2p } \in L ParseError: Expected 'EOF', got '#' at position 11: 0 ^ { p } #̲ 0 ^ { 2p } \in… then by the lemma we have that 0 ^ { p } # 0 ^ { 2p } = xyz ParseError: Expected 'EOF', got '#' at position 11: 0 ^ { p } #̲ 0 ^ { 2p } = x….

By the third property we have that |xy|<p since the first p characters of our string are p this implies that x=0j and y=0l by the second property of the lemma we also know that l1 now we also know that # \in z ParseError: Expected 'EOF', got '#' at position 1: #̲ \in z therefore by the first property we can set i=0 to show that xy0z=xzL, but x y = 0 ^ { p - l } # 0 ^ { 2p } \notin L ParseError: Expected 'EOF', got '#' at position 21: … 0 ^ { p - l } #̲ 0 ^ { 2p } \no… thus a contradiction so L is not regular

A Cfg Which Is Not Regular
Let G=(V,Σ,R,S) with V={S,T,U} and \Sigma = \left\{ 0, # \right\} ParseError: Expected '\right', got '#' at position 21: …a = \left\{ 0, #̲ \right\} be the following grammar defined by the following rules:
  • STT|U
  • T \to 0T \mid T0 \mid # ParseError: Expected 'EOF', got '#' at position 23: …T \mid T0 \mid #̲
  • U \to 0U00 \mid # ParseError: Expected 'EOF', got '#' at position 17: … \to 0U00 \mid #̲
Show that lang(G) is not regular

First we give an informal description of the language, since the language of a CFG equals to prod(S)Σ, then by induction on the length of the string produced by the second rule, starting with length 1, we can prove that productions of this rule are given by all strings in Σ such that the string contains exactly one # ParseError: Expected 'EOF', got '#' at position 1: #̲.

Using a similar analysis the productions of the third rule in isolation are given by all strings in Σ such that there is exactly one # ParseError: Expected 'EOF', got '#' at position 1: #̲ and if there are n zeros to the left of # ParseError: Expected 'EOF', got '#' at position 1: #̲ then there are 2n # ParseError: Expected 'EOF', got '#' at position 1: #̲'s on the right.

Finally the initial rule creates the union of these two langauges. We now move on to showing that the language is not regular.

Since we assumed lang(G) was regular, then we'll try and obtain a contradiction through the pumping route, we do this by using the closure rules for regular langauges to focus on an even more specific subset of the language which should also be regular.

Since lang(G) is regular, and the regular expression 0 ^ * # 0 ^ * ParseError: Expected 'EOF', got '#' at position 7: 0 ^ * #̲ 0 ^ * is also regular, then A = \operatorname{ lang } \left( G \right) \cap 0 ^ * # 0 ^ * = \left\{ 0 ^ { k } # 0 ^ { 2k } : k \in \mathbb{ N } _ 0 \right\} ParseError: Expected 'EOF', got '#' at position 55: …ht) \cap 0 ^ * #̲ 0 ^ * = \left\… is regular, but we know that it is not, thus a condtradiction, so then lang(G) must not be regular.

If a Language Is Context Free Then There Is Some Pushdown Automaton That Models It
TODO: Add the proof here.
A Language Is Context Free Iff There Is Some Pushdown Automaton That Models It
Suppose that L is a language then cf(L)P,lang(P)=L
TODO: Add the proof here.
Pumping for Context-free Languages
If cf(A) for some language A, then there is a number p where if sA and |s|p then s=wvxyz such that
  1. for each i0,uvixyizA
  2. |vy|>0
  3. |vxy|p
TODO: Add the proof here.
The Language of Abcs Is Not Context Free
The language L={anbncn:n0} is not context free

Suppose that the language is context free, therefore the pumping lemma holds, and thus there is some p with some properties. Consider s=apbpcpL since |s|p then by the pumping lemma we can write x=uvxyz, where at least one of v or y is non-empty.

If v,ya,b,c which is to say the consist only of the same character, then s=uv2xy2z makes the following false count(s,a)=count(s,b)=count(s,c) thus sL.

If either v or y contain more than one alphabet character then suppose wlog that vab, therefore uv2xy2zabab and we know that ababL= thus sL

Thus no matter what we obtain a contradiction so it must be that L is not context free.

Context Free Languages Are Not Closed Under Intersection
If cf(A)cf(B) does NOT imply that cf(AB)
The languages L1={anbncm:n,m0} and L2={ambncn:n0} are context free, but L1L2={anbncn:n0} shows that the intersection is not context free.
Zero One Zero One Language Is Not Context Free
Show that the language L={0n1n0n1n:n0} is not context free

Suppose that the language is context free for contradiction, therefore the pumping lemma for context free languages holds true and we obtain some p1 such that if a string is longer than it some properties hold true.

Now the string s=0p1p0p1pL and clearly |s|p therefore s=uvxyz, we know that |vy|1 so they are both non-empty. Its either the case v,y01 or not.

If v,y01, then there are couple of similar cases to consider, specficially if v0 and y1, and suppose that vϵ so that v=0j where j1 f we consider x=uv2xy2z=u02jxy2z. Observe that in the given language L for every lL we have that count(l,0)=count(l,1), since count(x,1)count(x,0) then xL, therefore this is a contradiction.

Similarly if v=1j we will obtain a symmetrical contradiction, for the case it is yϵ an identical anlysis on y holds.

If its not true that v,y01 then since not both of v,y are empty then at least one of v,y is an element of {0,1}{ϵ}, suppose it is v, then v=01v=10 since all strings in L are a sequence of 0 then a sequence of 1s then a sequence of 0s then a sequence of 1s, clearly uv2xy2zL as it contains more than four sequences of 0 and 1s as v2=0101 or v2=1010, if it is y that is non-empty the same analysis applies, which is a contradiction.

Thus not matter the case of v,y we always get a contradiction, therefore L is not context free.

The Language of Palindromes With an Equal Number of 0s and 1s Is Not Context Free
L={w{0,1}:count(w,0)=count(w,1)rev(w)=w}

Suppose that L is context free for the sake of contradiction, then the pumping lemma holds on this language and thus there is some p1, then we consider the string s=0p12p0p which clearly has |s|p, thus s=uvxyz.

We know that one of v,y is non-empty, and they cannot both be empty, suppose that v is empty and that y is non-empty, then y{0,1}{ϵ}, if count(y,1)count(y,0) we will have a problem because the string s=uv2xy2z has the property that count(s,0)count(s,1) thus sL . Therefore we must have that count(y,0)=count(y,1), since we assumed v=ϵ then s=uv2xy2 no longer has the property that rev(s)=s because it will change the string where the 0's meet the 1's.

Now suppose that both v,y are non-empty,if v resides on the left half of the string and y resides on the right half of the string, then because |vxy|p then it must be that v,y1{ϵ}, thus this could yield a contradiction since s=uv2xy2z has more 1's than 0's. Therefore, they most both be substrings of either the right or left hand side of the string, so without loss of generality asssume that they reside within the left side of the string. If v,y1 then uv2xy2z contains more 1s than 0s, which is a contradiction, if v0{ϵ} similarly if v,y0+ we get the same problem. If 01v then uv2xy2z has two 01's as substrings in the left side of the string whereas the right side only has one which is a contradiction.

Turing Machine
A turing machine is the following data:
  • Q is the set of states
  • Σ is the input alphabet not containing the blank symbol
  • Γ is the tape alphaphet which contains the blank symbol and ΣΓ
  • q:Q×
Configuration of a Turing Machine
A setting of the current state, the current tape contents, and the current head location is called a configuration of the turing machine
Start Configuration
Given a Turing Machine M with an input w, then the start configuration is the configuration q0w
Accepting Configuration
Is one such that the state of the configuration is qa
Rejecting Configuration
The state of the configuration is qr.
Halting Configuraiton
The state is an accepting configuration or a rejecting configuration

The machien is defined to halt when in the states qa or qr

A Turing Machine Accepts an Input
Suppose that M is a turing machine and w is an input, then we say that M accepts w if a sequence of configurations C1,C2,,Ck exist where
  • C1 is the start configuration of M on input w
  • each Ci yields Ci+1
  • Ck is an accepting configuration
When this is true we write that acc(M,w)
A Turing Machine Rejects an Input
The turing machine enters qr
A Turing Machine Loops on an Input
The turing machine never enters a halting configuration
Language of a Turning Machine
lang(M)={w:acc(M,w)}
Turing Recognizable
Given a language L we say that it is Turing Recognizable if there is some Turing machine M such that L=lang(M)
Decider Turing Machine
A decider is a turing machine that doesn't loop on any input
A Turing Machine Decides a Language
We say that a turing machine M decides a language L if it is recognized by a decider turing machine
Turing Decidable
We say that a language L is turing decidable if there is a turing machine that decides it.
Non-deterministic Turing Machine
A non determinstic turing machineeeeeeee is a turing machine that may proceed according to several possiblitiles, with a transition function of the form δ:Q×Γ𝒫(Q×Γ×{L,R})
Every Nondeterministic Turing Machine Has an Equivalent Determinstic Turing Machine
TODO: Add the content for the proposition here.
TODO: Add the proof here.
The Acceptance Set for Dfas
ADFA={B,w:B is a DFA that accepts input string w}
The Acceptance Set for Dfas Is a Decidable Language
TODO: Add the content for the proposition here.
To do so we just have to construct a turing machine M which decides ADFA
A Language Is Turing Recognizable Iff It Is a Projection of a Decidable Language
Let C be a language. Prove that C is Turing-recognizable iff a dedcidable language D exists such that C={x:y,x,yD}

Suppose that C is Turing-recognizable, therefore there is some turing machine M that recognizes C so that lang(M)=C which means that for any xC that M accepts and halts on input x, for each input, suppose the number of steps taken by the turing machine before halting is given by hx1, then we define the language D={x,y:acc(M,x) in hx steps }, this language is decidable. An element xC iff acc(M,x) in hx steps iff x,hxD as needed.

Suppose that such a language D exists, since it is decidable then it is clearly recognizable and thus some enumerator enumerates, if it enumerates D, then if we drop the second component y, we obtain an enumerator for C, and therefore is Turing-recognizable.

An Enumerator Enumerates a Language
We say that an enumerator enumerates a language L if it prints out at least L
A Language Is Turing Recognizable If and Only If Some Enumerator Enumerates It
TODO: Add the content for the proposition here.
TODO: Add the proof here.
Separating Language
Suppose that A,B are two disjoint languages, we say that a language C separates A and B if AC and BC
Co Turing Recognizable
We say that a language is co-Turing-recognizableif it is the complement of a Turing recognizable language
Any Two Disjoint Co Turing Recognizable Languages Are Separable by Some Decidable Language
Let A and B be two disjoint languages. Say that language C separates A and B if AC and BC . Show that any two disjoint co-Turing-recognizable languages are separable by some decidable language.

Since we assumed that A and B are co-Turing Recognizable that means that A and B are recognizable.

Since a language is turing recognizable iff it is enumerable by some enumerator then there exist enumerators E _ \overline{ A } , E _ \overline{ B } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ A } , E _ \ov… that enumerate A,B respectively.

We will now construct a turing machine M and if we can make it a decider then we'll use C=lang(M).

Consider the turing machine such taht given an input w it will run EA and EB in parallell, if E _ \overline{ A } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ A } prints w then we reject the input ; if E _ \overline{ B } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ B } prints w accept.

Now we must show that AC so suppose that wA then since AB= then we know that wB, that is wB and wA, thus w will eventually get printed out only by E _ \overline{ B } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ B } so the machine will accept, so wC

We also have to show that BC so let wB again, A,B are disjoint so this implies that wA that is wA and we also know wB thus w will eventually get printed by only E _ \overline{ A } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ A } so the machine will reject, and so wC, so wC as needed.

If w(AB) then wAB therefore E _ \overline{ A } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ A } and E _ \overline{ B } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ B } will print it in finitely many steps, thus our turing machine will halt. If E _ \overline{ A } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ A } prints it first, then reject, otherwise if its E _ \overline{ B } ParseError: Got function '\overline' with no arguments as subscript at position 5: E _ \̲o̲v̲e̲r̲l̲i̲n̲e̲{ B } then accept

Thus we've shown that M halts on all inputs and thus is a decider, since we showed that AC and BC then it's separated by a decidable language.

Turing Diagonalization
Let A be a Turing-recognizable language consisting of descriptions of Turing machines,{M1,M2,.} , where every Mi is a decider. Prove that some decidable language D is not decided by any decider Mi whose description appears in A .

If A was finite, then since there are infinitely many decidable languages, then at least one of them must be decided by a machine that is not in A, therefore assume that A is infinite, since A is turing recognizable, then we know that its enumerable by some enumerator E, now we define the following turing maachine

Let M be the turing machine operating on positive integers such that given the input n we run the enumerator until we have printed out n unique turing machines, say M1,,Mn, then run Mn with the input n and do the opposite of whatever Mn outputs.

M is a decider, this is because E must enumerate all of the elements in a finite number of steps and because every turing machine encoded in A was a decider, so nothing will loop forever in the above definition.

Since we have inverted the behavior for each i then we have induced a diagonalization argument, this is because we have inverted the behavior of the selected machine meaning that ilang(M) XOR ilang(Mi) must hold true, this shows that Mi cannot decide lang(M) for each i, and therefore no turing machine encoded in A can, on the other hand M decides that language, as needed.

Computable Function
A function f:ΣΣ is a computable function if some Turing machine M such that for every input w the TM M halts with just f(w) on its tape
Mapping Reducible
A language A is said to be mapping reducible to a language B written as AmB if there is a computable function f:ΣΣ where for every w wAf(w)B the function f is called the reduction from A to B
If a Language Is Mapping Reducible to a Regular Language Then It Might Not Be Reducible
Suppose that AmB and B is regular, then it doesn't imply that A is a regular language.

If we consider the language A={0n1n:n0} which is not a regular language as seen earlier. We will show that A is mapping reducible to B={11}, also note that this finite language is clearly regular.

So we have to show that there is a computable function f such that wAf(w)=11. If we define the function f(w)={11 if wA00 otherwise  then it satsfies the requirement that wAf(w)B

This function is computable because we can create a turing machine M that uses a stack to recognize strings from A as they are of the form 0n1n, whenever it recognizes a string then it writes 11 to the tape, and outputs 00 if it rejects the input string w, thus this function is computable. Additionally this function halts on all inputs, as for every finite string by the time we get to the end of the string in finitely many steps the stack is observed and a decision is made.

Thus we've shown that AmB where B is regular, but A is not.

5.9
The Encodings of Reversal Accepting Turing Machines Is Undecidable
Show that the collection R of encodings of turing machines that accept a string rev(w) whenever it accepts w is undecidable.

Suppose for the sake of contradiction that R was decidable, we'll get a contradiction by showing that ATM is decidable.

Since R is decidable, then there exists some decider D for the language R, we'll now construct a decider for ATM to obtain our contradiction.

We will do this by constructing a decider for ATM by using the following idea, given M,w we only accept if D accepts M where M is a turing machine that we will define during an intermediate phase, M will have the property that M accepts w if and only if MR.

If all that is set in place, then we have M,w is accepted by A iff D accepts M: iff M accepts w, that is A accepts M,W iff M accepts w.

Now that we have the idea, we can formally construct A based on the specification of R.

  • Given M,w
  • Construct M as follows
    • on input y
      • if y0+1+ accept
      • if y0+1+
        • run M on the input w if it accepts, then accept, otherwise reject
  • Run D on the input M and output what it outputs

Note that M is a decider, this is because the construction of M takes finitely many steps as we are not actually running anything, just constructing, then when we run the encoding of this machine on D since it is a decider then it is guarenteed to halt in finitely many steps.

The language 0+1+ seems arbitrary, but it was simply chosen as it is one of the many languages that thas the property that that there exists some string x in the language such that rev(x) is not in in the language, for this example we can see that the string 001 is in the language but 100 is not. Keep in mind we could have used any language that satifies this property.

Thus if we have any turing machine T such that lang(T)=0+1+ then we know that TR, while at the same time if lang(T)={0,1} then clearly TR.

Therefore if we observe our definition of A we can see that if M accepts w then lang(M)={0,1} so then MR. and also if M does not accept w then lang(m)=0+1+ so that implies that MR, thus M accepts w iff MR.

Since we have a decider D for R then we just have to run D with the input M. Therefore we've constructed a decider for ATM which is a contradiction, therefore it must not be true that R is decidable, therefore it is undecidable.

The Busy Beaver Function Is Not Computable
Let Γ={0,1,_} be the tape alphabet, and define the busy beaver function BB: as follows. For each value of k, consider all k-state TMs that halt when started with a blank tape. Let BB(k) be the maximum number of 1s that remain on the tape among all of these machines. Show that BB is not a computable function.

Suppose for the sake of contradiction that BB was a computable function, that is there is some Turing machine M such that on every input w it halts with just BB(w) on its tape.Specifically we'll assume without loss of generality that it does so in unary, so we have some turing machien M such that whenever the input is 1n then M halts with 1BB(n) on the tape.

We'll now observe a special TM M that will yield a contradiction, this turing machine will fit those turing machines that the busy beaver function talks about, and so it will be a turing machine that halts when started on a blank tape. It will write n ones to the tape, it then doubles the number of ones and then simulates the turing machine M on what is currently on the tape (12n), and therefore will halt with BB(2n) ones on the tape.

Next we can show that BB is a strictly increasing function, this is because for every k-state turing machine that halts when started on a blank tape, there is an analagous k+1-state turing machine that also halts when started on tha blank tape and simulates the other machine with one extra state which does nothing, this shows us that BB(k)BB(k+1), also if we use that extra state to write another one to the tape, then we have that BB(k)<BB(k+1).

M takes n states to write each 1 to the tape initially, but doubling the ones on the tape only requires a constant number of states to do, and simulating M only takes a finite number of states, therefore Mn would have n+k-states. M is a turing machine that halts when started with an empty tape, and when it terminates it has BB(2n) ones on the tape, since BB(n+k) is the maximum number of ones over all turing machines with n+k states that terminate when started on an empty tape, then we can conclude that BB(n+k)BB(2n).

Since k is some constant, then once n>k then we have that n+k<2n and since we concluded that BB was a strictly increasing function then this would imply that BB(n+k)<BB(2n) which is a contradiction, therefore our assumption that BB was computable is false.

5.16
A Language Is Turing Recognizable Iff It Is Mapping Reducible to the Acceptance Set for Turing Machines
A is Turing recognizable iff AmATM

Suppose that A is turing-recognizable and and so there exists a turing machine M that recognizes A.If we consider the function f(w)=M,w, clearly there is a turing machine such that for every w it halts with just M,w on its tape because all it would have to do is paste the encoding of M and then w.

Moreover we know wA iff wlang(M) iff M,wATM iff f(w)ATM, that is to say that wAf(w)ATM showing that A is mapping reducible to ATM

Now we show the other direction, where we assume that AmATM, since ATM is Turing recognizable by the Universal Turing machine (the turing machine that just simulates other turing machines), then that implies that A is turing recognizable, as needed.

A Language Is Decidable If and Only If It Is Mapping Reducible to Zeros Then Ones
A is decidable if and only if Am01

Suppose that A is decidable, therefore there is some turing machine D such that given some w it accepts if wA and rejects if wA , now if we make a simple wrapper turing machine R that simply takes in an input simulates w on D, and if D accepts output 01 and if it rejects output 10, then this creates a computable function f(x) such that f(x)=01 if xA and f(x)=10 if xA.

Since ran(f)={01,10} then we can say that xAf(x)01, therefore we have Am01

Now we assume that Am01, since we already discovered that regexs are decidable, then 01 is decidable, and thus A is decidable.

Prefixing the Acceptance Set for Turing Machines Makes It Not Turing Recognizable
Consider the set: J={w:w=0x f.s. xATM}{w:w=1x f.s. xATM} Show that J nor J are Turing recognizable

We claim that ATM is mapping reducible to J by the function f(w)=1w. The reason this is so is f is computable as there is a certainly a turing that can append 1 to the front of an input string onto the tape, additonally if wATM then f(w)=1wJ, and if 1wJ it implies that 1w{y:y=1w f.s. yATM} therefore wATM, so we have ATM<mJ, since ATM is not turing recognizable, then neither is J.

We also claim that ATM is mapping reducible to J, if we use the function f(w)=0w the details are similar to the above in that f is computable, and also in that if wATM, then f(w)=0wJ, and that if 0wJ then it must be that wJ, thus we have ATMmJ and since ATM is not turing recognizable, then neither is J

Acceptance Set for Context Free Grammars
ACFG={G,w:G is a CFG that generates the string w}
The Acceptance Set for Context Free Grammars Is Decidable
ACFG is decidable
TODO: Add the proof here.
The Set of Equivalent Context Free Grammars
EQCFG={G,H:G,H are CFG’s and lang(G)=lang(H)}
The Set of Equivalent Context Free Grammars Is Co Turing Recognizable
As per title.
In order to show that this is true we have to show that the complement of EQ _ \left{ CFG \right} ParseError: Got function '\left' with no arguments as subscript at position 6: EQ _ \̲l̲e̲f̲t̲{ CFG \right} is turing recognizable. So we need a turing machine that can recognize the language EQCFG={G,H:G,H are CFG’s and lang(G)lang(H)} In order to know if the two languages differ we just need to find an example of a string which is in one, but not the other, we also note that the set of strings over a language is countable, meaning that they can be enumerated by s1,s2, now we create a recognizer as follows
  • on input G,H:
    • for each string s1,s2,
    • since ACFG is decidable there is a decider D for it, so we can run G,si on D and H,si on D and compare the results, if they are the same go to the next iteration, otherwise if they are different accept

We claim that this is a recognizer, this is because G,HEQCFG if and only if there exists some i si such that G,siD and H,siD (or vise versa), iff the above turing machine terminates in the accept state after i iterations.

Therefore the above turing machine terminates in the accept state if and only iff G,HEQCFG therefore it is a recognizer.

There Is an Undecidable Subset of the Kleene Star of One
There exists a subset S1 that is undecidable

Instead of doing a turing machine argument we do it by counting, first of all we show that 𝒫(1) is in bijection with {0,1} to do this, we consider any subset of 1 which is of the form S={s1,s2,} where each si1 each si has a length, that is it is a sequenece of ni ones in a row, thus for each si wherein we have |si|=ni we set the nith element of the infinite binary string to 1 and the rest to zero, this sets up the mapping.

Clearly this function can hit any output, so given any infinite binary string, we just select the elements in 𝒫(1) of corresponding length. Additionally given any collection of subsets we know which string will hit it, all that remains is injectivity which is simple to prove, and we will not go into that detail.

Thus we have a bijection from 𝒫(1) to {0,1} therefore since we already know that the latter is uncountable, then so is the former.

Since the set of all turing machines is a subset of all possible strings which is countable, then the number of possible turing machines is countable, and thus the number of languages that are recgonized is also countable, therefore there is some element of 𝒫(1) which is not recognized by some turing machine, select that one, this is our example of a subset of 1 which is undecidable, because we already know it is unrecognizable.

Fixed Point of the Accept and Reject Switching Function for Turing Machines
In the fixed point version of the recusion theorem, let the transformation t be a function that interchanges the states qaccept and qreject in turing machine descriptions, find a fixed point for t.

Recall that the fixed point is a turing machine which when fed through t yields a turing machine equivalent to the original. Suppose we had such a machine M and lets see the restrictions on this machine, if we gave this machine some input w and it halts, then this must be because it either entered the accept or reject state, since t(M) inverts this behavior, then on this input the two machines would differ (one accept and one reject), thus if such a fixed point machine were to exist, it must be that it never halts.

If M is a turing machine that loops forever, then by definition this means that it never enters the accept or reject state, therefore if we consider t(M) then this is still a machine that loops forever on all inputs, thus the language of the two machines is the same (empty) and they are equivalent, thus any machine that loops on all possible inputs is a fixed point.

For Any Two Languages There Is Always Another Language That Is Is Turing Reducible To
As per title.

Something that works well here is embedding both languages into the following set J=0A1B. The reason we use such a set is that we know that wA0wJ and that wB1wJ Now we will start by proving that ATJ, to do this we assume that we have an oracle O for J, and now we construct a decider for A, to do this we construct a turing machine as follows:

  • on input w we query the orcale if 0w is an element of J, if it is we accept, and otherwise reject

As mentioned above 0wJwA thus the above turing machine accepts if wA and rejects if wA, that is it is a decider for A

The exact same construction where we query the oracle with 1w decides B

Computing the Descriptive Complexity With an Oricale for the Acceptance Set for Turing Machines
As per title.

We need to come up with an algorithm which will compute the descritpive complexity of a binary string x, we'll first introduce the idea, and then refine it so to actually work correctly. A naive approach would be to simply go through all binary strings in lexographic order, if we were on string s we would then try all possible ways of parsing it into the form M,w where M is a turing machine w an arbitrary input string, if no parsing works for string s then we would try the next string.

If it so happened that s was parsable into M,w then our goal would be to check if M on input w halts with x on its tape, and we would return |s|, this would work because lexiographic order forces shorter strings to come before longer strings, thus enforcing the two requirements that descriptive complexitiby be as small as possible and in the case of ties choosing the one that comes first in the lexicographic ordering.

The one problem with our plan is that running M on input w may never halt, as its just a regular turing machine, and so we need a way to get around this, this is why the assumption of having the oracle is there, as it gives us a method to determine if a turing machine will halt. Consdier the turing machine M if we construct a new turing machine N that is M but whenever there is a transition that leads to a reject state, it instead takes us to the accept state, then when we query the oracle with N,w then it accepts iff M on input w halts (either enters a reject or accept state). This provides us with a way to check if M on input w will halt in a finite number of steps making our algorithm tractable. Thus our final algorithm as as follows:

  • For each binary string s iterated in lexicographic order
  • attempt to parse s into M,w where M is a turing machine w an input, if it cannot be parsed, then move to the next string otherwise continue to the next step
  • Make the modifiation of M to N as specified in the previous paragraph, and check if N,wATM using the oracle, if it is not an element then go to the previous step, otherwise N,wATM therefore we know that M on input w halts
  • Run M on input w and if what remains on the tape is x then return |s| and stop this algorithm

Also note that even though the above seems to be a potentially infinite loop, but we can make it finite as we already know that there is some c such that K(x)x+c and so we only have to test strings up until this cut off.

The Acceptance Set for Oracle Turing Machines Is Undecidable
As per title.

Suppose for the sake of contradiction that ATM is decidable relative to ATM, which is to say that there is an oracle machine HATM that decides ATM, and now we construct the following which we will call N

  • On input M
  • Run HATM on M,M
  • If HATM accepts, then reject and if it rejects then accept

Since this turing machine just inverts the output of a decider it is also a decider. If we run N on the input N, then it will accept iff N rejects N, which is a contradiction, and it will reject iff N accepts N which is also a contradiction, therefore our assumption is incorrect and so ATM is undecidable.

There Exists Languages That Are Not Recognizable by a Turing Machine With an Oracle for the Acceptance Set for Turing Machines
As per title.
We already know that there are uncountably many languages, and we also discovered that there are countably many turing machines, and thus there are countably many turing machines that have an oracle for ATM, therefore each such turing machine defines a language, but there will still only be countably many of those, and thus since there are uncountably many languages, there must be a langauage for which a turing machine with such an oracle can never generate; as needed.
The Language of Turing Machines That Halt on All Inputs Is Neither Recognizable nor Co-recognizable
As per title.

Recall that H={M,w:M(w) halts } is not decidable, but it is recognizable. Because of that we know that H must not be recognizable, if it were then we would be able to construct a decider for H.

If H is not recognizable, then if we can make a mapping reduction to HA={N:N halts on all inputs }, then we could deduce that HA is unrecognizable as well. In order to do this we would have to come up with a function f such that xHf(x)HA, in otherwords we need a computable function f such that whenever we have a turing machine and input M,x that does not halt, it gets mapped to a turing machine N that always halts, and if f(x) is a turing machine that always halts, then it must be that x is of the form M,w where M loops on input w.

We construct the function f as follows, so that on input M,w:

  • We construct a turing machine N such that on input x
  • Simulate M on input w for |x| iterations
  • If M halted, then go into an infinite loop
  • If M has not yet halted, then halt

Now supose that xH, therefore x=M,w where M loops on input w, then f(x)=N where N is specified above. Then for any input y if we run N(y) then since M loops, we will hit the second if statement, and N will halt, which implies that NHA, so xHf(x)HA

Now suppose that xH so that x=M,w where M halts on input w, then f(x)=N now since M halts on w, suppose that it halts in k steps, if that's the case then we select an input y such that |y|>|k|, so that after |y| iterations, we've guarenteed that H has halted on w so that we go into the first if statement and loop forever, this implies that NHA. This concludes showing that xHf(x)HA, therefore since f is computable, then we've showing that H is mapping reducible to HA and since H is unrecognizable so is HA.

We will show that the complement of HA which is the set HA={M:M loops on at least one input } is not recognizable. We do a similar reduction from H, given any M,w we construct a machine N such that on input x, it ignores input x and just simulates M on input w.

Suppose xH, therefore x=M,w, and M does not halt on w, therefore the machine M doesn't halt on any input, and so ML.

Now suppose that xH that is to say that x=M,w and we know that M halts on input w, therefore M halts on every input, meaning that MHA, this shows that xHf(x)HA, thus since H was unrecognizable, so is HA.

5.22, 5.23 5.225.22