Is this NFA correctly accepting inputs that end with a 00? - nfa

In a lecture it was said that this NFA accepts inputs ending with two zeros or inputs=0: https://ibb.co/9Wt0j7J .
The alphabet is {0,1}
But if the input would be 001 we would on some path also end up in the acceptance state (z2) but it would not be possible to go back to another state when reading the last character, the one. That would mean, a wrong input was accepted. So, my question is: Is the NFA really constructed correctly without changing anything? And if yes, why? Can I just assume that we go to an "empty (invisible) state (error state without mentioning it explicitly)" or something like that if there is no other arrow to another state?

Yes, it is a correct NFA for the given definition.
But if the input would be 001 we would on some path also end up in the acceptance state (z2) but it would not be possible to go back to another state when reading the last character, the one. That would mean, a wrong input was accepted.
If you put 001, it will not accept it since NFAs checks all possible paths and eliminates the paths which stuck. So you will go to z2 after the first two 0s but after reading the 1, it will stuck and be eliminated.
Edit:
... an NFA accepts a string w if it is possible to make any
sequence of choices of next state, while reading the characters of w and go from the start state to any accepting state.
from the book Introduction to Automata Theory, Languages, and Computations by John E. Hopcroft, Rajeew Motwani, Jeffret D. Ullman, (2006, p.59).

Related

Mutli-track Turing Machines

I'm doing my homework, and i have a problem with multi-tape (multi-track) Turing Machine:
We have multi-tape Turing Machine, which always before moving a head left, writes a blank symbol.
Does this machine recognise the same class of languages as standard Turing machines?
Do you have any idea how to prove it? Certainly standard Turing Machine recognise a recursively enumerable language (Typa-0 in Chomsky hierarchy).
Without loss of generality we can supopose that TMs do not go further to the left than the first input symbol.
Consider the following PDA P:
P simulates the TM until the first step to the left and puts the output on the stack.
The TM moves to the left are done via pops from the stack.
When moving to the right again, the TM reads only blanks until it reaches the first untouched input symbol. P can do this in one single step.
For steps 2 and 3 we need the following: the state and direction in which the TM exits the block of blanks (between the last non-erased input symbol on the left and the first untouched one on the right) depends on the number of blanks in this block. There are infinitely many possibilities. However, there can only be a finite class of combinations of entrance/exit states and directions. Probably this can be coded into the PDA's finite control and updated every time another blank is written.
If this is correct, these TMs only accept the class of context-free languages. But these details would have to be worked out to really prove this.

Finite state machines how to implement minimum and maximum hits

I'm trying to implement a fsm and it's going fine. I can enter strings and see if they are valid and all that kind of stuff.
However regular expressions (which are fsms) have this feature where you can specify how many times a certain character may occur for example a{2,4} would accept "aa" and "aaa" but not "aaaaa" and "a"
I can imagine having a counter on edges that count how many times they have been hit and use this to deny any characters after the counter has hit a certain number but you can't implement minimum this way because it would always block the first character (unless minimum is 0).
Does anyone know a way to implement this feature?
it also has to work for really big numbers like a{1,99999999999}
To my understanding, this kind of constraint cannot be implemented dynamically in a finite state machine; parts of the FSM would have to be statically expanded. In your example, for a{2,3} three different separate FSMs would have to be built, one accepting aa, the second one accepting aaa and the third one accepting aaaa; these would then have to be made alternatives in the final FSM via some empty transitions. The reason for this is the fact that the FSM itself does not store the path by which its current state was reached, which means that a paremeterized form of the pattern a{i,j} cannot be checked.

Automata with kleene star

Im learning about automata. Can you please help me understand how automata with Kleene closure works? Let's say I have letters a,b,c and I need to find text that ends with Kleene star - like ab*bac - how will it work?
The question seems to be more about how an automaton would handle Kleene closure than what Kleene closure means.
With a simple regular expression, e.g., abc, it's pretty straightforward to design an automaton to recognize it. Each state essentially tells you where you are in the expression so far. State 0 means it's seen nothing yet. State 1 means it's seen a. State 2 means it's seen ab. Etc.
The difficulty with Kleene closure is that a pattern like ab*bc introduces ambiguity. Once the automaton has seen the a and is then faced with a b, it doesn't know whether that b is part of the b* or the literal b that follows it, and it won't know until it reads more symbols--maybe many more.
The simplistic answer is that the automaton simply has a state that literally means it doesn't know yet which path was taken.
In simple cases, you can build this automaton directly. In general cases, you usually build something called a non-deterministic finite automaton. You can either simulate the NDFA, or--if performance is critical--you can apply an algorithm that converts the NDFA to a deterministic one. The algorithm essentially generates all the ambiguous states for you.
The Kleene star('*') means you can have as many occurrences of the character as you want (0 or more).
a* will match any number of a's.
(ab)* will match any number of the string "ab"
If you are trying to match an actual asterisk in an expression, the way you would write it depends entirely on the syntax of the regex you are working with. For the general case, the backwards slash \ is used as an escape character:
\* will match an asterisk.
For recognizing a pattern at the end, use concatenation:
(a U b)*c* will match any string that contains 0 or more 'c's at the end, preceded by any number of a's or b's.
For matching text that ends with a Kleene star, again, you can have 0 or more occurrences of the string:
ab(c)* - Possible matches: ab, abc abcc, abccc, etc.
a(bc)* - Possible matches: a, abc, abcbc, abcbcbc, etc.
Your expression ab*bac in English would read something like:
a followed by 0 or more b followed by bac
strings that would evaluate as a match to the regular expression if used for search
abac
abbbbbbbbbbac
abbac
strings that would not match
abaca //added extra literal
bac //missing leading a
As stated in the previous answer actually searching for a * would require an escape character which is implementation specific and would require knowledge of your language/library of choice.

Find a non-deterministic CFL whose reverse is deterministic

I have a homework assignment, and i am finished other then one question (see title)
For the life of my, i cannot figure this out... so i started to think it was a trick question.
the current answer that i will submit is:
L1 = {a^n b^n: n>=1} is deterministic. And the reverse,
L2 = {b^n a^n: n>=1} is also deterministic.
However, since all deterministic languages are a subset of Non-deterministic languages, L2 can be considered non-deterministic.
On a side note, the only other example i was trying to make work is:
L3= {{a,b}a}
This seems possible because forward there is non-determinism, since the input could be either a, or b as long as its followed by an a.
and in reverse there is determinism since it will accept only an 'a'. But, it introduces new non-determinism since the second input could be either a or b.
any help / guidance would be great.
I know the deadline has passed, but somebody might find this useful in the future.
(a+b+c)*WcW^R, where W is in (a+b)+; this is non-deterministic because you don't know where the "WcW" bit starts.
W^RcW(a+b+c)*, where W is in (a+b)+; this is deterministic because you can write a deterministic PDA to accept simple palindromes of the form "W^RcW" and modify the accepting state to loop to itself on any of a, b and c.
The trick here is that PDAs have to read input from left to right.

Writing a program that writes a program

Its well known in theoretical computer science that the "Hello world tester" program is an undecidable problem.(Here is a link what i mean by hello world tester
My question is since given a program as input we can't say what the program will do,can we solve the reverse problem:
Given set of input and output,is there an algorithm for writing a program that writes a program to achieve a one to one mapping between the given input and output.
I know about metaprogramming but my question is more of theoretical interest. Something which can apply for a generic case.
With these kind of musings one has to be very careful. A lot of confusion arises from not clearly distinguishing about a program x for which proposition P(x) holds or any program x for which proposition P(x) hold. As long as the set of programs for which P(x) holds is finite there always is a proof, of their correctness (although this proof may not be known).
At this point you also have to distinguish between programs, which are and can be known and programs which can only be shown to exist by full enumeration of all posibilities. Let's make an example:
Take 10 Programs, which take no input and may or may not terminate and produce "hello World". Then there is a program which decides exactly which of these programs are correct, and which aren't. Lets call these programs (x_1,...,x_10). Then take the programs (X_0,...,X_{2^10}) where X_i output true for program x_j if the j-th bit in the binary representation of i is set. One of these programs has to be the one which decides correctly for all ten x_i, there just might not be any way to ever figure out which one of these 100 X_js is the correct one (a meta-problem at this point).
This goes to show that considering finite sets of programs and input/output pairs one can always resolve to full enumeration and all halting-problem type of paradoxies instantly disappear. In your case the set of generated programs for each input is of size one and the set of input/output pairs is of finite size (because you have to supply it to the meta-program). Hence full enumeration solves your problem very simple and you can also easily proof both the correctness of the corrected program as well as the correctness of the meta-program.
Note: Since the set of generated programs is infinite, this is one of the few cases where you can proof P(x) for a infinite set of programs (actually you can proof P(x,input,output) for this set). This shows that the set being infinite is only a necessary, not a sufficient condition for this type of paradoxes to appear.
Your question is ambiguously phrased.
How would you specify "what a program should do"?
Any precise, complete, and machine-readable specification of a program's functionality is already a program.
Thus, the answer to your question is, a compiler.
Now, you're asking how to find a function based on a sample of its input and output.
That is a question about statistical analysis that I cannot answer.
Sounds like you want to generate a state machine that learns by being given an input sequence and then updates itself to produce the appropriate output sequence. Assuming your output sequences are always the same for the same input sequence it should be simple enough to write. If your output is not deterministic, such as changing the output depending on the time of day, then you cannot automatically generate a state machine.
Depends on what you mean by "one to one mapping". (And also, I suppose, "input" and "output".)
My guess is that you're asking whether, given an example of inputs and outputs for a given arbitrary program, can one devise an algorithm to write an equivalent program? If so, the answer is no. Eg, you could have a program with the inputs/outputs of 1/1, 2/2, 3/3, 4/4, and yet, if the next input value was 5, the output would be 3782. There's no way to know, from a given set of results, what the next result might be.
The question is underspecified since you did not say how the input and output are presented. For finite lists, the answer is "yes", as in this Python code:
def f(input,output):
print "def g():"
print " x = {" + ",".join(repr(x) + ":" + repr(y) for x,y in zip(input,output)) + "}"
print " print x[raw_input()]"
>>> f(['2','3','4'],['a','b','x'])
def g():
x = {'2':'a','3':'b','4':'x'}
print x[raw_input()]
>>> def g():
... x = {'2':'a','3':'b','4':'x'}
... print x[raw_input()]
...
>>> g()
3
b
for infinite sets how are you going to present them? If you show only a small sample of input this does not specify the whole algorithm. Guessing the best fit is undecidable. If you have a "magic blackbox" then there are continuum many mappings but only a countable number of programs, so it's impossible.
I think I agree with SLaks, but taking things from a different angle, what does a compiler do?
(EDIT: I see SLaks edited his original answer, which was essentially 'you're describing the identity function').
It takes a program in one source language that describes the intended behaviour of a program, and "writes" another program in a target language that exhibits that behaviour.
We could also think of this in terms of things like process refinement --- given an abstract specification, we can construct a refinement mapping to some "more concrete" (read: less non-deterministic, usually) implementation.
But based on your question, it's really very difficult to tell which of these you meant, if any.

Resources