5

This question is on the GRE Computer Science test booklet (not homework). I tried applying closure properties of regular languages but no success.

Suppose $L$ is a regular language over $\Sigma = \{0, 1\}$. Show that the language

$\qquad L' = \{w \in L \mid |w| \in 2\mathbb{N}\}$

is also regular.

What I find surprising is that the booklet mentions that the language $\{w \in L \mid |w| = 2^k, k \in \mathbb{N}\}$ is not necessarily a regular language.

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • 3
    by closure properties, do intersection of $L$ with $E={w \mid |w|$ is even $}$. – Ran G. Mar 31 '13 at 07:00
  • 2
    Which closure properties have you tried? As the answers illustrate, there is a very basic answer using closure properties. For the second part of the question, see our reference question; I imagine that Parikh's theorem is interesting for you. – Raphael Apr 02 '13 at 08:18

4 Answers4

5

The language $Even = \{w\in\Sigma^{\ast}\mid \text{length of }w\text{ is even}\}$ is regular. user5507's answer demonstrates this with an NFA, and it's a basic exercise in most texts.

Then given that $L$ is regular, if we know that regular languages are closed under intersection for the purposes of the question, then the language $L'=L\cap Even$ is also regular.

If we're not allowed to use these closure properties, we can recapitulate the construction that gives the closure property (I'll just sketch it). Given a DFA $M_{L}$ for $L$ and a DFA $M_{Even}$ for $Even$, we can construct a DFA for $L' = L\cap Even$ that has a state space that is the product of the state spaces of $M_{L}$ and $M_{Even}$, with the follow transition rule: if $\delta_{L}(\sigma, q_{i}) = q_{j}$ and $\delta_{Even}(\sigma, p_{m})=p_{n}$ where $\sigma \in \Sigma$ and the $p$s and $q$s are states of the appropriate machines, then the product machine has a transition $\delta_{prod}(\sigma,(q_{i}, p_{m})) = (q_{j}, p_{n})$. Our accepting states are those states $(q_{i},p_{j})$ where $q_{i}$ and $p_{j}$ are accepting states in their respective machines.

That's the long an fiddly way around.

The second question depends on $L$, that is, if $L$ is not regular, then the intersection of $L$ and $Even$ may is not necessarily regular - the $w\in L$ in the definition is key.

EDIT: actually, reading vonbrand's answer, I misunderstood the second part. He is quite correct - the second language is the intersection of $L$ and $X=\{w\in\Sigma^{\ast}\mid \exists i \in \mathbb{N} \text{ such that } |w| = 2^{i}\}$ - not $Even$. So while what I said about $L \cap Even$ with $L$ not regular holds, $X$ isn't regular to begin with, so we get the same situation, but $L$ is regular and $X$ isn't.

Luke Mathieson
  • 18,125
  • 4
  • 55
  • 86
3

For the language with lengths an integer power of two, they can be regular only if they are finite. It is easy to prove by the pumping lemma that an infinite language of such kind can't be regular (just look at the lengths of the strings).

frafl
  • 2,299
  • 1
  • 16
  • 32
vonbrand
  • 14,004
  • 3
  • 40
  • 50
0

If the number of even-length strings in $L$ is finite (say $w_i,i \in \{1,\dots,n\}$, then $L^\prime$ is regular and the regex $(w_1\mid \dots \mid w_n)$ accepts it. If it's infinite, then by the pumping lemma we know that for strings $w \in L$, there are strings $x,y,z$ such that $w=xy^iz\in L$ for $i=0,1,2,\dots$. A case-analysis is required:

  1. $x,y,z$ are odd-length, $i$ is even: the regex $x(yy)^*z$ accepts case-1 even-length strings.

You should be able to fill in the missing cases. Now a regex accepting strings in $L^\prime$ can be formed by taking the union of the regex's of each case. The resulting regex accepts even-length strings in $L$.

mrk
  • 3,688
  • 22
  • 35
-2

We need to show that

$\{w ∈ L |$ length of w is even$\}$ is regular.

In order to show that, it is enough to construct an NFA/DFA for that. You can construct an NFA for this like

enter image description here

user5507
  • 2,191
  • 4
  • 24
  • 41
  • 1
    Not exactly. This is a DFA for $L={w \mid |w|$ is even $}, and not the language the OP asked for.. – Ran G. Mar 31 '13 at 06:59
  • @RanG. OP asked for the same thing. I have given an NFA, not a DFA. – user5507 Mar 31 '13 at 07:55
  • @user5507 The OP's question is: given a regular language $L$, show that all even sized words of $L$ also form a regular language. What you show is that a language with only even sized words is regular. – Paresh Mar 31 '13 at 09:11
  • @Paresh $L$ is defined over $\Sigma={0,1}$. Then his $L$ means all even sized words. That is what I represented using NFA!. Can you please elaborate on where I went wrong? – user5507 Mar 31 '13 at 14:16
  • $L$ is defined over $\Sigma$, but $L$ is not the same as $\Sigma^$. $L$ could be a subset of $\Sigma^$. The OP's language consists of even sized words that are also in $L$, and does not contain those even sized words that are not in $L$. As an example, if $L = {0,1,00}$ ($L$ is regular), then the DFA for $L^\prime$ should accept $00$ but not $01$ or $11$. – Paresh Mar 31 '13 at 15:48
  • @Paresh Where it says that $01$ is not a member of that language? – user5507 Apr 01 '13 at 00:23
  • 2
    $L$ is a regular language. $L^\prime$ is a language that only contains even sized words which are also in $L$. So, as an example, if $L = {0,1,00}$, then $L^\prime = {00}$. If $L={0,1}$, then $L^\prime$ is empty. And so on. – Paresh Apr 02 '13 at 05:21
  • I agree with @Paresh here. There is no mention of what are the alphabets of $\Sigma$. I have a proof that EVEN is regular via the Myhill-Nerode Theorem. I believe using it solves the problem without making any assumptions about the alphabet in $\Sigma$. I would most welcome any critique you might have in http://unpocologico.wordpress.com/2013/11/02/myhill-nerode-theorem-to-the-rescue-showing-a-language-is-regular-without-dfas/ – user11128 Nov 01 '13 at 23:26
  • There is no need to use Myhill-Nerode. For every $\Sigma$, it is easy to construct a DFA for EVEN with two states, hence EVEN is regular. This also follows from the existence of a regexp for it, namely $(\Sigma\Sigma)^*$. Then you can intersect $L$ with EVEN. If you don't like this proof, you can take a DFA for $L$, double the number of states, make each transition go from one copy to the other, and retain the accepting states only on the "even" copy. This is what the product construction gives in this case. No reference to $\Sigma$ here at all. – Yuval Filmus Nov 02 '13 at 00:05
  • "For every Σ, it is easy to construct a DFA for EVEN with two states, hence EVEN is regular. " Huh? Easy? Sorry for being thick, this is not concrete for me, so Myhill-Nerode won't hurt. Cheers. – user11128 Nov 02 '13 at 01:36
  • Here is the DFA. There are two states $s_0,s_1$, $s_0$ is the starting state, the set of accepting states is $F = {s_0}$, and the transition function is $q(s_i,\sigma) = s_{1-i}$. This is pretty concrete. – Yuval Filmus Nov 02 '13 at 01:53