Automaty a Gramatiky

Automaty a Gramatiky

Regular Expressions (RegE) Definition (Regular Expression (RegE), value of a RegE L(α)) Regular expressions α, β ∈ RegE(Σ) over a finite non–empty alphabet Σ = {x1, x2,..., xn} and their value L(α) is defined by induction: expression α for value L(α) ≡ [α] λ empty string L(λ) = {λ} Basis: ∅ empty expression L(∅) = {} ≡ ∅ a a ∈ Σ L(a) = {a}. Induction: expression value remark α + β L(α + β) = L(α) ∪ L(β) αβ L(αβ) = L(α)L(β) . may be used α∗ L(α∗) = L(α)∗ (α) L((α)) = L(α) brackets do not change the value. The class of regular expressions over Σ: RegE(Σ) is the smallest class closed under operations above. Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 1 / 32 Examples, Precedence Example (Regular Expressions) The language of alternating 0’s and 1’s may be written: either (01)∗ + (10)∗ + 1(01)∗ + 0(10)∗ or (λ + 1)(01)∗(λ + 0). ∗ ∗ ∗ ∗ ∗ ∗ The language L((0 10 10 1) 0 ) = {w|w ∈ {0, 1} , |w|1 = 3k, k ≥ 0}. Definition (Precedence) The star ∗is the operator with highest precedence, then concatenation ., the lowest precedence has the union +. Theorem (RegE and DFA) Any language recognizable by a DFA can be expressed by a regular expression. Any language of a regular expression can be recognized by a λ-NFA (therefore also a DFA). Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 2 / 32 From DFA to Regular Expressions Compare to Kleene Theorem. (k+1) (k) (k) (k) ∗ (k) Rij = Rij + Ri(k+1)(R(k+1)(k+1)) R(k+1)j (n) Finally, RegE = ⊕j∈FA R1j union over accepting states j. Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 3 / 32 From Regular Expression to an λ–NFA automaton From Regular Expression to an λ–NFA automaton By structural induction on R. In each Basis: step, we construct an λ-NFA E recog- nizing the language L(R) = L(E) with λ empty string λ additional properties: Exactly one accepting state. empty set ∅ No edges into the initial state. a No edges from the accepting state. a single letter a ∈ Σ a λ λ Union R + S: R λ λ INDUCTION: S λ Concatenation RS: R S λ ∗ λ λ Closure R : R λ Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 4 / 32 Converting Among Representations Converting NFA to DFA λ−NFA NFA λ closure in O(n3). Search O(n) n states multiplied by n2 O(n32n) arcs for λ transitions. O(n) 3 n Subset construction, DFA O(n 2 ) O(n) with possibly 2n states. For 3 each state, O(n ) time to RE DFA compute transitions. O(n34n) Converting DFA to NFA Just modify transition table by putting set-brackets around states and adding column for λ in the case of λ−NFA. Automaton to Regular Expression Conversion O(n34n) (see construction in Section 3.2.1) RE to Automaton Conversion λ−NFA in the time O(n). Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 5 / 32 Automata with the output Definition (Moore machine) Moore machine is a sixtuple A = (Q, Σ, Y , δ, µ, q0) consisting of Q non–empty set of states Σ finite nonempty set of symbols (input alphabet) Y finite nonempty set of symbols (output alphabet) δ a mapping Q × Σ → Q (transition function) µ a mapping Q → Y (output function) q0 ∈ Q (initial state) the output function may imitate final states F ⊆ Q may be replaced by output function µ : Q → {0, 1} as follows: µ(q) = 0 if q ∈/ F , µ(q) = 1 if q ∈ F . Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 6 / 32 Moore Machine Example Stav/výstup A B 00:00 15:00 00:15 15:00 30:00 15:15 15:15 30:15 15:30 00:15 15:15 00:30 30:00 40:00 30:15 30:15 40:15 30:30 Example (Tennis Game Score) 30:30 40:30 30:40 A machine calculates the tenis score. 15:30 30:30 15:40 00:30 15:30 00:40 Input alphabet: ID of the player 40:00 A 40:15 who scored a point 40:15 A 40:30 40:30 A deuce Output alphabet & states: the score 30:40 deuce B ( Q = Y and µ(q) = q) 15:40 30:40 B 00:40 15:00 B deuce A:40 40:B A:40 A deuce 40:B deuce B A 15:00 00:15 B 15:00 00:15 Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 7 / 32 Mealy machine Definition (Mealy machine) Mealy machine is a six–tuple A = (Q, Σ, Y , δ, λM , q0) consisting of: Q non–empty set of states Σ finite nonempty set of symbols (input alphabet) Y finte nonempty set of symbols (output alphabet) δ a mapping Q × Σ → Q (transition function) µ a mapping Q × Σ → Y (output function) q0 ∈ Q (initial state) The output is determined by a state and the input symbol Mealy machine is more general then Moore The output function may be replaced as follows ∀x ∈ Σ λM (q, x) = µ(q) or ∀x ∈ Σ λM (q, x) = µ(δ(q, x)) Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 8 / 32 Mealy Machine Example Example (Mealy Machine) The automaton for integer division of the input by 8 (the reminder is discarded). Three bit move to the left we need to remember last three bits three–bit dynamic memory. State\symbol 0 1 0/0 1/1 →000 000/0 001/0 1/0 1/0 1/0 001 010/0 011/0 000 001 011 111 010 100/0 101/0 0/0 0/0 1/1 0/1 011 110/0 111/0 1/0 100 000/1 001/1 1/1 010 101 110 1/1 101 010/1 011/1 0/1 0/1 0/0 110 100/1 101/1 0/1 111 110/1 111/1 100 After three steps calculates properly non–regarding the initial state. Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 9 / 32 Extended Output Function for any word in the input alphabet Σ∗ → we get a word in the output alphabet Y ∗ Moore machine a b c d output function µ : Q → Y µ∗ : Q × Σ∗ → Y ∗ y µ∗(q, λ) = λ (někdy µ∗(q, λ) = q) x u u v µ∗(q, wx) = µ∗(q, w).µ(δ∗(q, wx)) Example: µ∗(00:00,AABA)=(00:00 .) 15:00 . 30:00 . 30:15 . 40:15 Mealy machine output function λM : Q × Σ → Y a b c d ∗ ∗ ∗ λM : Q × Σ → Y ∗ λM (q, λ) = λ ∗ ∗ ∗ λM (q, wx) = λM (q, w).λM (δ (q, w), x) ∗ x y u u Example: λM (000,1101010)=0001101 Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 10 / 32 Lemma (Moore and Mealy Machines Reductions) For any Moore machine there exists a Mealy machine mapping each input word to the same output word. For any Mealy machine there exists a Moore machine mapping each input word to the same output word. Proof. a/x b/y q ⇒ Mealy machine B = (Q, Σ, Y , δ, λM , q0) where λM (q, x) = µ(δ(q, x)) ⇐ We define states of the Moore machine Q × Y , δ|([q, y] , x) = [δ(q, x), λ(q, x)]), µ([q, y]) = y. a b q/x q/y Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 11 / 32 Further Generalisation Finite automaton makes following actions: read a symbol changes its state moves its reading head to the right The head is not allowed to move to the left. What happens, if we allow the head to move left and right? The automaton does not write anything on the tape! Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 12 / 32 Two way finite automata Definition (Two way finite automata) Two way deterministic finite automaton is a five–tuple A = (Q, Σ, δ, q0, F ), where Q is a finite set of states, Σ is a finite set of input symbols transition function δ is a mapping Q × Σ → Q × {−1, 0, 1} extended by head transitions q0 ∈ Q initial state a set of accepting states F ⊆ Q. We may represent it by a graph or a table. Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 13 / 32 Two–way DFA computation Definition (Two–way DFA computation) A string w is accepted by the two–way DFA, iff: computation started in the initial state at the left–most symbol of w the first transition from w to the right was in an accepting state the computation is not defined outside the word w (computation ends without accepting w). We may add special end–symbols # ∈/ Σ to any word If L(A) = {#w#|w ∈ L ⊆ Σ∗} is regular, then also L is regular R ∗ L = ∂#∂#(L(A) ∩ #Σ #) Automata and Grammars Regular Expressions, Moore and Mealy Machine, 2 way FA 5 March 23, 2017 14 / 32 Two–way automaton example Example (Two–way automaton example) Let A = (Q, Σ, δ, q1, F ).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    32 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us