what is the regular expression for the automaton? - finite-automata

In this automaton how to find regular expression

There are three methods basically. Two are given in the book by Hopcroft and Ullman.
1) Calucalte R_ij recursively for all states i,j going through only k intermediate states.
2) Calculate regular expression by eliminating states between start state and a single final state. This is simpler than the first method.
3) Analyse and try to understand the DFA itself.
If we eliminate the middle state we have following
a_02 = (aa+ba)*(ab+bb) : Regular expression from state 0 to 2 without using arrow from state 2 to 0.
a_00 = (aa+ba)* : Regular expression from state 0 to 0 without using arrow from state 2 to 0.
We can now use the expression given in the textbook but at this stage we can also analyse the automata and come up with a solution. So finally R_02 becomes
((aa+ba)*(ab+bb)(a+b))*(aa+ba)*(ab+bb)

Related

DFA for odd sequences of 1 and 0

I want to create a DFA for language {1,0} which accepts only words build from sequences of odd 1 and 0.
I've found many examples for DFA with even/odd numbers of 0 and 1 in a string but not in each sequence of that string. I cannot grasp how to create said graph. Should it be build with 4 states or maybe 3?
Just thought about something, is this one correct or am I mistaken here?
Ok, so this one was wrong, but maybe this one?
With this one, however, I fell like you always have to start with either one 1 or one 0 and won't get more in the first sequence so it's not relly perfect...
Kind regards,
Give a deterministic finite automaton accepting those words over the alphabet {0, 1}, where each series of zeros and each series of 1s is of odd length.
Is not 100% unambiguous. I personally understand, that the empty word, and a word consisting solely of 0s or solely of 1s is also part of the language (if it is of odd length). Then something like the following should do the trick.
State 1 is the starting state. The "upper" branch (ie states 2, 3) is for accepting any odd number of 0, the "lower" branch (ie states 4,5) accepts any odd number of 1. You can "enter" the respective branch only by reading a single instance of the respective symbol, either starting from the empty word, or after reading an odd number of the respective other symbol.
For instance the word 1000111110001. After reading a single 1 you are in state 4. By reading a single 0, you switch to the "upper branch" and now can read any even (in this case 2) number of 0, which will always bring you back to the accepting state 2. Reading a 1 in state 3 is not possible (because the word would be invalid). Reading a single 1 in state 2 brings you back to state 4. And from here similar to the above, you can read any even number (in this case 4) of 1 which will always bring you back to the accepting state 4. And so on and so forth. If the symbol changes (or the word ends) after an even number of equal symbols, you are either in state 3 or 5, which are both not accepting, thus the word won't be accepted.

Z3 Conditional Statement

How to write a conditional statement in Z3.
eg:
if (a%2==0){
value=1
}
I am trying to achieve this in Z3 Solver by Microsoft Research but so far no luck
Look up SSA form: https://en.wikipedia.org/wiki/Static_single_assignment_form
Essentially, you'll have to change your program to look something like:
value_0 = 0
value_1 = (a%2 == 0) ? 1 : value_0
Once it is in this so called static single assignment form, you can now translate each line more or less directly; with the latest assignment to value_N being the final value of value.
Loops will be problematic: The usual strategy is to unroll them up to a certain count (bounded model checking), and hope that this suffices. If you detect that the last unrolling isn't sufficient, then you can generate an uninterpreted value at that point; which might cause your proofs to fail with spurious counter-examples; but that's the best you can do without a scheme that involves proper handling of induction and loop-invariants.
Note that this field of study is called "symbolic execution" and has a long history, with active research still being conducted. You might want to read through this: https://en.wikipedia.org/wiki/Symbolic_execution

DFA minimization algorithm understanding

I'm trying to understand this algorithm the DFA minimization algorithm at http://www.cs.umd.edu/class/fall2009/cmsc330/lectures/discussion2.pdf where it says:
while until there is no change in the table contents:
For each pair of states (p,q) and each character a in the alphabet:
if Distinct(p,q) is empty and Distinct(δ(p,a), δ(q,a)) is not empty:
set distinct(p,q) to be x
The bit I don't understand is "Distinct(δ(p,a), δ(q,a))" I think I understand the transition function where δ(p,a) = whatever state is reached from p with input a. but with the following DFA:
http://i.stack.imgur.com/arZ8O.png
resulting in this table:
imgur.com/Vg38ZDN.png
shouldn't (c,b) also be marked as an x since distinct(δ(b,0), δ(c,0)) is not empty (d) ?
Distinct(δ(p,a), δ(q,a)) will only be non-empty if δ(p,a) and δ(q,a) are distinct. In your example, δ(b,0) and δ(c,0) are both d. Distinct(d, d) is empty since it doesn't make sense for d to be distinct with itself. Since Distinct(d, d) is empty, we don't mark Distinct(c, b).
In general, Distinct(p, p) where p is a state will always be empty. Better yet, we don't consider it because it doesn't make sense.

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.

What is the language of this deterministic finite automata?

Given:
I have no idea what the accepted language is.
From looking at it you can get several end results:
1.) bb
2.) ab(a,b)
3.) bbab(a, b)
4.) bbaaa
How to write regular expression for a DFA
In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch.
A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always possible.
Let's see what information stored in the DFA (refer my colorful figure).
(note: In my explanation any number means zero or more times and Λ is null symbol)
State-1: is START state and information stored in it is even number of a has been come. And ZERO b.
Regular Expression(RE) for this state is = (aa)*.
State-4: Odd number of a has been come. And ZERO b.
Regular Expression for this state is = (aa)*a.
Figure: a BLUE states = EVEN number of a, and RED states = ODD number of a has been come.
NOTICE: Once first b has been come, move can't back to state-1 and state-4.
State-5: comes after Yellow b. Yellow b means b after odd numbers of a.
Once you gets b after odd numbers of a(at state-5) every thing is acceptable because there is self a loop for (b,a) at state-5.
You can write for state-5 : Yellow-b followed-by any string of a, b that is = Yellow-b (a + b)*
State-6: Just to differentiate whether odd a or even.
State-2: comes after even a then b then any number of b. = (aa)* bb*
State-3: comes after state-2 then first a then there is a loop via state-6.
We can write for state-3 comes = state-2 a (aa)* = (aa)*bb* a (aa)*
Because in our DFA, we have three final states so language accepted by DFA is union (+ in RE) of three RL (or three RE).
So the language accepted by the DFA is corresponding to three accepting states-2,3,5, And we can write like:
State-2 + state-3 + state-5
(aa)*bb* + (aa)*bb* a (aa)* + Yellow-b (a + b)*
I forgot to explain how Yellow-b comes?
ANSWER: Yellow-b is a b after state-4 or state-3. And we can write like:
Yellow-b = ( state-4 + state-3 ) b = ( (aa)*a + (aa)*bb* a (aa)* ) b
[ANSWER]
(aa)*bb* + (aa)*bb* a (aa)* + ( (aa)*a + (aa)*bb* a (aa)* ) b (a + b)*
English Description of Language: DFA accepts union of three languages
EVEN NUMBERs OF a's, FOLLOWED BY ONE OR MORE b's,
EVEN NUMBERs OF a's, FOLLOWED BY ONE OR MORE b's, FOLLOWED BY ODD NUMBERs OF a's.
A PREFIX STRING OF a AND b WITH ODD NUMBER OF a's, FOLLOWED BY b, FOLLOWED BY ANY STRING OF a AND b AND Λ.
English Description is complex but this the only way to describe the language. You can improve it by first convert given DFA into minimized DFA then write RE and description.
Also, there is a Derivative Method to find RE from a given Transition Graph using Arden's Theorem. I have explained here how to write a regular expression for a DFA using Arden's theorem. The transition graph must first be converted into a standard form without the null-move and single start state. But I prefer to learn Theory of computation by analysis instead of using the Mathematical derivation approach.
I guess this question isn't relevant anymore :) and it's probably better to guide you through it then just stating the answer, but I think I got a basic expression that covers it (it's probably minimizable), so i'll just write it down for future searchers
(aa)*b(b)* // for stoping at 2
U
(aa)*b(b)*a(aa)* // for stoping at 3
U
(aa)*b(b)*a(aa)*b((a)*(b)*)* // for stoping at 5 via 3
U
a(aa)*b((a)*(b)*)* // for stoping at 5 via 4
The examples (1 - 4) that you give there are not the language accepted by the DFA. They are merely strings that belong to the language that the DFA accepts. Therefore, they all fall in the same language.
If you want to figure out the regular expression that defines that DFA, you will need to do something called k-path induction, and you can read up on it here.