---
date: '2024-03-18'
description: and second assignment.
id: A2
modified: 2026-06-05 15:08:39 GMT-04:00
tags:
  - sfwr2fa3
title: Regex, pumping lemma
created: '2024-03-18'
published: '2024-03-18'
pageLayout: default
slug: thoughts/university/twenty-four-twenty-five/sfwr-2fa3/rev1/a2/A2
permalink: https://aarnphm.xyz/thoughts/university/twenty-four-twenty-five/sfwr-2fa3/rev1/a2/A2.md
generator:
  quartz: v4.6.0
  hostedProvider: Cloudflare
  baseUrl: aarnphm.xyz
full: https://aarnphm.xyz/llms-full.txt
---
> \[!note\]- solutions
>
> <iframe src="thoughts/university/twenty-four-twenty-five/sfwr-2fa3/rev1/a2/sols.html"></iframe>

## Problème 1.

Give regular expression for the languages bellow

> \[!question\] 1.a
>
> $$
> L = \{ a^nb^m \mid (n+m) \% 2 = 0 \}
> $$

$$
L = (aa)^*(bb)^* + a(aa)^*b(bb)^*
$$

> \[!question\] 1.b
>
> $$
> L = \{ w \mid w \text{ does not contain the substring: } aba \}
> $$

$$
L = b^* + b^*a^+b^* + b^*(ab^+)^*ab^*
$$

> \[!question\] 1.c
>
> $$
> L = \{ w \mid w \text{ has an even number of } b' \text{s}\}
> $$

$$
L = a^* + a^*ba^*ba^*
$$

## Problème 2.

Minimize the number of states in this DFA via quotient construction. Show all your steps, specifically in your table where you are “marking” nodes indicate which iteration you marked them on.

Final states $\{ 0, 3 \}$, and non-final states are $\{ 1, 2, 4, 5, 6, 7, 8, 9 \}
$

Initial table with all pairs:

```plaintext
      0 1 2 3 4 5 6 7 8 9
    ---------------------
0   |   *       * *
1   | *   *       *
2   |   *   *       *
3   |     *   *       *
4   |       *   *     *
5   | *       *   *   * *
6   | * *       *   *   *
7   |     *       *   * *
8   |       * * *   *   *
9   |           * * * *
```

Mark based on final/non-final states:

```plaintext
      0 1 2 3 4 5 6 7 8 9
    ---------------------
0   |   ✓       ✓ ✓
1   | ✓
2   |       ✓
3   |     ✓   ✓       ✓
4   |       ✓
5   | ✓
6   | ✓
7   |
8   |       ✓
9   |
```

### first iteration.

\{0,2\} -(a)<span>&rarr;</span> \{1,3\}: not marked
\{0,2\} -(b)<span>&rarr;</span> \{6,7\}: not marked
\{0,3\} -(a)<span>&rarr;</span> \{1,4\}: not marked
\{0,3\} -(b)<span>&rarr;</span> \{6,8\}: not marked
\{0,4\} -(a)<span>&rarr;</span> \{1,5\}: not marked
\{0,4\} -(b)<span>&rarr;</span> \{6,8\}: not marked
\{0,7\} -(a)<span>&rarr;</span> \{1,9\}: not marked
\{0,7\} -(b)<span>&rarr;</span> \{6,8\}: not marked
\{0,8\} -(a)<span>&rarr;</span> \{1,9\}: not marked
\{0,8\} -(b)<span>&rarr;</span> \{6,5\}: not marked
\{0,9\} -(a)<span>&rarr;</span> \{1,7\}: not marked
\{0,9\} -(b)<span>&rarr;</span> \{6,6\}: not marked

```plaintext
      0 1 2 3 4 5 6 7 8 9
    ---------------------
0   |   ✓       ✓ ✓
1   | ✓
2   |       ✓
3   |     ✓   ✓       ✓
4   |       ✓
5   | ✓
6   | ✓
7   |
8   |       ✓
9   |
```

### second iteration.

\{1,2\} -(a)<span>&rarr;</span> \{2,3\}: marked so we mark \{1,2\}
\{1,5\} -(a)<span>&rarr;</span> \{2,0\}:

```plaintext
      0 1 2 3 4 5 6 7 8 9
    ---------------------
0   |   ✓       ✓ ✓
1   | ✓
2   |   x   ✓
3   |     ✓   ✓       ✓
4   |       ✓
5   | ✓
6   | ✓
7   |
8   |       ✓
9   |
```

_sorry I gave up_

### Problème 3.

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

$$
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, $L$ must be infinite, because if $L$ was finite the argument about “looping” no longer holds. Therefore, the pumping lemma only holds when $L$ 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 $L$ is finite, then

$$
(\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))))
$$

evaluates to true. (hint: If $L$ is finite, there is a “longest string”)

_Solution_

Let $\ell$ be the length of the longest string in $L$. We can choose a pumping length $k$ such that $k \geq \ell = \ell+1$.

Now let’s evaluate the following statement

$$
(\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)))
$$

Since $k > \ell$, there doesn’t exist a string $xyz \in L$ such that $|y| > k$. Therefore, antecendent of the implication $xyz \in L \land |y| > p$ is always false.

Therefore, the entire inner implication is vacuously true, and the entire statement is true. Therefore, the pumping lemma holds for finite languages.

## Problème 4.

Using the Pumping Lemma, prove the following languages are not regular. Make your steps in the “game” and variable choices very clear for each question.

> \[!note\] Pumping Lemma
>
> There exists a pumping length $p$ such that $\forall s \in L, |s| \geq p$, we can write $s = xyz$ such that
>
> i. $|y| > 0$
>
> ii. $|xy| \leq p$
>
> iii. $\forall i \geq 0, xy^iz \in L$

> \[!question\] 4.a
>
> $$
> L = \{ a^{nm}b^ma^n \mid n,m \geq 0 \}
> $$

Assume $L$ is regular.

Let $s = a^{p^2}b^pa^p$. $s \in L$ since choosing $n=p,m=p$, and $|s|=p^2+2p \geq p$ for $p \geq 1$.

By the pumping lemma, we can write $s=xyz$ satisfying conditions i) and iii). Since $|xy| \leq p$, $y$ must consist of only $a$‘s. Let $y = a^k$ for $1 \leq k \leq p$.

Consider string $xy^0z = xz = a^{p^2-k}b^pa^p$. From condition iii), this must be in $L$.

However, $xz$ has the first block of $a$ to length $p^2-k$ and last block of length $p$. To be in $L$, we must have $p^2-k=p \cdot m$ for some integer $m$. But $p^2-k>p$ for $p \geq 2$, so there is no such $m$ exists, which means $xz \notin L$.

Thus, it contradicts the pumping lemma, and $L$ is not regular. $\square$

> \[!question\] 4.b
>
> $$
> L = \{ww \mid w \in \Sigma^*\}
> $$

Assume $L$ is regular.

Let $s = a^pb^pa^pb^p$. $s \in L$ since chos\sin g $w=a^pb^p$ and $|s|=4p \geq p$ for $p \geq 1$.

By pumping lemma, we can write $s=xyz$ satisfying conditions i) and iii). Since $|xy| \leq p$, $y$ must consist of only $a$‘s. Let $y = a^k$ for $1 \leq k \leq p$.

Consider the string $xy^2z = xa^kya^kb^pa^pb^p$. By condition iii) of the pumping lemma, this must be in $L$.

However, $xy^2z$ to be in $L$, it must be the for of $ww$ for some $w \in \Sigma^*$. But the first half of $xy^2z$ is $a^{p+k}b^p$ and the second half is $a^pb^p$. Since $k \leq p$. So $xy^2z \notin L$.

Thus, it contradicts the pumping lemma, and $L$ is not regular. $\square$

> \[!question\] 4.c
>
> $$
> L = \{ a^{k^3} \mid k \leq 0 \}
> $$

Assume $L$ is regular.

Let $s = a^{p^3}$. $s \in L$ since choosing $k=p$, and $|s|=p^3 \geq p$ for $p \geq 1$.

By the pumping lemma, we can write $s=xyz$ satisfying conditions i) and iii). Since $|xy| \leq p$, $y$ must consist of only $a$‘s. Let $y = a^k$ for $1 \leq k \leq p$.

Consider the string $xy^2z = xa^kya^kz = a^{p^3+k}$. By condition iii) of the pumping lemma, this must be in $L$.

However, $xy^2z$ to be in $L$, it must be of the form $a^{k^3}$ for some $k \leq 0$. $p^3 < p^3+k < (p+1)^3$, which means $p^3+k$ is not a perfect cube, so $xy^2z \notin L$.

Thus, it contradicts the pumping lemma, and $L$ is not regular. $\square$

