first order logic - uni-bamberg.de

30
Intelligent Agents First Order Logic Ute Schmid Cognitive Systems, Applied Computer Science, Bamberg University last change: 7. Juni 2010 U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 1 / 30

Upload: others

Post on 06-Dec-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: First Order Logic - uni-bamberg.de

Intelligent AgentsFirst Order Logic

Ute Schmid

Cognitive Systems, Applied Computer Science, Bamberg University

last change: 7. Juni 2010

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 1 / 30

Page 2: First Order Logic - uni-bamberg.de

Reasoning and Inference

Reasoning is the process of using facts and inference rules toproduce conclusions.A knowledge-based system typically consists of two components:knowledge representation + inference.Knowledge representation is domain-dependent and must beacquired and formalized for each new domain of interest(knowledge engineering).Inference mechanisms are independent of a concrete domain butthey rely on specific formats of knowledge representation.First order logic as representation formalism and resolution asinference mechanism are the foundation of manyknowledge-based systems (e.g. expert systems,question-answering systems).

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 2 / 30

Page 3: First Order Logic - uni-bamberg.de

Basic Types of Inference: Deduction

(Charles Peirce)

Deduction: Derive a conclusion from given axioms (“knowledge”)and facts (“observations”).

Example(axiom) All humans are mortal.(fact/premise) Socrates is a human.(conclusion) Therefore, it follows that Socrates is mortal.

I The conclusion can be derived by applying the modus ponensinference rule (Aristotelian/propositional logic).

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 3 / 30

Page 4: First Order Logic - uni-bamberg.de

Basic Types of Inference: Induction

Induction: Derive a general rule (axiom) from backgroundknowledge and observations.

Example(background knowledge) Socrates is a human.(observation/example) Socrates is mortal.(generalization) Therefore, I hypothesize that

all humans are mortal.

I Induction means to infer (unsure) generalized knowledge fromexample observations.

I Induction is the inference mechanism for learning! (see lesson onMachine Learning)

I Analogy is a special kind of induction.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 4 / 30

Page 5: First Order Logic - uni-bamberg.de

Basic Types of Inference: Abduction

Abduction: From a known axiom (theory) and some observation,derive a premise.

Example(theory) All humans are mortal.(observation) Socrates is mortal.(diagnosis) Therefore,

Socrates must have been a human.

I Abduction is typical for diagnostic systems/expert systems. (It isalso the preferred reasoning method of Sherlock Holmes.)

I Simple medical diagnosis:If one has the flue, one has moderate fewer.Patient X has moderate fewer.Therefore, he has the flue.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 5 / 30

Page 6: First Order Logic - uni-bamberg.de

Deduction

Deductive inference is also called theorem proving or logicinference.Deduction is truth preserving: If the premises (axioms and facts)are true, then the conclusion (also called theorem) is true.(given sound and complete inference rules!)Note: The truth of the premises is typically not the “logical truth”(premises in general are not tautologies).In deduction we infer special theorems from a more generaltheory.Deduction is “knowledge extraction” while induction is“construction of (hypothetical) knowledge”.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 6 / 30

Page 7: First Order Logic - uni-bamberg.de

Deduction Calculus

To perform deductive inference on a machine, a calculus isneeded:A calculus is a set of syntactical rewrite-rules defined for somelanguage. These rules must be sound and complete with respectto the task they should perform (to a model).Soundness and completeness are semantic properties!

We will focus on the resolution calculus for first order logic (FOL).I Syntax of FOL (language for knowledge representation + definition

of calculus)I Semantics of FOL (meaning of FOL sentences + properties of

calculus)

(Basic knowledge in propositional and first order logic is presumed.)

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 7 / 30

Page 8: First Order Logic - uni-bamberg.de

Syntax of FOL/Terms

Inductive definition:Terms:

I A variable v ∈ V is a term.I If f is a function symbol with arity n and t1. . . tn are terms, then

f (t1, . . . , tn) is a term. (including constant symbols as 0-ary functionsymbols)

I That are all terms.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 8 / 30

Page 9: First Order Logic - uni-bamberg.de

Syntax of FOL/Formulas

Inductive definition:Formulas:

I if P is a predicate symbol with arity n and t1. . . tn are terms, thenP(t1, . . . , tn) is a formula. (atomic formula)

I For all formulas F and G, ¬F , F ∧G, F ∨G, F → G and F ↔ G areformula. (connectives “not”, “and”, “or”, “implies”, “equivalent”)

I If v is a variable and F is a formula, then ∃v F and ∀v F areformulas. (existential and universal quantifier, “exists”, “for all”)

I That are all formulas.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 9 / 30

Page 10: First Order Logic - uni-bamberg.de

Remarks on Syntax of FOL

Formula are constructed over terms.Never confuse this categories!Additionally, parentheses can be used to group sub-expressions.Expressions which obey the given inductive definition are calledwell-formed formulas (wwfs).The closure “that are all terms/formulas” is necessary to excludeall other kinds of (not well-formed) expressions.We refer to atomic formulas also as “atoms”. Positive and negatedatoms (P, ¬P) are called positive/negative literals.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 10 / 30

Page 11: First Order Logic - uni-bamberg.de

Remarks on Syntax of FOL cont.

A variable which is in the scope of a quantor is called bound,otherwise it is is called free.P(x) ∨ ∀y∃z Q(y , z)x is free and y and z are bound.A formula without free variables is called sentence.Propositional logic is a special case of FOL: use only unarypredicate symbols (then there are no terms, no variable and noquantors) or just forbid variables and quantors (use only groundedformulas).

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 11 / 30

Page 12: First Order Logic - uni-bamberg.de

Semantics of FOL

Syntax defines how to form well-formed expressions. Semanticsgives meaning to expressions.Expressions are interpreted using an interpretation function I overa domain (set of objects) U . A pair A = (U , I) is called a structure(or algebra).Function symbols are interpreted as functions and predicatesymbols as predicates/relations over a domain.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 12 / 30

Page 13: First Order Logic - uni-bamberg.de

Example Interpretation

(∃x on(x, A)→ ¬clear(A)) ∧ ∃y clear(topof(y))

Constant symbol ‘A’ is interpreted as a block in a blocksworld B.Function symbol ‘topof(x)’ is interpreted as a function t : B → Bwhich returns the block which is lying on top of block x or ⊥ if noblock is lying on x .Predicate symbol ‘clear(x)’ is interpreted as unary relation C ⊆ Bwhich holds if no other block is lying on block x .Predicate symbol ‘on(x,y)’ is interpreted as binary relationO ⊆ B × B which holds if a block x is lying immediatly on top of ablock y .

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 13 / 30

Page 14: First Order Logic - uni-bamberg.de

Example Illustration

Possible interpretations for the formulas:clear(B)clear (B) ∧ clear(C)clear(B) ∨ clear(A)on(A, Table)→ clear(B)clear(B) ∧ clear(C)→ on(A, Table)

A C B C

C

A BA

B

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 14 / 30

Page 15: First Order Logic - uni-bamberg.de

Intuition about Semantics

Natural language sentence describes−→ situation in the world

“Block B lies on block A”A C

B

FOL formulais interpreted by

−→ a structure

Blocksworld = (B, I) with B asset of blocks and I as definedabove.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 15 / 30

Page 16: First Order Logic - uni-bamberg.de

Propositional Logic vs. FOL

In propositional logic, formula are interpreted directly by truthvalues.In FOL we first must map the components of a formula stepwiseinto a structure.Constant symbols are mapped to objects in the domain. Forinterpreted functions, their result can be determined within thestructure (evaluation of grounded terms). The result is again anobject in the domain.Formula over terms are mapped to truth values.

Now the difference between terms and formula should beclear: terms evaluate to values, formula to truth values!

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 16 / 30

Page 17: First Order Logic - uni-bamberg.de

Propositional Logic vs. FOL cont.

Mapping of formula to truth values:To assign a truth value, first, the arguments of a predicate symbolare interpreted, afterwards it is determined whether thecorresponding relation holds in the structure.If all atomic formula are associated with truth values, morecomplex formulas can be interpreted as known over the definitionof the junctors.For an existentially quantified formula there needs to be at leastone element in the domain for which the formula is true. Foruniversally quantified formulas, the formula must be true for alldomain objects.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 17 / 30

Page 18: First Order Logic - uni-bamberg.de

Semantics of the Connectives

A B ¬ A A ∧ B A ∨ B A→ B A↔ B0 0 1 0 0 1 10 1 0 1 1 01 0 0 0 1 0 01 1 1 1 1 1

¬ binds stronger than∧ and ∨ which bind stronger than→ and↔

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 18 / 30

Page 19: First Order Logic - uni-bamberg.de

Model, Satisfiability, Validity

If the interpretation of a formula F with respect to a structure Aresults in the truth value “true”, the structure is called a model. Wewrite A � F .If every structure for F is a model, we call F valid and write � F .If there exists at least one model for F , we call F satisfiable.

Remark: In general, structures can be defined over domainswhich are arbitrary sets. That is, the sets can contain lots ofirrelevant objects. There is a canonic way to constructstructures over a so called Herbrand Universe.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 19 / 30

Page 20: First Order Logic - uni-bamberg.de

Illustration

∀x y (p(x) ∧ p(y))→ (p(x) ∨ p(y)) is valid

e.g. For all humans it holds that if two persons are rich then atleast one of them is rich.e.g. For all natural numbers holds that if both numbers are eventhen at least one of them is even.∃x (s(x) ∧ v(x ,L)) is satisfiable

e.g. It exists a natural number smaller than 17.e.g. It exists a human being who is a student and who likes logic.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 20 / 30

Page 21: First Order Logic - uni-bamberg.de

Semantical Entailment

A formula G is called logical consequence (or entailment) of a setof formula F = {F1 . . .Fn}, if each model of F is also a model of G.Note: We write A � G to denote the “model relation” and alsoF � G to denote the “entailment relation”.The following propositions are equivalent:

1 G is a logical consequence of F .2 (∧n

i=1Fi)→ G is valid (tautology).3 (∧n

i=1Fi) ∧ ¬G is not satisfiable (a contradiction).

This relation between logical consequences and syntactical expressionscan be exploited for syntactical proofs. We write F ` G if formula G canbe derived from the set of formulas F .

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 21 / 30

Page 22: First Order Logic - uni-bamberg.de

Resolution Calculus

The resolution calculus consists of a single rule (and does notpossess any axioms).Resolution is defined for clauses (each formula is a disjunction ofpositive and negative literals).All formulas must hold: conjunction of clauses.Proof by contradiction, exploiting the equivalence given above.If

(n∧

i=1

Fi) ∧ ¬G

is not satisfiable, then “false” (the empty clause) can be derived:

[(n∧

i=1

Fi) ∧ ¬G] ` �

.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 22 / 30

Page 23: First Order Logic - uni-bamberg.de

Resolution Calculus cont.

Resolution rule in propositional logic:

(P ∨ P1 ∨ . . .Pn) ∧ (¬P ∨Q1 ∨ . . .Qm) ` (P1 ∨ . . .Pn ∨Q1 ∨ . . .Qm)

Resolution rule for clauses:

[(L ∨ C1) ∧ (¬L ∨ C2)]σ ` [C1 ∨ C2]σ

(σ is a substitution of variables such that L is identical in both parts of the conjunction)

The general idea is to cut out a literal which appears positive in onedisjunction and negative in the other.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 23 / 30

Page 24: First Order Logic - uni-bamberg.de

Resolution in Propositional Logic

ExampleTheory:

All humans are mortal. F1 = Human→ MortalSocrates is a human. F2 = Human

Query:

Socrates is mortal: G = Mortal

To prove F1 ∧ F2 ∧ ¬G ` �, we need the following resolution steps:1 Human→ Mortal ≡ ¬Human ∨Mortal2 Human ∧ [¬Human ∨Mortal] ∧ ¬Mortal3 ` Mortal ∧ ¬Mortal4 ` �.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 24 / 30

Page 25: First Order Logic - uni-bamberg.de

Resolution in FOL

ExampleTheory:

All humans are mortal. F1 = ∀x Human(x)→ Mortal(x)Socrates is a human. F2 = Human(S)

Query:

Socrates is mortal: G = Mortal(S)

To prove F1 ∧ F2 ∧ ¬G ` �, we need the following resolution steps:1 ∀x Human(x)→ Mortal(x) ≡ ∀x ¬Human(x) ∨Mortal(x)

(substitute S for universally quantified variable x)2 [Human(S) ∧ [¬Human(x) ∨Mortal(x)] ∧ ¬Mortal(S)]{x → S}3 ` Mortal(S) ∧ ¬Mortal(S)4 ` �.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 25 / 30

Page 26: First Order Logic - uni-bamberg.de

Resolution in FOL cont.

Resolution was introduced by Robinson (1965) as a mechanicway to perform logical proofs.We need to understand:

I Transformation of FOL formulas in clauses by applying equivalencerules.

I Substitution and unification.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 26 / 30

Page 27: First Order Logic - uni-bamberg.de

Semantic Equivalence

Two formulas F and G are called equivalent, if for eachinterpretation of G and F holds that G is valid iff F is valid. Wewrite F ≡ G.Theorem: Let be F ≡ G. Let H be a formula where F appears as asub-formula. Let H ′ be a formula derived from H by replacing F byG. Then it holds H ≡ H ′.Equivalences can be used to rewrite formulas.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 27 / 30

Page 28: First Order Logic - uni-bamberg.de

Semantic Equivalence cont.

(F ∧ F ) ≡ F , (F ∨ F ) ≡ F (idempotency)(F ∧G) ≡ (G ∧ F ), (F ∨G) ≡ (G ∨ F ) (commutativity)((F ∧G) ∧ H) ≡ (F ∧ (G ∧ H)), ((F ∨G) ∨ H) ≡ (F ∨ (G ∨ H))(associativity)(F ∧ (F ∨G)) ≡ F , (F ∨ (F ∧G)) ≡ F (absorption)(F ∧ (G ∨ H)) ≡ ((F ∧G) ∨ (F ∧ H)),(F ∨ (G ∧ H)) ≡ ((F ∨G) ∧ (F ∨ H)) (distributivity)¬¬F ≡ F (double negation)¬(F ∧G) ≡ (¬F ∨ ¬G), ¬(F ∨G) ≡ (¬F ∧ ¬G) (de Morgan)(F → G) ≡ (¬F ∨G) (remove implication)

F ∨ ¬F ≡ true (tautology)F ∧ ¬F ≡ false (contradiction)Remark: This is the tertium non datur principle of classical logic.

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 28 / 30

Page 29: First Order Logic - uni-bamberg.de

Semantic Equivalence cont.

¬∀x F ≡ ∃x ¬F , ¬∃x F ≡ ∀x ¬F

(F ∨G) ≡ F , if F tautology;(F ∧G) ≡ G, if F tautology(F ∨G) ≡ G, if F contradiction;(F ∧G) ≡ F , if F contradiction

If x is not free in G it holds:(∀x F ∧G) ≡ ∀x (F ∧G), (∀x F ∨G) ≡ ∀x (F ∨G),(∃x F ∧G) ≡ ∃x (F ∧G), (∃x F ∨G) ≡ ∃x (F ∨G)

(∀x F ∧ ∀x G) ≡ ∀x (F ∧G), (∃x F ∨ ∃x G) ≡ ∃x (F ∨G)

∀x∀yF ≡ ∀y∀xF , ∃x∃yF ≡ ∃y∃xF

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 29 / 30

Page 30: First Order Logic - uni-bamberg.de

Classical Logic

Propositional logic and FOL are classical logics.Classical logic is bivalent and monotonic: There are only two truthvalues “true” and “false”.Because of the tertium non datur, derived conclusions cannot bechanged by new facts or conclusions (vs. multi-valued andnon-monotonic logics).In classical logic, “everything” follows from a contradiction (ex falsoquod libet).A theorem can be proven by contradiction.In contrast, in intuitionistic logic, all proofs must be constructive!

U. Schmid (CogSys) Intelligent Agents last change: 7. Juni 2010 30 / 30