0% found this document useful (0 votes)
5 views

Unit3_Knowledge_9_11_2024-9pm

Uploaded by

prabhanjan.cs22
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit3_Knowledge_9_11_2024-9pm

Uploaded by

prabhanjan.cs22
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 138

Course – Artificial Intelligence

Course Instructor
Dr. Umadevi V
Department of CSE, BMSCE

January 21, 2025 BMSCE 1


Unit-3

Logical Agents: Knowledge–based agents, The


Wumpus world, Logic, Propositional logic, First Order
Logic: Representation Revisited, Syntax and
Semantics of First Order logic, Using First Order logic.

January 21, 2025 BMSCE 2


Discussion
 What is Knowledge ?
 Knowledge is what you've learned.
 Knowledge is the information you've obtained, whether
through education or from life experience.

 What is Intelligence ?
 Intelligence is how you use that knowledge
 Intelligence is how you've processed that knowledge.

January 21, 2025 BMSCE 3


Knowledge and Intelligence
 Does Knowledge have any role in
demonstrating intelligent behavior ?

Sensing
Decision
Knowledge
Maker

Action

January 21, 2025 BMSCE 4


Knowledge Representation and Reasoning

Intelligent agents should have capacity


for:
 Perceiving, that is, acquiring information from
environment,
 Knowledge Representation, that is,
representing its understanding of the world,
 Reasoning, that is, inferring the implications of
what it knows and of the choices it has, and
 Acting, that is, choosing what it want to do and
carry it out.

January 21, 2025 BMSCE 5


Knowledge-Based Agent (KBA)
 Knowledge-based agents are artificial intelligence systems that
use knowledge to perform their tasks.

 Knowledge-Based Agents are Composed of Two Main Parts


 Knowledge-Base (KB): The knowledge base of a knowledge-based agent is a collection
of knowledge that the agent uses to make decisions. The knowledge can be explicit, such
as rules or facts, or implicit, such as relationships or patterns. The knowledge base is
stored in a database or a knowledge representation system.
 Inference System: The inference system of a knowledge-based agent is responsible for
using the knowledge in the knowledge base to make decisions. The inference system
uses reasoning methods, such as deduction, induction, and abduction, to infer new
knowledge from existing knowledge.

January 21, 2025 BMSCE 6


The Architecture of Knowledge-Based Agent

 The KBA receives input from the environment through


perception, which the inference engine processes.
 The inference engine communicates with the knowledge base
(KB) to determine the appropriate action based on the
knowledge stored in the KB.

January 21, 2025 BMSCE 7


Knowledge-Based Agent

Domain independent algorithms

ASK Inference engine

TELL Knowledge Base

Domain specific content

Tell it what it needs to know


Then it can ask itself what to do—answers follow from the knowledge base

January 21, 2025 BMSCE 8


Knowledge-Based Agent
 Agent that uses prior or acquired knowledge to achieve
its goals
 Can make more efficient decisions
 Can make informed decisions
 Knowledge Base (KB): contains a set of representations
of facts about the Agent’s environment
 Each representation is called a sentence
 Use some knowledge representation language, to
TELL it what to know e.g., (temperature 32oC)
 ASK agent to query what to do
 Agent can use inference to deduce new facts from
TELLed facts

January 21, 2025 BMSCE 9


Generic Knowledge-Based Agent
A knowledge-based agent uses its knowledge base to
• represent its background knowledge
• store its observations
• store its executed actions
• . . . derive actions

January 21, 2025 BMSCE 10


Generic Knowledge-Based Agent

January 21, 2025 BMSCE 11


Example for Knowledge-based Agent Wumpus World

January 21, 2025 BMSCE 12


The Wumpus World: Example

January 21, 2025 BMSCE 13


The Wumpus World: Example

Finite number of Actions

January 21, 2025 BMSCE 14


Solve Wumpus World Problem

January 21, 2025 BMSCE 15


The Wumpus World: Example

January 21, 2025 BMSCE 16


The Wumpus World: Example

How you will explore


the Wumpus world
to acquire gold ?

January 21, 2025 BMSCE 17


The Wumpus World: Example
 A 4 × 4 grid
 In the square containing the wumpus and in the directly
adjacent squares, the agent perceives a stench.
 In the squares adjacent to a pit, the agent perceives a
breeze.
 In the square where the gold is, the agent perceives a
glitter.
 When the agent walks into a wall, it perceives a bump.
 When the wumpus is killed, its scream is heard
everywhere.
 Percepts are represented as a 5-tuple, e.g.,
[Stench, Breeze, Glitter , None, None]
means that it stinks, there is a breeze and a glitter, but no
bump and no scream. The agent cannot perceive its own
location.
January 21, 2025 BMSCE 18
The Wumpus World: Example
 Actions: Go forward, turn right by 90o, turn left
by 90o, pick up an object in the same square
(grab), shoot (there is only one arrow), leave
the cave (only works in square [1,1]).
 The agent dies if it falls down a pit or meets a
live wumpus.
 Initial situation: The agent is in square [1,1]
facing east. Somewhere exists a wumpus, a
pile of gold and 3 pits.
 Goal: Find the gold and leave the cave.

January 21, 2025 BMSCE 19


Reasoning in the Wumpus World

January 21, 2025 BMSCE 20


Reasoning in the Wumpus World

January 21, 2025 BMSCE 21


Problematic Situations

1 2 3

January 21, 2025 BMSCE 22


Problematic Situations

2 W?

1 W?

1 2

January 21, 2025 BMSCE 23


The Knowledge Base

January 21, 2025 BMSCE 24


Logic in General

January 21, 2025 BMSCE 25


Example

January 21, 2025 BMSCE 26


Entailment

January 21, 2025 BMSCE 27


Example of Entailment

January 21, 2025 BMSCE 28


Entailment

January 21, 2025 BMSCE 29


Entailment

January 21, 2025 BMSCE 30


Models

January 21, 2025 BMSCE 31


January 21, 2025 BMSCE 32
Models and Entailment

January 21, 2025 BMSCE 33


Entailment Applied to the Wumpus World

January 21, 2025 BMSCE 34


Entailment Applied to the Wumpus World

Now let us consider two possible conclusions:

Now we have to Show

there is no pit in [1,2].

the agent cannot conclude that there is no pit in [2,2]

January 21, 2025 BMSCE 35


January 21, 2025 BMSCE 36
Entailment by Model Checking

January 21, 2025 BMSCE 37


Entailment by Model Checking

January 21, 2025 BMSCE 38


Question
Suppose the agent has progressed to the point shown in Figure below, , having
perceived nothing in [1,1], a breeze in [2,1], and a stench in [1,2], and is now
concerned with the contents of [1,3], [2,2], and [3,1]. Each of these can contain a pit,
and at most one can contain a Wumpus. Following the example of Figure 7.5, construct
the set of possible worlds. (You should find 32 of them.) Mark the worlds in which the
KB is true and those in which each of the following sentences is true:

January 21, 2025 BMSCE 39


Below you will see the table I made that shows all 32 possibilities. This was actually pretty easy to do,
basically you are making a huge truth table for the problem. Either they can contain a pit, and at
most only 1 can contain a wumpus.

As you can see, some of these


will never happen because they
can only be a pit or a wumpus
not both.

January 21, 2025 BMSCE 40


The only worlds where there is no pit in [2,2] are; 4, 5, 6, 7, 8, 9, 13, 14, 15, 22, 23,
24, 26, 28, 30, 32, that’s a total of 16 worlds. Below I’ve highlighted the worlds for
you:

January 21, 2025 BMSCE 41


Knowledge base (KB)
The knowledge base (KB) for the wumpus world from figure
is:
 Stench in [1,2] means that there must be a wumpus in
[1,3] or [2,2].
Breeze in [2,1] means that there must be a pit in [2,2] or
[3,1] or both.

January 21, 2025 BMSCE 42


KB

January 21, 2025


KB

January 21, 2025 BMSCE 45


The only worlds that have a wumpus in [1,3] are; 3, 6, 9, 12, 15, 18, 21,
24, that’s a total of 8 worlds. Below I’ve highlighted the worlds for you:

January 21, 2025 BMSCE 46


KB

January 21, 2025 BMSCE 47


January 21, 2025 BMSCE 48
Logic is Formal Language
 Propositional Logic
• Arjun is Intelligent Propositions
• Arjun is Hardworking

• If Arjun is Intelligent and Arjun is


Compound
Hardworking Then Arjun Scores Proposition
high marks

January 21, 2025 BMSCE 49


Elements of Propositional Logic

• Arjun is Intelligent
• Arjun is Hardworking

 Objects and Relations or Functions

Arjun Hardworking
Intelligent

January 21, 2025 BMSCE 50


Propositional Logic: Syntax

January 21, 2025 BMSCE 51


Propositional logic: Syntax
 Complex sentences constructed from simpler
ones recursively using logical operators.
 The proposition symbols S1, S2 etc are
sentences

January 21, 2025 BMSCE 52


Propositional logic: Semantics
 Truth tables for connectives

January 21, 2025 BMSCE 53


Propositional logic: Semantics
 Implication operator

January 21, 2025 BMSCE 54


BNF (Backus–Naur Form) grammar of sentences

A BNF (Backus–Naur Form) grammar of sentences in propositional


logic, along with operator precedences, from highest to lowest

January 21, 2025 BMSCE 55


Represent the following statements using propositional logic.
 John will make supper only if Mary is working late

January 21, 2025 BMSCE 56


Represent the following statements using propositional logic.
 John will make supper only if Mary is working late

In propositional logic, the statement


"John will make supper only if Mary is working late" can be

𝐽⇒𝑀
represented as:

where: 𝐽 represents "John will make supper."


M represents "Mary is working late."

January 21, 2025 BMSCE 57


Represent the following statements using propositional logic.
"John will not make supper unless he is very hungry“

The statement "John will not make supper unless he is very


hungry" can be represented in propositional logic

¬𝐽 ⇒ 𝐻
as:

where: 𝐽 represents "John will make supper."


𝐻 represents "John is very hungry."

January 21, 2025 BMSCE 58


Represent the following statements using propositional logic.
"John will not make supper unless he is very hungry“

The statement "John will not make supper unless he is very


hungry" can be represented in propositional logic

¬𝐽 ⇒ 𝐻
as:

¬𝐻 ⇒ ¬ 𝐽
or equivalently:

where: 𝐽 represents "John will make supper."


𝐻 represents "John is very hungry."

January 21, 2025 BMSCE 59


Represent the following statements using propositional logic.
Not both John and Mary will make supper.

The statement "Not both John and Mary will make supper"
can be represented in propositional logic as:
¬(J∧M)
or equivalently:
¬J ∨¬M
where:
J represents "John will make supper."
MMM represents "Mary will make supper."

January 21, 2025 BMSCE 60


Represent the following statement using propositional logic.
If I keep my gas guzzler I contribute to global warming, but if I buy
a new car I consume a lot of natural resources.
 Let P: "I keep my gas guzzler."
 Let Q: "I contribute to global warming."
 Let R: "I buy a new car."
 Let S: "I consume a lot of natural resources."

"If I keep my gas guzzler, I contribute to global warming."


This can be represented as: P→Q
"If I buy a new car, I consume a lot of natural resources."
This can be represented as: R→S
Combine the Statements
(P→Q)∧(R→S)

January 21, 2025 BMSCE 61


Represent the following statement using propositional logic.
I’ll get a bicycle if and only if the city builds a bike path and I
don’t buy either a new or a used car.
Let B: "I’ll get a bicycle.“
Let P: "The city builds a bike path.“
Let N: "I buy a new car.“
Let U: "I buy a used car.“

B ↔ (P ∧ ¬(N ∨ U).

January 21, 2025 BMSCE 62


Represent the following statement using propositional logic.
I won’t buy both a bicycle and a used car unless I either get a raise
or inherit a lot of money.
Let B: "I buy a bicycle.“
Let U: "I buy a used car.“
Let R: "I get a raise.“
Let M: "I inherit a lot of money.“

¬(B∧U)→(R∨M)

January 21, 2025 BMSCE 63


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 64


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 65


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 66


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 67


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 68


Propositional Inference: Enumeration Method

January 21, 2025 BMSCE 69


Question
Consider a knowledge base KB that contains the following
propositional logic sentences:
Q→P
P → ¬Q
QVR
i) Construct a truth table that shows the truth value of each
sentence in KB and indicate the models in which the KB is
true.
ii) Does KB entail R?
iii) Does KB entail R → P?
iv) Does KB entail Q → R?

January 21, 2025 BMSCE 70


Solution
Construct a truth table that shows the truth value of each sentence in KB and indicate the models in
which the KB is true.
KB =(Q=>P ∧ P=> ¬Q ∧ QVR )

January 21, 2025 BMSCE 71


Solution

January 21, 2025 BMSCE 72


Solution

January 21, 2025 BMSCE 73


Solution

January 21, 2025 BMSCE 74


Inference Algorithms: Soundness and Completeness

January 21, 2025 BMSCE 75


Inference Algorithms: Soundness and Completeness Example

 There is a fishing contest. The goal is to catch fishes heavier than 1 Kg.
There are two contenders, Sunada and Compila. Each one uses their
own lake to catch fishes. Each lake have exactly same number of
fishes(100 fishes) and among those fishes, they have exactly same
number of fishes weighting more than 1 Kg (50 fishes).
 The referee starts the competition with a whistle. They both catch
numerous fishes until the end of the time. Now it comes to count fishes
which comply to the rule. The referee starts to weight all fishes caught
by Sunada first. Surprisingly, all fishes caught by Sunada weight more
than 1 Kg! But he caught only 45 fishes.
 On the other hand, Compila caught 60 fishes. It seems Compila wins
but referee didn’t decide yet. Because there may be less than 45 fishes
weighting more than 1 Kg. After counting and weighting, referee says
there are 50 fishes complying the rule which makes Compila the winner.
 Now in this analogy, all fishes caught by Sunada comply the rule, which
makes him perfectly sound! Compila, on the other hand caught all
fishes that comply the rule and that makes Compila the perfectly
complete!

January 21, 2025 BMSCE 76


Inference

January 21, 2025 BMSCE 77


Knowledge-base for Wumpus world
Atomic proposition variable for Wumpus world:
• Let Pi,j be true if there is a Pit in the room [i, j].
• Let Bi,j be true if agent perceives breeze in [i, j].
• Let Wi,j be true if there is wumpus in the square[i, j], (dead or
alive).
• Let Si,j be true if agent perceives stench in the square [i, j].
• Let Vi,j be true if that square[i, j] is visited.
• Let Gi,j be true if there is gold (and glitter) in the square [i, j].
• Let OKi,j be true if the room is safe.

January 21, 2025 BMSCE 78


Knowledge-base for Wumpus world
 Some Propositional Rules for the
wumpus world:

January 21, 2025 BMSCE 79


Knowledge-base for Wumpus world
 Some Propositional Rules for the
wumpus world:

January 21, 2025 BMSCE 80


Representation of Knowledgebase for Wumpus world:

Following is the Simple KB for wumpus world when an agent moves


from room [1, 1], to room [2,1]:

 Here in the first row, we have mentioned propositional variables for room[1,1], which is
showing that room does not have wumpus(¬ W 11), no stench (¬S11), no Pit(¬P11), no
breeze(¬B11), no gold (¬G11), visited (V11), and the room is Safe(OK11).
 In the second row, we have mentioned propositional variables for room [1,2], which is showing
that there is no wumpus, stench and breeze are unknown as an agent has not visited room
[1,2], no Pit, not visited yet, and the room is safe.
 In the third row we have mentioned propositional variable for room[2,1], which is showing that
there is no wumpus(¬ W21), no stench (¬S21), no Pit (¬P21), Perceives breeze(B21), no
glitter(¬G21), visited (V21), and room is safe (OK21).

January 21, 2025 BMSCE 81


The Wumpus World KB (only dealing with knowledge about pits)

January 21, 2025 BMSCE 82


Inference

January 21, 2025 BMSCE 83


Inference

January 21, 2025 BMSCE 84


Truth-table enumeration algorithm for deciding propositional entailment

A truth-table enumeration algorithm for deciding propositional entailment. (TT stands


for truth table.) PL-TRUE? returns true if a sentence holds within a model. The variable
model represents a partial model—an assignment to some of the symbols. The
keyword “and” is used here as a logical operation on its two arguments, returning true
or false.

January 21, 2025 BMSCE 85


Propositional logic: Revisited
 Logical constants: true, false
 Propositional symbols: P, Q, S, ... (atomic
sentences)
 Wrapping parentheses: ( … )
 Sentences are combined by connectives:
 ...and [conjunction]
 ...or [disjunction]
...implies [implication / conditional]
..is equivalent [biconditional]
 ...not [negation]
 Literal: atomic sentence or negated atomic
sentence

January 21, 2025 BMSCE 86


Examples of PL sentences
 (P  Q)  R
“If it is hot and humid, then it is raining”
QP
“If it is humid, then it is hot”

January 21, 2025 BMSCE 87


Limitations of Propositional logic:

• We cannot represent relations like


ALL, some, or none with propositional
logic. Example:
• All the Human beings are intelligent.
• Some Mangoes are sweet.
• Propositional logic has limited
expressive power.
• In propositional logic, we cannot
describe statements in terms of their
properties or logical relationships.
January 21, 2025 BMSCE 88
Propositional logic is a weak language
 Can’t directly talk about properties of
individuals or relations between individuals
(e.g., “Bill is tall”)
 Generalizations, patterns, regularities can’t
easily be represented (e.g., “all triangles have
3 sides”)
 First-Order Logic (abbreviated FOL or FOPC) is
expressive enough to concisely represent this
kind of information
FOL adds relations, variables, and quantifiers, e.g.,
“Every elephant is gray”:  x (elephant(x) → gray(x))
“There is a white alligator”:  x (alligator(X) ^ white(X))

January 21, 2025 BMSCE 89


First-order Logic
First-order logic (FOL), also known as predicate logic or first-
order predicate calculus, is a powerful framework used in
various fields such as mathematics, philosophy, linguistics, and
computer science.
In artificial intelligence (AI), FOL plays a crucial role in knowledge
representation, automated reasoning, and natural language
processing.

FOL is called “predicate logic”, since its atomic formulae consist of


applications of predicate/relation symbols to terms.

Why is it also called “first order”?


Because its variables range only over individual elements from the
interpretation domain.

January 21, 2025 BMSCE 90


First-order Logic
Propositional logic
Assumes that the world contains facts

First-order logic
Assumes that the world contains
Objects: which are things with individual identities
Students, lectures, companies, cars ...

Relations: that hold among sets of objects


red, round, prime, multistoried, ...brother of, bigger than, part of,
has color, occurred after, owns, ...

Functions: which are a subset of relations where there is


only one “value” for any given “input”
father-of, best-friend , one more than, beginning of, ...

January 21, 2025 BMSCE 91


User provides
 Constant symbols, which represent
individuals in the world
 Maruthi
 3
 Green
 Function symbols, which map individuals to
individuals
 father-of(Maruthi) = Jagdish
 color-of(Sky) = Blue
 Predicate symbols, which map individuals to
truth values
 greater(5,3)
 green(Grass)
 color(Grass, Green)

January 21, 2025 BMSCE 92


Syntax of First-Order Logic: Basic Elements

Symbols
Constants KingWadyar, 2, Bangalore, C,...
Predicates Brother, >, =, ...
Functions Sqrt, LeftLegOf , ...
Variables x, y, a, b, ...
Connectives ∧∨¬⇒⇔
Quantifiers ∀∃
Universal x
Existential x

January 21, 2025 BMSCE 93


Syntax of First-order Logic: Atomic Sentences

January 21, 2025 BMSCE 94


Syntax of First-order Logic: Atomic Sentences

January 21, 2025 BMSCE 95


Syntax of First-order Logic: Atomic Sentences

January 21, 2025 BMSCE 96


Syntax of First-order Logic: Complex Sentences

January 21, 2025 BMSCE 97


Quantifiers in First-order logic
• A quantifier is a language element which generates
quantification, and quantification specifies the quantity
of specimen in the universe of discourse.
• These are the symbols that permit to determine or
identify the range and scope of the variable in the
logical expression. There are two types of quantifier:
• Universal Quantifier (for all, everyone, everything)
• Existential quantifier (for some, at least one).

January 21, 2025 BMSCE 98


Universal Quantifier
 Universal quantifier is a symbol of logical
representation, which specifies that the
statement within its range is true for
everything or every instance of a particular
thing.
 The Universal quantifier is represented by a
symbol ∀, which resembles an inverted A.
 If x is a variable, then ∀x is read as:
• For all x
• For each x
• For every x.

January 21, 2025 BMSCE 99


Universal Quantifier

Example:
All man drink coffee.

∀x man(x) → drink (x, coffee)

It will be read as: There are all x where x


is a man who drink coffee.

January 21, 2025 BMSCE 100


Universal Quantifier

Sentence FOL Representation


All humans are mortal ∀xHuman(x)→Mortal(x)
Explanation: This means that for every
individual x in the domain, if x is a
human, then x is also mortal. We use
implication (→) because we only want
to assert that being mortal applies to
those individuals who are human.

January 21, 2025 BMSCE 101


Universal Quantifier

Sentence FOL Representation


All dogs have four legs ∀xDog(x)→FourLegs(x)
Explanation: For every x, if x is a dog,
then x has four legs. This implies that
the property of having four legs applies
only to those individuals who are dogs.

January 21, 2025 BMSCE 102


Existential Quantifier
 Existential quantifiers are the type of quantifiers, which express
that the statement within its scope is true for at least one
instance of something.
 It is denoted by the logical operator ∃, which resembles as
inverted E. When it is used with a predicate variable then it is
called as an existential quantifier.
 If x is a variable, then existential quantifier will be ∃x or ∃(x).
And it will be read as:
• There exists a 'x'
• For some 'x'
• For at least one 'x'

January 21, 2025 BMSCE 103


Existential Quantifier
Example: “There is a student who has completed the assignment.”

January 21, 2025 BMSCE 104


Existential Quantifier
Example: “There is a student who has completed the assignment.”
Step 1: Define the Predicate
Let Student(x) mean "x is a student."
Let Completed(x) mean "x has completed the assignment."

January 21, 2025 BMSCE 105


Existential Quantifier
Example: “There is a student who has completed the assignment.”

Step 1: Define the Predicate


Let Student(x) mean "x is a student."
Let Completed(x) mean "x has completed the assignment."
Step 2: Represent the Sentence with the Existential Quantifier
In first-order logic, we can express the statement "There is a student who has completed the
assignment" as:
∃x(Student(x)∧Completed(x))
Explanation
The existential quantifier ∃x means "there exists at least one x" in the domain.
The conjunction Student(x)∧Completed(x) states that x is both a student and has completed
the assignment.

January 21, 2025 BMSCE 106


Existential Quantifier

Sentence FOL Representation


There exists a human ∃x(Human(x)∧Doctor(x))
who is a doctor.
Explanation: This states that there is
at least one individual x in the domain
who is both a human and a doctor.
Conjunction (∧) is used because we
want to assert that both properties
apply simultaneously to at least one
element.

January 21, 2025 BMSCE 107


Existential Quantifier

Sentence FOL Representation


There exists a city that is ∃x(City(x)∧Polluted(x))
polluted.
Explanation: This states that at least
one element xxx in the domain is both
a city and polluted. The conjunction
ensures that both properties hold for
the same individual in the domain.

January 21, 2025 BMSCE 108


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
a. Emily is either a surgeon or a lawyer.
b. Joe is an actor, but he also holds another job.
c. All surgeons are doctors.
d. Joe does not have a lawyer (i.e., is not a customer of any lawyer).
e. Emily has a boss who is a lawyer.
f. There exists a lawyer all of whose customers are doctors.
g. Every surgeon has a lawyer.

January 21, 2025 BMSCE 109


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
a. Emily is either a surgeon or a lawyer.

Occupation(Emily, Surgeon) V Occupation(Emily, Lawyer)

January 21, 2025 BMSCE 110


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
b. Joe is an actor, but he also holds another job.

Occupation(Joe, Actor) ^ ( Occupation(Joe, Doctor) V Occupation(Joe,


Surgeon) V Occupation(Joe, Lawyer) )

January 21, 2025 BMSCE 111


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
c. All surgeons are doctors.

∀p Occupation(p, Surgeon) ⇒ Occupation(p, Doctor)

January 21, 2025 BMSCE 112


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations.
Emily, Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
d. Joe does not have a lawyer (i.e., is not a customer of any lawyer).

¬∃ p Customer(Joe, p) ∧ Occupation(p, Lawyer).

January 21, 2025 BMSCE 113


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
e. Emily has a boss who is a lawyer.

∃p Boss(p, Emily) ∧ Occupation(p, Lawyer)

January 21, 2025 BMSCE 114


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations.
Emily, Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
f. There exists a lawyer all of whose customers are doctors.

∃p1∀p2 Occupation(p1, Lawyer) ⇒ Customer ( p2, p1 ) ^ Occupation (p2,


Doctor)

January 21, 2025 BMSCE 115


Question
Consider a vocabulary with the following symbols:
Occupation(p, o): Predicate. Person p has occupation o.
Customer (p1, p2): Predicate. Person p1 is a customer of person p2.
Boss(p1, p2): Predicate. Person p1 is a boss of person p2.
Doctor , Surgeon, Lawyer , Actor : Constants denoting occupations. Emily,
Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic:
g. Every surgeon has a lawyer.

∀p1∃p2 Occupation(p1, Surgeon) ⇒Customer(p1, p2) ^ Occupation(p2,


Lawyer)

January 21, 2025 BMSCE 116


Question
Complete the following exercises about logical
sentences:

Translate into first-order logic the following


sentences:
i) Understanding leads to friendship.
Friendship(x,y): x has a friendship with y.
Understands(x,y) ⇒Friendship(x,y)

ii) Friendship is transitive.


Friendship(x,y) ^ Friendship(y,z) ⇒Friendship(x,z)

January 21, 2025 BMSCE 117


Question

Complete the following exercises about


logical sentences:
iii) Translate into good, natural English:
∀x,y,l SpeaksLanguage(x,l)^SpeaksLanguage(y,l)
⇒Understands(x,y) ^ Understands(y,x)

If two people speak the same language,


then they understand each other.

January 21, 2025 BMSCE 118


Question
Represent the following sentences in first-order logic, using a consistent vocabulary
(which you must define):
a. Some students took French in spring 2001.
b. Every student who takes French passes it.
c. Only one student took Greek in spring 2001.
d. The best score in Greek is always higher than the best score in French.

January 21, 2025 BMSCE 119


Question
Represent the following sentences in first-order logic, using a consistent vocabulary
(which you must define):
a. Some students took French in spring 2001.
b. Every student who takes French passes it.
c. Only one student took Greek in spring 2001.
d. The best score in Greek is always higher than the best score in French.

Let the basic vocabulary be as follows:


Takes(x, c, s): student x takes course c in semester s;
P asses(x, c, s): student x passes course c in semester s;
Score(x, c, s): the score obtained by student x in course c in semester s;
x>y: x is greater than y;
F and G: specific French and Greek courses

January 21, 2025 BMSCE 120


Question
Let the basic vocabulary be as follows:
Takes(x, c, s): student x takes course c in semester s;
P asses(x, c, s): student x passes course c in semester s;
Score(x, c, s): the score obtained by student x in course c in semester s;
x>y: x is greater than y;
F and G: specific French and Greek courses

a. Some students took French in spring 2001.


∃x Student(x) ∧ Takes(x, F, Spring2001)

b. Every student who takes French passes it.


∀x, s Student(x) ∧ Takes(x, F, s) ⇒ Passes(x, F, s)

c. Only one student took Greek in spring 2001.


∃x Student(x)∧Takes(x, G, Spring2001)∧ ∀y , y ≠ x ⇒ ¬Takes(y, G, Spring2001)

d. The best score in Greek is always higher than the best score in French.
∀s ∃x ∀y Score(x, G, s) > Score(y, F, s)

January 21, 2025 BMSCE 121


Represent the following sentences in first-order logic, using a
consistent vocabulary (which you must define):

Vocalbulary:
Buys(x, y, z): x buys y from z (using a binary predicate with unspecified
seller is OK but less felicitous); Sells(x, y, z): x sells y to z;
Person(x), Expensive(x), Agent(x), Insured(x), Smart(x): predicates satisfied
by members of the corresponding categories.

d. Every person who buys a policy is smart.


∀ x Person(x) ∧ (∃ y, z Policy(y) ∧ Buys(x, y, z)) ⇒ Smart(x).

f. No person buys an expensive policy.


∀ x, y, z Person(x) ∧ Policy(y) ∧ Expensive(y) ⇒ ¬Buys(x, y, z).

g. There is an agent who sells policies only to people who are not
insured.
∃x Agent(x) ∧ ∀y, z Policy(y) ∧ Sells(x, y, z) ⇒ (Person(z) ∧
¬Insured(z)).

January 21, 2025 BMSCE 122


A Common Mistake to Avoid
Note
 ⇒ is the main connective with ∀

Common mistake
Using ∧ as the main connective with ∀
Example
 Correct: ∀x (StudiesAt(x, BMSCE) ⇒ Smart(x))
“Everyone who studies at BMSCE is smart”

 Wrong: ∀x (StudiesAt(x, BMSCE) ∧ Smart(x))


“Everyone studies at BMSCE and is smart”, i.e.,
“Everyone studies at BMSCE and everyone is smart”

January 21, 2025 BMSCE 123


Another Common Mistake to Avoid
Note
∧ is the main connective with ∃

Common mistake
Using ⇒ as the main connective with ∃

Example
Correct: ∃x (StudiesAt(x,BMSCE) ∧ Smart(x))
“There is someone who studies at BMSCE and is smart”

Wrong: ∃x (StudiesAt(x,BMSCE) ⇒ Smart(x))


 “There is someone who, if he/she studies at BMSCE, is
smart”
 This is true if there is anyone not studying at BMSCE

January 21, 2025 BMSCE 124


Example

One’s mother is ∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c)


one’s female
parent

January 21, 2025 BMSCE 125


Example

One’s mother is ∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c)


one’s female
parent
Male and female ∀ x Male(x) ⇔ ¬Female(x) .
are disjoint
categories

January 21, 2025 BMSCE 126


Example

One’s mother is ∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c)


one’s female
parent
Male and female ∀ x Male(x) ⇔ ¬Female(x) .
are disjoint
categories
Parent and child ∀p,c Parent(p, c) ⇔ Child(c, p)
are inverse
relations.

January 21, 2025 BMSCE 127


Example

One’s mother is ∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c)


one’s female
parent
Male and female ∀ x Male(x) ⇔ ¬Female(x) .
are disjoint
categories
Parent and child ∀p,c Parent(p, c) ⇔ Child(c, p)
are inverse
relations.
A grandparent is ∀g, c Grandparent(g, c) ⇔ ∃ p Parent(g, p) ∧ Parent(p, c)
a parent of
one’s parent.

January 21, 2025 BMSCE 128


Example

One’s mother is ∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c)


one’s female
parent
Male and female ∀ x Male(x) ⇔ ¬Female(x) .
are disjoint
categories
Parent and child ∀p,c Parent(p, c) ⇔ Child(c, p)
are inverse
relations.
A grandparent is ∀g, c Grandparent(g, c) ⇔ ∃ p Parent(g, p) ∧ Parent(p, c)
a parent of
one’s parent.
A sibling is ∀ x, y Sibling(x, y) ⇔ x = y ∧ ∃ p Parent(p, x) ∧ Parent(p, y)
another child of
one’s parents

January 21, 2025 BMSCE 129


Connections between ∀ and ∃

∀x ¬Likes(x, Radish ) ¬∃x Likes(x,Radish)


Everyone dislikes There does not exist
parsnips someone who likes
Radish

∀x Likes(x,IceCream) ¬∃x ¬Likes(x, IceCream)


Everyone likes ice cream There is no one who
does not like ice cream

January 21, 2025 BMSCE 130


De Morgan’s rules
Because ∀ is really a conjunction over the universe of objects and ∃
is a disjunction, it should not be surprising that they obey De
Morgan’s rules. The De Morgan rules for quantified and
unquantified sentences are as follows:

January 21, 2025 BMSCE 131


Properties of Quantifiers
 Switching the order of universal
quantifiers does not change the
meaning:
 (x)(y)P(x,y) ↔ (y)(x) P(x,y)
 Similarly, you can switch the order of
existential quantifiers:
 (x)(y)P(x,y) ↔ (y)(x) P(x,y)
 Switching the order of universals and
existentials does change meaning:
 Everyone likes someone: (x)(y) likes(x,y)
 Someone is liked by everyone: (y)(x) likes(x,y)

January 21, 2025 BMSCE 132


The syntax of first-order logic

Operator precedences are specified,


from highest to lowest. The precedence
of quantifiers is such that a quantifier
holds over everything to the right of it.

January 21, 2025 BMSCE 133


Wumpus World in FOL

January 21, 2025 BMSCE 134


January 21, 2025 BMSCE 135
Thanks for Listening

January 21, 2025 BMSCE 136


Validity of a Sentence
 If a propositional sentence is true
under all possible interpretations, it is
VALID
 Tautology P v ~P is always true
 If the sentence is true irrespective of
the world then it is VALID

January 21, 2025 BMSCE 137


Terminology
 Given the truth values of all of the constituent symbols in a sentence,
that sentence can be "evaluated" to determine its truth value (True or
False). This is called an interpretation of the sentence.
 A model is an interpretation (i.e., an assignment of truth values to
symbols) of a set of sentences such that each sentence is True. A model
is just a formal mathematical structure that "stands in" for the world.
 A valid sentence (also called a tautology) is a sentence that is True
under all interpretations. Hence, no matter what the world is actually
like or what the semantics is, the sentence is True. For example "It's
raining or it's not raining."
 An inconsistent sentence (also called unsatisfiable or a contradiction) is
a sentence that is False under all interpretations. Hence the world is
never like what it describes. For example, "It's raining and it's not
raining."
 Sentence P entails sentence Q, written P |= Q, means that whenever P
is True, so is Q. In other words, all models of P are also models of Q

January 21, 2025 BMSCE 138

You might also like