AI unit 4
AI unit 4
AI unit 4
LOGICAL REASONING
Knowledge-based agents
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.
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:
o Forward chaining
o Backward chaining
1. TELL: This operation tells the knowledge base what it perceives from the
environment.
2. ASK: This operation asks the knowledge base what action it should
perform.
3. Perform: It performs the selected action.
7. t=t+1
8. return action
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:
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 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:
3. Implementation level:
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. 2. Procedural approach: In the procedural approach, we directly encode
Propositional logic
Propositional logic (PL) is the simplest form of logic where all the statements are
made by propositions. A proposition is a declarative statement which is either
true or false. It is a technique of knowledge representation in logical and
mathematical form.
Example:
1. a) It is Sunday.
2. b) The Sun rises from West (False proposition)
3. c) 3+3= 7(False proposition)
4. d) 5 is a prime number.
The syntax of propositional logic defines the allowable sentences for the
knowledge representation. There are two types of Propositions:
a. Atomic Propositions
b. Compound propositions
Example:
Example:
Logical Connectives:
Truth Table:
Precedence of connectives:
Precedence Operators
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:
o Commutativity:
o P∧ Q= Q ∧ P, or
o P ∨ Q = Q ∨ P.
o Associativity:
o (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
o (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
o Identity element:
o P ∧ True = P,
o P ∨ True= True.
o Distributive:
o P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
o P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
o DE Morgan's Law:
o ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
o ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
o Double-negation elimination:
o ¬ (¬P) = P.
Wumpus world:
The Wumpus can be shot by the agent, but the agent has a single arrow. In
the Wumpus world, there are some Pits rooms which are bottomless, and
if agent falls in Pits, then he will be stuck there forever.
The exciting thing with this cave is that in one room there is a possibility
of finding a heap of gold. So the agent goal is to find the gold and climb
out the cave without fallen into Pits or eaten by Wumpus.
The agent will get a reward if he comes out with gold, and he will get a
penalty if eaten by Wumpus or falls in the pit.
a. The rooms adjacent to the Wumpus room are smelly, so that it would have
some stench.
b. The room adjacent to PITs has a breeze, so if the agent reaches near to PIT,
then he will perceive the breeze.
c. There will be glitter in the room if and only if the room has gold.
d. 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:
o +1000 reward points if the agent comes out of the cave with the gold.
o -1000 points penalty for being eaten by the Wumpus or falling into the pit.
o -1 for each action, and -10 for using an arrow.
o The game ends if either agent dies or came out of the cave.
Environment:
Actuators:
o Left turn,
o Right turn
o Move forward
o Grab
o Release
o Shoot.
Sensors:
o The agent will perceive the stench if he is in the room adjacent to the
Wumpus. (Not diagonally).
o The agent will perceive breeze if he is in the room directly adjacent to the
Pit.
o The agent will perceive the glitter in the room where the gold is present.
o The agent will perceive the bump if he walks into a wall.
o When the Wumpus is shot, it emits a horrible scream which can be
perceived anywhere in the cave.
o These percepts can be represented as five element list, in which we will
have different indicators for each sensor.
o 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].
Now we will explore the Wumpus world and will determine how the agent will
find its goal by applying logical reasoning.
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.
Agent's second Step:
Now agent needs to move forward, so it will either move to [1, 2], or [2,1]. Let's
suppose agent moves to the room [2, 1], at this room agent perceives some breeze
which means Pit is around this room. The pit can be in [3, 1], or [2,2], so we will
add symbol P? to say that, is this Pit room?
Now agent will stop and think and will not make any harmful move. The agent
will go back to the [1, 1] room. The room [1,1], and [2,1] are visited by the agent,
so we will use symbol V to represent the visited squares.
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].
Agent's fourth step:
At room [2,2], here no stench and no breezes present so let's suppose agent
decides to move to [2,3]. At room [2,3] agent perceives glitter, so it should grab
the gold and climb out of the cave.
in some cases, this can be less work than model-checking (i.e. generating a truth
table) or even SAT solving
plus, logical rules of inference are at the level of logical reasoning that humans
consciously strive to do
the general idea is that sentence A is what the agent knows, and sentence B is
something that the agent can infer from what it knows
sentence A might be very big, i.e. the entire “brain” of an agent encoded in logic
A entails B if, and only if, A => B (A implies B) is a tautology (i.e. valid for all
assignments of values to its variables)
so we can answer the question “Does A entail B?” by showing that the sentence
A => B is a tautology
recall that a sentence is unsatisfiable if no assignment of values to its variables
makes it true
this means you can use a SAT solver to figure out entailment!
Rules of Inference
recall that there are various rules of inference that can be used to create proofs,
i.e. chains of correct inferences
A, A => B
this rule says that if you are given a sentence A, and a sentence A => B, you may
infer B
A&B
----- and-elimination
A&B
-----
these two rules encode the (obvious!) fact that if the sentence A & B is true, then
A is true, and also B is true
A <==> B
---------------
there are many inference rules, and choosing a reasonable set of rules for a
theorem-prover turns out to be important
if there are multiple inference rules to choose from, then we need knowledge (i.e.
heuristics) to help decide which rule to use
or we could rely on backtracking, i.e. just pick a rule at random, apply it, and keep
going until it “seems” like a proof is not being reached
plus, how do we know that the rules of inference we are using are complete, i.e.
if a proof exists, how do we know our set of inference rules will find it?
e.g. suppose the two and-elimination rules were our only rules of inference; is
this enough to prove any entailment in propositional logic?
no!
for example, (P | P) -> P is clearly true, but and-elimination doesn’t apply to this
sentence
Proof by Resolution
it turns out that only one particular inference rule is needed to prove any logical
entailment (that can be proved): the resolution rule
in a 2-variable form, the resolution inference rule is this (| here means “or”):
A | B, !B
----------
resolution
A | !B, B
----------
in English, the first rules says that if A or B is true, and B is not true, then A must
be true; the second rule says the same thing, but B and !B are swapped
note that A | !B is logically equivalent to B -> A, and so the resolution rules can
be translated to this:
!B -> A, !B
B -> A, B
notice that both sentence above and below the inference line are CNF clauses
--------------
here, L_i is a literal that has the opposite sign of a literal in Clause_1
Clause_2 is the same as Clause_1, but with the literal that is the opposite of L_i
removed
e.g.:
-----------------
!B | !C
A | !B
Clause_1 Clause_2
Clause_3
here, we assume that some literal L appears in Clause_1, and the complement of
L appears in Clause_2
Clause_3 contains all the literals (or-ed together) from both Clause_1 and
Clause_2, except for L and its opposite — those are not in Clause_3
e.g.:
----------------------------
!B | !C | D
what is surprising is that full resolution is complete: it can be used to proved any
entailment (assuming the entailment can be proven)
clauses with complementary literals are chosen and resolved (i.e. the resolution
rule is applied to them to remove the literal and its complement) and added as a
new clause in the knowledge base
no new clause can be added, which means that A does not entail B
two clauses resolve to yield the empty clause, which means that A entails B
the empty clause means there is a contradiction, i.e. if P and !P are clauses then
we can apply resolution to them to get the “empty clause”
clearly, if both P and !P are in the same knowledge base, then it is inconsistent
since P & !P is false for all values of P
Example. KB = {P->Q, Q->R}
!P | Q
!Q | R
!R
next we pick pairs of clauses and resolve them (i.e. apply the resolution inference
rule) if we can; we add any clauses produced by this to the collection of clauses:
!P | Q
!Q | R
!R
this is a proof of entailment, and the various resolutions are the steps of the proof
the exact order in which clauses are resolved could result in shorter or longer
proofs, and in practice you usually want short proofs, and so heuristic would be
needed to help make decisions
a fundamental difficulty with SAT solvers and algorithms like resolution is that,
for propositional logic, they have exponential running time
SAT solvers are fast, but in the worst case they can still take an exponential
amount of time to finish
so, some AI researchers have explored the possibility of using a logic that is less
expressive than propositional logic, but for which entilaments can be computed
more efficiently
for example, a definite clause is a clause in which exactly 1 literal is positive, e.g.:
A | !B | !C definite clause
!A | !W | E | !S definite clause
P definite clause
a horn clause is a clause with 0 or 1 positive literals (i.e. at most one positive
literal), e.g.:
A | !B | !C horn clause
A horn clause
note that every definite clause is a horn clause, but some horn clauses are not
definite clauses
entailment of horn clauses can be decided in time linear with respect to the size
of the knowledge base – much more efficient than full resolution
reasoning with horn clauses can be done in a straightforward way that humans
find easier to follow than resolution
definite clauses can be written in an appealing form using implication, i.e. the
definite clause A | !B | !C can be written (B & C) -> A
more generally, the definite clause A | !B1 | !B2 | … | !Bn can be written as (B1
& B2 & … & Bn) -> A
for some real-world problems, this is can be a natural way to encode knowledge,
i.e. A is true if B1, B2, …, and Bn are all true
horn clauses are used extensively in the logic programming language Prolog
however, the problem with Horn clauses is that not all problems can be
represented with them: they’re less expressive than propositional logic
this seems to be a fundamental trade-off: the more expressive the logic, the less
efficient entailment algorithms are
The first algorithm we consider is often called the Davis–Putnam algorithm, after
the seminal paper by Martin Davis and Hilary Putnam (1960). The algorithm is
in fact the version described by Davis, Logemann, and Loveland (1962), so we
will call it DPLL after the initials of all four authors. DPLL takes as input a
sentence in conjunctive normal form—a set of clauses. Like BACKTRACKING-
SEARCH and TT-ENTAILS?, it is essentially a recursive, depth-first
enumeration of possible models. It embodies three improvements over the simple
scheme of TT-ENTAILS?:
• Early termination: The algorithm detects whether the sentence must be true or
false, even with a partially completed model. A clause is true if any literal is true,
even if the other literals do not yet have truth values; hence, the sentence as a
whole could be judged true even before the model is complete. For example, the
sentence (A ∨ B) ∧ (A ∨ C) is true if A is true, regardless of the values of B and
C. Similarly, a sentence is false if any clause is false, which occurs when each of
its literals is false. Again, this can occur long before the model is complete. Early
termination avoids examination of entire subtrees in the search space.
• Pure symbol heuristic: A pure symbol is a symbol that always appears with the
same “sign” in all clauses. For example, in the three clauses (A ∨ ¬B), (¬B ∨
¬C), and (C ∨ A), the symbol A is pure because only the positive literal appears,
B is pure because only the negative literal appears, and C is impure. It is easy to
see that if a sentence has a model, then it has a model with the pure symbols
assigned so as to make their literals true, because doing so can never make a
clause false. Note that, in determining the purity of a symbol, the algorithm can
ignore clauses that are already known to be true in the model constructed so far.
For example, if the model contains B = false, then the clause (¬B ∨ ¬C) is already
true, and in the remaining clauses C appears only as a positive literal; therefore C
becomes pure.
• Unit clause heuristic: A unit clause was defined earlier as a clause with just one
literal. In the context of DPLL, it also means clauses in which all literals but one
are already assigned false by the model. For example, if the model contains B =
true, then (¬B ∨ ¬C) simplifies to ¬C, which is a unit clause. Obviously, for this
clause to be true, C must be set to false. The unit clause heuristic assigns all such
symbols before branching on the remainder. One important consequence of the
heuristic is that any attempt to prove (by refutation) a literal that is already in the
knowledge base will succeed immediately (Exercise 7.23). Notice also that
assigning one unit clause can create another unit clause—for example, when C is
set to false, (C ∨ A) becomes a unit clause, causing true to be assigned to A. This
“cascade” of forced assignments is called unit propagation. It resembles the
process of forward chaining with definite clauses, and indeed, if the CNF
expression contains only definite clauses then DPLL essentially replicates
forward chaining. (See Exercise 7.24.)
The DPLL algorithm is shown in Figure 7.17, which gives the the essential
skeleton of the search process.
What Figure 7.17 does not show are the tricks that enable SAT solvers to scale
up to large problems. It is interesting that most of these tricks are in fact rather
general, and we have seen them before in other guises:
1. Component analysis (as seen with Tasmania in CSPs): As DPLL assigns truth
values to variables, the set of clauses may become separated into disjoint subsets,
called components, that share no unassigned variables. Given an efficient way to
detect when this occurs, a solver can gain considerable speed by working on each
component separately.
2. 2. Variable and value ordering (as seen in Section 6.3.1 for CSPs): Our simple
implementation of DPLL uses an arbitrary variable ordering and always tries the
value true before false. The degree heuristic (see page 216) suggests choosing the
variable that appears most frequently over all remaining clauses.
3. Intelligent backtracking (as seen in Section 6.3 for CSPs): Many problems that
cannot be solved in hours of run time with chronological backtracking can be
solved in seconds with intelligent backtracking that backs up all the way to the
relevant point of conflict. All SAT solvers that do intelligent backtracking use
some form of conflict clause learning to record conflicts so that they won’t be
repeated later in the search. Usually a limited-size set of conflicts is kept, and
rarely used ones are dropped.
4. Random restarts (as seen on page 124 for hill-climbing): Sometimes a run
appears not to be making progress. In this case, we can start over from the top of
the search tree, rather than trying to continue. After restarting, different random
choices (in variable and value selection) are made. Clauses that are learned in the
first run are retained after the restart and can help prune the search space.
Restarting does not guarantee that a solution will be found faster, but it does
reduce the variance on the time to solution.
5. Clever indexing (as seen in many algorithms): The speedup methods used in
DPLL itself, as well as the tricks used in modern solvers, require fast indexing of
such things as “the set of clauses in which variable Xi appears as a positive
literal.” This task is complicated by the fact that the algorithms are interested only
in the clauses that have not yet been satisfied by previous assignments to
variables, so the indexing structures must be updated dynamically as the
computation proceeds.
With these enhancements, modern solvers can handle problems with tens of
millions of variables. They have revolutionized areas such as hardware
verification and security protocol verification, which previously required
laborious, hand-guided proofs.
We have seen several local search algorithms so far in this book, including HILL-
CLIMBING (page 122) and SIMULATED-ANNEALING (page 126). These
algorithms can be applied directly to satisfiability problems, provided that we
choose the right evaluation function. Because the goal is to find an assignment
that satisfies every clause, an evaluation function that counts the number of
unsatisfied clauses will do the job. In fact, this is exactly the measure used by the
MIN-CONFLICTS algorithm for CSPs (page 221). All these algorithms take
steps in the space of complete assignments, flipping the truth value of one symbol
at a time. The space usually contains many local minima, to escape from which
various forms of randomness are required. In recent years, there has been a great
deal of experimentation to find a good balance between greediness and
randomness.
One of the simplest and most effective algorithms to emerge from all this work is
called WALKSAT (Figure 7.18). On every iteration, the algorithm picks an
unsatisfied clause and picks a symbol in the clause to flip. It chooses randomly
between two ways to pick which symbol to flip: (1) a “min-conflicts” step that
minimizes the number of unsatisfied clauses in the new state and (2) a “random
walk” step that picks the symbol randomly.
When WALKSAT returns a model, the input sentence is indeed satisfiable, but
when it returns failure, there are two possible causes: either the sentence is
unsatisfiable or we need to give the algorithm more time. If we set max flips = ∞
and p > 0, WALKSAT will eventually return a model (if one exists), because the
random-walk steps will eventually hit upon the solution. Alas, if max flips is
infinity and the sentence is unsatisfiable, then the algorithm never terminates!
For this reason, WALKSAT is most useful when we expect a solution to exist—
for example, the problems discussed in Chapters 3 and 6 usually have solutions.
On the other hand, WALKSAT cannot always detect unsatisfiability, which is
required for deciding entailment. For example, an agent cannot reliably use
WALKSAT to prove that a square is safe in the wumpus world. Instead, it can
say, “I thought about it for an hour and couldn’t come up with a possible world
in which the square isn’t safe.” This may be a good empirical indicator that the
square is safe, but it’s certainly not a proof.
Sixteen of the 32 possible assignments are models of this sentence, so, on average,
it would take just two random guesses to find a model. This is an easy
satisfiability problem, as are most such underconstrained problems. On the other
hand, an overconstrained problem has many clauses relative to the number of
variables and is likely to have no solutions.
Now that we have a good idea where the satisfiable and unsatisfiable problems
are, the next question is, where are the hard problems? It turns out that they are
also often at the threshold value. Figure 7.19(b) shows that 50-symbol problems
at the threshold value of 4.3 are about 20 times more difficult to solve than those
at a ratio of 3.3. The underconstrained problems are easiest to solve (because it is
so easy to guess a solution); the overconstrained problems are not as easy as the
underconstrained, but still are much easier than the ones right at the threshold.
Introduction
Throughout the last few decades, the field of artificial intelligence (AI) has
experienced significant advancement. Scientists and researchers are developing a
variety of AI models to mimic human intelligence as a result of advances in
technology and computer science. The agent based on propositional logic is one
of the foundational AI techniques. This article will examine the definition,
operation, and numerous uses of a propositional logic-based agent.
An AI agent that utilises propositional logic to express its knowledge and make
decisions is known as a propositional logic-based agent. A straightforward form
of agent, it decides what to do depending on what it knows about the outside
world. A knowledge base, which is made up of a collection of logical phrases or
sentences, serves as a representation of the propositional logic-based agent's
knowledge.
The agent's knowledge is empty, however as it observes the outside world, it fills
it with fresh data. To decide what actions to do in response to the environment,
the agent uses its knowledge base. Depending on the logical inference it makes
on its knowledge base, the agent takes judgements.
In the field of AI, propositional logic-based agents have several uses. Expert
system applications are one of the most popular uses. Expert systems are artificial
intelligence programs created to address difficulties in a particular field. They
represent their subject knowledge in a knowledge base, and they draw new
information from the knowledge base using a reasoning engine.
Knowledge Representation
Logical Inference
Decision Making
Observing the environment and updating the agent's knowledge base is the
process of perception. Using logical inference to extract new information from
the knowledge base is the process of reasoning. Action is the process of choosing
a course of action based on the knowledge that has been obtained and the agent's
goals.
Limitations
Although agents based on propositional logic offer numerous benefits, they also
have certain drawbacks. One of the drawbacks is that they lack expressiveness
and are unable to depict intricate interactions between propositions. They are
unable to depict, for instance, causal or temporal links between assertions.
Another drawback is that propositional logic-based agents are unable to deal with
uncertainty or inadequate data. As a result, they are unable to handle
circumstances in which there is a lack of information or uncertainty regarding the
environment.
Fuzzy logic, Bayesian networks, and neural networks, among other forms of AI
models, have been developed to get around these restrictions. These models offer
a more powerful and expressive means of describing knowledge and making
judgements.
Conclusion
First-order logic
Variables x, y, z, a, b,....
Connectives ∧ , ∨ , ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences:
o 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.
o We can represent atomic sentences as Predicate (term1, term2, ......, term
n).
Complex Sentences:
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.
Universal Quantifier:
o For all x
o For each x
o For every x.
Example:
Let a variable x which refers to a cat so all x can be represented in UOD as below:
∀ x man(x) → drink (x, coffee).
It will be read as: There are all x where x is a man who drink coffee.
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.
∃ x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
Points to remember:
Properties of Quantifiers:
The quantifiers interact with variables which appear in a suitable way. There are
two types of variables in First-order logic which are given below:
What to Represent:
o Object: All the facts about objects in our world domain. E.g., Guitars
contains strings, trumpets are brass instruments.
o Events: Events are the actions which occur in our world.
o Performance: It describe behavior which involves knowledge about how
to do things.
o Meta-knowledge: It is knowledge about what we know.
o Facts: Facts are the truths about the real world and what we represent.
o Knowledge-Base: The central component of the knowledge-based agents
is the knowledge base. It is represented as KB. The Knowledgebase is a
group of the Sentences (Here, sentences are used as a technical term and
not identical with the English language).
Types of knowledge
1. Declarative Knowledge:
2. Procedural Knowledge
4. Heuristic knowledge:
5. Structural knowledge:
AI knowledge cycle:
o Perception
o Learning
o Knowledge Representation and Reasoning
o Planning
o Execution
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.
1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules
1. Logical Representation
Logical representation is a language with some concrete rules which deals with
propositions and has no ambiguity in representation. Logical representation
means drawing a conclusion based on various conditions. This representation lays
down some important communication rules. It consists of precisely defined
syntax and semantics which supports the sound inference. Each sentence can be
translated into logics using syntax and semantics.
Syntax:
o Syntaxes are the rules which decide how we can construct legal sentences
in the logic.
o It determines which symbol we can use in knowledge representation.
o How to write those symbols.
Semantics:
o Semantics are the rules by which we can interpret the sentence in the logic.
o Semantic also involves assigning a meaning to each sentence.
a. Propositional Logics
b. Predicate logics
Example: Following are some statements which we need to represent in the form
of nodes and arcs.
Statements:
a. Jerry is a cat.
b. Jerry is a mammal
c. Jerry is owned by Priya.
d. Jerry is brown colored.
e. All Mammals are animal.
Drawbacks in Semantic representation:
3. Frame Representation
Facets: The various aspects of a slot is known as Facets. Facets are features of
frames which enable us to put constraints on the frames. Example: IF-NEEDED
facts are called when data of any particular slot is needed. A frame may consist
of any number of slots, and a slot may include any number of facets and facets
may have any number of values. A frame is also known as slot-filter knowledge
representation in artificial intelligence.
Frames are derived from semantic networks and later evolved into our modern-
day classes and objects. A single frame is not much useful. Frames system consist
of a collection of frames which are connected. In the frame, knowledge about an
object or event can be stored together in the knowledge base. The frame is a type
of technology which is widely used in various applications including Natural
language processing and machine visions.
Example: 1
Slots Filters
Year 1996
Page 1152
4. Production Rules
Production rules system consist of (condition, action) pairs which mean, "If
condition then action". It has mainly three parts:
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. And the action
part carries out the associated problem-solving steps. This complete process is
called a recognize-act cycle.
The working memory contains the description of the current state of problems-
solving and rule can write knowledge to the working memory. This knowledge
match and may fire other rules.
If there is a new situation (state) generates, then multiple production rules will be
fired together, this is called conflict set. In this situation, the agent needs to select
a rule from these sets, and it is called a conflict resolution.
Example:
o IF (at bus stop AND bus arrives) THEN action (get into the bus)
o IF (on the bus AND paid AND empty seat) THEN action (sit down).
o IF (on bus AND unpaid) THEN action (pay charges).
o IF (bus arrives at destination) THEN action (get down from the bus).
Advantages of Production rule:
1. Production rule system does not exhibit any learning capabilities, as it does
not store the result of the problem for the future uses.
2. During the execution of the program, many rules may be active hence rule-
based production systems are inefficient.
Substitution:
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.
o Universal Generalization
o Universal Instantiation
o Existential Instantiation
o Existential introduction
1. Universal Generalization:
Example: Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All
bytes contain 8 bits.", it will also be true.
2. Universal Instantiation:
o 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.
o The new KB is logically equivalent to the previous KB.
o As per UI, we can infer any sentence obtained by substituting a ground
term for the variable.
o 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.
Example:1.
Example: 2.
"All kings who are greedy are Evil." So let our knowledge base contains this
detail as in the form of FOL:
So from this information, we can infer any of the following statements using
Universal Instantiation:
Example:
4. Existential introduction
For the inference process in FOL, we have a single inference rule which is called
Generalized Modus Ponens. It is lifted version of Modus ponens.
Generalized Modus Ponens can be summarized as, " P implies Q and P is asserted
to be true, therefore Q must be True."
According to Modus Ponens, for atomic sentences pi, pi', q. Where there is a
substitution θ such that SUBST (θ, pi',) = SUBST(θ, pi), it can be represented as:
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.
Forward chaining
In artificial intelligence, forward and backward chaining is one of the important
topics, but before understanding forward and backward chaining lets first
understand that from where these two terms came.
Inference engine:
a. Forward chaining
b. Backward chaining
Horn clause and definite clause are the forms of sentences, which enables
knowledge base to use a more restricted and efficient inference algorithm.
Logical inference algorithms use forward and backward chaining approaches,
which require KB in the form of the first-order definite clause.
Horn clause: A clause which is a disjunction of literals with at most one positive
literal is known as horn clause. Hence all the definite clauses are horn clauses.
It is equivalent to p ∧ q → k.
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.
Properties of Forward-Chaining:
Consider the following famous example which we will use in both approaches:
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."
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-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added,
which infers from the conjunction of Rule (2) and (3).
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.
Backward chaining
Example:
In backward-chaining, we will use the same above example, and will rewrite all
the rules.
Backward-Chaining proof:
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.
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.
Resolution
Resolution in FOL
Resolution
The resolution rule for first-order logic is simply a lifted version of the
propositional rule. Resolution can resolve two clauses if they contain
complementary literals, which are assumed to be standardized apart so that they
share no variables.
This rule is also called the binary resolution rule because it only resolves
exactly two literals.
Example:
Where two complimentary literals are: Loves (f(x), x) and ¬ Loves (a, b)
These literals can be unified with unifier θ= [a/f(x), and b/x] , and it will generate
a resolvent clause:
To better understand all the above steps, we will take an example in which we
will apply resolution.
Example:
In the first step we will convert all the given statements into its first order logic.
Step-2: Conversion of FOL into CNF
In First order logic resolution, it is required to convert the FOL into CNF as CNF
form makes easier for resolution proofs.
In this statement, we will apply negation to the conclusion statements, which will
be written as ¬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.