0

I am practicing for an exam. I am trying to convert a language to a regular expression. The language and my solution is as follows:

$L=\{w∈\{a,b\}^+│|w|≥4\ and\ the\ second\ symbols\ from \ the \ front\ and\ the\ back\ are\ equal\}$

Solution: $(a+b)x(a+b)^* x(a+b) \ \ where\ x=(a+b)$

Is this correct? If not, can someone correct me. also, am I allowed to use variables in regular expressions?

Thanks in advance

Amine
  • 3
  • 1
  • 2
  • I think the definition of $L$ is unclear. Is $aabb \in L$? – Raphael Jun 15 '17 at 12:47
  • @Raphael No, it is not – Amine Jun 15 '17 at 12:55
  • So, $L = { wvw \mid x, w \in {a,b}^2, |w| = 2 }$? Then, the easiest (if maybe not fastest) route is probably to come up with an NFA and convert it. – Raphael Jun 15 '17 at 13:26
  • Regarding your attempt, if your notation means to imply that $x$ "matches" the same string, it's not a regular expression. If that was not the intent, then the regular expression matches $abba$ which is not in $L$. – Raphael Jun 15 '17 at 13:27
  • @Raphael I think that "the second symbols from the front and the back are equal" mean that the second and the second to last symbols are the same. In this case, $abba$ is in $L$. – André Souza Lemos Jun 15 '17 at 16:51
  • 1
    @AndréSouzaLemos Oh, right. In that case, I understand the attempt -- but it's not a regular expression. Amine, you may have regexps with capturing groups in mind, as they are encountered in programming libraries. Those are strictly more powerful than regular expressions as defined in TCS. – Raphael Jun 15 '17 at 21:08
  • If the variable only has a finite number of possible values, it can be eliminated by simply enumerating the alternatives. – rici Jun 16 '17 at 15:39

1 Answers1

1

You asked two questions. The usual rule on this site is to ask one question per post.

No, you're not allowed to use variables in regular expressions. Regular expressions have a formal definition. To qualify as a regular expression, you need to meet the requirements in the definition. The definition can be found on Wikipedia or in your favorite textbook, and you'll note that it does not allow "where" or "variables".

For your first question about how to find a regular expression for a language, take a look at How to prove a language is regular?.

D.W.
  • 159,275
  • 20
  • 227
  • 470