AIML-Unit 2 Notes-Assignment 2
AIML-Unit 2 Notes-Assignment 2
UNIT- II
Knowledge–Representation and Reasoning: Logical Agents: Knowledge based agents, the Wumpus
world, logic. Patterns in Propositional Logic, Inference in First-Order Logic-Propositional vs first
order inference, unification and lifting.
================================================================================
Introduction
Knowledge Representation and Reasoning (KRR) refers to the field in artificial intelligence (AI) that
focuses on how to represent knowledge about the world in a way that a machine can understand
and use for reasoning tasks. The aim is to allow computers to perform reasoning processes such as
deduction, decision-making, and problem-solving based on the knowledge represented.
Key Concepts:
1. Knowledge Representation (KR): This involves creating structures that capture the knowledge
about objects, relationships, events, and processes. Common KR frameworks include:
o Logic-based representations: Use formal languages (like propositional logic, predicate
logic) to represent knowledge and derive conclusions through formal deduction.
o Frames and semantic networks: Hierarchical structures that represent objects, their
attributes, and relationships.
o Ontologies: Formal representations of a set of concepts within a domain and the
relationships between them.
2. Reasoning: Reasoning involves deriving new knowledge from existing knowledge. Types of
reasoning include:
o Deductive Reasoning: Drawing conclusions from general rules or facts, ensuring that
conclusions are logically valid.
o Inductive Reasoning: Drawing general conclusions from specific observations, often
probabilistic or uncertain.
o Abductive Reasoning: Inferring the best possible explanation for a set of observations.
o Non-monotonic Reasoning: Reasoning where new information can change previous
conclusions (e.g., updates in belief systems).
3. Challenges:
o Expressiveness: Balancing how richly knowledge is represented with the computational
efficiency of reasoning.
o Uncertainty and Incomplete Information: Many real-world scenarios involve
uncertainty, and reasoning must account for incomplete or ambiguous knowledge.
o Scalability: Representing and reasoning over large volumes of knowledge.
4. Applications:
o Expert Systems: Use KRR to model human expertise for decision-making.
o Natural Language Processing: Understanding and generating human language by
interpreting the knowledge embedded in text.
o Robotics: Representing the knowledge of the world and using reasoning to navigate,
plan, and make decisions.
KRR is essential for enabling machines to understand the world, make informed decisions, and solve
complex problems, playing a crucial role in AI and intelligent systems and the following are the kind
of knowledge which needs to be represented in AI systems:
o Object: All the facts about objects in our world domain. E.g., Guitars contains strings,
trumpets are brass instruments.
o Events: Events are the actions which occur in our world.
o Performance: It describe behaviour which involves knowledge about how to do things.
o Meta-knowledge: It is knowledge about what we know.
o Facts: Facts are the truths about the real world and what we represent.
o Knowledge-Base: The central component of the knowledge-based agents is the
knowledge base. It is represented as KB. The Knowledgebase is a group of the Sentences
(Here, sentences are used as a technical term and not identical with the English
language).
Logical Agents
Logical Agents are artificial intelligence systems that use formal logic to represent knowledge and
make decisions. These agents apply logical reasoning to derive conclusions, make inferences, and act
based on the knowledge they have about the world.
Key Concepts:
1. Knowledge Representation: Logical agents represent knowledge using formal logical languages,
such as propositional logic or first-order logic. This allows the agent to clearly express facts,
rules, and relationships about the world.
2. Reasoning: Logical agents perform reasoning using logical rules and inference techniques to
deduce new facts or make decisions. Common reasoning methods include:
o Deductive reasoning: Drawing conclusions from known facts and logical rules.
o Inference: Using rules to derive new knowledge from existing knowledge.
3. Actions: Based on the reasoning process, logical agents can make decisions or take actions that
bring about desired outcomes, such as problem-solving, planning, or reacting to changes in their
environment.
4. Examples of Logical Agents:
o Propositional Logic Agents: Use simple true/false statements to represent knowledge
and derive conclusions.
o First-Order Logic Agents: Use more expressive logical systems that allow for quantifiers,
such as "for all" and "there exists," to represent more complex relationships.
Logical Agents are intelligent systems that use formal logic to reason about their environment and
make decisions or take actions based on that reasoning.
There are also some components which can help the agent to navigate the cave.
These components are given as follows:
a) The rooms adjacent to the Wumpus room are smelly, so that it would have some
stench.
b) The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he
will perceive the breeze.
c) There will be glitter in the room if and only if the room has gold.
d) The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus will
emit a horrible scream which can be heard anywhere in the cave.
PEAS description of Wumpus world
To explain the Wumpus world we have given PEAS description as below:
Performance measure:
• +1000 reward points if the agent comes out of the cave with the gold.
• -1000 points penalty for being eaten by the Wumpus or falling into the pit.
• -1 for each action, and -10 for using an arrow.
• The game ends if either agent dies or came out of the cave.
Environment:
• A 4*4 grid of rooms.
• The agent initially in room square [1, 1], facing toward the right.
• Location of Wumpus and gold are chosen randomly except the first square [1,1].
• Each square of the cave can be a pit with probability 0.2 except the first square.
Actuators:
• Left turn,
• Right turn
• Move forward
• Grab
• Release
• Shoot
Sensors:
• The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not
diagonally).
• The agent will perceive breeze if he is in the room directly adjacent to the Pit.
• The agent will perceive the glitter in the room where the gold is present.
• The agent will perceive the bump if he walks into a wall.
• When the Wumpus is shot, it emits a horrible scream which can be perceived
anywhere in the cave.
• These percepts can be represented as five element list, in which we will have
different indicators for each sensor.
• Example if agent perceives stench, breeze, but no glitter, no bump, and no scream
then it can be represented as: [Stench, Breeze, None, None, None].
Atomic Proposition:
Atomic propositions are the simple propositions.
It consists of a single proposition symbol.
These are the sentences which must be either true or false.
Example:
a) 2+2 is 4, it is an atomic proposition as it is a true fact.
b) "The Sun is cold" is also a proposition as it is a false fact.
Compound proposition:
Compound propositions are constructed by combining simpler or atomic propositions, using
parenthesis and logical connectives.
Example:
a) "It is raining today, and street is wet."
b) "Ankit is a doctor, and his clinic is in Mumbai."
Logical Connectives:
Logical connectives are used to connect two simpler propositions or representing a sentence
logically.
We can create compound propositions with the help of logical connectives.
There are mainly five connectives as given in the following table:
Truth tables:
A truth table is a mathematical table used in logic—specifically in connection with Boolean
algebra, Boolean functions, and propositional calculus—which sets out the functional values of
logical expressions on each of their functional arguments, that is, for each combination of values
taken by their logical variables.
In particular, truth tables can be used to show whether a propositional expression is true for all
legitimate input values, that is, logically valid.
A truth table has one column for each input variable (for example, A and B), and one final
column showing all of the possible results of the logical operation that the table represents (for
example, A XOR B).
Each row of the truth table contains one possible configuration of the input variables (for
instance, A=true, B=false), and the result of the operation for those values.
A truth table is a structured representation that presents all possible combinations of truth
values for the input variables of a Boolean function and their corresponding output values.
First-order logic (FOL)
First-order logic (FOL) is a formal system used in mathematics, philosophy, linguistics, and computer
science. It is a system of logic that allows you to reason about objects, their properties, and
relationships between them.
First-order logic is another way of knowledge representation in artificial intelligence. It is an
extension to propositional logic.
First-order logic is also known as Predicate logic or First-order predicate logic. First-order logic is
a powerful language that develops information about the objects in a more easy way and can
also express the relationship between those objects.
First-order logic (like natural language) does not only assume that the world contains facts like
propositional logic but also assumes the following things in the world: o Objects: A, B, people,
numbers, colors, wars, theories, squares, pits, wumpus, ...... o Relations: It can be unary relation
such as: red, round, is adjacent, or n-any relation such as: the sister of, brother of, has color,
comes between o Function: Father of, best friend, third inning of, end of, ......
FOL is powerful for expressing and reasoning about a wide variety of concepts, and its formal
structure helps in proving statements or deriving conclusions systematically.
Basic Elements of First-order logic: Following are the basic elements of FOL syntax
Atomic sentences:
Atomic sentences are the most basic sentences of first-order logic. These sentences are
formed from a predicate symbol followed by a parenthesis with a sequence of terms.
We can represent atomic sentences as Predicate (term1, term2, ......, term n).
Example:
Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
Complex Sentences:
Complex sentences are made by combining atomic sentences using connectives. First-order
logic statements can be divided into two parts:
Subject: Subject is the main part of the statement.
Predicate: A predicate can be defined as a relation, which binds two atoms together in a
statement.
Consider the statement: "x is an integer.", it consists of two parts, the first part x is the
subject of the statement and second part "is an integer," is known as a predicate.
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:
a. Universal Quantifier, (for all, everyone, everything)
b. Existential quantifier, (for some, at least one).
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.
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.
Points to remember:
The main connective for universal quantifier ∀ is implication →.
The main connective for existential quantifier ∃ is and ∧.
FOL inference rules for quantifier:
As propositional logic, there are inference rules in first-order logic.
Following are some basic inference rules in FOL:
o Universal Generalization
o Universal Instantiation
o Existential Instantiation
o Existential introduction
1. Universal Generalization:
Universal generalization is a valid inference rule which states that if P(c) is true for any
element c in the universe of discourse, then we can have a conclusion as ∀ x P(x).
This rule can be used if we want to show that every element has a similar property.
Example:
Let's represent, P(c): "A byte contains 8 bits",
so for ∀ x P(x)
"All bytes contain 8 bits.", it will also be true.
2. Universal Instantiation:
Universal instantiation is also called as universal elimination or UI is a valid inference rule.
It can be applied multiple times to add new sentences.
The new KB is logically equivalent to the previous KB.
Example:
IF "Every person like ice-cream“ ∀x P(x)
so we can infer that "John likes ice-cream" => P(c).
3. Existential Instantiation:
Existential instantiation is also called as Existential Elimination, which is a valid inference
rule in first-order logic.
It can be applied only once to replace the existential sentence.
Example:
∃x Crown(x) ∧ OnHead(x, John)
4. Existential introduction
An existential introduction is also known as an existential generalization, which is a valid
inference rule in first-order logic.
Example:
Let's say that, "Priyanka got good marks in English."
"Therefore, someone got good marks in English."
Substitution:
Substitution is a basic procedure that is applied to terms and formulations.
It can be found in all first-order logic inference systems.
When there are quantifiers in FOL, the substitution becomes more complicated.
When we write F[a/x], we are referring to the substitution of a constant "a" for the variable
"x."
[ Note: first-order logic can convey facts about some or all of the universe's objects.]
Equality:
In First-Order Logic, atomic sentences are formed not only via the use of predicate and
words, but also through the application of equality.
We can do this by using equality symbols, which indicate that the two terms relate to the
same thing.
Example: Brother (John) = Smith.
In the above example, the object referred by the Brother (John) is close to the object
referred by Smith.
The equality symbol can be used with negation to portray that two terms are not the same
objects.
Example: ¬(x=y) which is equivalent to x ≠y
1. Unification in FOL
Unification is the process of finding a substitution (a mapping) of variables that makes two
logical expressions (or terms) identical. It’s a key operation in FOL, particularly in automated
reasoning and logic programming.
Goal: The goal of unification is to find a substitution that, when applied to both terms,
results in identical expressions.
How it works:
o You compare two terms (which can be predicates, functions, or individual constants)
and attempt to make them identical by substituting variables.
o If you can find such a substitution, the terms are unified; otherwise, they are
incompatible.
o Example:
Term 1: P(x,y)
Term 2: P(a,b)
A unification would occur if you substitute x=a and y=b, making both terms identical. So, the
substitution {x↦a,y↦b} unifies the two terms.
Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it can
be expressed as UNIFY(Ψ1, Ψ2).
E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
In this example, we need to make both above statements identical to each other.
For this, we will perform the substitution.
o P(x, y)......... (i)
o P(a, f(z))......... (ii)
Substitute x with a, and y with f(z) in the first expression, and it will be represented as a/x
and f(z)/y.
With both the substitutions, the first expression will be identical to the second expression
and the substitution set will be: [a/x, f(z)/y].
Applications: Unification is used in:
o Resolution (in automated theorem proving)
o Logic programming (e.g., in Prolog)
o Automated reasoning (where you need to match terms to infer new information)
2. Lifting in FOL
Lifting, in the context of FOL, typically refers to the process of generalizing or extending a
function or operation from the ground level (such as a specific term or constant) to more
complex expressions (involving variables or predicates).
Goal: The aim of lifting is to extend operations or properties defined over simple terms to a
broader scope, often involving quantified expressions.
How it works:
Lifting usually involves generalizing an operation or rule from specific elements (like
constants) to variable-bound elements or quantified terms.
It can involve extending an interpretation from the domain of individual constants to a
broader domain of variables, or from ground terms to terms that include quantifiers.
Example:
o If you have a function f(x)f(x), lifting might refer to generalizing it so that it can apply to
all xx, i.e., ∀x f(x)\forall x \, f(x).
Another example could be extending a rule, say, a property of constants like "every constant
is even," to a more general statement that holds for variables like "for all xx, xx is even."
Example 1:
Universal Statement: ∀x (Human(x)→Mortal(x))
This means: "For all x, if x is human, then x is mortal.“
Specific Instance: Human(Socrates)
This means: "Socrates is a human.“
Apply GMP: By Generalized Modus Ponens, since Human(Socrates) is true and
∀x (Human(x)→Mortal(x)) is also true, we can infer:
Conclusion: Mortal(Socrates)
This means: "Socrates is mortal.“
GMP rule is a powerful extension of Modus Ponens that allows inference from universal
statements by instantiating the variable with a specific object.
This rule is essential for reasoning in First-Order Logic where quantified statements are often
used.
Example 2:
Universal Statement: ∀x (Bird(x)→CanFly(x))
(All birds can fly.)
Specific Instance: Bird(Tweety)
(Tweety is a bird.)
Apply GMP: Since Tweety is a bird and the universal statement says all birds can fly, we can
apply GMP:
• Conclusion: CanFly(Tweety)
(Tweety can fly.)
Applications of Generalized Modus Ponens:
Medical Diagnosis: In medical reasoning systems, rules such as "If a patient has fever, they
might have an infection" can be generalized. If a specific patient (say, "John") has a fever, GMP
allows the system to infer that John might have an infection.
Expert Systems: Expert systems in various domains (like law, finance, or engineering) rely on
universal rules such as "All engineers understand physics" or "All lawyers are trained in law." If
the system knows a specific person is an engineer or a lawyer, it can apply GMP to infer
additional knowledge about their expertise.
Prolog: In logic programming languages like Prolog, facts and rules are often written as universal
statements. The inference engine applies GMP to derive conclusions. Example is shown below:
Basic Terminology:
Terms: Expressions that can include constants, variables, and functions.
Substitution: A replacement of variables with terms.
Unifier: A substitution that makes two terms identical.
Most General Unifier (MGU): The simplest unifier (in terms of variables) that can unify two
terms.
Example:
Let's consider an example to illustrate unification.
Problem:
We want to unify the two terms:
Term 1: f(X, g(Y))
Term 2: f(a, g(b))
Step-by-step process:
1. Compare the outermost structure:
Both terms are of the form f(A, B), where A and B are the arguments. Since the functor f is the
same in both terms, we proceed to unify the arguments.
2. Unify the first argument:
We need to unify X with a.
This gives the substitution {X → a}.
3. Unify the second argument:
We need to unify g(Y) with g(b).
Both terms have the same functor g, so we now unify their arguments. We need to unify Y with
b, giving the substitution {Y → b}.
4. Combine the substitutions:
The combined substitution from the two steps is:
o {X → a, Y → b}
Thus, the unifier for f(X, g(Y)) and f(a, g(b)) is {X → a, Y → b}.
The unification algorithm succeeds with the substitution {X → a, Y → b}, meaning the two terms are
unified under this substitution. The process would fail if, for example, the terms were f(X) and f(X, Y),
since no substitution could make both terms identical.
-------------------------------------------------------------------------------------------------------------------------------------
2) Mention the categories of hill climbing search. What are the reasons that hill climbing often
get struck?
Hill climbing is a simple search algorithm used in artificial intelligence (AI) to find the best solution by
iteratively moving toward a peak (optimum) in the problem space. It can be classified into different
categories based on how it approaches the search space. Additionally, it has certain limitations that
can lead to it getting stuck during the search process and the hill climbing search is shown in the
following figure:
Categories of Hill Climbing Search:
1. Simple Hill Climbing:
o In this version, the algorithm moves to the first neighbouring state that improves the
current state. It evaluates the neighbouring nodes one by one and selects the first one
that is better.
o Characteristics: Simple, greedy approach.
o Example: If you're trying to find the highest point in a terrain, you check the immediate
neighbours and climb to the highest one that you find.
2. Steepest-Ascent Hill Climbing:
o Here, the algorithm evaluates all the neighbours of the current state and selects the one
with the highest value (the steepest ascent).
o Characteristics: More thorough than simple hill climbing, but can still get stuck in local
optima.
o Example: If you're climbing a mountain and you look at all the nearby hills, you choose
the one with the greatest height difference from your current position.
3. Stochastic Hill Climbing:
o Instead of evaluating all neighbours or just the first improving neighbour, stochastic hill
climbing picks a random neighbour and moves to it if it improves the current state. If no
better neighbours are found, it may try others.
o Characteristics: More flexible than steepest ascent but still prone to getting stuck.
o Example: If you're randomly exploring different routes on a mountain and taking the
first route you find that is better than your current position.
4. First-Choice Hill Climbing:
o In this variation, the algorithm randomly picks a neighbour and if it’s better, it moves to
it. If not, it picks another random neighbour, continuing the process until a better
solution is found.
o Characteristics: Randomized version of the search, which can potentially avoid some
pitfalls of other hill climbing methods.
Hill climbing is a simple and fast approach to optimization, it is prone to getting stuck at local
maxima, plateaus, and ridges. More sophisticated algorithms or strategies are often required for
finding a global optimum.
-------------------------------------------------------------------------------------------------------------------------------------
3. What are the best first search strategy, depth first strategy and give comparison.
The Best-First Search (BFS) and Depth-First Search (DFS) are two common strategies used in search
algorithms for exploring state spaces. Both strategies have different approaches and trade-offs. The
BFS and DFS strategies are explained and compared.
Comparison
Criteria Best-First Search (BFS) Depth-First Search (DFS)
Exploration Expands the most promising node based Explores deeply along one path before
Strategy on a heuristic (h(n)) backtracking
Priority Queue (or Min-Heap, to prioritize
Data Structure Stack (can be implemented via recursion)
based on the heuristic)
Can be complete, depending on the Can be incomplete if the search space is
Completeness
heuristic and search space infinite or has loops
Can be optimal if the heuristic is
Not guaranteed to find the optimal
Optimality consistent and admissible (e.g., in A*
solution
Search)
Can have high memory usage since all Typically uses less memory (only the
Memory Usage
nodes are stored in the priority queue current path and visited nodes)
Depends on the quality of the heuristic;
Time O(b^d) where b is the branching factor
generally, higher time complexity
Complexity and d is the depth of the solution
compared to DFS
Space O(b^d) (like BFS) because all nodes must O(b * d) (since only the current path needs
Complexity be stored in the priority queue to be stored)
Can handle loops by using closed lists or May get stuck in infinite loops without
Handling Loops
visited nodes cycle detection
When memory is limited, or a solution is
When an evaluation function is available,
Best Use Case needed quickly without considering
and finding an optimal solution is a priority
optimality
Risk of Getting Can get stuck in local minima if the Can get stuck in infinite loops without a
Stuck heuristic is poorly designed mechanism to check for cycles
Key Differences and Use Cases:
Best-First Search is ideal when you have a good heuristic function, as it guides the search
towards the goal more efficiently. However, it can use a lot of memory and might not always
be complete or optimal unless combined with specific constraints (e.g., A*).
Depth-First Search is memory-efficient and works well for problems with deep solutions or
when a quick solution is needed, but it may miss the optimal path and is not guaranteed to
find a solution if there are infinite paths or loops.
-------------------------------------------------------------------------------------------------------------------------------------
In resolution-based inference, Conjunctive Normal Form (CNF) and Disjunctive Normal Form (DNF)
play important roles in structuring logical expressions for automated reasoning, particularly in logic
programming, automated theorem proving, and artificial intelligence. The explanation of each and
their relevance to the resolution process:
Rational Agents in AI
A rational agent is an entity in artificial intelligence (AI) that perceives its environment and takes
actions to maximize its chances of achieving a specific goal, given its available knowledge and
capabilities. The core idea behind rational agents is that they are designed to act in the most
beneficial or optimal way based on their current state of knowledge, reasoning, and decision-making
processes.
The self-driving car makes rational decisions based on the information it gathers from its sensors, its
goal of reaching a destination efficiently and safely, and its performance measure.
A rational agent is an AI entity that perceives its environment, acts based on that perception to
achieve specific goals, and chooses actions that maximize its performance based on available
information and capabilities. Rational agents form the foundation of many AI systems, as they
enable autonomous decision-making in a wide range of applications.
ASSIGNMENT 2
(Submit with in a week)
1) Write about logical agents and its representation.
2) Explain the following: (i) Knowledge based agents (ii)Logical Agents
3) Discuss about patterns and pattern representation Propositional Logic.
4) Discuss about Inference in Propositional Logic.
5) Write about Inference in First-Order Logic.
6) Compare inference in propositional logic with inference in first order logic.
7) Explain the predicate logic representation with suitable example.
8) What are the merits and demerits of propositional logic in Artificial Intelligence?
9) Explain the predicate logic representation and inference in predicate logic with a suitable
example.
10) What are the standard quantifiers used in first order logic? Explain them with examples.
11) Explain unification algorithm with suitable example.
12) Mention the categories of hill climbing search. What are the reasons that hill climbing often get
struck?
13) Compare best first search strategy with depth first strategy.
14) Describe the role of CNF/DNF in resolution .
15) What do you mean by rational agents? Explain.