• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • esc pour rejeter
⌘ '
raccourcis clavier

Question 1

Give regular expressions for the languages below

L={anbm(n+m)%2=0}L = \{ a^n b^m \mid (n+m)\%2 = 0 \}

(aa)(bb)+a(aa)b(bb)\boxed{(aa)^{*}(bb)^{*} + a(aa)^{*}b(bb)^{*}}

L={ww does not contain the substring: aba}L = \{ w \mid w \text{ does not contain the substring: } aba \}

ba((bb)ba)b\boxed{b^{*}a^{*}((bb)b^{*}a^{*})^{*}b^{*}}

L={ww has an even number of bs}L = \{ w \mid w \text{ has an even number of } b's \}

(abab)a\boxed{(a^{*}ba^{*}b)^{*} a^{*}}

Question 2

Minimize the number of states in DFA via quotient construction.

Note that all newly marked notes will be highlighted yellow.

Initial setup

0123456789
0
1x
2x
3xx
4xx
5xx
6xx
7xx
8xx
9xx

Iteration 1:

  • (δ(0,a),δ(3,a))=(1,4)(\delta (0,a), \delta (3,a)) = (1,4), which is unmarked, skipped

Iteration 2:

0123456789
0
1x
2xx
3xx
4xx
5xxx
6xx
7xx
8xx
9xx
  • (δ(1,a),δ(2,a))=(2,3)(\delta (1,a), \delta (2,a)) = (2,3), which is marked, mark (1,2)(1,2)
  • (δ(1,a),δ(4,a))=(2,5)(\delta (1,a), \delta (4,a)) = (2,5), which is unmarked, skipped
  • (δ(1,a),δ(5,a))=(2,0)(\delta (1,a), \delta (5,a)) = (2,0), which is marked, mark (1,5)(1,5)
  • (δ(1,a),δ(6,a))=(2,7)(\delta (1,a), \delta (6,a)) = (2,7), which is unmarked, skipped
  • (δ(1,a),δ(7,a))=(2,9)(\delta (1,a), \delta (7,a)) = (2,9), which is unmarked, skipped
  • (δ(1,a),δ(8,a))=(2,9)(\delta (1,a), \delta (8,a)) = (2,9), which is unmarked, skipped
  • (δ(1,a),δ(9,a))=(2,7)(\delta (1,a), \delta (9,a)) = (2,7), which is unmarked, skipped

Iteration 3:

0123456789
0
1x
2xx
3xx
4xxx
5xxx
6xxx
7xxx
8xxx
9xxx
  • (δ(2,a),δ(4,a))=(3,5)(\delta (2,a), \delta (4,a)) = (3,5), which is marked, mark (2,4)(2,4)
  • (δ(2,a),δ(5,a))=(3,0)(\delta (2,a), \delta (5,a)) = (3,0), which is unmarked, skipped
  • (δ(2,a),δ(6,a))=(3,7)(\delta (2,a), \delta (6,a)) = (3,7), which is marked, mark (2,6)(2,6)
  • (δ(2,a),δ(7,a))=(3,9)(\delta (2,a), \delta (7,a)) = (3,9), which is marked, mark (2,7)(2,7)
  • (δ(2,a),δ(8,a))=(3,9)(\delta (2,a), \delta (8,a)) = (3,9), which is marked, mark (2,8)(2,8)
  • (δ(2,a),δ(9,a))=(3,7)(\delta (2,a), \delta (9,a)) = (3,7), which is marked, mark (2,9)(2,9)

Iteration 4:

0123456789
0
1x
2xx
3xx
4xxx
5xxxx
6xxx
7xxx
8xxx
9xxx
  • (δ(4,a),δ(5,a))=(5,0)(\delta (4,a), \delta (5,a)) = (5,0), which is marked, mark (4,5)(4,5)
  • (δ(4,a),δ(6,a))=(5,7)(\delta (4,a), \delta (6,a)) = (5,7), which is unmarked, skipped
  • (δ(4,a),δ(7,a))=(5,9)(\delta (4,a), \delta (7,a)) = (5,9), which is unmarked, skipped
  • (δ(4,a),δ(8,a))=(5,9)(\delta (4,a), \delta (8,a)) = (5,9), which is unmarked, skipped
  • (δ(4,a),δ(9,a))=(5,7)(\delta (4,a), \delta (9,a)) = (5,7), which is unmarked, skipped

Iteration 5:

0123456789
0
1x
2xx
3xx
4xxx
5xxxx
6xxxx
7xxxx
8xxxx
9xxxx
  • (δ(5,a),δ(6,a))=(0,7)(\delta (5,a), \delta (6,a)) = (0,7), which is marked, mark (5,6)(5,6)
  • (δ(5,a),δ(7,a))=(0,9)(\delta (5,a), \delta (7,a)) = (0,9), which is marked, mark (5,7)(5,7)
  • (δ(5,a),δ(8,a))=(0,9)(\delta (5,a), \delta (8,a)) = (0,9), which is marked, mark (5,8)(5,8)
  • (δ(5,a),δ(9,a))=(0,7)(\delta (5,a), \delta (9,a)) = (0,7), which is marked, mark (5,9)(5,9)

Iteration 6:

0123456789
0
1x
2xx
3xx
4xxx
5xxxx
6xxxx
7xxxx
8xxxx
9xxxx
  • (δ(6,a),δ(7,a))=(7,9)(\delta (6,a), \delta (7,a)) = (7,9), which is unmarked, skip
  • (δ(6,a),δ(8,a))=(7,9)(\delta (6,a), \delta (8,a)) = (7,9), which is unmarked, skip
  • (δ(6,a),δ(9,a))=(7,7)(\delta (6,a), \delta (9,a)) = (7,7), which is unmarked, skip

We stopped here, given that 7,8,9 doesn’t contains any direct transition on a to any final states.

The final transition table are as follows:

0123456789
0xxxxxxxx
1xxxx
2xxxxxxx
3xxxxxxxx
4xxxx
5xxxxxxxx
6xxxx
7xxxx
8xxxx
9xxxx

We have the following states are equivalent:

  • 1467891 \approx 4 \approx 6 \approx 7 \approx 8 \approx 9
  • 252 \approx 5

Final DFA

Question 3

Your friend is looking at the formal definition of the pumping lemma and they think something is wrong

L is regular     (kk>0:(x,y,zxyzLy>k:(u,v,wy=uvwvϵ:(ii0:xuviwzL))))L \text{ is regular } \implies (\exists k \mid k>0: (\forall x,y,z \mid xyz \in L \land |y| > k: ( \exists u,v,w \mid y=uvw \land v \neq \epsilon: (\forall i | i \geq 0: xuv^iwz \in L))))

They understand the argument it is crafted around, that is, due to the fact that strings are arbitrarily long and a DFA has finite states there must be a segment of accepted strings which “loop” in the machine. However, they claim for the pumping lemma above to hold, LL must be infinite, because if LL was finite the argument about “looping” no longer holds. Therefore, the pumping lemma only holds when LL is infinite.

You can see where your friend is coming from, but they are incorrect. Why? Be precise in your argument, that is, show how if LL is finite, then

(kk>0:(x,y,zxyzLy>k:(u,v,wy=uvwvϵ:(ii0:xuviwzL))))(\exists k \mid k > 0: (\forall x,y,z \mid xyz \in L \land |y| > k: ( \exists u,v,w \mid y=uvw \land v \neq \epsilon: (\forall i | i \geq 0: xuv^iwz \in L))))

evaluate to true.

The Pumping lemma also holds for finite regular language as well.

We need to show that if we assume LL is finite, then the pumping lemma is True.

Now, there exists a longest string in L called mm, choose k=mk^{'} = |m|

Consider the “forall” section x,y,zxyzLy>k\forall x,y,z \mid xyz \in L \land |y| >k is False:

  • For any string xyzLxyz \in L we know that xyzm|xyz| \le m (since m is the longest string in LL)
  • since yy is a substring of xyzxyz, we must have yxyzm=k|y| \le |xyz| \le m = k

Given that the antecedent (“if” part) of an implication is false, the entire implication is vacuous truth (when the set is empty)

Therefore, the entire condition is true via vacuous truth (it holds trivially, as there are no strings xyzLy>kxyz \in L \mid |y| > k)

Question 4

Using the Pumping Lemma, prove the following languages are not regular.

L={anmbmann,m0}L = \{ a^{nm} b^{m} a^{n} \mid n,m \ge 0 \}

  1. The demon first pick k=n=mk=n=m
  2. Choose x=ak2,y=bk,z=akx=a^{k^{2}}, y=b^{k}, z=a^{k}
  3. pick u=bj,v=br,w=blu=b^{j},v=b^{r},w=b^{l} such that j+r+l=k,r>0j+r+l=k, r>0
  4. pick s=xuviwz=ak2bj(br)iblaks^{'} = xuv^{i}wz = a^{k^{2}}b^{j}(b^{r})^{i}b^{l}a^{k} use i=2i=2 we have s=ak2bjb2rblak=ak2brbkak\begin{aligned} s^{'}&=a^{k^{2}}b^{j}b^{2r}b^{l}a^{k} \\ &=a^{k^{2}}b^{r}b^{k}a^{k} \end{aligned}
  5. That sLs^{'} \notin L, therefore LL is not regular

q.e.d\boxed{q.e.d}

L={wwwΣ}L = \{ww \mid w \in \Sigma^*\}

  1. The demon pick k
  2. Choose x=akb,y=ak,z=bx=a^{k}b,y=a^{k},z=b
  3. pick u=aj,v=ar,w=alu=a^{j},v=a^{r},w=a^{l} such that j+r+l=k,r>0j+r+l=k, r>0
  4. pick s=xuviwz=akbaj(ar)ialbs^{'} = xuv^{i}wz = a^{k}ba^{j}(a^{r})^{i}a^{l}b use i=2i=2 we have s=akbaja2ralb=akbarakb\begin{aligned} s^{'}&=a^{k}ba^{j}a^{2r}a^{l}b \\ &=a^{k}ba^{r}a^{k}b \end{aligned}
  5. That sLs^{'} \notin L, therefore LL is not regular

q.e.d\boxed{q.e.d}

L={ak3k0}L = \{a^{k^{3} } \mid k \ge 0\}

  1. The demon pick k
  2. Choose x=z=ϵ,y=ak3x=z=\epsilon,y=a^{k^{3}}
  3. pick u=aj,v=ar,w=alu=a^{j},v=a^{r},w=a^{l} such that j+r+l=k3,r>0,j+rkj+r+l=k^{3}, r>0, j+r\le k
  4. pick s=xuviwz=aj(ar)ials^{'} = xuv^{i}wz = a^{j}(a^{r})^{i}a^{l} use i=2i=2 we have s=aj(ar)2al=ak3+r\begin{aligned} s^{'}&=a^{j}(a^{r})^{2}a^{l} \\ &=a^{k^{3}+r} \end{aligned} We can prove that k3<k3+r<(k+1)3k^{3} < k^{3}+r <(k+1)^{3}
    • Since r>0r>0, we have k3<k3+rk^{3}<k^{3}+r
    • Given rkr\le k therefore (k+1)3=k3+3k2+3k+1>k3+kk3+r(k+1)^{3} = k^{3}+3k^{2}+3k+1 > k^{3} + k \ge k^{3}+r Therefore, k3+rk^{3}+r cannot be a perfect cube
  5. That sLs^{'} \notin L, therefore LL is not regular

q.e.d\boxed{q.e.d}

Question 5

Give the CFGs for the following language

L={anbmcknm+k}L = \{a^{n}b^{m}c^{k} \mid n \neq m + k\}

L=L1L2L = L_{1} \cup L_{2} where

  • L1={anbmckn<m+k}L_{1} = \{a^{n}b^{m}c^{k} \mid n < m+k\}
  • L2={anbmckn>m+k}L_{2} = \{a^{n}b^{m}c^{k} \mid n > m+k\}

Let grammar G=(V,Σ,R,S)G = (V, \Sigma, R, S) where:

  • V={S,S1,S2,A,B}V = \{S, S_{1}, S_{2}, A, B\} be set of variables
  • Σ={a,b,c}\Sigma = \{a,b,c\} be the set of terminals
SS1S2S1aS1aAAaAbBBaBcϵS2S2bS2cCCaCbDDaDcϵ\begin{aligned} S &\to S_{1} \mid S_{2} \\ S_{1} &\to aS_{1} \mid aA \\ A &\to aAb \mid B \\ B &\to aBc \mid \epsilon \\ S_{2} &\to S_{2}b | S_{2}c | C\\ C &\to aCb | D\\ D &\to aDc | \epsilon \end{aligned}

L={anbmckn=m+k}L=\{a^{n}b^{m}c^{k} \mid n = m+k\}

SaScUUaUbϵ\begin{aligned} S &\to aSc \mid U\\ U &\to aUb \mid \epsilon \end{aligned}