• Nem Talált Eredményt

LászlóKabódi Languagesandautomata

N/A
N/A
Protected

Academic year: 2022

Ossza meg "LászlóKabódi Languagesandautomata"

Copied!
13
0
0

Teljes szövegt

(1)

Languages and automata

László Kabódi

(2)

Example

I L4 ={ww|w ∈ {0,1}} I L5 ={1n2}

(3)

Solution IV

I L4 ={ww|w ∈ {0,1}} I Let x=0p10p1

I Because |uv| ≤p,u andv can only contain 0.

I If we pump v with k >1, the rst half of x will be dierent from the second, so it won't be ww. Souvkw ∈/ L4

I L4 cannot be a regular language.

(4)

Solution V

I L5 ={1n2} I Let x=1p2

I |v| ≥1 and |uv| ≤p, so 1≤ |v| ≤p.

I |uvw|=p2. The next square number is (p+1)2. But if we usek =2 then

uv2w

can not be(p+1)2, but it is more than p2, so it is not a square number. uv2w ∈/ L5

I L5 cannot be a regular language.

(5)

How to use the pumping lemma

To show that a languageLis not regular, you have to I for a chosen word x∈L

I check for all possiblex =uvw partitions, where |uv| ≤p and

|v| ≥1

I that there is at least onek touvkw ∈/L

But if a language is pumpable, it does not mean that it is regular.

(6)

Denition

Grammar

A grammarG is:

I an alphabet (a,b, . . . ,∈Σ, terminals, do not change) I non-terminals or variables (V, they can change during a

deduction)

I starting variable or starting non-terminal (S) I deduction or production or substitution rules

I αβ

I αandβ are strings of terminals and/or non-terminals I αcontain at least one element fromV

I αV)VV) I βV)

I derivation: using the substitution rules

I L(G): all the words that can be derived using the substitutions rules from the starting symbol

(7)

Examples

Examples I

What languages these grammars dene?

I Grammar I:

S →0S1 S →01 I Grammar II:

S →AB A→0A A→0 B →B1 B →1

(8)

Examples

Solutions I

I Grammar I:

S →0S1|01

L1 ={0n1n|n >0} I Grammar II:

S →AB A→0A|0 B →B1|1

L2 ={0i1j|i,j >0}

(9)

Examples

Example II

What language this grammar denes?

S →aSBC|abC CB →BC bB →bb bC →bc cC →cc

(10)

Examples

Solution II

I S →aSBC|abC,CB →BC,bB→bb,bC →bc,cC →cc I L={anbncn|n >0}

I Not every derivation can be nished:

S →aS BC →aaS BCBC →aaabC BCBC → aaabcBCBC →aaabcBBCC

I But:

S →aS BC →aaS BCBC →aaabCBCBC → aaabBC CBC →aaabBCBCC →aaabBBCCC → aaabbBCCC →aaabbbC CC →aaabbbcC C → aaabbbccC →aaabbbccc

(11)

Examples

Examples III

1. Construct a grammar for palindromes! (Σ ={a,b})

2. Construct a grammar for a language where the number of as and the number of bs are the same!

3. Is there a grammar for all languages that contain nite number of words?

4. Is there a grammar for every language?

5. Construct a grammar for even length words!

6. Construct a grammar for the correct parentheses!

7. Construct a grammar for L={akbncm |n=k+m}

(12)

Examples

Solutions III

1. Construct a grammar for palindromes! (Σ ={a,b}) S →aSa|bSb|a|b|ε

2. Construct a grammar for a language where the number of as and the number of bs are the same!

S →aSbS|bSaS|ε

3. Is there a grammar for all languages that contain nite number of words?

Yes, there is. You can create a rule for all words.

4. Is there a grammar for every language?

No, the number of languages are greater than the number of possible grammars.

(13)

Examples

Solutions III

5. Construct a grammar for even length words!

S →SS|aa|ab|ba|bb|ε

6. Construct a grammar for the correct parentheses!

S →SS|(S)|ε

7. Construct a grammar for L={akbncm |n=k+m} S →S1S2

S1 →aS1b|ε S2 →bS2c|ε

Hivatkozások

KAPCSOLÓDÓ DOKUMENTUMOK

He proved that there are probabilistic languages (p-languages) that are not generated by any probabilistic finite state grammar (PFSG) even though their support (the set of strings

If the Turing machine have a time complexity f (n) then it stops in nite steps fot all inputs4. So it

Give a deterministic finite automaton that accepts the words that contain an even number of zeros, while the number of ones is divisible by three.. Give a deterministic finite

The grammar should be unambiguous and should confirm to the usual order of execution of operations (that is, without parentheses exponentation has precedence, and for example in case

I check is the input consists of word pairs, if not stop and reject I otherwise it tries all the 1 element index lists then 2 element. index lists and

We only nish a derivation with a deduction rule created form an accepting

I If L 1 is regular, there is a nite automaton M 1 for it I Create ε transitions from the accepting states to the

Let m be the number of non-terminals in the grammar and let d be the length of the longest right side from all the rules.. If the word is at least |x| ≥ p long, then there is at