languages and finite automata - al al-bayt university...languages fall 2019 2 language: a set of...

30
Fall 2019 1 Languages

Upload: others

Post on 04-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 1

Languages

Page 2: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Languages

Fall 2019 2

Language: a set of strings

String: a sequence of symbols

from some alphabet

Example:

Strings: cat, dog, house

Language: {cat, dog, house}

zcba ,,,, Alphabet:

Page 3: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Languages are used to describe computation problems

Fall 2019 3

},17,13,11,7,5,3,2{ PRIMES

},6,4,2,0{ EVEN

}9,,2,1,0{ Alphabet:

Page 4: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Alphabets and Strings

Fall 2019 4

abbaw

bbbaaav

abu

ba,

baaabbbaaba

abba

ab

aExample Strings

Example Alphabet:

An alphabet is a set of symbols

A string is a sequence of

symbols from the alphabet

Page 5: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Examples

Fall 2019 5

}9,,2,1,0{ Decimal numbers alphabet

102345 567463386

}1,0{Binary numbers alphabet

100010001 101101111

Page 6: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

More Examples

Fall 2019 6

}1{Unary numbers alphabet

1Unary number:

Decimal number: 1

11

2

111

3

1111

4

11111

5

Unary numbers alphabet - 0 }0{

Unary number – 0 0, 00, 000, 000 …0

Page 7: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 7

String Operations

m

n

bbbv

aaaw

21

21

bbbaaa

abba

mn bbbaaawv 2121

Concatenation

abbabbbaaa

Page 8: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

String Operations - reverse

Fall 2019 8

12aaaw nR

naaaw 21 ababaaabbbReverse

bbbaaababa

رفعت فما حطت لهم رتب **** طلبوا الذي نالوا فما حرموا

حرموا فما نالوا الذي طلبوا **** رتب لهم حطت فما رفعت

Page 9: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 9

String Length

Length:

Examples:

naaaw 21

nw

1

2

4

a

aa

abba

?

?

?

aabbaabb

aba

Page 10: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 10

Length of Concatenation

Example:

vuuv

853

8

5,

3,

vuuv

aababaabuv

vabaabv

uaabu

Page 11: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 11

Empty String

A string with no letters is denoted:

Observations:

or

abbabaababbaabba

www

0

Page 12: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 12

Substring

Substring of string:

a subsequence of consecutive characters

String Substring

bbab

b

abba

ab

abbab

abbab

abbab

abbab

Page 13: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 13

Prefix and Suffix

Prefixes Suffixesabbab

abbab

abba

abb

ab

a

b

ab

bab

bbab

abbab uvw

prefix

suffix

Page 14: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 14

Another Operation

Example:

Definition:

n

n wwww

abbaabbaabba 2

0w

0abba

Page 15: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 15

The * Operation

: the set of all possible strings from

alphabet

*

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

Page 16: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 16

The + Operation

: the set of all possible strings from

alphabet except

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

*

,,,,,,,, aabaaabbbaabaaba

Page 17: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 17

Languages

A language over alphabet

is any subset of

Examples:*

,,,,,,,,*

,

aaabbbaabaaba

ba

},,,,,{

,,

aaaaaaabaababaabba

aabaaa

Language:

Language:

Language:

Page 18: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 18

More Language Examples

An infinite language }0:{ nbaL nn

aaaaabbbbb

aabb

ab

L

Labb

},{ baAlphabet

Laaaabb?

Page 19: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 19

prime} is and :{ * xxxPRIMES

}9,,2,1,0{

},17,13,11,7,5,3,2{ PRIMES

Prime numbers

Alphabet

Language:

Page 20: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 20

even} is and :{ * xxxEVEN

}9,,2,1,0{

Even and odd numbers

Alphabet

odd} is and :{ * xxxODD

},6,4,2,0{ EVEN

},7,5,3,1{ ODD

Page 21: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 21

Unary Addition

},,1{

}n

,1z,1y,1x :{ mn

km

zyxADDITION k

ADDITION 1111111111

ADDITION 111111111

Alphabet:

Language:

Page 22: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 22

Squares

}#,1{

},1y,1x :#{ 2mn nmyxSQUARES

SQUARES1111#11

SQUARES1111#111

Alphabet:

Language:

Page 23: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 23

Note that:

}{}{

0}{

1}{

0

Sets

Set size

Set size

String length

CORRECTION

Page 24: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 24

Operations on Languages

The usual set operations

Complement:

aaaaaabbbaaaaaba

ababbbaaaaaba

aaaabbabaabbbaaaaaba

,,,,

}{,,,

},,,{,,,

LL *

,,,,,,, aaabbabaabbaa

Page 25: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 25

Reverse

Definition:

Examples:

}:{ LwwL RR

ababbaabababaaababR

,,,,

}0:{

}0:{

nabL

nbaL

nnR

nn

Page 26: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 26

Concatenation

Definition:

Example:

2121 ,: LyLxxyLL

baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

Page 27: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 27

Another Operation

Definition:

Special case:

n

n LLLL

bbbbbababbaaabbabaaabaaa

babababa

,,,,,,,

,,,,3

0

0

,, aaabbaa

L

Page 28: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 28

}0:{ nbaL nn

}0,:{2 mnbabaL mmnn

2Laabbaaabbb

Page 29: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 29

Star-Closure (Kleene *)

All strings that can be constructed from

Definition:

Example:

210* LLLL

,,,,

,,,,

,,

,

*,

abbbbabbaaabbaaa

bbbbbbaabbaa

bbabba

L

Page 30: Languages and Finite Automata - Al al-Bayt University...Languages Fall 2019 2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat, dog,

Fall 2019 30

Positive Closure

Definition: 21 LLL

,,,,

,,,,

,,

,

abbbbabbaaabbaaa

bbbbbbaabbaa

bba

bba

Same with but without the *L