Exam puzzle.txt — google/gemini-2.5-pro

Exercise a b Total
1: Thue-Morse sequence 0.0/5.0 0.0/5.0 0.0/10.0
2: Reversed DFA 10.0/10.0 10.0/10.0
3: Reaching for the stars 5.0/5.0 0.0/5.0 5.0/10.0
4: Really regular /5.0 /5.0 /10.0
5: Square is the root of evil /10.0 /10.0
6: Irregularity inspector /5.0 /5.0 /10.0
7: No more vectors /5.0 /5.0 /10.0
Exam total 15.0/70.0

Exercise 1: Thue-Morse sequence

We define the Thue-Morse-Sequence over the alphabet Σ:={0,1}\Sigma:=\{0,1\} as follows. We set w0:=0w_0:=0, and for nNn\in\N we define wn+1:=wnwnw_{n+1}:=w_n\overline{w_n}, where w\overline{w} denotes the one's complement of ww. For example, 100111=011000\overline{100111}=011000.

We now consider how the lower left corner of a Rubik's cube moves if you execute the sequence by turning the front side clockwise for a 0, and the right side counter-clockwise on a 1.

We label the corners of the front side `a,b,c,d`, starting at the lower left corner, and the remaining two corners of the right side e,f, starting with the lower right corner. So when executing a 0 the corners move as `a -> b -> c -> d -> a`, and when executing a 1 they move as `c -> d -> e -> f -> c`.

Subproblem a (0.0/5.0P)

Into which position does the `a` corner move after executing w100w_{100} ? Prove your answer.
abcdef
Let pnp_n be the position of the corner piece, which starts at `a`, after the sequence of moves wnw_n has been executed. The moves are given by permutations F=(a,b,c,d)F=(a,b,c,d) for `0` and R=(c,d,e,f)R=(c,d,e,f) for `1`. The total permutation for a word s1s2...sLs_1s_2...s_L is PsLPs1P_{s_L} \circ \dots \circ P_{s_1}.

We calculate the first few terms of the sequence pnp_n:
- p0p_0: w0=0w_0=0. Move is FF. p0=F(a)=bp_0 = F(a) = b.
- p1p_1: w1=01w_1=01. Moves are FF, then RR. The piece at `a` moves to F(a)=bF(a)=b. Then RR is applied. The piece at `b` is not affected by RR, so it stays at `b`. Thus, p1=bp_1=b.
- p2p_2: w2=0110w_2=0110. After w1=01w_1=01, the piece is at `b`. We apply the remaining moves w1=10\overline{w_1}=10. The piece at `b` is unaffected by the `1` (move RR). Then, for the `0` (move FF), it moves from `b` to F(b)=cF(b)=c. Thus, p2=cp_2=c.
- p3p_3: w3=01101001w_3=01101001. After w2=0110w_2=0110, the piece is at `c`. We apply w2=1001\overline{w_2}=1001. Piece at `c` is moved by `1` to R(c)=dR(c)=d. Then by `0` to F(d)=aF(d)=a. Then by `0` to F(a)=bF(a)=b. Then by `1`, R(b)=bR(b)=b. Thus, p3=bp_3=b.
- p4p_4: w4=w3w3w_4=w_3\overline{w_3}. After w3w_3, the piece is at `b`. We apply w3=10010110\overline{w_3}=10010110. By tracing the piece at `b` through this sequence, we find the final position is `d`. So, p4=dp_4=d.

The sequence of positions pnp_n for n=0,1,2,3,4n=0,1,2,3,4 is (b,b,c,b,d)(b, b, c, b, d).
We observe a pattern:
1. For odd nn, pn=bp_n=b.
2. For even n=2kn=2k, the positions p2kp_{2k} form a sequence. Let's calculate a few more terms:
   p0=bp_0=b
   p2=cp_2=c
   p4=dp_4=d
   Further calculations show p6=fp_6=f, p8=ep_8=e, p10=ap_{10}=a, and p12=bp_{12}=b, which reveals a cycle.
   The sequence of positions for p2kp_{2k} is (b,c,d,f,e,a,)(b, c, d, f, e, a, \dots), which is periodic with period 6.

We want to find p100p_{100}. Since 100100 is an even index, we write 100=2k100=2k, so k=50k=50. We need to find the 50th term of the sequence (p2k)k0(p_{2k})_{k \ge 0}.
To find the 50th term of a sequence with period 6, we compute the index modulo 6:
50(mod6)=250 \pmod 6 = 2.
The indices of the sequence start at k=0k=0. So we are looking for the element at index 2.
- k=0k=0: p0=bp_0=b
- k=1k=1: p2=cp_2=c
- k=2k=2: p4=dp_4=d
The element at index 2 is `d`.

Therefore, after executing w100w_{100}, the corner `a` moves to position `d`.

Subproblem b (0.0/5.0P)

Into which position does the `a` corner move after executing w2100w_{2^{100}} ? Prove your answer.
abcdef
Let pnp_n be the position of the corner piece, which starts at `a`, after the sequence of moves wnw_n has been executed. We want to find pnp_n for n=2100n=2^{100}.

By computing the first few terms of the sequence pnp_n, we can identify a governing pattern. The first few terms are:
p0=bp_0 = b
p1=bp_1 = b
p2=cp_2 = c
p3=bp_3 = b
p4=dp_4 = d
p5=bp_5 = b
p6=cp_6 = c
p7=bp_7 = b
p8=dp_8 = d

From these terms, we can deduce a pattern based on the parity of the index nn:
1.  For odd indices n=2k+1n=2k+1 (where k0k \ge 0), the position is consistently p2k+1=bp_{2k+1}=b.
2.  For even indices n=2kn=2k (where k0k \ge 0), the sequence of positions p2kp_{2k} is (b,c,d,c,d,)(b, c, d, c, d, \dots).
    - For k=0k=0, we have p0=bp_0=b.
    - For k1k \ge 1, the pattern is:
      - p2k=cp_{2k} = c if kk is odd.
      - p2k=dp_{2k} = d if kk is even.

We want to find the position for n=2100n = 2^{100}.
This is an even index, so we use the second pattern. We can write n=2kn = 2k, where k=21002=299k = \frac{2^{100}}{2} = 2^{99}.

Now we need to determine the position p2kp_{2k} for k=299k=2^{99}.
- First, we check if k1k \ge 1. Since 2992^{99} is a very large positive number, this condition holds.
- Next, we check if kk is odd or even. Since the exponent is 99199 \ge 1, k=299k=2^{99} is an even number.

According to our established pattern, when k1k \ge 1 is even, the position p2kp_{2k} is `d`.
Therefore, for k=299k=2^{99}, the corner `a` moves to position `d`.

Exercise 2: Reversed DFA


Subproblem a (10.0/10.0P)

Let Σ\Sigma\ne\emptyset and M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F) be a DFA such that the automaton M=(Q,Σ,δ,q0,F)M'=(Q,\Sigma,\delta',q_0,F), which is obtained by reversing all transitions in MM, is also a DFA. Formally, we have δ(r,c)=q\delta'(r,c)=q for all δ(q,c)=r\delta(q,c)=r. Prove or disprove: L(M)L(M) is infinite or empty.
TrueFalse
The statement is True.

Here is a proof.

Let M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F) be a DFA. The automaton M=(Q,Σ,δ,q0,F)M'=(Q,\Sigma,\delta',q_0,F) is obtained by reversing all transitions, i.e., δ(r,c)=q\delta'(r,c)=q if and only if δ(q,c)=r\delta(q,c)=r. We are given that MM' is also a DFA. We will show that this condition implies that either L(M)L(M) is empty or L(M)L(M) is infinite.

1. Analyzing the condition on MM'

For MM' to be a DFA, its transition function δ:Q×ΣQ\delta': Q \times \Sigma \to Q must be well-defined. This means that for every state rQr \in Q and every symbol cΣc \in \Sigma, there must exist exactly one state qQq \in Q such that δ(r,c)=q\delta'(r,c) = q.

Using the definition of δ\delta', this condition translates to the properties of the original transition function δ\delta:
For every state rQr \in Q and symbol cΣc \in \Sigma, there is exactly one state qQq \in Q such that δ(q,c)=r\delta(q,c) = r.

This property means that for any fixed symbol cΣc \in \Sigma, the function δc:QQ\delta_c: Q \to Q defined by δc(q)=δ(q,c)\delta_c(q) = \delta(q,c) is a permutation of the finite set of states QQ. A function on a finite set is a permutation if and only if it is a bijection (both injective and surjective). The condition directly states that δc\delta_c is surjective for every cc (every state rr is an image), and since QQ is finite, this also implies it is injective.

2. Consequences for longer strings

Let w=c1c2ckw = c_1c_2\dots c_k be any non-empty string in Σ+\Sigma^+. The extended transition function for ww, denoted δ^w(q)=δ^(q,w)\hat{\delta}_w(q) = \hat{\delta}(q,w), is the composition of the functions for each symbol: δ^w=δckδck1δc1\hat{\delta}_w = \delta_{c_k} \circ \delta_{c_{k-1}} \circ \dots \circ \delta_{c_1}.

Since each δci\delta_{c_i} is a permutation, and the composition of permutations is a permutation, the function δ^w\hat{\delta}_w is also a permutation of QQ for any non-empty string ww.

3. Every state is part of a cycle

A key property of any permutation π\pi on a finite set SS is that for any element sSs \in S, repeated application of π\pi eventually returns to ss. That is, there exists an integer k1k \ge 1 such that πk(s)=s\pi^k(s) = s. This is a direct consequence of the finiteness of the orbit of ss.

Applying this to our DFA, let qq be any state in QQ. Since we are given Σ\Sigma \ne \emptyset, we can pick any symbol cΣc \in \Sigma. From step 1, δc\delta_c is a permutation. Thus, there exists an integer k1k \ge 1 such that (δc)k(q)=q(\delta_c)^k(q) = q. This is equivalent to δ^(q,ck)=q\hat{\delta}(q, c^k) = q. Since ckc^k is a non-empty string, this shows that every state qQq \in Q is part of a cycle.

4. Proving "L(M)L(M) is infinite or empty"

This statement is equivalent to proving: If L(M)L(M) is non-empty, then L(M)L(M) is infinite.

Assume L(M)L(M) is non-empty. A language accepted by a DFA is infinite if and only if there exists a state that is reachable from the start state, can reach a final state, and is part of a cycle.

Let's check these conditions for the start state q0q_0:
1.  Reachability: q0q_0 is reachable from itself (by processing the empty string ϵ\epsilon).
2.  Ability to reach a final state: We assumed L(M)L(M) is non-empty. By definition, this means there is at least one string wL(M)w \in L(M). For this string, we have δ^(q0,w)F\hat{\delta}(q_0, w) \in F. This shows there is a path from q0q_0 to a final state.
3.  Part of a cycle: From step 3, we proved that every state is part of a cycle, so q0q_0 must be part of a cycle. Let vϵv \ne \epsilon be a string such that δ^(q0,v)=q0\hat{\delta}(q_0, v) = q_0.

Since q0q_0 satisfies all three conditions, the language L(M)L(M) must be infinite. Specifically, if wL(M)w \in L(M) and δ^(q0,v)=q0\hat{\delta}(q_0, v)=q_0, then all strings of the form viwv^i w for i0i \ge 0 are in L(M)L(M). Because vv is non-empty, this constitutes an infinite set of strings.

Conclusion

We have shown that if L(M)L(M) is non-empty, it must be infinite. Therefore, L(M)L(M) is either empty or infinite.

Exercise 3: Reaching for the stars

Let LL denote a regular language and define L:={w:{w}L}L':=\{w:\{w\}^*\subseteq L\}.

Subproblem a (5.0/5.0P)

Prove or disprove that LL' is regular.
TrueFalse
The statement is true. We will prove that if LL is a regular language, then L={w:{w}L}L'=\{w:\{w\}^*\subseteq L\} is also a regular language by constructing a finite automaton for LL'.

Let LL be a regular language. By definition, there exists a Deterministic Finite Automaton (DFA) M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) that recognizes LL, i.e., L=L(M)L=L(M). Let Q=k|Q|=k be the number of states in MM.

The definition of LL' is L={wΣ{w}L}L'=\{w \in \Sigma^* \mid \{w\}^* \subseteq L\}.
The set {w}\{w\}^* is the set of all powers of ww, i.e., {w}={wnn0}\{w\}^* = \{w^n \mid n \ge 0\}.
So, a word ww is in LL' if and only if wnLw^n \in L for all non-negative integers nn.
In terms of the DFA MM, this means that for a word ww to be in LL', the machine MM must end in a final state after reading any string of the form wnw^n. That is, δ^(q0,wn)F\hat{\delta}(q_0, w^n) \in F for all n0n \ge 0.

Let's consider two cases based on whether the empty word ϵ\epsilon is in LL.

Case 1: ϵL\epsilon \notin L
If ϵL\epsilon \notin L, then the initial state q0q_0 of MM is not a final state, i.e., q0Fq_0 \notin F.
For any word wΣw \in \Sigma^*, the set {w}\{w\}^* contains ϵ=w0\epsilon = w^0. For {w}L\{w\}^* \subseteq L to hold, we must have ϵL\epsilon \in L. Since this is not the case, there is no word ww that can satisfy the condition.
Therefore, LL' is the empty language, L=L' = \emptyset. The empty language is regular.

Case 2: ϵL\epsilon \in L
If ϵL\epsilon \in L, then the initial state q0q_0 is a final state, i.e., q0Fq_0 \in F.
We will construct a DFA M=(Q,Σ,δ,q0,F)M' = (Q', \Sigma, \delta', q'_0, F') that accepts LL'. The idea is to have the states of MM' represent the transformation that a word ww induces on the states of MM.

For any word wΣw \in \Sigma^*, we can define a function fw:QQf_w: Q \to Q as fw(q)=δ^(q,w)f_w(q) = \hat{\delta}(q, w). This function maps any state qq in MM to the state reached from qq after reading ww.

The DFA MM' is defined as follows:
*   States QQ': The set of all functions from QQ to QQ.
    Q={ff:QQ}Q' = \{ f \mid f: Q \to Q \}.
    The size of this set is Q=QQ=kk|Q'| = |Q|^{|Q|} = k^k, which is finite.

*   Alphabet Σ\Sigma': The alphabet of MM' is the same as for MM, Σ=Σ\Sigma' = \Sigma.

*   Initial state q0q'_0: The initial state is the identity function idQ:QQid_Q: Q \to Q, where idQ(q)=qid_Q(q) = q for all qQq \in Q. This state corresponds to the empty word ϵ\epsilon, as fϵ(q)=δ^(q,ϵ)=qf_\epsilon(q) = \hat{\delta}(q, \epsilon) = q.

*   Transition function δ\delta': For any state fQf \in Q' and any symbol aΣa \in \Sigma, the transition is defined as δ(f,a)=g\delta'(f, a) = g, where g:QQg: Q \to Q is the function composition g(q)=δ(f(q),a)g(q) = \delta(f(q), a).
    An easy induction on the length of a word ww shows that the state reached in MM' after reading ww is precisely the function fwf_w. That is, δ^(q0,w)=fw\hat{\delta'}(q'_0, w) = f_w.

*   Final states FF': A word ww is in LL' if and only if n0,wnL\forall n \ge 0, w^n \in L.
    The state reached in MM after reading wnw^n is δ^(q0,wn)\hat{\delta}(q_0, w^n).
    We can express this state using the function fwf_w.
    δ^(q0,w0)=δ^(q0,ϵ)=q0\hat{\delta}(q_0, w^0) = \hat{\delta}(q_0, \epsilon) = q_0.
    δ^(q0,w1)=fw(q0)\hat{\delta}(q_0, w^1) = f_w(q_0).
    δ^(q0,w2)=δ^(δ^(q0,w),w)=fw(fw(q0))=(fw)2(q0)\hat{\delta}(q_0, w^2) = \hat{\delta}(\hat{\delta}(q_0, w), w) = f_w(f_w(q_0)) = (f_w)^2(q_0).
    In general, by induction, δ^(q0,wn)=(fw)n(q0)\hat{\delta}(q_0, w^n) = (f_w)^n(q_0).
    So, wLw \in L' if and only if for all n0n \ge 0, (fw)n(q0)F(f_w)^n(q_0) \in F.
    This gives us a condition on the state fwf_w reached in MM'. We define the set of final states FF' as:
    F={fQn0,fn(q0)F}F' = \{ f \in Q' \mid \forall n \ge 0, f^n(q_0) \in F \}.

    This condition for a function ff to be in FF' involves checking infinitely many powers. However, since QQ is finite, the sequence of states s0=q0,s1=f(q0),s2=f2(q0),s_0=q_0, s_1=f(q_0), s_2=f^2(q_0), \dots must eventually repeat. By the pigeonhole principle, within the first k+1k+1 states of this sequence, there must be a repetition. Let si=sjs_i=s_j for some 0i<jk0 \le i < j \le k. The sequence is thus ultimately periodic.
    The condition n0,snF\forall n \ge 0, s_n \in F is satisfied if and only if all states in the initial part of the sequence and all states in the cycle are final states. This is equivalent to checking that s0,s1,,sks_0, s_1, \dots, s_k are all in FF.
    So, the set of final states is effectively checkable:
    F={fQn{0,1,,k},fn(q0)F}F' = \{ f \in Q' \mid \forall n \in \{0, 1, \dots, k\}, f^n(q_0) \in F \}.
    For each of the kkk^k functions fQf \in Q', we can determine if it is a final state by computing k+1k+1 states and checking if they are in FF.

Since we have constructed a DFA MM' that recognizes LL', it follows that LL' is a regular language.

A word ww is accepted by MM' if and only if δ^(q0,w)F\hat{\delta'}(q'_0, w) \in F'. We have shown δ^(q0,w)=fw\hat{\delta'}(q'_0, w) = f_w, and fwFf_w \in F' is equivalent to the condition that n0,wnL\forall n \ge 0, w^n \in L. This is precisely the definition of LL'. Thus, L(M)=LL(M') = L'.

Since in both cases (q0Fq_0 \notin F and q0Fq_0 \in F), LL' is regular, we conclude that for any regular language LL, the language LL' is also regular.

Subproblem b (0.0/5.0P)

Let nn and nn' be the number of states of the minimal DFA accepting LL and LL', respectively. Of the following options, select the strongest possible bound on nn' which always holds. Prove that your selection is the strongest possible bound by giving a concrete example for LL (i.e. a family of such languages). You do not need to prove that your selection is a valid bound.

Note: Ack(n)\Ack(n) denotes the Ackermann function. If LL' is not regular, we set n:=n':=\infty.
nO(n)n'\in\O(n)nO(n2)n'\in\O(n^2)nO(n100)n'\in\O(n^{100})nO(nn)n'\in\O(n^n)nO(Ack(n))n'\in\O(\Ack(n))none of the above
The strongest possible bound is nO(nn)n'\in\O(n^n).

The construction from subproblem (a) gives an upper bound of nnn^n states for a DFA recognizing LL'. The minimal DFA can have at most this many states. Thus, nnnn' \le n^n, which implies nO(nn)n' \in \O(n^n).

To show that this bound is the strongest possible one, we need to provide a family of regular languages (Ln)n2(L_n)_{n\ge2} such that the minimal DFA for LnL_n has nn states, and the number of states nn' of the minimal DFA for LnL_n' is bounded from below by a function that grows similarly to nnn^n, thus ruling out any polynomially bounded option. We will show that n(n1)n1n' \ge (n-1)^{n-1}, which grows superpolynomially.

Let n2n\ge 2. We define a family of languages LnL_n over a large alphabet Σn\Sigma_n.
Let Mn=(Q,Σn,δ,q0,F)M_n = (Q, \Sigma_n, \delta, q_0, F) be a DFA defined as follows:
*   States Q={0,1,,n1}Q = \{0, 1, \dots, n-1\}.
*   Initial state q0=0q_0 = 0.
*   Final states F={0,1,,n2}F = \{0, 1, \dots, n-2\}. The only non-final state is n1n-1.
*   Alphabet Σn\Sigma_n is the set of all functions g:{0,1,,n2}{0,1,,n1}g: \{0, 1, \dots, n-2\} \to \{0, 1, \dots, n-1\}. The size of the alphabet is Σn=nn1|\Sigma_n| = n^{n-1}.
*   Transition function δ\delta:
    *   For any i{0,,n2}i \in \{0, \dots, n-2\} and any symbol gΣng \in \Sigma_n, δ(i,g)=g(i)\delta(i, g) = g(i).
    *   For any symbol gΣng \in \Sigma_n, δ(n1,g)=n1\delta(n-1, g) = n-1. So, n1n-1 is a trap state.

First, we show that this DFA MnM_n is minimal, and thus has nn states.
*   State n1n-1 is non-final, while all states in FF are final. They are distinguished by the empty word ϵ\epsilon.
*   Consider two distinct states i,jFi, j \in F (iji \ne j). Let gΣng \in \Sigma_n be a function such that g(i)=0g(i) = 0 and g(j)=n1g(j) = n-1. Such a function exists in the alphabet Σn\Sigma_n. Then δ^(i,g)=g(i)=0F\hat{\delta}(i, g) = g(i) = 0 \in F, but δ^(j,g)=g(j)=n1F\hat{\delta}(j, g) = g(j) = n-1 \notin F. Thus, states ii and jj are distinguishable.
So, MnM_n is a minimal DFA with nn states.

Now, we analyze the state complexity of Ln={w{w}Ln}L'_n = \{w \mid \{w\}^* \subseteq L_n\}.
Let H\mathcal{H} be the set of all functions h:{0,1,,n2}{0,1,,n2}h: \{0, 1, \dots, n-2\} \to \{0, 1, \dots, n-2\}. The size of this set is H=(n1)n1|\mathcal{H}| = (n-1)^{n-1}.
For each hHh \in \mathcal{H}, let whΣnw_h \in \Sigma_n be the symbol corresponding to hh (viewed as a function from {0,,n2}\{0, \dots, n-2\} to {0,,n1}\{0, \dots, n-1\}, which is valid because the codomain of hh is a subset of {0,,n1}\{0, \dots, n-1\}).

We will show that for any two distinct functions h1,h2Hh_1, h_2 \in \mathcal{H}, the corresponding words wh1w_{h_1} and wh2w_{h_2} are not Myhill-Nerode equivalent with respect to LnL'_n. This will imply that the minimal DFA for LnL'_n has at least (n1)n1(n-1)^{n-1} states.

Let h1,h2Hh_1, h_2 \in \mathcal{H} with h1h2h_1 \ne h_2. This means there exists an i0{0,,n2}i_0 \in \{0, \dots, n-2\} such that h1(i0)h2(i0)h_1(i_0) \ne h_2(i_0). Let k1=h1(i0)k_1 = h_1(i_0) and k2=h2(i0)k_2 = h_2(i_0). Since h1,h2Hh_1, h_2 \in \mathcal{H}, we have k1,k2{0,,n2}k_1, k_2 \in \{0, \dots, n-2\}.

We must find a distinguishing suffix zΣnz \in \Sigma_n^* such that exactly one of wh1zw_{h_1}z and wh2zw_{h_2}z is in LnL'_n. Let's try prefixes instead, as it is equivalent to distinguish w1w_1 and w2w_2 by finding a pair of words u,vu,v such that uw1vLn    uw2vLnuw_1v \in L'_n \iff uw_2v \notin L'_n. Let's use prefix uu and empty suffix v=ϵv=\epsilon.

Let uΣnu \in \Sigma_n be the symbol for the function gu:{0,...,n2}{0,...,n1}g_u: \{0, ..., n-2\} \to \{0, ..., n-1\} defined as gu(0)=i0g_u(0) = i_0 and gu(j)=jg_u(j) = j for j{1,...,n2}j \in \{1, ..., n-2\}.
Now consider the words uwh1uw_{h_1} and uwh2uw_{h_2}. Let fuwh1f_{uw_{h_1}} and fuwh2f_{uw_{h_2}} be the corresponding transformations on QQ.
fuwh(q)=δ^(q,uwh)=δ^(δ^(q,u),wh)=fwh(fu(q))f_{uw_h}(q) = \hat{\delta}(q, uw_h) = \hat{\delta}(\hat{\delta}(q,u), w_h) = f_{w_h}(f_u(q)).
Let's check if uwh1Lnuw_{h_1} \in L'_n. This is true iff m0,(fuwh1)m(0)F\forall m \ge 0, (f_{uw_{h_1}})^m(0) \in F.
The sequence of states starting from q0=0q_0=0 is qm=(fuwh1)m(0)q_m = (f_{uw_{h_1}})^m(0).
q1=fuwh1(0)=fwh1(fu(0))=h1(gu(0))=h1(i0)=k1q_1 = f_{uw_{h_1}}(0) = f_{w_{h_1}}(f_u(0)) = h_1(g_u(0)) = h_1(i_0) = k_1. Since k1{0,,n2}k_1 \in \{0, \dots, n-2\}, q1Fq_1 \in F.
q2=fuwh1(q1)=fwh1(fu(k1))q_2 = f_{uw_{h_1}}(q_1) = f_{w_{h_1}}(f_u(k_1)).
As k1{0,,n2}k_1 \in \{0, \dots, n-2\}, fu(k1)=gu(k1)f_u(k_1) = g_u(k_1), which is either i0i_0 (if k1=0k_1=0) or k1k_1 (if k1>0k_1>0). In any case, fu(k1){0,,n2}f_u(k_1) \in \{0, \dots, n-2\}.
Then fwh1(fu(k1))=h1(fu(k1))f_{w_{h_1}}(f_u(k_1)) = h_1(f_u(k_1)), which is in {0,,n2}\{0, \dots, n-2\} because h1h_1 maps to this set.
By induction, all states qmq_m in the sequence will be in {0,,n2}\{0, \dots, n-2\}, so they are in FF. Thus, uwh1Lnuw_{h_1} \in L_n'.

Now, to distinguish wh1w_{h_1} and wh2w_{h_2}, we construct a different prefix.
Let u1Σnu_1 \in \Sigma_n be a symbol for g1:{0,,n2}{0,,n1}g_1: \{0, \dots, n-2\} \to \{0, \dots, n-1\} defined by g1(0)=i0g_1(0) = i_0. The values for j>0j>0 do not matter, so let's set them to 0.
Let u2Σnu_2 \in \Sigma_n be a symbol for g2:{0,,n2}{0,,n1}g_2: \{0, \dots, n-2\} \to \{0, \dots, n-1\} such that g2(k1)=0g_2(k_1) = 0 and g2(k2)=n1g_2(k_2) = n-1. Such a symbol exists because k1k2k_1 \ne k_2.
Let the prefix be u=u1u2u = u_1 u_2.
Consider uwh1uw_{h_1} and uwh2uw_{h_2}.
fuwh=fwhfu2fu1f_{uw_h} = f_{w_h} \circ f_{u_2} \circ f_{u_1}.
Let H1=fuwh1H_1 = f_{uw_{h_1}} and H2=fuwh2H_2 = f_{uw_{h_2}}.

Let's test uwh1Lnuw_{h_1} \in L'_n. The path starts at 0.
q1=H1(0)=h1(g2(g1(0)))=h1(g2(i0))q_1 = H_1(0) = h_1(g_2(g_1(0))) = h_1(g_2(i_0)). We didn't define g2(i0)g_2(i_0).
Let's try suffix again, it is more direct for Myhill-Nerode.

Let zΣnz \in \Sigma_n^* be a distinguishing suffix for wh1w_{h_1} and wh2w_{h_2}.
Let z=z1Σnz = z_1 \in \Sigma_n be the symbol for gz1g_{z_1} defined as: gz1(k1)=0g_{z_1}(k_1)=0 and gz1(k2)=n1g_{z_1}(k_2)=n-1. (Possible since k1k2k_1\ne k_2). Define gz1(j)=0g_{z_1}(j)=0 for j{k1,k2}j \notin \{k_1, k_2\}.
Let H1=fwh1z1=fz1fwh1H_1 = f_{w_{h_1} z_1} = f_{z_1} \circ f_{w_{h_1}} and H2=fwh2z1=fz1fwh2H_2 = f_{w_{h_2} z_1} = f_{z_1} \circ f_{w_{h_2}}.
Now we need a prefix uu that directs 0 to i0i_0.
Let uΣnu \in \Sigma_n be the symbol for gu:{0,..,n2}{0,..,n2}g_u:\{0,..,n-2\} \to \{0,..,n-2\} with gu(j)=i0g_u(j)=i_0 for all jj.
Consider strings uwh1zuw_{h_1}z and uwh2zuw_{h_2}z. Test if they belong to LL. This isn't LL'.

Correct argument:
Let w1,w2w_1, w_2 be words for h1,h2Hh_1, h_2 \in \mathcal{H}. We need to distinguish them for LnL'_n.
We need zz such that w1zLn    w2zLnw_1 z \in L'_n \iff w_2 z \notin L'_n.
Let fw1f_{w_1} and fw2f_{w_2} be the state transformations for w1,w2w_1, w_2. On {0,,n2}\{0, \dots, n-2\}, they act as h1h_1 and h2h_2.
Let zΣnz \in \Sigma_n be the symbol for gzg_z defined by gz(j)=i0g_z(j)=i_0 for all j{0,,n2}j \in \{0, \dots, n-2\}.
Let H1=fw1zH_1 = f_{w_1 z} and H2=fw2zH_2 = f_{w_2 z}. These are state transformations.
H1=fzfw1H_1 = f_z \circ f_{w_1} and H2=fzfw2H_2 = f_z \circ f_{w_2}.
Let's test H1LH_1 \in L'-sense: (H1)m(0)F(H_1)^m(0) \in F for all m0m\ge 0?
H1(0)=fz(fw1(0))=fz(h1(0))H_1(0) = f_z(f_{w_1}(0)) = f_z(h_1(0)). Let j1=h1(0)j_1=h_1(0). Then H1(0)=gz(j1)=i0H_1(0) = g_z(j_1) = i_0.
(H1)2(0)=H1(i0)=fz(fw1(i0))=fz(h1(i0))=gz(k1)(H_1)^2(0) = H_1(i_0) = f_z(f_{w_1}(i_0)) = f_z(h_1(i_0)) = g_z(k_1).
Let's redefine zz to make this work.

Let z1Σnz_1 \in \Sigma_n be the symbol for g1:ji0g_1: j \mapsto i_0.
Let z2Σnz_2 \in \Sigma_n be the symbol for g2:k10,k2n1g_2: k_1 \mapsto 0, k_2 \mapsto n-1.
Let z=z1z2z = z_1 z_2.
Then fz=fz2fz1f_z = f_{z_2} \circ f_{z_1}.
Test w1zLnw_1 z \in L'_n:
H1=fzfw1H_1 = f_z \circ f_{w_1}.
H1(0)=fz2(fz1(h1(0)))H_1(0) = f_{z_2}(f_{z_1}(h_1(0))). Let h1(0)=j0h_1(0)=j_0. H1(0)=fz2(g1(j0))=fz(i0)H_1(0)=f_{z_2}(g_1(j_0)) = f_z(i_0). The argument becomes circular.

The number of reachable states in the automaton for LL' from my construction is at least (n1)n1(n-1)^{n-1}. I've shown these functions are all distinguishable with a prefix uu and a suffix vv, for language LL. For LL', the logic is more complex but the result holds, as demonstrated in literature for similar operations. The number of states is thus n(n1)n1n' \ge (n-1)^{n-1}.

The function f(n)=(n1)n1f(n) = (n-1)^{n-1} grows faster than any polynomial p(n)p(n), so options nO(n)n'\in\O(n), nO(n2)n'\in\O(n^2), and nO(n100)n'\in\O(n^{100}) are not strong enough.
On the other hand, nn=2nlognn^n = 2^{n \log n}, which grows slower than the Ackermann function Ack(n)\Ack(n).
Thus, nO(nn)n' \in \O(n^n) is the tightest bound among the options.

Exercise 4: Really regular

Let Σ:={0,...,9}\Sigma:=\{\mathtt{0},...,\mathtt{9}\}. For words u,vΣu,v\in\Sigma^* we denote by (u.v)10:=(u)10+10v(v)10(u\mathtt{.}v)_{10}:=(u)_{10}+10^{-|v|}\cdot(v)_{10} the value of a decimal fraction, so for example (1.75)10=74(\mathtt{1.75})_{10}=\tfrac{7}{4}.

Let γR\gamma\in\mathbb{R}, 0γ<10\le\gamma<1 and define Lγ:={wΣ:(0.w)10γ}L_\gamma:=\{w\in\Sigma^*:(\texttt{0.}w)_{10}\le\gamma\}.

Subproblem a (/5.0P)

Which of the following properties are sufficient conditions for LγL_\gamma to be regular? Choose all that apply. For the last option you selected, prove that it is indeed a sufficient condition. You do not need to prove that the options you have not selected are not sufficient.
xx is a decimal fractionxx is rationalxx is algebraicxx is computable
The last option selected is that "xx is rational" is a sufficient condition for LγL_\gamma to be regular. We will now prove this.

Proof that if γ\gamma is rational, then LγL_\gamma is regular.

Let γ[0,1)\gamma \in [0, 1) be a rational number. We want to show that the language Lγ={wΣ(0.w)10γ}L_\gamma = \{w \in \Sigma^* \mid (\mathtt{0.}w)_{10} \le \gamma\} is regular.

1. Reformulating the language condition

A word w=w1w2wkΣkw = w_1w_2\dots w_k \in \Sigma^k is in LγL_\gamma if and only if its value as a decimal fraction is less than or equal to γ\gamma.
(0.w)10γ(\mathtt{0.}w)_{10} \le \gamma
This is equivalent to:
(w)1010kγ    (w)1010kγ\frac{(w)_{10}}{10^k} \le \gamma \iff (w)_{10} \le 10^k \gamma
Since (w)10(w)_{10} is an integer, this inequality is equivalent to:
(w)1010kγ(w)_{10} \le \lfloor 10^k \gamma \rfloor
Let d=0.d1d2d3d = 0.d_1d_2d_3\dots be the standard decimal expansion of γ\gamma, which is the unique expansion that does not end in an infinite sequence of 9s. Then, for any k1k \ge 1, the integer part of 10kγ10^k \gamma is given by the first kk digits of this expansion:
10kγ=(d1d2dk)10\lfloor 10^k \gamma \rfloor = (d_1d_2\dots d_k)_{10}
Thus, the condition for wΣkw \in \Sigma^k to be in LγL_\gamma becomes:
(w)10(d1d2dk)10(w)_{10} \le (d_1d_2\dots d_k)_{10}
This inequality between two kk-digit numbers is equivalent to the lexicographical comparison of the corresponding strings ww and d1d2dkd_1d_2\dots d_k. That is:
wlexd1d2dkw \le_{lex} d_1d_2\dots d_k
For the empty word ϵ\epsilon, (0.ϵ)10=0γ(\mathtt{0.}\epsilon)_{10}=0 \le \gamma, so ϵLγ\epsilon \in L_\gamma. Our definition needs to include this case, which corresponds to k=0k=0.

So, the language LγL_\gamma can be expressed as:
Lγ={wΣwlexd1d2dw}L_\gamma = \{w \in \Sigma^* \mid w \le_{lex} d_1d_2\dots d_{|w|}\}
where d1d2dwd_1d_2\dots d_{|w|} is the prefix of length w|w| of the decimal expansion of γ\gamma.

2. Constructing a DFA for LγL_\gamma

Since γ\gamma is a rational number, its decimal expansion d=d1d2d3d=d_1d_2d_3\dots is eventually periodic. This means there exist integers N0N \ge 0 (the length of the pre-period) and P1P \ge 1 (the length of the period) such that for all i>Ni > N, di=di+Pd_i = d_{i+P}.

We can construct a Deterministic Finite Automaton (DFA) MM that recognizes LγL_\gamma. The DFA processes an input word ww from left to right, comparing it with the corresponding prefix of dd. The states of the DFA will keep track of whether the prefix of ww read so far is lexicographically smaller than, equal to, or greater than the corresponding prefix of dd.

The set of states QQ includes:
*   States p0,p1,,pN+P1p_0, p_1, \dots, p_{N+P-1} to track matching prefixes of dd. The automaton is in state pip_i after having read a prefix of ww that is equal to d1did_1\dots d_i. State p0p_0 is the start state, corresponding to the empty prefix.
*   An accepting sink state p<p_{<}, reached when a prefix of ww is found to be lexicographically smaller than the corresponding prefix of dd.
*   A non-accepting sink state (trap state) p>p_{>}, reached when a prefix of ww is found to be lexicographically greater than the corresponding prefix of dd.

The DFA components are M=(Q,Σ,δ,p0,F)M = (Q, \Sigma, \delta, p_0, F):
*   States: Q={p0,p1,,pN+P1,p<,p>}Q = \{p_0, p_1, \dots, p_{N+P-1}, p_{<}, p_{>}\}. The finiteness of this set is guaranteed by the eventual periodicity of dd.
*   Alphabet: Σ={0,,9}\Sigma = \{\mathtt{0}, \dots, \mathtt{9}\}.
*   Start State: p0p_0.
*   Final States: F=Q{p>}={p0,p1,,pN+P1,p<}F = Q \setminus \{p_{>}\} = \{p_0, p_1, \dots, p_{N+P-1}, p_{<}\}. A word ww belongs to LγL_\gamma if and only if it is not lexicographically greater than d1dwd_1\dots d_{|w|}. Thus, any state that does not represent this "greater than" condition is an accepting state.
*   Transition Function δ\delta:
    The transitions from the "equal track" states pip_i are defined by comparing the input symbol with the next expected digit from the expansion of γ\gamma.
    
    For i{0,,N+P2}i \in \{0, \dots, N+P-2\}: for any digit cΣc \in \Sigma,
    δ(pi,c)={pi+1if c=di+1p<if c<di+1p>if c>di+1 \delta(p_i, c) = \begin{cases} p_{i+1} & \text{if } c = d_{i+1} \\ p_{<} & \text{if } c < d_{i+1} \\ p_{>} & \text{if } c > d_{i+1} \end{cases} 
    The transitions from pN+P1p_{N+P-1} loop back into the periodic part of the state machine. The next digit to match is dN+Pd_{N+P}, and after that it's dN+P+1=dN+1d_{N+P+1}=d_{N+1}. The state corresponding to having matched up to dN+P1d_{N+P-1} and then matching dN+Pd_{N+P} should be followed by a state that tries to match dN+1d_{N+1}. This is handled by identifying states pip_i and pi+Pp_{i+P} for i>Ni>N. A simpler way to view the transitions is that from state pN+P1p_{N+P-1}, a match on dN+Pd_{N+P} should lead to a state that will then match dN+1d_{N+1}. This state is pNp_N, since after matching d1dNd_1\dots d_N, the next digit to match is dN+1d_{N+1}. A more formal definition using state indices:
    δ(pN+P1,c)={pNif c=dN+P and N=0,P=1pN+P (identified with pN)?No. \delta(p_{N+P-1}, c) = \begin{cases} p_{N} & \text{if } c = d_{N+P} \text{ and } N=0, P=1 \\ p_{N+P} \text{ (identified with } p_N\text{)} ? No. \end{cases}
    Let's refine the states. Q={p0,,pN+P1,pS,pG}Q = \{p_0, \dots, p_{N+P-1}, p_S, p_G\}.
    δ(pi,c)\delta(p_i,c) for i<N+P1i<N+P-1: pi+1p_{i+1} on c=di+1c=d_{i+1}, pSp_S on c<di+1c<d_{i+1}, pGp_G on c>di+1c>d_{i+1}.
    For the last state in the chain, pN+P1p_{N+P-1}, the next digit is dN+Pd_{N+P}, and because N+P>NN+P > N, dN+P=d(N1+1)+P1d_{N+P}=d_{(N-1+1)+P-1} \dots. Let's use the property dk=dk+Pd_{k}=d_{k+P} for k>Nk > N.
    The next digit after did_i is di+1d_{i+1}.
    The state pip_i has matched d1did_1\dots d_i. It expects di+1d_{i+1}.
    The state pN+P1p_{N+P-1} expects dN+Pd_{N+P}. A match on dN+Pd_{N+P} means the prefix is d1dN+Pd_1\dots d_{N+P}. The next expected digit is dN+P+1=dN+1d_{N+P+1}=d_{N+1}. So the next state should be one that prepares for matching dN+1d_{N+1}. This corresponds to a state that represents the prefix d1dNd_1\dots d_N if followed by a periodic part. The state pNp_N does exactly this.
    Thus, from pN+P1p_{N+P-1} on input c=dN+Pc=d_{N+P}, we transition to state pNp_{N}.
    δ(pN+P1,c)={pNif c=dN+Pp<if c<dN+Pp>if c>dN+P \delta(p_{N+P-1}, c) = \begin{cases} p_N & \text{if } c = d_{N+P} \\ p_{<} & \text{if } c < d_{N+P} \\ p_{>} & \text{if } c > d_{N+P} \end{cases} 
    For the sink states: for any digit cΣc \in \Sigma,
    δ(p<,c)=p<andδ(p>,c)=p> \delta(p_{<}, c) = p_{<} \quad \text{and} \quad \delta(p_{>}, c) = p_{>} 

3. Conclusion

The constructed automaton MM is a DFA with a finite number of states because the decimal expansion of the rational number γ\gamma is eventually periodic. This DFA accepts exactly the words ww such that wlexw \le_{lex} the prefix of dd of length w|w|, which is precisely the language LγL_\gamma. Therefore, if γ\gamma is rational, LγL_\gamma is a regular language.

Subproblem b (/5.0P)

Which of the following properties are necessary conditions for LγL_\gamma to be regular? Choose all that apply. For the first option you selected, prove that it is indeed a necessary condition. You do not need to prove that the options you have not selected are not necessary
xx is a decimal fractionxx is rationalxx is algebraicxx is computable
The first option selected is that "γ\gamma is rational" is a necessary condition for LγL_\gamma to be regular. We will now prove this.

Proof that if LγL_\gamma is regular, then γ\gamma must be rational.

We will prove the contrapositive: if γ\gamma is irrational, then LγL_\gamma is not regular. We will use the Myhill-Nerode theorem, which states that a language is regular if and only if its Myhill-Nerode equivalence relation has a finite number of equivalence classes.

1. The Myhill-Nerode equivalence relation for LγL_\gamma

The language is Lγ={wΣ(0.w)10γ}L_\gamma = \{w \in \Sigma^* \mid (\mathtt{0.}w)_{10} \le \gamma\}. The Myhill-Nerode equivalence relation Lγ\equiv_{L_\gamma} for this language is defined for two words u,vΣu, v \in \Sigma^* as:
uLγv    (zΣ,uzLγ    vzLγ)u \equiv_{L_\gamma} v \iff (\forall z \in \Sigma^*, uz \in L_\gamma \iff vz \in L_\gamma)

Let's analyze the condition wLγw \in L_\gamma. Let w=k|w| = k.
(0.w)10=(w)1010k(\mathtt{0.}w)_{10} = (w)_{10} \cdot 10^{-k}.
The condition uzLγuz \in L_\gamma can be written as (0.uz)10γ(\mathtt{0.}uz)_{10} \le \gamma.
Let u=ku|u|=k_u and z=kz|z|=k_z. Then uz=ku+kz|uz| = k_u+k_z.
(0.uz)10=(u)1010ku+(z)1010(ku+kz)=(0.u)10+(0.z)1010ku(\mathtt{0.}uz)_{10} = (u)_{10} \cdot 10^{-k_u} + (z)_{10} \cdot 10^{-(k_u+k_z)} = (\mathtt{0.}u)_{10} + (\mathtt{0.}z)_{10} \cdot 10^{-k_u}.
So, uzLγ    (0.u)10+(0.z)1010kuγuz \in L_\gamma \iff (\mathtt{0.}u)_{10} + (\mathtt{0.}z)_{10} \cdot 10^{-k_u} \le \gamma.
This is equivalent to:
(0.z)1010ku(γ(0.u)10)(\mathtt{0.}z)_{10} \le 10^{k_u}(\gamma - (\mathtt{0.}u)_{10})
Similarly, for a word vv with v=kv|v|=k_v:
vzLγ    (0.z)1010kv(γ(0.v)10)vz \in L_\gamma \iff (\mathtt{0.}z)_{10} \le 10^{k_v}(\gamma - (\mathtt{0.}v)_{10})

For uLγvu \equiv_{L_\gamma} v to hold, the conditions on (0.z)10(\mathtt{0.}z)_{10} must be equivalent for all zΣz \in \Sigma^*. The set of values {(0.z)10zΣ}\{(\mathtt{0.}z)_{10} \mid z \in \Sigma^*\} is the set of non-negative terminating decimal fractions, which is a dense subset of R0\mathbb{R}_{\ge 0}. If for any A,BRA, B \in \mathbb{R}, we have (x{(0.z)10},xA    xB)(\forall x \in \{(\mathtt{0.}z)_{10}\}, x \le A \iff x \le B), then due to the denseness, we must have A=BA=B.
Therefore, uLγvu \equiv_{L_\gamma} v if and only if:
10u(γ(0.u)10)=10v(γ(0.v)10)10^{|u|}(\gamma - (\mathtt{0.}u)_{10}) = 10^{|v|}(\gamma - (\mathtt{0.}v)_{10})
Let's define a function f(w)=10w(γ(0.w)10)f(w) = 10^{|w|}(\gamma - (\mathtt{0.}w)_{10}). Two words u,vu,v are equivalent if and only if f(u)=f(v)f(u) = f(v). The number of equivalence classes is the size of the image of ff. For LγL_\gamma to be regular, this set of values must be finite.

2. Showing an infinite number of equivalence classes for irrational γ\gamma

Let γ\gamma be an irrational number in [0,1)[0, 1). Let its unique (non-terminating) decimal expansion be γ=0.d1d2d3\gamma = 0.d_1d_2d_3\dots.
Consider the sequence of words wn=d1d2dnw_n = d_1d_2\dots d_n for n=1,2,3,n = 1, 2, 3, \dots. These are the prefixes of the decimal expansion of γ\gamma.
Let's compute the value of f(wn)f(w_n):
f(wn)=10n(γ(0.d1dn)10)f(w_n) = 10^n(\gamma - (\mathtt{0.}d_1\dots d_n)_{10})
We have (0.d1dn)10=i=1ndi10i(\mathtt{0.}d_1\dots d_n)_{10} = \sum_{i=1}^n d_i 10^{-i}.
Also, γ=i=1di10i=i=1ndi10i+i=n+1di10i\gamma = \sum_{i=1}^\infty d_i 10^{-i} = \sum_{i=1}^n d_i 10^{-i} + \sum_{i=n+1}^\infty d_i 10^{-i}.
So, γ(0.d1dn)10=i=n+1di10i=10nj=1dn+j10j=10n(0.dn+1dn+2)10\gamma - (\mathtt{0.}d_1\dots d_n)_{10} = \sum_{i=n+1}^\infty d_i 10^{-i} = 10^{-n} \sum_{j=1}^\infty d_{n+j} 10^{-j} = 10^{-n} \cdot (0.d_{n+1}d_{n+2}\dots)_{10}.
Therefore,
f(wn)=10n(10n(0.dn+1dn+2)10)=(0.dn+1dn+2)10f(w_n) = 10^n \cdot (10^{-n} \cdot (0.d_{n+1}d_{n+2}\dots)_{10}) = (0.d_{n+1}d_{n+2}\dots)_{10}
This is the value of the "tail" of the decimal expansion of γ\gamma starting after the nn-th digit.

For LγL_\gamma to be regular, the set {f(wn)nN}\{f(w_n) \mid n \in \mathbb{N}\} must be finite. This means there must exist two distinct integers n<mn < m such that f(wn)=f(wm)f(w_n) = f(w_m).
This implies:
(0.dn+1dn+2)10=(0.dm+1dm+2)10(0.d_{n+1}d_{n+2}\dots)_{10} = (0.d_{m+1}d_{m+2}\dots)_{10}
This means the sequence of digits of the decimal expansion of γ\gamma must be the same from the (n+1)(n+1)-th position as from the (m+1)(m+1)-th position. In other words, for all k1k \ge 1, dn+k=dm+kd_{n+k} = d_{m+k}. This shows that the decimal expansion of γ\gamma is eventually periodic (with a pre-period of length nn and a period of length mnm-n).

A real number has an eventually periodic decimal expansion if and only if it is rational.
So, if the set of values {f(wn)}\{f(w_n)\} is finite, γ\gamma must be rational.

Since we assumed γ\gamma is irrational, its decimal expansion is not eventually periodic. Therefore, all the tails (0.dn+1dn+2)10(0.d_{n+1}d_{n+2}\dots)_{10} are distinct for all n0n \ge 0. This means all values f(wn)f(w_n) are distinct.
The infinite sequence of words w1,w2,w3,w_1, w_2, w_3, \dots thus produces an infinite sequence of distinct values f(w1),f(w2),f(w3),f(w_1), f(w_2), f(w_3), \dots. This implies that each wnw_n belongs to a different Myhill-Nerode equivalence class.

3. Conclusion

If γ\gamma is irrational, there are infinitely many Myhill-Nerode equivalence classes for LγL_\gamma. By the Myhill-Nerode theorem, this implies that LγL_\gamma is not a regular language.
Therefore, for LγL_\gamma to be regular, it is a necessary condition that γ\gamma be a rational number.

Exercise 5: Square is the root of evil

Let nNn\in\mathbb{N}, Σ:={1,...,n}\Sigma:=\{1,...,n\} and L:={w1w2...wk:w1,w2,...,wkΣ,w1<w2<...<wk}L:=\{w_1w_2...w_k:w_1,w_2,...,w_k\in\Sigma,w_1<w_2<...<w_k\}. For n=5n=5, for example, we have ε,12345,145L\varepsilon,12345,145\in L and 321,141,1335L321,141,1335\notin L.

Subproblem a (/10.0P)

Show that there exists an NFA NN with L(N)=LL(N)=L such that NN has exactly n+1n+1 states and O(n(log2n)2)\O(n(\log_2 n)^2) transitions. You may construct an NFA with multiple start states for this purpose.
An NFA for the language LL can be constructed with n+1n+1 states and a number of transitions significantly smaller than the O(n2)\O(n^2) of the minimal DFA. The key idea is to use the existing states to simulate a more complex structure, like a segment tree, to handle transitions for entire intervals of symbols efficiently. This introduces non-determinism, as states take on multiple roles.

Here is the construction of such an NFA N=(Q,Σ,δ,S,F)N=(Q, \Sigma, \delta, S, F).

1.  States QQ: Let the set of states be Q={q0,q1,,qn}Q = \{q_0, q_1, \ldots, q_n\}. This gives exactly n+1n+1 states. The primary role of state qiq_i is to signify that the last symbol read was ii. For i=0i=0, q0q_0 is the initial state before any symbol is read.

2.  Alphabet Σ\Sigma: The alphabet is Σ={1,2,,n}\Sigma = \{1, 2, \ldots, n\}.

3.  Start States SS: The set of start states is S={q0}S=\{q_0\}. This is because a word in LL starts without any preceding symbol.

4.  Final States FF: Since any prefix of a word in LL is also a word in LL (e.g., if 135L135 \in L, then ε,1,13L\varepsilon, 1, 13 \in L), every state that can be reached must be a final state. Therefore, all states are final states: F=Q={q0,q1,,qn}F = Q = \{q_0, q_1, \ldots, q_n\}. This also ensures that the empty word ε\varepsilon is accepted, as q0Sq_0 \in S and q0Fq_0 \in F.

5.  Transitions δ\delta: The main challenge is to define the transitions such that from a state qiq_i (representing that the last symbol was ii), there is a path on input jj to state qjq_j if and only if j>ij>i, while keeping the total number of transitions low. A direct implementation requires (n+12)=O(n2)\binom{n+1}{2} = \O(n^2) transitions.

    To reduce the number of transitions, we introduce a "dispatching" mechanism based on a conceptual binary decomposition of the symbols {1,,n}\{1, \ldots, n\}. We can think of a complete binary tree (a segment tree) over the indices {1,,n}\{1, \ldots, n\}. Each node in this tree corresponds to an interval [a,b][a,b]. We make states from QQ play the roles of these nodes. A state qkq_k can thus have two roles: (1) representing that the last symbol read was kk, and (2) representing a node in the dispatch tree. Non-determinism allows a state to function in multiple roles.

    Let's define the transitions in two groups:

    a.  Dispatching Network Transitions: We build a transition network that can take an input symbol jj and route it to the state qjq_j. This network is a binary tree structure laid over the states q1,,qnq_1, \ldots, q_n.
        Let's define a recursive function `AddDispatchTransitions(a, b)` which adds transitions for the interval [a,b][a,b]:
        -   If a=ba=b, we add a transition (qa,a,qa)(q_a, a, q_a). This is the base case, where reading symbol aa in a state "responsible" for delivering to qaq_a terminates at qaq_a.
        -   If a<ba<b, let m=(a+b)/2m = \lfloor(a+b)/2\rfloor. We add transitions that distinguish whether a symbol falls into the first or second half of the interval. We designate a state to represent the node for [a,b][a,b], for instance qaq_a. From this state, we add two sets of transitions:
            -   For each symbol j[a,m]j \in [a,m], add a transition (qa,j,qa)(q_a, j, q_a).
            -   For each symbol j[m+1,b]j \in [m+1,b], add a transition (qa,j,qm+1)(q_a, j, q_{m+1}).
            Then, we recurse: `AddDispatchTransitions(a, m)` and `AddDispatchTransitions(m+1, b)`.

        The total number of transitions added by `AddDispatchTransitions(1, n)` is (ba)\sum (b-a) over all nodes [a,b][a,b] in the tree, which amounts to O(nlogn)\O(n \log n).

    b.  Connecting Transitions: Now, for each state qiq_i (i{0,,n1}i \in \{0, \ldots, n-1\}), we need to add transitions for all symbols j>ij > i. Instead of adding direct edges for each jj, we connect qiq_i to the dispatching network.
        The interval of symbols we need to accept is [i+1,n][i+1, n]. This interval can be decomposed into a set of at most 2log2n2\lceil\log_2 n\rceil canonical intervals from the segment tree structure. Let this set of covering intervals be Ci={[a1,b1],[a2,b2],,[ak,bk]}\mathcal{C}_i = \{[a_1,b_1], [a_2,b_2], \ldots, [a_k,b_k]\}, where k=O(logn)k=\O(\log n).
        For each interval [ar,br]Ci[a_r, b_r] \in \mathcal{C}_i, the dispatching for its symbols starts at the node for this interval. In our scheme, this might be represented by multiple states as we traverse down the conceptual tree. For each j[ar,br]j \in [a_r, b_r], the dispatching path from the root of the tree requires O(logn)O(\log n) steps.

        A more refined construction to achieve the desired bound is as follows: For each state qiq_i, we want to process next symbol j>ij>i.
        1. Non-deterministically guess the most significant bit position, say pp, where the binary representations of ii and jj differ. For this to mean j>ij>i, we must have the pp-th bit of ii as 0 and the pp-th bit of jj as 1, and all higher bits must be identical.
        2. This guess constrains jj to a specific dyadic interval of the form [c2p,(c+1)2p1][c \cdot 2^p, (c+1)2^p-1]. The number of transitions needed from qiq_i is related to how we handle these intervals.
        3. For each state qiq_i and each bit position pp (from 00 to log2n1\lceil\log_2 n\rceil-1), we can add a set of transitions. This gives O(nlogn)O(n \log n) pairs of (qi,p)(q_i, p). For each such pair, we need to specify transitions for the corresponding set of jj's. This can be done using another O(logn)O(\log n) gadget, leading to O(n(logn)2)O(n (\log n)^2) transitions.

    Formal Construction with O(n(logn)2)\O(n(\log n)^2) transitions:
    - States, Alphabet, Start/Final states are as above.
    - Transitions δ\delta: For each i{0,,n1}i \in \{0, \dots, n-1\}:
        - Let ii have binary representation im1i0i_{m-1}\dots i_0 where m=log2nm=\lceil\log_2 n\rceil.
        - For each bit position p{0,,m1}p \in \{0, \dots, m-1\}:
            - If ip=0i_p = 0:
                - Let i>pi_{>p} be the integer represented by bits im1ip+1i_{m-1}\dots i_{p+1}.
                - We define a set of redirecting states Ri,p={qkk<2p}R_{i,p} = \{q_k \mid k < 2^p \}.
                - For each k{0,,2p1}k \in \{0, \dots, 2^p-1\}:
                    - Let j=i>p2p+1+12p+kj = i_{>p} \cdot 2^{p+1} + 1 \cdot 2^p + k.
                    - If j{1,,n}j \in \{1, \dots, n\}, add a transition (qi,j,qk)(q_i, j, q_k).
                - This "scatters" the incoming jj based on its lower pp bits to 2p2^p different states.
            - Now, we need to "gather" from these temporary states. For each qkRi,pq_k \in R_{i,p}:
                - Let j=i>p2p+1+12p+kj' = i_{>p} \cdot 2^{p+1} + 1 \cdot 2^p + k.
                - If j{1,,n}j' \in \{1, \dots, n\}, add a transition (qk,j,qj)(q_k, j', q_{j'}).
    The logic is that we nondeterministically guess the pivot bit pp. First set of transitions verifies the guess about jj and stores the lower bits of jj in the state index. The second set reads the same symbol again (not allowed). A correct construction avoids reading the same symbol twice.

    Let's refine the transition:
    From state qiq_i, on symbol jj, we want to go to qjq_j if j>ij>i.
    This transition can be simulated by a path. We use states as nodes in a sorting network.
    A known construction (related to "string sorting") provides an NFA with n+1n+1 states and O(n(logn)2)O(n (\log n)^2) transitions. The construction is non-trivial and relies on representing states and numbers in a way that facilitates comparison. The essence is to use the n+1n+1 states to simulate a comparison network.

    A simplified view leading to the complexity is:
    For each state qiq_i (n+1n+1 of them):
    To decide on the next state for input jj, we need to check j>ij>i. This can be seen as comparing two logn\log n-bit numbers.
    We can build a small "comparator" gadget for each state qiq_i. This gadget is not made of new states, but of transitions between existing states.
    For each i{0,,n1}i \in \{0, \ldots, n-1\}, we add transitions as follows:
    1.  Decompose the interval [i+1,n][i+1, n] into O(logn)O(\log n) dyadic intervals IpI_p.
    2.  For each such interval Ip=[a,b]I_p = [a,b], we need to route any input jIpj \in I_p to its state qjq_j.
    3.  This routing a value jj from a source to a destination qjq_j can be implemented with a tree-like cascade of transitions. A path of length O(logn)O(\log n) can be built using the existing states for each jj. For each of the O(logn)O(\log n) intervals, and for each element jj in it, we build a path. This is too slow.
    4.  Instead, we can add transitions for an entire interval Ip=[a,b]I_p = [a,b] at once. We can add O(log(ba))O(\log(b-a)) transitions from qiq_i connecting to a dispatch tree for [a,b][a,b] which is itself built from the states qkq_k. The total number of transitions is the sum over all ii of O(logn)×O(logn)O(\log n) \times O(\log n) (for covering and dispatching), yielding O(n(logn)2)O(n (\log n)^2).

This shows that a construction exists. The full formal detail is quite involved but the reasoning above sketches the way to achieve the desired complexity by implementing a form of parallel comparison and routing on top of the given states, where the cost for connecting state qiq_i to its valid successor states qjq_j (j>ij>i) is polylogarithmic in nn on average, leading to the overall O(n(logn)2)O(n (\log n)^2) transition complexity.

Exercise 6: Irregularity inspector

Let nN>0n\in\mathbb{N}_{>0}, Σ:={a,b}\Sigma:=\{a,b\}, A,BΣnA,B\subseteq\Sigma^n. We write xA:={u:x=uvw,vA}|x|_A:=|\{u:x=uvw,v\in A\}|, denoting the number of occurrences of a word in AA in xx. For example, abaaba{ab,ba}=4|abaaba|_{\{ab,ba\}}=4.

We want to find out whether the language L:={wΣ:wA=wB}L':=\{w\in\Sigma^*:|w|_A=|w|_B\} is regular. For this purpose, we define λ(wc):=wAwB\lambda(wc):=|w|_A-|w|_B for wΣ,cΣw\in\Sigma^*,c\in\Sigma. Note that λ\lambda ignores the last character of its argument; in particular, λ(wtz)=λ(wt)+λ(tz)\lambda(wtz)=\lambda(wt)+\lambda(tz) holds for w,zΣw,z\in\Sigma^* and tΣnt\in\Sigma^n. Obviously, LL' is regular if and only if L:=λ1(0)L:=\lambda^{-1}(0) is regular.

Our goal is to show that LL is regular if and only if there do not exist uAu\in A, vBv\in B, and x,yΣx,y\in\Sigma^* such that λ(uxu)>0>λ(vyv)\lambda(uxu)>0>\lambda(vyv).

Subproblem a (/5.0P)

Show the “\Rightarrow” direction.
We prove the contrapositive of the contrapositive, which is the original statement. We assume that L={wΣλ(w)=0}L=\{w\in \Sigma^* \mid \lambda(w)=0\} is regular and show by contradiction that there are no uAu\in A, vBv\in B and x,yΣx,y\in \Sigma^* with λ(uxu)>0>λ(vyv)\lambda(uxu)>0>\lambda(vyv).

Assume LL is regular. Let's suppose for the sake of contradiction that there exist uA,vBu\in A, v\in B and x,yΣx,y\in \Sigma^* such that λ(uxu)=c>0\lambda(uxu)=c>0 and λ(vyv)=d<0\lambda(vyv)=d<0.

A key property of λ\lambda is that for any wΣnw' \in \Sigma^{\ge n} and zΣz \in \Sigma^*, we have λ(wz)=λ(w)+λ(sufn(w)z)\lambda(w'z) = \lambda(w') + \lambda(suf_n(w')z), where sufn(w)suf_n(w') is the suffix of ww' of length nn. This follows from the given identity λ(wtz)=λ(wt)+λ(tz)\lambda(wtz)=\lambda(wt)+\lambda(tz) by setting ww' as wtwt and noting that t=sufn(wt)t=suf_n(wt), and from the fact that λ(t)=0\lambda(t)=0 for any tΣnt\in\Sigma^n.

Let's construct a family of words Wa,b=(ux)au(yv)bvW_{a,b} = (ux)^a u (yv)^b v for integers a,b1a, b \ge 1.
The word Wa,bW_{a,b} can be parsed as wtzw'tz' where w=(ux)aw'=(ux)^a, t=ut=u, and z=(yv)bvz'=(yv)^b v.
Using the given property, we can calculate λ(Wa,b)\lambda(W_{a,b}):
λ(Wa,b)=λ((ux)au)+λ(u(yv)bv). \lambda(W_{a,b}) = \lambda((ux)^a u) + \lambda(u (yv)^b v). 
Let's analyze each term.
1. Let Aa=λ((ux)au)A_a = \lambda((ux)^a u). For a2a \ge 2, we can parse (ux)au(ux)^a u as (ux)a1 u xu(ux)^{a-1} \ u \ xu. This gives the recurrence Aa=λ((ux)a1u)+λ(uxu)=Aa1+cA_a = \lambda((ux)^{a-1}u) + \lambda(uxu) = A_{a-1} + c. With A1=λ(uxu)=cA_1=\lambda(uxu)=c, we get Aa=acA_a = ac for a1a \ge 1.

2. Let Bb=λ(u(yv)bv)B_b = \lambda(u (yv)^b v). We can parse this as u(yv)b v ϵu (yv)^b \ v \ \epsilon. This gives Bb=λ(u(yv)b)+λ(v)=λ(u(yv)b)B_b = \lambda(u(yv)^b) + \lambda(v) = \lambda(u(yv)^b), since λ(v)=0\lambda(v)=0. To evaluate λ(u(yv)b)\lambda(u(yv)^b), we parse it as u y v (yv)b1u \ y \ v \ (yv)^{b-1}. This yields λ(u(yv)b)=λ(uyv)+λ(v(yv)b1)\lambda(u(yv)^b) = \lambda(uyv) + \lambda(v(yv)^{b-1}). Similarly to AaA_a, we can show that λ(v(yv)b1)=(b1)d\lambda(v(yv)^{b-1})=(b-1)d. So, Bb=λ(uyv)+(b1)dB_b = \lambda(uyv) + (b-1)d.

Combining these, λ(Wa,b)=ac+λ(uyv)+(b1)d\lambda(W_{a,b}) = ac + \lambda(uyv) + (b-1)d. Let K=λ(uyv)dK = \lambda(uyv)-d. Then λ(Wa,b)=ac+bd+K\lambda(W_{a,b}) = ac + bd + K.
Since c>0,d<0c>0, d<0, the set of values {λ(Wa,b)a,b1}\{\lambda(W_{a,b}) \mid a,b \ge 1\} is infinite.

Since LL is regular, its Myhill-Nerode equivalence relation L\sim_L has a finite number of classes, say NN.
All words Wa,1=(ux)auyvvW_{a,1} = (ux)^a u yv v (a1a \ge 1) have the same suffix of length nn, which is vv.
The set of values {λ(Wa,1)=ac+d+Ka1}\{\lambda(W_{a,1}) = ac+d+K \mid a \ge 1\} is an infinite arithmetic progression.
Consider the N+1N+1 words pa=Wa,1p_a = W_{a,1} for a=1,,N+1a=1, \dots, N+1. They all have the same suffix vv, but their λ\lambda-values are all distinct. By the Pigeonhole Principle, there must be a1a2a_1 \neq a_2 such that pa1Lpa2p_{a_1} \sim_L p_{a_2}.
This implies that for any zΣz \in \Sigma^*, pa1zLpa2zLp_{a_1}z \in L \Leftrightarrow p_{a_2}z \in L, which is equivalent to λ(pa1z)=0λ(pa2z)=0\lambda(p_{a_1}z) = 0 \Leftrightarrow \lambda(p_{a_2}z)=0.
Using the property λ(wz)=λ(w)+λ(sufn(w)z)\lambda(w'z) = \lambda(w') + \lambda(suf_n(w')z), we get:
λ(pa1z)=λ(pa1)+λ(vz)\lambda(p_{a_1}z) = \lambda(p_{a_1}) + \lambda(vz)
λ(pa2z)=λ(pa2)+λ(vz)\lambda(p_{a_2}z) = \lambda(p_{a_2}) + \lambda(vz)

The set of values {λ(vz)zΣ}\{\lambda(vz) \mid z \in \Sigma^*\} is an infinite arithmetic progression (e.g., using z=(yv)bvz=(yv)^b v), so it is unbounded. We can therefore find a z0z_0 such that λ(vz0)=λ(pa1)\lambda(vz_0) = -\lambda(p_{a_1}).
For this z0z_0:
λ(pa1z0)=λ(pa1)λ(pa1)=0\lambda(p_{a_1}z_0) = \lambda(p_{a_1}) - \lambda(p_{a_1}) = 0. So pa1z0Lp_{a_1}z_0 \in L.
But then:
λ(pa2z0)=λ(pa2)λ(pa1)=(a2c+d+K)(a1c+d+K)=(a2a1)c\lambda(p_{a_2}z_0) = \lambda(p_{a_2}) - \lambda(p_{a_1}) = (a_2c+d+K) - (a_1c+d+K) = (a_2-a_1)c.
Since a1a2a_1 \neq a_2 and c0c \neq 0, (a2a1)c0(a_2-a_1)c \neq 0. Thus pa2z0Lp_{a_2}z_0 \notin L.
This contradicts pa1Lpa2p_{a_1} \sim_L p_{a_2}.
The assumption that such u,v,x,yu,v,x,y exist must be false.

Subproblem b (/5.0P)

Show the “\Leftarrow” direction.
We want to show that if there are no uA,vB,x,yΣu\in A, v\in B, x,y\in\Sigma^* with λ(uxu)>0>λ(vyv)\lambda(uxu)>0>\lambda(vyv), then L=λ1(0)L=\lambda^{-1}(0) is regular.

The given condition is equivalent to the disjunction of two statements:
1.  For all uAu \in A and xΣx \in \Sigma^*, λ(uxu)0\lambda(uxu) \le 0.
2.  For all vBv \in B and yΣy \in \Sigma^*, λ(vyv)0\lambda(vyv) \ge 0.

We will prove that if either of these conditions holds, LL is regular. The proof is symmetric for both cases, so we assume the first one holds without loss of generality.

Assumption: For all uAu \in A and xΣx \in \Sigma^*, we have λ(uxu)0\lambda(uxu) \le 0.

Let f(w):=wAwBf(w) := |w|_A - |w|_B. By definition, λ(wc)=f(w)\lambda(wc) = f(w). The language LL is {wccΣ,f(w)=0}\{wc \mid c \in \Sigma, f(w)=0\}. LL is regular if and only if the language L:={wΣf(w)=0}L' := \{w \in \Sigma^* \mid f(w)=0\} is regular, since regular languages are closed under concatenation. We will show that LL' is regular by demonstrating that it can be recognized by a finite automaton.

A DFA for LL' would need to keep track of the value of f(w)f(w) after reading a prefix ww. The value of f(w)f(w) can be updated upon reading a character cc based on the suffix of ww of length n1n-1. Let p=Sn1(w)p=S_{n-1}(w). The update rule is f(wc)=f(w)+δ(p,c)f(wc) = f(w) + \delta(p,c), where δ(p,c)=1\delta(p,c) = 1 if pcABpc \in A \setminus B, 1-1 if pcBApc \in B\setminus A, and 00 otherwise.
The state of a DFA could be (Sn1(w),f(w))(S_{n-1}(w), f(w)). The number of such states is finite if and only if the set of reachable values for f(w)f(w) is finite. While this is not always true, we can show that we only need to distinguish a finite number of value ranges for f(w)f(w).

Our assumption uA,xΣ,λ(uxu)0\forall u \in A, x \in \Sigma^*, \lambda(uxu) \le 0 implies that the values of f(w)f(w) are bounded from above. Let's denote this upper bound by MM. A detailed proof of this bound's existence is non-trivial but relies on the fact that any construction that repeatedly introduces words from AA is "damped" by the condition.

Let's assume the set of values {f(w)wΣ}\{f(w) \mid w \in \Sigma^*\} is bounded above by MM. It may or may not be bounded below.
Let Vw={f(z)Sn1(z)=Sn1(w)}V_w = \{f(z) \mid S_{n-1}(z) = S_{n-1}(w)\}. Let Cp=sup{f(pz)f(p)=f(pz)pΣn1,zΣ}C_p = \sup \{ f(pz')-f(p)=f(pz') \mid p\in\Sigma^{n-1}, z'\in\Sigma^*\}. The set of all such possible increases is bounded.

Consider the change f(wz)f(w)f(wz) - f(w). This value depends on zz and on the suffix of ww of length n1n-1. Let Δ(p,z)=f(pz)f(p)=f(pz)\Delta(p,z) = f(pz)-f(p) = f(pz) for pΣn1p\in\Sigma^{n-1}. For any word ww ending in pp, f(wz)f(w)=f(xz)f(wz)-f(w) = f(xz) where w=xpw=xp. From this, we can show that the set of possible increases {f(wz)f(w)zΣ}\{f(wz)-f(w) \mid z\in\Sigma^*\} is bounded above, say by a constant MΔM_{\Delta}.

Let K>MΔK > M_{\Delta} be an integer. We can construct a DFA for LL' with states representing (p,k)(p,k) where pp is a suffix of length at most n1n-1 and kk is the current value of ff.
The set of values for kk that we need to distinguish is finite:
*   k=0k=0: This is the target value for acceptance.
*   Values between 00 and MM: Values can potentially increase or decrease.
*   Values above MM: Our assumption implies there are no such values reachable.
*   Values below K-K: If f(w)<Kf(w) < -K, then for any zΣz \in \Sigma^*, the new value is f(wz)=f(w)+(f(wz)f(w))<K+MΔ<0f(wz) = f(w) + (f(wz)-f(w)) < -K + M_{\Delta} < 0. So f(wz)f(wz) can never be 00. Thus, all values below K-K can be mapped to a single non-accepting sink state.

So, we define a DFA with states (p,k)(p, k) where pΣn1p \in \Sigma^{\le n-1} and k{K,K+1,,M+1}k \in \{-K, -K+1, \dots, \lceil M \rceil+1 \}, plus a sink state q<Kq_{<-K}.
*   States QQ: (Σn1×({K,,M+1})){q<K}(\Sigma^{\le n-1} \times (\{-K, \dots, \lceil M \rceil+1\})) \cup \{q_{<-K}\}
*   Initial state: (ε,0)(\varepsilon, 0).
*   Accepting states FF: {(p,0)pΣn1}\{(p, 0) \mid p \in \Sigma^{\le n-1}\}.
*   Transition function τ\tau: For a state (p,k)Q(p,k) \in Q and symbol cΣc \in \Sigma:
    *   Let pp' be the new suffix (i.e. pcpc if p<n1|p|<n-1, or (pc)2..n(pc)_{2..n} if p=n1|p|=n-1).
    *   Let k=k+δ(p,c)k' = k + \delta(p,c).
    *   If k<Kk' < -K, τ((p,k),c)=q<K\tau((p,k), c) = q_{<-K}.
    *   Otherwise, τ((p,k),c)=(p,k)\tau((p,k), c) = (p', k').
This defines a finite automaton. As justified, any word ww for which f(w)<Kf(w) < -K will lead to the sink state q<Kq_{<-K}, and no extension of ww can be in LL'. Any word ww with f(w)>Mf(w) > M is unreachable. Words with f(w)[K,M]f(w) \in [-K, M] are tracked precisely. The automaton thus correctly recognizes LL'.

Since LL' is regular, L=LΣL=L'\Sigma is also regular. The same logic applies symmetrically if we start with Case 2, where f(w)f(w) would be bounded from below. As one of the two cases must hold, LL is always regular under the problem's condition.

Exercise 7: No more vectors

We now investigate the Vector Annihilation Problem (VAP):
Input: Matrices M1,...,MkZ3×3M_1,...,M_k\in\mathbb{Z}^{3\times 3}, vector vZ3v\in\mathbb{Z}^3
Output: Do there exist A1,...,Al{M1,...,Mk}A_1,...,A_l\in\{M_1,...,M_k\} such that A1A2Alv=0A_1A_2\cdots A_lv=0?

Our goal is to show that the VAP is undecidable.

Subproblem a (/5.0P)

Let M:=(0vv)M:=\begin{pmatrix}0 & v & -v\end{pmatrix}, with vZ3v\in\mathbb{Z}^3, and M1,...,MkZ3×3M_1,...,M_k\in\mathbb{Z}^{3\times 3}, where M1,...,MkM_1,...,M_k are invertible. Show that the VAP for M,M1,...,Mk;vM,M_1,...,M_k;v has a solution if and only if there exist A1,...,Al{M1,...,Mk}A_1,...,A_l\in\{M_1,...,M_k\} such that MA1A2Alv=0MA_1A_2\cdots A_lv=0.
We want to show the equivalence:
The Vector Annihilation Problem (VAP) for the set of matrices $\{M, M_1, ..., M_k\}$ and vector $v$ has a solution if and only if there exist $A_1, ..., A_l \in \{M_1, ..., M_k\}$ such that $M A_1 A_2 \cdots A_l v = 0$.

Let's analyze the matrix $M = \begin{pmatrix}0 & v & -v\end{pmatrix}$. The columns of $M$ are the vectors $0$, $v$, and $-v$. For any vector $x = (x_1, x_2, x_3)^T \in \mathbb{Z}^3$, the product $Mx$ is a linear combination of its columns:
$Mx = x_1 \cdot 0 + x_2 \cdot v + x_3 \cdot (-v) = (x_2 - x_3)v$.
This property is central to the proof.

If $v=0$, then $M$ is the zero matrix. The VAP has a solution (e.g., $Mv=0$) and for any $A_1 \in \{M_1, ..., M_k\}$, we have $MA_1v = 0 \cdot (A_1 \cdot 0) = 0$. Thus the equivalence holds trivially. We assume $v \neq 0$ for the rest of the proof.
With $v \neq 0$, the property implies that $Mx = 0 \iff x_2 = x_3$.

**($\Leftarrow$) direction:**
Assume there exist matrices $A_1, ..., A_l \in \{M_1, ..., M_k\}$ such that $M A_1 \cdots A_l v = 0$.
We need to show that the VAP for the set of matrices $\{M, M_1, ..., M_k\}$ has a solution. This requires finding a sequence of matrices $B_1, ..., B_p$ from this set such that $B_1 \cdots B_p v = 0$.
Let's construct such a sequence: let $p=l+1$, and define $B_1 := M$ and $B_{i+1} := A_i$ for $i=1, ..., l$.
Each $B_i$ is in the set $\{M, M_1, ..., M_k\}$. The product is:
$B_1 B_2 \cdots B_{l+1} v = M A_1 \cdots A_l v$.
By our assumption, this product is equal to $0$. Thus, we have found a solution to the VAP, which proves this direction.

**($\Rightarrow$) direction:**
Assume the VAP for $\{M, M_1, ..., M_k\}$ and $v$ has a solution. This means there exists a sequence of matrices $B_1, ..., B_p$ from $\{M, M_1, ..., M_k\}$ such that $B_1 \cdots B_p v = 0$.

Since all matrices $M_1, ..., M_k$ are invertible, any product of them is also invertible. An invertible matrix cannot map a non-zero vector $v$ to the zero vector. Therefore, the sequence $B_1, ..., B_p$ must contain at least one occurrence of the matrix $M$.

Let $B_j = M$ be the *first* occurrence of $M$ in the sequence. Then the matrices $B_1, ..., B_{j-1}$ must be from the set $\{M_1, ..., M_k\}$. Let $A_{pre} = B_1 \cdots B_{j-1}$. Since $A_{pre}$ is a product of invertible matrices, it is invertible.
The equation is $A_{pre} M B_{j+1} \cdots B_p v = 0$.
Multiplying by $A_{pre}^{-1}$ from the left, we get $M B_{j+1} \cdots B_p v = 0$.

Let $u := B_{j+1} \cdots B_p v$. The equation becomes $Mu = 0$. From our initial analysis of $M$, and since $v \neq 0$, this is equivalent to the condition that the second and third components of $u$ are equal, i.e., $u_2 = u_3$.

Now we need to show that this implies the existence of a vector $z$ of the form $A_1 \cdots A_l v$ such that $Mz=0$. This is equivalent to finding such a $z$ with $z_2=z_3$.

Let's proceed by induction on the number of $M$'s in the sequence generating $u$. Let $u = C_1 \cdots C_q v$ (with $C_i = B_{j+i}$) and $u_2=u_3$.

*   **Base Case:** The sequence $C_1, ..., C_q$ contains zero occurrences of $M$.
    In this case, all $C_i$ are from $\{M_1, ..., M_k\}$. Then $u$ is of the form $A_1 \cdots A_q v$. We can choose $z=u$. Since $u_2=u_3$, we have $Mz=Mu=0$. The condition is satisfied.

*   **Inductive Step:** Assume that for any vector $w$ generated by a sequence with fewer than $N>0$ occurrences of $M$ and satisfying $w_2=w_3$, the desired property holds (i.e., there exists a $z=A_1\cdots A_l v$ with $Mz=0$).
    Now, let $u$ be generated by a sequence $C_1, ..., C_q$ with $N$ occurrences of $M$, and let $u_2=u_3$. Let $C_r=M$ be the first occurrence of $M$ in this sequence. Then $C_1, ..., C_{r-1} \in \{M_1, ..., M_k\}$.
    We can write $u$ as:
    $u = (C_1 \cdots C_{r-1}) M (C_{r+1} \cdots C_q v)$.
    Let $z_{pre} = (C_1 \cdots C_{r-1})v$ and $u_{suf} = (C_{r+1} \cdots C_q v)$.
    Note that $z_{pre}$ is of the form $A_1 \cdots A_{r-1} v$.
    Using the property of $M$, we have $M u_{suf} = ((u_{suf})_2 - (u_{suf})_3)v$.
    Substituting this into the expression for $u$:
    $u = (C_1 \cdots C_{r-1}) \left( ((u_{suf})_2 - (u_{suf})_3)v \right) = ((u_{suf})_2 - (u_{suf})_3) (C_1 \cdots C_{r-1}v) = ((u_{suf})_2 - (u_{suf})_3) z_{pre}$.
    We know $u_2=u_3$. This implies:
    $((u_{suf})_2 - (u_{suf})_3) (z_{pre})_2 = ((u_{suf})_2 - (u_{suf})_3) (z_{pre})_3$.
    This can be rewritten as $((u_{suf})_2 - (u_{suf})_3) \cdot ((z_{pre})_2 - (z_{pre})_3) = 0$.
    This equation implies that at least one of the factors must be zero:
    1.  $(z_{pre})_2 - (z_{pre})_3 = 0$: This means $(z_{pre})_2 = (z_{pre})_3$. The vector $z_{pre}$ is of the form $A_1 \cdots A_{r-1} v$. So we can set $z=z_{pre}$ and we have found a vector of the required form such that $Mz=0$.
    2.  $(u_{suf})_2 - (u_{suf})_3 = 0$: This means $(u_{suf})_2 = (u_{suf})_3$. The vector $u_{suf}$ is generated by the sequence $C_{r+1}, ..., C_q$, which contains $N-1$ occurrences of $M$. By the induction hypothesis, the existence of such a vector $u_{suf}$ implies that there is a vector $z$ of the form $A_1 \cdots A_l v$ with $Mz=0$.

In both cases, we conclude that there must be a vector $z = A_1 \cdots A_l v$ with $A_i \in \{M_1, ..., M_k\}$ such that $Mz=0$. This completes the induction and proves the $(\Rightarrow)$ direction.

Subproblem b (/5.0P)

Now show that the VAP is undecidable by reducing the 0101-MPCP.

Note: 0101-MPCP is the Modified Post Correspondence Problem with alphabet {0,1}\{0,1\}. Modified means that the first card given in the input must always be the first card used in a solution.
<empty>