introduction to artificial intelligence · p: it is a tuesday. q: it is raining. r: harry will go...

99
Introduction to Artificial Intelligence with Python

Upload: others

Post on 31-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Introduction to Artificial Intelligence

with Python

Page 2: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Knowledge

Page 3: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

knowledge-based agents

agents that reason by operating on internal representations of knowledge

Page 4: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

If it didn't rain, Harry visited Hagrid today.

Harry visited Hagrid or Dumbledore today, but not both.

Harry visited Dumbledore today.

It rained today.

Harry did not visit Hagrid today.

Page 5: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Logic

Page 6: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

sentence

an assertion about the world in a knowledge representation language

Page 7: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Propositional Logic

Page 8: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Proposition Symbols

P Q R

Page 9: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Logical Connectives

¬not

∧and

∨or

→implication

↔biconditional

Page 10: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Not (¬)

P ¬Pfalse true

true false

Page 11: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

And (∧)

P Q P ∧ Qfalse false false

false true false

true false false

true true true

Page 12: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Or (∨)

P Q P ∨ Qfalse false false

false true true

true false true

true true true

Page 13: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Implication (→)

P Q P → Qfalse false true

false true true

true false false

true true true

Page 14: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Biconditional (↔)

P Q P ↔ Qfalse false true

false true false

true false false

true true true

Page 15: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

model

assignment of a truth value to every propositional symbol (a "possible world")

Page 16: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

modelP: It is raining.

Q: It is a Tuesday.

{P = true, Q = false}

Page 17: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

knowledge base

a set of sentences known by a knowledge-based agent

Page 18: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Entailment

α ⊨ β

In every model in which sentence α is true, sentence β is also true.

Page 19: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

If it didn't rain, Harry visited Hagrid today.

Harry visited Hagrid or Dumbledore today, but not both.

Harry visited Dumbledore today.

It rained today.

Harry did not visit Hagrid today.

Page 20: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

inference

the process of deriving new sentences from old ones

Page 21: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P: It is a Tuesday.

Q: It is raining.

R: Harry will go for a run.

KB: (P ∧ ¬Q) → R P ¬Q

Inference: R

Page 22: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference Algorithms

Page 23: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Does

?

KB ⊨ α

Page 24: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Model Checking

Page 25: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Model Checking

• To determine if KB ⊨ α:

• Enumerate all possible models.

• If in every model where KB is true, α is true, then KB entails α.

• Otherwise, KB does not entail α.

Page 26: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P: It is a Tuesday. Q: It is raining. R: Harry will go for a run.

KB: (P ∧ ¬Q) → R P ¬QQuery: R

P Q R KBfalse false falsefalse false truefalse true falsefalse true truetrue false falsetrue false truetrue true falsetrue true true

Page 27: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P: It is a Tuesday. Q: It is raining. R: Harry will go for a run.

KB: (P ∧ ¬Q) → R P ¬QQuery: R

P Q R KBfalse false false falsefalse false true falsefalse true false falsefalse true true falsetrue false false falsetrue false true truetrue true false falsetrue true true false

Page 28: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P: It is a Tuesday. Q: It is raining. R: Harry will go for a run.

KB: (P ∧ ¬Q) → R P ¬QQuery: R

P Q R KBfalse false false falsefalse false true falsefalse true false falsefalse true true falsetrue false false falsetrue false true truetrue true false falsetrue true true false

Page 29: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Knowledge Engineering

Page 30: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue

Page 31: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue

Col. Mustard

People

Prof. Plum

Ms. Scarlet

Ballroom

Rooms

Kitchen

Library

Knife

Weapons

Revolver

Wrench

Page 32: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue

Col. Mustard

People

Prof. Plum

Ms. Scarlet

Ballroom

Rooms

Kitchen

Library

Knife

Weapons

Revolver

Wrench

Page 33: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue

Col. Mustard

People

Prof. Plum

Ms. Scarlet

Ballroom

Rooms

Kitchen

Library

Knife

Weapons

Revolver

Wrench

Page 34: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Col. Mustard

People

Prof. Plum

Ms. Scarlet

Ballroom

Rooms

Kitchen

Library

Knife

Weapons

Revolver

Wrench

Page 35: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Col. Mustard

People

Prof. Plum

Ms. Scarlet

Ballroom

Rooms

Kitchen

Library

Knife

Weapons

Revolver

Wrench

Page 36: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue

Propositional Symbols

mustard plum scarlet

ballroom kitchen library

knife revolver wrench

Page 37: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Clue(mustard ∨ plum ∨ scarlet)

(ballroom ∨ kitchen ∨ library)(knife ∨ revolver ∨ wrench)

¬plum

¬mustard ∨ ¬library ∨ ¬revolver

Page 38: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Logic Puzzles

• Gilderoy, Minerva, Pomona and Horace each belong to a different one of the four houses: Gryffindor, Hufflepuff, Ravenclaw, and Slytherin House.

• Gilderoy belongs to Gryffindor or Ravenclaw.

• Pomona does not belong in Slytherin.

• Minerva belongs to Gryffindor.

Page 39: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Logic Puzzles

Propositional Symbols

GilderoyGryffindor GilderoyHufflepuff GilderoyRavenclaw GilderoySlytherin

MinervaGryffindor MinervaHufflepuff MinervaRavenclaw MinervaSlytherin

PomonaGryffindor PomonaHufflepuff PomonaRavenclaw PomonaSlytherin

HoraceGryffindor HoraceHufflepuff HoraceRavenclaw HoraceSlytherin

Page 40: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Logic Puzzles

(GilderoyGryffindor ∨ GilderoyRavenclaw)

(PomonaSlytherin → ¬PomonaHufflepuff)

(MinervaRavenclaw → ¬GilderoyRavenclaw)

Page 41: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Mastermind

2

0

4

Page 42: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference Rules

Page 43: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

If it is raining, then Harry is inside.

It is raining.

Harry is inside.

Modus Ponens

Page 44: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

α → β

α

β

Modus Ponens

Page 45: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Harry is friends with Ron and Hermione.

Harry is friends with Hermione.

And Elimination

Page 46: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

α ∧ β

α

And Elimination

Page 47: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

It is not true that Harry did not pass the test.

Harry passed the test.

Double Negation Elimination

Page 48: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

¬(¬α)

α

Double Negation Elimination

Page 49: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

If it is raining, then Harry is inside.

It is not raining or Harry is inside.

Implication Elimination

Page 50: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

α → β

¬α ∨ β

Implication Elimination

Page 51: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

It is raining if and only if Harry is inside.

If it is raining, then Harry is inside, and if Harry is inside, then it is raining.

Biconditional Elimination

Page 52: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

α ↔ β

(α → β) ∧ (β → α)

Biconditional Elimination

Page 53: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

It is not true that both Harry and Ron passed the test.

Harry did not pass the test or Ron did not pass the test.

De Morgan's Law

Page 54: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

¬(α ∧ β)

¬α ∨ ¬β

De Morgan's Law

Page 55: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

It is not true that Harry or Ron passed the test.

Harry did not pass the test and Ron did not pass the test.

De Morgan's Law

Page 56: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

¬(α ∨ β)

¬α ∧ ¬β

De Morgan's Law

Page 57: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

(α ∧ (β ∨ γ))

(α ∧ β) ∨ (α ∧ γ)

Distributive Property

Page 58: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

(α ∨ (β ∧ γ))

(α ∨ β) ∧ (α ∨ γ)

Distributive Property

Page 59: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Search Problems

• initial state

• actions

• transition model

• goal test

• path cost function

Page 60: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Theorem Proving

• initial state: starting knowledge base

• actions: inference rules

• transition model: new knowledge base after inference

• goal test: check statement we're trying to prove

• path cost function: number of steps in proof

Page 61: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Resolution

Page 62: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

(Ron is in the Great Hall) ∨ (Hermione is in the library)

Ron is not in the Great Hall

Hermione is in the library

Page 63: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q

¬P

Q

Page 64: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q1 ∨ Q2 ∨ ...∨ Qn

¬P

Q1 ∨ Q2 ∨ ...∨ Qn

Page 65: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

(Ron is in the Great Hall) ∨ (Hermione is in the library)

(Ron is not in the Great Hall) ∨ (Harry is sleeping)

(Hermione is in the library) ∨ (Harry is sleeping)

Page 66: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q

¬P ∨ R

Q ∨ R

Page 67: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q1 ∨ Q2 ∨ ...∨ Qn

¬P ∨ R1 ∨ R2 ∨ ...∨ Rm

Q1 ∨ Q2 ∨ ...∨ Qn ∨ R1 ∨ R2 ∨ ...∨ Rm

Page 68: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

clause

a disjunction of literals

e.g. P ∨ Q ∨ R

Page 69: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

conjunctive normal form

logical sentence that is a conjunction of clauses

e.g. (A ∨ B ∨ C) ∧ (D ∨ ¬E) ∧ (F ∨ G)

Page 70: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Conversion to CNF

• Eliminate biconditionals

• turn (α ↔ β) into (α → β) ∧ (β → α)

• Eliminate implications

• turn (α → β) into ¬α ∨ β

• Move ¬ inwards using De Morgan's Laws

• e.g. turn ¬(α ∧ β) into ¬α ∨ ¬β

• Use distributive law to distribute ∨ wherever possible

Page 71: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Conversion to CNF

(P ∨ Q) → R

¬(P ∨ Q) ∨ R

(¬P ∧ ¬Q) ∨ R

(¬P ∨ R) ∧ (¬Q ∨ R)

eliminate implication

De Morgan's Law

distributive law

Page 72: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Page 73: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q

¬P ∨ R

(Q ∨ R)

Page 74: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q ∨ S

¬P ∨ R ∨ S

(Q ∨ S ∨ R ∨ S)

Page 75: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P ∨ Q ∨ S

¬P ∨ R ∨ S

(Q ∨ R ∨ S)

Page 76: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

P

¬P

( )

Page 77: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

• To determine if KB ⊨ α:

• Check if (KB ∧ ¬α) is a contradiction?

• If so, then KB ⊨ α.

• Otherwise, no entailment.

Page 78: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

• To determine if KB ⊨ α:

• Convert (KB ∧ ¬α) to Conjunctive Normal Form.

• Keep checking to see if we can use resolution to produce a new clause.

• If ever we produce the empty clause (equivalent to False), we have a contradiction, and KB ⊨ α.

• Otherwise, if we can't add new clauses, no entailment.

Page 79: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(A ∨ B) (¬B ∨ C) (¬C) (¬A)

Page 80: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(A ∨ B) (¬B ∨ C) (¬C) (¬A)

Page 81: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A)

Page 82: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A)

Page 83: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A)

Page 84: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A) (A)

Page 85: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A) (A)

Page 86: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A) (A)

Page 87: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A) (A) ( )

Page 88: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Inference by Resolution

Does (A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) entail A?

(A ∨ B) ∧ (¬B ∨ C) ∧ (¬C) ∧ (¬A)

(¬B)(A ∨ B) (¬B ∨ C) (¬C) (¬A) (A) ( )

Page 89: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

First-Order Logic

Page 90: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Propositional Logic

MinervaGryffindorMinervaHufflepuff

Propositional Symbols

MinervaRavenclawMinervaSlytherin…

Page 91: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

First-Order Logic

Minerva Pomona Horace Gilderoy Gryffindor Hufflepuff Ravenclaw Slytherin

Constant Symbol Predicate Symbol

Person House BelongsTo

Page 92: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

First-Order Logic

Person(Minerva) Minerva is a person.

House(Gryffindor) Gryffindor is a house.

¬House(Minerva) Minerva is not a house.

BelongsTo(Minerva, Gryffindor)Minerva belongs to Gryffindor.

Page 93: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Universal Quantification

Page 94: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Universal Quantification

∀x. BelongsTo(x, Gryffindor) → ¬BelongsTo(x, Hufflepuff)

For all objects x, if x belongs to Gryffindor, then x does not belong to Hufflepuff.

Anyone in Gryffindor is not in Hufflepuff.

Page 95: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Existential Quantification

Page 96: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Existential Quantification

∃x. House(x) ∧ BelongsTo(Minerva, x)

There exists an object x such that x is a house and Minerva belongs to x.

Minerva belongs to a house.

Page 97: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Existential Quantification

∀x. Person(x) → (∃y. House(y) ∧ BelongsTo(x, y))

For all objects x, if x is a person, then there exists an object y such that

y is a house and x belongs to y.

Every person belongs to a house.

Page 98: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Knowledge

Page 99: Introduction to Artificial Intelligence · P: It is a Tuesday. Q: It is raining. R: Harry will go for a run. KB: (P ∧ ¬Q) → R P ¬QQuery: R P Q R KB false false false false

Introduction to Artificial Intelligence

with Python