0% found this document useful (0 votes)
33 views84 pages

Unit-3 4350705

Uploaded by

adityatike02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views84 pages

Unit-3 4350705

Uploaded by

adityatike02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 84

UNIT-3

Knowledge
Representation
Representations And Mappings
 In order to solve complex problems encountered in artificial intelligence,
one needs both a large amount of knowledge and some mechanism for
manipulating that knowledge to create solutions.
 Knowledge and Representation are two distinct entities.
 They play central but distinguishable roles in the intelligent system.
 Knowledge is a description of the world. It determines a system’s
competence by what it knows.
 Moreover, Representation is the way knowledge is encoded. It defines a
system’s performance in doing something.
 Different types of knowledge require different kinds of representation.
 The Knowledge Representation models/mechanisms are often based on:
Logic, Rules, Frames, Semantic Net, etc.
Types of Knowledge
Informal or Implicit Formal or
Explicit
• Exists within a human being • Exists outside a human being;

• It is embodied. • It is embedded.

• Difficult to articulate formally. • Can be articulated formally.

• Difficult to communicate or share. • Can be shared, copied, processed and


stored.
• Hard to steal or copy.
• Easy to steal or copy
• Drawn from experience, action,
subjective insight • Drawn from artifact of some type as
principle, procedure, process,
concepts.
Mapping between Facts and Representation
Desired
Real
Initial Facts Reasoning Final Facts

Forward Backward
Representa Representa
tion tion
Mapping Mapping

Internal Internal
Representation of Representation of final
Operated
Initial Facts by Facts
Program
Approaches To Knowledge Representation
 A knowledge representation system should have following properties.
1. Representational Adequacy : The ability to represent all kinds of
knowledge that are needed in that domain.
2. Inferential Adequacy : The ability to manipulate the representational
structures to derive new structures corresponding to new knowledge
inferred from old.
3. Inferential Efficiency : The ability to incorporate additional information
into the knowledge structure that can be used to focus the attention of
the inference mechanisms in the most promising direction.
4. Acquisitional Efficiency : The ability to acquire new knowledge using
automatic methods wherever possible rather than reliance on human
intervention.
Knowledge Representation Schemes
 Relational Knowledge : The simplest way to represent declarative facts is
as a set of relations of the same sort used in the database system.

Player Height Weight Bats - Throws

Aaron 6-0 180 Right - Right

Mays 5-10 170 Right - Right

Ruth 6-2 215 Left - Left


Willia
6-3 205 Left - Right
ms
Knowledge Representation Schemes
 Inheritable Knowledge : Here the knowledge elements inherit attributes
from their parents.
Adult-male

Is
a
Player

Is Is
a a

Cricket Football

Instan Instan
ce ce
Peter Ankit
Knowledge Representation Schemes
 Inferential Knowledge : This knowledge generates new information from
the given information. This new information does not require further data
gathering form source, but does require analysis of the given information
to generate new knowledge.
 Example:
 given a set of relations and values, one may infer other values or relations.
 A predicate logic (a mathematical deduction) is used to infer from a set of attributes.
 Inference through predicate logic uses a set of logical operations to relate individual
data.
 Represent knowledge as formal logic:
All dogs have tails :: ∀x: dog(x) → hastail(x)
Knowledge Representation Schemes
 Procedural Knowledge : A representation in which the control information,
to use the knowledge, is embedded in the knowledge itself.
 For example, computer programs, directions, and recipes.
 Knowledge is encoded in some procedures, small programs that know how
to do specific things, how to proceed.
Techniques of Knowledge
Representation

1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules
1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
• The structure of frame is like record which contains collection of attributes and its values to describe an entity
in the world. Frames are the AI data structure which divides knowledge into substructures by representing
stereotypes situations. It consists of a collection of slots and slot values. These slots may be of any type and
sizes. Slots have names and values which are called facets.
• A frame is also known as slot-filter knowledge representation in artificial intelligence.
Example: Frame for a book

Slots Filters

Title Artificial Intelligence

Genre Computer Science

Author Peter Norvig

Edition Third Edition

Year 1996

Page 1152
4. Production Rules
First-Order Logic (FOL)
 First-Order Logic (FOL) is a formal language used to represent
knowledge and reason about the world in artificial intelligence (AI). It
provides a powerful framework for expressing complex relationships and
making inferences.
Key Components of FOL
• Constants: Represent individuals or objects (e.g., John, Mary, 2).
• Variables: Represent arbitrary individuals or objects (e.g., x, y, z).
• Functions: Represent relationships between individuals or objects (e.g.,
fatherOf, marriedTo).
• Predicates: Represent properties or relationships (e.g., isHuman,
greaterThan).
• Quantifiers: Represent universal (∀) and existential (∃) quantification.
• Logical connectives: Represent logical operations (e.g., AND (∧), OR
(∨), NOT (¬), IMPLIES (→), IF AND ONLY IF (↔)).
Syntax of FOL
 Well-formed formulas (WFFs): Sentences that are grammatically
correct according to the rules of FOL.
Atomic formulas: Predicates applied to terms (e.g., isHuman(John)).
Complex formulas: Formed using logical connectives, quantifiers, and
atomic formulas.
Semantics of FOL
• Models: Interpretations of the symbols in a first-order language.
• Truth values: The assignment of true or false to formulas based on a
given model.
Inference in FOL
• Deduction: Drawing conclusions from given premises using logical
rules.
• Abduction: Inferring the most likely explanation for a given
observation.
• Induction: Generalizing from specific instances to a broader rule.
Applications of FOL in Knowledge Representation
 Representing complex relationships: FOL can represent a wide
range of relationships between objects, including hierarchical
relationships, part-whole relationships, and causal relationships.
 Reasoning about knowledge: FOL can be used to reason about
knowledge, including deduction, abduction, and induction.
 Problem-solving: FOL can be used to represent problems and find
solutions using logical reasoning.
 Natural language processing: FOL can be used to understand and
generate natural language.
Example
 Consider the following knowledge base:
• person(john)
• person(mary)
• fatherOf(john, mary)
• isMale(john)
• isFemale(mary)
We can use FOL to represent and reason about this knowledge.
For example, we can infer that John is the father of a female using the
following FOL formula:
∃x (fatherOf(john, x) ∧ isFemale(x))
This formula states that there exists an individual x such that John is the
father of x and x is female.
Here are some additional examples of FOL in action:

Representing Family Relationships:


 Grandparent: grandparent(x, y) :- parent(x, z), parent(z, y).
 Sibling: sibling(x, y) :- parent(z, x), parent(z, y), x ≠ y.
 Cousin: cousin(x, y) :- parent(z, x), parent(w, y), sibling(z, w), x ≠ y.
Representing Mathematical Concepts:
 Prime number: primeNumber(x) :- x > 1, ∀y (y > 1 ∧ y < x →
¬divisible(y, x)).
 Even number: evenNumber(x) :- exists(y, x = 2 * y).
 Factorial: factorial(x, y) :- x = 0 → y = 1; x > 0 → exists(z, factorial(x - 1,
z), y = x * z).
Representing Knowledge About the World:
 Location: locatedAt(object, place)
 Ownership: owns(person, object)
 Action: does(person, action)
Reasoning with FOL:
 Deduction: Given the facts person(john) and fatherOf(john, mary), we
can deduce that isMale(john).
 Abduction: Given the facts isWet(ground) and if raining then
groundIsWet, we can abduce that itIsRaining.
 Induction: Given the facts isBird(tweety), flies(tweety), and
isBird(tweety2), flies(tweety2), we can induce the rule ∀x (isBird(x) →
flies(x)).
Computable Functions and Predicates in Knowledge
Representation
 Computable functions and predicates are fundamental concepts in
knowledge representation, providing a formal way to represent
relationships and properties in a logical framework.
Computable Functions

• Definition: A computable function is a mathematical function that can


be effectively calculated or computed by a mechanical process, such as
a computer algorithm.
• Properties:
• Deterministic: For a given input, a computable function always produces
the same output.
• Effective: There exists an algorithm or procedure to compute the function's
output.
• Total: A computable function is defined for all possible inputs.
Predicates
 Definition: A predicate is a relation between objects or individuals. It can
be thought of as a property or attribute that an object may or may not
possess.
 Examples:
• isHuman(x): x is a human.
• greaterThan(x, y): x is greater than y.
• parentOf(x, y): x is the parent of y.
Relationship between Functions andPredicates
 Functions can be seen as special cases of predicates with a single
output value. For example, the function f(x) = x + 1 can be represented
as the predicate plusOne(x, y), where y is the output value.
 Predicates can be used to define functions. For example, the function
max(x, y) can be defined as:
• max(x, y) = z if greaterThan(x, y) then z = x else z = y
Using Functions and Predicates in
Knowledge Representation
 Representing objects and their properties:
• Use constants to represent objects (e.g., john, mary) and predicates to
represent their properties (e.g., isHuman(john)).
 Expressing relationships between objects:
• Use predicates to represent relationships between objects (e.g.,
parentOf(john, mary)).
 Defining functions:
• Use functions to compute values based on the properties of objects.
Example
 Consider the following knowledge base:
• person(john)
• person(mary)
• fatherOf(john, mary)
• age(john, 30)
• age(mary, 25)
 We can define a function olderThan(x, y) as follows:
• olderThan(x, y) :- age(x, X), age(y, Y), greaterThan(X, Y).
 This rule states that x is older than y if x's age is greater than y's age.
 By using functions and predicates, we can represent complex
knowledge and reason about it in a logical and systematic way.
Examples:
1. Mary loves everyone.
2. No one talks.
3. Everyone loves himself.
4. Everyone loves everyone.
5. Everyone loves everyone except himself.
6. Every student smiles.
7. Every student except George smiles.
8. Everyone walks or talks.
9. Every student walks or talks.
10. Every student who walks talks.
11. Every student who loves Mary is happy.
12. Every boy who loves Mary hates every boy who Mary loves.
13. Every boy who loves Mary hates every other boy who Mary loves.
Examples:
1. Everyone loves Mary.
2. John does not love anyone.
3. Everyone who sees Mary loves Mary.
4. Everyone loves someone. (Ambiguous)
5. Someone loves everyone. (Ambiguous)
6. Someone walks and talks.
7. Someone walks and someone talks.
8. Everyone who walks is calm.
9. No one who runs walks.
10. Everyone who Mary loves loves someone who is happy.
Forward and Backward Reasoning in AI

 Forward reasoning and backward reasoning are two common


inference techniques used in artificial intelligence (AI) to draw
conclusions from existing knowledge.
Forward Reasoning (Data-DrivenReasoning)
• Process: Starts with known facts and applies inference rules to derive
new facts.
• Approach: Moves from the known to the unknown.
• Suitable for: Problems where the goal is to predict future states or
outcomes based on initial conditions.
 Example:
• Given:
• If it rains, the ground gets wet.
• It is raining.
• Inference:
• The ground is wet.
Forward Reasoning (Data-Driven Reasoning):
 Example 1: Traffic Light Control:
• Rules:
 If the traffic light is red, then cars must stop.
 If the traffic light is green, then cars may go.
• Facts:
 The traffic light is red.
• Inference:
 Cars must stop.
 Example 2: Medical Diagnosis:
• Rules:
 If a patient has a fever and a cough, then they likely have a cold.
 If a patient has a rash and itching, then they likely have allergies.
• Facts:
 Patient has a fever and a cough.
• Inference:
 The patient likely has a cold.
Backward Reasoning (Goal-Driven Reasoning)
• Process: Starts with a goal and works backward to find the necessary
conditions to achieve it.
• Approach: Moves from the unknown to the known.
• Suitable for: Problems where the goal is to find a solution or plan to
achieve a specific outcome.
 Example:
• Goal: Prove that the grass is wet.
• Backward chaining:
• The grass is wet if it is raining.
• Is it raining?
• If the answer is yes, then the grass is wet.
Backward Reasoning (Goal-Driven Reasoning):
 Example 1: Planning a Trip:
• Goal: Reach the destination.
• Rules:
 To reach the destination, you must first get on the correct bus.
 To get on the correct bus, you must find the bus stop.
• Backward Chaining:
 To reach the destination, find the bus stop.
 To find the bus stop, use a map or ask for directions.
 Example 2: Solving a Puzzle:
• Goal: Solve the puzzle.
• Rules:
 To solve the puzzle, you must move the pieces correctly.
 To move a piece, it must be adjacent to an empty space.
• Backward Chaining:
 To solve the puzzle, find a piece that can be moved.
 If a piece can be moved, try moving it to an empty space.
Hybrid Reasoning
 In many real-world applications, a combination of forward and backward
reasoning is used to achieve more effective results.
 For example, a planning system might use forward reasoning to
simulate the effects of actions and backward reasoning to find a
sequence of actions that achieves the desired goal.
Unification
 Definition: Unification is the process of finding a substitution that
makes two terms identical.
 Unification is a process in which two terms, which may include
variables, constants, and functions, are made identical by finding a
substitution for the variables. A substitution is a mapping of variables to
terms.
 For instance, if we have a variable (X) and we substitute it with a
constant (a), the variable (X) is unified with (a).
 Substitution: A substitution is a mapping from variables to terms.
Basic Terminology -
 Term: A term can be a constant, a variable, or a compound term (a
function with arguments).
 Substitution: A mapping from variables to terms.
 Unifier: A substitution that, when applied to two terms, makes them
identical.
 Most General Unifier (MGU): The simplest unifier that can be used to
unify two terms, meaning that any other unifier can be derived from the
MGU by further substitution
Conditions for Unification:
Following are some basic conditions for unification:

 Predicate symbol must be same, atoms or expression with different


predicate symbol can never be unified.
 Number of Arguments in both expressions must be identical.
 Unification will fail if there are two similar variables present in the same
expression.
Example 1:
Example: Find the MGU for Unify{King(x), King(John)}
 Let Ψ1 = King(x), Ψ2 = King(John),
 Substitution θ = {John/x} is a unifier for these atoms and
applying this substitution, and both expressions will be identical.
 The UNIFY algorithm is used for unification, which takes two
atomic sentences and returns a unifier for those sentences (If
any exist).
 Unification is a key component of all first-order inference
algorithms.
 It returns fail if the expressions do not match with each other.
 The substitution variables are called Most General Unifier or
MGU.
Example 2:
 Example: Find the MGU for Unify{P(x, y), 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.
• P(x,y).........(i)
• 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].
Unification Algorithm -
 The unification algorithm attempts to find the Most General Unifier for two
terms. The algorithm involves recursively applying substitutions until the
terms become identical or a conflict is found that prevents unification.

Steps in the Unification Algorithm:

1. Initialization: Start with the two terms you want to unify.


2. Decompose Compound Terms: If the terms are compound (i.e.,
functions with arguments), break them down into their constituent parts.
3. Check for Conflicts: If a variable is being unified with a term that
contains that variable (occurs check), unification fails.
4. Apply Substitutions: Continuously apply the substitutions and simplify
the terms until they are identical or no further simplification is possible.
Unification Algorithm:
Algorithm: Unify(Ψ1, Ψ2)
Step. 1: If Ψ1 or Ψ2 is a variable or constant, then:
a) If Ψ1 or Ψ2 are identical, then return NIL.
b) Else if Ψ1is a variable,
a. then if Ψ1 occurs in Ψ2, then return FAILURE
b. Else return { (Ψ2/ Ψ1)}.

c) Else if Ψ2 is a variable,
a. If Ψ2 occurs in Ψ1 then return FAILURE,
b. Else return {( Ψ1/ Ψ2)}.

d) Else return FAILURE.


Step.2: If the initial Predicate symbol in Ψ1 and Ψ2 are not same, then return FAILURE.
Step. 3: IF Ψ1 and Ψ2 have a different number of arguments, then return FAILURE.
Step. 4: Set Substitution set(SUBST) to NIL.
Step. 5: For i=1 to the number of elements in Ψ1.
a) Call Unify function with the ith element of Ψ1 and ith element of Ψ2, and put the result into S.
b) If S = failure then returns Failure
c) If S ≠ NIL then do,
a. Apply S to the remainder of both L1 and L2.
b. SUBST= APPEND(S, SUBST).
Example-1
 Suppose we have the following expressions:

Expression 1: f(a, X, g(Y))


Expression 2: f(Z, b, g(h))

To unify these expressions, we need to find a substitution that makes them equal. The unification
process involves matching corresponding parts and finding a set of variable assignments that
satisfy both expressions:

Match f(a, X, g(Y)) with f(Z, b, g(h)):

X unifies with b (X/b)


Y unifies with h (Y/h)
Z unifies with a (Z/a)

The resulting substitution is: {X/b, Y/h, Z/a}. Applying this substitution to both expressions gives
us:

f(a, b, g(h)) = f(a, b, g(h))


The expressions are now unified.
Example-2
 Let's consider a more complex example involving predicates and quantifiers in first-order
logic:

Expression 1: ∀x P(x, f(Y))


Expression 2: P(Z, f(a))

To unify these expressions, we need to find a substitution that makes them equal. The
unification process involves matching the quantifiers and predicates and finding a set of
variable assignments:

Match ∀x P(x, f(Y)) with P(Z, f(a)):


x unifies with Z (x/Z)
Y unifies with a (Y/a)

The resulting substitution is: {x/Z, Y/a}. Applying this substitution to both expressions gives
us:

∀Z P(Z, f(a)) = P(Z, f(a))


The expressions are now unified.
Lifting

 Definition: Lifting is the process of generalizing inference rules to apply


to any terms, not just specific constants.
 Importance: Lifting allows for more flexible and powerful reasoning.
Example:
 The inference rule "If P(x) and Q(x), then R(x)" can be lifted to:
• For any terms P, Q, and R, if P(t) and Q(t), then R(t).
 Facts to FOL
 FOL to CNF
Relationship between Unification and Lifting:
 Unification is used to find instances of variables that make two terms
identical.
 Lifting is used to generalize inference rules to apply to any terms.
Resolution
 Resolution is a theorem proving technique that proceeds by building
refutation proofs, i.e., proofs by contradictions.
 It was invented by a Mathematician John Alan Robinson in the year
1965.
 Resolution is used, if there are various statements are given, and we
need to prove a conclusion of those statements. Unification is a key
concept in proofs by resolutions. Resolution is a single inference rule
which can efficiently operate on the conjunctive normal form or
clausal form.
 Clause: Disjunction of literals (an atomic sentence) is called a clause. It
is also known as a unit clause.
Steps for Resolution:
1.Conversion of facts into first-order logic.
2.Convert FOL statements into Conjuctive Normal Form (Clausa
3.Negate the statement which needs to prove (proof by
contradiction)
4.Draw resolution graph (unification).
Resolution by Refutation – Example
1. John likes all kinds of food.
2. Apples and vegetables are food.
3. Anything anyone eats and isn’t killed by is food.
4. Anil eats peanuts and is still alive.
5. Harry eats everything Anil eats.
6. John Likes Peanuts
Step-1: Conversion of Facts into FOL
Step 1 : Translate these sentences into formulas in FOPL
1. John likes all kinds of food.
∀x Food(x) → Likes(John, x)
2. Apples and vegetables are food.
Food(Apples) ∧ food(vegetables)
3. Anything anyone eats and isn’t killed by is food.
∀x ∀y : Eats(x, y) ∧ ¬Killed(x) → Food(y)
4. Anil eats peanuts and is still alive.
Eats(Anil, Peanuts) ∧ alive(Anil)
5. Harry eats everything Anil eats.
∀x : Eats(Anil, x) → Eats(Harry, x)
6. John Likes Peanuts
Likes(John, Peanuts)
7. ∀x : ¬Killed(x) → alive(x)
8. ∀x : alive(x) → ¬Killed(x)
Steps to Convert the FOL into clause Normal form (CNF).
1. Eliminate all implications and rewrite
2. Move negation Inwards
3. Rename variables
4. Remove Existential and Universal Quantifiers.
Eliminate all implications and rewrite
1. John likes all kinds of food.
∀x Food(x) → Likes(John, x)
∀x (¬Food(x) ∨ Likes(John, x))
2. Apples and vegetables are food.
Food(Apples) ∧ food(vegetables)
3. Anything anyone eats and isn’t killed by is food.
∀x ∀y : Eats(x, y) ∧ ¬Killed(x) → Food(y)
∀x ∀y ¬((Eats(x,y) ∧ ¬Killed(x)) ∨ Food(y))
4. Anil eats peanuts and is still alive.
Eats(Anil, Peanuts) ∧ alive(Anil)
5. Harry eats everything Anil eats.
∀x : Eats(Anil, x) → Eats(Harry, x)
∀x (¬Eats(Anil, x) ∨ Eats(Harry, x))
6. John Likes Peanuts
Likes(John, Peanuts)
7. ∀x : ¬Killed(x) → alive(x)
∀x : ¬ (¬Killed(x)) ∨ alive(x)
8. ∀x : alive(x) → ¬Killed(x)
∀x : ¬ (alive(x)) ∨ ¬Killed(x)
Move negation Inwards
1. John likes all kinds of food.
∀x Food(x) → Likes(John, x)
∀x (¬Food(x) ∨ Likes(John, x))
2. Apples and vegetables are food.
Food(Apples) ∧ food(vegetables)
3. Anything anyone eats and isn’t killed by is food.
∀x ∀y : Eats(x, y) ∧ ¬Killed(x) → Food(y)
∀x ∀y ¬((Eats(x,y) ∧ ¬Killed(x)) ∨ Food(y))
∀x ∀y ( (¬Eats(x,y) ∨ Killed(x)) ∨ Food(y) )
4. Anil eats peanuts and is still alive.
Eats(Anil, Peanuts) ∧ alive(Anil)
5. Harry eats everything Anil eats.
∀x : Eats(Anil, x) → Eats(Harry, x)
∀z (¬Eats(Anil, x) ∨ Eats(Harry, x))
6. John Likes Peanuts
Likes(John, Peanuts)
7. ∀x : ¬Killed(x) → alive(x)
1. ∀x : ¬ (¬Killed(x)) ∨ alive(x)
2. ∀x : Killed(x) ∨ alive(x)
8. ∀x : alive(x) → ¬Killed(x)
1. ∀x : ¬ (alive(x)) ∨ ¬Killed(x)
Rename Variables
1. John likes all kinds of food.
∀x Food(x) → Likes(John, x)
∀x (¬Food(x) ∨ Likes(John, x))
2. Apples and vegetables are food.
Food(Apples) ∧ food(vegetables)
3. Anything anyone eats and isn’t killed by is food.
∀x ∀y : Eats(x, y) ∧ ¬Killed(x) → Food(y)
∀x ∀y ¬((Eats(x,y) ∧ ¬Killed(x)) ∨ Food(y))
∀y ∀z ( (¬Eats(y,z) ∨ Killed(y)) ∨ Food(z) )
4. Anil eats peanuts and is still alive.
Eats(Anil, Peanuts) ∧ alive(Anil)
5. Harry eats everything Anil eats.
∀x : Eats(Anil, x) → Eats(Harry, x)
∀w (¬Eats(Anil, w) ∨ Eats(Harry, x))
6. John Likes Peanuts
Likes(John, Peanuts)
7. ∀x : ¬Killed(x) → alive(x)
1. ∀x : ¬ (¬Killed(x)) ∨ alive(x)
2. ∀g : Killed(g) ∨ alive(g)
8. ∀x : alive(x) → ¬Killed(x)
1. ∀x : ¬ (alive(x)) ∨ ¬Killed(x)
2. ∀k : ¬ alive(k) ∨ ¬Killed(k)
Remove Existential and Universal Quantifiers.
1. John likes all kinds of food.
∀x Food(x) → Likes(John, x)
∀x (¬Food(x) ∨ Likes(John, x))
¬Food(x) ∨ Likes(John, x)
2. Apples and vegetables are food.
Food(Apples) ∧ food(vegetables)
3. Anything anyone eats and isn’t killed by is food.
∀x ∀y : Eats(x, y) ∧ ¬Killed(x) → Food(y)
∀x ∀y (¬(Eats(x,y) ∧ ¬Killed(x)) ∨ Food(y))
∀y ∀z ( (¬Eats(y,x) ∨ Killed(y)) ∨ Food(z) )
¬Eats(y,x) ∨ Killed(y)) ∨ Food(z)
4. Anil eats peanuts and is still alive.
Eats(Anil, Peanuts) ∧ alive(Anil)
5. Harry eats everything Anil eats.
∀x : Eats(Anil, x) → Eats(Harry, x)
∀w (¬Eats(Anil, w) ∨ Eats(Harry, x))
¬Eats(Anil, w) ∨ Eats(Harry, x)
6. John Likes Peanuts
Likes(John, Peanuts)
7. ∀x : ¬Killed(x) → alive(x)
1. ∀x : ¬ (¬Killed(x)) ∨ alive(x)
2. ∀g : Killed(g) ∨ alive(g)
3. Killed(g) ∨ alive(g)
8. ∀x : alive(x) → ¬Killed(x)
1. ∀x : ¬ (alive(x)) ∨ ¬Killed(x)
2. ∀k : ¬ alive(k) ∨ ¬Killed(k)
3. ¬ alive(k) ∨ ¬Killed(k)
Resolution Tree
Example: “Does the Ramesh pass the exam?” 📚😂
Knowledge Base:
 If a student studies, then he passes.
• Studies(x) → Pass(x)
 If a student plays PUBG all night, then he doesn’t study.
• PUBG(x) → ¬Studies(x)
 Ramesh plays PUBG all night.
• PUBG(Ramesh)

 Goal to prove: Pass(Ramesh)


 For proof-by-contradiction add ¬Pass(Ramesh) is not true
Logic Programming in AI
 Logic programming is a paradigm of computer programming that
uses logic to represent knowledge and reason about problems. It is a
declarative programming language, meaning that the programmer
specifies what the problem is, rather than how to solve it.
Key Features of Logic Programming

 Declarative style: Focuses on describing the problem rather than


providing explicit instructions.
 Horn clauses: Uses Horn clauses, which are a restricted form of first-
order logic formulas.
 Unification: Uses unification to match terms and find solutions.
 Backtracking: Uses backtracking to explore different solution paths.
Basic Syntax

 Facts: Simple declarative statements.


 Rules: Implication statements.
 Queries: Questions to be answered by the logic programming system.
Example:
 Facts:
• person(john).
• person(mary).
• fatherOf(john, mary).
 Rule:
• male(X) :- fatherOf(Y, X), isMale(Y).
 Query:
• ?- male(mary).
What is Logic Programming?
 • A programming paradigm based on symbolic logic.
 • Uses logical statements to represent knowledge.
 • Focuses on expressing what to solve rather than how to solve it.

 Why Important in AI?


 • AI systems need to reason with incomplete information.
 • Logic programming provides tools to model relationships and infer
conclusions.
Formal Structure of Logic Programming
 1. Facts
 • Represent known truths about the domain.
 • Example: parent(john, mary).

 2. Rules
 • Define relationships between facts.
 • Example: ancestor(X, Y) :- parent(X, Y).

 3. Queries
 • Ask questions to the logic system.
 • Example: ?- ancestor(john, susan).
Example: Facts and Rules
 Facts:
 parent(john, mary).
 parent(mary, susan).
 parent(mary, tom).

 Rules:
 ancestor(X, Y) :- parent(X, Y).
 ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

 Queries:
 ?- ancestor(john, susan).
 ?- ancestor(mary, tom).
Reasoning in Logic Programming
 Forward Reasoning (Data-driven):
 • Starts with known facts.
 • Applies rules to infer new facts.

 Example:
 Start with parent(john, mary) and parent(mary, susan) → infer
ancestor(john, susan).

 Backward Reasoning (Goal-driven):


 • Starts from a goal.
 • Works backward to see if it can be proven using available facts and
rules.
Unification and Pattern Matching
 • Unification is a process of matching variables with constants or other
variables.
 • Used to apply rules during reasoning.

 Example:
 ancestor(X, susan) → matches with ancestor(john, susan) by substituting
X = john.

 • Unification helps to generalize reasoning.


Search and Backtracking
 Logic programming explores possible solutions using systematic
search.
 If a path fails, it "backtracks" and tries alternative solutions.

 Example:
 Check if ancestor(john, tom) → tries multiple paths through parent
facts.
 This process is efficient for problems like puzzles and planning.
Comparison with Procedural Programming
 | Feature | Procedural Programming | Logic Programming |
 | Focus | How to solve | What to solve
 | Execution flow | Sequence of steps | Rules and inferences |
 | Data representation | Variables, loops | Facts, rules |
 | Flexibility | Fixed logic | Dynamically reasoned logic |
Applications in AI
1. Expert Systems
• Simulate human decision-making (medical diagnosis, finance).

2. Natural Language Processing


• Understand and interpret structured text (grammar parsing).

3. Automated Theorem Proving


• Prove mathematical and logical theorems.

4. Planning and Scheduling


• Generate action sequences for robots or logistics.

5. Robotics
• Make decisions based on environmental data.

6. Knowledge Representation
Advantages of Logic Programming
 ✔ Intuitive and expressive – closer to human reasoning
 ✔ Declarative – you state facts and rules, not steps
 ✔ Powerful inference engine – can deduce new information
 ✔ Easily modifiable and extendable
 ✔ Well-suited for AI applications where knowledge is incomplete
Limitations and Challenges
 ✘ Computational overhead – may require more time/resources
 ✘ Difficulty handling uncertain or probabilistic information
 ✘ Not always scalable for large datasets
 ✘ Debugging can be challenging due to indirect execution flow
Logic Programming Languages
Prolog:
• First and most widely used logic language.
• Designed for AI applications.
• Features pattern matching, recursion, unification, and backtracking.

Datalog:
• A simplified logic language used in databases
• Focuses on deductive queries

Others:
• Answer Set Programming (ASP)
• Mercury (strong typing and determinism)
Example of Real-World Systems
• MYCIN – medical diagnosis system
• XCON – configuration system for computers
• Chatbots using grammar-based rules
• Automated legal reasoning tools
Advanced Topics
• Integration with Machine Learning
• Probabilistic Logic Programming
• Knowledge graphs and semantic reasoning
• Hybrid systems combining rules and neural networks
Future of Logic Programming in AI
 ✅ Explainable AI – Logic helps machines justify decisions
 ✅ Human-machine collaboration – Transparent reasoning
 ✅ AI in healthcare, education, and robotics
 ✅ Reasoning in autonomous systems
Summary
 ✔ Logic programming allows AI to reason like humans
 ✔ Facts, rules, and queries form the backbone
 ✔ Unification and backtracking enhance flexibility
 ✔ Widely applied in expert systems and planning
 ✔ Still evolving with probabilistic and hybrid approaches

You might also like