Lnguges & Automt Dr. Lim Nughton Lnguges A lnguge is sed on n lphet which is finite set of smols such s {, } or {, } or {,..., z}. If Σ is n lphet, string over Σ is finite sequence of letters from Σ, (strings re like words!) e.g. for Σ = {, } the following re ll strings over Σ,,,,,, etc. The empt or null string is denoted Λ. sustring: is sustring of ecuse. Strings hve length e.g. for s = we hve s = 7, Λ =. B Σ we denote the set of ll words over Σ. A lnguge over Σ is suset of Σ. Wh? Emple Let Σ = {, } nd Σ e the set of ll strings over Σ. Then the following re ll lnguges over Σ. L = {,,, } L = {s Σ : s = }. L = {Λ} the empt lnguge! We cn define n opertion (multipliction?) on strings conctention s follows. For s = nd t = st =, ts = Nottion: k = The string conctented together k times, e.g. 4 =.
For n lphet Σ we define Σk = {s Σ : s = k} i.e. the set of strings of length k. For e.g. s = sk we denote k copies of s conctented together e.g. s =. We cn conctente lnguges too! If L nd M re lnguges then LM = {st : s L, t M }, M L = {ts : s L, t M } Emple If L = {pl, send} nd M = {ing, of f } then LM = {pling, plof f, sending, sendof f }. We will write L for the conctention LL of L with itself, L for LLL nd so on. We then hve L = [ Li i= nd + L = [ Li. i= Wht s the difference? Ans: L+ = LL = L L. Most of the lnguges we del with will e infinite so we cn t list ll their strings. We ll descrie them in ws like the following L = {,,, } {}{}. L = {s {, } : N (s) < N (s)}, where e.g. N (s) refers to the numer of occurrences of the letter in the string s. Here L shows how n ritrr string is constructed wheres L shows how to recognize string from the lnguge. Emple Find n emple of lnguges L nd M over {, } such tht (L M ) 6= L M. Solution Let L = {}, M = {} then L M = {, } nd (L M ) = {,, } i.e. the lnguge of ll strings tht cn e constructed using s nd s. L = {} nd M = {} nd L M = {} {} which onl contins strings of repeted s or repeted s, e.g., {} {} ut is not.
Emple List some elements of {, }. How cn ou recognize strings in this lnguge? Solution {Λ,,,,,,...}. This is the lnguge of strings which egin with nd don t contin s sustring. We will e concerned with recognising lnguges. B recognizing the lnguge we men providing method for determining whether or not given string is in the lnguge. This m e done using Finite Automt (Finite Stte Mchine) or Turing Mchine. the lnguges we re concerned with re clled regulr lnguges (more lter). Automt Definition.. A deterministic finite utomton (or finite stte mchine) is n ordered quintuple (Q, Σ, q, δ, A) where Q is finite set of sttes, Σ is finite lphet, q Q is the initil stte, δ is trnsition function, rule which governs wht the mchine does in given stte if it is pssed given input smol/word. A Q is set of ccepting sttes. A finite utomton cn e pictured directed grph clled stte trnsition digrm with nodes representing sttes nd rrows leled letters of the lphet. An rrow from stte q to stte q will e leled to men tht if the mchine is in stte q nd the net smol red is the mchine chnges to stte q. Emple An utomton tht ccepts ll words over {, } ending in. strt In the ove emple Q = {,,, }, q =, Σ = {, }, the ccepting stte is A = {} nd the trnsition function is given:
q δ(q, ) δ(q, ) Emple The DFA elow ccepts the lnguge of ll words over Σ = {, } which end in nd don t contin. strt Λ, N Emple For the DFA elow, descrie the lnguge it recognizes., strt A B C It recognizes the lnguge of ll strings tht do not contin the sustring. Eercises Q. Construct DFA ccepting the lnguge {n : n 6}. Q. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α is divisile }, i.e. ll words where the numer of occurrences of the letter is divisile. Note tht divides so the empt word L. 4
Eercises Q. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α is not divisile }, i.e. ll words where the numer of occurrences of the letter is not divisile. Note tht divides so the empt word / L. Q4. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α does not contin s sustring }. Q5. Construct DFA M such tht L(M ) = { 4k : k N}. 5
Solutions Q. Construct DFA ccepting the lnguge { n : n 6}. strt 6 5 4 Q. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α is divisile }, i.e. ll words where the numer of occurrences of the letter is divisile. Note tht divides so the empt word L. strt Q. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α is not divisile }, i.e. ll words where the numer of occurrences of the letter is not divisile. Note tht divides so the empt word / L. strt 6
Q4. Let Σ = {, }. Construct deterministic finite utomton M ccepting the lnguge L = {α Σ : α does not contin s sustring }. strt, Q5. Construct DFA M such tht L(M) = { 4k : k N}. strt 4 5 8 R 7, 6 7