What is the Set defined by this Regular Expression? - regular-language

I am trying to go through regular expression and language questions however, this one seems to have gotten me stuck.
Can somebody help?
I am trying to write out the set that is defined by this regular expression:

To understand this regular expression, lets consider its three parts separately:
( a | Ɛ ) abb (a | b)
\---1---- --2--- ---3---
this regular expression is defined in three groups/parts using parenthesis
Part-1: Ɛ is a null symbol in regular expression, if it appears with some other symbol (or a group of symbols) with union operator | that means that symbol(or group) is option e.g. can be appear or not appear in some strings of language ( Ɛ symbols in FA as edge label defines 'null-transition' — which allows a transformation to a new state without consuming any input symbols).
In your regular expression, first 'a' is written with Ɛ — ( a | Ɛ ) so it is option - it can appear in some string or absent in other. Hence strings generated with using this regular expression either starts with two 'a' or one 'a'.
Part-2: Sub-string 'aab' always appears in all possible string using this regular expression.
so strings can be in two possible forms:
aabb(a|b)
abb(a|b)
Part-3: (a | b) string either ends with symbol 'a' or symbol 'b'.
if both above forms ends with 'a'
aabba
abba
if both above forms ends with 'b'
aabbb
abbb
Of-course it is a finite language and its DFA does not contain any loop. Its DFA for this language { aabba, abba, aabbb, abbb } would be as following:

Related

Is L = {ww^Ru | w, u ∈ {0,1}+} regular language?

let L = {wwRu | w, u ∈ {0,1}+}. Is L regular language ? Note that w, u cannot be empty.
I've tried to prove it is not regular language by the pumping lemma, but I failed when w = 0^p1^p, 01^p, (01)^p. Once I take y = 0^p or 1^p, xyyz will be 00.../11.../01^n0... etc.
And I cannot draw its DFA/NFA or write its regular expression to prove it is regular language.
So is L regular or not ? How can I prove it ?
The language is not regular, and we can prove it using the Myhill-Nerode theorem.
Consider the sequence of strings 01, 0101, ..., (01)^n, ...
First, notice that none of these strings are in the language. Any prefix of any of these strings which has even length is of the form (01)^2m for some m, and therefore just a shorter string in the sequence; splitting such a prefix in two either has both substrings start with 0 and end with 1, or else it has the first substring start and end with 0 and the second start and end with 1. In either case, these strings are not of the form w(w^R)u for any w or u.
Next, notice that the shortest possible string which we can append to any of these strings, to produce a string in the language, is always the reverse of itself followed by either 0 or 1. That is, to turn 01 into a string in the language, we must append 100 or 101; there are no shorter strings we can append to 01 to get a string in the language. The same holds true for 0101: 10100 and 10101 are the shortest possible strings that take 0101 to a string in L. And so on for each string of the form (01)^n.
This means that each string of the form (01)^n is distinguishable with respect to the target language w(w^R)u. The Myhill-Nerode theorem tells us that a minimal DFA for a regular language has exactly as many states as there are equivalence classes under the indistinguishability relation. Because we have infinitely many distinguishable strings with respect to our language, a minimal DFA for this language must have infinitely many states. But, a DFA cannot have infinitely many states; this is a contradiction. This means that our language cannot be regular.
The language is REGULAR:
L = 00(0+1)+ + 11(0+1)+ + 0(11)+0(0+1)+ + 1(00)+1(0+1)+

How to define a Alternative Label inside parenthesesn

This is part of my parser grammar:
expression:
multiplyingExpression
(
PLUS multiplyingExpression #plus
| MINUS multiplyingExpression #minus
)*;
I want to define plus and minus Alternative Label, apparently it doesn't allow me to do so.
at #plus and #minus it gives me the error:
missing RPAREN at '#' while look for rule element
Anybody knows how to achieve this whithout changing the structure of this rule's definition?
An alt label can only be defined on the outer edge (non-nested) of an alt. Therefore, cannot be done without changing the structure of the rule.
What can be done is to use an ordinary label to effectively achieve the desired result.
expression:
multiplyingExpression
( type+=PLUS multiplyingExpression
| type+=MINUS multiplyingExpression
)*;
The result is that the ExpressionContext will contain List<Token> type; whose successive values will, by inference, identify the alts matched.

design NFA which accepts specific length of strings

Im looking forward to design a FA which accepts some kind of string that accept some A and B.
First a string which the number of A is five more times higher than B.
i mean L={w∈{A,B}* and (nA(W)-nB(W) mod 5=0)
And also a FA which accept different number of character in a string:
L={A^n B^m C^k | n,k>0 and m>3}
I design some FAs But they did not work perfectly on this complicated strings.
Any help on how should i design this ?
Unfortunately, your questions are confusing as the english text doesn't agree with the mathematical formula. I will try to answer to these four questions then:
A language which consists of string over {a,b} that the number of a (= #a(w))
is five times as the number of b ( #b(w)),
L = { w in {a,b}* : #a(w)>#b(w) and #a(w)=#b(w)mod5 }
This cannot be done by an NFA. The proof is simple by using the pumping lemma (P.L) with the string a^pb^5p, where p is the constant of P.L.
For the language: L={w∈{A,B}* : (nA(W)-nB(W)) mod 5=0} that you wrote,
you can do it with an DFA that consists of a cycle of 5 states.
The transitions are, if you read a go clockwise if you read b go counter-clocwise. Choose at random one state to be initial state and the same state will be the final state.
For the language L={A^n B^m C^k | n,k>0 and m>3}, it should be easy to find out
if you read L as L=A(A)* B(B)* c^4(C)*
For the language that accepts different number of character in the string (let's say over a,b). The language should be R={ w in {a,b}* : #a(w) not equal #b(w)}
This language again it cannot be recognized by an NFA. If this language was regular (recognzied by an NFA) so would be this language:
L=a*b* intersection (R complement). The language L is {a^n b^n/ n non-negative integer}.
The language L is the first example of most books when they speak about languages that are non-regular.
Hopefully, you will find this answer helpful.

Cnnverting FSM to regular expression

I know how to convert regular expression into FSM but not exactly sure how to reverse it.
what would the regular expression for this example be?
Regular expression for your DFA will is (b + ab*a)*
The language description: Symbol b can appear in any fashion but restriction is a can to be for even number of times in language strings.
(b + ab*a)*
^ ^ ^
| | "* because loop on initial state"
| | "* on b because of self loop with label b on 2nd state"
|
|"+ because two outgoing edges, One is self loop other via 2nd state"
Here: + means Union, * means repetition for zero or more times
Note: Language string examples: {^, b, aa, bababb...}
(even as and any bs including null)

Can I have a value constructor named "/""?

I've declared a recursive data type with the following structure:
data Path = GET | POST | Slash Path String
I'd really like to rename that last value constructor to / so that I can infix it in cute expressions like GET /"controller"/"action". However, if I try to do so:
import Prelude hiding ((/))
infixr 5 /
data Path = GET | POST | Path / String
...then I get this:
Path.hs:4:30: parse error on input `/'
Those same three lines compile just fine if I replace / with :/ or any other special character sequence beginning with :.
So, is there any way I can name my value constructor /? I know that I can just name it Slash and then declare a separate function:
(/) :: Path -> String -> Path
(/) = Slash
...but that won't let me pattern match, as in:
request :: Path -> String
request path = case path of GET /"hello" -> "Hello!"
GET /"goodbye" -> "Goodbye!"
Short answer: No.
Long answer: Type classes, type names, and data constructors must begin with either a capital letter or a colon (some of this requires using a language extension). Everything else must begin with a lowercase letter or any other allowed symbol.
Note that type variables, which are normally lowercase identifiers, follow the same rules and do not begin with a colon.
See also the GHC user's guide for enabling type operators. Data constructors are always allowed, I think.
Personally, in your case I'd just use (:/). It doesn't look that bad, and after a while you get used to ignoring the colons. Some people like a trailing colon as well, especially if the data is "symmetric" in some sense.
No, you can't do this. In pure Haskell 98, user-defined type names and constructors must be alphanumeric and begin with an uppercase letter; this is in section 4.1.2 of the Haskell 98 Report. In GHC, just as user-defined constructors with alphanumeric names must begin with an uppercase letter, user-defined constructors which are operators must begin with a :.1 (The same is true for user-defined type names.) This is documented in section 7.4.2 of the GHC manual. I'd probably use :/, myself, with or without / as a synonym.
1: The reason for the "user-defined" qualification is that there are a few built-in exceptions: ->, [], (), and the tuple types (,), (,,), etc. as type names; and () and the tuple type constructors (,), (,,), etc., as type constructors
I think all constructor operators need to start with a colon, (but I may be wrong).
So you could do:
data Path = GET | POST | Path :/ String

Resources