How can I make a string empty again after going through different states in a non deterministic finite automata? - finite-automata

For example I have several states I will name A, B and C.
A allows 1,0 and loops. When it enters state B, is it possible that everything will be empty again before going to C? If yes, how?

In general finite automata is like decision making type.It can tell whether the given string is recognized by the automata or not.The major draw back of finite automata is that it can't recognize the previously given input.so to enhance it we are going for push down automata(pda).In pda we have stack to store the input symbols.There also we can push or pop only one element at a time.If you want to pop all elements when it enters state B then use a loop to pop all elements of the stack until stack becomes empty

Related

How to show that if the language L is regular, then L' is regular?

Let L be any regular language and a ∈ Σ. How to show that the language L'={uav | uv ∈ L} is regular too?
Wikipedia says a way to proove it is to lead it back to a regular language but I don't understand how to do that in this case. Hope somebody can help.
There are lots of ways to show this. I think an argument whereby we construct a DFA is particularly easy to visualize.
Imagine a DFA for your language L. Let's call it M. Imagine it sprawled out in diagram form on a table. Now, imagine making a copy of M and spreading it out next to M on the table. Call it M'.
Now - from M, add a new transition from state q of M to the corresponding state q' of M'. The transition is on the symbol a.
Now, consider the aggregate machine whose start state is the start state of M and whose accepting states are the accepting states of M'. This machine starts out accepting strings in L, then accepts an a somewhere in the middle, and then continues accepting strings in L from where it left off. This is the language we were going for and we have defined a perfectly reasonable NFA for it. Since any language accepted by an NFA is regular, our language is regular.

Turing Machines

I'm reading a book on Languages & Automata and I'm not understanding Turing Machines. I've taught myself about DFA's NFA's and Pushdown Automata without any problems. Can someone please explain what this is doing?
B = {w#w|w ∈ {0, 1}*}
The following figure contains several snapshots of Ml 's tape while it is computing
in stages 2 and 3 when started on input 011000#011000.
Thanks alot!
"Imagine an endless row of hotel rooms, and each room contains a lightbulb and a switch that controls it. Initially, all the rooms are dark. A robot starts at one of the rooms, and has the ability to operate switches and move to adjacent rooms.
The robot has several states that it can be in, and each state determines what it should do based on whether the current room is light or dark. For example, a robot's rules could include these states:
The "scared" state:
If the room is dark, turn on the light and move to the room to the left.
If the room is light, do nothing and go to the "normal" state.
The "normal" state:
If the room is light, turn off the light and move to the room on the right.
Otherwise, go to the "scared" state.
One special state is the "stop" state. When the robot finds itself in this state, the process is complete.
Suppose a robot has n states (not including the "stop" state), and it stops. What is the maximum number of light rooms at this point?
This system is in direct allegory to Turing machines. The hotel is the tape, the robot is the Turing machine, and dark rooms and light rooms are 0 and 1 cells."
It is from googology wiki. I gave an idea to it, but, of course, this text has been improved since me.
Turing machine is a hypothetical machine with a tape where symbols are stored. It can have multiple heads that can read symbols from the tape or write symbols to the tape.
Now your grammar says B = {w#w|w ∈ {0, 1}*}, that is any string of the form "w#w", where w is any combination of 0's and 1's or none at all. So let's say w = 011000 for this particular example. The resulting string will be 011000#011000 and your turing machine will be verifying if it follows this grammar.
Your turing machine has one head in this case. It starts at the beginning of string. Reads the first character which is 0. Mark it "x": meaning I've read this. Then goes immediately after the # and checks if what it just read is matching. In this case it's 0 as well so it marks it as matching "x". It then goes back to previous position and does the same for next character. It keeps doing this until it reaches #. When it reads hash or #, it checks for the end of the string and if it is the end of string, it accepts this string saying yes this follows the given grammar.

Is this language regular?

Is a language that accepts n(n-1)(n-2)/6+n(n-1)/2+1 many numbers of {0,1}^n for every n is a regular language?
I have a question to draw the dfa of those language, but I'm not even sure whether it is a regular one.
This sounds like homework, and I'm guessing the question is: draw a DFA that accepts exactly n(n-1)(n-2)/6+n(n-1)/2+1 words of length n (over the alphabet {0,1}). Lets construct the automaton as an intersection of two DFAs.
The first automaton accepts words of length n. This is very easy - there is a chain of n+1 states. The first state is the initial state, only the last state is accepting, and every state has a transition labeled 0,1 to the next state in the chain. The accepting state has no outgoing transitions.
The second automaton accepts words in which there is one, two, or three 1s. Also, very easy - we need 4 states: q_0, q_1, q_2, q_sink. The state q_0 is the initial state, the states q_0,q_1,q_2 are accepting, and they have a self loop with 0. There are transitions q_0 --1--> q_1 --1--> q_2 --1--> q_sink. Finally, q_sink is rejecting and it has a self loop with 0,1.
In order to construct the intersection of the automata we need the product of the two automata. This is a general construction which also isn't very hard.

Markov decision process - how to use optimal policy formula?

I have a task, where I have to calculate optimal policy
(Reinforcement Learning - Markov decision process) in the grid world (agent movies left,right,up,down).
In left table, there are Optimal values (V*).
In right table, there is sollution (directions) which I don't know how to get by using that "Optimal policy" formula.
Y=0.9 (discount factor)
And here is formula:
So if anyone knows how to use that formula, to get solution (those arrows), please help.
Edit: there is whole problem description on this page:
http://webdocs.cs.ualberta.ca/~sutton/book/ebook/node35.html
Rewards: state A(column 2, row 1) is followed by a reward of +10 and transition to state A', while state B(column 4, row 1) is followed by a reward of +5 and transition to state B'.
You can move: up,down,left,right. You cannot move outside the grid or stay in same place.
Break the math down, piece by piece:
The arg max (....) is telling you to find the argument, a, which maximizes everything in the parentheses. The variables a, s, and s' are an action, a state you're in, and a state that results from that action, respectively. So the arg max (...) is telling you to find an action that maximizes that term.
You know gamma, and someone did the hard work of calculating V*(s'), which is the value of that resulting state. So you know what to plug in there, right?
So what is p(s,a,s')? That is the probability that, starting from s and doing a, you end in some s'. This is meant to represent some kind of faulty actuator-- you say "go forward!" and it foolishly decides to go left (or two squares forward, or remain still, or whatever.) For this problem, I'd expect it to be given to you, but you haven't shared it with us. And the summation over s' is telling you that when you start in s, and you pick an action a, you need to sum over all possible resulting s' states. Again, you need the details of that p(s,a,s') function to know what those are.
And last, there is r(s,a) which is the reward for doing action a in state s, regardless of where you end up. In this problem it might be slightly negative, to represent a fuel cost. If there is a series of rewards in the grid and a grab action, it might be positive. You need that, too.
So, what to do? Pick a state s, and calculate your policy for it. For each s, you're going have the possibility of (s,a1), and (s,a2), and (s,a3), etc. You have to find the a that gives you the biggest result. And of course for each pair (s,a) you may (in fact, almost certainly will) have multiple values of s' to stick in the summation.
If this sounds like a lot of work, well, that's why we have computers.
PS - Read the problem description very carefully to find out what happens if you run into a wall.

Equivalence between two automata

Which is the best or easiest method for determining equivalence between two automata?
I.e., if given two finite automata A and B, how can I determine whether both recognize the same language?
They are both deterministic or both nondeterministic.
A different, simpler approach is to complement and intersect the automata. An automaton A is equivalent to B iff L(A) is contained in L(B) and vice versa which is iff the intersection between the complement of L(B) and L(A) is empty and vice versa.
Here is the algorithm for checking if L(A) is contained in L(B):
Complementation: First, determinize B using the subset construction. Then, make every accepting state rejecting and every rejecting state accepting. You get an automaton that recognizes the complement of L(B).
Intersection: Construct an automaton that recognizes the language that is the intersection of the complement of L(B) and L(A). I.e., construct an automaton for the intersection of the automaton from step 1 and A. To intersect two automata U and V you construct an automaton with the states U x V. The automaton moves from state (u,v) to (u',v') with letter a iff there are transitions u --a--> u' in U and v --a--> v' in V. The accepting states are states (u,v) where u is accepting in U and v is accepting in V.
After constructing the automaton in step 2, all that is needed is to check emptiness. I.e., is there a word that the automaton accepts. That's the easiest part -- find a path in the automaton from the initial state to an accepting state using the BFS algorithm.
If L(A) is contained in L(B) we need to run the same algorithm to check if L(B) is contained in L(A).
Two nondeterministic finite automota (NFA's) are equivalent if they accept the same language.
To determine whether they accept the same language, we look at the fact that every NFA has a minimal DFA, where no two states are identical. A minimal DFA is also unique. Thus, given two NFA's, if you find that their corresponding minimal DFA's are equivalent, then the two NFA's must also be equivalent.
For an in-depth study on this topic, I highly recommend that you read An Introduction to Formal Language and Automata.
I am just rephrasing answer by #Guy.
To compare languages accepted by both we have to figure out if L(A) is equal to L(B) or not.
Thus, you have to find out if L(A)-L(B) and L(B)-L(A) is null set or not. (Reason1)
Part1:
To find this out, we construct NFA X from NFA A and NFA B, .
If X is empty set then L(A) = L(B) else L(A) != L(B). (Reason2)
Part2:
Now, we have to find out an efficient way of proving or disproving X is empty set. When will be X empty as DFA or NFA? Answer: X will be empty when there is no path leading from starting state to any of the final state of X. We can use BFS or DFS for this.
Reason1: If both are null set then L(A) = L(B).
Reason2: We can prove that set of regular languages is closed under intersection and union. Thus we will able to create NFA X efficiently.
and for sets: