0% found this document useful (0 votes)
4 views110 pages

CSA (2001) : Fundamental in AIML, Module 3

The document discusses the fundamentals of knowledge representation in artificial intelligence, focusing on propositional logic and first-order predicate logic. It explains the syntax, semantics, and components of these logical systems, as well as their differences and applications in AI. Additionally, it covers various techniques for knowledge representation, including semantic networks, frame representation, production rules, and ontological engineering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views110 pages

CSA (2001) : Fundamental in AIML, Module 3

The document discusses the fundamentals of knowledge representation in artificial intelligence, focusing on propositional logic and first-order predicate logic. It explains the syntax, semantics, and components of these logical systems, as well as their differences and applications in AI. Additionally, it covers various techniques for knowledge representation, including semantic networks, frame representation, production rules, and ontological engineering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 110

Fundamentals In AI & ML

(Department of Computer Science Engineering and


Artificial Intelligence)

Dr. Priscilla Dinkar Moyya


VIT Bhopal University
Knowledge
Representation

2
Propositional Logic:

Propositional logic (PL) is the simplest form of logic


where all the statements are made by propositions. A
proposition is a declarative statement which is either
true or false. It is a technique of knowledge
representation in logical and mathematical form.

Alphabet Set:
1. Set of variables or propositional symbols P,Q,R
2. Logical constants – True (T), False(F)
3. Two Parentheses – “(“and”)”
4. Set of logical operators
3
Word Symbol Example
not ¬ ¬X
and
 ∧ X ∧Y
or ∨ X ∨Y
Implies → X → Y (if X then Y)
If and only ⇔ X ⇔Y

Example: Sentences
X: It is hot
Y: It is humid
Z: It is raining
1. If it is humid then it is hot
Sol. (Y→ X)
4
2. If it is hot and humid then it is not raining
Sol. (X ∧ Y) → ¬ Z

5
First Order Predicate Logic :
 First Order Logic (FOL) can be simply put as a
collection of objects, their attributes and relations
among them to represent knowledge. It is also known
as Predicate Logic.
 First-order logic is another way of knowledge
representation in artificial intelligence. It is an
extension to propositional logic. FOL is sufficiently
expressive to represent the natural language statements
in a concise way. First-order logic is also known as
Predicate logic or First-order predicate logic.

6
What is First Order Logic?
1. FOL is a mode of representation in Artificial
Intelligence. It is an extension of PL.
2. FOL represents natural language statements in a
concise way.
3. FOL is also called predicate logic. It is a powerful
language used to develop information about an object
and express the relationship between objects.
4. FOL not only assumes that does the world contains
facts (like PL does), but it also assumes the following:
 Objects: A, B, people, numbers, colors, wars, theories,
squares, pit, etc.
7
 Relations: It is unary relation such as red, round, sister
of, brother of, etc.
 Function: father of, best friend, third inning of, end of,
etc.

8
Representing Simple Statements
in FOL:
It is important that you know the logical
operators/connectives that are used in Propositional
Logic.

9
Parts of First Order Logic:
FOL also has two parts:
1. Syntax
2. Semantics

 Syntax: The syntax of FOL decides which collection


of symbols is a logical expression. The basic
syntactic elements of FOL are symbols. We use
symbols to write statements in shorthand notation.

10
Basic Elements of FOL:

11
Atomic and Complex Sentences
in FOL:
1. Atomic Sentence:
• This is a basic sentence of FOL formed from a
predicate symbol followed by a parenthesis with a
sequence of terms.
• We can represent atomic sentences as a predicate
(value1, value2…., value n).
Example-
▪ John and Michael are colleagues→ colleagues (John,
Michael)
▪ German Shepherd is a dog→ Dog (German Shepherd )

12
Complex Sentence:
 Complex sentences are made by combining atomic
sentences using connectives.
FOL is further divided into two parts:

• Subject: the main part of the statement.

• Predicate: defined as a relation that binds two atoms


together.

Example-
1. “x is an integer”
13
It has two parts;
First, x is the subject.
Second, “is an integer” is called a predicate.

14
Quantifiers and their use in FOL:
Quantifiers generate quantification and specify the
number of specimen in the universe.
• Quantifiers allow us to determine or identify the range
and scope of the variable in a logical expression.
• There are two types of quantifiers:
1. Universal quantifier: for all, everyone, everything.
2. Existential quantifier: for some, at least one.

15
1. Universal Quantifiers:
• Universal quantifiers specify that the statement within
the range is true for everything or every instance of a
particular thing.
• Universal quantifiers are denoted by a symbol
that looks like an inverted A. In a universal quantifier,
we use
• If x is a variable then, can read as:
1. For all x
2. For every x
3. For each x

16
Example-
Every student likes educative.

17
Explanation:
So, in logical notation, it can be written as:

This can be interpreted as: There is every x where x is a


student who likes Educative.
2. Existential Quantifiers:
Existential quantifiers are used to express that the
statement within their scope is true for at least one
instance of something.
which looks like an inverted E, is used to represent
18
them. We always use AND or conjunction symbols.
If x is a variable, the existential quantifier will be
1. For some x
2. There exists an x
3. For at least one x

Example-
Some people like Football.

19
Explanation:
So, in logical notation, it can be written as:

It can be interpreted as: There are some x where x is


people who like football.

20
Difference between Propositional Logic and
Predicate Logic:
Propositional Logic Predicate Logic
1. Propositional logic is the logic that deals 1. Predicate logic is an expression
with a collection of declarative statements consisting of variables with a specified
which have a truth value, true or false. domain. It consists of objects, relations and
functions between the objects.

2. It is the basic and most widely used 2. It is an extension of propositional logic


logic. Also known as Boolean logic. covering predicates and quantification.

3. A proposition has a specific truth value, 3. A predicate’s truth value depends on the
either true or false. variables’ value.

4. It is a more generalized representation. It is a more specialized representation.

21
Propositional Logic Predicate Logic
5. It cannot deal with sets of entities. 5. It can deal with set of entities with the help
of quantifiers.
6. Scope analysis is not done in propositional 6. Predicate logic helps analyze the scope of the
logic. subject over the predicate. There are three
quantifiers : Universal Quantifier (∀) depicts
for all, Existential Quantifier (∃) depicting
there exists some and Uniqueness Quantifier
(∃!) depicting exactly one.

7. Propositions are combined with Logical 7. Predicate Logic adds by introducing


Operators or Logical Connectives like quantifiers to the existing proposition.
Negation(¬), Disjunction(∨), Conjunction(∧),
Exclusive OR(⊕), Implication(⇒), Bi-
Conditional or Double Implication(⇔).

22
FOPL Examples:

1. All boys like cricket

2. Some boys like football

3. Some girls hate football

23
4. All girls love Pink

5. Every person who buys a policy is smart

6. No person buys expensive Policy

24
FOPL Examples:

1. All boys like cricket


∀x: boys(x)→ like (x, cricket)

2. Some boys like football


∃x: boys(x) ∧ like (x, football)

3. Some girls hate football


∃x: girls(x) ∧ hate (x, football)

25
4. All girls love Pink
∀x: girls(x)→ love (x, Pink)

5. Every person who buys a policy is smart


∀x∀y : Person(x) ∧ Policy(y) ∧ buys(x,y)→ smart(x)

6. No person buys expensive Policy


∀x∀y : Person(x) ∧ Policy(y) ∧ expensive(y) →
¬ buys(x,y)

26
Knowledge Representation:
 Knowledge Representation and Reasoning (KR, KRR)
represents information from the real world for a computer
to understand and then utilize this knowledge to
solve complex real-life problems like communicating with
human beings in natural language.
 The different kinds of knowledge that need to be
represented in AI include:
➢ Objects
➢ Events
➢ Performance
➢ Facts
➢ Meta-Knowledge
➢ Knowledge-Base
27
Different Types of Knowledge:
There are 5 types of knowledge such as:

28
1. Declarative knowledge- It includes concepts, facts,
and objects and expressed in a declarative sentence.
2. Structural knowledge- It is a basic problem-solving
knowledge that describes the relationship between
concepts and objects.
3. Procedural Knowledge – This is responsible for
knowing how to do something and includes rules,
strategies, procedures, etc.
4. Meta Knowledge – Meta Knowledge defines
knowledge about other types of Knowledge.
5. Heuristic Knowledge – This represents some expert
knowledge in the field or subject.
29
Cycle of Knowledge Representation:

Artificial Intelligent Systems usually consist of various


components to display their intelligent behaviour. Some
of these components include:
• Perception
• Learning
• Knowledge Representation & Reasoning
• Planning
• Execution

30
Here is an example to show the different components of
the system and how it works:
Example:

31
Relation Between Knowledge and
Intelligence:

 In the real world, knowledge plays a vital role in


intelligence as well as creating artificial intelligence. It
demonstrates the intelligent behaviour in AI agents or
systems. It is possible for an agent or system to act
accurately on some input only when it has the
knowledge or experience about the input.

32
33
Techniques of Knowledge
Representation:

34
1. Logical Representation: Logical Representation is a
language with some definite rules which deals with
propositions and has no ambiguity in representation.
It represents a conclusion based on various
conditions and lays down some important
communication rules.

35
Syntax Semantics

It decides how we can construct legal Semantics are rules by which we can
sentences in logic. interpret the sentence in the logic.

It determines which symbol we can use in It assigns a meaning to each sentence.


knowledge representation.

Also, how to write those symbols.

36
Advantages:
• Logical representation helps to perform logical
reasoning.
• This representation is the basis for the programming
languages.
Disadvantages:
• Logical representations have some restrictions and are
challenging to work with.
• This technique may not be very natural, and inference
may not be very efficient.

37
2. Semantic Network Representation:
TOM is a cat
TOM is grey in color
TOM is mammal
TOM is owned by Sam
CAT is a mammal

38
Advantages Disadvantages

Semantic networks are a natural representation Semantic networks take more computational
of knowledge. time at runtime.

Also, it conveys meaning in a transparent Also, these are inadequate as they do not have
manner. any equivalent quantifiers.

These networks are simple and easy to These networks are not intelligent and depend
understand. on the creator of the system.

39
Components of Semantic Networks:
1. Lexical Component- Nodes, Links, Labels
2. Structural Component- Links, Nodes
3. Semantic Component- It shows definition related to
link or nodes. It basically represents the facts.
4. Procedural Component-
• Constructor Level
• Destructor Level

40
3. Frame Representation:
A frame is a record like structure that consists of
a collection of attributes and values to describe an entity
in the world.

41
Advantages Disadvantages

It makes the programming easier by grouping In frame system inference, the mechanism
the related data. cannot be easily processed.

Frame representation is easy to understand and The inference mechanism cannot be smoothly
visualize. proceeded by frame representation.

It is very easy to add slots for new attributes and It has a very generalized approach.
relations.

42
There are certain attributes that are attached with each slot-
▪ Instance- It relates the slot with the class.
▪ Definition- Slot Def./value
▪ Default- Slot Default value
▪ Domain- Slots elements Domain
▪ Range- Specify the class of which elements
▪ Range Constrain- It is a logical expression. Eg. 6<i<10
▪ To-Complete- Value of slot is to be completed.
▪ Single valued- Function returns single value
▪ Inverse- Slot inverse which is used in reasoning.
▪ Transfer Through- It is used in Inheritance.

43
4. Production Rules:
 In production rules, agent checks for the condition and
if the condition exists then production rule fires and
corresponding action is carried out. The condition part
of the rule determines which rule may be applied to a
problem. Whereas, the action part carries out the
associated problem-solving steps. This complete
process is called a recognize-act cycle.
 The production rules system consists of three main
parts:
• The set of production rules
• Working Memory
• The recognize-act-cycle
44
Examples of Production Rules:

• IF (at bus stop AND bus arrives) THEN action (get


into the bus)

• IF (on the bus AND paid AND empty seat) THEN


action (sit down).

• IF (on bus AND unpaid) THEN action (pay


charges).

• IF (bus arrives at destination) THEN action (get


down from the bus).
45
Advantages Disadvantages

The production rules are expressed in It does not exhibit any learning capabilities
natural language. and does not store the result of the problem
for future uses.

The production rules are highly modular and During the execution of the program, many
can be easily removed or modified. rules may be active. Thus, rule-based
production systems are inefficient.

46
Ontological Engineering:
 A set of concepts and categories in a subject area or
domain that shows their properties and the relations
between them
 Ontology engineering is a set of tasks related to the
development of ontologies for a particular domain.
 It allows the reuse of knowledge in a knowledge
base by providing conceptualization, reflecting
assumptions and requirements made in the
problem solving using the knowledge base.
Ontology engineering provides the means to build
and use ontologies for building models.
47
The word itself and its origin:
 The word ontology comes from two Greek work
 “onto” = existence, or being real
 “logia” = science, or study
 The word is used in two settings
 The ontology is used in both in philosophical and non
philosophical context.

48
Ontology vs Knowledge Base:

“The Artificial- Intelligence literature contains many


definitions of an ontology; many of these contradict one
another…An ontology together with a set of individual
instances of classes constitutes a knowledge base. In
reality, there is a fine line where the ontology ends and
the knowledge base begins.”

49
Types of Ontologies:

50
Upper Ontology:
▪ An upper Ontology- also called top-level ontology or
foundation ontology- describes the most general
concepts that are same across all knowledge domains.
(e.g. Entity).

General Ontologies:
▪ General Ontologies represent knowledge at an
intermediate level of detail independently of a specific
task.. Theories of time and space.

51
Domain Level Ontologies:
▪ …Ontologies designed for specific tasks are called
application ontologies. Conversely, reference
ontologies are developed independently of any
particular purpose.

52
Categories and Objects:
 The organization of objects into categories.
 Much reasoning takes place at the level of categories.
 For example, a shopper would normally have the goal
of buying a basketball, rather than a particular
basketball such as BB9.
 Categories also serve to make predictions about
objects once they are classified.
 Representation of categories in first-order logic:
a) Predicates e.g. Basketball(b)
b) Objects e.g. Basketball

53
Categories:
 Categories serve to organize and simplify the
knowledge base through inheritance.

 Subclass relations organize categories into a


taxonomy, or taxonomic hierarchy
➢ Subset(Basketball, Balls)

54
Example:
 An object is a member of a category.
BB9 ∈ Basketballs
• A category is a subclass of another category.
Basketballs C Balls
• All members of a category have some properties.
(x ∈ Basketballs) ⇒ Spherical (x)
• Members of a category can be recognized by
some properties.
• Orange(x) ∧ Round(x) ∧ Diameter(x) = 9.5 ∧ x ∈
Balls ⇒ x ∈ Basketballs
• A category as a whole has some properties.
55 Dogs ∈ Domesticated Species
Objects:
▪ The real-world can be seen as consisting of primitive objects
(e.g., atomic particles) and composite objects built from
them.
➢ Stuff
➢ Things
▪ Some Properties are Intrinsic: they belong to very substance
of the objects, rather than to the object as a whole.
▪ Extrinsic properties- Weight, length, shape, and so on- are
not retained under subdivision.
▪ A category of objects that includes in its destination only
intrinsic properties is then a substance, or mass noun; a class
that includes any extrinsic properties in its definition is a
56 count noun.
Mental Events and Mental Objects:

 A mental event is any event that happens within the


mind of conscious individual such as thoughts,
feelings, decisions, dreams and realizations.
 Example- Mary feels happy after doing well on an
exam and she smiles. This thought is a mental event
while the smile is physical event.
A killer whale recognized a feeling of hunger. It eats a
fish. The recognition of the feeling of hunger is a mental
event. Eating the fish is physical event.

57
Mental Events and Mental Objects:
 Knowledge about one’s own knowledge and reasoning
processes is useful for controlling the Inference.
 The agent should know what are in its knowledge base and
what are not
 What we need is a model of the mental objects that are in
someone’s hear (or some-thing’s knowledge base) and of the
mental processes that manipulate those mental objects.
 Propositional attitudes that an agent can have toward mental
objects: attitudes such as Believes, Knows, Wants, Intends and
Informs.

58
Monotonic Reasoning:

 Once the conclusion is taken, then it will remain same


even if we add some information to existing
information in our knowledge base.
 Decision are not affected by new facts, not suitable for
real time system.
 Example-
1. Earth revolves around the sun.
2. Earth is not Round- new information.

59
Advantages:

 All old proofs are valid.

Disadvantages:
 Can’t use for real-world problem.
 New knowledge from real world can’t be
added.
 Example- Theorem Proving.
60
Non-Monotonic Reasoning:
 In Non-monotonic reasoning, some conclusions may
be invalidated if we add some more information to
our knowledge base. Logic will be said as non-
monotonic if some conclusions can be invalidated by
adding more knowledge into our knowledge base.
Non-monotonic reasoning deals with incomplete and
uncertain models.
 “Human perceptions for various things in daily life, "is
a general example of non-monotonic reasoning.

61
Example: Let suppose the knowledge base contains the
following knowledge:
• Birds can fly
• Penguins cannot fly
• Pitty is a bird
• Conclusion: Pitty can Fly

62
 Example-
▪ Facts:
▪ Birds can fly.
▪ Penguins can’t fly.
▪ Pitty is a bird.
▪ Conclusion: Pitty Can’t Fly.
▪ Disadvantages: Can’t used for theorem proving
▪ Example- Robot Navigation

63
Example-
▪ Penguin cannot Fly
▪ Birds has wings
▪ Birds can Fly
▪ Penguin is a bird
▪ Conclusion: Penguin can Fly

64
Advantages Disadvantages

For real-world systems such as Robot In non-monotonic reasoning, the old facts
navigation, we can use non-monotonic may be invalidated by adding new sentences.
reasoning.

In Non-monotonic reasoning, we can choose It cannot be used for theorem proving.


probabilistic facts or can make assumptions.

65
Default Reasoning:

Logics for Non-monotonic Reasoning:


 Default logic can express facts like “by default, something
is true”; by contrast, standard logic can only express that
something is true or that something is false. This is a
problem because reasoning often involves facts that are true
in the majority of cases but not always.
 Example is:
 “birds typically fly”. This rule can be expressed in standard
logic either by “all birds fly”, which is inconsistent with the
fact that are not penguins and not ostriches and…. Fly”,
which requires all exceptions to the rule to be specified.
 Default logic aims at formalizing inference rules like this
66 one without explicitly mentioning all their exceptions.
Default Logic:

▪ For example
A:B
C
▪ Read as “If A is provable and it is consistent to
assume B then conclude C”.

67
Example-
 The Default rule “birds typically fly” is formalized by
the following default:
D = {Bird(X): Flies(X)}
Flies(X)

This rules means that, “if X is a bird, and it can be


assumed that it flies, then we can conclude that it flies”.
A background theory containing some facts about birds
is the following one:

W = {Bird(Condor), Bird(Penguin),¬ Flies (Penguin),


Flies(Bee)}.
68
What is Default Reasoning?
▪ Q. How many wheels of Johan’s car have?
▪ Ans. 4

▪ The Conclusion is withdrawn if one supplied with the


information that one wheel of john’s car has just been stolen

Non monotonicity
69
Approaches of Default Reasoning:
1. Non Monotonic Logic:
▪ Truth of proposition may change when new
information are added and logic may be built to allow
the statement to be retracted.
▪ Use Model Operator M
▪ M is used for to allow consistency
Example-
∀x:plays_instrument(x) AND M Manages(x) -
>johns_musician(x)

70
Default Logic:

▪ For example
A:B
C
Where,
A = Pre requisite
B = Justification
C = Consequent

71
Forward Chaining and Backward
Chaining in AI:
Inference Engine:
The inference engine is the component of the intelligent
system in artificial intelligence, which applies logical
rules to the knowledge base to infer new information
from known facts. The first inference engine was part of
the expert system. Inference engine commonly proceeds
in two modes, which are:
a. Forward Chaining
b. Backward Chaining

72
Forward Chaining:
 Forward chaining is also known as a forward
deduction or forward reasoning method when using an
inference engine. Forward chaining is a form of
reasoning which start with atomic sentences in the
knowledge base and applies inference rules (Modus
Ponens) in the forward direction to extract more data
until a goal is reached.
 The Forward-chaining algorithm starts from known
facts, triggers all rules whose premises are satisfied,
and add their conclusion to the known facts. This
process repeats until the problem is solved.
73
Properties of Forward Chaining:
• It is a down-up approach, as it moves from bottom to
top.
• It is a process of making a conclusion based on known
facts or data, by starting from the initial state and
reaches the goal state.
• Forward-chaining approach is also called as data-
driven as we reach to the goal using available data.
• Forward -chaining approach is commonly used in the
expert system, such as CLIPS, business, and
production rule systems.
74
Advantages:
• It can be used to draw multiple conclusions.
• It provides a good basis for arriving at conclusions.
• It’s more flexible than backward chaining because it
does not have a limitation on the data derived from it.

Disadvantages:
• The process of forward chaining may be time-
consuming. It may take a lot of time to eliminate and
synchronize available data.
• Unlike backward chaining, the explanation of facts or
observations for this type of chaining is not very clear.
The former uses a goal-driven method that arrives at
75 conclusions efficiently.
Example of Forward Chaining:
 When based on available data a
decision is taken then the process is
called as the forward chaining.
 It works from initial state and
reaches to goal state.

76
77
Proof by Forward Chaining:

78
Backward Chaining:
Backward-chaining is also known as a backward
deduction or backward reasoning method when using an
inference engine. A backward chaining algorithm is a
form of reasoning, which starts with the goal and works
backward, chaining through rules to find known facts
that support the goal.

79
Properties of Backward Chaining:

• It is known as a top-down approach.


• Backward-chaining is based on modus ponens
inference rule.
• In backward chaining, the goal is broken into sub-goal
or sub-goals to prove the facts true.
• It is called a goal-driven approach, as a list of goals
decides which rules are selected and used.
• Backward -chaining algorithm is used in game theory,
automated theorem proving tools, inference engines,
proof assistants, and various AI applications.
• The backward-chaining method mostly used a depth-
80 first search strategy for proof.
Advantages:
• The result is already known, which makes it easy to
deduce inferences.
• It’s a quicker method of reasoning than forward
chaining because the endpoint is available.
• In this type of chaining, correct solutions can be
derived effectively if pre-determined rules are met by
the inference engine.

81
Disadvantages:

• The process of reasoning can only start if the endpoint


is known.
• It doesn’t deduce multiple solutions or answers.
• It only derives data that is needed, which makes it less
flexible than forward chaining.

82
Backward Chaining Example-

83
84
Resolution:

 Resolution method is an inference rule which is used


in both Propositional as well as First-order Predicate
Logic in different ways. This method is basically used
for proving the satisfiability of a sentence. In
resolution method, we use Proof by
Refutation technique to prove the given statement.

85
Example-
Prove Ravi likes Peanuts
FOL: likes (Ravi, Peanuts)

Steps:
▪ Negate the statement to be proved
likes (Ravi, Peanuts)
▪ Convert given Facts into FOL
▪ Convert FOL into CNF (Conjunctive Normal Form) or
(Closed Normal Form)
▪ Draw Resolution Graph

86
Convert into FOL:

87
Rules to convert FOL into CNF:

88
For example-

89
Resolution Graph:

90
Prolog:
 Prolog (Programming in logic) is one of the most
widely used programming languages in artificial
intelligence research. As opposed to imperative
languages such as C or Java(which also happens to be
object-oriented) it is a declarative programming
language.
 Prolog is very useful in some problem areas, like
artificial intelligence, natural language processing,
databases, etc…, but pretty useless in others, like
graphics or numerical algorithms.

91
 Programming in Prolog means describing the world.
Using such programs means asking Prolog questions
about the previously described world. The simplest
way of describing the world is by stating facts, like this
one:

bigger( elephant, horse).


• This states, the fact that an elephant is bigger than a
horse. (Whether the world described by a Prolog
program has anything to do with our real world is of
course entirely up to the programmer.)
92
 Let’s add a few more facts to our little program:

bigger( elephant, donkey).


bigger( horse, donkey).
bigger( donkey, dog).
bigger( donkey, monkey).

After having compiled it we can ask the Prolog system


questions (or queries in proper Prolog-jargon) about it.
Here’s an example:

?- bigger( donkey, dog).


93
 The query bigger( donkey, dog)(i.e. the question \Is a
donkey bigger than a dog?”) succeeds, because the fact
bigger( donkey, dog) has been communicated to the Prolog
system before. Now, is a monkey bigger than an elephant?

?- bigger( monkey, elephant).


No

No, it’s not. We get exactly the answer we expected: the


corresponding query namely bigger( monkey, elephant) fails.

94
Prolog Syntax:

1. Terms
▪ The central data structure in Prolog is that of a term.
There are of four kinds:
i. Atoms
ii. Numbers
iii. Variables and
iv. Compound terms

95
i. Atoms
• Atoms are usually strings made up of lower- and
uppercase letters, digits and the underscore starting
with the lowercase letter. The following are all valid
Prolog atoms:

Atoms → elephant, b, abcXYZ, x_123

• Also any series of arbitrary characters enclosed in


single quotes denotes an atom.

‘This is also a Prolog atom.’


96
ii. Numbers
• Number can be in integer or in float.

iii. Variables
• Variables are strings of letters, digits and underscore,
starting with a capital letter or an underscore.

Variables→ X, Elephant, _4711, X_1_2, MyVariable, _

• The last one of the above examples (the single


underscore) constitutes a special case. It is called the
anonymous variable and is used when the value of a
variable is of no particular interest.
97
iv. Compound terms
• Compound terms are made up of a functor (a Prolog
atom) and a number of arguments (Prolog terms, i.e.
atoms, numbers, variables, or other compound terms)
enclosed in parenthesis and separated by commas. The
following are some examples for compound terms:

is_bigger( horse, X), f(g(X,_),7), ‘My Functor’( dog)

• It’s important not to put any blank characters between


the functor and the opening parenthesis, or Prolog
won’t understand what you’re trying to say.
• In Prolog, the word functor is used to refer to the atom
at the start of a structure, along with its arity, that is,
98
the number of arguments it takes.
2. Clauses
• Prolog programs are made up of facts and rules. Facts
and rules are called clauses.
❑ Facts
A fact is a predicate followed by a dot. And predicate is
the name given to the word occurring before the bracket
in a fact or rule.
❑ Examples: bigger(cat, rat).
• It can be read as cat is bigger then rat.
• The intuitive meaning of a fact is that, we define a
certain instance of the relation as being true.
99
Rules:
▪ Rules allow us to understand that a property or relationship
holds based on preconditions.
▪ A rule consists of head (a predicate) and a body. (a
sequence of predicates separated by commas). Head and
body are separated by the sign :- and, like every Prolog
expression, a rule has to be terminated by a dot.
❑ Examples: For all X and Y
if X is a mother of Y then
X is a parent of Y
▪ Here the prolog clauses is: parent(X,Y):-mother(X,Y). are
called rules.
Head Body
100
▪ There is important difference between fact and rules. A fact
like parent(tom,liz). Is something that is always
unconditionally true. On the other hand rules specify things
that are true if some condition is satisfied.

101
3. Recursive Rules (predecessor relation)
This relation will be defined in terms of parent relation.
The whole definition can be expressed with two rules.
The first rule will define the direct (immediate)
predecessors and the second rule the indirect
predecessors. We say that some X is an indirect
predecessor of some Z if there is a parentship chain of
people between X and Z as illustrated in figure below.

102
The first rule is simple and can be formulated as:
For all X and Z,
X is a predecessor of Z if
X is a parent of Z.

▪ This is straightforwardly translated into Prolog as:

103
predecessor(X, Z) :- parent(X, Z)
▪ The second rule can be formulated as:
For all X and Z.
X is a predecessor of Z if
there is a Y such that
(1) X is a parent of Y and
(2) Y is a predecessor/ parent of Z.
▪ This is straightforwardly translated into Prolog as:
predecessor(X, Z) :- parent(X,Y), predecessor/parent(Y,Z).
104
Unification:
• Unification is the process of finding a substitute that
makes two separate logical atomic expressions
identical. The substitution process is necessary for
unification.
• It accepts two literals as input and uses substitution to
make them identical.
• Let Ψ1 and Ψ2 be two atomic sentences, and be a
unifier such that Ψ1𝜎 = Ψ2𝜎, then UNIFY(Ψ1, Ψ2)can
be written.
 Example: Find the MGU for Unify{King(x),
King(John)}
Let Ψ1 = King(x), Ψ2 = King(John),
105
Conditions for Unification:
The following are some fundamental requirements
for unification:
• Predicate Symbols must be same.
• No. of arguments in both expressions must be
identical.
• If two similar variables present in same expression
then unification fails.

106
Simple E.g.-

P(x, F(y))--------------(1)
P(a, F(g(z))------------(2)

Eqn. (1) & (2) are identical if x is replace with a –


and y is replace with g(z)

P(a, F(g(z))
[a/x, g(z)/y]

It means x is replaced with a and y is replace with g(z)

107
Example-1:
Q (a, g(x, a), f(y)) , Q (a, g(f(b), a), x)

A1 A2

Substitute x with f(b) [f(b)/x]

Q(a, g(f(b), a), f(y)), Q(a, g(f(b),a), f(b))

Substitute (b/y) [y is substituted with b]

[Q(a, g(f(b), a), Q (a, g(f(b),a), f(b)]


Unified Successfully
108
Example-2:
Prime (11), Prime (y)

Substitute y with 11

Prime (11), Prime(11)

Unified Successfully

109
Thank you

110

You might also like