How does a pushdown automaton know how to read a palindrome? - computation-theory

For example, how does a PDA know how to read a palindrome in L = {a, b}*?
PDA that accepts palindromes over {a,b}* :
So, based on my drawing of the PDA:
How does it know when the first half of the string is on the final terminal (letter of the alphabet), and therefore knows to go from state 0 to state 1 (and furthermore knowing to "pop" letters from the stack backwards, hence creating the palindrome)?

This is a nondeterministic pushdown automata. The answer to your question is that it guesses and may be assumed to guess correctly. Nondeterministic automata accept a string w if any path along which w might be processed results in w's being accepted.
If we define acceptance as having an empty stack in an accepting state, then the only way something can be accepted by the above NPDA is if:
it puts some stuff on the stack in state q0
it eventually guesses that it needs to read the second half of the string
it reads what it pushed onto the stack, but backwards, in q1
There are three "guesses" that the NPDA makes:
it guesses that the string is an even-length palindrome when it guesses e e/e, where e is used in place of lambda.
it guesses that the string is an odd-length palindrome with a in between the two halves when it guesses a e/e, where e is used in place of lambda
it guesses that the string is an odd-length palindrome with b in between the two halves when it guesses b e/e, where e is used in place of lambda
Each of the above three guesses is also guessing that the first half of the string, excluding a possible middle element, has been seen already.
This guess will eventually be true for any palindrome, and it won't be true for anything but a palindrome, so the NPDA accepts PAL.

Related

Is the empty string a subset or element of all alphabets?

I'm having trouble understanding when the empty string (epsilon) is a subset or element of an alphabet? My understanding was that epsilon was only part of a language, but my TA in the class said it was an element of all alphabets so now I am confused.
e.g. would {a,b,c} contain epsilon as an element?
e.g. would {} contain epsilon as an element?
e.g. is {eps} a subset of all alphabets or languages?
This question is probably better suited for cs.stackexchange but I will try to help you according to my understanding, please do correct me if necessary.
In general, your own intuition seems quite correct to me. ϵ is not automatically part of every alphabet. It is the empty string of characters.
However, this means that ϵ is a string over any alphabet, even your alphabet {a, b, c}.
So to answer your three examples:
No, it does not. If {a, b, c} is an alphabet, it is a set of symbols, and ϵ is a string. However, ϵ is definitely part of some languages defined over this alphabet.
No, {} is the empty set, and it contains nothing, not even ϵ.
{ϵ} is the set containing only ϵ. ϵ is a string, not a symbol, so it is not a subset of all alphabets (however, it seems there are cases where some alphabets are defined to contain ϵ but that is a different confusing story). It is also not a subset of all languages, because consider the language L = {aa, ab, ba, bb}. The empty string ∈ is not one of these elements.
The analogue to set theory might cause some additional confusion. Notice that the empty set is a subset of every set. The empty string is not a subset of every language, but rather it is a substring of any string.

How to demonstrate a set is decidible, semi-decidible or not semi-decidible?

I have been asked to prove if the following set is decidible, semi-decidible or not semi-decidible:
In other words, it is the set of inputs such that exists a Turing Machine encoded with the natural y with input p that returns its input.
Consider the set K as the set of naturals such that the Turing machine encoded with x and input x stops. This is demonstrated to be a non-decidible set.
I think that what I need is to find a reduction of K to L, but I don't know how to prove that L is decidible, semi-decidible or not semi-decidible.
L may not look decidable at first glance, because there is this nasty unbounded quantifier included, which seems to make necessary a possibly infinite search when you look for a y satisfying the condition for a specific p.
However, the answer is much simpler: There is a turing machine M which always returns its input, i.e. M(p) = p holds for all p in the considered language. Let y be a code of M. Then you can use this same y for all p, showing that L contains all words of the language. Hence L is of course decidable.
In fact, this is an example to demonstrate the principle of extensionality (if two sets have the same elements and one is decidable, then the other is decidable too, even if it doesn't look so).

Prove that a specific language is not semidecidable

I have to prove that the language L = {< M >: |L(M)| <= 2016} is NOT semi-decidable. Now I thought of doing it like this:
Take a random alfabet E. Now there are an infinite number of words in E. We can only conclude that |L(M)| <= 2016 by passing every word from E* as an input to M. But because there are an infinite number of words, this means that we would have to pass an input to M an infinite number of times. But this implies that Turing Machine that performs these checks ends up in an infinite loop, and thus never returns accepts nor rejects it's input. The language L is thus not semi-decidable.
But I think that this might not be formal enough? Mainly because I just assume that the Turing Machine that checks this language will let M run on every word from E*. Is this assumption valid, or should I be more formal in this?
Consider the complement of L: the language of Turing-machine encodings whose languages contain more than 2016 strings. We can easily prove this language is semi-decidable. Given this fact, assume that L is also semi-decidable. Because L and its complement are both semi-decidable, we have an effective procedure for deciding each: run the TMs for L and its complement alternately, and one will eventually list the input.
To see that the complement of L is semi-decidable, imagine a TM that executes one step of M on every possible input, alternating moves so that each string is eventually processed by arbitrarily many moves of the TM. The order in which it would visit the inputs would be like:
e,
e, 0,
e, 0, 1,
e, 0, 1, 00,
e, 0, 1, 00, 01, ...
Clearly, any string of input will eventually be processed every possible number of times. Our machine, which is simulating M running on all possible input strings, one step at a time, will eventually find 2017 strings have cause M to halt-accept, or it will run forever. If it finds 2017 strings that works, it halt-accepts.

Part of the theorem: "A language is Turing-recognizable if and only if some enumerator enumerates it"

I need help to understand this proof.
"First we show that if we have an enumerator E that enumerates a
language A, a TM M recognizes A. The TM M works in the following way.
PROOF M = "On input w:
1.Run E. Every time that E outputs a string, compare it with w.
If w ever appears in the output of E, accept."
Clearly, M accepts those strings that appear on E's list. "
If w doesn't appear in the output of E it doesn't appear in the E's list.
What is he triyng to say?
You have to prove both parts since it includes "if and only if" phrase.
First, you should show that if there exists an enumerator E which enumerates all strings in the language L, we can construct a recognizer for this language L.
This recognizer works with an input w ( a string ) and runs the E inside. E is an enumerator which generates all strings in L one by one. If the input string is equal to one of these generated strings then ACCEPT. If this language is infinite, then the recognizer may not halt, which is not a problem for a recognizer since it is not a decider.
Second part is, if L is Turing recognizable then there must be a Turing Machine M that recognizes L. An enumerator can be constructed as follows;
for k=1,2,3...
Run M on w1,w2,w3... in parallelized for k steps
if M accepts any of the wi then print wi on the printer.
The reason why we run them in parallelized with limited steps is the same reason why we prefer depth-limited search over depth-first search. It can go through an infinite dead path on the search graph.
Your theorem has two directions: if the "if" and the "only if". The proof is for the "if" direction.
Assuming you have an enumerator E for a language L, can you construct a Turing machine M that recognizes L? Yes, you can. Just define a Turing machine M that, on input string w, checks to see if w is ever in the output of E (which may be infinite). If it is, accept. If it isn't reject.
Since E is an enumerator for L, for any w in L, E eventually outputs w before halting (if it ever halts). Thus, M halts for every string in L. If w is not in L, either M never halts, or M rejects w.
Also, for M to be a decider, not just a recognizer for L, M must always halt.

what is the logic of Finite Automa and loops

I have to draw a Finite Automaton that accepts the following string
Λ, a, aabc, acba and accb
In my view a(a+b+c)* this might be it's regular expression as the string is starting from a and includes an empty string as well.
Now I didn't find the logic of drawing FA as in below image
Question 1: If the string is starting with a then in FA, We are moving from x to y while reading b
Why we don't read a here.
Question 2: Why we use loop of a,b on state y and z
The language L = {λ, a, aabc, acba, accb} is finite. Therefore, L is not equivalent to the language denoted by the Kleene closure of the regular expression a(a + b + c), which is infinite. There is a simple algorithm that generates the nondeterministic finite automaton accepting a finite language, which consists of drawing paths accepting each of the strings in the language.
It's unclear what the relationship between the two languages and the diagram in the original post is, since the automaton in the diagram accepts neither language. Assuming that the nodes are labeled with their names, and circled nodes indicate acceptance, the language accepted by the automaton in the diagram is (a + b)*. In this case, the loops are used to accept the Kleene closure of (a + b). That said, it would be useful if you could clarify the meaning of the diagram.

Resources