Logic Logic Roadmap

Logic (M´etodos Formais em Engenharia de Software) Classical Propositional Logic Classical First-Order Logic

￿ syntax; semantics; validity; satisfiability; modeling with FOL Maria Jo˜ao Frade ￿ normal forms; Herbrandization; Skolemization; Herbrand’s theorem; semi-decidability; decidable fragments Departmento de Inform´atica ￿ FOL with equality; many-sorted FOL Universidade do Minho First-Order Theories 2011/2012 Natural Deduction

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 1 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 2 / 44 Logic Logic (Classical) First-Order Logic Introduction

First-order logic (FOL) is a richer language than propositional logic. Its lexicon contains not only the symbols , , ,and (and parentheses) from ∧ ∨ ¬ → propositional logic, but also the symbols and for “there exists” and “for all”, ∃ ∀ along with various symbols to represent variables, constants, functions, and (Classical) First-Order Logic relations. There are two sorts of things involved in a first-order logic formula: terms, which denote the objects that we are talking about; formulas, which denote truth values.

Examples: “Not all birds can fly.” “Every mother is older than her children.” “John and Peter have the same maternal grandmother.”

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 3 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 4 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Syntax Syntax

Terms The alphabet of a first-order language is organised into the following The set of terms of a first-order language over a vocabulary is given by categories. V the following abstract syntax Variables: x, y, z, . . . (arbitrary elements of an underlying domain) ∈X Constants: a, b, c, . . . (specific elements of an underlying domain) Term t ::= x c f(t1,...,tar(f)) ∈C V ￿ | | Functions: f,g,h,... (every function f as a fixed arity, ar(f)) ∈F Formulas Predicates: P, Q, R, . . . (every predicate P as a fixed arity, ar(P )) ∈P The set Form , of formulas of FOL, is given by the abstract syntax Logical connectives: , , , , , , (for all), (there exists) V ￿ ⊥ ∧ ∨ ¬ → ∀ ∃ Auxiliary symbols: “.”, “(“ and “)”. Form φ,ψ ::= P (t1,...,tar(P )) ( φ) (φ ψ) (φ ψ) V ￿ |⊥|￿| ¬ | ∧ | ∨ (φ ψ) ( x. φ) ( x. φ) | → | ∀ | ∃ We assume that all these sets are disjoint. , and are the non-logical C F P symbols of the language. These three sets constitute the vocabulary An atomic formula has the form , ,orP (t1,...,tar(P )).Aground term is a ⊥ ￿ = . term without variables. Ground formulas are formulas without variables, i.e., V C∪F∪P quantifier-free formulas φ such that all terms occurring in φ are ground terms.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 5 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 6 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Syntax Modeling with FOL

Convention “Not all birds can fly.” We adopt some syntactical conventions to lighten the presentation of We can code this sentence assuming the two unary predicates B and F formulas: expressing B(x) – x is a bird Outermost parenthesis are usually dropped. F (x) – x can fly In absence of parentheses, we adopt the following convention about precedence. Ranging from the highest precedence to the lowest, we The declarative sentence “Not all birds can fly” can now be coded as have respectively: , , and .Finallywehavethat binds ¬ ∧ ∨ → → more tightly than and . x. B(x) F (x) ∀ ∃ ¬∀ → All binary connectives are right-associative. or, alternatively, as Nested quantifications such as x. y.φ are abbreviated to x, y. φ. ∀ ∀ ∀ x.B(x) F (x) x.φ denotes the nested quantification x ,...,x .φ. ∃ ∧¬ ∀ ∀ 1 n

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 7 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 8 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Modeling with FOL Modeling with FOL

“Every mother is older than her children.” Assume further the following predicates and constant symbols “John and Peter have the same maternal grandmother.” flower(x) – x is a flower likes(x, y) – x likes y sport(x) – x is a sport brother(x, y) – x is brother of y Using constants symbols j and p for John and Peter, and predicates =, mother a –Anne and older expressing that mother(x, y) – x is a mother of y “Anne likes John’s brother.” x. brother(x, j) likes(a, x) ∃ ∧ older(x, y) – x is older than y “John likes all sports.” x. sports(x) likes(j ,x) these sentences could be expressed by ∀ → “John’s mother likes flowers.” x. flower(x) likes(m(j ),x) x. y. mother(x, y) older(x, y) ∀ → ∀ ∀ → “John’s mother does not like some sports.” y.sport(y) likes(m(j ),y) ∃ ∧¬ x, y, u, v. mother(x, y) mother(y, j ) mother(u, v) mother(v, p) x = u “Peter only likes sports.” x. likes(p,x) sports(x) ∀ ∧ ∧ ∧ → ∀ → A different and more elegant encoding is to represent y’mother in a more direct “Anne has two children.” way, by using a function instead of a relation.Wewritem(y) to mean y’mother. This way the two sentences above have simpler encondings. x1,x2. mother(a, x1) mother(a, x2) x1 = x2 ∃ ∧ ∧ ￿ ∧ z. mother(a, z) z = x1 z = x2 x. older(m(x),x) and m(m(j)) = m(m(p)) ∀ → ∨ ∀

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 9 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 10 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Free and bound variables Substitution

Substitution The free variables of a formula φ are those variables occurring in φ that are not quantified. FV(φ) denotes the set of free variables occurring in φ. We define u[t/x] to be the term obtained by replacing each occurrence of variable x in u with t. The bound variables of a formula φ are those variables occurring in φ that do have quantifiers. BV(φ) denote the set of bound variables occurring in φ. We define φ[t/x] to be the formula obtained by replacing each free occurrence of variable x in φ with t.

Note that variables can have both free and bound occurrences within the same Care must be taken, because substitutions can give rise to undesired formula. Let φ be x. R(x, y) y. P(y, x),then ∃ ∧∀ effects. FV(φ)= y and BV(φ)= x, y . { } { } Given a term t,avariablex and a formula φ,wesaythatt is free for x in φ if no free x in φ occurs in the scope of z or z for any variable z ∀ ∃ Aformulaφ is closed (or asentence) if it does not contain any free variables. occurring in t. If FV(φ)= x ,...,x ,then { 1 n} From now on we will assume that all substitutions satisfy this condition. ￿ its universal closure is x .... x .φ ∀ 1 ∀ n That is when performing the φ[t/x] we are always assuming that t is free ￿ its existential closure is x .... x .φ ∃ 1 ∃ n for x in φ.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 11 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 12 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Substitution Semantics

Convention -structure We write φ(x ,...,x ) to denote a formula having free variables V 1 n Let be a vocabulary. A -structure is a pair =(D, I) where D is a x1,...,xn.Wewriteφ(t1,...,tn) to denote the formula obtained by nonemptyV set called the interpretationV M domain,andMI is an interpretation function replacing each free occurrence of xi in φ with the term ti.Whenusing that assigns constants, functions and predicates over D to the symbols of as V this notation, it should always be assumed that each ti is free for xi in φ. follows: Also note that when writhing φ(x1,...,xn) we do not mean that x1,...,xn for each constant symbol c , the interpretation of c is a constant are the only free variables of φ. I(c) D; ∈C ∈ for each f , the interpretation of f is a function I(f):Dar(f) D; ∈F → ar(P ) A sentence of first-order logic is a formula having no free variables. for each P , the interpretation of P is a function I(P ):D 0, 1 . In particular,∈P 0-ary predicate symbols are interpreted as truth values.→{ }

The presence of free variables distinguishes formulas from sentences. -structures are also called models for . This distinction did not exist in propositional logic. V V

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 13 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 14 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Semantics Semantics

Assignment Satisfaction relation An assignment for a domain D is a function α : D. Given a -structure =(D, I) and given an assignment α : D,we X→ V M X→ define the satisfaction relation ,α = φ for each φ Form as follows: We denote by α[x a] the assignment which maps x to a and any other M | ∈ V ￿→ variable y to α(y). ,α = M | ￿ ,α = M ￿| ⊥ ,α = P (t1,...,tn) iff I(P )(α (t1),...,α (tn)) = 1 M | M M ,α = φ iff ,α = φ Given a -structure =(D, I) and given an assignment α : D,we M | ¬ M ￿| V M X→ ,α = φ ψ iff ,α = φ and ,α = ψ define an interpretation function for terms, α : Term D, as follows: M | ∧ M | M | M V → ,α = φ ψ iff ,α = φ or = ψ M | ∨ M | M| α (x)=α(x) ,α = φ ψ iff ,α = φ or ,α = ψ M M | → M ￿| M | α (c)=I(c) ,α = x. φ iff ,α[x a] = φ for all a D M M | ∀ M ￿→ | ∈ α (f(t1,...,tn)) = I(f)(α (t1),...,α (tn)) ,α = x. φ iff ,α[x a] = φ for some a D M M M M | ∃ M ￿→ | ∈

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 15 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 16 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Validity and satisfiability Consequence and equivalence

When ,α = φ,wesaythat satisfies φ with α. M | M Given a set of formulas Γ,amodel and an assignment α, is said to satisfy We write = φ iff ,α = φ holds for every assignment α. M M M| M | Γ with α, denoted by ,α =Γ,if ,α = φ for every φ Γ. M | M | ∈ Aformulaφ is Γ entails φ (or that φ is a logical consequence of Γ), denoted by Γ = φ,iffforall structures and assignments α,whenever ,α =Γholds, then | ,α = φ valid iff ,α = φ holds for all structure and assignments α. M M | M | AvalidformulaiscalledaM | tautologyM.Wewrite= φ. holds as well. | satisfiable iffthere is some structure and some assigment α φ is logically equivalent to ψ, denoted by φ ψ,iff φ = ψ and ψ = φ. such that ,α = φ holds.M ≡ { }| { }| M | unsatisfiable iffit is not satisfiable. Deduction theorem An unsatisfiable formula is called a contradiction. Γ,φ = ψ iff Γ = φ ψ | | → refutable iffit is not valid.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 17 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 18 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Consistency Substitution

The set Γ is consistent or satisfiable iffthere is a model and an Formula ψ is a subformula of formula φ if it occurs syntactically M assigment α such that ,α = φ holds for all φ Γ. within φ. M | ∈

We say that Γ is inconsistent iffit is not consistent and denote this by Formula ψ is a strict subformula of φ if ψ is a subformula of φ and Γ = . ψ = φ | ⊥ ￿

Proposition Substitution theorem φ, φ = Suppose φ ψ.Letθ be a formula that contains φ as a subformula. Let { ¬ }| ⊥ ≡ If Γ = and Γ Γ ,thenΓ = . θ be the formula obtained by safe replacing (i.e., avoiding the capture of | ⊥ ⊆ ￿ ￿ | ⊥ ￿ Γ = φ iff Γ, φ = free variables of φ) some occurrence of φ in θ with ψ.Thenθ θ￿. | ¬ | ⊥ ≡

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 19 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 20 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Adquate sets of connectives for FOL Decidability

Renaming of bound variables Given formulas φ and ψ as input, we may ask: If y is free for x in φ and y FV(φ), then the following equivalences hold. ￿∈ Decision problems x.φ y.φ[y/x] ∀ ≡∀ Validity problem: “Is φ valid ?” x.φ y.φ[y/x] ∃ ≡∃ Satisfiability problem: “Is φ satisfiable ?” Consequence problem: “Is ψ a consequence of φ ?” Lemma Equivalence problem: “Are φ and ψ equivalent ?” The following equivalences hold in first-order logic.

x.φ ψ ( x.φ) ( x.ψ) x.φ ψ ( x.φ) ( x.ψ) These are, in some sense, variations of the same problem. ∀ ∧ ≡ ∀ ∧ ∀ ∃ ∨ ≡ ∃ ∨ ∃ x.φ ( x.φ) φ[t/x] x.φ ( x.φ) φ[t/x] ∀ ≡ ∀ ∧ ∃ ≡ ∃ ∨ φ is valid iff φ is unsatisfiable x.φ x. φ x.φ x. φ ¬ ¬∀ ≡∃ ¬ ¬∃ ≡∀ ¬ φ = ψ iff (φ ψ) is unsatisfiable | ¬ → φ ψ iff φ = ψ and ψ = φ ≡ | | As in propositional logic, there is some redundancy among the connectives φ is satisfiable iff φ is not valid and quantifiers since x. φ x. φ and x. φ x. φ. ¬ ∀ ≡¬∃ ¬ ∃ ≡¬∀ ¬ Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 21 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 22 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Decidability Semi-decidability

A solution to a decision problem is a program that takes problem instances However, there is a procedure that halts and says “yes” if φ is valid. as input and always terminates, producing a correct “yes” or “no” output. A decision problem is semi-decidable if exists a procedure that, given an A decision problem is decidable if it has a solution. input, A decision problem is undecidable if it is not decidable. halts and answers “yes” iff“yes” is the correct answer, In PL we could, in theory, compute a truth table to determine whether or not a halts and answers “no” if “no” is the correct answer, or formula is satisfiable. In FOL, we would have to check every model to do this. does not halt if “no” is the correct answer Theorem (Church & Turing) Unlike a decidable problem, the procedure is only guaranteed to halt if the The decision problem of validity in first-order logic is undecidable:no correct answer is “yes”. program exists which, given any φ,decideswhether= φ. | The decision problem of satisfiability in first-order logic is undecidable: The decision problem of validity in first-order logic is semi-decidable. no program exists which, given any φ,decideswhetherφ is satisfiable.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 23 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 24 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Normal forms Normal forms

Afirst-orderformulaisinnegation normal form (NNF) if the implication connective is not used in it, and negation is only applied to atomic Aformulaisinprenex form if it is of the form Q1x1.Q2x2....Qnxn.ψ where each Q is a quantifier (either or )andψ is a quantifier-free formulas. i ∀ ∃ formula. If x does not occur free in ψ, then the following equivalences hold.

( x.φ) ψ x.φ ψψ( x.φ) x.ψ φ Prenex form of x.( y.P (x, y) Q(x)) z.P (x, z) ∀ ∧ ≡∀ ∧ ∧ ∀ ≡∀ ∧ ∀ ∀ ∨ →∃ ( x.φ) ψ x.φ ψψ( x.φ) x.ψ φ First we compute the NNF and then we go for the prenex form. ∀ ∨ ≡∀ ∨ ∨ ∀ ≡∀ ∨ ( x.φ) ψ x.φ ψψ( x.φ) x.ψ φ x.( y.P(x, y) Q(x)) z.P(x, z) ∃ ∧ ≡∃ ∧ ∧ ∃ ≡∃ ∧ ∀ ∀ ∨ →∃ ≡ ( x.φ) ψ x.φ ψψ( x.φ) x.ψ φ x. ( y.P(x, y) Q(x)) z.P(x, z) ∃ ∨ ≡∃ ∨ ∨ ∃ ≡∃ ∨ ∀ ¬ ∀ ∨ ∨∃ ≡ (NNF) x. y.( P (x, y) Q(x)) z.P(x, z) ∀ ∃ ¬ ∧¬ ∨∃ ≡ (prenex) x. y. z.( P (x, y) Q(x)) P (x, z) The applicability of these equivalences can always be assured by ∀ ∃ ∃ ¬ ∧¬ ∨ appropriate renaming of bound variables.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 25 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 26 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Herbrand/Skolem normal forms Herbrandization/Skolemization

Aformulaφ and its Herbrandization/Skolemization are not logically equivalent. Let φ be a first-order formula in . Proposition H The Herbrandization of φ (written φ ) is an existential formula obtained Let φ be a first-order formula in prenex normal form. from φ by repeatedly and exhaustively applying the following transformation: φ is valid iff its Herbrandization φH is valid. x ,...,x . y.ψ x ,...,x .ψ[f(x ,...,x )/y] S ∃ 1 n ∀ ￿ ∃ 1 n 1 n φ is unsatisfiable iff its Skolemization φ is unsatisfiable. with f a fresh function symbol with arity n (i.e. f does not occur in ψ). The Skolemization of φ (written φS) is a universal formula obtained from φ It is convenient to write Herbrand and Skolem formulas using vector notation x.ψ and x.ψ (with ψ quantifier free), respectively. by repeatedly applying the transformation: ∃ ∀ The quantifier-free sub-formula can be furthered normalised: x1,...,xn y.ψ ￿ x1,...,xn.ψ[f(x1,...,xn)/y] ∀ ∃ ∀ ￿ Universal CNF: x. lij ∀ i j ￿ Existencial DNF: x. lij with f a fresh function symbol with arity n. ∃ ￿i ￿j where literals are either atomic predicates or negation of atomic predicates. Herbrand normal form (resp. Skolem normal form) formulas are those ￿ ￿ obtained by the process of Herbrandization (resp. Skolemization). Herbrandization/Skolemization change the underlying vocabulary. These additional symbols are called Herbrand/Skolem functions.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 27 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 28 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Herbrandization/Skolemization Herbrand models

Herbrand interpretation Let be a first-order vocabulary and assume has at least one constant symbol The requirement that the original formula be in prenex normal form is too (otherwise,V we explicitly expand the vocabularyV with such a symbol). A Herbrand strong: Skolemization/Herbrandization can be applied to formulas in Interpretation =(D ,I ) is a -structure specified by a set of closed atomic negative normal form. In fact, this relaxation results in potentially simpler predicates (i.e.H atomicH predicatesH appliedV to ground terms), also denoted by . Skolem normal forms (with fewer Skolem functions, or functions with lower The interpretation structure is given as follows: H arity). Interpretation domain: D is the set of ground terms for the vocabulary . It is called the Herbrand universeH for . V V Herbrand (resp. Skolem) normal form is important since it allows to reduce Interpretation of constants:foreveryc , I (c)=c; validity (resp. unsatisfiability) of a first-order formula to the existence of ∈V H suitable instances of a quantifier-free formula, considering models Interpretation of functions:foreveryf with ar(f)=n, I (f) consists ∈V H constructed directly from the syntax of terms. of the n-ary function that, given ground terms t1,...,tn, returns the ground term f(t1,...,tn); Interpretation of predicates: for every P with ar(P )=n, I (P ) is the n-ary relation (t ,...,t ) P (t ,...,t ∈) V . H { 1 n | 1 n ∈H}

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 29 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 30 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Herbrand’s theorem Semi-decidability

Lemma Theorem An existential formula φ is valid ifffor every Herbrand model , The problem of validity of first-order formulas is semi-decidable,i.e.there H = φ. exists a procedure that, given a first-order formula, answers “yes” iffthe H| formula is valid (but might not terminate if the formula is not valid). Auniversalformulaφ is unsatisfiable iffthere exists no Herbrand model such that = φ. H H| An interesting refinement is to investigate fragments in which bounds can be established for searching the ground instance space. Herbrand’s Theorem An existential first-order formula x.ψ (with ψ quantifier-free) is valid ∃ This immediately leads to a bound on the number of instances whose iffthere exists an integer k and ground instances ψσ ,...,ψσ such 1 k search is required by Herbrand’s theorem, turning validity of formulas that ψσ ... ψσ is propositionally valid. 1 ∨ ∨ k decidable. Auniversalformula x.ψ (with ψ quantifier-free) is unsatisfiable iff ∀ there exists an integer k and closed instances ψσ ,...,ψσ such that 1 k Clearly if the set of ground terms is finite, the set of ground instances ψσ ψσ is propositionally unsatisfiable. 1 ∧···∧ k of the formula under scrutiny will be finite as well.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 31 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 32 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Semi-decidability Decidable fragments

Consider a vocabulary with two constants 1 and 2, and two unary predicates P and Q. To prove the validity of the formula x. (P (x) y. P(y)),wecan If the underlying vocabulary has a finite set of constants and no function ∃ →∀ symbol, the set of ground terms is finite. Note however that function 1 Calculate the prenex normal form equivalent of the formula. symbols might be introduced during the Herbrandization/Skolemization. x. y. ( P (x) P (y)) ∃ ∀ ¬ ∨ 2 Calculate the Herbrandization of the result. This process introduces a new Restricting attention to formulas whose prenex normal form has the shape function f in the vocabulary. x. y. ψ ensures that only constants are introduced by Herbrandization. ∀ ∃ x. P (x) P (f(x)) ￿ This fragment of formulas is normally known as the AE fragment. ∃ ¬ ∨

3 The set of ground terms for the new vocabulary is ￿ The class of formulas can be further enlarged by observing that a 1, 2,f(1),f(2),f(f(1)),f(f(2)),... { } formula not in AE may be equivalent to one in AE (e.g. miniscope – 4 Using the Herbrand’s Theorem we can say that x. P (x) P (f(x)) is pushing existential quantifiers inside the formula, thus minimizing their valid, because the formula ∃ ¬ ∨ scopes). ( P (1) P (f(1))) ( P (2) P (f(2))) ( P (f(1)) P (f(f(1)))) ¬ ∨ ∨ ¬ ∨ ∨ ¬ ∨ x. y. P(x) Q(y) x.P (x) y.Q(y) y. x. P (x) Q(y) ∃ ∀ ∨ ≡∃ ∨∀ ≡∀ ∃ ∨ 5 Hence, x. (P (x) y. P(y)) is valid. ∃ →∀ Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 33 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 34 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Decidable fragments FOL with equality

There are different conventions for dealing with equality in first-order logic. We have follow the approach of considering equality predicate (=)asa Although first-order validity is undecidable, there are special simple non-logical symbol, treated in the same way as any other predicate. fragments of FOL where it is decidable, e.g. We are working with what are usually known as “first-order languages without equality”. Monadic predicate logic (i.e. only unary predicates and no function An alternative approach, usually called “first-order logic with equality”, symbols) is decidable. considers equality as a logical symbol with a fixed interpretation.

The Bernays-Sch¨onfinkel class of formulas (i.e. formulas that can be In this approach the equality symbol (=)isinterpretedastheequality written with all quantiers appearing at the beginning of the formula relation in the domain of interpretation. So we have, for a structure =(D, I) and an assignment α : D,that with existentials before universals and that do not contain any M X→ function symbols) is decidable. ,α = t1 = t2 iff α (t1) and α (t2) are the same element of D M | M M

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 35 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 36 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic FOL with equality Many-sorted FOL

To understand the significant difference between having equality with the status A natural variant of first-order logic that can be considered is the one that of any other predicate, or with a fixed interpretation as in first-order logic with results from allowing different domains of elements to coexist in the equality, consider the formulas framework. This allows distinct “sorts” or types of objects to be distinguished at the syntactical level, constraining how operations and x ,x . y. y = x y = x predicates interact with these different sorts. ∃ 1 2 ∀ 1 ∨ 2 With a fixed interpretation of equality, the validity of this formula implies that the cardinality of the interpretation domain is at most two – the Having full support for different sorts of objects in the language allows for quantifiers can actually be used to fix the cardinality of the domain, which is cleaner and more natural encodings of whatever we are interested in not otherwise possible in first-order logic. modeling and reasoning about.

x ,x . (x = x ) ∃ 1 2 ¬ 1 2 By adding to the formalism of FOL the notion of sort, we can obtain a The validity of this formula implies that there exist at least two distinct flexible and convenient logic called many-sorted first-order logic, which has elements in the domain, thus its cardinality must be at least two. the same properties as FOL.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 37 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 38 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Many-sorted FOL Proof system

A many-sorted vocabulary (signature) is composed of a set of sorts, a set of So far we have taken the “semantic” approach to logic, with the aim function symbols, and a set of predicate symbols. of characterising the semantic concept of model, from which validity, satisfiability and semantic entailment were derived. ￿ Each function symbol f has associated with a type of the form S1 ... Sar(f) S where S1,...,Sar(f),S are sorts. × × → ￿ Each predicate symbol P has associated with it a type of the form However, this is not the only possible point of view. S1 ... Sar(P ). × × ￿ Each variable is associated with a sort. Instead of adopting the view based on the notion of truth, we can The formation of terms and formulas is done only accordingly to the typing think of logic as a codification of reasoning. This alternative approach policy, i.e., respecting the “sorts”. to logic, called “deductive”, focuses directly on the deduction relation The domain of discourse of any structure of a many-sorted vocabulary is that is induced on formulas, i.e., on what formulas are logical fragmented into different subsets, one for every sort. consequences of other formulas. The notions of assignment and structure for a many-sorted vocabulary, and the interpretation of terms and formulas are defined in the expected way. We will explore this perspective later in this course.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 39 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 40 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Exercises (from [Huth&Ryan 2004]) Exercises (from [Huth&Ryan 2004])

Use the predicates A(x, y): x admires yP(x): x is a professor B(x, y): x attended yS(x): x is a student Find appropriate predicates and their specification to translate the following L(x): x is a lecture into predicate logic:

and the nullary function symbol (constant) ’Mary’ to translate the following 1 All red things are in the box. into predicate logic: 2 Only red things are in the box. 1 Mary admires every professor. 3 No animal is both a cat and a dog. 2 Some professor admires Mary. 4 Every prize was won by a boy. 3 Mary admires herself. 5 A boy won every prize. 4 No student attended every lecture. 5 No lecture was attended by every student. 6 No lecture was attended by any student.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 41 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 42 / 44 Logic (Classical) First-Order Logic Logic (Classical) First-Order Logic Exercises (from [Huth&Ryan 2004]) Exercises (from [RSD 2011])

Let F (x, y) mean that x is the father of y; M(x, y) denotes x is the mother of y.Similarly,H(x, y), S(x, y),andB(x, y) say that x is the husband/sister/brother of y, respectively. You may also use constants to denote individuals, like ’Ed’ and ’Patsy’. However, you are not allowed to use any predicate symbols other than the above to translate the following Compute Herbrand and Skolem normal forms for each of the following sentences into predicate logic: formulas: 1 x.( y. z.P(x, y, z)) x. y. P (x, y, z) 1 Everybody has a mother. ∃ ∀ ∃ ∧∃ ∀ ¬ 2 x.( y.Q(x, y)) y. z.R(x, y, z) 2 Everybody has a father and a mother. ∀ ∃ ∨∀ ∃ 3 x.( y.P(x, y)) y.Q(x, y) 3 Whoever has a mother has a father. ∀ ∃ →∃ 4 x.P (x) ( y.Q(y)) y.R(x, f(x, y)) 4 Ed is a grandfather. ∀ ∧ ∀ →∃ 5 All fathers are parents. 6 All husbands are spouses. 7 No uncle is an aunt. 8 Nobody’s grandmother is anybody’s father. 9 Ed and Patsy are husband and wife. 10 Carl is Monique’s brother-in-law.

Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 43 / 44 Dep. Inform´atica, Univ. Minho Maria Jo˜aoFrade MFES 2011/12 44 / 44