[英]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 声明:
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.