简体   繁体   English

为定义在 Σ = {0, 1} 上的以下语言构建 NFA。 D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)}

[英]Construct a NFA for the following language defined over Σ = {0, 1}. D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)}

Need help solving the below question:需要帮助解决以下问题:

Construct a NFA for the following language defined over Σ = {0, 1}.为定义在 Σ = {0, 1} 上的以下语言构建 NFA。

D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)} D = {0^n 10^m10^q |n, m, q ∈ N, q ≡ nm (mod 5)}

I am confused on how to create the NFA factoring in the q part of the language.我对如何在语言的 q 部分创建 NFA 分解感到困惑。

We can use five states to remember the value of n mod 5:我们可以使用五种状态来记住 n mod 5 的值:

        _______________0______________
       /                              \
       |                              |
       V                              |
----->q0--0-->q1--0-->q2--0-->q3--0-->q4

Now we need to read the 1:现在我们需要阅读1:

        _______________0______________
       /                              \
       |                              |
       V                              |
----->q0--0-->q1--0-->q2--0-->q3--0-->q4
       |       |       |       |       |
       1       1       1       1       1
       |       |       |       |       |
       V       V       V       V       V
      q0'     q1'     q2'     q3'     q4'

Now we can look at each case individually.现在我们可以单独查看每个案例。 For q0', we know we saw a number of 0s in the first section that is congruent to 0 mod 5. Thus, nm = 0 (mod 5) is already known.对于 q0',我们知道我们在第一部分看到了许多与 0 mod 5 一致的 0。因此,nm = 0 (mod 5) 是已知的。 We can accept any number of 0s, then a 1, and then accept if we have no further input: we can make q0' do this:我们可以接受任意数量的 0,然后是 1,如果我们没有进一步的输入,则接受:我们可以让 q0' 这样做:

     _0_
    /   \
    |   |
    \   /
----->q0'--1-->qA

For q1', we will have q = nm (mod 5) = m (mod 5) since n = 1 (mod 5) in this case.对于 q1',我们将有 q = nm (mod 5) = m (mod 5),因为在这种情况下 n = 1 (mod 5)。 We can accomplish this by remembering the current value so far of m (mod 5) and then looking for that many 0s in q.我们可以通过记住 m (mod 5) 到目前为止的当前值然后在 q 中查找那么多 0 来实现这一点。 That is, q1' can be replaced with:也就是说,q1' 可以替换为:

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q1'--0-->q1''--0-->q1'''--0-->q1''''--0-->q1'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA<--0--qA'<--0--qA''<--0--qA'''<--0--qA''''

qA is the same accepting state we introduced previously. qA 与我们之前介绍的接受状态相同。 For q2', we can keep track of the current value of nm (mod 5) which is 2m (mod 5):对于 q2',我们可以跟踪 nm (mod 5) 的当前值,即 2m (mod 5):

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q2'--0-->q2''--0-->q2'''--0-->q2''''--0-->q2'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA''     qA''''     qA'         qA'''

The states qA', qA'', qA''' and qA'''' are the same as introduced before, but notice the order is different now: this reflects the fact that 2 x 0 = 0 (as before), 2 x 1 = 2 (not 1), 2 x 2 = 4 (not 2), etc.状态 qA'、qA''、qA''' 和 qA'''' 与之前介绍的相同,但请注意现在的顺序不同:这反映了 2 x 0 = 0(如前)、2 的事实x 1 = 2(不是 1)、2 x 2 = 4(不是 2)等。

We can do the same thing for q3' and q4':我们可以对 q3' 和 q4' 做同样的事情:

        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q3'--0-->q3''--0-->q3'''--0-->q3''''--0-->q3'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA'''    qA'        qA''''      qA''


        _______________0________________________
       /                                        \
       |                                        |
       V                                        |
----->q4'--0-->q4''--0-->q4'''--0-->q4''''--0-->q4'''''
       |        |        |          |           |
       1        1        1          1           1
       |        |        |          |           |
       V        V        V          V           V
       qA      qA''''   qA'''      qA''        qA'

Putting all of these various DFAs together into one huge DFA is guaranteed to give you a DFA that will work.将所有这些不同的 DFA 放在一个巨大的 DFA 中,可以保证为您提供一个有效的 DFA。 Whether there is a substantially similar NFA, I cannot say for certain.是否存在实质上相似的NFA,我不能肯定。 This DFA has states:该 DFA 声明:

  1. q0, q0': 2 states q0, q0': 2 个状态
  2. q1, q1', …., q1''''': 6 states q1, q1', ...., q1''''': 6 个状态
  3. q2, q2', …., q2''''': 6 states q2, q2', ...., q2''''': 6 个状态
  4. q3, q3', …., q3''''': 6 states q3, q3', ...., q3''''': 6 个状态
  5. q4, q4', …., q4''''': 6 states q4, q4', ...., q4''''': 6 个状态
  6. qA, qA', …., qA'''': 5 states qA, qA', ...., qA'''': 5 个状态

This is a total of 32 states.这总共是32个州。 If you wanted to attempt minimization you might be able to knock a few of those off.如果您想尝试最小化,您可能可以取消其中的一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 L = {a^na^nb^m |m, n ≥ 0} 是规则语言还是不规则语言? - Is L = {a^n a^n b^m |m, n ≥ 0} a regular or irregular language? pda 接受语言 L={a^nb^m | n <m}< div><div id="text_translate"><p> 我知道如何解决 m&lt;n,但我很难理解 m&gt;n 的逻辑。</p><p> 在 m&lt;n 中,我们将所有 a 压入堆栈,当我们得到 b 时,我们弹出一个 a,当输入以包含 mn a 的堆栈结束时,机器应该进入最终的 state</p><p> 我该怎么办 m&gt;n.... </p></div></m}<> - pda to accept the language L={a^n b^m | n<m} L1 = {a ^ n b ^ n | n <4}且L2 = {a ^ n b ^ n | n <10 ^ 10 ^ 10},常规语言? - Are L1 = {a^n b^n | n < 4 } and L2 = {a^n b^n | n < 10^10^10 }, regular languages? 为什么是 {a^nb^n | n &lt;= 10} 常规? - Why is {a^nb^n | n <= 10} regular? 什么是语言a ^ mb ^ n的PDA(下推式自动机),其中n &lt;m - What would be the PDA (pushdown automata) of the language a^mb^n where n<m O(n + log(m)) 可以简化吗? - Can O(n + log(m)) be simplified? 语言A = {0 ^ n 1 ^ n 0 ^ n}是否上下文无关? - Is the language A = {0^n 1^n 0^n} context free? 是a ^ n,其中n&gt; 1000是常规语言吗? - Is a^n, where n>1000 a regular language? 是语言{0 ^ n 1 ^ n 0 ^ k | k!= n}上下文免费? - Is the language {0^n 1^n 0^k | k != n} context free? 是n log n = O(n)且是n log n = Omega(n) - Is n log n = O(n) and is n log n = Omega(n)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM