你如何规范有限状态机?

时间:2021-06-14 04:16:52
  1. How do you find the minimal Deterministic FSM?
  2. 您如何找到最小的确定性FSM?

  3. Is there a way to normalize non-deterministic FSMs?
  4. 有没有办法规范化非确定性FSM?

  5. Is there a linear time bound algorithm to find the minimal FSM for a given machine?
  6. 是否有线性时间限制算法来查找给定机器的最小FSM?

  7. Is there a way to see if two FSMs are equivalent?
  8. 有没有办法看看两个FSM是否相同?

This is not a homework question. I was watching this lecture series and just got curious.

这不是一个家庭作业问题。我正在看这个系列讲座而且很好奇。

4 个解决方案

#1


Some informal answers to give you the ideas, for detailed proofs read a good book on Automata, for example this one or the ones mentioned in the other answers. And I am pretty sure there are online materials you could find answering all of your questions.

一些非正式的答案给你的想法,详细的证据读了一本关于Automata的好书,例如这个或其他答案中提到的那些。而且我很确定您可以找到回答所有问题的在线资料。

  • How do you find the minimal Deterministic FSM?
  • 您如何找到最小的确定性FSM?

The procedure is to eliminate duplicated states (or to merge equivalent states). You know that state and transitions are the keys to generate strings. Basically, duplicated states do not contribute in making the language generated any larger or less. The algorithm starts from final states that always have the ability of generating the lamda (empty string), and recursively update a table which indicate the generating ability of a state, and finally merge those states making no difference.

该过程是消除重复状态(或合并等效状态)。您知道状态和转换是生成字符串的关键。基本上,重复的状态无助于使语言生成更大或更少。该算法从始终具有生成lamda(空字符串)的能力的最终状态开始,并递归地更新指示状态的生成能力的表,并最终合并那些没有区别的状态。

  • Is there a way to normalize non-deterministic FSMs?
  • 有没有办法规范化非确定性FSM?

The normalized DFA for the NFA is using different collections of the states of NFA as DFA's states, for example, {state0} -(1)-> {state1, state2} to remove the non-deterministic part, there is no way to avoid the state explosion as DFA has to do that to represent the language.

NFA的规范化DFA使用不同的NFA状态集合作为DFA的状态,例如,{state0} - (1) - > {state1,state2}来删除非确定性部分,没有办法避免国家爆炸,DFA必须这样做才能代表语言。

  • Is there a linear time bound algorithm to find the minimal FSM for a given machine?
  • 是否有线性时间限制算法来查找给定机器的最小FSM?

I remember the best one is O(NLogN) by doing some tricks of reusing information in some paper by a Western Ontario University Professor, and doubt there exists better ones. I believe the classical one is O(N^2).

我记得最好的一个是O(NLogN)在西安大略大学教授的一些论文中重复使用信息,并怀疑是否存在更好的信息。我相信经典的是O(N ^ 2)。

  • Is there a way to see if two FSMs are equivalent?
  • 有没有办法看看两个FSM是否相同?

Yes. Get the minimal one, code the state by their accessing string (a string that could reach the state from the start state, this is pretty much the real "name" of a state there), and verify the transition map. There might be better ways though, but there would be no big difference on the bigO.

是。获取最小的一个,通过访问字符串来编码状态(一个字符串可以从开始状态到达状态,这几乎就是状态的真实“名称”),并验证转换映射。可能有更好的方法,但bigO上没有太大的区别。

#2


As all nondeterministic FSM have a coresponding deterministic FSM, the answer to to 1 and 2 should be the same.

由于所有非确定性FSM都具有相应的确定性FSM,因此对1和2的答案应该相同。

If you want to know more, get a copy "Introduction to the Theory of Computation" by Michael Sipser, which is a really great book to learn these things. Sipser knows what he talks about and how to communicate it very well.

如果您想了解更多信息,请获取Michael Sipser撰写的“计算理论导论”,这是一本非常好的书,可以学习这些东西。 Sipser知道他谈论什么以及如何很好地沟通。

#3


  • If you are given some deterministic FSM, then you can find an equivalent, minimal one using a quite easy algorithm in O(n2); Hopcroft's algorithm does it in O(n log n). Here you'll find description of both. You can check if A and B are equivalent by minimizing them and checking if they are the same.
  • 如果给你一些确定性的FSM,那么你可以在O(n2)中使用一个非常简单的算法找到一个等价的,最小的FSM; Hopcroft的算法在O(n log n)中完成。在这里你可以找到两者的描述。您可以通过最小化它们并检查它们是否相同来检查A和B是否相同。

  • If you are given some nondeterministic FSM, then finding an equivalent, minimal one is PSPACE-complete. In other words, no good algorithm is known and is conjectured that it doesn't exist. Checking equivalence of two nondeterministic automatas is PSPACE-complete too. So, unless there will be a very improbable breakthrough, you should convert the automaton to a deterministic one (this takes much time) and then perform checks.
  • 如果给你一些不确定的FSM,那么找到一个等价的,最小的是PSPACE-complete。换句话说,没有好的算法是已知的,并且推测它不存在。检查两个非确定性自动机的等价性也是PSPACE完成的。所以,除非有一个非常不可能的突破,你应该将自动机转换为确定性的(这需要很长时间),然后执行检查。

  • You can transform a nondeterministic FSM to a deterministic one with exponential number of states. This is unavoidable. Exercise (not hard!): the language consisting of words in which the n-th letter from the end is "a" can be recognized using a nondeterministic FSM with n states, and it cannot be recognized using a deterministic FSM with less than 2n states. Exponential bound cannot be broken in general case.
  • 您可以将非确定性FSM转换为具有指数状态的确定性FSM。这是不可避免的。练习(不难!):使用具有n个状态的非确定性FSM识别由末尾的第n个字母为“a”的单词组成的语言,并且使用小于2n的确定性FSM无法识别状态。在一般情况下,指数界限不能被破坏。

#4


Check "Basics of Compiler Design" starting at section 2.5. Available for free online. http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/basics_lulu.pdf

从2.5节开始检查“编译器设计基础”。可在线免费使用。 http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/basics_lulu.pdf

It covers converting a NFA to a DFA and minimizing the DFA. NFAs can expand exponentially when converted to DFAs.

它包括将NFA转换为DFA并最小化DFA。当转换为DFA时,NFA可以指数级扩展。

"... any regular language (a language that can be expressed by a regular expression, NFA or DFA) has a unique minimal DFA. Hence, we can decide equivalence of regular expressions (or NFAs or DFAs) by converting both to minimal DFAs and compare the results."

“......任何常规语言(可由正则表达式表示的语言,NFA或DFA)都具有唯一的最小DFA。因此,我们可以通过将两者都转换为最小DFA来确定正则表达式(或NFA或DFA)的等效性并比较结果。“

#1


Some informal answers to give you the ideas, for detailed proofs read a good book on Automata, for example this one or the ones mentioned in the other answers. And I am pretty sure there are online materials you could find answering all of your questions.

一些非正式的答案给你的想法,详细的证据读了一本关于Automata的好书,例如这个或其他答案中提到的那些。而且我很确定您可以找到回答所有问题的在线资料。

  • How do you find the minimal Deterministic FSM?
  • 您如何找到最小的确定性FSM?

The procedure is to eliminate duplicated states (or to merge equivalent states). You know that state and transitions are the keys to generate strings. Basically, duplicated states do not contribute in making the language generated any larger or less. The algorithm starts from final states that always have the ability of generating the lamda (empty string), and recursively update a table which indicate the generating ability of a state, and finally merge those states making no difference.

该过程是消除重复状态(或合并等效状态)。您知道状态和转换是生成字符串的关键。基本上,重复的状态无助于使语言生成更大或更少。该算法从始终具有生成lamda(空字符串)的能力的最终状态开始,并递归地更新指示状态的生成能力的表,并最终合并那些没有区别的状态。

  • Is there a way to normalize non-deterministic FSMs?
  • 有没有办法规范化非确定性FSM?

The normalized DFA for the NFA is using different collections of the states of NFA as DFA's states, for example, {state0} -(1)-> {state1, state2} to remove the non-deterministic part, there is no way to avoid the state explosion as DFA has to do that to represent the language.

NFA的规范化DFA使用不同的NFA状态集合作为DFA的状态,例如,{state0} - (1) - > {state1,state2}来删除非确定性部分,没有办法避免国家爆炸,DFA必须这样做才能代表语言。

  • Is there a linear time bound algorithm to find the minimal FSM for a given machine?
  • 是否有线性时间限制算法来查找给定机器的最小FSM?

I remember the best one is O(NLogN) by doing some tricks of reusing information in some paper by a Western Ontario University Professor, and doubt there exists better ones. I believe the classical one is O(N^2).

我记得最好的一个是O(NLogN)在西安大略大学教授的一些论文中重复使用信息,并怀疑是否存在更好的信息。我相信经典的是O(N ^ 2)。

  • Is there a way to see if two FSMs are equivalent?
  • 有没有办法看看两个FSM是否相同?

Yes. Get the minimal one, code the state by their accessing string (a string that could reach the state from the start state, this is pretty much the real "name" of a state there), and verify the transition map. There might be better ways though, but there would be no big difference on the bigO.

是。获取最小的一个,通过访问字符串来编码状态(一个字符串可以从开始状态到达状态,这几乎就是状态的真实“名称”),并验证转换映射。可能有更好的方法,但bigO上没有太大的区别。

#2


As all nondeterministic FSM have a coresponding deterministic FSM, the answer to to 1 and 2 should be the same.

由于所有非确定性FSM都具有相应的确定性FSM,因此对1和2的答案应该相同。

If you want to know more, get a copy "Introduction to the Theory of Computation" by Michael Sipser, which is a really great book to learn these things. Sipser knows what he talks about and how to communicate it very well.

如果您想了解更多信息,请获取Michael Sipser撰写的“计算理论导论”,这是一本非常好的书,可以学习这些东西。 Sipser知道他谈论什么以及如何很好地沟通。

#3


  • If you are given some deterministic FSM, then you can find an equivalent, minimal one using a quite easy algorithm in O(n2); Hopcroft's algorithm does it in O(n log n). Here you'll find description of both. You can check if A and B are equivalent by minimizing them and checking if they are the same.
  • 如果给你一些确定性的FSM,那么你可以在O(n2)中使用一个非常简单的算法找到一个等价的,最小的FSM; Hopcroft的算法在O(n log n)中完成。在这里你可以找到两者的描述。您可以通过最小化它们并检查它们是否相同来检查A和B是否相同。

  • If you are given some nondeterministic FSM, then finding an equivalent, minimal one is PSPACE-complete. In other words, no good algorithm is known and is conjectured that it doesn't exist. Checking equivalence of two nondeterministic automatas is PSPACE-complete too. So, unless there will be a very improbable breakthrough, you should convert the automaton to a deterministic one (this takes much time) and then perform checks.
  • 如果给你一些不确定的FSM,那么找到一个等价的,最小的是PSPACE-complete。换句话说,没有好的算法是已知的,并且推测它不存在。检查两个非确定性自动机的等价性也是PSPACE完成的。所以,除非有一个非常不可能的突破,你应该将自动机转换为确定性的(这需要很长时间),然后执行检查。

  • You can transform a nondeterministic FSM to a deterministic one with exponential number of states. This is unavoidable. Exercise (not hard!): the language consisting of words in which the n-th letter from the end is "a" can be recognized using a nondeterministic FSM with n states, and it cannot be recognized using a deterministic FSM with less than 2n states. Exponential bound cannot be broken in general case.
  • 您可以将非确定性FSM转换为具有指数状态的确定性FSM。这是不可避免的。练习(不难!):使用具有n个状态的非确定性FSM识别由末尾的第n个字母为“a”的单词组成的语言,并且使用小于2n的确定性FSM无法识别状态。在一般情况下,指数界限不能被破坏。

#4


Check "Basics of Compiler Design" starting at section 2.5. Available for free online. http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/basics_lulu.pdf

从2.5节开始检查“编译器设计基础”。可在线免费使用。 http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/basics_lulu.pdf

It covers converting a NFA to a DFA and minimizing the DFA. NFAs can expand exponentially when converted to DFAs.

它包括将NFA转换为DFA并最小化DFA。当转换为DFA时,NFA可以指数级扩展。

"... any regular language (a language that can be expressed by a regular expression, NFA or DFA) has a unique minimal DFA. Hence, we can decide equivalence of regular expressions (or NFAs or DFAs) by converting both to minimal DFAs and compare the results."

“......任何常规语言(可由正则表达式表示的语言,NFA或DFA)都具有唯一的最小DFA。因此,我们可以通过将两者都转换为最小DFA来确定正则表达式(或NFA或DFA)的等效性并比较结果。“