(MIT6.045) Automata, Computability and Complexity - DFA and NFA

The graduation thesis is finished. Find something to do.
Buddhist update.

this is a tell

  • What is calculation?
  • What can be counted?
  • How to calculate efficiently?

courses on philosophical, mathematical, and engineering issues.

mainly include:

  1. Finite Avtomata: Simple model.

  2. Computable theory.

  3. Computational complexity theory: models constrained by time and space complexity.

The (mathematical) proofs covered in this course will mainly illustrate the idea of ​​a proof.

It is more important to explain the idea clearly than to write a bunch of details (it is not a mathematical analysis class

Deterministic Finite Avtomata

A simple example: calculate whether there is an odd number of 1s or an even number of 1s in a string of all 1s.
insert image description here
The state machine starts from q 0 q_0q0start. Given a string (limited length) of 111...111, read one character (1) each time, and perform state transition according to the transition rules of the state at this time until the end of reading.

Detailed explanation of DFA:
insert image description here

There is an entry (initial state) and a string. When the character meets the condition, it needs to transition from state A to state B. There are terminal states (represented by concentric circles).

If starting from the initial state, the state follows the order of the characters in the string and the state transition logic to transform, and finally stops at the termination state (concentric circle state), it means that DFA accepts the string, otherwise, DFA rejects the string.

A more formal definition is as follows:
insert image description here
A DFA is defined as a quintuple. State set, character set Σ \SigmaΣ (such as {0, 1}, English alphabet, UTF-8), start state, end state set, state transition function.

Language: Language is 2 Σ 2^\Sigma2A subset of Σ . For example,Σ \SigmaΣ is the English alphabet, and language L can be all words starting with a in English, or all words containing sh*t.

In other words, a language is a function that takes a string as input and outputs 0 or 1.

L(M) = language defined by a deterministic finite state machine M.
insert image description here
Note that ∗ → q 0 * \rightarrow q_0q0, means: q 0 q_0q0is an initial state and a terminal state.

We can also extend the state transition function of DFA, and recursively define the "extended" state transition function when the input is a string:
insert image description here

Proofs for Finite Automata:
insert image description here
What does this automaton say? (In other words, which grammars match the above automata?)
How to prove that the grammar we got is correct?

The automaton above matches strings that have an odd number of 0s and end with a 1.

Proof:
q 0 q_0q0State: There are even number of 0
q 1 q_1q1Status: There are an odd number of 0, and the end is 0
q 2 q_2q2Status: There are an odd number of 0s and the end is 1

The rest can be solved by mathematical induction.

Definition: A language L' is regular if L' can be described by DFA. That is, there exists M such that: L' = L(M).

Union Theorem of Regular Languages:
Given two regular languages ​​L i , i = 1 , 2 L_i, i=1,2Li,i=1,2 L 1 ∪ L 2 = w ∣ w ∈ L i , i = 1 ∣ ∣ i = 2 L_1 \cup L_2 = {w| w \in L_i, i=1 || i=2 } L1L2=wwLi,i=1∣∣i=2 .
Then,L 1 ∪ L 2 L_1 \cup L_2L1L2Also regular.

Proof idea: mainly consider the parallel operation of two DFAs. For a regular language L i L_iLi, we consider the corresponding DFA, denoted as M i M_iMi. Consider M i M_i separatelyMiThe state of Q i Q_iQi, as Cartesian product Q 1 × Q 2 Q_1 \times Q_2Q1×Q2. Then construct the transition rules that meet the two DFAs.

The Intersection Theorem of Regular Languages:
Given two regular languages ​​L i , i = 1 , 2 L_i, i=1,2Li,i=1,2 L 1 ∩ L 2 = w ∣ w ∈ L i , i = 1 & & i = 2 L_1 \cap L_2 = {w| w \in L_i, i=1 \&\& i=2 } L1L2=wwLi,i=1&&i=2 .
Then,L 1 ∩ L 2 L_1 \cap L_2L1L2Also regular.

Proof idea: still consider the parallel operation of two DFAs.

Complementation Theorem:
Given a regular language LLLL c L^cLC is also a regular language.
Proof: Just flip the terminal set and non-terminal set over.

Language inversion LRL^RLR. _ For example:0 , 10 , 110 , 0101 R = 0 , 01 , 011 , 1010 {0, 10, 110, 0101}^R = {0, 01, 011, 1010}0,10,110,0101R=0,01,011,1010

Inversion theorems for regular languages.
An inverted regular language is also a regular language. For every DFA-readable language that can be read from right to left, there is a corresponding DFA-readable language that can be read from left to right.
But how to prove it?
We wish: Given a DFA MMM , the corresponding regular language isLLL , able to construct aMRM^RMR , such thatMRM^RMR acceptsw R w^RwR if and only ifMMM acceptswww

A simple try: invert all arrows and set states of M. But in this way of operation, there will be problems:

M R M^R MR is not always a DFA.

For example, there may be many initial states, and for a given state and input, there may be multiple (or none) transition rules.

So we introduce:

Non-Deterministic Finite Avtomata

First, we consider a DFA:
insert image description here
the DFA MMM accepts strings containing 001.

We consider MRM^RMR

insert image description here

In the new automaton shown above, for a string, if there is a path that allows the state to reach the final state, then we consider the logic to be accepted.

Another type of NFA: ϵ \epsilonϵ -NFA. Hereϵ \epsilonϵpath means empty hop, which can transfer state without accepting characters.
insert image description here
For example: in the case of multiple starting states, it can be expressed as follows:
insert image description here

The state transition function in NFA δ ( q , char ) \delta(q, char)d ( q ,c ha r ) may return a collection of states. Of course, this set may also be an empty set.

For DFAs:

  1. When the state and input are given, the transfer function value of DFA is deterministic (Deterministic).
  2. A DFA accepts a string if and only if this string will take the DFA to an end state.

For NFAs:

  1. For a given string, NFA may choose one of many different paths.
  2. An NFA accepts strings if and only if this string "may" lead the NFA to an end state.

In DFA, the expanded state transition function δ ^ ( state , string ) \hat \delta(state, string)d^(state,s t r in g ) can eat the next string.

In NFA, such operations can also be defined. If NFA has initial state qqq , then the stringxxx is grammatical if and only ifδ ^ ( q , x ) ∩ F ≠ ∅ \hat \delta(q, x) \cap F \neq \varnothingd^(q,x)F= . Among them, F is the terminal state set.

Recursive definition of NFA:
insert image description here

Definition of the set of states in NFA. Suppose PPP is a state set, then
δ ( P , a ) = ∪ q ∈ P δ ( q , a ) \delta (P, a) = \cup_{q \in P} \delta (q, a)d ( P ,a)=qPd ( q ,a)

An example of an NFA:
insert image description here

Given the string str = 10101, how does the above NFA perform?

  • F = q 2 F = q_2 F=q2
  • δ^(q0,10101) = q0,q2\hat\delta(q_0,10101) = {q_0,q_2}d^(q0,10101)=q0,q2
  • q 0 , q 2 ∩ F = q 2 {q_0, q_2} \cap F = {q_2} q0,q2F=q2
    The string 10101 then conforms to the above NFA.

In general, NFA is more convenient to use than DFA.
insert image description here
Are NFA and DFA equivalent?
Yes.

Theorem: For any NFA NNN , there exists a DFAMMM such thatL ( M ) = L ( N ) L(M)=L(N)L(M)=L ( N )

Specific ideas: For NFA, we can directly construct DFA by constructing the power set of the state set.

おすすめ

転載: blog.csdn.net/weixin_43466027/article/details/130586818