You are on page 1of 25

Khoa HTTT - i hc

CNTT 1
Bi 6: Ngn ng tn t
Khoa HTTT - i hc CNTT 2
Ni dung
1. Gii thiu
2. C php
3. Cc nh ngha
4. Din gii ca mt cng thc
5. Quy tc lng gi cng thc
6. Ngn ng tn t c bin l n b
7. Ngn ng tn t c bin l min gi tr
Khoa HTTT - i hc CNTT 3
1. Gii thiu
Ngn ng tn t l ngn ng truy vn hnh thc do Codd
ngh (1972-1973) c Lacroit, Proix v Ullman pht
trin, ci t trong mt s ngn ng nh QBE, ALPHA..
c im:
Ngn ng phi th tc
Rt trch ci g ch khng phi rt trch nh th no
Kh nng din t tng ng vi i s quan h
C hai loi:
C bin l n b
C bin l min gi tr
Khoa HTTT - i hc CNTT 4
2. C php
( ) : biu thc trong ngoc
Bin: dng ch thng cui b k t: x,y,z,t,s
Hng: dng ch thng u b k t: a,b,c,
Hm: l mt nh x t mt min gi tr vo tp hp gm 2
gi tr: ng hoc sai. Thng dng ch thng gia b
k t: h,g,f,
Tn t: l mt biu thc c xy dng da trn biu thc
logic. Dng ch in hoa gia b k t P,Q,R
Cc php ton logic: ph nh (), ko theo (), v (.),
hoc (v).
Cc lng t: vi mi (), tn ti (-)
Khoa HTTT - i hc CNTT 5
3. Cc nh ngha (1)
nh ngha 1: Tn t 1 ngi
Tn t 1 ngi c nh ngha trn tp X v bin x c gi tr
chy trn cc phn t ca X.
Vi mi gi tr ca x, tn t P(x) l mt mnh logic, tc l n
c gi tr ng () hoc sai (S)
V d
P(x), x l bin chy trn X, l mt tn t
P(gt), gteX l mt mnh , X = {Nguyen Van A, Tran Thi B}
Vi tn t N(x) c xc nh: x l ngi n. Khi
Mnh N(Nguyen Van A): cho kt qu Sai
N(Tran Thi B): cho kt qu ng
Khoa HTTT - i hc CNTT 6
3. Cc nh ngha (2)
nh ngha 2: Tn t n ngi
Tn t n ngi c nh ngha trn cc tp X
1
, X
2
, , X
n
v
n bin x
1
, x
2
, , x
n
ly gi tr trn cc tp X
i
tng ng.
Vi mi gi tr a
i
eX
i
, x
i
=a
i
.Tn t n ngi l mt mnh .
K hiu: P(x
1
, x
2
, , x
n
)
V d: CHA(x
1
,x
2
): x
1
l CHA ca x
2

Ch :
Cc X
i
khng nht thit phi l ri nhau
Vi x
i
=a
i
, P(x
1
, x
2
, , a
i
, , x
n
) l tn t n-1 ngi
Khoa HTTT - i hc CNTT 7
3. Cc nh ngha (3)
nh ngha 3: T
T l mt hng hay l mt bin
Nu f(t
1
, t
2
, , t
n
) l hm n ngi th f l mt t
nh ngha 4: Cng thc
Cng thc nguyn t: P(t
1
, t
2
, , t
n
), t
i
l cc t
Nu F
1
, F
2
l cc cng thc th cc biu thc sau cng l cc
cng thc: F
1
vF
2
, F
1
.F
2
, F
1
=>F
2
, F
1
Nu F
1
l mt cng thc th :F
1
, -x:F
1
cng l cc cng thc
Nu F
1
l cng thc th (F
1
) cng l mt cng thc
Khoa HTTT - i hc CNTT 8
3. Cc nh ngha (4)
nh ngha 4:
Cng thc ng l cng thc nu mi bin u c km
vi lng t. (khng nh , S)
Cng thc m l cng thc tn ti 1 bin khng km
lng t. (tm kim thng tin)
V d:
C
1
:x-ty(P(x,y,a) -z(Q(y,z,t).R(x,t)) l cng thc
ng v cc bin x,y,z,t u c km lng t ,-
C
2
:x -t (P(x,y,a) -z(Q(y,z,t).R(x,t)) l cng thc m
v bin y khng c lng t ,-
Khoa HTTT - i hc CNTT 9
4. Din gii ca mt cng thc
Gm 4 phn:
Min gi tr ca cc bin ca cng thc (k
hiu l tp M)
S dng cc hng, cc tn t ( ngha tn t,
xc nh c quan h n ngi)
ngha ca cng thc
Xc nh 1 quan h n ngi trn tp M
n
Khoa HTTT - i hc CNTT 10
5. Quy tc lng gi cng thc
Lng gi tn t: xt tn t bc n: P(x
1
,x
2
,x
n
) v lin
kt vi quan h R, n ngi.
P(a
1
,a
2
,,a
n
): (a
1
,a
2
,,a
n
) eR
P(a
1
,a
2
,,a
n
): S (a
1
,a
2
,,a
n
) eR
Cc php ton .,v,, dng bng chn tr
Lng t -: gi x l bin. Cng thc -x F(x) l ng
khi c t nht mt a
i
eM/F(a
i
):
M={a
1
,a
2
,,a
n
} vF(a
i
), a
i
eM
Lng t : x l bin, x F(x): vi a
i
eM/F(a
i
):
M={a
1
,a
2
,,a
n
} .F(a
i
), a
i
eM
Khoa HTTT - i hc CNTT 11
6. Ngn ng tn t c bin l n b
6.1 Qui tc
6.2 nh ngha
6.3 Cng thc an ton
6.4 Biu din cc php ton
Khoa HTTT - i hc CNTT 12
6.1 Quy tc (1)
1. Bin l 1 b ca quan h
2. T: hng, bin hoc biu thc c dng s[C], s:
bin, C: tp cc thuc tnh ca quan h c gi
l t chiu.
3. Cng thc:
Rs (R l quan h, s l bin) c gi l t. Min gi tr
s nh ngha min bin thin ca s.
t
1
u a , t
1
u t
2
y t
1
,t
2
l cc t chiu, cn a l mt
hng, u l ton t so snh dc gi l cng thc
nguyn t
Khoa HTTT - i hc CNTT 13
6.1 Quy tc (2)
4. Mt cng thc nguyn t l mt cng thc
5. F
1
v F
2
l cng thc: F
1
vF
2
, F
1
.F
2
,
F
1
F
2
, F
1
l cng thc
6. F l cng thc , s l bin -sF, sF l cng
thc
7. F l cng thc, (F) l cng thc
Khoa HTTT - i hc CNTT 14
6.2 nh ngha
Mt cu hi trong ngn ng tn t c bin l
n b c biu din nh sau: {s | F} . Trong
s l bin n b, F l mt cng thc ch c
mt bin t do l s.
V d: BIENGIOI(nuoc,tinhtp). Php ton
quan h BIENGIOI[nuoc] c chuyn
thnh cu hi trong ngn ng tn t c bin
l b: {s[nuoc] BIENGIOI s}
Khoa HTTT - i hc CNTT 15
F l cng thc an ton: nu n tho mn 3 iu kin sau:
i) Nu s l b n tha: F(s) l ng th mi thnh phn ca s
l phn t ca DOM(F):


ii) F l cng thc con ca F:


iii)
6.3 Cng thc an ton
) ( ) : ( F DOM s ng
s
F e
) ' ( : ' , ' F DOM s ng
s
F
s
sF e -
) ' ( : ' , ' F DOM s ng
s
F
s
sF e
Khoa HTTT - i hc CNTT 16
6.4 Biu din cc php ton (1)
1. Php hi
Q
1
,Q
2
l cc quan h n chiu
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
Q
2
F
s
=F
1s
vF
2s
2. Php tr
Q
1
,Q
2
l cc quan h n chiu
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
-Q
2
F
s
=F
1
.F
2s
Khoa HTTT - i hc CNTT 17
6.4 Biu din cc php ton (2)
3. Php tch
Q
1
(x
1
,,x
m
), Q
2
(y
1
,,y
n
)
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
x Q
2
F
s
: s(x
1
,,x
m
,

y
1
,,y
n
)
F
s
=(-v) (- p) (F
1v
. F
2p
.
s
1
=v
1
. s
m
=v
m
. s
m+1
=p
1
. s
m+n
=p
n
)


Khoa HTTT - i hc CNTT 18
6.4 Biu din cc php ton (3)
4. Php chiu
Q
1
(x
1
,,x
n
), F
1
l cc cng thc ng vi Q
1
Cng thc ca Q= Q
1
[x
i1
, x
i2
,,x
ik
]

F
s
=(-v) (F
1v
. s
1
=v
i1
.s
2
=v
i2
. s
k
=v
ik
)
5. Php chn
Q
1
l quan h n chiu, F
1
l cng thc ng vi Q
1
Cng thc Q=Q
1
:iu kin K (K:x
i
ux
j
hoc x
i
ua)
F
s
=F
1s
. s
i
u

s
j
hoc F
1s
. s
i
u

a

(1si, j s n, i=j)
Khoa HTTT - i hc CNTT 19
7. Ngn ng tn t c bin l min gi
tr
7.1 Quy tc
7.2 Biu din cu hi
7.3 Cng thc an ton
7.4 Biu din cc php ton
Khoa HTTT - i hc CNTT 20
7.1 Quy tc
1. T: l hng hoc bin
2. Cng thc nguyn t
Q(t
1
,t
2
,,t
n
): t
i
l cc t, Q l quan h
t
i
u t
j
,t
i
u a vi t
i
l t, a l mt hng, u l php ton
3. Mt cng thc nguyn t l mt cng thc
4. F
1
v F
2
l cng thc: F
1
vF
2
, F
1
.F
2
, F
1
F
2
, F
1
l
cng thc
5. F l cng thc , t:bin t do, -sF,sF cng cng thc
6. F l cng thc, (F) l cng thc
Khoa HTTT - i hc CNTT 21
7.2 Biu din cu hi
{(x
1
,x
2
,,x
n
) | F(x
1
,x
2
,,x
n
)}
x
i
l cc bin t do ca F
Q= {(x
1
,x
2
,,x
n
) | F(x
1
,x
2
,,x
n
)} nn
(x
1
,x
2
,,x
n
)eQ F(x
1
,x
2
,,x
n
):ng
Khoa HTTT - i hc CNTT 22
F l cng thc an ton: nu n tho mn 3 iu kin sau:
i) Nu s l b n tha: F(s) l ng th mi thnh phn ca s
l phn t ca DOM(F):


ii) F l cng thc con ca F:


iii)
7.3 Cng thc an ton
n i F DOM
i
x ng
n
x x F ,..., 1 , ) ( ) : ) ,...,
1
( ( = e
) ' ( : ' F DOM x ng xF e -
) ' ( : ' F DOM x ng xF e -
n i F DOM
i
x ng
n
x x F ,..., 1 , ) ( ) : ) ,...,
1
( ( = e -
Khoa HTTT - i hc CNTT 23
7.4 Biu din cc php ton (1)
1. Php hi
Q
1
,Q
2
l cc quan h n chiu
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
Q
2
F=F
1
vF
2
2. Php tr
Q
1
,Q
2
l cc quan h n chiu
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
-Q
2
F=F
1
.F
2
Khoa HTTT - i hc CNTT 24
7.4 Biu din cc php ton (2)
3. Php tch
Q
1
(x
1
,,x
m
), Q
2
(y
1
,,y
n
)
F
1
, F
2
l cc cng thc ng vi Q
1
, Q
2
Cng thc ca Q= Q
1
x Q
2
F(x
1
,,x
m
,

y
1
,,y
n
) =F
1
(x
1
,,x
m
).F
2
(y
1
,,y
n
)
Khoa HTTT - i hc CNTT 25
7.4 Biu din cc php ton (3)
4. Php chiu
Q
1
(x
1
,,x
n
), F
1
(x
1
,,x
n
) l cc cng thc ng vi Q
1
Cng thc ca Q= Q
1
[x
i1
, x
i2
,,x
ik
]

F
s
(x
i1
, x
i2
,,x
ik
)= (-x
ji
)(-x
jz
)(-x
jn-k
)(F
1
(x
1
,,x
n
))
trong (x
i1
, x
i2
,,x
ik
)(x
j1
, x
j2
,,x
jn-k
)=(x
1
, x
2
,,x
n
)
5. Php chn
Q
1
(x
1
,,x
n
), F
1
(x
1
,,x
n
) l cc cng thc ng vi Q
1
Cng thc Q=Q
1
:iu kin K (K:x
i
ux
j
hoc x
i
ua)
F
1
(x
1
,,x
n
)

= F
1
(x
1
,,x
n
) . x
i
u

x
j
hoc
= F
1
(x
1
,,x
n
)

. x
i
u

a