I need help to solve in regular expression way. The language of all strings defined over Σ = {X, Y, Z} with Y as the third letter and Z being the second last letter
.

- 73,866
- 12
- 100
- 156

- 155
- 2
- 3
- 11
3 Answers
If you are allowed to use intersection (which does preserve rationality), I would state it simply as ΣΣYΣ* & Σ*ZΣ
. If you feed this to Vcsn to normalize it, you get:
In [1]: import vcsn
In [2]: vcsn.B.expression('([XYZ]{2}Y[XYZ]*)&([XYZ]*Z[XYZ])').derived_term().expression()
Out[2]: (X+Y+Z)ZY+(X+Y+Z)(X+Y+Z)Y(X+Y+Z)*Z(X+Y+Z)
The call to derived_term
is to build an automaton from the expression, and the last call to expression
is to extract a rational expression from this automaton.

- 8,255
- 3
- 44
- 60
As given Σ = {X, Y, Z} , you need to construct the language of all strings defined over it with Y as third letter and Z being the second last letter.
"ΣΣYΣ*ZΣ | ΣZY" will be the required regular expression.
Σ* has all strings that are 0 or more concatenations of strings from Σ.
As you can see, here Y being the third element and Z is placed in second last position. And, Σ can be replaced with any of the X,Y or Z element.

- 18,735
- 7
- 49
- 73
-
Sorry, I couldn't comprehend your statement @akim. Would you be please more specific? OR point at the exact error according to you. – Am_I_Helpful May 22 '15 at 08:30
-
2For instance `XZY` is correct. Your solution includes only "long" answers, but misses the case where the second to last letter is actually before the third one. The right answer is `ΣZY|ΣΣYΣ*ZΣ`. – akim May 22 '15 at 08:34
-
Thanks @akim. By the way you should have edited my answer to reflect that, editing for correction is always ''most welcome'' from my side. :) – Am_I_Helpful May 22 '15 at 13:43
i think regular expression should be like this....
(x+y+z)zy(x+y+z)^*

- 1,105
- 4
- 30
- 68