Download Artificial Intelligence - KBU ComSci by : Somchai

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Top 10 Languages 2015
2
Languages
Symbol a, b, . . .
Alphabet A finite, nonempty set of symbols usually
denoted by 
String - finite sequence of symbols
e.g. abba, b, bb
Empty string denoted by 
*= set of all strings over alphabet
e.g. {a, b}* a, b, aa, ab, . . .}
language - set of strings defined over 
3
Languages
Examples
 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
L= {0, 1, 2, ..., 12, 13, 14, ...}
 ={a, b, c}
L={ab, ac, cabb}
 ={1, 2, +, =}
L1 = {1+1=2}
L2 = {2+2+2+2+2+2=12}
What’s about L3={1+1=2} ? And L4 = { 1+1=3 }
All strings of even length
 ={a, b}
L= {, aa, ab, ba, bb, aaaa, . . .}
All strings of a’s and b’s in equal numbers
L= {, ab, ba, aabb, abab, abba, . . .}
4
Languages
Let ={a,b,c}. The elemnets of * include
Length 0 : 
Length 1 : a, b, c
Length 2 : aa, ab, ac, ba, bb, bc, ca, cb, cc
Length 3 : aaa, aab, aac, aba, abb, abc,
aca, acb, acc, baa, bab, bac, …,
cbc, cca, ccb, ccc
…
In general, if  is an alphabet and L is a subset of *, then L is said to
be a language over .
Example
{0, 11, 001}, {, 10}, and {0, 1}* are subsets of {0, 1}*, and so they are
languages over the alphabet {0, 1}.
5
Languages
The union of two languages L1 and L2, denoted L1L2,
refers to the language that consists of all the strings that are
either in L1 or in L2, that is, to { x | x is in L1 or x is in L2
}.
The intersection of L1 and L2, denoted L1L2, refers to the
language that consists of all the strings that are both in L1
and L2, that is, to { x | x is in L1 and in L2 }.
6
The complementation of a language L over  , or just the L
complementation of L when  is understood, denoted,
refers to the language that consists of all the strings over *
that are not in L, that is, to { x | x is in * but not in L }.
Languages
Example
Consider the languages L1 = {, 0, 1} and L2 = {,
01, 11}.
The union of these languages is
L1  L2 = {, 0, 1, 01, 11},
their intersection is
L1  L2 = {},
and the complementation of L1 is
L1 = {00, 01, 10, 11, 000, 001, . . . }.
7
Languages
The difference of L1 and L2, denoted L1 - L2, refers to the
language that consists of all the strings that are in L1 but not
in L2, that is, { x | x is in L1 but not in L2 }.
Example
If L1 = {, 1, 01, 11} and L2 = {1, 01, 101} then L1 - L2 =
{, 11} and L2 - L1 = {101}.
Try this : L1 = Set of all even number and L2 = Set of all number.
L2 - L1 = ? and L1 = ?
8
Concatenation
Let u,v  *. The concatenation of u and v is
1. If length(v) = 0 then v =  and uv = u
2. If length(u) and length(v) > 0 ,
let u = a1a2…an v = b1b2…bn then
uv = a1a2…anb1b2…bn
The concatenation of X and Y, denoted XY, is
the language XY = {uv| u  X and v Y}
The concatenation of X with itself n times is
Denoted Xn,
X0 is denoted as {}
9
Concatenation
Example
Let u = ab, v = ca, w = bb then
uv = abca
vw = cabb
(uv)w = abcabb u(vw) = abcabb
So that , (uv)w = u(vw)
10
Concatenation
Example
Let X = { a, b, c } and Y = {abb, ba} then
XY = {aabb, babb, cabb, aba, bba, cba}
X0 = {}
X1 = X = {a, b, c}
X2 = XX = {aa, ab, ac, ba, bb, bc, ca, cb, cc}
X3 = X2X = {aaa, aab, aac, aba, abb, abc,
aca, acb, acc, …, ccb, ccc}
11
Try this
Let X = { 011, 110 } ,Y = { ab, bc } , Z = { d }
Find XZY,YZX , ZX2 ,YZ4
Let u = {abcdef} The reversal of u=uR= {fedcba}
Let v = {jklmnop}. Find (uv)R and vRuR
12
Kleen star
Kleen star of set X, denoted X*

X*
=
X
i
and
X 

+
i0
X
i
i 1
X* contains all strings that can be built from the
elements of X.
X+ is the set of nonnull strings built from X.
X  XX
+
13
*
Kleen star
Example
The language L = {a,b}*{bb}{a,b}* consists of the
strings over ={a,b} that contain the substring bb.
Strings that accepted by L = bb, bba, abb, bbb,…
Strings that rejected by L = a,b,aa,ab,ba,aba,...
14
Kleen star
Example
Let L be the language that consists of all strings
over ={a,b} that begin with aa or end with bb.
Thus L = {aa}{a,b}*  {a,b}*{bb}
What’s the different between {a,b}*, {a }*{b }*
and {ab}* ?
15
Try this
Let L be a language over ={a,b} consists
of all even-length strings
Let L be a language over ={a} consists of
even number of a.
16
Regular sets
Let  be an alphabet. The regular sets over 
Arer defined recursively as follows:
i)
Basis: , {} and {a}, for every a, are regular sets
over 
ii) Recursive step: Let X and Y be regular sets over . The
sets
X Y
XY
X*
are regular sets over .
III. Closure: X is a regular set over  only if it can be
obtained from the basis elements by a finite number of
applications of the recusive step.
17
Regular sets
Example
Language L is the set of strings over ={a,b}
that containing the substring bb is a regular set
L = {a,b}*{bb}{a,b}*
From basis : {a} and {b} are regular sets
Apply union and kleen star operation produce {a,b}*,
the set of all strings over {a,b}. By concatenation, {b}{b}
={bb} is regular.
By concatenation {a,b}*{bb} and then concatenation
{a,b}*{bb}{a,b}* is regular sets.
18
Regular sets
Example
Language L is the set of strings over ={a,b} that
Begin and end with a and contain at least one b.
L = {a}{a,b}*{b}{a,b}*{a}
From basis : {a} and {b} are regular sets
Apply union and kleen star operation produce {a,b}*, then
concat {a} and {a,b}* = {a}{a,b}* then
concat {a}{a,b}* and {b} = {a}{a,b}*{b} then
concat {a}{a,b}*{b} and {a,b}* = {a}{a,b}*{b} {a,b}* then
concat {a}{a,b}*{b} {a,b}* and {a} = {a}{a,b}*{b} {a,b}* {a}
is a regular set.
19
Regular expression
Let  be an alphabet. The regular sets over 
Arer defined recursively as follows:
i)
Basis: ,  and a, for every a, are regular expressions over 
ii)
Recursive step: Let u and v be regular expressions over . The
expressions
(u + v)
(uv)
(u*)
are regular expressions over .
III.
Closure: u is a regular expression over  only if it can be
obtained from the basis elements by a finite number of
applications of the recursive step.
20
Regular expression
Example
A regular expression for the set of strings over
={a,b} that contain exactly two b’s. Any number of
a’s may occur before, between, and after b’s.
r = a*ba*ba*
Example
The regular expression for the set of strings over
={a,b,c} containing the substring bc.
r = (a+b+c)*bc(a+b+c)*
21
Regular expression
Example
The regular expression for the set of strings over ={a,b} with
an even number of a’s and an even number of b’s
Strings in this language will have clumps of 3 kinds:
Type 1 — aa
Type 2 — bb
Type 3 — starting with ab (or with ba ) and eventually
balancing with another ab or ba.
So:
( aa+bb+ ((ab+ba)(aa+bb)*(ab+ba)) )*
22
Regular Expression Example
The regular expression R is the string over ={a,b} with an
odd number of a’s.
String in R : a,ab,ba,bab,abbbb,bbbba,bbabbb,…, aaa, ababa,
aabbbba,ababab,abababbb, abbbabbabbb,bbbbabbabbabbb,…
String not in R : ,aa,baa,aab,bbaa,baba,abab,aaaa,…
We can do in 2 cases : a aa or aa a
Case 1 : bbbb…b a bb..abb..abbb.. / bb…b a bbb…b /
bbbb…b a bb..babb..ba / bb…b a abb..ba / bb..b a aa
R = b*a(b + ab*a)*
Case 2 : bb..baa a b..b / b..bab..bab..b a b..b / bb..b a bb..b
R = (b + ab*a)*ab*
So that : R = (b*a(b + ab*a)*) + ((b + ab*a)*ab*)
23
Regular Expression Example
The regular expression R is the string over ={a,b} ending
with b and not containing aa.
String in R : b,ab,bab,abb..b,abab,bb..b, ababb..b, bb..babb..bab
String not in R : ,aa,ba,baa,bbaa,aabb,aba,aaaab,…
So, string must be the combination of b and ab. The two smallest
string are b, ab.
R=
? (b + ab) ,
R = (b + ab)*(b+ab)
24
Try this
The regular expression of the string over
={a,b,c} in which all the a’s precede the b’s
which in turn precede the c’s.
The regular expression of the string over
={0,1} in which the string end with 1 and does not contain
the substring 00.
The regular expression of the string over
={a,b} consists of all odd-length strings
25
Try this
The regular expression of the string over ={a,b,c} in which
all the a’s precede the b’s which in turn precede the c’s, but
without the empty string .
The regular expression of the string over ={a,b,c} that begin
with a, contain exactly two b's, and end with cc.
The regular expression of the string over ={a,b,c} that do
not contain substring aa.
26
Try this
The regular expression of the string over ={a,b} with
an even number of a's or an odd number of b's.
The regular expression of the string over ={a,b,c}
with an even length and contain exactly one a.
The regular expression of the string over ={a,b}
with an odd length and contain exactly two b’s.
27
Related documents