Explain Knowledge
Representation(prolog) in AI
Mam Iram
Knowledge Representation in Prolog
for AI
Knowledge representation is an important part of
artificial intelligence (AI). It means organizing
information in a way that machines can understand
and use. Prolog, which stands for Programming in
Logic, is a popular language for this because it is based
on logic and is easy to describe what needs to be done.
• Here’s an explanation of how knowledge
representation works in Prolog and its significance
in AI:
1. What is Prolog?
 Prolog is a logic programming language based on
rules and facts.
 Unlike procedural languages (e.g., C++ or Python),
Prolog programs define what needs to be solved
rather than how to solve it.
 It is excellent for problems involving relationships,
 pattern matching, and logical reasoning.
 Example: she has doll set
 Tow boys have brothers if both are male and they
have same parents.
she doll
has
has(she, doll_set).
This means "she has a doll set."
2. Components of Knowledge Representation in Prolog
 Prolog uses three primary components for representing
knowledge:
 a. Facts
 Represent statements about the world that are always true.
 Explicit relationship
 For example:
 Amna is girl
 Hair Is black
 Syntax: predicate(arguments).
 Amna has account (1234567) has written in prolog
Account(amna,1234567).
 Amna is a teacher of all subject.
 Teacher (amna, all subject).
Symbol:
:- if
, and/ conjuction
; Or /disjunction
Code Example:
prolog
parent(john, mary).
parent(mary, alice).
Meaning: John is Mary’s parent, and Mary is Alice’s
parent.
jhon
mary
alice
b. Rules
Represent conditional statements or relationships.
Syntax: Head :- Body.
Example:
prolog
X: ahmed
Y: Ali
Z: zain
X: ahmed Z: zain Y: Ali
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
Meaning: X is a grandparent of Y if X is a parent of Z and Z is a parent of Y.
Example:
 Mega is a daughter of sham if sham is a father of mega.
 X is father of Y if X is a parent of Y and X is male.
prolog
father(X,Y):- parent(X,Y),male(X).
c. Queries
Allow the system to infer information from facts and rules.
Syntax: ?- query.
Example:
prolog
?- grandparent(john, alice).
The system will return true if the query is satisfied based on facts and rules, or false otherwise.
Example:
Mega is jhon?
 Is pizza a food?
?-food(pizza)
 Which food is meal and lunch
?-meal(X);lunch(X).
X:- Y;Z
X:- Y
X:- Z
3. Advantages of Prolog for Knowledge Representation
•Declarative Nature: You just explain what to do, not how to do
it.
•Logical Reasoning: Prolog finds answers by matching queries
with rules and facts.
•Expressiveness: Easily handles complex relationships and
structures.
•Compact Syntax: Knowledge is written in a short and clear
way.
4. Applications in AI
•Expert Systems: Use rules and facts to solve
problems, like medical diagnosis systems.
•Natural Language Understanding: Helps in
understanding and processing human language.
•Problem Solving: Handles planning and solving
constraint-based problems.
•Semantic Web: Organizes and queries
knowledge so machines can understand it.
5. Example: Family Relationship Knowledge Base
 Here’s a simple Prolog program for representing family relationships:
 prolog
 % Facts parent(john, mary).
 parent(mary, alice).
 parent(mary, tom).
 parent(alice, sarah).
 % Rules
 grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
 sibling(X, Y) :- parent(Z, X), parent(Z, Y), X = Y.
 % Queries
 ?- grandparent(john, sarah). % true
 ?- sibling(alice, tom). % true
 ?- parent(john, tom). % false
6. Challenges of Knowledge Representation in Prolog
 Scalability: Handling large-scale knowledge
bases can be challenging.
 Uncertainty: Prolog doesn’t handle probabilistic
reasoning directly.
 Ambiguity: Representing vague or ambiguous
knowledge requires extensions or workarounds.
Conclusion
Prolog provides a robust framework for
representing and reasoning about knowledge in
AI. Its logical structure allows developers to
focus on the semantics of the problem rather
than the implementation, making it a powerful
tool for building intelligent systems.
Any Question?
Thank You

Explain Knowledge Representation(prolog) in AI.pptx

  • 1.
  • 2.
    Knowledge Representation inProlog for AI Knowledge representation is an important part of artificial intelligence (AI). It means organizing information in a way that machines can understand and use. Prolog, which stands for Programming in Logic, is a popular language for this because it is based on logic and is easy to describe what needs to be done. • Here’s an explanation of how knowledge representation works in Prolog and its significance in AI:
  • 3.
    1. What isProlog?  Prolog is a logic programming language based on rules and facts.  Unlike procedural languages (e.g., C++ or Python), Prolog programs define what needs to be solved rather than how to solve it.  It is excellent for problems involving relationships,  pattern matching, and logical reasoning.  Example: she has doll set  Tow boys have brothers if both are male and they have same parents. she doll has has(she, doll_set). This means "she has a doll set."
  • 4.
    2. Components ofKnowledge Representation in Prolog  Prolog uses three primary components for representing knowledge:  a. Facts  Represent statements about the world that are always true.  Explicit relationship  For example:  Amna is girl  Hair Is black  Syntax: predicate(arguments).  Amna has account (1234567) has written in prolog Account(amna,1234567).  Amna is a teacher of all subject.  Teacher (amna, all subject). Symbol: :- if , and/ conjuction ; Or /disjunction
  • 5.
    Code Example: prolog parent(john, mary). parent(mary,alice). Meaning: John is Mary’s parent, and Mary is Alice’s parent. jhon mary alice
  • 6.
    b. Rules Represent conditionalstatements or relationships. Syntax: Head :- Body. Example: prolog X: ahmed Y: Ali Z: zain X: ahmed Z: zain Y: Ali grandparent(X, Y) :- parent(X, Z), parent(Z, Y). Meaning: X is a grandparent of Y if X is a parent of Z and Z is a parent of Y. Example:  Mega is a daughter of sham if sham is a father of mega.  X is father of Y if X is a parent of Y and X is male. prolog father(X,Y):- parent(X,Y),male(X).
  • 7.
    c. Queries Allow thesystem to infer information from facts and rules. Syntax: ?- query. Example: prolog ?- grandparent(john, alice). The system will return true if the query is satisfied based on facts and rules, or false otherwise. Example: Mega is jhon?  Is pizza a food? ?-food(pizza)  Which food is meal and lunch ?-meal(X);lunch(X). X:- Y;Z X:- Y X:- Z
  • 8.
    3. Advantages ofProlog for Knowledge Representation •Declarative Nature: You just explain what to do, not how to do it. •Logical Reasoning: Prolog finds answers by matching queries with rules and facts. •Expressiveness: Easily handles complex relationships and structures. •Compact Syntax: Knowledge is written in a short and clear way.
  • 9.
    4. Applications inAI •Expert Systems: Use rules and facts to solve problems, like medical diagnosis systems. •Natural Language Understanding: Helps in understanding and processing human language. •Problem Solving: Handles planning and solving constraint-based problems. •Semantic Web: Organizes and queries knowledge so machines can understand it.
  • 10.
    5. Example: FamilyRelationship Knowledge Base  Here’s a simple Prolog program for representing family relationships:  prolog  % Facts parent(john, mary).  parent(mary, alice).  parent(mary, tom).  parent(alice, sarah).  % Rules  grandparent(X, Y) :- parent(X, Z), parent(Z, Y).  sibling(X, Y) :- parent(Z, X), parent(Z, Y), X = Y.  % Queries  ?- grandparent(john, sarah). % true  ?- sibling(alice, tom). % true  ?- parent(john, tom). % false
  • 11.
    6. Challenges ofKnowledge Representation in Prolog  Scalability: Handling large-scale knowledge bases can be challenging.  Uncertainty: Prolog doesn’t handle probabilistic reasoning directly.  Ambiguity: Representing vague or ambiguous knowledge requires extensions or workarounds.
  • 12.
    Conclusion Prolog provides arobust framework for representing and reasoning about knowledge in AI. Its logical structure allows developers to focus on the semantics of the problem rather than the implementation, making it a powerful tool for building intelligent systems.
  • 13.
  • 14.