Ai Unit 4
Ai Unit 4
AL3391-ARTIFICIAL INTELLIGENCE
UNIT IV
LOGICAL REASONING
SYLLABUS
INTRODUCTION
Reasoning:
The reasoning is the mental process of deriving logical conclusion and making
predictions from available knowledge, facts, and beliefs. Or we can say,
"Reasoning is a way to infer facts from existing data."
It is a general process of thinking rationally, to find valid conclusions.
In artificial intelligence, the reasoning is essential so that the machine can also
think rationally as a human brain, and can perform like a human.
When a system is required to do something, that it has not been explicitly told how
to do,, it must figure out what it needs to know from what it already knows.
Fact 1 : Robins are Birds
Fact 2 : All birds have wings
Question : Do Robins have wings?
Hence Reasoning system, must find out, what it needs to know from what it
already knows.
Logic is a language of reasoning. It is a collection of rules called logic arguments,
we use when doing logic reasoning.
Logical Reasoning is a process of drawing conclusions from premises using rule of
inference.
o An intelligent agent needs knowledge about the real world for taking decisions
and reasoning to act efficiently.
o 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.
o Knowledge-based agents are composed of two main parts:
o Knowledge-base and
o Inference system.
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.
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
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 behavior.
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 implements his knowledge and logic
so that he can reach to the destination.
1. Declarative approach:
We can create a knowledge-based agent by initializing with an empty
knowledge base and telling the agent all the sentences with which we want to
start with.
This approach is called Declarative approach.
2. Procedural approach:
In the procedural approach, we directly encode desired behavior as a program
code.
Which means we just need to write a program that already encodes the desired
behavior or agent.
However, in the real world, a successful agent can be built by combining both
declarative and procedural approaches, and declarative knowledge can often be
compiled into more efficient procedural code.
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
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.
Atomic Proposition:
Atomic propositions are the simple propositions.
It consists of a single proposition symbol.
These are the sentences which must be either true or false.
Example:
a) 2+2 is 4, it is an atomic proposition as it is a true fact.
b) "The Sun is cold" is also a proposition as it is a false fact.
Compound proposition:
• Compound propositions are constructed by combining simpler or atomic
propositions, using parenthesis and logical connectives.
Example:
a) "It is raining today, and street is wet."
b) "Ankit is a doctor, and his clinic is in Mumbai."
Logical Connectives:
• Logical connectives are used to connect two simpler propositions or representing a
sentence logically.
• We can create compound propositions with the help of logical connectives.
• There are mainly five connectives, which are given as follows:
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:
Logical equivalence:
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:
o P∧ Q= Q ∧ P, or
o P ∨ Q = Q ∨ P.
• Associativity:
o (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
o (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
• Identity element:
o P ∧ True = P,
o P ∨ True= True.
• Distributive:
o P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
o P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
• DE Morgan's Law:
o ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
o ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
• Double-negation elimination:
o ¬ (¬P) = P.
First-Order 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.
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.
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:
• Objects: A, B, people, numbers, colors, wars, theories, squares, pits,
wumpus, ......
The preceding section illustrated the use of first-order logic to represent knowledge in
three simple domains. This section describes the general process of knowledge-base
construction— a process called knowledge engineering. A knowledge engineer is
someone who investigates a particular domain, learns what concepts are important in
that domain, and creates a formal representation of the objects and relations in the
domain. We illustrate the knowledge engineering process in an electronic circuit
domain that should already be fairly familiar, so that we can concentrate on the
representational issues involved. The approach we take is suitable for developing
Substitution:
Substitution is a fundamental operation performed on terms and formulas.
It occurs in all inference systems in first-order logic.
The substitution is complex in the presence of quantifiers in FOL.
If we write F[a/x], so it refers to substitute a constant "a" in place of variable "x".
Equality:
First-Order logic does not only use predicate and terms for making atomic
sentences but also uses another way, which is equality in FOL.
For this, we can use equality symbols which specify that the two terms refer to the
same object.
1. 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).
2. Universal Instantiation:
• Universal instantiation is also called as universal elimination or UI is a valid
inference rule. It can be applied multiple times to add new sentences.
• The new KB is logically equivalent to the previous KB.
• 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.
3. 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 KB is not logically equivalent to old KB, but it will be satisfiable if
old KB 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.
4. Existential introduction
• An existential introduction is also known as an existential generalization,
which is a valid inference rule in first-order logic.
• This rule states that if there is some element c in the universe of discourse
which has a property P, then we can infer that there exists something in the
universe which has the property P.
Forward chaining
Forward chaining is a method of reasoning in artificial intelligence in which inference
rules are applied to existing data to extract additional data until an endpoint (goal) is
achieved.
In this type of chaining, the inference engine starts by evaluating existing facts,
derivations, and conditions before deducing new information. An endpoint (goal) is
achieved through the manipulation of knowledge that exists in the knowledge base.
The mass spectrum of the sample is then used to establish the arrangement of the
atoms.
We can summarize these steps as follows.
• The chemical formula is determined ( the number of atoms in every
molecule).
• The spectrum machine is used to form mass spectrums of the sample.
• The isomer and structure of the chemical are identified.
In this example, the identification of the chemical structure is the endpoint.
In the DENDRAL expert system, a generate and test technique is employed.
There are two elements in the generator:
• a synthesizer and
• structural enumerator.
The synthesizer plays the role of producing the mass spectrum.
The structural enumerator identifies the structure of substances and prevents
redundancy in the generator.
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 conclusions efficiently.
Backward chaining
Backward chaining is a concept in artificial intelligence that involves backtracking
from the endpoint or goal to steps that led to the endpoint.
This type of chaining starts from the goal and moves backward to comprehend the
steps that were taken to attain this goal.
The backtracking process can also enable a person establish logical steps that can
be used to find other important solutions.
B
A->B
A
B is the goal or endpoint, that is used as the starting point for backward tracking.
A is the initial state. A->B is a fact that must be asserted to arrive at the endpoint
B.
A practical example of backward chaining will go as follows:
Tom is sweating (B).
If a person is running, he will sweat (A->B).
Tom is running (A).
The MYCIN expert system is a real life example of how backward chaining works.
This is a system that’s used in the diagnosis of bacterial infections.
It also recommends suitable treatments for this type of infections.
The knowledge base of a MYCIN comprises many antecedent-consequent rules,
that enable the system to recognize various causes of (bacterial) infections.
This system is suitable for patients who have a bacterial infection, but don’t know
the specific infection.
The system will gather information relating to symptoms and history of the patient.
It will then analyze this information to establish the bacterial infection.
A suitable sequence can be as follows:
• The patient has a bacterial infection.
• The patient is vomiting.
• He/she is also experiencing diarrhea and severe stomach upset.
• Therefore, the patient has typhoid (salmonella bacterial infection).
The MYCIN expert system uses the information collected from the patient to
recommend suitable treatment.
The recommended treatment corresponds to the identified bacterial infection. In
the case above, the system may recommend the use of ciprofloxacin.
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.
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.
Thus,
Backward and forward chaining are important methods of reasoning in artificial
intelligence.
These concepts differ mainly in terms of approach, strategy, technique, speed, and
operational direction.
Forward chaining is important to developers that want to use data-driven
algorithms to develop effective computer-based systems.
Backward chaining is important to developers that are interested in using goal-
driven algorithms to design effective solutions in complex database systems.
Topic: 10 : RESOLUTION
Clause: Disjunction of literals (an atomic sentence) is called a clause. It is also known
as a unit clause.
a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
d. eats (Anil, Peanuts) Λ alive(Anil)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
f. ∀x¬ [¬ killed(x) ] V alive(x)
g. ∀ x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).
Now in this step, we will solve the problem by resolution tree using substitution. For
the above problem, it will be given as follows:
Hence the negation of the conclusion has been proved as a complete contradiction
with the given set of statements.