The language is an infinite set of chains that are defined by the next conditions.


1) The language chains may consist of symbols from the set {1,a,b}. 
2) The language chains always start from subchain '1a'.
3) Every languange chain has to include at least one subchain 'aa'.

For example:

1aa, 1abaa, 1aaab, 1aab1a, ... etc.

My current solution is this:

1a ((1+b)* a)* (a (1+b)*)* a (1+b+a)*

My solution seems to pass tests like these:

Allowed chains    : 1aa, 1aaa, 1abaa, 1aaba, 1aabaa, 1aab, 1aaab, 1aaabaaa
Not allowed chains: 1aba, 1abab, 1ababab

But I'm not quite sure if it's still correct. Is it correct?

If not, please offer your solution using only the type of formal language used in my solution.

  • $\begingroup$ But how to do this without priority parens ()? Using only iteration parens ()* is allowed. $\endgroup$ May 15 '14 at 11:35
  • $\begingroup$ Why should we just use parens in combination with the star-operator? $\endgroup$
    – Danny
    May 15 '14 at 11:38
  • $\begingroup$ Because I was told to use only the star-operator. So there's no solution without using the star-operator only? My solution seems to be Okay. If you see any kind of mistake in my solution, I would be grateful if you tell me about it. $\endgroup$ May 15 '14 at 11:51
  • $\begingroup$ Your solution seems to be right, but you also use 'concatenation' and 'or' in your solution.. so I do not understand why we can use everything except priority brackets. But if you want to do so, your expression seems to be fine. $\endgroup$
    – Danny
    May 15 '14 at 12:09
  • $\begingroup$ @Danny Your regexp is wrong: it doesn't match $1aab$. $\endgroup$ May 15 '14 at 15:21

One way to do it by hand, in such a simple case, would be to build a FA for condition 2, i.e. strings that start with $1a$, and another FA for condition 3, i.e. strings that contain $aa$. Both FAs have only 3 states.

Then you use the intersection construction to have an automaton that obeys both conditions. That remains simple enough if you organize your state pairs as a 3 by 3 matrix.

From that you can easily deduce a regular expression: $1(a+a(a+b+1)^*a)a(a+b+1)^*$

Your solution can be proved consistent (compliant with the stated conditions) with a case analysis over the two main star operators (cases depending on whether there is zero occurrence or at least one). One also has to prove it is complete, i.e. that it does cover all compliant strings.

If you have a constraint regarding the use of parentheses, you should state it in your question. Is there a reason for the constraint ?

Find more details in the answer to your other question about this language, and a comment on how to better write the question.

  • $\begingroup$ 1a((1+b)* a)*(a (1+b)*)*a(1+b+a)* - Is my version of solution correct too? I converted it into a context-free grammar and tried to run a couple of test chains. Still I haven't found any "errors" in my regexp. $\endgroup$ May 16 '14 at 20:26
  • $\begingroup$ As I said in my answer I did a quick check of consistency with the conditions, and I believe you regular expression is consistent with the conditions (I would have to write the proof fully to be really sure). However, I did not prove that any chain meeting your conditions is accounted for by that regular expression. That is a bit long and tedious to prove, unless it was built in a systematic way, which you can describe. This is why I used a systematic technique to build my solution: I know I can prove correctness quite easily (up to typos and mistakes). $\endgroup$
    – babou
    May 16 '14 at 20:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.