What is a Logic Program Introduction to Logic Programming Foundations, First-Order Language ◮ Logic program is a set of certain formulas of a first-order language. Temur Kutsia ◮ In this lecture: syntax and semantics of a first-order language. Research Institute for Symbolic Computation Johannes Kepler University Linz, Austria kutsia@risc.jku.at Introductory Examples Introductory Examples ◮ Representing “John loves Mary”: loves ( John , Mary ) . ◮ loves : a binary predicate (relation) symbol. ◮ father : A unary function symbol. ◮ Intended meaning: The object in the first argument of loves ◮ Intended meaning: The father of the object in its argument. loves the object in its second argument. ◮ John’s father loves John: loves ( father ( John ) , John ) . ◮ John , Mary : constants. ◮ Intended meaning: To denote persons John and Mary, respectively.
First-Order Language Syntax ◮ Alphabet ◮ Syntax ◮ Terms ◮ Semantics ◮ Formulas Alphabet Terms A first-order alphabet consists of the following disjoint sets of Definition symbols: ◮ A countable set of variables V . ◮ A variable is a term. ◮ For each n ≥ 0 , a set of n -ary function symbols F n . ◮ If t 1 , . . . , t n are terms and f ∈ F n , then f ( t 1 , . . . , t n ) is a term. Elements of F 0 are called constants. ◮ Nothing else is a term. ◮ For each n ≥ 0 , a set of n -ary predicate symbols P n . Notation: ◮ Logical connectives ¬ , ∨ , ∧ , ⇒ , ⇔ . ◮ s , t , r for terms. ◮ Quantifiers ∃ , ∀ . ◮ Parenthesis ‘(’, ‘)’, and comma ‘,’. Example Notation: ◮ plus ( plus ( x , 1 ) , x ) is a term, where plus is a binary function ◮ x , y , z for variables. symbol, 1 is a constant, x is a variable. ◮ f , g for function symbols. ◮ father ( father ( John )) is a term, where father is a unary ◮ a , b , c for constants. function symbol and John is a constant. ◮ p , q for predicate symbols.
Formulas Eliminating Parentheses Definition ◮ If t 1 , . . . , t n are terms and p ∈ P n , then p ( t 1 , . . . , t n ) is a ◮ Excessive use of parentheses often can be avoided by formula. It is called an atomic formula. introducing binding order. ◮ If A is a formula, ( ¬ A ) is a formula. ◮ ¬ , ∀ , ∃ bind stronger than ∨ . ◮ If A and B are formulas, then ( A ∨ B ) , ( A ∧ B ) , ( A ⇒ B ) , and ◮ ∨ binds stronger than ∧ . ( A ⇔ B ) are formulas. ◮ ∧ binds stronger than ⇒ and ⇔ . ◮ If A is a formula, then ( ∃ x . A ) and ( ∀ x . A ) are formulas. ◮ Furthermore, omit the outer parentheses and associate ◮ Nothing else is a formula. ∨ , ∧ , ⇒ , ⇔ to the right. Notation: ◮ A , B for formulas. Eliminating Parentheses Example Translating English sentences into first-order logic formulas: Example 1. Every rational number is a real number. The formula ∀ x . ( rational ( x ) ⇒ real ( x )) ( ∀ y . ( ∀ x . (( p ( x )) ∧ ( ¬ r ( y ))) ⇒ (( ¬ q ( x )) ∨ ( A ∨ B ))))) 2. There exists a number that is prime. ∃ x . prime ( x ) due to binding order can be rewritten into 3. For every number x , there exists a number y such that ( ∀ y . ( ∀ x . ( p ( x ) ∧ ¬ r ( y ) ⇒ ¬ q ( x ) ∨ ( A ∨ B )))) x < y . ∀ x . ∃ y . x < y which thanks to the convention of the association to the right and omitting the outer parentheses further simplifies to Assume: ◮ rational , real , prime : unary predicate symbols. ∀ y . ∀ x . ( p ( x ) ∧ ¬ r ( y ) ⇒ ¬ q ( x ) ∨ A ∨ B ) . ◮ < : binary predicate symbol.
Example Semantics Translating English sentences into first-order logic formulas: 1. There is no natural number whose immediate successor is 0. ¬∃ x . zero . ◮ Meaning of a first-order language consists of an universe = succ ( x ) and an appropriate meaning of each symbol. 2. For each natural number there exists exactly one ◮ This pair is called structure. immediate successor natural number. ∀ x . ∃ y . ( y . = succ ( x ) ∧ ∀ z . ( z . = succ ( x ) ⇒ y . ◮ Structure fixes interpretation of function and predicate = z )) symbols. 3. For each nonzero natural number there exists exactly one ◮ Meaning of variables is determined by a variable immediate predecessor natural number. assignment. ∀ x . ( ¬ ( x . = zero ) ⇒ ∃ y . ( y . = pred ( x ) ∧ ∀ z . ( z . = pred ( x ) ⇒ y . = z ))) ◮ Interpretation of terms and formulas. Assume: ◮ zero : constant ◮ succ , pred : unary function symbols. ◮ . = : binary predicate symbol. Structure Variable Assignment ◮ Structure: a pair ( D , I ) . ◮ A structure S = ( D , I ) is given. ◮ D is a nonempty universe, the domain of interpretation. ◮ Variable assignment σ S maps each x ∈ V into an element ◮ I is an interpretation function defined on D that fixes the of D : σ S ( x ) ∈ D . meaning of each symbol associating ◮ Given a variable x , an assignment ϑ S is called an x -variant ◮ to each f ∈ F n an n -ary function f I : D n → D , of σ S iff ϑ S ( y ) = σ S ( y ) for all y � = x . (in particular, c I ∈ D for each constant c ) ◮ to each p ∈ P n different from . = , an n -ary relation p I on D .
Interpretation of Terms Interpretation of Formulas ◮ A structure S = ( D , I ) and a variable assignment σ S are ◮ A structure S = ( D , I ) and a variable assignment σ S are given. given. ◮ Value of an atomic formula under S and σ S is one of true , ◮ Value of a term t under S and σ S , Val S ,σ S ( t ) : false : ◮ Val S ,σ S ( s . ◮ Val S ,σ S ( x ) = σ S ( x ) . = t ) = true iff Val S ,σ S ( s ) = Val S ,σ S ( t ) . ◮ Val S ,σ S ( f ( t 1 , . . . , t n )) = f I ( Val S ,σ S ( t 1 ) , . . . , Val S ,σ S ( t n )) . ◮ Val S ,σ S ( p ( t 1 , . . . , t n )) = true iff ( Val S ,σ S ( t 1 ) , . . . , Val S ,σ S ( t n )) ∈ p I . Interpretation of Formulas Interpretation of Formulas ◮ A structure S = ( D , I ) and a variable assignment σ S are given. ◮ Values of compound formulas under S and σ S are also either true or false : ◮ A structure S = ( D , I ) is given. ◮ Val S ,σ S ( ¬ A ) = true iff Val S ,σ S ( A ) = false . ◮ The value of a formula A under S is either true or false : ◮ Val S ,σ S ( A ∨ B ) = true iff Val S ,σ S ( A ) = true or Val S ,σ S ( B ) = true . ◮ Val S ( A ) = true iff Val S , σ S ( A ) = true for all σ S . ◮ Val S ,σ S ( A ∧ B ) = true iff ◮ S is called a model of A iff Val S ( A ) = true . Val S ,σ S ( A ) = true and Val S ,σ S ( B ) = true . ◮ Written � S A . ◮ Val S ,σ S ( A ⇒ B ) = true iff Val S ,σ S ( A ) = false or Val S ,σ S ( B ) = true . ◮ Val S ,σ S ( A ⇔ B ) = true iff Val S ,σ S ( A ) = Val S ,σ S ( B ) . ◮ Val S ,σ S ( ∃ x . A ) = true iff Val S ,ϑ S ( A ) = true for some x -variant ϑ S of σ S . ◮ Val S ,σ S ( ∀ x . A ) = true iff Val S ,ϑ S ( A ) = true for all x -variants ϑ S of σ S .
Example Validity, Unsatisfiability ◮ A formula A is valid, if � S A for all S . ◮ Formula: ∀ x . ( p ( x ) ⇒ q ( f ( x ) , a )) ◮ Written � A . ◮ Define S = ( D , I ) as ◮ A formula A is unsatisfiable, if � S A for no S . ◮ D = { 1 , 2 } , ◮ If A is valid, then ¬ A is unsatisfiable and vice versa. ◮ a I = 1 , ◮ The notions extend to (multi)sets of formulas. ◮ f I ( 1 ) = 2 , f I ( 2 ) = 1 , ◮ p I = { 2 } , ◮ For { A 1 , . . . , A n } , just formulate them for A 1 ∧ · · · ∧ A n . ◮ q I = { ( 1 , 1 ) , ( 1 , 2 ) , ( 2 , 2 ) } . ◮ If σ S ( x ) = 1 , then Val S ,σ S ( ∀ x . ( p ( x ) ⇒ q ( f ( x ) , a ))) = true . ◮ If σ S ( x ) = 2 , then Val S ,σ S ( ∀ x . ( p ( x ) ⇒ q ( f ( x ) , a ))) = true . Non-valid Valid Unsat sat ◮ Hence, � S A . Validity, Unsatisfiability Logical Consequence Definition A formula A is a logical consequence of the formulas B 1 , . . . , B n , if every model of B 1 ∧ · · · ∧ B n is a model of A . Non-valid Valid Unsat sat Example ◮ mortal ( socrates ) is a logical consequence of ∀ x . ( person ( x ) ⇒ mortal ( x )) and person ( socrates ) . ◮ ∀ x . p ( x ) ⇒ ∃ y . p ( y ) is valid. ◮ cooked ( apple ) is a logical consequence of ◮ p ( a ) ⇒ ¬∃ x . p ( x ) is satisfiable non-valid. ∀ x . ( ¬ cooked ( x ) ⇒ tasty ( x )) and ¬ tasty ( apple ) . ◮ ∀ x . p ( x ) ∧ ∃ y . ¬ p ( y ) is unsatisfiable. ◮ genius ( einstein ) is not a logical consequence of ∃ x . person ( x ) ∧ genius ( x ) and person ( einstein ) .
Recommend
More recommend