jon

Oct 2, 2009 - A transition function δ ∈ Q x Σ → P(Q); .... A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa, a gas, an oil, a ...
4MB taille 15 téléchargements 311 vues
Introduction à l’Informatique Théorique Jonathan Grattage www.grattage.co.uk/jon

1 Friday, October 2, 2009

Outline Recap Examples of Finite Automata Regular Languages Finite Automata and Regular Languages Pigeonhole principle The Pumping Lemma Palindromes 2 Friday, October 2, 2009

Deterministic Finite Automata (automate fini déterministe) A Deterministic Finite Automaton (DFA) A = (Q, Σ, δ, q0, F) is given by: A finite set of states Q; A finite set of input symbols Σ; A transition function δ ∈ Q x Σ → Q; An initial state q0 ∈ Q; A set of accepting states F ⊆ Q.

3 Friday, October 2, 2009

Deterministic Finite Automata Extended Transition Function ^ ∈ Q × Σ* → Q δ ^ ε)! =!q! δ(q, ^ xw)!=!δ( ^ δ(q, x), w) δ(q,

4 Friday, October 2, 2009

Nondeterministic FA (automate fini non-déterministe) A Nondeterministic Finite Automaton (NFA) A = (Q, Σ, δ, S, F) is given by: A finite set of states Q; A finite set of input symbols Σ; A transition function δ ∈ Q x Σ → P(Q); A set of initial states S ⊆ Q; A set of accepting states F ⊆ Q.

5 Friday, October 2, 2009

Nondeterministic FA Extended Transition Function

^ ∈ P(Q) × Σ* → P(Q) δ ^ ε)! =!S δ(S, ^ xw)!=!δ( ^ U{ δ(q, x) | q ∈ S}, w) δ(S,

6 Friday, October 2, 2009

Machine à Café FA Draw a FA for a vending machine: Vends a tea or coffee for 1€ (2 final states) Accepts 20c, 50c & 1€ coins Has a return coins (RC) button Doesn’t give change 7 Friday, October 2, 2009

Exercises Σ = {0,1,2}. Construct a DFA A which precisely recognises those words which only contain decreasing sequences of digits, i.e. the 01,02 or 12 should not occur. Σ = {a,b,c}. Construct an NFA B where either the last symbol is b or the one before the last is a. More formally: L (B) = { wb | w ∈ Σ* } ∪ { wax | w ∈ Σ*, x ∈ Σ } 8 Friday, October 2, 2009

Regular Expressions (Expression rationnelle)

Given an alphabet Σ (e.g. Σ = {a,b,c, . . . ,z}), the syntax (or form) of regular expressions over Σ is defined inductively: ∅ is a regular expression. ε is a regular expression. For each x ∈ Σ, x is a regular expression. ... 9 Friday, October 2, 2009

Regular Expressions (Expression rationnelle) Continued... Concatenation: If E and F are regular expressions then EF is a regular expression. Union: If E and F are regular expressions then E + F is a regular expression (E or F, sometimes E|F). Kleene Star: If E is a regular expression then E* is a regular expression. Parenthesis: If E is a regular expression then (E) is a regular expression. 10 Friday, October 2, 2009

Meaning of Regular Expressions (inductive) For a RE(E) over Σ we assign a language L(E): L( ∅ ) = ∅ = {}

L( E* ) = L( E )*

L( ε ) = {ε}

L( (E) ) = L( E )

L(x) = {x}, (x ∈ Σ)

L(E+F) = L(E) U L(F)

L( EF ) = { wv | w ∈ L(E), v ∈ L(F) }

11 Friday, October 2, 2009

Regular Expressions Exercises For Σ = {a, b, c} define the following languages: Words which do contain a b (at least). Words which do not contain a b. Words where all as appear before all the cs. Words where the number of as plus the number of bs is odd. Words which contain the sequence aa. Words which do not contain the sequence aa. 12 Friday, October 2, 2009

Regular languages and Finite automata NFA RE Constructions given on board ... Exercises: Construct the NFA N( (ab+ba)*c* ), where Σ = {a,b,c} Draw a DFA of NFA N using the subset construction Convert your vending machine into a RE 13 Friday, October 2, 2009

Pigeonhole principle (Principe des tiroirs)

There does not exist an injective function on finite sets whose codomain is smaller than its domain Although apparently trivial and obvious, it can be used to demonstrate (possibly) unexpected results (eg. 2 people in Paris have the same number of hairs) 14 Friday, October 2, 2009

The Pumping Lemma (Lemme de l'étoile) 2. |xy| ≤n Let L be a regular language 3. for all k ∈ N we have xy k z ∈ L.

Then there exists an integer n ≥ 1 depending Forthat a regular language L there only onProof: L such every string w in exists L of a DFA A s.t. L us assume that A has got n states. Now if A accepts a word w w length at least n can be written as w = xyz must have visited a state q twice: Such that: |y| ≥ 1 |xy| ≤ n

Friday, October 2, 2009

y

x

q

z

We choose q s.t. it is the first cycle, hence |xy| ≤ n. We also k i for i ≥ (otherwise 0, xy z ∈there L is no cycle). nonall empty Now, consider what happens if we feed a word of the form automaton, i.e. s instead of y it contains an arbitrary number of 15 y, including the case i = 0, i.e. y is just left out. The automaton

Palindromes A man, a plan, a canal: Panama! amanaPlana c analpanama {wwR | w ∈ Σ*} (even length) All palindromes?

16 Friday, October 2, 2009

Palindromes A man, a plan, a canal: Panama! A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama! {wwR | w ∈ Σ* } (even length)

17 Friday, October 2, 2009

Palindromes A man, a plan, a canal: Panama! A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal – Panama!

18 Friday, October 2, 2009

Palindromes A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa, a gas, an oil, a bird, a yell, a vat, a caw, a pax, a wag, a tax, a nay, a ram, a cap, a yam, a gay, a tsar, a wall, a car, a luger, a ward, a bin, a woman, a vassal, a wolf, a tuna, a nit, a pall, a fret, a watt, a bay, a daub, a tan, a cab, a datum, a gall, a hat, a fag, a zap, a say, a jaw, a lay, a wet, a gallop, a tug, a trot, a trap, a tram, a torr, a caper, a top, a tonk, a toll, a ball, a fair, a sax, a minim, a tenor, a bass, a passer, a capital, a rut, an amen, a ted, a cabal, a tang, a sun, an ass, a maw, a sag, a jam, a dam, a sub, a salt, an axon, a sail, an ad, a wadi, a radian, a room, a rood, a rip, a tad, a pariah, a revel, a reel, a reed, a pool, a plug, a pin, a peek, a parabola, a dog, a pat, a cud, a nu, a fan, a pal, a rum, a nod, an eta, a lag, an eel, a batik, a mug, a mot, a nap, a maxim, a mood, a leek, a grub, a gob, a gel, a drab, a citadel, a total, a cedar, a tap, a gag, a rat, a manor, a bar, a gal, a cola, a pap, a yaw, a tab, a raj, a gab, a nag, a pagan, a bag, a jar, a bat, a way, a papa, a local, a gar, a baron, a mat, a rag, a gap, a tar, a decal, a tot, a led, a tic, a bard, a leg, a bog, a burg, a keel, a doom, a mix, a map, an atom, a gum, a kit, a baleen, a gala, a ten, a don, a mural, a pan, a faun, a ducat, a pagoda, a lob, a rap, a keep, a nip, a gulp, a loop, a deer, a leer, a lever, a hair, a pad, a tapir, a door, a moor, an aid, a raid, a wad, an alias, an ox, an atlas, a bus, a madam, a jag, a saw, a mass, an anus, a gnat, a lab, a cadet, an em, a natural, a tip, a caress, a pass, a baronet, a minimax, a sari, a fall, a ballot, a knot, a pot, a rep, a carrot, a mart, a part, a tort, a gut, a poll, a gateway, a law, a jay, a sap, a zag, a fat, a hall, a gamut, a dab, a can, a tabu, a day, a batt, a waterfall, a patina, a nut, a flow, a lass, a van, a mow, a nib, a draw, a regular, a call, a war, a stay, a gam, a yap, a cam, a ray, an ax, a tag, a wax, a paw, a cat, a valley, a drib, a lion, a saga, a plat, a catnip, a pooh, a rail, a calamus, a dairyman, a bater, a canal – Panama! 19 Friday, October 2, 2009

Exercises Show that the following languages are not regular: Σ = {a,b,c}: L = { anbmcn+m | m,n ∈ Nat } (eg. aabbbccccc ∈ L1, but aabbcc isn’t)

Σ = {0, 1}: L = { ww | w ∈ Σ* } (repetitions)

Σ = {a..z}: L ={ wwR | w ∈ Σ* } (even length palindromes)

20 Friday, October 2, 2009