How does the epsilon conversion work for NFA to DFA conversion? - dfa

This is the NFA:
Here are two tables I made for DFA and then my attempt for the DFA equivalent:
(source: yimg.com)
The problem is that it doesn't account for the epsilon, because I don't know how to convert when there are epsilon arrows.

This is an epsilon-NFA, just transform the epsilon-NFA into an equivalent NFA without the epsilon transitions. Make a table as you would do while transforming an NFA to a DFA, and instead of just checking where that state goes with an input, first, check the where it can go with epsilon transitions then with the input then again with the epsilon transition (this is called the epsilon-closure ). This way you will have sets of states you will reach with your inputs. The only thing you need to do is to mark any state that can reach a final state using only epsilon transition as final states as well. Then you can build an NFA without epsilon transitions and then you can use your knowledge to transform it into a DFA. Just an example; In your table, you show B has an empty set for the input 0 but it can actually take an epsilon transition to C and take a 0 there so it is actually not an empty set.

To account for the epsilon transitions you can do any number of epsilon transitions before and after your read the next symbol. So you don't only consider where you can go when you read the symbol 0 (as an example) but also consider where you can go when you do epsilon transitions before and after, like ε* 0 ε*.
This means that when you start at the state {A} and read the symbol 0 you can go to the following states:
A --0--> B
A --0--> B --ε--> C
A --0--> C
A --ε--> B --ε--> C --0--> C
And for reading the symbol 1 you can go to the following states:
A --1--> A
A --1--> A --ε--> B
A --1--> A --ε--> B --ε--> C
A --ε--> B --1--> B
A --ε--> B --1--> B --ε--> C
A --ε--> B --ε--> C --1--> C
So in your resulting DFA, the transition will look as follow:
+-------+---------+---------+
| state | 0 | 1 |
+-------+---------+---------+
| {A} | {B,C} | {A,B,C} |
+-------+---------+---------+

Related

Why is this DFA not accepted?

So I am supposed to construct a DFA that accepts sets of all strings over {0,1} of length 2:
So sigma = {0,1}
L = {00, 01, 10, 11}
What I initially tried was :
Why is it wrong?
Assuming B is final state, it can even accept string of length 1. Thats why. Add one more state to mark length 2 and it should be good.
A 0,1 B 0,1 (C) 0,1 D
( ) - accepted state
Also make sure anything more than length 3 results in non terminal state by adding a D.
This is the DFA you want:
This way, if another input symbol is present after the second one - you go from C to D and can never go back to an accepting state.
By the way, and perhaps more importantly - I didn't draw this image myself. I used graphviz, which is a neet tool you might use to visualize your DFAs. The code is:
digraph G {
node [shape="circle"];
Start [shape="none" label=""];
C [shape="doublecircle"];
Start -> A;
A -> B [label="0,1"];
B -> C [label="0,1"];
C -> D [label="0,1"];
D -> D [label="0,1"];
}
and there are online renderers even, like this one.
The "Start" node is a hack to get an arrow to point at the initial state of the DFA (this is why the image is centered on B despite there being 4 states).

Show that the language is decidable

How do I show this language
{<C,A,B> | C,A,B are DFAs, L(C) contains the shuffle of L(A) and L(B)}
is decidable ?
I believe if I can construct automatas for A and B, then I can get an automata that contains the shuffle of them.
I am also thinking about using emptiness testing but I have not made any progress yet.
Given DFAs A and B, construct a DFA D such that L(D) is equal to the shuffle of L(A) and L(B).
Then, construct two DFAs using the Cartesian Product Machine construction for the languages L(M1) = L(C) \ L(D) and L(M2) = L(D) \ L(C).
Determine which, if either of L(M1) and/or L(M2) is empty.
if L(M1) is empty and L(M2) is empty, L(C) is the shuffle of L(A) and L(B)
if L(M1) is empty, L(C) is a subset of the shuffle of L(A) and L(B)
if L(M2) is empty, L(C) is a superset of the shuffle of L(A) and L(B)
To do #1: create a new DFA whose states are triples (x, y, z) where:
x is a state from A
y is a state from B
z is either 1 or 2
The initial state of the DFA will be (qi_A, qi_B, 1). The input alphabet will be the union of the input alphabets of A and B. The transitions will be such that:
f((x,y,1), a) = (x',y,2) where f(x,a) = x' in machine A
f((x,y,2), b) = (x,y',1) where f(y,b) = y' in machine B
The accepting states shall be the states with are accepting in either A or B (or just B if you prefer).
To do #2: create a new DFA whose states are pairs (x, y) where:
x is a state from D
y is a state from C
The initial state of he DFA will be (qi_D, qi_C). The input alphabet will be the union of input alphabets of A and C. The transitions will be such that:
f((x,y),c) = (x',y') where f(x,c) = x' in D and f(y,c) = y' in C.
The accepting states will be:
states that are accepting in D but not C, for L(D) \ L(C)
states that are accepting in C but not D, for L(C) \ L(D)
To do #3:
You can minimize the DFAs using the well-known DFA minimization algorithm. Iff you end up with a DFA that has a single non-accepting state, the language is empty.
You can try all input strings up to the pumping length for the resulting DFA (strings that don't cause the DFA to enter any state more than once). If none of these are accepted by the DFA, then the DFA accepts no strings and the language is empty.

Theorem Solution by Resolution Refutation

I have the following problem which I need to solve by resolution method in Artificial Intelligence
I don't understand why the negation of dog(x) is added in the first clause and ///y in the fourth clause why negation of animal(Y) is added ...
I mean what is the need of negation there?
Recall that logical implication P → Q is equivalent to ¬P ∨ Q. You can verify this by looking at the truth table:
P Q P → Q
0 0 1
1 0 0
0 1 1
1 1 1
Now clearly dog(X) → animal(X) is equivalent to ¬dog(X) ∨ animal(X) which is a disjunction of literals therefore is a clause.
The same reasoning applies to animal(Y) → die(Y).
As soon as you have got a set of formulas in clausal form that is equivalent to your input knowledge base, you can apply binary resolution to check if your knowledge base is consistent, or to prove a goal.
To prove a goal you add a negation of it to your consistent knowledge base and see if the knowledge base with the added negation of the goal becomes inconsistent.

Can a DFA state have two arrows pointing to it with the same value?

I know that to be considered a DFA, each state cannot have more than one arrow with the same value pointing to another state. However, can a DFA have a state that has two arrows pointing to it with the same value?
Sure. As long as each response is deterministic, several states might go to the same state on the same next input. Since you can only be in one of the states, determinism isn't lost.
x
A ----> B
| |
|y |z
| |
V z V
C ----> D

Context Free pumping lemma

Is the following language context free?
L = {a^i b^k c^r d^s | i+s = k+r, i,k,r,s >= 0}
I've tried to come up with a context free grammar to generate this but I can not, so I'm assuming its not context free. As for my proof through contradiction:
Assume that L is context free,
Let p be the constant given by the pumping lemma,
Choose string S = a^p b^p c^p d^p where S = uvwxy
As |vwx| <= p, then at most vwx can contain two distinct symbols:
case a) vwx contains only a single type of symbol, therefore uv^2wx^2y will result in i+s != k+r
case b) vwx contains two types of symbols:
i) vwx is composed of b's and c's, therefore uv^2wx^2y will result in i+s != k+r
Now my problem is that if vwx is composed of either a's and b's, or c's and d's, then pumping them won't necessary break the language as i and k or s and r could increase in unison resulting in i+s == k+r.
Am I doing something wrong or is this a context free language?
I can't come up with a CFG to generate that particular language at the top of my head either, but we know that a language is context free iff some pushdown automata recognizes it.
Designing such a PDA won't be too difficult. Some ideas to get you started:
we know i+s=k+r. Equivalently, i-k-r+s = 0 (I wrote it in that order since that is the order in they appear). The crux of the problem is deciding what to do with the stack if (k+r)>i.
If you aren't familiar with PDA's or cannot use them to answer the problem, at least you know now that it is Context Free.
Good luck!
Here is a grammar that accepts this language:
A -> aAd
A -> B
A -> C
B -> aBc
B -> D
C -> bCd
C -> D
D -> bDc
D -> ε

Resources