0% found this document useful (0 votes)
5 views

AI Ch3

It is a ch 3 of artificial intelligence sem7 BE

Uploaded by

Afrin shaikh
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)
5 views

AI Ch3

It is a ch 3 of artificial intelligence sem7 BE

Uploaded by

Afrin shaikh
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/ 14

AI Unit– 3 Knowledge Representation

Q.1 What is knowledge representation?


 Knowledge representation and reasoning (KR, KRR) is the part of Artificial
intelligence which concerned with AI agents thinking and how thinking contributes
to intelligent behavior of agents.

o It is responsible for representing information about the real world so that a


computer can understand and can utilize this knowledge to solve the complex real
world problems.
o Like diagnosis a medical condition or communicating with humans in natural
language.
o Following are the kind of knowledge which needs to be represented in AI systems:

 Object: All the facts about objects in our world domain. E.g., Guitars contains
strings, trumpets are brass instruments.
 Events: Events are the actions which occur in our world.
 Performance: It describe behavior which involves knowledge about how to do
things.
 Meta-knowledge: It is knowledge about what we know.
 Facts: Facts are the truths about the real world and what we represent.
 Knowledge-Base: The central component of the knowledge-based agents is the
knowledge base.

Types of knowledge

DHAVAL R.PATEL Page 1


AI Unit– 3 Knowledge Representation

Q.2 Explain AI knowledge cycle:


o Perception
o Learning
o Knowledge Representation and Reasoning
o Planning
o Execution

DHAVAL R.PATEL Page 2


AI Unit– 3 Knowledge Representation

 The above diagram is showing how an AI system can interact with the real world
and what components help it to show intelligence.
 AI system has Perception component by which it retrieves information from its
environment.
 It can be visual, audio or another form of sensory input. The learning component is
responsible for learning from data captured by Perception comportment.
 In the complete cycle, the main components are knowledge representation and
Reasoning.
 These two components are involved in showing the intelligence in machine-like
humans. These two components are independent with each other but also coupled
together.
 The planning and execution depend on analysis of Knowledge representation and
reasoning.

Q.3 Explain First-Order Logic in Artificial intelligence.


o First-order logic is another way of knowledge representation in artificial
intelligence. It is an extension to propositional logic.
o FOL is sufficiently expressive to represent the natural language statements in a
concise way.
o First-order logic is also known as Predicate logic or First-order predicate logic.
First-order logic is a powerful language that develops information about the objects
in a more easy way and can also express the relationship between those objects.

DHAVAL R.PATEL Page 3


AI Unit– 3 Knowledge Representation

o First-order logic (like natural language) does not only assume that the world
contains facts like propositional logic but also assumes the following things in the
world:
o Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus,
......
o Relations: It can be unary relation such as: red, round, is adjacent, or n-
any relation such as: the sister of, brother of, has color, comes between
o Function: Father of, best friend, third inning of, end of, ......
o As a natural language, first-order logic also has two main parts:
o Syntax
o Semantics

Syntax of First-Order logic:

 The syntax of FOL determines which collection of symbols is a logical expression in


first-order logic.
 The basic syntactic elements of first-order logic are symbols
 . We write statements in short-hand notation in FOL.

Basic Elements of First-order logic:

Following are the basic elements of FOL syntax:

Constant 1, 2, A, John, Mumbai, cat,....

Variables x, y, z, a, b,....

Predicates Brother, Father, >,....

Function sqrt, LeftLegOf, ....

Connectives ∧, ∨, ¬, ⇒, ⇔

DHAVAL R.PATEL Page 4


AI Unit– 3 Knowledge Representation

Equality ==

Quantifier ∀, ∃

Q.4 Explain Computable Function Predicate Logic with


example.
 Predicate Logic deals with predicates, which are propositions, consist of variables.

Predicate Logic - Definition

 A predicate is an expression of one or more variables determined on some specific


domain.
 A predicate with variables can be made a proposition by either authorizing a value
to the variable or by quantifying the variable.

The following are some examples of predicates.

o Consider E(x, y) denote "x = y"


o Consider X(a, b, c) denote "a + b + c = 0"
o Consider M(x, y) denote "x is married to y."

Quantifier:

 The variable of predicates is quantified by quantifiers.


 There are two types of quantifier in predicate logic - Existential Quantifier and
Universal Quantifier.

Existential Quantifier:

 If p(x) is a proposition over the universe U.

DHAVAL R.PATEL Page 5


AI Unit– 3 Knowledge Representation

 Then it is denoted as ∃x p(x) and read as "There exists at least one value in the
universe of variable x such that p(x) is true.
 The quantifier ∃ is called the existential quantifier.

There are several ways to write a proposition, with an existential quantifier, i.e.,

(∃x∈A)p(x) or ∃x∈A such that p (x) or (∃x)p(x) or p(x) is true for some x ∈A.

Universal Quantifier:

 If p(x) is a proposition over the universe U. Then it is denoted as ∀x,p(x) and read as
"For every x∈U,p(x) is true." The quantifier ∀ is called the Universal Quantifier.

There are several ways to write a proposition, with a universal quantifier.

∀x∈A,p(x) or p(x), ∀x ∈A Or ∀x,p(x) or p(x) is true for all x ∈A.

Negation of Quantified Propositions:

 When we negate a quantified proposition, i.e., when a universally quantified


proposition is negated, we obtain an existentially quantified proposition,and when
an existentially quantified proposition is negated, we obtain a universally quantified
proposition.
 The two rules for negation of quantified proposition are as follows. These are also
called DeMorgan's Law.

Example: Negate each of the following propositions:

1.∀x p(x)∧ ∃ y q(y)

Sol: ~.∀x p(x)∧ ∃ y q(y))


≅~∀ x p(x)∨∼∃yq (y) (∴∼(p∧q)=∼p∨∼q)
≅ ∃ x ~p(x)∨∀y∼q(y)

2. (∃x∈U) (x+6=25)

Sol: ~( ∃ x∈U) (x+6=25)


≅∀ x∈U~ (x+6)=25
≅(∀ x∈U) (x+6)≠25

3. ~( ∃ x p(x)∨∀ y q(y)

DHAVAL R.PATEL Page 6


AI Unit– 3 Knowledge Representation

Sol: ~( ∃ x p(x)∨∀ y q(y))


≅~∃ x p(x)∧~∀ y q(y) (∴~(p∨q)= ∼p∧∼q)
≅ ∀ x ∼ p(x)∧∃y~q(y))

Q.5 What is Forward Reasoning?


 Forward reasoning is a process in artificial intelligence that finds all the possible
solutions of a problem based on the initial data and facts.
 Thus, the forward reasoning is a data-driven task as it begins with new data.
 The main objective of the forward reasoning in AI is to find a conclusion that would
follow.
 Forward reasoning flows from initial to the consequence. The inference engine
searches the knowledge base with the given information depending on the
constraints. The precedence of these constraints have to match the current state.
 In forward reasoning, the first step is that the system is given one or more
constraints.
 The rules are then searched for in the knowledge base for every constraint.
 The rule that fulfils the condition is selected. Also, every rule can generate a new
condition from the conclusion which is obtained from the invoked one. This new
conditions can be added and are processed again.

Q.6 What is Backward Reasoning?


 Backward reasoning is the reverse process of the forward reasoning in which a
goal is selected and it is analyzed to find the initial data, facts, and rules.
 Therefore, the backward reasoning is a goal driven task as it begins with
conclusions or goals that are uncertain.
 The main objective of the backward reasoning is to find the facts that support the
conclusions.
 Backward reasoning uses a conservative type of approach and flows from
consequence to the initial.
 The system helps to choose a goal state and reasons in a backward direction.

DHAVAL R.PATEL Page 7


AI Unit– 3 Knowledge Representation

 The first step in the backward reasoning is that the goal state and rules are selected.
Then, sub-goals are made from the selected rule, which need to be satisfied for the
goal state to be true.
 Backward reasoning is also known as a decision-driven or goal-driven inference
technique because the system selects a goal state and reasons in the backward
direction.

Q.7 Difference between Forward and Backward


Reasoning in AI.
The following are the important differences between Forward and Backward Reasoning in
AI −

S.No. Forward Reasoning Backward Reasoning

1. It is a data-driven task. It is a goal driven task.

It begins with conclusions that are


2. It begins with new data.
uncertain.

The objective is to find a conclusion that The objective is to find the facts that
3.
would follow. support the conclusions.

4. It uses an opportunistic type of approach. It uses a conservative type of approach.

It flows from consequence to the


5. It flows from incipient to the consequence.
incipient.

Forward reasoning begins with the initial Backward reasoning begins with some
6.
facts. goal (hypothesis).

7. Forward reasoning tests all the rules. Backward reasons tests some rules.

DHAVAL R.PATEL Page 8


AI Unit– 3 Knowledge Representation

Backward reasoning is a top-down


8. Forward reasoning is a bottom-up approach.
approach.

Forward reasoning can produce an infinite Backward reasoning produces a finite


9.
number of conclusion. number of conclusions.

In the forward reasoning, all the data is In the backward reasoning, the data is
10.
available. acquired on demand.

Forward reasoning has a small number of Backward reasoning has a smaller


11. initial states but a large number of number of goals and a larger number of
conclusions. rules.

In forward reasoning, the goal formation is In backward reasoning, it is easy to form


12.
difficult. a goal.

Forward reasoning works in forward Backward reasoning work in backward


13. direction to find all the possible conclusions direction to find the facts that justify the
from facts. goal.

Forward reason is suitable to answer the


Backward reasoning is suitable for
14. problems such as planning, control,
diagnosis like problems.
monitoring, etc.

Q.8 Explain unification in AI with examples


 Unification is a fundamental concept in artificial intelligence (AI), particularly in
logic programming and automated reasoning.
 It is the process of making two or more logical expressions identical by finding a
suitable substitution for their variables.
 This technique is widely used in AI for tasks such as theorem proving, natural
language processing, and the implementation of logic programming languages like
Prolog.

Definition -
DHAVAL R.PATEL Page 9
AI Unit– 3 Knowledge Representation

“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).”

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

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.

Example 1:

Suppose we have the following expressions:

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


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

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

DHAVAL R.PATEL Page 10


AI Unit– 3 Knowledge Representation

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))

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.

Q. 9 What is resolution in AI and give some examples?

 Resolution is a fundamental inference rule and a key technique used in automated


theorem proving and logic programming within the field of artificial intelligence.

Resolution Rule:

DHAVAL R.PATEL Page 11


AI Unit– 3 Knowledge Representation

Given two clauses that contain complementary literals (a literal and its negation),
resolution allows us to derive a new clause that is a result of resolving the two
clauses by eliminating the complementary literals.

Example 1:

Let's consider a simple example with propositional logic. Suppose we want to prove
that the following statements are contradictory:

P OR Q
NOT P OR R
NOT Q OR R

To prove contradiction, we can use the resolution rule:

Resolve clauses 1 and 2: (P OR Q) AND (NOT P OR R) => Q OR R


Resolve the result with clause 3: (Q OR R) AND (NOT Q OR R) => R
Since we have derived a clause that contains both R and NOT R (a contradiction), we
conclude that the original statements are contradictory.

Example 2:

Let's consider a more complex example using first-order logic. Suppose we want to
prove the statement: "All humans are mortal."

For all x, Human(x) => Mortal(x)

We'll assume that our knowledge base includes the following premises:

A. Human(Socrates)
B. NOT Mortal(Socrates)

Q.10 Explain Logical programming in ai with example.


 Logic Programming is the combination of two words, logic and programming.
 Logic Programming is a programming paradigm in which the problems are
expressed as facts and rules by program statements but within a system of formal
logic. Just like other programming paradigms like object oriented, functional,
declarative, and procedural, etc., it is also a particular way to approach
programming.

DHAVAL R.PATEL Page 12


AI Unit– 3 Knowledge Representation

 Logic Programming uses facts and rules for solving the problem. That is why they
are called the building blocks of Logic Programming. A goal needs to be specified for
every program in logic programming. To understand how a problem can be solved
in logic programming, we need to know about the building blocks − Facts and Rules

 Following is the syntax of rule –

A∶− B1,B2,...,Bn.

Here, A is the head and B1, B2, ... Bn is the body.

For example − ancestor(X,Y) :- father(X,Y).

ancestor(X,Z) :- father(X,Y), ancestor(Y,Z).

This can be read as, for every X and Y, if X is the father of Y and Y is an ancestor of Z,
X is the ancestor of Z. For every X and Y, X is the ancestor of Z, if X is the father of Y
and Y is an ancestor of Z.

 Installing Useful Packages


o Kanren
o SymPy

 Examples of Logic Programming

Matching mathematical expressions

from kanren import run, var, fact


from kanren.assoccomm import eq_assoccomm as eq
from kanren.assoccomm import commutative, associative

We need to define the mathematical operations which we are going to use −

add = 'add'
mul = 'mul'

Both addition and multiplication are communicative processes. Hence, we need to specify it
and this can be done as follows −

DHAVAL R.PATEL Page 13


AI Unit– 3 Knowledge Representation

fact(commutative, mul)
fact(commutative, add)
fact(associative, mul)
fact(associative, add)

It is compulsory to define variables; this can be done as follows −

a, b = var('a'), var('b')

We need to match the expression with the original pattern. We have the following original
pattern, which is basically (5+a)*b −

Original_pattern = (mul, (add, 5, a), b)

We have the following two expressions to match with the original pattern −

exp1 = (mul, 2, (add, 3, 1))


exp2 = (add,5,(mul,8,1))

Output can be printed with the following command −

print(run(0, (a,b), eq(original_pattern, exp1)))


print(run(0, (a,b), eq(original_pattern, exp2)))

After running this code, we will get the following output −

((3,2))
()

DHAVAL R.PATEL Page 14

You might also like