Exam puzzle.txt — openai/gpt-5

Exercise a b Total
1: Thue-Morse sequence 5.0/5.0 5.0/5.0 10.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 25.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 (5.0/5.0P)

Into which position does the `a` corner move after executing w100w_{100} ? Prove your answer.
abcdef
Let σ be the permutation induced by a 0 (front clockwise) and τ the one induced by a 1 (right counter-clockwise):
- σ = (a b c d), fixes e,f.
- τ = (c d e f), fixes a,b.

Let A_n be the permutation effected by the word w_n (applied left-to-right), so for concatenation uv we have A_{uv} = A_v ∘ A_u. Since w_{n+1} = w_n \overline{w_n} and \overline{w_{n+1}} = \overline{w_n} w_n, we get
A_{n} = A_{\overline{w_{n-1}}} ∘ A_{n-1}, and A_{\overline{w_n}} = A_{n-1} ∘ A_{\overline{w_{n-1}}}.
Eliminating A_{\overline{w_{n-1}}} yields the recurrence
A_{n+1} = A_{n-1} A_n A_{n-1}^{-1} A_n.  (∗)

Compute A_1,…,A_4 explicitly:
- A_0 = σ.
- A_1 = τ ∘ σ: a→b, b→d, c→e, d→a, e→f, f→c.
- A_2 = σ ∘ τ^2 ∘ σ: a→c, b→e, c→f, d→b, e→d, f→a.
- Using (∗): A_3 = A_1 A_2 A_1^{-1} A_2 gives a→b, b→c, c→a, d→e, e→f, f→d.
- Then A_4 = A_2 A_3 A_2^{-1} A_3 gives a→d, b→e, c→b, d→f, e→c, f→a.
In particular, A_4(a) = d.

We now show A_{n+4} = A_n for all n ≥ 2. First verify the base cases:
- Using (∗) and the above values, A_5 = A_3 A_4 A_3^{-1} A_4 = A_1, and
- A_6 = A_4 A_5 A_4^{-1} A_5 = A_4 A_1 A_4^{-1} A_1 = A_2 (check on all six points).
Assume A_{k+4} = A_k and A_{k+3} = A_{k-1} for some k ≥ 2. Then by (∗),
A_{k+5} = A_{k+3} A_{k+4} A_{k+3}^{-1} A_{k+4} = A_{k-1} A_k A_{k-1}^{-1} A_k = A_{k+1},
and similarly A_{k+6} = A_{k+2}. Thus by induction, A_{n+4} = A_n for all n ≥ 2.

Since 100 ≡ 0 mod 4 and 100 ≥ 2, we have A_{100} = A_4, hence A_{100}(a) = A_4(a) = d.

Therefore, after executing w_{100}, corner a is in position d.

Subproblem b (5.0/5.0P)

Into which position does the `a` corner move after executing w2100w_{2^{100}} ? Prove your answer.
abcdef
Let A_n be the permutation induced by w_n. From subproblem (a) we have, for all n ≥ 2, the 4-periodicity A_{n+4} = A_n (proved via the recurrence A_{n+1} = A_{n-1} A_n A_{n-1}^{-1} A_n). Since 2^{100} ≥ 2 and 2^{100} ≡ 0 (mod 4), it follows that A_{2^{100}} = A_4. From the explicit computation in (a), A_4(a) = d. Hence after executing w_{2^{100}}, corner a is in 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
Because M′ is a DFA, δ′ must be total and single-valued. Hence for each c∈Σ, the map δ_c:Q→Q given by δ_c(q)=δ(q,c) is bijective (its inverse is δ′(·,c)). Thus M is a permutation (group) automaton: every letter acts as a permutation of Q.

Let G be the finite group generated by {δ_c : c∈Σ}, and let O be the orbit of q₀ under G: O={g(q₀) : g∈G}. Then
L(M) = { w∈Σ* : δ_w(q₀) ∈ F }.

If O∩F=∅, then L(M)=∅.

Otherwise pick s∈O∩F and u∈Σ* with δ_u(q₀)=s. Since Σ≠∅, choose any a∈Σ. The permutation δ_a has finite order m≥1, so δ_{a^m}=id. Hence for all k≥0,
δ_{u a^{mk}}(q₀)=δ_u(q₀)=s∈F,
so u a^{mk} ∈ L(M). These are infinitely many distinct words, so L(M) is infinite.

Therefore 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
Let L be recognized by a DFA A = (Q, Σ, δ, q₀, F). For a ∈ Σ define τ_a: Q → Q by τ_a(q) = δ(q, a), and for w = a₁…a_n define τ_w = τ_{a_n} ∘ ⋯ ∘ τ_{a_1}. Then δ̂(q, w) = τ_w(q). The set M = {τ_w : w ∈ Σ*} ⊆ Q^Q is finite (|M| ≤ |Q|^{|Q|}), and μ: Σ* → M, μ(w) = τ_w, is a monoid morphism.

Define the accepting set
T := { m ∈ M : ∀k ≥ 0, m^k(q₀) ∈ F }.
Note that the k = 0 case enforces q₀ ∈ F, i.e., ε ∈ L.

Consider the DFA B with state set M, start state id (the identity on Q), transition m —a→ m ∘ τ_a, and accepting states T. For any w, B reaches state μ(w) = τ_w. Then:
w ∈ L(B) ⇔ τ_w ∈ T ⇔ ∀k ≥ 0, τ_w^k(q₀) ∈ F ⇔ ∀k ≥ 0, δ̂(q₀, w^k) ∈ F ⇔ {w}^* ⊆ L.

Hence L(B) = L′, so L′ is 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
Upper bound (always holds): Let LL be accepted by a minimal DFA AA with nn states. As shown in part (a), LL' is recognized by the DFA whose states are the elements of the transition monoid MM of AA, with Mnn|M| \le n^n. Hence nnnn' \le n^n, i.e., nO(nn)n' \in O(n^n).

Why this is the strongest among the listed bounds: It suffices to exhibit a family (Ln)(L_n) with minimal DFA size nn such that the minimal DFA for LnL'_n has at least 2n2^n states (superpolynomial), which rules out options 1–3, while option 4 still holds by the general upper bound.

Witness family: For each n2n \ge 2, fix Q={1,,n}Q = \{1, \ldots, n\}, start state q0=1q_0 = 1, and let the alphabet generate the full transformation monoid TnT_n on QQ (for example, take letters that realize an nn-cycle, a transposition/merge, and a reset; it is classical that a small fixed set of such transformations generates TnT_n). Let F={1}F = \{1\}. Then:
- Reachability: For every rQr \in Q there is a transformation tt with t(1)=rt(1) = r, hence a word taking q0q_0 to rr; thus every state is reachable.
- Distinguishability: For any distinct p,qQp, q \in Q there is a transformation ss with s(p)=1Fs(p) = 1 \in F and s(q)=2Fs(q) = 2 \notin F; hence from pp there is a word to accept and from qq the same word leads to reject. Thus the DFA for LnL_n is minimal with nn states.

Now consider the DFA BB recognizing LnL'_n built in part (a); its states are the transformations mTnm \in T_n. For each subset SQS \subseteq Q, let mSTnm_S \in T_n be the map with mS(x)=1m_S(x) = 1 if xSx \in S, and mS(x)=2m_S(x) = 2 otherwise. For each xQx \in Q, let cxc_x be the constant map to xx (also in TnT_n). In BB, from the state mSm_S, reading a word realizing cxc_x moves to the transformation mScxm_S \circ c_x, which is the constant map to mS(x)m_S(x). By the definition of TT in part (a) and F={1}F = \{1\}, we have:
mScxT    mS(x)F    xS.m_S \circ c_x \in T \iff m_S(x) \in F \iff x \in S.

Hence for SSS \ne S', pick xSSx \in S \triangle S'; then the residuals of LnL'_n after words realizing mSm_S and mSm_{S'} differ on the suffix realizing cxc_x, so these two states are distinguishable. Therefore BB has at least 2n2^n pairwise distinguishable states, and the minimal DFA for LnL'_n has n2nn' \ge 2^n. This shows nn' is not O(n100)O(n^{100}) (nor O(n2)O(n^2), O(n)O(n)) in general.

Combining with the universal upper bound nnnn' \le n^n, option 4 is the strongest bound among the given choices that always holds.

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
We prove: if γ is rational, then L_γ is regular.

Fix the (unique) decimal expansion of γ that is not eventually 9, so γ = 0.b₁…b_N (c₁…c_p)^ω for some N ≥ 0, p ≥ 1, with digits b_i, c_j ∈ {0,…,9} and the period (c₁…c_p) not equal to 9…9.

Construction of a DFA recognizing L_γ:
- States:
  * “equal” states that remember the position in γ’s digit stream:
    - eq(1), …, eq(N) for the preperiod,
    - eq(N,0), …, eq(N,p−1) for the periodic phase (index modulo p),
  * an absorbing accepting state LESS,
  * an absorbing rejecting state GREATER.
- Start state: eq(1) (or eq(N,0) if N=0).
- Accepting states: LESS and all eq(·).
- Transitions on reading a digit d:
  * From LESS: stay in LESS on any d.
  * From GREATER: stay in GREATER on any d.
  * From eq(i), 1 ≤ i ≤ N: compare d with b_i:
    - if d < b_i, go to LESS;
    - if d > b_i, go to GREATER;
    - if d = b_i, go to eq(i+1) (with eq(N+1) understood as eq(N,0)).
  * From eq(N,k), 0 ≤ k ≤ p−1: let expected digit be c_{k+1} (with indices modulo p):
    - if d < c_{k+1}, go to LESS;
    - if d > c_{k+1}, go to GREATER;
    - if d = c_{k+1}, go to eq(N,(k+1) mod p).

Correctness:
- If the first position where the input’s digit differs from γ’s digit is k and the input digit there is smaller, then any continuation yields a value ≤ γ. Indeed, the maximum tail the input can add is ∑_{i>k} 9/10^i = 1/10^k, so 0.w ≤ ∑_{i<k} b_i/10^i + (b_k−1)/10^k + 1/10^k = ∑_{i≤k} b_i/10^i ≤ γ.
- If at that first differing position the input digit is larger, then 0.w ≥ ∑_{i≤k} b_i/10^i + 1/10^k > γ, where the strict inequality holds because we chose γ’s expansion not eventually 9, so its tail beyond k is strictly less than 1/10^k.
- If no difference occurs within the length of the input, then the input equals a prefix of γ’s digits, hence its value is ≤ γ.

The DFA exactly implements these three cases with finitely many states (only N+p index-tracking “equal” states plus two sinks). Therefore L_γ is regular.

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
We prove: if L_γ is regular, then γ is rational.

Fix the unique decimal expansion of γ that is not eventually 9:
γ = 0.a₁a₂a₃… with a_i ∈ {0,…,9}.
For a prefix p = a₁…a_k of this expansion, write suf(p) = a_{k+1}a_{k+2}… for the infinite tail.

Claim. If p is a prefix of γ’s digits, then for every finite word x,
(0.px)_{10} ≤ γ  iff  x ≤_lex suf(p).
Justification: comparing (0.px) to γ reduces to the first position where x and suf(p) differ; the choice of the non-9 expansion guarantees strict separation when the first differing digit is larger.

Assume L_γ is recognized by a DFA M. Let q_k be the state reached after reading the prefix a₁…a_k. Since M has finitely many states, there exist i<j with q_i = q_j. Then for all x ∈ Σ*,
a₁…a_i x ∈ L_γ  iff  a₁…a_j x ∈ L_γ.
By the claim, this means for all x,
x ≤_lex suf(a₁…a_i)  iff  x ≤_lex suf(a₁…a_j).
The set {x : x ≤_lex β} determines the infinite word β uniquely when the expansion is not eventually 9; hence suf(a₁…a_i) = suf(a₁…a_j). Therefore the digit sequence a₁a₂… is ultimately periodic with period p = j−i, so γ has an ultimately periodic decimal expansion and is rational.

Consequences. Since rational numbers are algebraic and computable, options 3 and 4 are also necessary.

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.
Let Q={q0,,qn}Q=\{q_0,\dots,q_n\} be the set of states. Take q0q_0 as the (single) start state and let all states be accepting, i.e., F=QF=Q. The alphabet is Σ={1,,n}\Sigma=\{1,\dots,n\}.

Transitions are of two kinds.

1) Epsilon “jump” transitions (independent of the input symbol):
For every i{0,,n}i\in\{0,\dots,n\} and every t0t\ge 0 with i+2tni+2^t\le n, add
(qi,ε,qi+2t)(q_i,\varepsilon,q_{i+2^t}).
These allow moving forward by any distance using a binary decomposition.

2) Symbol transitions (one per letter per “landmark” predecessor):
For every j{1,,n}j\in\{1,\dots,n\} and every t{0,1,,log2j}t\in\{0,1,\dots,\lfloor \log_2 j\rfloor\}, add
(qj2t,j,qj)(q_{j-2^t},\,j,\,q_j).
Thus, for letter jj, there are edges into qjq_j from the “landmark” predecessors
qj1,qj2,qj4,qj8,q_{j-1},q_{j-2},q_{j-4},q_{j-8},\dots (as far as they are nonnegative).

Correctness:
- If w=a1a2akLw=a_1a_2\cdots a_k\in L (strictly increasing), we build an accepting run inductively.
  Assume we are at qam1q_{a_{m-1}} (with a0:=0a_0:=0). Let d=amam11d=a_m-a_{m-1}\ge 1 and let 2td<2t+12^t\le d<2^{t+1}.
  Using epsilon jumps (which only go forward), move from qam1q_{a_{m-1}} to qam2tq_{a_m-2^t} (possible since am2tam1a_m-2^t\ge a_{m-1} and any forward distance decomposes into powers of two), then take the symbol edge (qam2t,am,qam)(q_{a_m-2^t},a_m,q_{a_m}). Since all states are accepting, the run accepts.
- Conversely, suppose ww is not strictly increasing; then at some step we attempt to read bab\le a, where aa is the last letter already read. Epsilon jumps only move forward (to larger indices), so just before consuming bb the current state index ss satisfies sas\ge a. Any edge labeled bb must originate at some qb2tq_{b-2^t} with b2t<basb-2^t<b\le a\le s, which is not reachable from qsq_s by forward-only epsilons. Hence no transition can consume bb, so ww is rejected. Therefore L(N)=LL(N)=L.

Size bounds:
- States: exactly n+1n+1.
- Epsilon transitions: for each ii, at most log2(ni)+1\lfloor\log_2(n-i)\rfloor+1 jumps; summing gives O(nlogn)O(n\log n).
- Symbol transitions: for letter jj, exactly log2j+1\lfloor\log_2 j\rfloor+1 edges; summing gives O(nlogn)O(n\log n).
Total transitions: O(nlogn)O(n(log2n)2)O(n\log n)\subseteq O\bigl(n(\log_2 n)^2\bigr).

Thus, there exists an NFA with n+1n+1 states and O(n(log2n)2)O\bigl(n(\log_2 n)^2\bigr) transitions recognizing LL.

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.
Assume L is regular. Suppose, for a contradiction, that there exist u∈A, v∈B and x,y∈Σ* with α:=λ(uxu)>0 and β:=-λ(vyv)>0.

For k≥1 define p_k:=(ux)^k u and n_k:=(vy)^k v. By the additivity identity λ(wtz)=λ(wt)+λ(tz) applied at the occurrences of u (resp. v), we get
- λ(p_k)=k·α,
- λ(n_k)=−k·β.

Fix k. Consider suffixes of the form
z = (xu)^r v (yv)^s,
with r,s≥0 to be chosen. Using the identity at u, then at v, one computes
λ(p_k z) = kα + λ(u (xu)^r v (yv)^s) = kα + rα + λ(uv) − sβ.
Thus
λ(p_k z)=0 ⇔ (k+r)α − sβ = −λ(uv).

Let d:=gcd(α,β). Since α,β>0, the linear Diophantine equation (k+r)α − sβ = −λ(uv) has integer solutions (r,s) and, by shifting along the solution lattice by multiples of (β/d, α/d), we can ensure r,s≥0. Choose such r,s, and set z_k:=(xu)^r v (yv)^s. Then λ(p_k z_k)=0, i.e., p_k z_k∈L. But
λ(p_{k+1} z_k) = (k+1)α + rα + λ(uv) − sβ = α ≠ 0,
so p_{k+1} z_k∉L. Hence for every k the two prefixes p_k and p_{k+1} are distinguished by the same suffix z_k. Therefore Σ* has infinitely many Myhill–Nerode equivalence classes w.r.t. L, contradicting the regularity of L.

Thus, if L is regular, no such u∈A, v∈B, x,y∈Σ* with λ(uxu)>0>λ(vyv) can exist.

Subproblem b (/5.0P)

Show the “\Leftarrow” direction.
Assume there do not exist u∈A, v∈B and x,y∈Σ* with λ(uxu)>0>λ(vyv). We prove that L=λ^{-1}(0) is regular.

View the evolution of λ along the de Bruijn graph on Σ^n:
- Vertices are t∈Σ^n.
- From t to t′ there is an edge labeled by c∈Σ if the last n−1 symbols of t′ equal the last n−1 of t followed by c.
- Assign weight g(t):=1_A(t)−1_B(t)∈{−1,0,1} to every outgoing edge from t. Then for any word w and next letter c, λ(wc)−λ(w)=g(t), where t is the length-n suffix of w (if |w|<n, the increment is 0).

A closed walk starting and ending in t has total weight exactly λ(t z t) for the corresponding label z. Any positive-weight closed walk visits some vertex in A, and any negative-weight closed walk visits some vertex in B; by cyclic rotation we may base such a walk at a vertex of A or B respectively. Hence the hypothesis implies that not both signs occur: either every directed cycle has weight ≥0, or every directed cycle has weight ≤0. By symmetry it suffices to treat the case “all cycles have weight ≥0”.

In this case, along any walk the minimal prefix-sum (relative to its start) is attained before the first repetition of a vertex. Since the de Bruijn graph has N:=|Σ|^n vertices and each step decreases by at most 1, the total possible drop from any starting vertex is bounded by D:=N−1:
for every vertex t and every path z, λ(tz)−λ(t) ≥ −D.
Consequently, for any word w and any continuation z we have
λ(wz) ≥ λ(w) − D.
In particular, if λ(w) > D then for all z, λ(wz) > 0, so w cannot be extended to reach 0 (and w∉L already).

We now build a DFA recognizing L. Its states store:
- the current suffix of length <n (to determine when increments start and what the next g(·) will be), and
- a clipped counter r∈{−D,−D+1,…,D} recording λ exactly as long as |λ|≤D, with a single rejecting sink state ⊤ representing “λ>D”.

Transitions update the suffix in the usual de Bruijn manner; when the suffix has length n and equals t, the counter is updated by r←r+g(t), except that any attempt to make r>D moves to ⊤; ⊤ is absorbing. A state is accepting iff its counter component equals 0.

Correctness: By induction on the input length, as long as the run is not in ⊤, the counter equals the true λ of the input read so far. If the run ever enters ⊤, then the true λ>D and, by the bound above, no continuation can bring λ back to 0; rejecting forever is thus correct. Therefore this finite automaton recognizes L.

The case “all cycles have weight ≤0” is symmetric (use a lower absorbing state for λ<−D). Hence, under the given hypothesis, L is regular.

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.
Let M=[0  v  v]M=[0\ \ v\ \ -v], so for every x=(x1,x2,x3)Z3x=(x_1,x_2,x_3)^\top\in\mathbb{Z}^3 we have
Mx=(x2x3)vMx=(x_2-x_3)\,v.
In particular, im(M)=Zv\mathrm{im}(M)=\mathbb{Z}\cdot v and Mx=0Mx=0 iff x2=x3x_2=x_3.

(⇒) Suppose there is a product B1Btv=0B_1\cdots B_t v=0 with each Bi{M,M1,,Mk}B_i\in\{M,M_1,\dots,M_k\}.
Take the rightmost occurrence of MM and write B1Bt=PMQB_1\cdots B_t=P\,M\,Q, where QQ is a product of invertible matrices from {M1,,Mk}\{M_1,\dots,M_k\} and hence invertible.
Let x:=Qvx:=Qv; then Mx=svMx=s v with s:=x2x3Zs:=x_2-x_3\in\mathbb{Z}.
Thus 0=P(Mx)=s(Pv)0=P(Mx)=s\cdot(Pv).
If s=0s=0, then MQv=0MQv=0 and we are done, taking A1A=QA_1\cdots A_\ell=Q.
If s0s\neq 0, then (over Z\mathbb{Z}, which has no zero divisors) Pv=0Pv=0.
This gives a shorter annihilating product.
Repeating the argument finitely many times, we either find a suffix QQ' of invertible matrices with MQv=0MQ'v=0, or we end with a product of only invertible matrices annihilating vv, which is impossible when v0v\neq 0.
(If v=0v=0, both statements are trivially true.)
Hence there exist A1,,A{M1,,Mk}A_1,\dots,A_\ell\in\{M_1,\dots,M_k\} such that MA1Av=0MA_1\cdots A_\ell v=0.

(⇐) Conversely, if such A1,,AA_1,\dots,A_\ell exist, then the product MA1AM A_1\cdots A_\ell (whose factors lie in {M,M1,,Mk}\{M,M_1,\dots,M_k\}) annihilates vv, so the VAP instance has a solution.

Therefore, the VAP for M,M1,,Mk;vM,M_1,\dots,M_k;v has a solution iff there exist A1,,A{M1,,Mk}A_1,\dots,A_\ell\in\{M_1,\dots,M_k\} with MA1Av=0MA_1\cdots A_\ell v=0.

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.
Reduction from 01-MPCP.

Let the 01-MPCP instance be cards (u_i, w_i) over {0,1}, with card 1 fixed as the first card in any solution.

Encoding. Work in base B=3 but map symbols by τ(0)=1, τ(1)=2. For a word a_1...a_m∈{0,1}^*, define
enc(a_1...a_m) := ∑_{j=1}^m τ(a_j)·3^{m-j} ∈ ℕ.
Because no digit 0 appears, enc is injective and concatenation is realized by the affine update
U ↦ 3^{|p|}·U + enc(p).

Matrices. For each card i, with lengths m_i=|u_i| and n_i=|w_i|, and α_i=enc(u_i), β_i=enc(w_i), define the invertible matrix
T_i :=
[ [1,            0,           0],
  [α_i,      3^{m_i},         0],
  [β_i,          0,      3^{n_i}] ]
∈ ℤ^{3×3}.
Let s_0:=(1,0,0)^\top and set the VAP input vector
v := T_1 s_0 = (1, enc(u_1), enc(w_1))^\top.
Let M := [0 v -v] as in part (a), and consider the VAP instance with matrices {M, T_1, …, T_k} and vector v.

Correctness. By part (a), this VAP instance has a solution iff there exist i_2,…,i_t such that
M T_{i_2}\cdots T_{i_t} v = 0.
By construction and induction on t, for any sequence i_2,…,i_t we have
T_{i_2}\cdots T_{i_t} v = (1, enc(u_1 u_{i_2}\cdots u_{i_t}), enc(w_1 w_{i_2}\cdots w_{i_t}))^\top.
Since Mx=(x_2−x_3)·v, the equality M T_{i_2}\cdots T_{i_t} v=0 holds iff
enc(u_1 u_{i_2}\cdots u_{i_t}) = enc(w_1 w_{i_2}\cdots w_{i_t}),
which, by injectivity of enc, holds iff
u_1 u_{i_2}\cdots u_{i_t} = w_1 w_{i_2}\cdots w_{i_t}.
This is exactly the existence of a solution to the 01-MPCP with the first card fixed to be card 1 (the case t=1 allows the solution consisting only of the first card).

Thus we have a many-one reduction from 01-MPCP to VAP. Since 01-MPCP is undecidable, VAP is undecidable.