跳到主要内容

京都大学 情報学研究科 知能情報学専攻 2024年8月実施 専門科目 S-5

Author

itsuitsuki

Description

大学公表の原題

Consider deterministic finite state automata (Q,Σ,δ,q0,F)(Q, \Sigma, \delta, q_0, F), where QQ is a finite set of states, Σ\Sigma is a finite set of characters, δ:Q×ΣQ\delta : Q \times \Sigma \to Q is a transition function, q0Qq_0 \in Q is a start state, and FQF \subseteq Q is a set of accept states. Also, ϵΣ\epsilon \in \Sigma^* denotes the empty string. Let Σ={0,1,2,,9}\Sigma = \{0, 1, 2, \dots, 9\}. For wΣw \in \Sigma^*, n(w)n(w) returns an integer number represented by ww. For example, n(52)=52n(52) = 52 and n(068)=68n(068) = 68. For ϵ\epsilon, we define n(ϵ)=0n(\epsilon) = 0.

(1) Depict the state transition diagram of a deterministic finite state automaton (Q2)(|Q| \leq 2) that accepts L1={wΣn(w)0(mod2)}L_1 = \{w \in \Sigma^* \mid n(w) \equiv 0 \pmod 2\}.

(2) Depict the state transition diagram of a deterministic finite state automaton (Q3)(|Q| \leq 3) that accepts L2={wΣn(w)0(mod3)}L_2 = \{w \in \Sigma^* \mid n(w) \equiv 0 \pmod 3\}.

(3) Show Q,δQ, \delta, and FF of a deterministic finite state automaton that accepts L3={wΣn(w)0(modk)}L_3 = \{w \in \Sigma^* \mid n(w) \equiv 0 \pmod k\} for any k2k \geq 2. You may use mod to describe δ\delta.

(4) Let L4={wΣ+h(w)0 or w=0}L_4 = \{w \in \Sigma^+ \mid h(w) \neq 0 \text{ or } w = 0\}, where h(w)h(w) returns the first character of string ww. Show Q,δQ, \delta, and FF of a deterministic finite state automaton that accepts L3L4L_3 \cap L_4 for any k2k \geq 2. You may use mod to describe δ\delta.

题目描述

考虑确定性有限自动机 (Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F),其中 QQ 是有限状态集,Σ\Sigma 是有限字符集,δ:Q×ΣQ\delta:Q\times\Sigma\to Q 是转移函数,q0Qq_0\in Q 是初始状态,FQF\subseteq Q 是接受状态集;ϵΣ\epsilon\in\Sigma^* 表示空串。

Σ={0,1,2,,9}\Sigma=\{0,1,2,\ldots,9\}。对 wΣw\in\Sigma^*n(w)n(w) 表示字符串 ww 所代表的十进制整数,允许前导零,例如 n(52)=52n(52)=52n(068)=68n(068)=68,并规定 n(ϵ)=0n(\epsilon)=0

  1. 画出一个状态数满足 Q2|Q|\leq2、接受语言

    L1={wΣn(w)0(mod2)}L_1=\{w\in\Sigma^*\mid n(w)\equiv0\pmod2\}

    的确定性有限自动机状态转移图。

  2. 画出一个状态数满足 Q3|Q|\leq3、接受语言

    L2={wΣn(w)0(mod3)}L_2=\{w\in\Sigma^*\mid n(w)\equiv0\pmod3\}

    的确定性有限自动机状态转移图。

  3. 对任意 k2k\geq2,给出接受

    L3={wΣn(w)0(modk)}L_3=\{w\in\Sigma^*\mid n(w)\equiv0\pmod k\}

    的确定性有限自动机的 Q,δ,FQ,\delta,F;描述 δ\delta 时可以使用取模运算。

  4. 定义

    L4={wΣ+h(w)0 或 w=0},L_4=\{w\in\Sigma^+\mid h(w)\ne0\ \text{或}\ w=0\},

    其中 h(w)h(w) 返回字符串 ww 的首字符。对任意 k2k\geq2,给出接受 L3L4L_3\cap L_4 的确定性有限自动机的 Q,δ,FQ,\delta,F;描述 δ\delta 时可以使用取模运算。

Kai

(1)

Use states r0,r1r_0,r_1 for the remainder modulo 22. The start state r0r_0 is accepting, including the empty string. Reading an even digit leads to r0r_0 from either state; reading an odd digit leads to r1r_1.

DFA for divisibility by 2

(2)

Use states r0,r1,r2r_0,r_1,r_2 for the remainder modulo 33, starting and accepting at r0r_0. Since 101(mod3)10\equiv1\pmod3, a digit with remainder dd changes state rir_i to r(i+d)mod3r_{(i+d)\bmod3}.

DFA for divisibility by 3

The edge labels are A={0,3,6,9}A=\{0,3,6,9\}, B={1,4,7}B=\{1,4,7\}, and C={2,5,8}C=\{2,5,8\}.

(3)

Let

Q={r0,,rk1},q0=r0,F={r0},δ(ri,d)=r(10i+d)modk.Q=\{r_0,\ldots,r_{k-1}\},\quad q_0=r_0,\quad F=\{r_0\}, \qquad\delta(r_i,d)=r_{(10i+d)\bmod k}.

Induction on the number of read digits shows that the current index is n(w)modkn(w)\bmod k, proving the recognized language is L3L_3.

(4)

Add three states s,z,s,z,\bot distinct from all remainder states:

Q={s,z,}{r0,,rk1},q0=s,F={z,r0}.Q=\{s,z,\bot\}\cup\{r_0,\ldots,r_{k-1}\}, \qquad q_0=s,\qquad F=\{z,r_0\}.

Here ss is the initial state, zz means the complete prefix is the single character 0, and \bot is a rejecting sink. Define

δ(s,0)=z,δ(s,d)=rdmodk(d=1,,9),δ(z,d)=(d=0,,9),δ(,d)=(d=0,,9),δ(ri,d)=r(10i+d)modk(d=0,,9).\begin{aligned} \delta(s,0)&=z,\\ \delta(s,d)&=r_{d\bmod k} &&(d=1,\ldots,9),\\ \delta(z,d)&=\bot &&(d=0,\ldots,9),\\ \delta(\bot,d)&=\bot &&(d=0,\ldots,9),\\ \delta(r_i,d)&=r_{(10i+d)\bmod k} &&(d=0,\ldots,9). \end{aligned}

The empty word ends at rejecting ss, the single zero ends at accepting zz, and any longer word starting with zero reaches \bot. A word starting with a nonzero digit is accepted precisely when its value is divisible by kk. Hence the language is L3L4L_3\cap L_4.