Chapter3 Notes NEP
Chapter3 Notes NEP
Chapter3 Notes NEP
Logical Agents:
In this chapter we design agent-based system that can represent a complex world. The new
representation about the world can be derived by using process of inference and these new
representations to deduce what to do. Also develop logic as a general class of representation to
support knowledge-based agent.
Knowledge-Based Agent in Artificial intelligence
The main component of knowledge -based agent is its of knowledge-base(KB).
A knowledge base is a set of representations of facts of the world.
Each individual representation is called a sentence.
The sentences are expressed in language termed as knowledge representation language.
An intelligent agent needs knowledge about the real world for taking decisions and
reasoning to act efficiently.
Knowledge-based agents are those agents who have the capability of maintaining an
internal state of knowledge, reason over that knowledge, update their knowledge after
observations and take actions. These agents can represent the world with some formal
representation and act intelligently.
Knowledge-based agents are composed of two main parts:
1. Knowledge-base and
2. Inference system.
A knowledge-based agent must able to do the following:
An agent should be able to represent states, actions, etc.
An agent Should be able to incorporate new percept’s
An agent can update the internal representation of the world
An agent can deduce the internal representation of the world
An agent can deduce appropriate actions.
The architecture of knowledge-based agent:
The above diagram is representing a generalized architecture for a knowledge-based agent. The
knowledge-based agent (KBA) takes input from the environment by perceiving the environment.
The input is taken by the inference engine of the agent and which also communicate with KB to
decide as per the knowledge store in KB. The learning element of KBA regularly updates the KB
by learning new knowledge.
Knowledge base: Knowledge-base is a central component of a knowledge-based agent, it is also
known as KB. It is a collection of sentences (here 'sentence' is a technical term and it is not
identical to sentence in English). These sentences are expressed in a language which is called a
knowledge representation language. The Knowledge-base of KBA stores fact about the
world.
Knowledge-base is required for updating knowledge for an agent to learn with experiences and
take action as per the knowledge
Inference system:
Inference means deriving new sentences from old. Inference system allows us to add a new
sentence to the knowledge base. A sentence is a proposition about the world. Inference system
applies logical rules to the KB to deduce new information.
Inference system generates new facts so that an agent can update the KB. An inference system
works mainly in two rules which are given as:
Forward chaining
Backward chaining
Operations Performed by KBA
Following are three operations which are performed by KBA in order to show the intelligent
behaviour:
TELL: This operation tells the knowledge base what it perceives from the environment.
ASK: This operation asks the knowledge base what action it should perform.
Perform: It performs the selected action.
A generic knowledge-based agent:
Following is the structure outline of a generic knowledge-based agents program:
The knowledge-based agent takes percept as input and returns an action as output. The agent
maintains the knowledge base, KB, and it initially has some background knowledge of the real
world. It also has a counter to indicate the time for the whole process, and this counter is
initialized with zero.
Each time when the function is called, it performs its three operations:
Firstly it TELLs the KB what it perceives.
Secondly, it asks KB what action it should take
Third agent program TELLS the KB that which action was chosen.
The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent perceived the
given percept at the given time.
The MAKE-ACTION-QUERY generates a sentence to ask which action should be done at the
current time.
MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen action was
executed.
Various levels of knowledge-based agent:
A knowledge-based agent can be viewed at different levels which are given below:
1. Knowledge level
Knowledge level is the first level of knowledge-based agent, and in this level, we need to specify
what the agent knows, and what the agent goals are. With these specifications, we can fix its
behaviour. For example, suppose an automated taxi agent needs to go from a station A to station
B, and he knows the way from A to B, so this comes at the knowledge level.
2. Logical level:
At this level, we understand that how the knowledge representation of knowledge is stored. At
this level, sentences are encoded into different logics. At the logical level, an encoding of
knowledge into logical sentences occurs. At the logical level we can expect to the automated taxi
agent to reach to the destination B.
3. Implementation level:
This is the physical representation of logic and knowledge. At the implementation level agent
perform actions as per logical and knowledge level. At this level, an automated taxi agent
actually implement his knowledge and logic so that he can reach to the destination.
There are also some components which can help the agent to navigate the cave. These
components are given as follows:
1. The rooms adjacent to the Wumpus room are smelly, so that it would have some stench.
The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he will
perceive the breeze.
2. There will be glitter in the room if and only if the room has gold.
3. The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus will emit
a horrible scream which can be heard anywhere in the cave.
PEAS description of Wumpus world:
Performance measure:
+1000 reward points if the agent comes out of the cave with the gold.
-1000 points penalty for being eaten by the Wumpus or falling into the pit.
-1 for each action, and -10 for using an arrow.
The game ends if either agent dies or came out of the cave.
Environment:
A 4*4 grid of rooms.
The agent initially in room square [1, 1], facing toward the right.
Location of Wumpus and gold are chosen randomly except the first square [1,1].
Each square of the cave can be a pit with probability 0.2 except the first square.
Actuators:
Left turn,
Right turn
Move forward
Grab
Release
Shoot.
Sensors:
The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not
diagonally).
The agent will perceive breeze if he is in the room directly adjacent to the Pit.
The agent will perceive the glitter in the room where the gold is present.
The agent will perceive the bump if he walks into a wall.
When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere
in the cave.
These percepts can be represented as five element list, in which we will have different
indicators for each sensor.
Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it
can be represented as:
[Stench, Breeze, None, None, None].
Exploring the Wumpus world:
Now we will explore the Wumpus world and will determine how the agent will find its goal by
applying logical reasoning.
Agent's First step:
Initially, the agent is in the first room or on the square [1, 1], and we already know that this room
is safe for the agent, so to represent on the below diagram (a) that room is safe we will add
symbol OK. Symbol A is used to represent agent, symbol B for the breeze, G for Glitter or gold,
V for the visited room, P for pits, W for Wumpus.
At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent squares
are also OK.
At the third step, now agent will move to the room [1,2] which is OK. In the room [1,2] agent
perceives a stench which means there must be a Wumpus nearby. But Wumpus cannot be in the
room [1,1] as by rules of the game, and also not in [2,2] (Agent had not detected any stench
when he was at [2,1]). Therefore agent infers that Wumpus is in the room [1,3], and in current
state, there is no breeze which means in [2,2] there is no Pit and no Wumpus. So it is safe, and
we will mark it OK, and the agent moves further in [2, 2].
Logic:
Logic is defined as proof or validation of a reason. Knowledge base consist of sentence and these
sentences are expressed according to the syntax. Syntax is a formal description of the structure of
program in a given language. The notion of syntax must be in well forms for example “x+y=10”
is a well-formed but “xyz+=” is not in well formed.
A logic can also define the semantic or meaning of sentence. Semantic is a formal description of
the programs in a given language. The semantics of the language defines the truth of each
sentence with respect to each possible world. For example, consider the sentence “x+y=10” is
true in a world where possible value of x is 5 and y is 5, but false where x is 1 and y is1. In
standard logic each sentence must be either true or false only.
When we need to be precise, we will use the term model in place of possible world. If a sentence
α is true in a model, then m is a model of α and M(α) notation is used to mean the set of all
models of α.
Logical reasoning is the process through which any statement is verified. It is relation of logical
entailment (Entailment is the relationship between two sentences where the truth of one (A)
requires the truth of the other (B)) between sentences.
It can be denoted by α |=β and mean that the sentence α entails the sentence β.
The entailment is defined as α |=β if and only if, in every model in which α is true then β is also
true and can be written as α |=β iff M(α) ⊆ M(β)
This analysis can be applied on Wumpus world reasoning example.
Propositional logic in Artificial intelligence
Propositional logic is a simplest form of logic in which knowledge is represented as proposition.
A proposition is a declarative statement which is either true or false. It is a technique of
knowledge representation in logical and mathematical form.
Example:
a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number
Following are some basic facts about propositional logic:
Propositional logic is also called Boolean logic as it works on 0 and 1.
In propositional logic, we use symbolic variables to represent the logic, and we can use
any symbol for a representing a proposition, such A, B, C, P, Q, R, etc.
Propositions can be either true or false, but it cannot be both.
Propositional logic consists of an object, relations or function, and logical connectives.
These connectives are also called logical operators.
The propositions and connectives are the basic elements of the propositional logic.
Connectives can be said as a logical operator which connects two sentences.
A proposition formula which is always true is called tautology, and it is also called a
valid sentence.
A proposition formula which is always false is called Contradiction.
A proposition formula which has both true and false values is called
Statements which are questions, commands, or opinions are not propositions such as
"Where is Rohini", "How are you", "What is your name", are not propositions.
Semantics:
The semantic defines the rules for determining the truth of a sentence with respect to particular
model. In a propositional logic, model fixes the truth value as true or false for every proposition
symbol.
Suppose if the sentence in the knowledge base makes use of the proposition symbols such as
P1,2, P2,2 and P3,1 then model is as follows
M1 = {P1,2=false, P2,2=false, P3,1=false}
With these three symbols there are 23 =8 possible models.
The semantic must specify how to compute the truth value of any sentence and it done
recursively. By using atomic sentences and five connectives all sentences are constructed. So,
it’s necessary to specify how to compute the truth of atomic sentence and sentence which are
formed with each of the five connectives.
The atomic sentences are easy
True is true and False is false in every model.
The truth value of every other proposition symbol must be specified directly in the
model. For example, in the model m1 given earlier, P1;2 is false.
There are five rules for complex sentence, that hold any substances P and Q in any model m:
For any sentence s and any model m, the sentence :s is true in m, if and only if s is false
in m.
¬ P is true iff P is false in m.
P∧ Q is true iff both P and Q are true in m.
P ∨ Q is true iff either P or Q is true in m.
P=>Q is true unless P is true and Q is false in m.
P ⇔ Q is true iff P and Q are both true or both false in m.
For complex sentences:
Truth Table:
In propositional logic, we need to know the truth values of propositions in all possible scenarios.
We can combine all the possible combination with logical connectives, and the representation of
these combinations in a tabular format is called Truth table. Following are the truth table for all
logical connectives:
Precedence of connectives:
Just like arithmetic operators, there is a precedence order for propositional connectors or logical
operators. This order should be followed while evaluating a propositional problem. Following is
the list of the precedence order for operators:
Precedence Operators
First Precedence Parenthesis
Second Precedence Negation
Third Precedence Conjunction(AND)
Fourth Precedence Disjunction(OR)
Fifth Precedence Implication
Six Precedence Biconditional
Logical equivalence is one of the features of propositional logic. Two propositions are said to
be logically equivalent if and only if the columns in the truth table are identical to each other.
Let's take two propositions A and B, so for logical equivalence, we can write it as A⇔B. In
below truth table we can see that column for ¬A∨ B and A→B, are identical hence A is
Equivalent to B
Properties of Operators:
Commutativity:
P∧ Q= Q ∧ P, or
P ∨ Q = Q ∨ P.
Associativity:
(P ∧ Q) ∧ R= P ∧ (Q ∧ R),
(P ∨ Q) ∨ R= P ∨ (Q ∨ R)
Identity element:
P ∧ True = P,
P ∨ True= True.
Distributive:
P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
DE Morgan's Law:
¬ (P ∧ Q) = (¬P) ∨ (¬Q)
¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
Double-negation elimination:
¬ (¬P) = P.
Limitations of Propositional logic:
We cannot represent relations like ALL, some, or none with propositional logic.
Example:
All the girls are intelligent.
Some apples are sweet.
Propositional logic has limited expressive power.
In propositional logic, we cannot describe statements in terms of their properties or
logical relationships.
Example:
Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
Statement-2: "I am sleepy" ==> P
Conclusion: "I go to bed." ==> Q.
Hence, we can say that, if P→ Q is true and P is true then Q will be true.
Proof by Truth table:
It indicates that any sentence of the form α ⇒ β and α are given, then the sentence β can be
inferred For example, if (Wumpus Ahead ∧ Wumpus Alive) => Shoot and (Wumpus Ahead ∧
Wumpus Alive) are given then shoot can be inferred.
2) And-elimination:
It says that from conjunction any conjuncts can be inferred.
For example, from the sentence (Wumpus Ahead ∧ Wumpus Alive) the inference, “Wumpus
Alive” can be drawn.
3) Monotonicity:
it says that the set of entailed sentences can only increases as information is added to the
knowledge base. For any sentence α and β
if KB|= α then KB ∧ β|= α
Monotonicity means inference rules can be applied whenever suitable premises are found in the
knowledge base. the conclusion of the rule must follow regardless of what else is in the
knowledge base.
Proof by Resolution:
Resolution is a theorem proving technique that proceeds by proofs by contradictions ( In logic
and mathematics, proof by contradiction is a form of proof that establishes the truth or the
validity of a proposition, by showing that assuming the proposition to be false leads to a
contradiction.)
Resolution method is basically used for proving the satisfiability of a sentence.
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.
Conjunctive Normal Form: A sentence represented as a conjunction of clauses is said to be
conjunctive normal form or CNF.
The resolution inference rule:
Resolution can resolve two clauses if they contain complementary literals, which are assumed to
be standardized apart so that they share no variables.
Where li and mj are complementary literals. This rule is also called the binary (Unit)
resolution rule because it only resolves exactly two literals.
So, resolution takes two clauses and generate a new clause. The new clause containing all the
literals of the two original clause except two complementary literals. The resulting clause should
contain only one copy of each literal is the technical aspect of resolution rule. The removal of
multiple copies of literals is called factoring.
A resolution Algorithm:
It takes the input as a knowledge base and α and its output is either true or false.
First (KB ∧ ¬ α) is converted into CNF. Then the resolution rule is applied to the resulting
clauses. Each pair in which complementary literals are there is resolved to produce a new clause
and it is added to the new set if it is not there.
The procedure continues until one of the two things happens
first, there are no new clauses that can be added in which KB does not entails α or second two
clauses resolve to yield the empty clause in which case KB entails α.
The resolution algorithm is as shown below.
For better inferences efficient algorithm is needed that based on model checking. Algorithm
approach can be backtracking search or hill-climbing search.
A Complete Backtracking Algorithm:
This algorithm is also called as Davis-Putnam algorithm or DPLL algorithm. It takes as input a
sentence in conjunction normal form, which is set of clauses. It is recursive depth first
enumeration of possible models. The algorithm is improvement over earlier general inferencing
algorithm. There are three improvements over the simple scheme TT-ENTAILS.
There are three improvements over the simple scheme TT-ENTAILS.
1) Early termination: The algorithm finds whether the sentence must be true or false. A clause
is true if any literal is true. A sentence is false if any clause is false, which occurs when each of
its literal is false.
2) Pure symbol heuristic: it is a symbol that always appears with same “sign” in all clauses. If a
sentence has a model, then it has a model with pure symbol assigned so as to make literal true.
3) Unit clause heuristic: it is clause with just one literal. One unit clause can create another unit
clause. The only literal in unit clause is true.
On every iteration, the algorithm picks an unsatisfied clause, and chooses randomly between 2
ways to pick a symbol to flip:
Either a. a “min-conflicts” step that minimizes the number of unsatisfied clauses in the new state;
Or b. a “random walk” step that picks the symbol randomly.
When the algorithm returns a model, the input sentence is indeed satifiable;
When the algorithm returns failure, there are 2 possible causes:
Either a. The sentence is unsatisfiable;
Or b. We need to give the algorithm more time.
AGENT BASED ON PROPOSITIONAL LOGIC
we have learned so far in order to construct agents that operate using propositional logic. We will
look at two kinds of agents: those which use inference algorithms and a knowledge base, like the
generic knowledge-based agent and those which evaluate logical expressions directly in the form
of circuits.
Inference based agent -it requires the separate copies of its knowledge base for every time
step. Inference based agent takes exponential time for inferencing and huge time
requirements for completeness. It is easy to represent in propositional logic language. It
requires large memory as it stores previous percepts or states.
Circuit based agent- it doesn’t require separate copy of its KB for every time step. Circuit
based agent takes linear time for inferencing which is dependent on circuit size. For a
complete circuit CBA will take exponential time with respect to circuit size so it is
incomplete. It is easy to describe and construct knowledge base.
5. and a crown.
The objects in the model may be related in various ways. In the figure, Richard and John are
brothers.
Thus, the brotherhood relation in this model is the set
{ <Richard the Lionheart, King John>, <King John, Richard the Lionheart> }
The “brother” and “on head” relations are binary relations that is, they relate pairs of objects.
The model also contains unary relations, or properties:
the “person” property is true of both Richard and John; and the “crown” property is true only for
the crown.
Prepared by: Chandrashekhar K, Asst. Prof, Dept. of BCA Page 23
CHAPTER - 3
Certain kinds of relationships are considered as functions, in that a given object must be related
to exactly one object.
For example, each person has one left leg, so the model has a unary “left leg” function that
includes the following mappings:
<Richard the Lionheart>→ Richard’s left leg
<King John> → John’s left leg.
Figure: The syntax of first-order logic, specified in Backus–Naur form and Operator precedences
are specified from highest to lowest.
Like proposition symbols, the choice of names is entirely up to the user & every model must
provide the information required to determine if any given sentence is true or false.
In addition to its objects, relations, and functions, each model includes an interpretation that
specifies exactly which objects, relations and functions are referred to by the constant, predicate,
and function symbols. One possible interpretation for our example is as follows:
Interpretation:
Richard refers to Richard the Lionheart and John refers to the evil King John.
Brother refers to the brotherhood relation; OnHead refers to the “on head” relation that holds
between the crown and King John; Person, King, and Crown refer to the sets of objects that are
persons, kings, and crowns.
Variables x, y, z, a, b,....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences:
Atomic sentences are the most basic sentences of first-order logic. These sentences are
formed from a predicate symbol followed by a parenthesis with a sequence of terms.
We can represent atomic sentences as Predicate (term1, term2, ......, term n).
Example: Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
Atomic sentences can also have complex terms as arguments. Such as,
Married(Father (Ravi),Mother (Ajay))
states that Ravi’s father is married to Ajay’s mother.
Complex Sentences:
Complex sentences are made by combining atomic sentences using connectives.
Logical connectives can be used to construct more complex sentences, with the same
syntax and semantics as in propositional calculus. Logical connectives like ¬, ∧, ∨, ⇒,
⇔ can be used.
First-order logic statements can be divided into two parts:
Subject: Subject is the main part of the statement.
Predicate: A predicate can be defined as a relation, which binds two atoms together in a
statement.
Consider the statement: "x is an integer.", it consists of two parts, the first part x is the subject of
the statement and second part "is an integer," is known as a predicate.
Example 2
All man drink coffee.
Let a variable x which refers to a man so all x can be represented as below:
x1 drinks coffee.
x2 drinks coffee.
x3 drinks coffee. .
xn drinks coffee.
We can write it as: ∀x man(x) → drink (x, coffee).
It will be read as: For all x, if x is a man, then x drinks coffee.
2 Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its
scope is true for at least one instance of something.
It is denoted by the logical operator ∃, which resembles as inverted E. When it is used with a
predicate variable then it is called as an existential quantifier.
Note: In Existential quantifier we always use AND or Conjunction symbol (∧).
If x is a variable, then existential quantifier will be ∃x or ∃(x).
And it will be read as:
There exists a 'x.'
For some 'x.'
For at least one 'x.'
Example 1:
King John has a crown on his head, we write
∃ x: Crown(x) ∧ OnHead(x, John)
That is, at least one of the following is true:
i. Richard the Lionheart is a crown ∧ Richard the Lionheart is on John’s head;
ii. King John is a crown ∧ King John is on John’s head;
iii. Richard’s left leg is a crown ∧ Richard’s left leg is on John’s head;
iv. John’s left leg is a crown ∧ John’s left leg is on John’s head;
v. The crown is a crown ∧ the crown is on John’s head.
The fifth assertion is true in the model.
Example 2:
Some boys are intelligent.
∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
Properties of Quantifiers:
In universal quantifier, ∀x∀y is similar to ∀y∀x.
In Existential quantifier, ∃x∃y is similar to ∃y∃x.
∃x∀y is not similar to ∀y∃x.
Nested quantifiers:
More complex sentences can be expressed using multiple quantifiers. The simplest case is where
the quantifiers are of the same type.
For example,
“Brothers are siblings”
can be written as ∀ x ∀ y Brother (x, y) ⇒ Sibling(x, y)
Siblinghood is a symmetric relationship, we can write ∀ x, y Sibling(x, y) ⇔ Sibling(y, x
In other cases, we will have mixtures.
“Everybody read few books” means that for every person, there is some book that person
read:
∀ x ∃ y Read(x, y).
On the other hand, to say “There is someone who is liked by everyone,”
we write ∃ y ∀ x Likes(x, y) The order of quantification is therefore very important. It
becomes clearer if we insert parentheses.
Connections between ∀ and ∃:
The two quantifiers are actually connected with each other, through negation. Asserting that
everyone dislikes XYZ is the same as asserting there does not exist someone who likes them, and
vice versa:
∀ x ¬Likes(x, XYZ ) is equivalent to ¬∃ x Likes(x, XYZ)
We can go one step further: “Everyone likes ice cream” means that there is no one who does not
like ice cream:
∀ x Likes(x, IceCream) is equivalent to ¬∃ x ¬Likes(x, IceCream)
Because ∀ is a conjunction over the universe of objects and ∃ is a disjunction, quantifiers obey
De Morgan’s rules.
The De Morgan rules for quantified and unquantified sentences are as follows:
In this statement, the predicate is failed(x, y), where x= student, and y= subject.
Since there is only one student who failed in Mathematics, so we will use following
representation for this:
∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x,
Mathematics)]
Equality:
Equality symbol can be used to signify that two terms refer to the same object.
For example, Father (John)=Henry says that the object referred to by Father (John) and
the object referred to by Henry are the same.
The equality symbol can be used to state facts about a given function, as we just did for
the Father symbol. It can also be used with negation to insist that two terms are not the
same object. To say that Richard has at least two brothers, we would write
∃ x, y Brother (x,Richard ) ∧ Brother (y,Richard ) ∧¬(x=y)
The sentence ∃ x, y Brother (x,Richard ) ∧ Brother (y,Richard ) does not have the
intended meaning. If x is John & y is also John the sentence will not be valid because
Richard’s both the brothers will not be having the same name as John, therefore x and y
both should be different. For this purpose, ¬(x=y) is added. The notation x ≠ y is
sometimes used as an abbreviation for ¬(x=y).
3. Binary Predicates:
Kinship relations parenthood, brotherhood, marriage, and so on are represented by binary predicates:
Parent, Sibling, Brother, Sister, Child, Daughter, Son, Spouse, Wife, Husband, Grandparent, Grandchild,
Cousin, Aunt, and Uncle.
4. Functions: Mother and Father, because every person has exactly one of each of these (at least according
to nature’s design).
We can go through each function and predicate, writing down what we know in terms of the other
symbols.
Example:
1. One’s mother is one’s female parent:
∀ m, c Mother (c)=m ⇔ Female(m) ∧ Parent(m, c)
2. One’s husband is one’s male spouse:
∀ w, h Husband(h,w) ⇔ Male(h) ∧ Spouse(h,w)
3. Male and female are disjoint categories:
∀ x Male(x) ⇔ ¬Female(x)
4. Parent and child are inverse relations:
∀ p, c Parent(p, c) ⇔ Child (c, p)
5. A grandparent is a parent of one’s parent:
∀ g, c Grandparent (g, c) ⇔ ∃p Parent(g, p) ∧ Parent(p, c)
6. A sibling is another child of one’s parents:
∀ x, y Sibling(x, y) ⇔ x = y ∧ ∃p Parent(p, x) ∧ Parent(p, y)
We could go on for several examples like this. Each of these sentences can be viewed as an
axiom of the kinship domain.
The axioms define the Mother function and the Husband, Male, Parent, Grandparent, and Sibling
predicates.
This is a natural way in which we can build up the representation of a domain. Axioms can also
be “just plain facts,” such as Male(Jim) and Spouse(Jim, Laura) etc. Not all logical sentences
about a domain are axioms.
Some are theorems that is, they are entailed by the axioms.
For example, consider the assertion that siblinghood is symmetric: ∀ x, y Sibling(x, y) ⇔
Sibling(y, x)
As per UI, we can infer any sentence obtained by substituting a ground term for the
variable.
The UI rule state that we can infer any sentence P(c) by substituting a ground term c (a
constant within domain x) from ∀ x P(x) for any object in the universe of discourse.
It can be represented as:
Example: 1
IF "Every person like ice-cream"=> ∀x P(x). So we can infer that
"John likes ice-cream" => P(c)
Example: 2.
Let's take a famous example,
"All kings who are greedy are Evil." So let our knowledge base contains this detail as in the form
of FOL:
∀x king(x) ∧ greedy (x) → Evil (x),
So, from this information, we can infer any of the following statements using Universal
Instantiation:
King(John) ∧ Greedy (John) → Evil (John),
King(Richard) ∧ Greedy (Richard) → Evil (Richard),
King(Father(John)) ∧ Greedy (Father(John)) → Evil (Father(John)),
Here, the substitutions are {x/John }, {x/Richard }, and {x/Father (John )}.
2 Existential Instantiation:
Existential instantiation is also called as Existential Elimination, which is a valid
inference rule in first-order logic.
It can be applied only once to replace the existential sentence.
The new knowledge base is not logically equivalent to old knowledge base, but it will be
satisfiable if old knowledge base was satisfiable.
This rule states that one can infer P(c) from the formula given in the form of ∃x P(x) for a
new constant symbol c.
The restriction with this rule is that c used in the rule must be a new term for which P(c)
is true.
Example:
From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),
So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the
knowledge base.
The above used K is a constant symbol, which is called Skolem constant.
The Existential instantiation is a special case of Skolemization process.
3. Universal Generalization:
Universal generalization is a valid inference rule which states that if premise P(c) is true
for any arbitrary element c in the universe of discourse, then we can have a conclusion as
∀ x P(x).
Example:
Let's say that,
"Ravi got good marks in English."
"Therefore, someone got good marks in English."
Example:
We will use this rule for Kings are evil, so we will find some x such that x is king, and x is
greedy so we can infer that x is evil.
Here let say,
p1' is king(John) p1 is king(x)
p2' is Greedy(y) p2 is Greedy(x)
θ is {x/John, y/John} q is evil(x)
SUBST(θ, q) is Evil(John) .
Unification:
Unification is a process of making two different logical atomic expressions identical by
finding a substitution. Unification depends on the substitution process.
It takes two literals as input and makes them identical using substitution.
Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it
can be expressed as UNIFY(Ψ1, Ψ2)
Lifted inference rules require finding substitutions that make different logical expressions
look identical. This process is called unification and is a key component of all first-order
inference algorithms.
The algorithm takes two sentences and returns a unifier for them if one exists:
UNIFY(p, q)= θ where SUBST(θ, p)= SUBST(θ, q) .
Let us look at some examples of how UNIFY should behave. Suppose we have a query
AskVars (Knows (John , x)): whom does John know?
Answers to this query can be found by finding all sentences in the knowledge base that unify
with Knows(John , x). Here are the results of unification with four different sentences that might
be in the knowledge base:
UNIFY(Knows (John, x), Knows (John, Jane)) = {x/Jane }
UNIFY(Knows (John, x), Knows (y, Bill )) = {x/Bill, y/John }
UNIFY(Knows (John, x), Knows (y, Mother (y))) = {y/John , x/Mother (John )}
UNIFY(Knows (John, x), Knows (x, Elizabeth )) = fail .
The last unification fails because x cannot take on the values John and Elizabeth at the same
time. Now, remember that Knows(x, Elizabeth) means “Everyone knows Elizabeth,” so we
should be able to infer that John knows Elizabeth.
The problem arises only because the two sentences happen to use the same variable name, x. The
problem can be avoided by standardizing apart one of the two sentences being unified, which
means renaming its variables to avoid name clashes.
For example, we can rename x in Knows(x, Elizabeth) to x17 (a new variable name) without
changing its meaning.
Now the unification will work:
UNIFY(Knows(John, x), Knows(x17, Elizabeth)) = {x/Elizabeth, x17/John} .
There is one more complication:
we said that UNIFY should return a substitution that makes the two arguments look the same.
But there could be more than one such unifier.
For example,
UNIFY(Knows(John, x), Knows(y, z)) could return {y/John, x/z} or {y/John, x/John, z/John}.
The first unifier gives Knows(John, z) as the result of unification, whereas the second gives
Knows(John, John).
The second result could be obtained from the first by an additional substitution {z/John}; we say
that the first unifier is more general than the second, because it places fewer restrictions on the
values of the variables.
It turns out that, for every unifiable pair of expressions, there is a single most general unifier (or
MGU) that is unique up to renaming and substitution of variables. (For example, {x/John} and
{y/John} are considered equivalent, as are {x/John, y/John} and {x/John, y/x}.)
In this case it is {y/John, x/z}.
A. 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.
Example:
"As per the law, it is a crime for an American to sell weapons to hostile nations. Country A, an
enemy of America, has some missiles, and all the missiles were sold to it by Robert, who is an
American citizen."
Prove that "Robert is criminal."
To solve the above problem, first, we will convert all the above facts into first-order definite
clauses, and then we will use a forward-chaining algorithm to reach the goal.
Facts Conversion into FOL:
It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are
variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
Country A has some missiles. ?p Owns(A, p) ∧ Missile(p). It can be written in two
definite clauses by using Existential Instantiation, introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
All of the missiles were sold to country A by Robert.
?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
Country A is an enemy of America.
Enemy (A, America) .........(7)
Robert is American
American(Robert). ..........(8)
Forward chaining proof:
Step-1:
In the first step we will start with the known facts and will choose the sentences which do not
have implications,
such as: American(Robert), Enemy(A, America), Owns(A, T1), and Missile(T1). All these facts
will be represented as below.
Step-2: At the second step, we will see those facts which infer from available facts and with
satisfied premises.
Rule-(1) does not satisfy premises, so it will not be added in the first iteration.
Rule-(2) and (3) are already added.
Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added, which infers
from the conjunction of Rule (2) and (3).
Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and which infers from
Rule-(7).
Step-3:
At step-3, as we can check Rule-(1) is satisfied with the substitution {p/Robert, q/T1, r/A}, so we
can add Criminal(Robert) which infers all the available facts. And hence we reached our goal
statement.
with the goal and works backward, chaining through rules to find known facts that support the
goal.
Example:
In backward-chaining, we will use the same above example, and will rewrite all the rules.
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
Owns(A, T1) ........(2)
Missile(T1)
?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
Missile(p) → Weapons (p) .......(5)
Enemy(p, America) →Hostile(p) ........(6)
Enemy (A, America) .........(7)
American(Robert). ..........(8)
Backward-Chaining proof:
In Backward chaining, we will start with our goal predicate, which is Criminal(Robert), and then
infer further rules.
Step-1:
At the first step, we will take the goal fact. And from the goal fact, we will infer other facts, and
at last, we will prove those facts true. So our goal fact is "Robert is Criminal," so following is the
predicate of it.
Step-2:
At the second step, we will infer other facts form goal fact which satisfies the rules. So as we can
see in Rule-1, the goal predicate Criminal (Robert) is present with substitution {Robert/P}. So
we will add all the conjunctive facts below the first level and will replace p with Robert.
Here we can see American (Robert) is a fact, so it is proved here.
Step-3:t At step-3, we will extract further fact Missile(q) which infer from Weapon(q), as it
satisfies Rule-(5). Weapon (q) is also true with the substitution of a constant T1 at q.
Step-4:
At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert, T1, r) which
satisfies the Rule- 4, with the substitution of A in place of r. So these two statements are proved
here.
Step-5:
At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which satisfies Rule- 6.
And hence all the statements are proved true using backward chaining.