Fundamentele Informatica 1 (I&E) najaar 2015 - - PowerPoint PPT Presentation

fundamentele informatica 1 i e
SMART_READER_LITE
LIVE PREVIEW

Fundamentele Informatica 1 (I&E) najaar 2015 - - PowerPoint PPT Presentation

Fundamentele Informatica 1 (I&E) najaar 2015 http://www.liacs.leidenuniv.nl/~vlietrvan1/fi1ie/ Rudy van Vliet kamer 124 Snellius, tel. 071-527 5777 rvvliet(at)liacs(dot)nl college 2, vrijdag 30 oktober 2015 2.1 Finite Automata: Examples


slide-1
SLIDE 1

Fundamentele Informatica 1 (I&E)

najaar 2015 http://www.liacs.leidenuniv.nl/~vlietrvan1/fi1ie/ Rudy van Vliet kamer 124 Snellius, tel. 071-527 5777 rvvliet(at)liacs(dot)nl college 2, vrijdag 30 oktober 2015 2.1 Finite Automata: Examples and Definitions 2.2 Accepting the Union, Intersection, or Difference

  • f Two Languages

1

slide-2
SLIDE 2
  • reg. languages

FA

  • reg. grammar
  • reg. expression
  • determ. cf. languages

DPDA

  • cf. languages

PDA

  • cf. grammar
  • re. languages

TM

  • unrestr. grammar

2

slide-3
SLIDE 3

Binary representations of 0,1,2,. . . ,10. . .

3

slide-4
SLIDE 4

Binary representations of 0,1,2,. . . ,10. . . Example 2.7. A finite automaton for accepting L4 = {x ∈ {0, 1}∗ | x is binary representation

  • f integer divisible by 3}

4

slide-5
SLIDE 5

Example 2.9. A finite automaton for lexical analysis: accepting strings that consist of one or more consecutive ‘tokens’ in a programming language Possible tokens: identifier ; = if numeric literal

5

slide-6
SLIDE 6

Definition 2.11. A Finite Automaton A finite automaton (FA) is a 5-tuple (Q, Σ, q0, A, δ), where Q is a finite set of states Σ is a finite input alphabet q0 ∈ Q is the initial state A ⊆ Q is the set of accepting states δ : . . . is the transition function

  • Example. . .

6

slide-7
SLIDE 7

Definition 2.11. A Finite Automaton A finite automaton (FA) is a 5-tuple (Q, Σ, q0, A, δ), where Q is a finite set of states Σ is a finite input alphabet q0 ∈ Q is the initial state A ⊆ Q is the set of accepting states δ : Q × Σ → Q is the transition function For any state q of Q and any symbol σ ∈ Σ, we interpret δ(q, σ) as the state to which the FA moves, if it is in state q and receives the input σ.

7

slide-8
SLIDE 8

Definition 2.12. The Extended Transition Function δ∗ Where do we go to from state q, if we receive a string x ∈ Σ∗ as input? Let M = (Q, Σ, q0, A, δ) be a finite automaton. We define the extended transition function δ∗ : Q × Σ∗ → Q as follows:

  • 1. For every q ∈ Q, δ∗(q, Λ) = q
  • 2. For every q ∈ Q, every y ∈ Σ∗, and every σ ∈ Σ,

δ∗(q, yσ) = . . .

8

slide-9
SLIDE 9

Definition 2.12. The Extended Transition Function δ∗ Where do we go to from state q, if we receive a string x ∈ Σ∗ as input? Let M = (Q, Σ, q0, A, δ) be a finite automaton. We define the extended transition function δ∗ : Q × Σ∗ → Q as follows:

  • 1. For every q ∈ Q, δ∗(q, Λ) = q
  • 2. For every q ∈ Q, every y ∈ Σ∗, and every σ ∈ Σ,

δ∗(q, yσ) = δ(δ∗(q, y), σ) Recursive definition

9

slide-10
SLIDE 10

Definition 2.12. The Extended Transition Function δ∗ Where do we go to from state q, if we receive a string x ∈ Σ∗ as input? Let M = (Q, Σ, q0, A, δ) be a finite automaton. We define the extended transition function δ∗ : Q × Σ∗ → Q as follows:

  • 1. For every q ∈ Q, δ∗(q, Λ) = q
  • 2. For every q ∈ Q, every y ∈ Σ∗, and every σ ∈ Σ,

δ∗(q, yσ) = δ(δ∗(q, y), σ)

♣ ✫✪ ✬✩ ✫✪ ✬✩ ✫✪ ✬✩ ✫✪ ✬✩ ✲ ✲ ✲ ✲

p q r s

a b c

δ∗(p, abc) = . . .

10

slide-11
SLIDE 11

Definition 2.13. Acceptance by a Finite Automaton Let M = (Q, Σ, q0, A, δ) be a finite automaton, and let x ∈ Σ∗. The string x is accepted by M if δ∗(q0, x) ∈ A and is rejected by M otherwise. The language accepted by M is the set L(M) = {x ∈ Σ∗ | x is accepted by M} If L is a language over Σ, L is accepted by M if and only if L = L(M). M accepts L and nothing more!

11

slide-12
SLIDE 12

2.2 Accepting the Union, Intersection,

  • r Difference of Two Languages

12

slide-13
SLIDE 13

Example 2.16. Let L1 = {x ∈ {a, b}∗ | aa is not a substring of x} L2 = {x ∈ {a, b}∗ | x ends with ab} FAs for: L1, L2, L1 ∪ L2

13

slide-14
SLIDE 14

Theorem 2.15. Suppose M1 = (Q1, Σ, q1, A1, δ1) and M2 = (Q2, Σ, q2, A2, δ2) are finite automata accepting L1 and L2, respectively. Let M be the FA (Q, Σ, q0, A, δ), where Q = Q1 × Q2 q0 = (q1, q2) and the transition function δ is defined by the formula δ((p, q), σ) = (δ1(p, σ), δ2(q, σ)) for every p ∈ Q1, every q ∈ Q2, and every σ ∈ Σ. Then

  • 1. If A = {(p, q)| p ∈ A1 or q ∈ A2},

M accepts the language L1 ∪ L2.

  • 2. If . . .

M accepts the language L1 ∩ L2.

  • 3. If . . .

M accepts the language L1 − L2.

14

slide-15
SLIDE 15

Theorem 2.15. Suppose M1 = (Q1, Σ, q1, A1, δ1) and M2 = (Q2, Σ, q2, A2, δ2) are finite automata accepting L1 and L2, respectively. Let M be the FA (Q, Σ, q0, A, δ), where Q = Q1 × Q2 q0 = (q1, q2) and the transition function δ is defined by the formula δ((p, q), σ) = (δ1(p, σ), δ2(q, σ)) for every p ∈ Q1, every q ∈ Q2, and every σ ∈ Σ. Then

  • 1. If A = {(p, q)| p ∈ A1 or q ∈ A2},

M accepts the language L1 ∪ L2.

  • 2. If A = {(p, q)| p ∈ A1 and q ∈ A2},

M accepts the language L1 ∩ L2.

  • 3. If A = {(p, q)| p ∈ A1 and q /

∈ A2}, M accepts the language L1 − L2.

15

slide-16
SLIDE 16

Example 2.16. Let L1 = {x ∈ {a, b}∗ | aa is not a substring of x} L2 = {x ∈ {a, b}∗ | x ends with ab} FAs for: L1, L2, L1 ∪ L2, L1 ∩ L2, and L1 − L2 simplification possible

16

slide-17
SLIDE 17

Example 2.18. Let L1 = {x ∈ {a, b}∗ | x contains the substring ab} L2 = {x ∈ {a, b}∗ | x contains the substring bba} FAs for: L1, L2, and L1 ∪ L2 = {x ∈ {a, b}∗ | x contains either ab or bba} (two versions)

17

slide-18
SLIDE 18

Corollary. For every finite language . . .

18

slide-19
SLIDE 19

Corollary. For every finite language L = {x1, x2, . . . , xn} for some n ≥ 0, we can construct an FA accepting L. Proof L = {x1} ∪ {x2} ∪ . . . ∪ {xn}

19