First-Order Queries Chapter I First-Order Logic Outline
Total Page:16
File Type:pdf, Size:1020Kb
Overview of Part 1: First-order queries Knowledge Bases and Databases Part 1: First-Order Queries 1 First-order logic 1 Syntax of first-order logic Diego Calvanese 2 Semantics of first-order logic 3 First-order logic queries Faculty of Computer Science Master of Science in Computer Science 2 First-order query evaluation A.Y. 2007/2008 1 Query evaluation problem 2 Complexity of query evaluation 3 Conjunctive queries 1 Evaluation of conjunctive queries 2 Containment of conjunctive queries 3 Unions of conjunctive queries unibz.it D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (2/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic Outline Chapter I 1 Syntax of first-order logic First-Order Logic 2 Semantics of first-order logic 3 First-order logic queries D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (3/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (4/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic Outline First-order logic 1 Syntax of first-order logic First-order logic (FOL) is the logic to speak about objects, which are the domain of discourse or universe. 2 Semantics of first-order logic FOL is concerned about properties of these objects and relations over objects (resp., unary and n-ary predicates). 3 First-order logic queries FOL also has functions including constants that denote objects. unibz.it D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (5/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (6/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic FOL syntax – Terms FOL syntax – Formulas Def.: The set of Formulas is defined inductively as follows: We first introduce: k If t1, . , tk Terms and P is a k-ary predicate, then A set Vars = x1, . , xn of individual variables (i.e., variables ∈ { } P k(t , . , t ) Formulas (atomic formulas). that denote single objects). 1 k ∈ If t , t Terms, then t = t Formulas. A set of functions symbols, each of given arity 0. 1 2 ∈ 1 2 ∈ ≥ If ϕ Formulas and ψ Formulas then Functions of arity 0 are called constants. ∈ ∈ ϕ Formulas ϕ¬ ∈ψ Formulas ∧ ∈ Def.: The set of Terms is defined inductively as follows: ϕ ψ Formulas ϕ ∨ ψ∈ Formulas Vars Terms; → ∈ ⊆ If ϕ Formulas and x Vars then k ∈ ∈ If t1, . , tk Terms and f is a k-ary function symbol, then x.ϕ Formulas k ∈ ∃ ∈ f (t1, . , tk) Terms; x.ϕ Formulas ∈ ∀ ∈ Nothing else is in Terms. Nothing else is in Formulas. Note: a predicate of arity 0 is a proposition of propositional logic. D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (7/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (8/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic Outline Interpretations Given an alphabet of predicates P1,P2,... and functions f1, f2,..., each with an associated arity, a FOL interpretation is: 1 Syntax of first-order logic = (∆I ,P I ,P I , . , f I , f I ,...) I 1 2 1 2 2 Semantics of first-order logic where: ∆I is the domain (a set of objects) 3 First-order logic queries if P is a k-ary predicate, then P ∆ ∆ (k times) i iI ⊆ I × · · · × I if f is a k-ary function, then f : ∆ ∆ ∆ (k times) i iI I × · · · × I −→ I if f is a constant (i.e., a 0-ary function), then f : () ∆ i iI −→ I (i.e., fi denotes exactly one object of the domain) unibz.it D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (9/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (10/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic Assignment Truth in an interpretation wrt an assignment We define when a FOL formula ϕ is true in an interpretation wrt an Let Vars be a set of (individual) variables. I assignment α, written , α = ϕ: I | Def.: Given an interpretation , an assignment is a function , α = P (t , . , t ) if (ˆα(t ),..., αˆ(t )) P I I | 1 k 1 k ∈ I , α = t = t if αˆ(t ) =α ˆ(t ) I | 1 2 1 2 α : Vars ∆I , α = ϕ if , α = ϕ −→ I | ¬ I 6| that assigns to each variable x Vars an object α(x) ∆ . , α = ϕ ψ if , α = ϕ and , α = ψ I I | ∧ I | I | ∈ ∈ , α = ϕ ψ if , α = ϕ or , α = ψ I | ∨ I | I | , α = ϕ ψ if , α = ϕ implies , α = ψ I | → I | I | It is convenient to extend the notion of assignment to terms. We can do , α = x.ϕ if for some a ∆ we have , α[x a] = ϕ I | ∃ ∈ I I 7→ | so by defining a function αˆ : Terms ∆I inductively as follows: , α = x.ϕ if for every a ∆ we have , α[x a] = ϕ −→ I | ∀ ∈ I I 7→ | αˆ(x) = α(x), if x Vars ∈ Here, α[x a] stands for the new assignment obtained from α as αˆ(f(t1, . , tk)) = f I (ˆα(t1),..., αˆ(tk)) 7→ follows: α[x a](x) = a 7→ Note: for constants αˆ(c) = cI . α[x a](y) = α(y) for y = x 7→ 6 D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (11/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (12/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic Open vs. closed formulas Outline Definitions A variable x in a formula ϕ is free if x does not occur in the scope of any quantifier, otherwise it is bounded. 1 Syntax of first-order logic An open formula is a formula that has some free variable. A closed formula, also called sentence, is a formula that has no free 2 Semantics of first-order logic variables. For closed formulas (but not for open formulas) we can define what it 3 First-order logic queries means to be true in an interpretation, written = ϕ, without I | mentioning the assignment, since the assignment α does not play any role in verifying , α = ϕ. I | Instead, open formulas are strongly related to queries — cf. relational databases. unibz.it D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (13/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (14/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic FOL queries FOL boolean queries Def.: A FOL query is an (open) FOL formula. Def.: A FOL boolean query is a FOL query without free variables. When ϕ is a FOL query with free variables (x1, . , xk), then we sometimes write it as ϕ(x1, . , xk), and say that ϕ has arity k. Hence, the answer to a boolean query ϕ() is defined as follows: Given an interpretation , we are interested in those assignments that I map the variables x1, . , xk (and only those). We write an assignment ϕ()I = () , = ϕ() { | I hi | } α s.t. α(x ) = a , for i = 1, . , k, as a , . , a . i i h 1 ki Def.: Given an interpretation , the answer to a query ϕ(x , . , x ) is I 1 k Such an answer is ϕ(x1, . , xk)I = (a1, . , ak) , a1, . , ak = ϕ(x1, . , xk) (), if = ϕ { | I h i | } I | , if = ϕ. Note: We will also use the notation ϕI , which keeps the free variables ∅ I 6| implicit, and ϕ( ) making apparent that ϕ becomes a functions from As an obvious convention we read () as “true” and as “false”. I ∅ interpretations to set of tuples. D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (15/66) D. Calvanese Part 1: First-Order Queries KBDB – 2007/2008 (16/66) Syntax of first-order logic Semantics of first-order logic First-order logic queries Syntax of first-order logic Semantics of first-order logic First-order logic queries Chap. 1: First-Order Logic Chap. 1: First-Order Logic FOL formulas: logical tasks FOL queries – Logical tasks Validity: if ϕ is valid, then ϕ = ∆ ∆ for all , i.e., the I I × · · · × I I Definitions query always returns all the tuples of . I Validity: ϕ is valid iff for all and α we have that , α = ϕ. Satisfiability: if ϕ is satisfiable, then ϕ = for some , i.e., the I 6 ∅ I I I | query returns at least one tuple. Satisfiability: ϕ is satisfiable iff there exists an and α such that Logical implication: if ϕ logically implies ψ, then ϕ ψ for all I I ⊆ I , α = ϕ, and unsatisfiable otherwise.