Logic for Computer Science/First-Order Logic

From testwiki
Jump to navigation Jump to search

First-Order Logic

In propositional logic, we considered formulas made about atomic objects, which could only be either true or false. First-order logic, the topic of this chapter, builds upon propositional logic and allows you to look inside the objects discussed in formulas. We can provide this more refined level of granularity by discussing objects as elements of sets that can be larger than just the set {0,1}, and also include arbitrarily complex relationships with each other.

We begin first by defining the syntax of first-order (FO) logic, and then give these structures meaning.

Syntax

The domain of discourse for first order logic is first-order structures or models. A first-order structure contains

  1. Relations,
  2. Functions, and
  3. Constants (functions of arity 0).

The vocabulary of first-order logic is

  1. a set of relation symbols with associated arities, and
  2. a set of function symbols with associated arities.

Here are some example first-order logic vocabularies:

  1. A graph
    • Relation Set = { V : unary, E : binary }
    • Function Set = { 𝑛𝑒π‘₯𝑑 : unary }
  2. Arithmetic
    • Relation Set = { + : ternary, × : ternary,  : ternary, = : binary, < : binary}
    • Function Set = { 𝑛𝑒π‘₯𝑑 : unary, 0 : const }

Here, a graph is a set of vertices V and a set of edges E. For the arithmetic set note that the use of + and × is purely syntactic and we could have used the symbols "plus" and "times" instead. We haven't provided the symbols with any meaning yet.

A term denotes an element in the first-order structure. A term is used to refer to the elements in our domain of discourse. Here are the rules that describe what a term is:

  • every variable is a term, where a variable is simply another set of symbols
  • every constant is a term
  • If t1,t2,,tk are terms, and f is a k-ary function then f(t1,t2,,tk) is a term.

For example, if f is a binary function and g is a ternary function then the following are all terms: x,a,f(x,y),g(x,f(x,y),a).

An atomic formula is

R(t1,t2,,tk),

where R is a k-ary relation and t1,t2,,tk are terms. When viewing R as a set, then this is just another way of saying that the tuple

(t1,t2,,tk)R.

A special relation = means "equal" and cannot be interpreted otherwise. For example, t1=t2 stands for

=(t1,t2).

A first-order formula is an expression built using a given first-order vocabulary and variables and the symbols (,),¬,,,,,. The set of first-order formulas is the minimum set satisfying the following:

  • atomic formulas are first order formulas
  • If ϕ and ψ are formulas and x is a variable, then the following are also formulas:
  1. (ϕψ)
  2. (ϕψ)
  3. (¬ϕ)
  4. (ϕψ)
  5. (xϕ)
  6. (xϕ)

Semantics

A first-order structure over a given vocabulary consists of

  1. A domain, which is a set of elements (also known as a universe)
  2. A mapping associating to every k-ary relation symbol in the vocabulary a k-ary relation over the domain, and to every k-ary function symbol a k-ary function over the domain.

These components give meaning to the symbols.

Example:

Relation Set = { + : ternary, × : ternary,  : ternary, = : binary, < : binary }
Function Set = { next : unary, 0 : const }

A first-order structure over this vocabulary is:

  1. Domain: the set of integers
  2. Mapping : + addition, × multiplication, exponentiation, < ordering, 𝑛𝑒π‘₯𝑑i+1

In this structure, the formula

xyz[×(y,z,x)((y=1)(z=1))]

expresses the statement "there exists a prime number" (the number 1 also satisfies this statement).

Note here that ×(y,z,x) is equivalent to (x=y×z).

Scope of Quantifiers

In the formula (xϕ) or (xϕ), ϕ is referred to as the scope of quantification of the variable x. An occurrence of a variable in a formula is bound if it is in the scope of quantification of that variable, otherwise the occurrence is said to be free. You can consider a quantifier use as a variable declaration.

A sentence is a formula with no free variables (i.e., all variables are bound). A sentence is either true or false.

A formula with free variable(s) can be considered as describing the properties of the free variable(s). For example, ϕ(x) denotes a formula with x occurring free and describes the properties of x.

If a sentence ϕ evaluates to true over a structure I, we say I satisfies ϕ and denote this by Iϕ.

  • IR(t1,t2,,tk) iff (t1,t2,,tk)I(R), where I(R) is the interpretation of R by I.
  • Iϕψ iff Iϕ and Iψ. (Similar for .)
  • I¬φ iff I⊭φ.
  • Ixϕ(x) if Iϕ(xc) for some c in the domain.
  • Ixϕ(x) if Iϕ(xc) for every c in the domain.

Note: ϕ(xc) denotes the result of substituting c for every free occurrence of x in ϕ. Substitution is covered further later in this chapter.

Axiomatic approach

The axioms are a set of sentences meant to distinguish "desired" models from others. But typically, also have "undesired" models, which are called non-standard models.

Examples: Consider the vocabulary (𝑛𝑒π‘₯𝑑,+,×,,0,=,<), where the symbols have the usual meaning (defined by FO sentences over this vocabulary). The standard interpretation for this set of axioms (see the end of this chapter) is the integers, but these are also satisfied by the set of integers modulo p. This possibility is ruled out by adding the following sentence to the axioms: x(x<𝑛𝑒π‘₯𝑑(x))

Question: Can all non-standard models be axiomatized away? The answer is no. Consider the model shown in [TODO: import figure] for the vocabulary containing only 0,<,σ (all elements in the upper line are larger than those on the lower line).

There is no set of first-order sentences that can distinguish this model from the natural numbers. Intuitively, the reason is that we cannot "backtrack" arbitrarily (towards 0) in a first-order sentence. A similar non-standard model can be obtained for the full vocabulary above.

Evaluating FO Sentences

Given a first-order structure I and a FO sentence ϕ, can we tell if Iϕ?

This problem is decidable for finite structures. For example, suppose E is a binary relation representing the edges of a graph, and the given sentence is

x1x2x3(E(x1,x2)E(x2,x3)E(x3,x1)x1x2x2x3x3x1).

We can evaluate the truth of this sentence by trying all possible values for x1,x2 and x3. (Naive evaluation: "nested loop".) This is polynomial time (in domain size) but exponential in the size of the formula.

On infinite domains, we may or may not be able to evaluate the truth of a sentence. With the vocabulary (N,0,σ,<,+), where N is the set of natural numbers, it is decidable if a sentence is true. (This is known as Presburger arithmetic.) However if we include multiplication, the truth of a sentence becomes undecidable.

A Deductive System for FO

A set Δ of FO sentences is

  • Satisfiable if there is some structure I such that IΔ
  • Unsatisfiable if it is not satisfiable
  • Valid if IΔ for all structure I

Given a set of FO sentences Σ and a sentence ϕ

  • Σ entails ϕ (denoted Σϕ), if every structure that satisfies Σ also satisfies ϕ.
  • Σϕ iff Σ{¬ϕ} is unsatisfiable.
  • If Σ is finite then, Σϕ iff ¬Σϕ is valid.
  • If a formula ϕ has free variables Xβ†’=(x1,,xk), ϕ is valid iff Xβ†’ϕ is valid.

Axioms for Validity

The axioms for validity are from three categories:

  1. Axioms for boolean validity. These are inherited from propositional logic.
  2. Axioms for equality.
  3. Axioms for quantification.
Boolean Validity

Given a FO formula φ, a boolean form of φ a propositional formula ψ such that φ is obtained from ψ by replacing each propositional variable in ψ by a subformula of φ.

The set of Boolean forms of φ is denoted BF(φ).

Examples:

  • For the FO formula xP(x)¬xP(x), the boolean form is p¬p.
  • If φxG(x,y)xG(x,y)(G(z,x)xG(x,y)), then BF(φ)x1x3(x2x1) where x1=xG(x,y),x2=G(z,x),x3=xG(x,y).

Claim: If ψBF(φ) and ψ is valid, then φ is valid.

Equality Axioms

Let t,t1,,tk,t'1,,t'k be terms. The following are valid formulas.

  • t=t
  • (t1=t'1tk=t'k)(f(t1,,tk)=f(t'1,,t'k)), where f is a k-ary function.
  • (t1=t'1tk=t'k)(R(t1,,tk)R(t'1,,t'k)), where R is a k-ary relation.
Substitutions

Given a formula φ in which variable x occurs free (denoted by φ(x)) and a term t, we define the substitution of t for x in φ, denoted φ(xt), as the formula that results from replacing every free occurrence of x in φ by t, subject to the constraint that t contains no variable y quantified in φ such that x occurs free within the scope of quantification of y. If x does not occur free φ, then φ(xt) is defined as φ.

Example: Let φ be

((x=1)x(x=y)),

then

  • φ(x(y+1)) is a valid substitution
  • φ(y(x+1)) is not a valid substitution.
Quantification Axioms
  1. xφφ(xt), where t is a term and φ(xt) is a valid substitution
  2. (x(φψ))((xφ)(xψ))
  3. φxφ
  4. xφ¬x¬φ

In summary, the axioms for validity are 𝐀𝐱:

  1. Axioms for boolean validity. These are inherited from propositional logic.
  2. Axioms for equality.
  3. Axioms for quantification.

Definition: A proof is a sequence ϕ1,ϕ2,,ϕk of FO sentences such that for each i{1,,k} either ϕi𝐀𝐱 or j,k<i such that ϕjψ and ϕk(ψϕi).

Notation: If there is a proof of ϕ using 𝐀𝐱, we denote this fact by 𝐀𝐱ϕ.

Fact (Soundness): If 𝐀𝐱ϕ, then ϕ is valid.

Remark: The set of formulas which can be proven valid is recursively enumerable.

Example: Proof of the formula x(ϕψ)(xϕxψ)

x(ϕψ)
x(ϕψ)(ϕψ)(xx)
ϕψ
ϕ
x(ϕψ)ϕ
x(x(ϕψ)ϕ)
xx(ϕψ)xϕ
x(ϕψ)xϕ
xϕ

The proof of xψ is symmetrical.

xϕxψ
x(ϕψ)(xϕxψ)

Useful Equivalences

  • x(ϕψ)(xϕ)(xψ)
  • x(ϕψ)↮(xϕ)(xψ) e.g. ϕ(x) "x is even" and ψ(x) "x is odd"
  • x(ϕ(x)¬ϕ(x))↮(xϕ(x)x¬ϕ(x))
  • x(ϕψ)(xϕ)(xψ)
  • ¬xϕx¬ϕ
  • ¬xϕx¬ϕ

Prenex Normal Form

Claim: Every FO sentence is equivalent to a FO sentence of the form Q1x1Qkxkϕ, where Qi{,} and ϕ is quantifier free.

This is proved using the distributive properties of quantifiers. It may be necessary to rename variables, to avoid ambiguities. Although you can always move all quantifiers to the left, the resulting formula can actually be exponentially larger than the original one.

Example:

ϕx(G(x,x)(yG(x,y)y¬G(y,y)))G(x,0)
(x(G(x,x)(yG(x,y)y¬G(y,y))))G(w,0)
x(G(x,x)(yG(x,y)y¬G(y,y))G(w,0))
x(G(x,x)(yG(x,y)z¬G(z,z))G(w,0))
x(G(x,x)y(G(x,y)z¬G(z,z))G(w,0))
xy(G(x,x)(G(x,y)z¬G(z,z))G(w,0))
xy(G(x,x)z(G(x,y)¬G(z,z))G(w,0))
xyz(G(x,x)(G(x,y)¬G(z,z))G(w,0))

Recall the Axiomatic Method

  1. Describe the desired model as closely as possible using a (possibly infinite but recursive) set Δ of axioms (FO sentences).
  1. Prove things using deduction.

Notation: We say ϕ is a valid consequence of Δ (denoted Δϕ), if every model satisfying Δ also satisfies ϕ.

Fact: Σϕ iff Σ{¬ϕ} is unsatisfiable.

Aside: Nonlogical axioms for number theory

The following fourteen first-order axioms describe the properties of arithmetic and numbers, i.e. addition (+), multiplication (×), exponentiation (, equality (=), ordering (<), successor function (σ) and remainder (mod). This example shows the expressive power of first-order statements, which were originally hoped to provide a basis for the "one true mathematics."

Question: Why are they called "nonlogical" axioms?

NT1: x(σ(x)0)
NT2: xy(σ(x)=σ(y)x=y)
NT3: x(x=0yσ(y)=x)
NT4: x(x+0=x)
NT5: xy(x+σ(y)=σ(x+y))
NT6: x(x×0=0)
NT7: xy(x×σ(y)=(x×y)+x)
NT8: x(x0=σ(0))
NT9: xy(xσ(y)=(xy)×x)
NT10: x(x<σ(x))
NT11: xy(x<y(σ(x)y))
NT12: xy(¬(x<y)yx)
NT13: xyz(((x<y)(y<z))x<z)
NT14: xyzz(mod(x,y,z)mod(x,y,z)z=z)

Template:BookCat