Lecture Slides for MAT-60556 PART IV: First Order Logic: - - PowerPoint PPT Presentation

lecture slides for mat 60556 part iv first order logic
SMART_READER_LITE
LIVE PREVIEW

Lecture Slides for MAT-60556 PART IV: First Order Logic: - - PowerPoint PPT Presentation

Lecture Slides for MAT-60556 PART IV: First Order Logic: Resolution, Logic programming and Model theory Henri Hansen October 1, 2013 1 Resolution Resolution is a sound and complete algorithm for propositional logic: A formula in clausal


slide-1
SLIDE 1

Lecture Slides for MAT-60556 PART IV: First Order Logic: Resolution, Logic programming and Model theory

Henri Hansen October 1, 2013

1

slide-2
SLIDE 2

Resolution

  • Resolution is a sound and complete algorithm for

propositional logic: A formula in clausal form is un- sat if and only if the algorithm reports unsat, and in propositional logic the procedure is guaranteed to terminate

  • The generalization to FOL is sound and complete

as well, but the algorithm may fail to terminate

  • The generalization is done in two steps: First, we

present ground resolution, which works on ground literals, and then general resolution, wchih uses uni- fication, to enable resolution on non-ground literals

2

slide-3
SLIDE 3

Ground Resolution

  • Let C1 and C2 be ground clauses such that l ∈ C1

annd lc ∈ C2. We say that C1 and C2 are clashing clauses and they clash on the ground literals l and

  • lc. The resolvent of C1 and C2 is the clause

C = (C1 − {l}) ∪ (C2 − {lc}) C1 and C2 are the parent clauses of C

  • Theorem: The resolvent is satisfiable if and only if

its parents are both satisfiable

  • Remember:

A ground literal is a predicate where the parameters are ground terms (only constants and functions!)

3

slide-4
SLIDE 4

Substitution

  • A substitution of terms for variables is the set

{x1 ← t1, . . . , xn ← tn} where each xi is a distinct variable and ti is not identical to the corresponding variable. The set may be empty.

  • An expression is a term, a literal, a clause, or a set
  • f clauses.

If E is an expression and θ = {x1 ← t1, . . . , xn ← tn} is a substitution, then an instance Eθ of E is obtained by simultaneously replacing xi with ti in E

4

slide-5
SLIDE 5

Unification

  • Let U = {A1, . . . , An} be a set of atoms. A unifier
  • f U is a substitution θ such that A1θ = · · · = Anθ
  • A most general unifier (mgu) is a unifier µ such

that any unifier θ of U can be expressed as θ = µλ for some substitution λ

  • Note that not all atoms are unifiable, for instance,

it is impossible to unify atoms when predicate sym- bols are different, as well as atoms whose outer functions are different, or, for instance the atoms p(x), p(f(x)), which cannot be unified.

5

slide-6
SLIDE 6

Unification algorithm

  • A set of term equations is in solved form iff all

equations are of the form xi = ti, where xi is a variable, and each variable that appears in the left- hand side of an equation, never appears anywhere else.

  • A set of equations in solved form defines a substi-

tution, where xi ← ti for each i

  • It will turn out later, that the set in solved form

is the mgu of the original set of term equations,

6

slide-7
SLIDE 7

and thus for the set of atoms from which the terms were taken

  • The following algorithm transforms a set of term

equations into solved form, or reports if it cannot be done

  • 1. Transform t = x when t is not a variable, into

x = t

  • 2. Erase the equation x = x
  • 3. Let t′ = t′′ be an equation where t′ and t′′ are

not variables – If the outermost functions are not identical, terminate, not unifiable

slide-8
SLIDE 8

– Otherwise, replace f(t′

1, . . . , t′ k) = f(t′′ 1, . . . t′′ k)

with the equations t′

i = t′′ i

  • 4. Let x = t be an exuation such that x occurs

elsewhere in the set – If x occurs in t and differs from t, terminate, not unifiable – Otherwise, transform the set by replacing oc- currences of x in other equations by t

  • note: Algorithms for unification may be extremely

inefficient

slide-9
SLIDE 9

General resolution step

  • The general resolution rule:

Let C1 and C2 be clauses such that some predicate appears in C1 and its negation appears in C2. Let l1 and l2 be the corresponding literals, such that l1σ and (l2σ)c are unified, by an mgu σ. The resolvent of C1 and C2 is defined C = (C1σ − {l1σ}) ∪ (C2σ − {l2σ})

  • The resolvent is satisfiable if and only if C1 and C2

are satisfiable.

7

slide-10
SLIDE 10

Resolution algorithm

  • Let S = S0 be a set of clauses
  • Si+1 is constructed from Si by choosing a pair of

clashing clauses C1, C2 ∈ Si, and calculating the re- solvent C

  • If C = , then terminate and S is not satisfiable.

Otherwise Si+1 = Si ∪ {C}

  • If Si+1 = Si for all possible pairs of clashing clauses,

then S is satisfiable

8

slide-11
SLIDE 11

Soundness of resolution

  • Theorem: If the empty clause is derived from S,

then S is unsatisfiable – Idea of proof: If the parent clauses are simul- taneously satisfiable, then the resolvent is also; Because is unsat, then the parent clauses must also be unsat – If parent clauses are sat, then there is a Herbrand interpretation for them. The elements of the Herbrand base that satisfy C1 and C2 have the same form as ground atoms, so there is a sub- stitution that unifies Ci with some ground clause C′

i

9

slide-12
SLIDE 12

– We can infer that the Herbrand model for C1 and C2 is also a Herbrand model for C

slide-13
SLIDE 13

Completeness of resolution

  • Lifting Lemma: Let C′

1 and C′ 2 be ground instances

  • f C1 and C2. Let C′ be a ground resolvent for C′

1

and C′

2 Then there exists a resolvent C of C1 and

C2 such that C′ is a ground instance of C

  • Theorem: If a set of clauses is unsat, the empty

clause can be derived by resolution

  • Resolution has an important application in Logic

programming, which we shall discuss forthwith

10

slide-14
SLIDE 14

Logic Programming

  • Resolution was devoleped for automatic theorem

proving

  • However, a restricted form of resolution can be used

to carry out computation as well

  • Making use of this fact, logic programming has been

developed

  • In logic programming, a program is a set of clauses,

and and a query which is a negation of the results

  • f the program.

11

slide-15
SLIDE 15

From formulas to logic programming

  • Consider a deductive system with two kinds of ax-

ioms:

  • 1. Universally closed predicates, like ∀x(x + 0 = x)
  • 2. Universally closed implication, like ∀x∀y∀z(x ≤

y ∧ y ≤ z → x ≤ z)

  • In clausal form, the first is a literal x + 0 = x, and

the second one negates the left hand side, in the example ¬(x ≤ y)∨¬(y ≤ z)∨(x ≤ z), so that there is exactly one positive literal. These are the so-called program clauses

12

slide-16
SLIDE 16

From formulas to logic programming (contd)

  • Suppose that we ghave a set of program clauses

and we want to prove G1 ∧ · · · ∧ Gn is a logical con- sequence of the set

  • The formula is negated to ¬G1 ∨ · · · ∨ ¬Gn, and this

is refuted by resolution with program clauses

  • ¬G1 ∨ · · · ∨ ¬Gn is called the goal clause, and it can
  • nly clash on program clauses’ positive literal, as it

consists of only negative literals

13

slide-17
SLIDE 17

From formulas to logic programming (contd II)

  • The sequence of resolution produces a sequence
  • f unifying substitutions, which then become the

answer to the query

  • The computation is implicitly carried out as part of

the substitutions

  • Given a gaol clause, it is possible that several literals

clash with a positive literal of a program clause, which means the computation is nondeterministic

14

slide-18
SLIDE 18
  • A computation rule must be used to specify, how a

literal in the goal is chosen

  • Once a literal is chosen, the next program rule must

be chosen, so a search rule is needed

slide-19
SLIDE 19

Horn Clauses and SLD-resolution

  • A Horn clause is a clause of the form A ← B1 ∧ · · · ∧

Bn, which is equivalent to A ∨ ¬B1 ∨ · · · ∨ Bn, and it has at most one positive literal – A fact is a positive unit Horn clause, i.e. A ← – A goal clause is a Horn clause with no positive literals, i.e., ← B1 · · · Bn – A program clause is a Horn clause with one pos- itive, and one or more negative literals

  • ← means reverse implication, with the meaning “To

prove A, prove B1, . . . Bn”

15

slide-20
SLIDE 20

Correct Answer Substitution

  • Let P be a program and G be a goal clause. a sub-

stitution θ for the variables in G is a correct answer substitution if P | = ∀(¬Gθ), with quantification over all free variables in ¬Gθ

  • Given a program, a goal clause G = ¬G1 ∨ · · · ¬Gn,

and a correct substitution θ, P | = ∀(G1 ∧ · · · Gn)θ, and therefore for any substitution σ that makes this conjunction into a ground formula (G1 ∧ · · · ∧ Gn)θσ is true for any model of P

16

slide-21
SLIDE 21

SLD-resolution

  • Let P be a set of program clauses, R a computation

rule, and G a goal clause. A derivation by SLD- resolution is a sequence of resolution steps between goals and program clauses.

  • 1. The first goal clause G0 = G
  • 2. The clause Gi+1 is derived from Gi by selecting

a literal Aj

i ∈ Gi and choosing a clause Ci ∈ P

such that the head of Ci unifies with Aj

i by mgu

θi, and resolving

  • An SLD-refutation is an SLD-derivation that results

in .

17

slide-22
SLIDE 22

Excursion: Prolog

  • Prolog was the first logic programming language
  • The computation rule for Prolog is to choose the

leftmost literal in the goal

  • The search rule is to choose clauses from top to

bottom in the list of program clauses

  • In addition, Prolog implements some non-logic pred-

icates whose purpose is to produce side-effects, such as I/O- functions

18

slide-23
SLIDE 23

Prolog (example)

  • Consider the following program in Prolog

ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).

  • in addition we should have a database of facts, like

parent(bob,allen) and parent(dave,bob)

  • the goal :- ancestor(Y,bob), ancestor(bob,Z) will

succeed and the correct substitution Y = dave, X = allen will be returned

19

slide-24
SLIDE 24

Features of Prolog

  • The search for a proof is depth-first, which can

lead to non-termination of computation even if ter- minating computation exists

  • This means that a prolog programmer must order

clauses to avoid non-termination

  • Also important feature is forced failure, which can

be used to implement “iteration”, and Cuts that prevent backtracking

  • Arithmetic is also treated in a special way

20

slide-25
SLIDE 25

FOL Undecidability and Model Theory

  • Validity in FOL is undecidable; this can be proven

by showing it to be reducible to the halting problem

  • Model theory is used in the process. The proof is

handled in detail here so as to be more informative

  • Instead of Turing machines, the theory operates

with two register machines, which consist of two registers, x and y which can store natural numbers, and a program P = {L1, . . . , Ln}. Li is either incre- mentation of x, incrementation of yor conditional jump/decrementation of either register

21

slide-26
SLIDE 26

Chuch theorem

  • Theorem: Validity of FOL is undecidable

– We can construct a formula that is valid if and

  • nly if a given two-register machine M halts:

SM = (p0(a, a) ∧

n−1

i=0

Si) → ∃z1∃z2pn(z1, z2) – Si is defined according to what instruction Li is. For instance, incrementing x corresponds to ∀x∀y(pi(x, y) → pi+1(s(x), y)), and conditional jump/decrementation is given as ∀x(pi(a, x) → pj(a, x))∧∀x∀y(pi(s(x), y) → pi+1(x, y))

22

slide-27
SLIDE 27

Church Theorem (contd.)

  • There are predicates p0, . . . , pn, one for each state-

ment in M. The meaning of these predicates is that pi(x, y) holds when computation is at label Li and the two registers have values x and y. The constant a means 0, and s is a function such that s(x) = x + 1.

  • First one has to prove that if M halts, the formula

is valid; we can rule out interpretations where the antecedent in SM is false, because those are always true

23

slide-28
SLIDE 28

– If the program is just one step (halt) then SM = p0(a, a) → ∃z1∃z2p0(z1, z2), which clearly is valid – For inductive step, showing that an interpre- tation that makes the antecedent true, makes ∃z2pn(z1, z2) true as well, is enough when you add one more step (left as exercise)

slide-29
SLIDE 29

Church Theorem (contd. II)

  • Then one has to prove that if SM is valid, then M

halts – Consider the interpretation {N, {P0, . . . , Pn}, {succ}, {0}} where succ means the successor function and (x, y) ∈ Pi if and only if the machine visits Li when the registers contain the values x and y. – In this direction, the induction is much simpler

  • The corollary is that validity must be undecidable,

because deciding validity would solve the halting problem!

24

slide-30
SLIDE 30

Decidable cases of FOL

  • Theorem: Pure PCNF formulas with prefixes of the

following form are decidable – ∀x1 · · · ∀xn∃y1 · · · ∃ym – ∀x1 · · · ∀xn∃y∀z1 · · · ∀zm – ∀x1 · · · ∀xn∃y1∃y2∀z1 · · · ∀zm

  • Theorem: PCNF formulas with matrix where 1) all

conjuctions are single literals; 2) All conjunctions are either single atomic formulas or consist of only negative literals; or 3) All formulas have only unary predicates, these are all decidable

25

slide-31
SLIDE 31

Finite and infinite models

  • A set of formulas U has the finite model property

iff: Uis satisfiable if and only if it is satisfied by an interpretation that has a finite domain

  • wenheim theorem: If a formula is satisfiable, it is

satisfiable in a countable domain

  • wenheim-Skolem theorem: If a countable set of

formulas is satisfiable, then it is satisfiable in a countable domain

26

slide-32
SLIDE 32
  • Corollary: There is a countable model for the real

numbers! (There is a countable first-order axioma- tization of real numbers!)

slide-33
SLIDE 33

Complete and incomplete theories

  • Let T (U) be a theory. T (U) is complete if and only

if, for every closed formula A, U ⊢ A or U ⊢ ¬A. T (U) is incomplete if and only if it is not complete

  • The completeness of a theory should not be con-

fused with the completeness of a deductive system

  • Deductive systems map syntactic objects (proofs)

to semantic objects (validity)

  • Theory talks about logical consequences of a set of

formulas.

27

slide-34
SLIDE 34

Example of a theory: Number theory (Peano Axioms)

  • 1. Peano axioms include axioms for a special relation

“=”, for equality; omitted

  • 2. ∀x(¬s(x) = 0) The successor of a number is never

zero

  • 3. ∀x∀y(s(x) = s(y) → x = y) Successor is unique and

injective

  • 4. ∀x(x + 0 = x)

28

slide-35
SLIDE 35
  • 5. ∀x∀y(x + s(y) = s(x + y))
  • 6. ∀x(x · 0 = 0)
  • 7. ∀x∀y(x · s(y) = x · y + x)
  • 8. Induction Scheme (one axiom for any predicate B):

(B(0) ∧ ∀x(B(x) → B(s(x)))) → ∀xB(x)

slide-36
SLIDE 36

  • del numbering
  • Symbols used in FOL and Peano Axioms are each

given a number.

  • Intermediary symbols (whitespace, separators, etc)

are given numbers

  • A sequence of numbers are interpreted as a number,

using separators

  • Any formula of FOL that uses the symbols in Peano

Axioms, is given a unique natural number.

29

slide-37
SLIDE 37
  • Proofs are sequences of formulas, so they are given

unique natural numbers

  • Whether a given number is an encoding of some

formula, can be expressed using only operations de- fined by the Peano axioms, i.e., one can define a predicate F(x) using multiplication, addition, suc- cessor, etc, so that F(x) = T if and only if x is a number of a well-defined formula.

  • Then, we define a predicate D(x, y) when y is a

number of a legitimate deduction step from x

slide-38
SLIDE 38
  • Then one can define a predicate P(x) when x is a

number of a legitimate proof: It is a sequence of legitimate deduction steps.

slide-39
SLIDE 39

  • del’s incompleteness theorem: Peano arithemetic is

either incosistent or incomplete

  • Using G¨
  • del numbering, it is possible fo define a

formula A(x, y) in Peano arithmetic such that, for any numbers i, j, A(i, j) is true if and only if i is the G¨

  • del number associated with some formula B(x),

and j is the G¨

  • del number of the proof of B(i).
  • If ∃j : A(i, j) is true, then a proof can be constructed

for the formula whose number is i.

  • Consider then the formula C(x) = ∀y¬A(x, y) Let

m be the G¨

  • del number of this formula, then C(m)

30

slide-40
SLIDE 40

means that there is no G¨

  • del number for the proof
  • f C(m).