55
Lecture Notes 1 Knowledge Representation and Reasoning. Propositional Logic Lecture Notes for Computer Science Students Faculty EAIiIB AGH Antoni Lig˛ eza Other support material: http://home.agh.edu.pl/~ligeza http://ai.ia.agh.edu.pl/wiki/ c Antoni Lig ˛ eza: 2018

Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 1

Knowledge Representation and Reasoning.Propositional Logic

Lecture Notes

for

Computer Science StudentsFaculty EAIiIB AGH

Antoni Ligeza

Other support material:

http://home.agh.edu.pl/~ligeza

http://ai.ia.agh.edu.pl/wiki/

c©Antoni Ligeza: 2018

Page 2: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 2

References

1. Mordechai Ben-Ari: Mathematical Logic for Computer Science (Logika

matematyczna w informatyce). Springer-Verlag, London, 2001 (WN-T,

Warszawa, 2005).

2. Kenneth A. Ross i Charles R. B. Wright: Discrete Mathematics (Mate-

matyka dyskretna). WN PWN, 2013.

3. Antoni Ligeza: Logical Foundations for Rule-Based Systems.

Springer-Verlag, Berlin, 2006. Wydawnictwo AGH, Kraków, 2005.

4. Michael R. Genesereth, Nils J. Nilsson: Logical Foundations of Artificial

Intelligence. Morgan Kaufmann Publishers, Inc., Los Altos, California,

1987.

5. Zbigniew Huzar: Elementy logiki dla informatyków. Oficyna Wydawni-

cza Politechniki Wrocławskiej, Wrocław, 2007.

6. Stuart Russell, Peter Norvig: Artificial Intelligence. A Modern Appro-

ach. Pearson, 2010.

7. Marek Wójcik: Zasada rezolucji. Metoda automatycznego wnioskowa-

nia. PWN, Warszawa, 1991.

8. C. L. Chang and R. C. T. Lee: Symbolic Logic and Mechanical Theorem

Proving. Academic Press, 1973.

9. Ronald J. Brachman and Hector J. Levesque: Knowledge Representa-

tion and Reasoning. Morgan Kaufmann, 2004.

10. Frank van Harmelen, Vladimir Lifschitz, Bruce Porter (Eds.): Hand-

book of Knowledge Representation. Elsevier B.V., Amsterdam, 2008.

http://ii.fmph.uniba.sk/~sefranek/kri/handbook/

c©Antoni Ligeza

Page 3: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 3

On the Net. Stanford: Coursera

Stanford on-line Course:

https://www.coursera.org/course/intrologic

1. Wikipedia-pl: http://pl.wikipedia.org/wiki/Logika_

matematyczna

2. Wikipedia-en: http://en.wikipedia.org/wiki/Logic

3. AI-Lab-Prolog: http://ai.ia.agh.edu.pl/wiki/pl:prolog:

prolog_lab

4. EIS-KRR: http://ai.ia.agh.edu.pl/wiki/pl:dydaktyka:

krr:start

5. ALI-home: home.agh.edu.pl/~ligeza

6. David Poole and Allen Mackworth: Artificial Intelligence. Foundations

of Computational Agents. http://artint.info/

7. Ulf Nilsson and Jan Maluszynski: Logic, Programming and Prolog.

http://www.ida.liu.se/~ulfni/lpp/

c©Antoni Ligeza

Page 4: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 4

A Problem to Start: Tracking the Murderer

Some knowledge specification — in natural language:

• If Sarah was drunk then either James is the murderer or Sarah lies,

• Either James is the murderer or Sarah was not drunk and the crime

took place after midnight,

• If the crime took place after midnight then either James is the murderer

or Sarah lies,

• Sarah does not lie when sober.

Introduction symbols and transformation to formal specification:

• A = James is the murderer,

• B = Sarah is drunk,

• C = Sarah lies,

• D = The murder took place after midnight.

B =⇒ A ∨ C

A ∨ (¬B ∧D)

D =⇒ (A ∨ C)

C =⇒ B

Questions:

Who is the murderer? Which facts are true/false? Is the system consistent?

How many models does it have (if consistent)? What are the exact models?

c©Antoni Ligeza

Page 5: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 5

Knowledge-Based Systems: Basic Concepts

We need some tools:

• A formal language for KRR:

– alphabet

– syntax,

– semantics,

– inference rules;

• various goals — various types of reasoning,

• inference strategies,

• knowledge acquisition,

• knowledge verification,

• minimal knowledge representation (uniform representation),

• internal knowledge structure (knowledge graphs),

• user interface, explanations, learning, adaptation, optimization.

c©Antoni Ligeza

Page 6: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 6

Formal Knowledge Representation Language: Specification of

Requirements

Knowledge Representation Language:

• unique interpretation,

• expressive power and precision, but

• automated processing,

• adequate for the domain,

• readable for man and machine,

• extensible,

• ...

Knowledge Base:

• consistent, (internal consistency)

• complete,

• valid; sound, (external consistency)

• non-redundant,

• efficient in problem solving, (optimal)

• ...

c©Antoni Ligeza

Page 7: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 7

Something has gone wrong...

c©Antoni Ligeza

Page 8: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 8

Logic — how it works?

Logic – formal language:

• alphabet,

• syntax,

• semantics,

• axiomatization

|= p ∨ ¬p

6|= p ∧ ¬p

• equivalency-preserving transformations,

• inference rules (logical consequence),

• inference chain – derivation,

• problem, hypothesis, question,

• answer, solution, proof.

System modeling :

• language selection – for adequate modeling,

• model building (inputs – outputs – internal structure),

• model analysis (verification, validation),

• model exploration – theorem proving, SAT,

• model tuning and adaptation; learning.

c©Antoni Ligeza

Page 9: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 9

Example: Unicorn

Given the following Knowledge Base (KB):

• If the unicorn is mythical, then it is immortal

• If the unicorn is not mythical, then it is a mortal mammal

• If the unicorn is either immortal or a mammal, then it is horned

• The unicorn is magical if it is horned

answer the following questions:

• Is the unicorn mythical? (M )

• Is it magical? (G)

• Is it horned? (H)

In terms of logic:

KB |= G,H,M

KB ` G,H,Mc©Antoni Ligeza

Page 10: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 10

Logic for KRR – Tasks and Tools

• Theorem Proving – Verification of Logical Consequence:

∆ |= H;

• Automated Inference – Derivation:

∆ ` H;

• SAT (checking for models) – satisfiability:

|=I H;

• un-SAT verification – unsatisfiability:

6|=I H for any interpretation I;

• Tautology verification (completeness):

|= H

• valid inference rules – checking:

(∆ ` H) −→ (∆ |= H)

• complete inference rules – checking:

(∆ |= H) −→ (∆ ` H)

c©Antoni Ligeza

Page 11: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 11

Unicorn - Logical Model

Definition of propositional variables:

• M: The unicorn is mythical

• I: The unicorn is immortal

• L: The unicorn is mammal

• H: The unicorn is horned

• G: The unicorn is magical

Building a Logical Model for the puzzle:

• If the unicorn is mythical, then it is immortal:

M −→ I

• If the unicorn is not mythical, then it is a mortal mammal:

¬M −→ (¬I ∧ L)

• If the unicorn is either immortal or a mammal, then it is horned:

(I ∨ L) −→ H

• The unicorn is magical if it is horned:

H −→ G

Resulting Boolean formula (the Knowledge Base):

(M −→ I) ∧ (¬M −→ (¬I ∧ L)) ∧ ((I ∨ L) −→ H) ∧ (H −→ G)

c©Antoni Ligeza

Page 12: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 12

A Solution

(M −→ I) ≡ (¬M ∨ I)

(¬M −→ (¬I ∧ L)) ≡ (M ∨ (¬I ∧ L))

(M ∨ (¬I ∧ L)) ≡ ((M ∨ ¬I) ∧ (M ∨ L))

¬M ∨ I,M ∨ LI ∨ L

I ∨ L, (I ∨ L) −→ H

H

H,H −→ G

G

So we have:

KB ` H ∧GQuestions:

• What about M (mythical), I (immortal) and L (mammal)?

• What combinations are admissible?

• How many models do we have?

c©Antoni Ligeza

Page 13: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 13

Abductive Inference and Consistency-Based Reasoning

A

B

D

C

E

3

2

2

3

Y

X

3 Z

12

10

G

F

m3

m2

m1

a1

a2

Questions:

• Does the system work OK (Fault Detection)?

• Which component(s) is(are) faulty (Fault Isolation)?

• What are the diagnoses (minimal diagnoses)?

c©Antoni Ligeza

Page 14: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 14

Inference example

A – signal from process,

P – signal added to a queue,

B – signal blocked by process,

D – signal received by process,

S – state of the process saved,

M – signal mask read,

H – signal management procedure activated,

N – procedure executed in normal mode,

R – process restart from context,

I – process must re-create context.

Rules — axiomatization:

A −→ P ,

P ∧ ¬B −→ D,

D −→ S ∧M ∧H,

H ∧N −→ R,

H ∧ ¬R −→ I,

Facts:

A, ¬B, ¬R.

c©Antoni Ligeza

Page 15: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 15

Conclusions

P , D, S, M , H, I, ¬N .

Try to draw an AND/OR/NOT Graph

How to represent:

• facts?

• implication?

• disjunctive conditions?

• conjunctive conditions?

• negation?

• constraints?

Examine Forward Chaining vs Backward Chaining!

c©Antoni Ligeza

Page 16: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 16

Properties of Formulas

A formula φ may be:

true/satisfied — for interpretation I, |=I φ,

false/unsatisfied — for interpretation I, 6|=I φ,

satisfiable — there exists interpretation I such that |=I φ,

unsatisfiable/always false — there does not exists interpretation I, |=I φ,

tautology — for any interpretation I, |=I φ; we write:

|= φ

always false — for any interpretation I:

6|= φ

c©Antoni Ligeza

Page 17: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 17

Extra problem

Assumptions:

A1. There are 3 houses in a row

A2. The houses are numbered 1, 2 and 3, from left to right

A3. Each house has one of the colors Blue, Green or White

A4. Each house is inhabited by one person with one of the nationalities:

Dutch, German and Italian

A5. Each person drinks (exactly one) of the following beverages: Coffee,

Tea and Water

Conditions (constraints):

C1 The third house is green

C2 There is one house between the house of the person drinking coffee

and the blue house

C3 The person drinking water lives in the blue house

C4 The Italian lives to the left of the coffee drinking person

C5 The German lives in house two

Query:

Who lives in the 1st house? What does the Dutch drink?

c©Antoni Ligeza

Page 18: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 18

Syntax

Definicja 1 Definition of legal formulas:

• > i ⊥ are formulas,

• every p ∈ P is a formula,

• if φ, ψ are formulas, then:

– ¬(φ) is a formula (also: ¬(ψ)),

– (φ ∧ ψ) is a formula,

– (φ ∨ ψ) is a formula,

– (φ⇒ ψ) is a formula,

– (φ⇔ ψ) is a formula,

– and nothing else.

Set of formulas == FOR.

Every formula has a parsing tree.

Atomic formulas — simple symbols.

Literals: atoms or their negations.

c©Antoni Ligeza

Page 19: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 19

Semantics

Interpretation I maps propositional symbols into T = T,F.

Definicja 2 Let P be a set of propositional symbols. Interpretations is defi-

ned as:

I : P −→ T,F, (1)

Notation: I(φ) = T is noted as |=I φ; I(φ) = F is noted as 6|=I φ

Definicja 3 The Interpretation I is extended over all formulas φ, ψ, ϕ from

FOR as follows:

• I(>) = T (|=I >),

• I(⊥) = F (6|=I ⊥),

• |=I ¬φ iff 6|=I φ,

• |=I ψ ∧ ϕ iff |=I ψ and |=I ϕ,

• |=I ψ ∨ ϕ iff |=I ψ or |=I ϕ,

• |=I ψ ⇒ ϕ iff |=I ϕ or 6|=I ψ,

• |=I ψ ⇔ ϕ iff |=I (ψ ⇒ ϕ) and |=I (ϕ⇒ ψ).

Definicja 4 Equivalence Formulas φ and ψ are logically equivalent iff for any

I:

|=I φ iff |=I ψ. (2)

Definicja 5 Logical Implication Formula ψ is logical consequence of φ iff for

any I:

if |=I φ then |=I ψ. (3)

c©Antoni Ligeza

Page 20: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 20

Truth Tables

φ ¬φ

F T

T F

φ ϕ φ ∧ ϕ

F F F

F T F

T F F

T T T

φ ϕ φ ∨ ϕ

F F F

F T T

T F T

T T T

φ ϕ φ⇒ ϕ

F F T

F T T

T F F

T T T

φ ϕ φ⇔ ϕ

F F T

F T F

T F F

T T T

c©Antoni Ligeza

Page 21: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 21

Tabular definitions of logical connectives

φ ψ ¬φ φ ∧ ψ φ ∨ ψ φ⇒ ψ φ⇔ ψ

true true false true true true true

true false false false true false false

false true true false true true false

false false true false false true true

Semantics through equivalent transformation:

• φ⇒ ψ ≡ ¬φ ∨ ψ,

• φ⇔ ψ ≡ (φ⇒ ψ) ∧ (φ⇐ ψ),

• φ|ψ ≡ ¬(φ ∧ ψ) –Sheffer function or NAND; also noted as φ ∧ ψ,

• φ ↓ ψ ≡ ¬(φ ∨ ψ) – Pierce function or NOR; other notation φ ∨ ψ,

• φ⊕

ψ ≡ (¬φ ∧ ψ) ∨ (φ ∧ ¬ψ) — EX-OR,

For n arguments there are 22n functions, so for n = 2 there is 16 different

functions.

c©Antoni Ligeza

Page 22: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 22

Functional Completeness

Definicja 6 A Set of Functions is functionally complete if it allows to express

any logical function.

Some examples:

AND, OR, NOT:

¬,∧,∨

AND, NOT:

¬,∧

OR, NOT:

¬,∨

IMPLICATION, NOT:

¬,⇒

NAND:

|

NOR:

Definicja 7 A functionally complete set of functions is minimal — if it cannot

be further reduced.

For convenience, redundant systems are in use.

c©Antoni Ligeza

Page 23: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 23

Most important equivalent transformations

• ¬¬φ ≡ φ — double negation elimination,

• φ ∧ ψ ≡ ψ ∧ φ — conjunction alternation,

• φ ∨ ψ ≡ ψ ∨ φ — disjunction alternation,

• (φ ∧ ϕ) ∧ ψ ≡ φ ∧ (ϕ ∧ ψ) — commutativity,

• (φ ∨ ϕ) ∨ ψ ≡ φ ∨ (ϕ ∨ ψ) — commutativity,

• (φ ∨ ϕ) ∧ ψ ≡ (φ ∧ ψ) ∨ (ϕ ∧ ψ) — distributive law,

• (φ ∧ ϕ) ∨ ψ ≡ (φ ∨ ψ) ∧ (ϕ ∨ ψ) — distributive law,

• φ ∧ φ ≡ φ — idempotency,

• φ ∨ φ ≡ φ — idempotency,

• φ ∧ ⊥ ≡ ⊥, φ ∧ > ≡ φ — identity,

• φ ∨ ⊥ ≡ φ, φ ∨ > ≡ >— identity,

• φ ∨ ¬φ ≡ >— tertium non datur ; excluded middle,

• φ ∧ ¬φ ≡ ⊥— falsification,

• ¬(φ ∧ ψ) ≡ ¬(φ) ∨ ¬(ψ) — De Morgan rule,

• ¬(φ ∨ ψ) ≡ ¬(φ) ∧ ¬(ψ) — De Morgan rule,

• φ⇒ ψ ≡ ¬ψ ⇒ ¬φ — contraposition,

• φ⇒ ψ ≡ ¬φ ∨ ψ — implication elimination.

c©Antoni Ligeza

Page 24: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 24

Example: Tautology Verification

φ = ((p⇒ r) ∧ (q ⇒ r))⇔ ((p ∨ q)⇒ r).

There are (23) possible interpretations.

p q r p⇒ r q ⇒ r (p⇒ r) ∧ (q ⇒ r) (p ∨ q)⇒ r Φ

0 0 0 1 1 1 1 10 0 1 1 1 1 1 10 1 0 1 0 0 0 10 1 1 1 1 1 1 11 0 0 0 1 0 0 11 0 1 1 1 1 1 11 1 0 0 0 0 0 11 1 1 1 1 1 1 1

Other possibility — through equivalent transformations:

φ ≡ ((¬p ∨ r) ∧ (¬q ∨ r))⇔ (¬(p ∨ q) ∨ r).

φ ≡ ((¬p ∧ ¬q) ∨ r)⇔ (¬(p ∨ q) ∨ r).

φ ≡ (¬(p ∨ q) ∨ r)⇔ (¬(p ∨ q) ∨ r).

Let us put: ψ = (¬(p ∨ q) ∨ r); so we see:

φ ≡ ψ ⇔ ψ,

c©Antoni Ligeza

Page 25: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 25

Example: Logical Consequence Verification

(p⇒ q) ∧ (r ⇒ s)

(p ∨ r)⇒ (q ∨ s)Put:

φ = (p⇒ q) ∧ (r ⇒ s)

and

ϕ = (p ∨ r)⇒ (q ∨ s),

Now, check if:

φ |= ϕ. (4)

p q r s p⇒ q r ⇒ s (p⇒ q) ∧ (r ⇒ s) p ∨ r q ∨ s (p ∨ r)⇒ (q ∨ s)

0 0 0 0 1 1 1 0 0 10 0 0 1 1 1 1 0 1 10 0 1 0 1 0 0 1 0 00 0 1 1 1 1 1 1 1 10 1 0 0 1 1 1 0 1 10 1 0 1 1 1 1 0 1 10 1 1 0 1 0 0 1 1 10 1 1 1 1 1 1 1 1 11 0 0 0 0 1 0 1 0 01 0 0 1 0 1 0 1 1 11 0 1 0 0 0 0 1 0 01 0 1 1 0 1 0 1 1 11 1 0 0 1 1 1 1 1 11 1 0 1 1 1 1 1 1 11 1 1 0 1 0 0 1 1 11 1 1 1 1 1 1 1 1 1

From analysis of columns 7 and 10 the logical consequence is confirmed

(but not equivalence; see rows: 7, 10, 12 and 15).

c©Antoni Ligeza

Page 26: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 26

Minterms

Definicja 8 Literal A literal is an atomic formula p or its negation ¬p.

Definicja 9 Let q1, q2, . . . qn are literals:

φ = q1 ∧ q2 ∧ . . . ∧ qn

is a minterm, simple conjunction or product.

Lemat 1 Minterm is satifiable iff it does not contain a pair of complementary

literals.

Lemat 2 Minterm is unsatisfiable iff it contains a pair of complementary

literals.

Notation:

φ = q1 ∧ q2 ∧ . . . ∧ qn

to

[φ] = q1, q2, . . . qn

Definicja 10 Minterm φ subsumes minterm ψ iff [φ] ⊆ [ψ].

Lemat 3 Let φ and ψ are any minterms; then :

ψ |= φ iff [φ] ⊆ [ψ].

c©Antoni Ligeza

Page 27: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 27

Maxterms

Definicja 11 Let q1, q2, . . . qn are literals; then:

φ = q1 ∨ q2 ∨ . . . ∨ qn

is a maxterm, simple disjunction or a clause.

Lemat 4 Maxterm is falsifiable iff it does not contain a pair of complemen-

tary literals.

Lemat 5 Maxterm is a tautology iff it contains a pair of complimentary lite-

rals.

Definicja 12 Maxterm ψ subsumes maxterm φ iff

[ψ] ⊆ [φ]

Lemat 6 Let φ and ψ are any maxterms; then:

ψ |= φ iff [ψ] ⊆ [φ].

Let us consider a clause:

ψ = ¬p1 ∨ ¬p2 ∨ . . . ∨ ¬pk ∨ h1 ∨ h2 ∨ . . . ∨ hm

After applying the de Morgan rule:

¬(p1 ∧ p2 ∧ . . . ∧ pk) ∨ (h1 ∨ h2 ∨ . . . ∨ hm)

This can be put as:

p1 ∧ p2 ∧ . . . ∧ pk ⇒ h1 ∨ h2 ∨ . . . ∨ hm

Definicja 13 A clause of the form:

ψ = ¬p1 ∨ ¬p2 ∨ . . . ∨ ¬pk ∨ h

is called a Horn Clause.

Page 28: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 28

Alternative notations:

p1 ∧ p2 ∧ . . . ∧ pk ⇒ h.

In PROLOG or in DATALOG:

h : −p1, p2, . . . , pk.

also:

h :- p_1, p_2,..., p_k.

h if p_1 and p_2 and ... and p_k.

Three forms of Horn clauses:

• facts,

• full clauses,

• constraints/calls.

c©Antoni Ligeza

Page 29: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 29

CNF — Conjunctive Normal Form

Definicja 14 Formula Ψ is in Conjunctive Normal Form (CNF) iff

Ψ = ψ1 ∧ ψ2 ∧ . . . ∧ ψn

where ψ1, ψ2, . . . , ψn are clauses. Notation: [Ψ] = ψ1, ψ2, . . . , ψn.

Examples:

Which of the following are in CNF:

1. (p ∨ g ∨ ¬r) ∧ (p ∨ r) ∧ ¬r

2. ((p ∧ q) ∨ ¬r) ∧ (p ∨ r) ∧ ¬r

3. ¬(p ∨ q) ∧ (p ∨ r) ∧ ¬r

Definicja 15 Implicent — a clause, that is false then the respective formula

is also false.

Definicja 16 A formula is in maximal CNF form iff it is composed of all

full/maximal clauses:

maxCNF (Ψ) = ψ1 ∧ ψ2 ∧ . . . ∧ ψn

all ψ1, ψ2, . . . , ψn contain all propositional symbols in use.

Definicja 17 Formula

Ψ = ψ1 ∧ ψ2 ∧ . . . ∧ ψn

in CNF is minimal iff it cannot be reduced without violating logical equiva-

lence.

CNF — appropriate for inconsistency checking.c©Antoni Ligeza

Page 30: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 30

DNF — Disjunctive Normal Form

Definicja 18 Formula Φ is in Disjunctive Normal Form (DNF) iff

Φ = φ1 ∨ φ2 ∨ . . . ∨ φn

where φ1, φ2, . . . , φn are any minterms. Notation: [Φ] = φ1, φ2, . . . , φn.

Example:

Which of the following are in DNF:

1. (p ∧ q) ∨ ((p ∨ ¬q) ∧ (¬p ∨ ¬q)))

2. (p ∧ q) ∨ ((p ∨ q) ∨ ¬(p ∧ q)))

3. (p ∧ q) ∨ ((p ∧ ¬q) ∨ (¬p ∧ ¬q)))

Definicja 19 Implicant — a minterm, such that if it is true, then the respec-

tive formula is also true.

Definicja 20 A maximal DNF form is any formula containing all the possible

minterms:

maxDNF (Φ) = φ1 ∨ φ2 ∨ . . . ∨ φn

where all the minterms φ1∨φ2∨. . .∨φn are composed of all the propositional

symbols in use.

Definicja 21 Formula

Φ = φ1 ∨ φ2 ∨ . . . ∨ φn

in DNF is minimal iff it cannot be reduced without violating logical equiva-

lency.

DNF — is appropriate for checking satisfiability.c©Antoni Ligeza

Page 31: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 31

Transformation to CNF/DNF

1. Φ⇔ Ψ ≡ (Φ⇒ Ψ) ∧ (Ψ⇒ Φ) – elimination of equivalence,

2. Φ⇒ Ψ ≡ ¬Φ ∨Ψ – elimination of implication,

3. ¬(¬Φ) ≡ Φ – elimination of double negations,

4. ¬(Φ ∨Ψ) ≡ ¬Φ ∧ ¬Ψ – De Morgan’s rule,

5. ¬(Φ ∧Ψ) ≡ ¬Φ ∨ ¬Ψ – De Morgan’s rule,

6. Φ ∨ (Ψ ∧Υ) ≡ (Φ ∨Ψ) ∧ (Φ ∨Υ) – distributivity rule; towards CNF,

7. Φ ∧ (Ψ ∨Υ) ≡ (Φ ∧Ψ) ∨ (Φ ∧Υ) – distributivity rule; towards DNF.

Example:

(p ∧ (p⇒ q))⇒ q ≡ ¬(p ∧ (p⇒ q)) ∨ q ≡¬(p ∧ (¬p ∨ q)) ∨ q ≡ (¬p ∨ ¬(¬p ∨ q)) ∨ q ≡(¬p ∨ (p ∧ ¬q)) ∨ q ≡ ¬p ∨ (p ∧ ¬q) ∨ q ≡

(¬p ∨ p) ∧ (¬p ∨ ¬q) ∨ q ≡ ¬p ∨ ¬q ∨ q ≡ ¬p ∨ > ≡ >.

Example:

Transforming CNF to DNF:

• φ = ((p ∨ q) ∧ (p ∨ r) ∧ (q ∨ s) ∧ (r ∨ s)), ψ = ((p ∧ s) ∨ (q ∧ r))

• φ = ((p ∨ q) ∧ (q ∨ r) ∧ (r ∨ p)), ψ = ((p ∧ q) ∨ (q ∧ r) ∨ (r ∧ p))

• φ = ((p∨q∨r)∧(q∨r∨s)∧(r∨s∨p)) ψ = ((p∧q)∨(p∧s)∨(q∧s)∨r).

c©Antoni Ligeza

Page 32: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 32

Example:

Let us reconsider:

φ = (p⇒ q) ∧ (r ⇒ s),

ϕ = (p ∨ r)⇒ (q ∨ s).

We check for logical implication:

φ |= ϕ.

Transform φ to DNF:

φ = (p⇒ q) ∧ (r ⇒ s) = (¬p ∨ q) ∧ (¬r ∨ s) =

= (¬p ∧ ¬r) ∨ (¬p ∧ s) ∨ (q ∧ ¬r) ∨ (q ∧ s).

and next to its maxDNF form:

maxDNF (φ) = (¬p ∧ ¬q ∧ ¬r ∧ ¬s) ∨ (¬p ∧ ¬q ∧ ¬r ∧ s) ∨ (¬p ∧ ¬q ∧ r ∧ s)∨

(¬p ∧ q ∧ ¬r ∧ ¬s) ∨ (¬p ∧ q ∧ ¬r ∧ s) ∨ (¬p ∧ q ∧ r ∧ s)∨

(p ∧ q ∧ ¬r ∧ ¬s) ∨ (p ∧ q ∧ ¬r ∧ s) ∨ (p ∧ q ∧ r ∧ s).

Transform ϕ to DNF:

ϕ = (p ∨ r)⇒ (q ∨ s) = ¬(p ∨ r) ∨ q ∨ s = (¬p ∧ ¬r) ∨ q ∨ s =

= (¬p ∧ ¬r) ∨ q ∨ s.

and next to its maxDNF form:

maxDNF (ϕ) = (¬p ∧ ¬q ∧ ¬r ∧ ¬s) ∨ (¬p ∧ ¬q ∧ ¬r ∧ s) ∨ (¬p ∧ ¬q ∧ r ∧ s)∨

(¬p ∧ q ∧ ¬r ∧ ¬s) ∨ (¬p ∧ q ∧ ¬r ∧ s) ∨ (¬p ∧ q ∧ r ∧ s)∨

(¬p ∧ q ∧ r ∧ ¬s) ∨ (p ∧ q ∧ ¬r ∧ ¬s) ∨ (p ∧ q ∧ ¬r ∧ s)∨

(p ∧ q ∧ r ∧ s) ∨ (p ∧ q ∧ r ∧ ¬s) ∨ (p ∧ ¬q ∧ ¬r ∧ s)∨

(p ∧ ¬q ∧ r ∧ s).

Page 33: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 33

It can be seen that:

[maxDNF (φ)] ⊆ [maxDNF (ϕ)],

c©Antoni Ligeza

Page 34: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 34

Logic for KRR — Tasks and Tools

• Theorem Proving — Verification of Logical Consequence:

∆ |= H;

• Automated Inference —- Derivation:

∆ ` H;

• SAT (checking for models) — satisfiability:

|=I H (if such I exists);

• un-SAT verification — unsatisfiability:

6|=I H (for any I);

• Tautology verification (completeness):

|= H

• valid inference rules — checking:

(∆ ` H) −→ (∆ |= H)

• complete inference rules — checking:

(∆ |= H) −→ (∆ ` H)

Two basic approaches – reasoning paradigmes:

• systematic evaluation of possible interpretations — the 0-1 method;

problem — combinatorial explosion,

Page 35: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 35

• logical inference — derivation — with rules preserving logical conse-

quence.

Notation: formula H is derivable from ∆:

∆ ` H

Two principal issues in logical knowledge-based systems:

∆ ` H versus ∆ |= H

c©Antoni Ligeza

Page 36: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 36

Some more important inference rules

• α

α ∨ β— Disjunction Introduction,

• α, β

α ∧ β— Conjunction Introduction,

• α ∧ βα

— Conjunction Elimination,

• α, α⇒ β

β— Modus Ponens (modus ponendo ponens); implication

elimination (EI),

• α⇒ β, ¬β¬α

— Modus Tollens (modus tollendo tollens),

• α ∨ β, ¬αβ

— Modus Tollendo Ponens,

• α⊕

β, α

¬β— Modus Ponendo Tollens,

• α⇒ β, β ⇒ γ

α⇒ γ— Transitivity Rule,

• α ∨ γ, ¬γ ∨ βα ∨ β

— Resolution Rule,

• α ∧ γ, ¬γ ∧ βα ∧ β

— Dual Resolution Rule; (backward) dual resolution

(works backwards); also consolution

• α⇒ β, γ ⇒ δ

(α ∨ γ)⇒ (β ∨ δ)— Constructive Dilemma I,

• α⇒ β, γ ⇒ δ

(α ∧ γ)⇒ (β ∧ δ)— Constructive Dilemma II.

c©Antoni Ligeza

Page 37: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 37

The Deduction Theorems

Twierdzenie 1 Let ∆1,∆2, . . .∆n and Ω are logical formulas. Ω is their logi-

cal consequence iff ∆1 ∧∆2 ∧ . . .∆n ⇒ Ω is a tautology.

Twierdzenie 2 Let ∆1,∆2, . . .∆n and Ω are logical formulas. Ω is their logi-

cal consequence iff ∆1 ∧ ∆2 ∧ . . .∆n ∧ ¬Ω is invalid (false under any inter-

pretation).

Theorem proving: having ∆1,∆2, . . .∆n assumed to be true show that so is

Ω. Hence:

∆1 ∧∆2 ∧ . . .∆n |= Ω

Basic methods for theorem proving:

• evaluation of all possible interpretations (the 0-1 method),

• direct proof (forward chaining) – derivation of Ω from initial axioms,

• search for proof (backward chaining) – search for derivation of Ω from

initial axioms; Backtracking Search,

• proving tautology – from the Deduction Theorem 1 we prove that

∆1 ∧∆2 ∧ . . .∆n ⇒ Ω is a tautology,

• indirect proof – through constraposition:

¬Ω⇒ ¬(∆1 ∧∆2 ∧ . . .∆n).

• Reductio ad Absurdum; basing on Deduction Theorem 2 we show that

∆1 ∧∆2 ∧ . . .∆n ∧ ¬Ω.

is unsatisfiable

c©Antoni Ligeza

Page 38: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 38

Examples

Direct proof: (p⇒ r) ∧ (q ⇒ s) ∧ (¬r ∨ ¬s) |= (¬p ∨ ¬q):

1. p⇒ r assumption,

2. q ⇒ s assumption,

3. ¬r ∨ ¬s assumption,

4. s⇒ ¬r implication reconstruction; through equivalence to 3,

5. q ⇒ ¬r transitivity 2 and 4,

6. ¬p ∨ r EI from 1,

7. ¬q ∨ ¬r EI from 5

8. ¬p ∨ ¬q by resolution rule from 6 and 7.

Proving tautology: [p⇒ (q ⇒ r)] |= [q ⇒ (p⇒ r)].

We transform the formula [p ⇒ (q ⇒ r)] ⇒ [q ⇒ (p ⇒ r)] and through

elimination of implications we obtain α ∨ ¬α.

Indirect proof: p |= ¬q ⇒ ¬(p⇒ q)

1. ¬(¬q ⇒ ¬(p⇒ q)) assumption (contraposition),

2. ¬(q ∨ ¬(p⇒ q)) EI,

3. (¬q ∧ (p⇒ q)) De Morgan rule,

4. ¬q CE,

5. p⇒ q CE from 3,

6. ¬p ∨ q EI from 5,

Page 39: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 39

7. q ∨ ¬p commutativity from 6,

8. ¬p RR from 4 and 7.

Reductio ad Absurdum: (p ∨ q) ∧ ¬p |= q

1. p ∨ q assumption,

2. ¬p assumption,

3. ¬q assumption (negation of the hypothesis),

4. q RR to 1 and 2

5. ⊥ from 3 and 4.

c©Antoni Ligeza

Page 40: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 40

Example: Logical Consequence

(p⇒ q) ∧ (r ⇒ s)

(p ∨ r)⇒ (q ∨ s)Let us put:

φ = (p⇒ q) ∧ (r ⇒ s)

and

ϕ = (p ∨ r)⇒ (q ∨ s),

So we have to check if:

φ |= ϕ. (5)

p q r s p⇒ q r ⇒ s (p⇒ q) ∧ (r ⇒ s) p ∨ r q ∨ s (p ∨ r)⇒ (q ∨ s)

0 0 0 0 1 1 1 0 0 10 0 0 1 1 1 1 0 1 10 0 1 0 1 0 0 1 0 00 0 1 1 1 1 1 1 1 10 1 0 0 1 1 1 0 1 10 1 0 1 1 1 1 0 1 10 1 1 0 1 0 0 1 1 10 1 1 1 1 1 1 1 1 11 0 0 0 0 1 0 1 0 01 0 0 1 0 1 0 1 1 11 0 1 0 0 0 0 1 0 01 0 1 1 0 1 0 1 1 11 1 0 0 1 1 1 1 1 11 1 0 1 1 1 1 1 1 11 1 1 0 1 0 0 1 1 11 1 1 1 1 1 1 1 1 1

From columns 7 and 10 we conclude that there is logical consequence (but

no equivalence — 7, 10, 12 i 15).

c©Antoni Ligeza

Page 41: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 41

The Resolution Method

1. Problem:

∆ |= H

2. From Deduction Theorem 2:

∆ ∪ ¬H

should be unsatisfiable.

3. Transform ∆ ∪ ¬H to CNF.

4. Using the RR derive an empty formula ⊥.

Example:

1. Problem:

(p⇒ q) ∧ (r ⇒ s) |= (p ∨ r)⇒ (q ∨ s)

2. From Deduction Theorem 2 — show that:

[(p⇒ q) ∧ (r ⇒ s)] ∪ ¬[(p ∨ r)⇒ (q ∨ s)]

is unsatisfiable.

3. After transformation to CNF we have:

¬p ∨ q,¬r ∨ s, p ∨ r,¬q,¬s

4. Derive ⊥.

c©Antoni Ligeza

Page 42: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 42

Dual Resolution Method

1. Problem:

∆ |= H

2. From Deduction Theorem 1 show that:

∆⇒ H

is a tautology.

3. Transform ∆⇒ H to DNF.

4. Using the DRR derive an empty formula — the always true one >.

Example:

1. Problem:

(p⇒ q) ∧ (r ⇒ s) |= (p ∨ r)⇒ (q ∨ s)

2. From Deduction Theorem 1 show that:

[(p⇒ q) ∧ (r ⇒ s)]⇒ [(p ∨ r)⇒ (q ∨ s)]

is a tautology.

3. After transformation to DNF we have:

p ∧ ¬q, r ∧ ¬s,¬p ∧ ¬r, q, s

4. Using the DRR derive an empty formula — the always true one >.

c©Antoni Ligeza

Page 43: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 43

Example of Resolution Derivation

A – signal from process,

P – signal added to a queue,

B – signal blocked by process,

D – signal received by process,

S – state of the process saved,

M – signal mask read,

H – signal management procedure activated,

N – procedure executed in normal mode,

R – process restart from context,

I – process must re-create context.

Rules — axiomatization:

A −→ P ,

P ∧ ¬B −→ D,

D −→ S ∧M ∧H,

H ∧N −→ R,

H ∧ ¬R −→ I,

Facts:

A, ¬B, ¬R.

Page 44: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 44

Application of RR to CNF:

¬A∨P,¬P∨B∨D,¬D∨S,¬D∨M,¬D∨H,¬H∨¬N∨R,¬H∨R∨I, A,¬B,¬R

Conclusions

P , D, S, M , H, I, ¬N .

c©Antoni Ligeza

Page 45: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 45

Inference step; derivation

Step of inference: single application of RR.

Example:

Application of RR:φ ∨ ¬p, p ∨ ψ

φ ∨ ψNotation: φ ∨ ¬p, p ∨ ψ `R φ ∨ ψ

Definicja 22 Derivation A derivation of φ from ∆ we call a sequence:

φ1, φ2 . . . φk

such that:

• formula φ1 is derivable from ∆ (in a single step):

∆ ` φ1,

• every next formula is derivable from ∆ and the earlier-derived formulas:

∆, φ1, φ2, . . . , φi ` φi+1

for i = 2, 3, . . . , k − 1,

• φ is the last formula:

φ = φk

Notation: ∆ ` φ, and φ is called derivable from ∆.

c©Antoni Ligeza

Page 46: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 46

Set of Logical Consequences Cn

Definicja 23 Let ∆ be set of formulas. The set of logical consequences is:

Cn(∆) = φ : ∆ |= φ

where every φ contains (only) propositional symbols of ∆.

Lemat 7 Properties of Cn There are:

• ∆ ⊆ Cn(∆),

• monotonicity — if ∆1 ⊆ ∆2, then:

Cn(∆1) ⊆ Cn(∆2)

• Cn(Cn(∆)) = Cn(∆) (the so-called fixed point).

c©Antoni Ligeza

Page 47: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 47

Constructive Theorem Proving: The Fitch System

• AND Introduction (AI):φ1, . . . , φnφ1 ∧ . . . ∧ φn

• AND Elimination (AE):φ1 ∧ . . . ∧ φn

φi

• OR Introduction (OI):φi

φ1 ∨ . . . ∨ φn• OR Elimination (OE):

φ1 ∨ . . . ∨ φn, φ1 ⇒ ψ, . . . φn ⇒ ψ

ψ

• Negation Introduction (NI):

φ⇒ ψ, φ⇒ ¬ψ¬φ

• Negation Elimination (NE):¬¬φφ

• Implication Introduction (II):

φ ` ψφ⇒ ψ

• Implication Elimination (IE):

φ, φ⇒ ψ

ψ

• Equivalence Introduction (EI),

• Equivalence Elimination (EE)

c©Antoni Ligeza

Page 48: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 48

SAT by Example: Unicorn

Given the following Knowledge Base (KB):

• If the unicorn is mythical, then it is immortal

• If the unicorn is not mythical, then it is a mortal mammal

• If the unicorn is either immortal or a mammal, then it is horned

• The unicorn is magical if it is horned

answer the following questions:

• Is the unicorn mythical? (M )

• Is it magical? (G)

• Is it horned? (H)

In terms of logic:

KB |= G,H,M

KB ` G,H,Mc©Antoni Ligeza

Page 49: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 49

Unicorn - Logical Model

Definition of propositional variables:

• M: The unicorn is mythical

• I: The unicorn is immortal

• L: The unicorn is mammal

• H: The unicorn is horned

• G: The unicorn is magical

Building a Logical Model for the puzzle:

• If the unicorn is mythical, then it is immortal:

M −→ I

• If the unicorn is not mythical, then it is a mortal mammal:

¬M −→ (¬I ∧ L)

• If the unicorn is either immortal or a mammal, then it is horned:

(I ∨ L) −→ H

• The unicorn is magical if it is horned:

H −→ G

Resulting Boolean formula (the Knowledge Base):

(M −→ I) ∧ (¬M −→ (¬I ∧ L)) ∧ ((I ∨ L) −→ H) ∧ (H −→ G)

c©Antoni Ligeza

Page 50: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 50

A Solution

(M −→ I) ≡ (¬M ∨ I)

(¬M −→ (¬I ∧ L)) ≡ (M ∨ (¬I ∧ L))

(M ∨ (¬I ∧ L)) ≡ ((M ∨ ¬I) ∧ (M ∨ L))

¬M ∨ I,M ∨ LI ∨ L

I ∨ L, (I ∨ L) −→ H

H

H,H −→ G

G

So we have:

KB ` H ∧G

Questions:

• What about M (mythical), I (immortal) and L (mammal)?

• What are the exact models? What combinations are admissible?

• How many models do we have?

c©Antoni Ligeza

Page 51: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 51

SAT: Transformation to CNF and Encoding

Introducing enumeration:

1. M: The unicorn is mythical

2. I: The unicorn is immortal

3. L: The unicorn is mammal

4. H: The unicorn is horned

5. G: The unicorn is magical

Building a Logical Model for the puzzle:

• If the unicorn is mythical, then it is immortal:

M −→ I

• If the unicorn is not mythical, then it is a mortal mammal:

¬M −→ (¬I ∧ L)

• If the unicorn is either immortal or a mammal, then it is horned:

(I ∨ L) −→ H

• The unicorn is magical if it is horned:

H −→ G

c©Antoni Ligeza

Page 52: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 52

CNF and Encoded File

Resulting CNF:

¬M ∨ I,M ∨ ¬I,M ∨ L,¬I ∨H,¬L ∨H,¬H ∨G

-1 2

1 -2

1 3

-2 4

-3 4

-4 5

Input file in the DIMACS format:

p cnf 5 6

-1 2 0

1 -2 0

1 3 0

-2 4 0

-3 4 0

-4 5 0

Using Minisat

Page: http://minisat.se/

Online: http://www.msoos.org/2013/09/minisat-in-your-browser/

Manual: http://www.dwheeler.com/essays/minisat-user-guide.html

How to get ALL solutions?

c©Antoni Ligeza

Page 53: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 53

Extra problem

Assumptions:

A1. There are 3 houses in a row

A2. The houses are numbered 1, 2 and 3, from left to right

A3. Each house has one of the colors Blue, Green or White

A4. Each house is inhabited by one person with one of the nationalities:

Dutch, German and Italian

A5. Each person drinks (exactly one) of the following beverages: Coffee,

Tea and Water

Conditions (constraints):

C1 The third house is green

C2 There is one house between the house of the person drinking coffee

and the blue house

C3 The person drinking water lives in the blue house

C4 The Italian lives to the left of the coffee drinking person

C5 The German lives in house two

Query:

Who lives in the 1st house? What does the Dutch drink?

c©Antoni Ligeza

Page 54: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 54

References

1. Mordechai Ben-Ari: Mathematical Logic for Computer Science (Logika

matematyczna w informatyce). Springer-Verlag, London, 2001 (WN-T,

Warszawa, 2005).

2. Kenneth A. Ross i Charles R. B. Wright: Discrete Mathematics (Mate-

matyka dyskretna). WN PWN, 2013.

3. Antoni Ligeza: Logical Foundations for Rule-Based Systems.

Springer-Verlag, Berlin, 2006. Wydawnictwo AGH, Kraków, 2005.

4. Michael R. Genesereth, Nils J. Nilsson: Logical Foundations of Artificial

Intelligence. Morgan Kaufmann Publishers, Inc., Los Altos, California,

1987.

5. Zbigniew Huzar: Elementy logiki dla informatyków. Oficyna Wydawni-

cza Politechniki Wrocławskiej, Wrocław, 2007.

6. Stuart Russell, Peter Norvig: Artificial Intelligence. A Modern Appro-

ach. Pearson, 2010.

7. Marek Wójcik: Zasada rezolucji. Metoda automatycznego wnioskowa-

nia. PWN, Warszawa, 1991.

8. C. L. Chang and R. C. T. Lee: Symbolic Logic and Mechanical Theorem

Proving. Academic Press, 1973.

9. Ronald J. Brachman and Hector J. Levesque: Knowledge Representa-

tion and Reasoning. Morgan Kaufmann, 2004.

10. Frank van Harmelen, Vladimir Lifschitz, Bruce Porter (Eds.): Hand-

book of Knowledge Representation. Elsevier B.V., Amsterdam, 2008.

http://ii.fmph.uniba.sk/~sefranek/kri/handbook/

c©Antoni Ligeza

Page 55: Knowledge Representation and Reasoning. Propositional Logicdydaktyka:krr:krr-logics-pc.pdf · Knowledge-Based Systems: Basic Concepts We need some tools: Aformal languagefor KRR:

Lecture Notes 55

On the Net; Stanford/Coursera

Coursera on-line/Stanford:

https://www.coursera.org/course/intrologic

1. Wikipedia-pl: http://pl.wikipedia.org/wiki/Logika_

matematyczna

2. Wikipedia-en: http://en.wikipedia.org/wiki/Logic

3. AI-Lab-Prolog: http://ai.ia.agh.edu.pl/wiki/pl:prolog:

prolog_lab

4. EIS-KRR: http://ai.ia.agh.edu.pl/wiki/pl:dydaktyka:

krr:start

5. ALI-home: home.agh.edu.pl/~ligeza

6. David Poole and Allen Mackworth: Artificial Intelligence. Foundations

of Computational Agents. http://artint.info/

7. Ulf Nilsson and Jan Maluszynski: Logic, Programming and Prolog.

http://www.ida.liu.se/~ulfni/lpp/

8. Inês Lynce: Boolean SATisfiability. Materiały z kursu ACAI, Lille, Octo-

ber 2015.

c©Antoni Ligeza