CSA (2001) : Fundamental in AIML, Module 3
CSA (2001) : Fundamental in AIML, Module 3
2
Propositional Logic:
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
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:
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:
Example-
Some people like Football.
19
Explanation:
So, in logical notation, it can be written as:
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.
3. A proposition has a specific truth value, 3. A predicate’s truth value depends on the
either true or false. variables’ value.
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.
22
FOPL Examples:
23
4. All girls love Pink
24
FOPL Examples:
25
4. All girls love Pink
∀x: girls(x)→ love (x, Pink)
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:
30
Here is an example to show the different components of
the system and how it works:
Example:
31
Relation Between Knowledge and
Intelligence:
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.
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:
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:
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.
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:
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:
59
Advantages:
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.
65
Default Reasoning:
▪ 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)
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:
81
Disadvantages:
82
Backward Chaining Example-
83
84
Resolution:
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:
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:
iii. Variables
• Variables are strings of letters, digits and underscore,
starting with a capital letter or an underscore.
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.
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)
P(a, F(g(z))
[a/x, g(z)/y]
107
Example-1:
Q (a, g(x, a), f(y)) , Q (a, g(f(b), a), x)
A1 A2
Substitute y with 11
Unified Successfully
109
Thank you
110