Logic Aspects of Databases teacher: doc. RNDr. Stanislav Kraj ci, - - PowerPoint PPT Presentation

logic aspects of databases
SMART_READER_LITE
LIVE PREVIEW

Logic Aspects of Databases teacher: doc. RNDr. Stanislav Kraj ci, - - PowerPoint PPT Presentation

Pavol Jozef Saf arik University in Ko sice Faculty of Science Supportive textbooks in course Logic Aspects of Databases teacher: doc. RNDr. Stanislav Kraj ci, PhD. study programme: Informatics Project 2005/NP1-051 11230100466


slide-1
SLIDE 1

Pavol Jozef ˇ Saf´ arik University in Koˇ sice Faculty of Science Supportive textbooks in course

Logic Aspects of Databases

teacher: doc. RNDr. Stanislav Krajˇ ci, PhD. study programme: Informatics Project 2005/NP1-051 11230100466

Stanislav Krajˇ ci Logic Aspects of Databases

slide-2
SLIDE 2

Administrative information

◮ assessment: examination ◮ duration: 2 hours per week, 26 hours per study ◮ final examination: written test ◮ course objective: to acquire information connecting logic and

the databases theory

◮ course content: first order logic, database, relational algebra

Stanislav Krajˇ ci Logic Aspects of Databases

slide-3
SLIDE 3

Recommended reading

◮ S. Abiteboul, R. Hull, V. Vian: Foundations of Databases,

Addison-Wesley Publishing Company, 1995, ISBN 0-201-53771-0

Stanislav Krajˇ ci Logic Aspects of Databases

slide-4
SLIDE 4

1 LOGIC PRELIMINARIES

Stanislav Krajˇ ci Logic Aspects of Databases

slide-5
SLIDE 5

Basic logic symbols

◮ UCnn = {¬

¬ ¬} – unary connectives

◮ BCnn = {∧

∧ ∧,∨ ∨ ∨,→ → →,↔ ↔ ↔,↑ ↑ ↑,↓ ↓ ↓,⊕ ⊕ ⊕} – binary connectives

◮ Cnn = UCnn ∪ BCnn – connectives ◮ Qua = {∀

∀ ∀,∃ ∃ ∃} – quantifiers

◮ Aux = {(

( (,) ) ),, , ,} – auxiliary symbols

◮ BLS = Cnn ∪ Qua ∪ Aux – basic logic symbols

Stanislav Krajˇ ci Logic Aspects of Databases

slide-6
SLIDE 6

Typed first order logic 1/2

◮ sets of special symbols

◮ DatL – data types ◮ VarL – variables ◮ ConL – constant symbols ◮ FunL – function symbols ◮ PreL – predicate symbols

◮ all these sets are disjoint and disjoint of BLS

Stanislav Krajˇ ci Logic Aspects of Databases

slide-7
SLIDE 7

Typed first order logic 2/2

◮ L = DatL, typVarL, typConL, sigFunL, sigPreL – typed first

  • rder logic

◮ typVarL : VarL → DatL – variable types ◮ typConL : ConL → DatL – constant symbol types ◮ sigFunL : FunL →

n∈N+ Datn L × DatL – function symbol

signatures

◮ sigPreL : PreL →

n∈N+ Datn L – predicate symbol signatures

◮ all often written without the index L

Stanislav Krajˇ ci Logic Aspects of Databases

slide-8
SLIDE 8

Terms

◮ TrmL (or shortly Trm) – the least set fulfilling the following

conditions:

1a VarL ⊆ TrmL and typ(v) = typVar(v) for each v ∈ VarL, 1b ConL ⊆ TrmL and typ(c) = typCon(c) for each c ∈ ConL 2 if f ∈ FunL s.t. sigFun(f ) = D1, . . . , Dn, D and for all i ∈ {1, . . . , n}, ti ∈ TrmL s.t. typ(ti) = Di then t = f ( ( (t1, , , . . ., , ,tn) ) ) ∈ TrmL and typ(t) = D

◮ L-terms (or shortly terms) – elements of TrmL

Stanislav Krajˇ ci Logic Aspects of Databases

slide-9
SLIDE 9

Formulae

◮ FrmL (or shortly Frm) – the least set fulfilling the following

conditions:

1 if p ∈ PreL s.t. sigPre(p) = D1, . . . , Dn and for all i ∈ {1, . . . , n}, ti ∈ TrmL s.t. typ(ti) = Di then p( ( (t1, , , . . ., , ,tn) ) ) ∈ FrmL (so-called atomic formulae or atoms) 2a if ψ ∈ FrmL then ( ( (¬ ¬ ¬ψ) ) ) ∈ FrmL 2b if ψ1, ψ2 ∈ FrmL and @ ∈ BCnn then ( ( (ψ1@ψ2) ) ) ∈ FrmL 2c if ψ ∈ FrmL, # ∈ Qua and v ∈ VarL then ( ( (( ( (#v) ) )ψ) ) ) ∈ FrmL

◮ L-formulae (or shortly formulae) – elements of FrmL

Stanislav Krajˇ ci Logic Aspects of Databases

slide-10
SLIDE 10

Constant symbols in terms

◮ define function ConTrm : Trm → P(Con) in the following

way:

1a if t = v ∈ Var then ConTrm(t) = ∅ 1b if t = c ∈ Fun then ConTrm(t) = {c} 2 if t = f ( ( (t1, , , . . ., , ,tn) ) ) then ConTrm(t) =

i∈{1,...,n} ConTrm(ti)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-11
SLIDE 11

Variables in terms

◮ define function VarTrm : Trm → P(Var) in the following

way:

1a if t = v ∈ Var then VarTrm(t) = {v} 1b if t = c ∈ Fun then VarTrm(t) = ∅ 2 if t = f ( ( (t1, , , . . ., , ,tn) ) ) then VarTrm(t) =

i∈{1,...,n} VarTrm(ti)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-12
SLIDE 12

Free and bounded variables in formulae

◮ define functions FVarFrm, BVarFrm : Frm → P(Var) in the

following way:

1 if ϕ = p( ( (t1, , , . . ., , ,tn) ) ) then FVarFrm(ϕ) =

i∈{1,...,n} VarTrm(ti)

and BVarFrm(ϕ) = ∅ 2a if ϕ = ( ( (¬ ¬ ¬ψ) ) ) then FVarFrm(ϕ) = FVarFrm(ψ) and BVarFrm(ϕ) = BVarFrm(ψ) 2b if ϕ = ( ( (ψ1@ψ2) ) ) then FVarFrm(ϕ) = FVarFrm(ψ1) ∪ FVarFrm(ϕ2) and BVarFrm(ϕ) = BVarFrm(ψ1) ∪ BVarFrm(ϕ2) 2c if ϕ = ( ( (( ( (#v) ) )ψ) ) ) then FVarFrm(ϕ) = FVarFrm(ψ) {v} and BVarFrm(ϕ) = BVarFrm(ψ) ∪ {v}

◮ define VarFrm(ϕ) = FVarFrm(ϕ) ∪ BVarFrm(ϕ)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-13
SLIDE 13

Pre-interpretation

◮ data type interpretation:

if D ∈ Dat then IntDat(D) is some non-empty set

◮ constant symbol interpretation:

if c ∈ Con and typCon(c) = D then IntCon(c) ∈ IntDat(D)

◮ function symbol interpretation:

if f ∈ Fun and sigFun(f ) = D1, . . . , Dn, D then IntFun(f ) : IntDat(D1) × · · · × IntDat(Dn) → IntDat(D)

◮ such IntDat, IntCon, IntFun is called a pre-interpretation

Stanislav Krajˇ ci Logic Aspects of Databases

slide-14
SLIDE 14

Evaluation of variables

◮ evaluation of variables:

an arbitrary function E s. t. Dom(E) = Var and E(v) ∈ typVar(v)

◮ if E is an evaluation of variables, v is a variable and

m ∈ IntDat(typVar(v)) then define Ev/m in the following way: Ev/m(w) =

  • E(w)

if w = v m if w = v

Stanislav Krajˇ ci Logic Aspects of Databases

slide-15
SLIDE 15

Evaluation of terms

◮ let E is an evaluation of variables and

IntDat, IntCon, IntFun is a pre-interpretation

◮ define function E with Dom(E) = Trm by induction:

1a if t = v ∈ Var then E(t) = E(v) 1b if t = c ∈ Con then E(t) = IntCon(c) 2 if t = f ( ( (t1, , , . . ., , ,tn) ) ) where f ∈ Fun and t1, . . . , tn ∈ Trm then E(t) = (IntFun(f )) (E(t1), . . . , E(tn))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-16
SLIDE 16

Interpretation of predicate symbols

◮ let p ∈ Pre and sigPre(p) = D1, . . . , Dn ◮ two possible interpretations:

◮ as a relation:

IntPreRel(p) ⊆ IntDat(D1) × · · · × IntDat(Dn)

◮ (alternatively) as a function to a set TrV of truth values:

IntPreFun(p) : IntDat(D1) × · · · × IntDat(Dn) → TrV

◮ if TrV = {0, 1} both interpretations are clearly in this

correspondence: x1, . . . , xn ∈ IntPreRel(p) iff (IntPreFun(p)) (x1, . . . , xn) = 1

Stanislav Krajˇ ci Logic Aspects of Databases

slide-17
SLIDE 17

Basic Boolean functions 1/2

x y B∨

∨ ∨(x, y)

B∧

∧ ∧(x, y)

B→

→ →(x, y)

B↔

↔ ↔(x, y)

1 1 1 1 1 1 1 1 1 1 1 1

x y B↓

↓ ↓(x, y)

B↑

↑ ↑(x, y)

B⊕

⊕ ⊕(x, y)

1 1 1 1 1 1 1 1 1 1

Stanislav Krajˇ ci Logic Aspects of Databases

slide-18
SLIDE 18

Basic Boolean functions 2/2

x B¬

¬ ¬(x)

1 1

X B∃

∃ ∃(X)

B∀

∀ ∀(X)

∅ 1 {0} {1} 1 1 {0, 1} 1 1

Stanislav Krajˇ ci Logic Aspects of Databases

slide-19
SLIDE 19

Evaluation of formulae

◮ let E is an evaluation of variables,

IntDat, IntCon, IntFun is a pre-interpretation and IntPreFun is a interpretation of predicate symbols

◮ define function E with Dom(E) = Frm by induction:

1 if ϕ = p( ( (t1, , , . . ., , ,tn) ) ) where f ∈ Fun and t1, . . . , tn ∈ Trm then E(ϕ) = (IntPreFun(p)) (E(t1), . . . , E(tn)) 2a if ϕ = ( ( (¬ ¬ ¬ψ) ) ) where ψ ∈ Frm then E(ϕ) = B¬

¬ ¬(E(ψ))

2b if ϕ = ( ( (ψ1@ψ2) ) ) where ψ1, ψ2 ∈ Frm and @ ∈ BCnn then E(ϕ) = B@(E(ψ1), E(ψ2)) 2c if ϕ = ( ( (( ( (#v) ) )ψ) ) ) where ψ ∈ Frm, # ∈ Qua and v ∈ Var then E(ϕ) = B#({Ev/m(ψ) : m ∈ IntDat(typVar(v))})

Stanislav Krajˇ ci Logic Aspects of Databases

slide-20
SLIDE 20

Substitution

◮ σ : Var → Trm is called a substitution

if for all v ∈ Var, typ(σ(v)) = typVar(v)

◮ a special case – identity Id:

for all v ∈ Var, Id(v) = v

◮ if σ is a substitution, w is a variable and t is a term s. t.

typ(t) = typVar(w) then σw/t is a substitution defined by σw/t(v) =

  • t,

if v = w σ(v), if v = w

Stanislav Krajˇ ci Logic Aspects of Databases

slide-21
SLIDE 21

Substitution to a term

◮ let σ is a substitution ◮ define σ : Trm → Trm:

1a if t = v ∈ Var then σ(t) = σ(v) 1b if t = c ∈ Con then σ(t) = c 2 if t = f ( ( (t1, , , . . ., , ,tn) ) ) where f ∈ Fun and t1, . . . , tn ∈ Trm then σ(t) = f ( ( (σ(t1), , , . . ., , ,σ(tn)) ) )

Stanislav Krajˇ ci Logic Aspects of Databases

slide-22
SLIDE 22

Substitution to a formula

◮ let σ is a substitution ◮ define σ : Frm → Frm:

1 if ϕ = p( ( (t1, , , . . ., , ,tn) ) ) where f ∈ Fun and t1, . . . , tn ∈ Trm then σ(ϕ) = p( ( (σ(t1), , , . . ., , ,σ(tn)) ) ) 2a if ϕ = ( ( (¬ ¬ ¬ψ) ) ) where ψ ∈ Frm then σ(ϕ) = ( ( (¬ ¬ ¬σ(ψ)) ) ) 2b if ϕ = ( ( (ψ1@ψ2) ) ) where ψ1, ψ2 ∈ Frm and @ ∈ BCnn then σ(ϕ) = ( ( (σ(ψ1)@σ(ψ2)) ) ) 2c if ϕ = ( ( (( ( (#v) ) )ψ) ) ) where ψ ∈ Frm, # ∈ Qua and v ∈ Var then σ(ϕ) = ( ( (( ( (#) ) )σv/v(ψ)) ) )

Stanislav Krajˇ ci Logic Aspects of Databases

slide-23
SLIDE 23

The variant theorem

◮ theorem:

Let v and w are variables of the same type and ϕ be a formula s. t. v, w / ∈ BVarFrm(ϕ) and moreover v / ∈ FVarFrm(ϕ). Then for all E E(( ( (( ( (∃ ∃ ∃w) ) )ϕ) ) )) = E(( ( (( ( (∃ ∃ ∃v) ) )Idw/vϕ) ) )).

Stanislav Krajˇ ci Logic Aspects of Databases

slide-24
SLIDE 24

2 FORMALIZATION OF DATABASES

Stanislav Krajˇ ci Logic Aspects of Databases

slide-25
SLIDE 25

Attribute and table names

◮ Abc – the English abc including other special characters ◮ ≤Abc (shortly ≤) – an arbitrary but fixed linear ordering of

the set Abc (e.g. lexicographical)

◮ TbN – table names – an arbitrary but fixed infinite countable

subset of Abc+

◮ AtN – attribute names – an arbitrary but fixed infinite

countable subset of Abc+

◮ att : TbN → Pfin(AtN) – s.t. att−1(U) is infinite for all

U ∈ Pfin(AtN)

◮ if M ∈ TbN then ari(M) = |att(M)|

Stanislav Krajˇ ci Logic Aspects of Databases

slide-26
SLIDE 26

Abstract table

◮ All – the universe (or (not very correctly) domain) – an

arbitrary but fixed infinite set

◮ T = M, D – an abstract table (or shortly table)

◮ M ∈ TbN – the T’s metadata (or name),

M = met(T), T is an instantion of M

◮ D ⊆ Allatt(M) – the T’s data,

D = dat(T)

◮ T1 T2 (T1 and T2 are tables) – if met(T1) = met(T2) and

dat(T1) ⊆ dat(T2)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-27
SLIDE 27

Database

◮ database – an arbitrary finite subset of tables with different

metadata

◮ sch(B) – database schema of a database B – the set of all

metadata of all tables from B; B is an instantion of sch(B)

◮ tab(B, M) (B is a database and M ∈ sch(B)) – the only table

T of the database B s.t. met(T) = M

◮ B1 B2 (B1 and B2 are databases) – if sch(B1) = sch(B2)

and for each M ∈ sch(B1), tab(B1, M) tab(B2, M)

◮ the active universe (or active domain) of the database B –

act(B) =

T∈B

  • f ∈dat(T) Rng(f )

Stanislav Krajˇ ci Logic Aspects of Databases

slide-28
SLIDE 28

Example (1/6)

◮ table T1 with a name “cinema

cinema cinema”:

“cinema address cinema address cinema address” “cinema name cinema name cinema name” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1” “´ Usmev ´ Usmev ´ Usmev” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” ◮ table T2 with a name “movie

movie movie”:

“country country country” “director director director” “movie name movie name movie name” “year year year” “USA USA USA” “Robert Zemeckis Robert Zemeckis Robert Zemeckis” “Forrest Gump Forrest Gump Forrest Gump” “1994 1994 1994” “USA USA USA” “Frank Darabont Frank Darabont Frank Darabont” “The Shawshank Redemption The Shawshank Redemption The Shawshank Redemption” “1994 1994 1994” “USA USA USA” “David Leane David Leane David Leane” “The Bridge over the River Kwai The Bridge over the River Kwai The Bridge over the River Kwai” “1959 1959 1959” “USA USA USA” “Robert Zemeckis Robert Zemeckis Robert Zemeckis” “Back to the Future Back to the Future Back to the Future” “1985 1985 1985” “Czechia Czechia Czechia” “Oldˇ rich Lipsk´ y Oldˇ rich Lipsk´ y Oldˇ rich Lipsk´ y” “Mareˇ cku, podejte mi pero! Mareˇ cku, podejte mi pero! Mareˇ cku, podejte mi pero!” “1976 1976 1976”

Stanislav Krajˇ ci Logic Aspects of Databases

slide-29
SLIDE 29

Example (2/6)

◮ table T3 with a name “performance

performance performance”:

“cinema name cinema name cinema name” “datetime datetime datetime” “movie name movie name movie name” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank Redemption The Shawshank Redemption The Shawshank Redemption” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over the River Kwai The Bridge over the River Kwai The Bridge over the River Kwai” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte mi pero! Mareˇ cku, podejte mi pero! Mareˇ cku, podejte mi pero!”

Stanislav Krajˇ ci Logic Aspects of Databases

slide-30
SLIDE 30

Example (3/6)

◮ TbN ⊇ {“cinema

cinema cinema”,“movie movie movie”,“performance performance performance”}

◮ AtN ⊇ {“cinema address

cinema address cinema address”,“cinema name cinema name cinema name”,“country country country”, “director director director”,“movie name movie name movie name”,“year year year”,“datetime datetime datetime”}

◮ att(“cinema

cinema cinema”) = {“cinema address cinema address cinema address”,“cinema name cinema name cinema name”}, att(“movie movie movie”) = {“country country country”,“director director director”,“movie name movie name movie name”,“year year year”}, att(“performance performance performance”) = {“cinema name cinema name cinema name”,“datetime datetime datetime”,“movie name movie name movie name”}

◮ ari(“cinema

cinema cinema”) = 2, ari(“movie movie movie”) = 4, ari(“performance performance performance”) = 3

Stanislav Krajˇ ci Logic Aspects of Databases

slide-31
SLIDE 31

Example (4/6)

◮ All ⊇ {“Hronsk´

a 12 Hronsk´ a 12 Hronsk´ a 12”,“Druˇ zba Druˇ zba Druˇ zba”,“Masarykova 2 Masarykova 2 Masarykova 2”, “Capitol Capitol Capitol”, . . . ,“USA USA USA”,“Robert Zemeckis Robert Zemeckis Robert Zemeckis”, “Forrest Gump Forrest Gump Forrest Gump”,“1994 1994 1994”, . . . ,“2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00”, . . . }

◮ e. g. dat(T1) = {f1, f2, f3, f4} where

f1 = {“cinema address cinema address cinema address”,“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12”, “cinema name cinema name cinema name”,“Druˇ zba Druˇ zba Druˇ zba”}, f2 = {“cinema address cinema address cinema address”,“Masarykova 2 Masarykova 2 Masarykova 2”, “cinema name cinema name cinema name”,“Capitol Capitol Capitol”}, f3 = {“cinema address cinema address cinema address”,“Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1”, “cinema name cinema name cinema name”,“´ Usmev ´ Usmev ´ Usmev”}, f4 = {“cinema address cinema address cinema address”,“Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8”, “cinema name cinema name cinema name”,“Tatra Tatra Tatra”}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-32
SLIDE 32

Example (5/6)

◮ met(T1) = “cinema

cinema cinema”, met(T2) = “movie movie movie”, met(T3) = “performance performance performance”

◮ database B = {T1, T2, T3} ◮ sch(B) = {“cinema

cinema cinema”,“movie movie movie”,“performance performance performance”}

◮ tab(B,“cinema

cinema cinema”) = T1, tab(B,“movie movie movie”) = T2, tab(B,“performance performance performance”) = T3

Stanislav Krajˇ ci Logic Aspects of Databases

slide-33
SLIDE 33

Example (6/6)

◮ table T ′ 1 with a name “cinema

cinema cinema”:

“cinema address cinema address cinema address” “cinema name cinema name cinema name” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1” “´ Usmev ´ Usmev ´ Usmev” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “Hlavn´ a 59 Hlavn´ a 59 Hlavn´ a 59” “Slovan Slovan Slovan” ◮ T1 T ′ 1

because met(T ′

1) = metT1 and dat(T ′ 1) ⊇ datT1 ◮ if B′ = {T ′ 1, T2, T3} then

sch(B′) = sch(B) and B B′

Stanislav Krajˇ ci Logic Aspects of Databases

slide-34
SLIDE 34

Corresponding tuple

◮ let n ∈ N and U is an n-element set of attributes,

let U = {u1, . . . , un} where u1 < · · · < un; if f : U → All then tup(f ) = f (u1), . . . , f (un)

◮ in a special case n = 0 clearly f = ∅,

hence tup(f ) =

◮ if f = {“cinema address

cinema address cinema address”,“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12”, “cinema name cinema name cinema name”,“Druˇ zba Druˇ zba Druˇ zba”}, then tup(f ) = “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12”,“Druˇ zba Druˇ zba Druˇ zba” because “cinema address cinema address cinema address” ≤ “cinema name cinema name cinema name”

Stanislav Krajˇ ci Logic Aspects of Databases

slide-35
SLIDE 35

(Abstract) table relation

◮ (abstract) table relation:

if T is an abstract table then rel(T) = {tup(f ) : f ∈ dat(T)}

◮ clearly T1 T2 iff rel(T1) ⊆ rel(T2) ◮ in our example rel(T1) =

{“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12”,“Druˇ zba Druˇ zba Druˇ zba” “Masarykova 2 Masarykova 2 Masarykova 2”,“Capitol Capitol Capitol” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1”,“´ Usmev ´ Usmev ´ Usmev” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8”,“Slovan Slovan Slovan”}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-36
SLIDE 36

Reconstruction of table from its relation

◮ lemma:

If met(T) = M and rel(T) = R then dat(T) = {f : f : att(M) → All ∧ f (u1), . . . , f (un) ∈ R} where {u1, . . . , un} = att(M) and u1 < · · · < un.

◮ proof:

simply using definitions

Stanislav Krajˇ ci Logic Aspects of Databases

slide-37
SLIDE 37

3 CONJUNCTIVE QUERIES

Stanislav Krajˇ ci Logic Aspects of Databases

slide-38
SLIDE 38

First order language for conjunctive queries

◮ special symbols

◮ Dat – the only one (in our simplified version) ◮ Var – unspecified ◮ Con – the set All, they are interpreted by themselves ◮ Fun – none ◮ Pre – the set TbN

◮ a new auxiliary symbol ←

← ←

◮ i. e. terms are variables and constant symbols only

Stanislav Krajˇ ci Logic Aspects of Databases

slide-39
SLIDE 39

Conjunctive query

◮ let M1, . . . , Mn ∈ TbN and for all i ∈ {1, . . . , n},

mi = ari(Mi) and ti

1, . . . , ti mi are terms ◮ let K ∈ TbN, k = ari(K) and s1, . . . , sk are terms ◮ if k i=1 VarTrm(si) ⊆ n i=1

mi

j=1 VarTrm(ti j )

then the word K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ) is called a conjunctive query

◮ its head / body – the part before / after ←

← ←

◮ if S is a database schema, M1, . . . , Mn ∈ S and K /

∈ S then this is conjunctive query over S

Stanislav Krajˇ ci Logic Aspects of Databases

slide-40
SLIDE 40

Example

Forrest Gump cinemas Forrest Gump cinemas Forrest Gump cinemas( ( (y y y, , ,x x x) ) )← ← ← cinema cinema cinema( ( (x x x, , ,y y y) ) ), , ,performance performance performance( ( (x x x, , ,z z z, , ,Forrest Gump Forrest Gump Forrest Gump) ) ) is a conjunctive query over S

◮ k = 2, n = 2, m1 = 2, m2 = 3 ◮ K = Forrest Gump cinemas

Forrest Gump cinemas Forrest Gump cinemas / ∈ S, M1 = cinema cinema cinema ∈ S, M2 = performance performance performance ∈ S

◮ s1 = y

y y ∈ Var, s2 = x x x ∈ Var, t1

1 = x

x x ∈ Var, t1

2 = y

y y ∈ Var, t2

1 = x

x x ∈ Var, t2

2 = z

z z ∈ Var, t2

3 = Forrest Gump

Forrest Gump Forrest Gump ∈ Con

◮ k i=1 VarTrm(si) = VarTrm(y

y y) ∪ VarTrm(x x x) = {x x x,y y y}, n

i=1

mi

j=1 VarTrm(ti j ) = (VarTrm(x

x x) ∪ VarTrm(y y y)) ∪ (VarTrm(x x x) ∪ VarTrm(z z z) ∪ VarTrm(Forrest Gump Forrest Gump Forrest Gump)) = {x x x,y y y,z z z}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-41
SLIDE 41

Answer of a database to a conjunctive query

◮ let B be a database and q be a conjunctive query over sch(B),

q = K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) )

◮ answer of the database B to a conjunctive query q:

a table T = aC(B, q) s. t. met(T) = K and rel(T) = {E(s1), . . . , E(sk) : E : Var → All ∧ ∧ (∀i ∈ {1, . . . , n})E(ti

1), . . . , E(ti mi) ∈ rel(tab(B, Mi))}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-42
SLIDE 42

Example

◮ the answer T of our database B to the previous conjunctive

query:

◮ met(T) = Forrest Gump cinemas

Forrest Gump cinemas Forrest Gump cinemas

◮ rel(T)

= {E(y y y), E(x x x) : E : Var → All ∧ ∧ E(x x x), E(y y y) ∈ rel(tab(B,cinema cinema cinema)) ∧ ∧ E(x x x), E(z z z), E(Forrest Gump Forrest Gump Forrest Gump) ∈ ∈ rel(tab(B,performance performance performance))} = {E(y y y), E(x x x) : E : Var → All ∧ ∧ E(x x x) = Masarykova 2 Masarykova 2 Masarykova 2 ∧ ∧ E(y y y) = Capitol Capitol Capitol ∧ ∧ E(z z z) = “2007-03-23 20:00” “2007-03-23 20:00” “2007-03-23 20:00”} = {Capitol Capitol Capitol,Masarykova 2 Masarykova 2 Masarykova 2}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-43
SLIDE 43

Monotony of a conjunctive query

◮ lemma:

Let S be a database schema and q be a conjunctive query

  • ver S. For all databases B1 a B2 which are instantiations of

S, B1 B2 implies aC(B1, q) aC(B2, q).

◮ proof:

simply using definitions

Stanislav Krajˇ ci Logic Aspects of Databases

slide-44
SLIDE 44

Satisfiability of a conjunctive query

◮ lemma:

Let S be a database schema and q be a conjunctive query

  • ver S. Then there is a database B which is an instantiation
  • f S s. t. rel(aC(B, q)) = ∅.

◮ proof:

◮ let q be K(

( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) )

◮ let C be the set of all constant symbols in q and a ∈ Con C ◮ for all M ∈ S take its instantiation TM s. t.

rel(TM) = (C ∪ {a})ari(M), and take B = {TM : M ∈ S}

◮ clearly TM = tab(B, M) and sch(B) = S ◮ let E be an evaluation of variables s. t. E(v) = a ◮ then for all i ∈ {1, . . . , n},

E(ti

1), . . . , E(ti mi) ∈ rel(TMi) = rel(tab(B, Mi))}

hence E(s1), . . . , E(sk) ∈ rel(aC(B, q))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-45
SLIDE 45

Range of the answer

◮ lemma:

Let S be a database schema and q be a conjunctive query

  • ver S and

q = K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ) Then

  • f ∈dat(aC(q,B))

Rng(f ) ⊆ ⊆

n

  • i=1
  • f ∈dat(tab(B,Mi))

Rng(f ) ∪

k

  • j=1

ConTrm(sj).

◮ proof:

using definitions

Stanislav Krajˇ ci Logic Aspects of Databases

slide-46
SLIDE 46

4 EQUALITY-CONJUNCTIVE QUERIES

Stanislav Krajˇ ci Logic Aspects of Databases

slide-47
SLIDE 47

First order language for equality-conjunctive queries

◮ special symbols (almost the same as above)

◮ Dat – the only one (in our simplified version) ◮ Var – unspecified ◮ Con – the set All ◮ Fun – none ◮ Pre – the set TbN, moreover =

= =

◮ i. e. there is a new type of atomic formulae, namely t1 =

= = t2

Stanislav Krajˇ ci Logic Aspects of Databases

slide-48
SLIDE 48

Equality-conjunctive query

◮ let M1, . . . , Mn ∈ TbN and for all i ∈ {1, . . . , n},

mi = ari(Mi) and ti

1, . . . , ti mi are terms ◮ let K ∈ TbN, k = ari(K) and s1, . . . , sk are terms ◮ let u1 1, u1 2, . . . , uℓ 1, uℓ 2 are terms ◮ if k i=1 VarTrm(si) ⊆

n

i=1

mi

j=1 VarTrm(ti j ) ∪ ℓ i=1

2

j=1 VarTrm(ui j)

then the word K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ), , ,u1

1 =

= = u1

2,

, , . . ., , ,uℓ

1 =

= = uℓ

2

is called an equality-conjunctive query

◮ if S is a database schema, M1, . . . , Mn ∈ S and K /

∈ S then this is equality-conjunctive query over S

◮ clearly each conjunctive query (over S) is an

equality-conjunctive query (over S) (for ℓ = 0)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-49
SLIDE 49

Answer of a database to an equality-conjunctive query

◮ let B be a database and q be a equality-conjunctive query

  • ver sch(B),

q = K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ), , ,u1

1 =

= = u1

2,

, , . . ., , ,uℓ

1 =

= = uℓ

2 ◮ answer of the database B to an equality-conjunctive query q:

a table T = aEC(B, q) s. t. met(T) = K and rel(T) = {E(s1), . . . , E(sk) : E : Var → All ∧ ∧ (∀i ∈ {1, . . . , n})E(ti

1), . . . , E(ti mi) ∈ rel(tab(B, Mi)) ∧

∧ (∀i ∈ {1, . . . , ℓ})E(ui

1) = E(ui 2)} ◮ for each database S and conjunctive query q over sch(B),

aEC(B, q) = aC(B, q)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-50
SLIDE 50

Monotony of an equality-conjunctive query

◮ lemma:

Let S be a database schema and q be an equality-conjunctive query over S. For all databases B1 a B2 which are instantiations of S, B1 B2 implies aEC(B1, q) aEC(B2, q).

◮ proof:

simply using definitions

Stanislav Krajˇ ci Logic Aspects of Databases

slide-51
SLIDE 51

(Un)satisfiability of an equality-conjunctive query

◮ an equality-conjunctive query q over S is called satisfiable

if there is a database B which is an instantiation of S s. t. rel(aEC(B, q)) = ∅

◮ an equality-conjunctive query need not be satisfiable:

  • e. g. take

K( ( (x) ) )← ← ← M( ( (x) ) ), , ,x = = = a, , ,x = = = b where a and b are different constants

Stanislav Krajˇ ci Logic Aspects of Databases

slide-52
SLIDE 52

Value-restricted equality-conjunctive query

◮ the set of value-restricted equality-conjunctive query:

1 each conjunctive query is value-restricted 2 if i ∈ {0, . . . , ℓ}, v1 and v2 are terms s. t. v1 or v2 is an element of n

i=1

mi

j=1 VarTrm(ti j ) ∪ ℓ i=1

2

j=1 VarTrm(ui 1)

and K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ), , , u1

1 =

= = u1

2,

, , . . ., , ,uℓ

1 =

= = uℓ

2

is value-restricted, then K( ( (s1, , , . . ., , ,sk) ) )← ← ← M1( ( (t1

1,

, , . . ., , ,t1

m1)

) ), , , . . ., , ,Mn( ( (tn

1,

, , . . ., , ,tn

mn)

) ), , , u1

1 =

= = u1

2,

, , . . ., , ,ui

1 =

= = ui

2,

, ,v1 = = = v2, , ,ui+1

1

= = = ui+1

2

, , , . . ., , ,uℓ

1 =

= = uℓ

2

is value-restricted

Stanislav Krajˇ ci Logic Aspects of Databases

slide-53
SLIDE 53

Equivalence theorem

◮ a value-restricted equality-conjunctive query need not be

satisfiable:

  • e. g.

K( ( (x, , ,y) ) )← ← ← M( ( (x) ) ), , ,y = = = z where x, y and z are different variables

◮ theorem:

Let S be a database schema. For all satisfiable value-restricted equality-conjunctive query q over S there exists conjunctive query q′ over S s. t. aEC(B, q) = aC(B, q′).

◮ i. e. these two sets of queries have the same expressive power,

they are equivalent in this sense

◮ proof:

◮ by induction through ℓ Stanislav Krajˇ ci Logic Aspects of Databases

slide-54
SLIDE 54

5 CONJUNCTIVE CALCULUS

Stanislav Krajˇ ci Logic Aspects of Databases

slide-55
SLIDE 55

Conjunctive S-formulae

◮ let S be a database schema;

the set CFrmS of conjunctive S-formulae (or shortly S-formulae):

1 if M ∈ S and t1, . . . , tm are terms then M( ( (t1, , , . . ., , ,tm) ) ) ∈ CFrmS 2a if ψ1, ψ2 ∈ CFrmS then ( ( (ψ1∧ ∧ ∧ψ2) ) ) ∈ CFrmS. 2b if ψ ∈ CFrmS and v ∈ Var then ( ( (( ( (∃ ∃ ∃v) ) )ψ) ) ) ∈ CFrmS.

◮ clearly each S-formula is a formula

Stanislav Krajˇ ci Logic Aspects of Databases

slide-56
SLIDE 56

Interpretation of S-formula in a database

◮ let B be a database s. t. sch(B) = S ◮ set IntPreRel(M) = rel(tab(B, M))

and take corresponding interpretation IntPreFun

◮ denote TV(B, E, ϕ) corresponding E(ϕ) ◮ clearly if E1 ↾ FVarFrm(ϕ) = E2 ↾ FVarFrm(ϕ)

then TV(B, E1, ϕ) = TV(B, E2, ϕ), hence this value depends on valuation of the variables from FVarFrm(ϕ) only

Stanislav Krajˇ ci Logic Aspects of Databases

slide-57
SLIDE 57

Conjunctive calculus query

◮ let S be a database schema ◮ conjunctive calculus query: an expression

{ { {

  • t1,

, , . . ., , ,tn

  • :

: :ϕ} } } where t1, . . . , tn are terms, ϕ is a S-formula and

n

  • i=1

VarTrm(ti) = FVarFrm(ϕ).

Stanislav Krajˇ ci Logic Aspects of Databases

slide-58
SLIDE 58

Answer of a database to a conjunctive calculus query

◮ let B be a database and d be a conjunctive calculus query,

d = { { {

  • t1,

, , . . ., , ,tn

  • :

: :ϕ} } }

◮ answer of the database B to a conjunctive calculus query d:

aCC(B, d) = {E(t1), . . . , E(tn) : E : Var → All ∧ TV(B, E, ϕ) = 1}

Stanislav Krajˇ ci Logic Aspects of Databases

slide-59
SLIDE 59

Restriction to the active domain

◮ lemma:

Let B be a database, E be a variable valuation and ϕ be a sch(B)-formula. Then If TV(B, E, ϕ) = 1 then Rng(E ↾ FVarFrm(ϕ)) ⊆ act(B).

◮ proof:

◮ by the induction on ϕ

◮ corollary:

Let B be a database and d be a conjunctive calculus query. Then aCC(B, d) = {E(t1), . . . , E(tn) : E : Var → act ∧ TV(B, E, ϕ) = 1}

◮ this means that it is enough to verify the finite number of

valuations of the variables from FVarFrm(ϕ)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-60
SLIDE 60

Normal form

◮ S-formula ϕ is in the normal form

if there is a sequence (ϕ0, . . . , ϕn) s. t. ϕn = ϕ and there are k, ℓ ∈ {0, . . . , n}, k ≤ ℓ s. t.:

1 for each i ∈ {0, . . . , k}, ϕi is an atomic formula 2a for each i ∈ {k + 1, . . . , ℓ} there are h, j < i s. t. ϕi = ( ( (ϕh∧ ∧ ∧ϕj) ) ) 2b for each i ∈ {ℓ + 1, . . . , n} there is j < i and v ∈ Var s. t. ϕi = ( ( (( ( (∃ ∃ ∃v) ) )ϕj) ) )

◮ e. g. (

( (∃ ∃ ∃y y y) ) )( ( (∃ ∃ ∃z z z) ) )( ( (cinema cinema cinema( ( (Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8, , ,x x x) ) )∧ ∧ ∧performance performance performance( ( (x x x, , ,z z z, , ,y y y) ) )) ) )

◮ clearly ϕ is in the normal form

iff ( ( (( ( (∃ ∃ ∃v) ) )ϕ) ) ) is in the normal form

◮ a conjunctive calculus query is in the normal form

iff its formula is in the normal form

◮ {

{ {

  • x

x x

  • :

: :( ( (∃ ∃ ∃y y y) ) )( ( (∃ ∃ ∃z z z) ) )( ( (cinema cinema cinema( ( (Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8, , ,x x x) ) )∧ ∧ ∧performance performance performance( ( (x x x, , ,z z z, , ,y y y) ) )) ) )} } }

Stanislav Krajˇ ci Logic Aspects of Databases

slide-61
SLIDE 61

Gluing of normal forms

◮ let Var = {vi : i ∈ N} and all vi’s be different ◮ define function glu gluing two S-formulae in the normal form

into one: glu(( ( (∃ ∃ ∃vi1

1)

) ) . . .( ( (∃ ∃ ∃vi1

n1)

) )ψ1,( ( (∃ ∃ ∃vi2

1)

) ) . . .( ( (∃ ∃ ∃vi2

n2)

) )ψ2) = ( ( (∃ ∃ ∃vj1

1)

) ) . . .( ( (∃ ∃ ∃vj1

n1)

) )( ( (∃ ∃ ∃vj2

1)

) ) . . .( ( (∃ ∃ ∃vj2

n2)

) )( ( (ξ1∧ ∧ ∧ξ2) ) ) where ξh = Idvih

1 /jh 1 (. . . (Idvih nh /jh nh (ψh)) . . . ),

j1

k = i1 k + max({u : vu ∈ VarFrm(ψ1) ∪ VarFrm(ψ2)}),

j2

ℓ = i2 ℓ + max({j1 k : k ∈ {1, . . . , n1}})

Stanislav Krajˇ ci Logic Aspects of Databases

slide-62
SLIDE 62

S-formulae in the normal form are sufficient

◮ define function NFF from S-formulae to S-formulae in the

normal form:

1 if ϕ is an atomic formula set NFF(ϕ) = ϕ 2a if ϕ = ( ( (ψ1∧ ∧ ∧ψ2) ) ) then NFF(ϕ) = glu(NFF(ψ1), NFF(ψ2)) 2b if ϕ = ( ( (( ( (∃ ∃ ∃v) ) )ψ) ) ) then NFF(ϕ) = ( ( (( ( (∃ ∃ ∃v) ) )NFF(ψ)) ) )

◮ clearly NFF(ϕ) is equivalent to ϕ ◮ corollary:

For each conjunctive query q there exists a conjunctive query in the normal form d′ such that d and d′ are equivalent.

Stanislav Krajˇ ci Logic Aspects of Databases

slide-63
SLIDE 63

Equivalence theorem

◮ theorem:

Let S be a database schema.

1 For each query of conjunctive calculus d in the normal form there exists a conjunctive query q s. t. for all databases B of the schema S aCC(B, d) = rel(aC(B, q)). 2 For each conjunctive query q there exists a query of conjunctive calculus d in the normal form s. t. for all databases B of the schema S aCC(B, d) = rel(aC(B, q)).

◮ i. e. conjunctive calculus (wlog in the normal form) and

conjunctive queries have the same expressive power

Stanislav Krajˇ ci Logic Aspects of Databases

slide-64
SLIDE 64

6 RELATIONAL SPC ALGEBRA

Stanislav Krajˇ ci Logic Aspects of Databases

slide-65
SLIDE 65

Selection, Projection and Cross-product

◮ selection

◮ σn

k,ℓ : P(Alln) → P(Alln) where n ∈ N and k, ℓ ∈ {1, . . . , n}:

σn

k,ℓ(R) = {x1, . . . , xn ∈ R : xk = xℓ}

◮ projection

◮ πn

j1,...,jk : P(Alln) → P(Alln) where if n ∈ N and

j1, . . . , jk ∈ {1, . . . , n}: πn

j1,...,jk(R) = {xj1, . . . , xjk :

(∃y1) . . . (∃yn)(y1, . . . , yn ∈ R ∧ (∀i ∈ {1, . . . , k})yji = xji)}

◮ cross-product (isomorphic (but not equal) to Cartesian one)

◮ κn,m : P(Alln) × P(Allm) → P(Alln+m) where if n, m ∈ N:

κn,m(R, S) = {x1, . . . , xn, y1, . . . , ym : x1, . . . , xn ∈ R ∧ y1, . . . , ym ∈ S}

◮ shortly (and not very correctly) R × S Stanislav Krajˇ ci Logic Aspects of Databases

slide-66
SLIDE 66

Changing lemmas (1/9)

◮ lemma:

Let n ∈ N, k1, k2, ℓ1, ℓ2 ∈ {1, . . . , n} and R ⊆ Alln. Then σn

k1,ℓ1(σn k2,ℓ2(R)) = σn k2,ℓ2(σn k1,ℓ1(R)). ◮ proof:

◮ σn

k1,ℓ1(σn k2,ℓ2(R))

= σn

k1,ℓ1({x1, . . . , xn ∈ R : xk2 = xℓ2})

= {y1, . . . , yn ∈ {x1, . . . , xn ∈ R : xk2 = xℓ2} : yk1 = yℓ1}) = {y1, . . . , yn ∈ R : yk2 = yℓ2 ∧ yk1 = yℓ1} = {y1, . . . , yn ∈ R : yk1 = yℓ1 ∧ yk2 = yℓ2} = {y1, . . . , yn ∈ {x1, . . . , xn ∈ R : xk1 = xℓ1} : yk2 = yℓ2}) = σn

k2,ℓ2({x1, . . . , xn ∈ R : xk1 = xℓ1})

= σn

k2,ℓ2(σn k1,ℓ1(R))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-67
SLIDE 67

Changing lemmas (2/9)

◮ lemma:

Let n, m, k ∈ N, j1, . . . , jk ∈ {1, . . . , n} i1, . . . , in ∈ {1, . . . , m} and R ⊆ Allm. Then πn

j1,...,jk(πm i1,...,in(R)) = πm ij1,...,ijk (R). ◮ proof:

◮ πn

j1,...,jk(πm i1,...,in(R))

= πn

j1,...,jk({xi1, . . . , xin : (∃y1, . . . , ym)(y1, . . . , ym ∈ R∧

∧ (∀p ∈ {1, . . . , n})yip = xip)}) = {zj1, . . . , zjk : (∃w1, . . . , wn)(w1, . . . , wn ∈ {xi1, . . . , xin : (∃y1, . . . , ym)(y1, . . . , ym ∈ R∧(∀p ∈ {1, . . . , n})yip = xip)} ∧ (∀q ∈ {1, . . . , k})wjq = zjq)} = {zj1, . . . , zjk : (∃w1, . . . , wn)(∃y1, . . . , ym)(y1, . . . , ym ∈ R ∧ (∀p ∈ {1, . . . , n})yip = wp ∧ (∀q ∈ {1, . . . , k})wjq = zjq)} = {zj1, . . . , zjk : (∃y1, . . . , ym)(y1, . . . , ym ∈ R ∧ (∀q ∈ {1, . . . , k})yijq = zjq)} = πm

ij1,...,ijk (R)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-68
SLIDE 68

Changing lemmas (3/9)

◮ lemma:

Let R, S and T are relations. Then (R × S) × T = R × (S × T).

◮ proof:

◮ (R × S) × T

= {x1, . . . , xn, y1, . . . , ym:x1, . . . , xn∈R ∧ y1, . . . , ym∈S} × ×T = {x1, . . . , xn, y1, . . . , ym, z1, . . . , zk : (x1, . . . , xn ∈ R ∧ ∧ y1, . . . , ym ∈ S) ∧ z1, . . . , zk ∈ T} = {x1, . . . , xn, y1, . . . , ym, z1, . . . , zk : x1, . . . , xn ∈ R ∧ ∧ (y1, . . . , ym ∈ S ∧ z1, . . . , zk ∈ T)} = R × × {y1, . . . , ym, z1, . . . , zk:y1, . . . , ym∈S ∧ z1, . . . , zk∈T} = R × (S × T)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-69
SLIDE 69

Changing lemmas (4/9)

◮ lemma:

Let m,n∈N, k,ℓ∈{1, . . . , m}, j1,. . . ,jk ∈{1, . . . , n}, R ⊆Alln. σm

k,ℓ(πn j1,...,jm(R)) = πn j1,...,jm(σn jk,jℓ(R)). ◮ proof:

◮ σm

k,ℓ(πn j1,...,jm(R))

= σm

k,ℓ(

{ xj1, . . . , xjk:(∃y1, . . . , yn∈R)(∀i∈{1, . . . , k})yji=xji) } ) = {z1, . . . , zm ∈ {xj1, . . . , xjk : (∃y1, . . . , yn) (y1, . . . , yn ∈ R ∧ (∀i ∈ {1, . . . , k})yji = xji)} : zk = zℓ} = {xj1, . . . , xjk : (∃y1, . . . , yn)(y1, . . . , yn ∈ R ∧ ∧ (∀i ∈ {1, . . . , k})yji = xji) ∧ xjk = xjℓ} = {xj1, . . . , xjk : (∃y1, . . . , yn)(y1, . . . , yn ∈ R ∧ ∧ (∀i ∈ {1, . . . , k})yji = xji ∧ yjk = yjℓ)} = {xj1, . . . , xjm : (∃y1, . . . , yn)(y1, . . . , yn ∈ {w1, . . . , wn ∈ R : wjk = wjℓ}∧(∀i ∈ {1, . . . , k})yji = xji)} = πm

j1,...,jm({w1, . . . , wn ∈ R : wjk = wjℓ})

= πm

j1,...,jm(σn jk,jℓ(R))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-70
SLIDE 70

Changing lemmas (5/9)

◮ lemma:

Let k, m, n ∈ N, j1, . . . , jk ∈ {1, . . . , n} and R ⊆ Allm, S ⊆ Alln. Then R × πn

j1,...,jk(S) = πm+n 1,...,m,m+j1,...,m+jk(R × S). ◮ proof:

◮ R × πn

j1,...,jk(S)

= R × {xj1, . . . , xjk : (∃y1) . . . (∃yn) (y1, . . . , yn ∈ S ∧ (∀i ∈ {1, . . . , k})yji = xji)} = {z1, . . . , zm, xj1, . . . , xjk : z1, . . . , zm ∈ R ∧ (∃y1) . . . (∃yn) (y1, . . . , yn ∈ S ∧ (∀i ∈ {1, . . . , k})yji = xji)} = {z1, . . . , zm, xj1, . . . , xjk : (∃y1, . . . , ym+n)(w1, . . . , ym+n ∈ R × S ∧ ∧(∀i ∈ {1, . . . , m})yi = zi ∧(∀i ∈ {1, . . . , k})ym+ji = xji)} = πm+n

1,...,m,m+j1,...,m+jk(R × S)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-71
SLIDE 71

Changing lemmas (6/9)

◮ lemma:

Let k, m, n ∈ N, j1, . . . , jk ∈ {1, . . . , n} and R ⊆ Allm, S ⊆ Alln. Then πm

j1,...,jk(R) × S = πm+n j1,...,jk,m+1,...,m+n(R × S). ◮ proof:

◮ πm

j1,...,jk(R) × S

= {xj1, . . . , xjk : (∃y1) . . . (∃yn) (y1, . . . , ym ∈ R ∧ (∀i ∈ {1, . . . , k})yji = xji)} × S = {xj1, . . . , xjk, z1, . . . , zn : z1, . . . , zn ∈ S ∧ (∃y1) . . . (∃yn) (y1, . . . , ym ∈ R ∧ (∀i ∈ {1, . . . , k})yji = xji)} = {xj1, . . . , xjk, z1, . . . , zn : z1, . . . , zn ∈ S ∧ (∃y1, . . . , yn+m) (y1, . . . , yn+m ∈ R × S ∧ (∀i ∈ {1, . . . , k})yji = xji ∧ (∀i ∈ {1, . . . , n})yi+m = zi)} = πm+n

j1,...,jk,m+1,...,m+n(R × S)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-72
SLIDE 72

Changing lemmas (7/9)

◮ lemma:

Let m, n ∈ N, k, ℓ ∈ {1, . . . , n} and R ⊆ Allm, S ⊆ Alln. Then R × σn

k,ℓ(S) = σm+n m+k,m+ℓ(R × S). ◮ proof:

◮ R × σn

k,ℓ(S)

= R × {x1, . . . , xn ∈ S : xk = xℓ} = {y1, . . . , ym, x1, . . . , xn ∈ R × S : xk = xℓ} = {z1, . . . , zm, zm+1, . . . , zm+n ∈ R × S : zm+k = zm+ℓ} = σm+n

m+k,m+ℓ(R × S)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-73
SLIDE 73

Changing lemmas (8/9)

◮ lemma:

Let m, n ∈ N, k, ℓ ∈ {1, . . . , m} and R ⊆ Allm, S ⊆ Alln. Then σm

k,ℓ(R) × S = σm+n k,ℓ (R × S). ◮ proof:

◮ σm

k,ℓ(R) × S

= {x1, . . . , xm ∈ R : xk = xℓ} × S = {x1, . . . , xm, y1, . . . , yn ∈ R × S : xk = xℓ} × S = {z1, . . . , zm, zm+1, . . . , zm+n ∈ R × S : zk = zℓ} × S = σm+n

k,ℓ (R × S)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-74
SLIDE 74

Changing lemmas (9/9)

◮ lemma:

Let m, n ∈ N, and R ⊆ Allm, S ⊆ Alln. Then S × R = πm+n

m+1,...,m+n,1,...,m(R × S). ◮ proof:

◮ S × R

= {z1, . . . , zm, zm+1, . . . , zm+n ∈ R × S} = {xm+1, . . . , xm+n, x1, . . . , xm : (∃y1) . . . (∃yn)(y1, . . . , yn ∈ R × S ∧ (∀i ∈ {1, . . . , m})yi = xn+i ∧ (∀i ∈ {1, . . . , n})ym+i = xn} = πm+n

m+1,...,m+n,1,...,m(R × S)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-75
SLIDE 75

First order language for the SPC algebra (1/2)

◮ let S is a given database schema ◮ special symbols of the language for the SPC algebra)

◮ Dat = N ◮ Var = S;

if M ∈ Var then typVar(M) = ari(M)

◮ Con = {I

I Ia : a ∈ All}; typCon(I I Ia) = 1

◮ Pre = ∅ ◮ Fun – to be continued Stanislav Krajˇ ci Logic Aspects of Databases

slide-76
SLIDE 76

First order language for the SPC algebra (2/2)

◮ special function symbols

◮ Fun contains: ◮ unary σ

σ σn

k, , ,ℓ for all n ∈ N and k, ℓ ∈ {1, . . . , n};

sigFun(σ σ σn

k, , ,ℓ) = n, n ◮ unary π

π πn

j1, , ,..., , ,jk for all n ∈ N and j1, . . . , jk ∈ {1, . . . , n};

sigFun(π π πn

j1, , ,..., , ,jk ) = n, k ◮ binary κ

κ κn,

, ,m for all n, m ∈ N;

sigFun(κ κ κn,

, ,m) = n, m, n + m;

κ κ κn,

, ,m (

( (t1, , ,t2) ) ) will be abbreviated to t1 × × × t2

Stanislav Krajˇ ci Logic Aspects of Databases

slide-77
SLIDE 77

Interpretation

◮ (pre-)interpretation

◮ IntDat(n) = P(Alln) ◮ IntCon(I

I Ia) = {a}

◮ IntFun(σ

σ σn

k, , ,ℓ) = σn k,ℓ

◮ IntFun(π

π πn

j1, , ,..., , ,jk) = πn j1,...,jk

◮ IntFun(κ

κ κn,

, ,m) = κn,m

◮ datatypes correspond to arities of engaged relations

Stanislav Krajˇ ci Logic Aspects of Databases

slide-78
SLIDE 78

SPC query and the answer to it

◮ an arbitrary term (in the sense of this language) is called a

SPC query

◮ if sch(B) = S

then EB(M) = rel(tab(B, M)) is the corresponding evaluation

  • f variables

and induced EB is the corresponding evaluation of variables

◮ if t is a SPC query then

aSPC(B, t) = EB(t) is called the answer of database B to a SPC query t

Stanislav Krajˇ ci Logic Aspects of Databases

slide-79
SLIDE 79

Example (1/4)

◮ we want names and adresses all working cinemas ◮ a suitable term: t = π

π π5

5 5 2 2 2, , ,1 1 1(

( (σ σ σ5

5 5 2 2 2, , ,3 3 3(

( (cinema cinema cinema× × ×performance performance performance) ) )) ) )

◮ the answer to it:

aSPC(B, t) = = EB(t) = EB(π π π5

5 5 2 2 2, , ,1 1 1(

( (σ σ σ5

5 5 2 2 2, , ,3 3 3(

( (cinema cinema cinema× × ×performance performance performance) ) )) ) )) = π5

2,1(EB(σ

σ σ5

5 5 2 2 2, , ,3 3 3(

( (cinema cinema cinema× × ×performance performance performance) ) ))) = π5

2,1(σ5 2,3(EB(cinema

cinema cinema× × ×performance performance performance))) = π5

2,1(σ5 2,3(EB(cinema

cinema cinema) × EB(performance performance performance))) = π5

2,1(σ5 2,3(EB(cinema

cinema cinema) × EB(performance performance performance))) = π5

2,1(σ5 2,3(rel(tab(B,cinema

cinema cinema)) × rel(tab(B,performance performance performance))))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-80
SLIDE 80

Example (2/4)

◮ rel(tab(B,cinema

cinema cinema)) × rel(tab(B,performance performance performance)):

“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Hlavn´ a 8 Hlavn´ a 8 Hlavn´ a 8” “Tatra Tatra Tatra” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” Stanislav Krajˇ ci Logic Aspects of Databases

slide-81
SLIDE 81

Example (3/4)

◮ σ5 2,3(rel(tab(B,cinema

cinema cinema)) × rel(tab(B,performance performance performance))):

“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ”

◮ i. e.

“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-28 16:00 2007-03-28 16:00 2007-03-28 16:00” “Back to the Future Back to the Future Back to the Future” “Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba” “Druˇ zba Druˇ zba Druˇ zba” “2007-03-29 20:00 2007-03-29 20:00 2007-03-29 20:00” “Mareˇ cku, podejte Mareˇ cku, podejte Mareˇ cku, podejte. . . ” “Masarykova 2 Masarykova 2 Masarykova 2” “Capitol Capitol Capitol” “Capitol Capitol Capitol” “2007-03-23 20:00 2007-03-23 20:00 2007-03-23 20:00” “Forrest Gump Forrest Gump Forrest Gump” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-26 18:00 2007-03-26 18:00 2007-03-26 18:00” “The Shawshank The Shawshank The Shawshank. . . ” “Kas´ arensk´ e Kas´ arensk´ e Kas´ arensk´

  • e. . . ”

“´ Usmev ´ Usmev ´ Usmev” “´ Usmev ´ Usmev ´ Usmev” “2007-03-27 16:00 2007-03-27 16:00 2007-03-27 16:00” “The Bridge over The Bridge over The Bridge over. . . ” Stanislav Krajˇ ci Logic Aspects of Databases

slide-82
SLIDE 82

Example (4/4)

◮ π5 2,1(σ5 2,3(rel(tab(B,cinema

cinema cinema)) × rel(tab(B,performance performance performance)))):

“Druˇ zba Druˇ zba Druˇ zba”“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Druˇ zba Druˇ zba Druˇ zba”“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Capitol Capitol Capitol” “Masarykova 2 Masarykova 2 Masarykova 2” “´ Usmev ´ Usmev ´ Usmev” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1” “´ Usmev ´ Usmev ´ Usmev” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1”

◮ i. e.:

“Druˇ zba Druˇ zba Druˇ zba”“Hronsk´ a 12 Hronsk´ a 12 Hronsk´ a 12” “Capitol Capitol Capitol” “Masarykova 2 Masarykova 2 Masarykova 2” “´ Usmev ´ Usmev ´ Usmev” “Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1 Kas´ arensk´ e n´ amestie 1”

Stanislav Krajˇ ci Logic Aspects of Databases

slide-83
SLIDE 83

6 RELATIONAL SPCJ ALGEBRA

Stanislav Krajˇ ci Logic Aspects of Databases

slide-84
SLIDE 84

Fixing selection

◮ let n ∈ N, j ∈ {1, . . . , n} and a ∈ All ◮ then define a function ϕn j,a : P(Alln) → P(Alln)

ϕn

j,a(R) = {x1, . . . , xn ∈ R : xj = a} ◮ each such function is called fixing selection

Stanislav Krajˇ ci Logic Aspects of Databases

slide-85
SLIDE 85

Commutability of fixing selections

◮ lemma:

Let n ∈ N, j1, j2 ∈ {1, . . . , n} and a1, a2 ∈ All. Then ϕn

j1,a1(ϕn j2,a2(R)) = ϕn j2,a2(ϕn j1,a1(R)). ◮ proof:

◮ ϕn

j1,a1(ϕn j2,a2(R))

= ϕn

j1,a1({x1, . . . , xn ∈ R : xj2 = a2})

= {x1, . . . , xn ∈ R : xj1 = a1 ∧ xj2 = a2} = {x1, . . . , xn ∈ R : xj2 = a2 ∧ xj1 = a1} = ϕn

j2,a2({x1, . . . , xn ∈ R : xj1 = a1})

= ϕn

j2,a2(ϕn j1,a1(R))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-86
SLIDE 86

Commutability of a selection and a fixing selection

◮ lemma:

Let n ∈ N, j, k, ℓ ∈ {1, . . . , n} and a ∈ All. Then ϕn

j,a(σn k,ℓ(R)) = σn k,ℓ(ϕn j,a(R)). ◮ proof:

◮ ϕn

j,a(σn k,ℓ(R))

= ϕn

j,a({x1, . . . , xn ∈ R : xk = xℓ})

= {x1, . . . , xn ∈ R : xj = a ∧ xk = xℓ} = {x1, . . . , xn ∈ R : xk = xℓ ∧ xj = a} = σn

k,ℓ({x1, . . . , xn ∈ R : xj = a})

= σn

k,ℓ(ϕn j,a(R))

Stanislav Krajˇ ci Logic Aspects of Databases

slide-87
SLIDE 87

Fixing selection by means of a SPC algebra

◮ lemma:

Let n ∈ N, j ∈ {1, . . . , n} and a ∈ All. Then ϕn

j,a(R) = πn+1 1,...,n

  • σn+1

j,n+1(R × {a})

  • .

◮ proof:

◮ πn+1

1,...,n(σn+1 j,n+1(R × {a}))

πn+1

1,...,n({x1, . . . , xn+1 ∈ R × {a} : xj = xn+1})

= πn+1

1,...,n({x1, . . . , xn, a ∈ R × {a} : xj = a})

= {x1, . . . , xn ∈ R : xj = a} = ϕn

j,a(R)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-88
SLIDE 88

Multiselection

◮ define for fixed n ∈ N functions µn F,G : P(Alln) → P(Alln)

where F = j1, a1, . . . , ju, au, G = k1, ℓ1, . . . , kv, ℓv, a1, . . . , au ∈ All, j1, . . . , ju, k1, . . . , kv, ℓ1, . . . , ℓv ∈ {1, . . . , n}

1 for all R ⊆ Alln µn

,(R) = R

2a if j ∈ {1, . . . , n} and a ∈ All then for all R ⊆ Alln µn

F ||j,a,G(R) = ϕn j,a

  • µn

F,G(R)

  • 2b if k, ℓ ∈ {1, . . . , n} then for all R ⊆ Alln

µn

F,G ||k,ℓ(R) = σn k,ℓ

  • µn

F,G(R)

  • ◮ each such function is called a multiselection

Stanislav Krajˇ ci Logic Aspects of Databases

slide-89
SLIDE 89

Invariancy of multiselection

◮ let F = j1, a1, . . . , ju, au, G = k1, ℓ1, . . . , kv, ℓv ◮ let p is a permutation of {1, . . . , u}

and q is a permutation of {1, . . . , v}

◮ let Fp = jp(1), ap(1), . . . , jp(u), ap(u)

and Gq = kq(1), ℓq(1), . . . , kq(v), ℓq(v)

◮ clearly

µn

F,G = µn Fp,Gq

(because functions σn

k,ℓ and ϕn j,a commute) ◮ clearly

µn

F1,G1(µn F2,G2(R)) = µn F2,G2(µn F1,G1(R))

(again because functions σn

k,ℓ and ϕn j,a commute)

Stanislav Krajˇ ci Logic Aspects of Databases

slide-90
SLIDE 90

Join

◮ define for fixed n, m ∈ N, u ∈ N, k1, . . . , ku ∈ {1, . . . , n}

ℓ1, . . . , ℓu ∈ {1, . . . , m} and H = k1, ℓ1, . . . , ku, ℓu function ⊲ ⊳m,n

H : P(Alln) → P(Alln):

⊲ ⊳m,n

H

(R, S) = {x1, . . . , xn, y1, . . . , ym : x1, . . . , xn ∈ R ∧ y1, . . . , ym ∈ S ∧(∀i ∈ {1, . . . , u})xki = yℓi}

◮ each such function is called a join

Stanislav Krajˇ ci Logic Aspects of Databases

slide-91
SLIDE 91

Join by means of other operations of SPCJ algebra

◮ if H = k1, ℓ1, . . . , ku, ℓu and a, b ∈ N

then set Ha,b = {a + k1, b + ℓ1, . . . , a + ku, b + ℓu}

◮ lemma:

Let m, n, u ∈ N, j ∈ {1, . . . , n}, k1, . . . , ku ∈ {1, . . . , m}, ℓ1, . . . , ℓu ∈ {1, . . . , n}, H = k1, ℓ1, . . . , ku, ℓu and R ⊆ Allm, S ⊆ Alln. Then ⊲ ⊳m,n

H

(R, S) = µm+n

,H0,n(R × S). ◮ proof:

◮ by induction on m Stanislav Krajˇ ci Logic Aspects of Databases

slide-92
SLIDE 92

First order language for the SPCJ algebra

◮ as for SPC algebra but: ◮ Fun contains:

◮ unary µ

µ µn

  • j1,

, ,a1

  • ,

, ,..., , ,

  • ju,

, ,au

  • ,

, ,

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • kv,

, ,ℓv

  • for all n, u, v ∈ N,

j1, . . . , ju, k1, . . . , kv, ℓ1, . . . , ℓv ∈ {1, . . . , n}, a1, . . . , au ∈ All; sigFun(µ µ µn

  • j1,

, ,a1

  • ,

, ,..., , ,

  • ju,

, ,au

  • ,

, ,

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • kv,

, ,ℓv

  • ) = n, n

◮ unary π

π πn

j1, , ,..., , ,jk as before

◮ binary κ

κ κn,

, ,m as before

◮ binary ⊲

⊳ ⊲ ⊳ ⊲ ⊳n,

, ,m

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • ku,

, ,ℓu

  • for all n, m, u ∈ N,

k1, . . . , ku ∈ {1, . . . , n} ℓ1, . . . , ℓu ∈ {1, . . . , m}; sigFun(⊲ ⊳ ⊲ ⊳ ⊲ ⊳n,

, ,m

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • ku,

, ,ℓu

  • ) = n, m, n + m

◮ expected interpretation of the new symbols

◮ IntFun(µ

µ µn

  • j1,

, ,a1

  • ,

, ,..., , ,

  • ju,

, ,au

  • ,

, ,

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • kv,

, ,ℓv

  • ) =

µn

j1,a1,...,ju,au,k1,ℓ1,...,kv,ℓv

◮ IntFun(⊲

⊳ ⊲ ⊳ ⊲ ⊳n,

, ,m

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • ku,

, ,ℓu

  • ) =⊲

⊳n,m

k1,ℓ1,...,ku,ℓu

Stanislav Krajˇ ci Logic Aspects of Databases

slide-93
SLIDE 93

SPCJ query and the answer to it

◮ an arbitrary term (in the sense of this language) is called a

SPCJ query

◮ if sch(B) = S

then EB(M) = rel(tab(B, M)) is the corresponding evaluation

  • f variables

and induced EB is the corresponding evaluation of variables

◮ if t is a SPCJ query then

aSPCJ(B, t) = EB(t) is called the answer of database B to a SPCJ query t

Stanislav Krajˇ ci Logic Aspects of Databases

slide-94
SLIDE 94

Normal form of SPCJ term

◮ an SPCJ-term t is in the normal form

if there is a sequence (t0, . . . , tp) s. t. tp = t and there are k > 0 and ℓ s. t. 2k + 1 + 2ℓ + 1 = n and:

◮ for each i ∈ {0, . . . , k}, ti ∈ Var ◮ for each i ∈ {k + 1, . . . , 2k}, ti = (

( (ti−2 × × × ti−1) ) )

◮ t2k+1 = µ

µ µn

  • j1,

, ,a1

  • ,

, ,..., , ,

  • ju,

, ,au

  • ,

, ,

  • k1,

, ,ℓ1

  • ,

, ,..., , ,

  • kv,

, ,ℓv

  • (

( (t2k) ) ) for some suitable parameters

◮ for each i ∈ {2k + 2, . . . , 2k + 1 + ℓ}, ti ∈ Con ◮ for each i ∈ {2k + 2 + ℓ, . . . , 2k + 1 + 2ℓ}, ti = (

( (ti−2 × × × ti−1) ) )

◮ tp = π

π πn

j1, , ,..., , ,jk(

( (tp−1) ) ) for some suitable parameters

◮ i. e. a normal form is simply

π π π...

...(

( (µ µ µ...

...(

( (M1 × × × . . .× × × Mk) ) )× × ×I I Ia1 × × × . . .× × ×I I Iaℓ) ) ) where M1, . . . , Mk ∈ S and a1, . . . , aℓ ∈ All

Stanislav Krajˇ ci Logic Aspects of Databases

slide-95
SLIDE 95

Normal form and basic SQL

◮ a normal form

π π π...

...(

( (µ µ µ...

...(

( (M1 × × × . . .× × × Mk) ) )× × ×I I Ia1 × × × . . .× × ×I I Iaℓ) ) ) corresponds to an SQL query SELECT columns given by down-indices of π π π (including ai’s) FROM M1, . . . , Mk WHERE conditions given by down-indices of µ µ µ

Stanislav Krajˇ ci Logic Aspects of Databases

slide-96
SLIDE 96

Normal form is sufficient

◮ theorem:

Let S be a database schema. For each SPCJ query d there exists a SPCJ query e in the normal form s. t. for all databases B of the schema S aSPCJ(B, d) = aSPCJ(B, e).

◮ proof:

◮ rewrite each ⊲

⊳...

... by means of µ... ...’s and ×’s

◮ rewrite each µ...

... by means of σ... ...’s and ϕ... ...’s

◮ use changing lemmas in order to obtain a form

π...

...(. . . (π... ...((X × Y ))) . . . ) where Y = {a1} × · · · × {a...},

X = ϕ...

...(. . . (ϕ... ...(Z)) . . . ), Z = σ... ...(. . . (σ... ...(W )) . . . ) and

W = reltab(B, M1) × reltab(B, Mk)

◮ rewrite π...

...(. . . (π... ...((X × Y ))) . . . ) as one π... ...(X × Y )

◮ rewrite X as µ...

...,(Z)

◮ rewrite Z as µ...

,...(W )

◮ group this two consequent µ...

... to one

Stanislav Krajˇ ci Logic Aspects of Databases

slide-97
SLIDE 97

Equivalence theorem

◮ theorem:

Let S be a database schema.

1 For each satisfiable SPCJ query d in the normal form there exists a conjunctive query q s. t. for all databases B of the schema S aSPCJ(B, d) = rel(aC(B, q)). 2 For each conjunctive query q there exists a satisfiable SPCJ query d in the normal form s. t. for all databases B of the schema S aSPCJ(B, d) = rel(aC(B, q)).

◮ i. e. SPC(J) algebra (wlog in the normal form) and

conjunctive queries have the same expressive power

Stanislav Krajˇ ci Logic Aspects of Databases

slide-98
SLIDE 98

7 CONCLUSION

Stanislav Krajˇ ci Logic Aspects of Databases

slide-99
SLIDE 99

Our models

◮ above-mentioned models of databases:

◮ conjunctive queries ◮ equality-conjunctive queries ◮ queries of conjunctive calculus ◮ queries of conjunctive calculus in the normal form ◮ queries of the relational SPC algebra ◮ queries of the relational SPCJ algebra ◮ queries of the relational SPCJ algebra in the normal form

◮ roughly speaking, all of them have the same expressive power

Stanislav Krajˇ ci Logic Aspects of Databases

slide-100
SLIDE 100

Other aspects

◮ adding of negation ◮ adding of recursion ◮ . . .

Stanislav Krajˇ ci Logic Aspects of Databases