0% found this document useful (0 votes)
30 views21 pages

First-Order Logic in Artificial Intelligence

don't now

Uploaded by

chandruyck42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views21 pages

First-Order Logic in Artificial Intelligence

don't now

Uploaded by

chandruyck42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

First-Order Logic in Artificial intelligence

In the topic of Propositional logic, we have seen that how to represent


statements using propositional logic. But unfortunately, in
propositional logic, we can only represent the facts, which are either
true or false. PL is not sufficient to represent the complex sentences or
natural language statements. The propositional logic has very limited
expressive power. Consider the following sentence, which we cannot
represent using PL logic.

o "Some humans are intelligent", or


o "Sachin likes cricket."

To represent the above statements, PL logic is not sufficient, so we


required some more powerful logic, such as first-order logic.

First-Order logic:

o First-order logic is another way of knowledge representation in


artificial intelligence. It is an extension to propositional logic.
o FOL is sufficiently expressive to represent the natural language
statements in a concise way.
o First-order logic is also known as Predicate logic or First-
order predicate logic. First-order logic is a powerful language
that develops information about the objects in a more easy way
and can also express the relationship between those objects.
o First-order logic (like natural language) does not only assume
that the world contains facts like propositional logic but also
assumes the following things in the world:
o Objects: A, B, people, numbers, colors, wars, theories,
squares, pits, wumpus, ......
o Relations: It can be unary relation such as: red, round,
is adjacent, or n-any relation such as: the sister of,
brother of, has color, comes between
o Function: Father of, best friend, third inning of, end
of, ......
o As a natural language, first-order logic also has two main parts:

a. Syntax

b. Semantics

Syntax of First-Order logic:

The syntax of FOL determines which collection of symbols is a


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

Basic Elements of First-order logic:


Following are the basic elements of FOL syntax:

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

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

Predicates Brother, Father, >,....

Function sqrt, LeftLegOf, ....

Connectives ∧, ∨, ¬, ⇒, ⇔

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

Example: Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).


Chinky is a cat: => cat (Chinky).

Complex Sentences:

o Complex sentences are made by combining atomic sentences


using connectives.
First-order logic statements can be divided into two parts:

o Subject: Subject is the main part of the statement.


o 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.

Quantifiers in First-order logic:

o A quantifier is a language element which generates


quantification, and quantification specifies the quantity of
specimen in the universe of discourse.
o These are the symbols that permit to determine or identify the
range and scope of the variable in the logical expression. There
are two types of quantifier:

a. Universal Quantifier, (for all, everyone, everything)

b. Existential quantifier, (for some, at least one).


Universal Quantifier:

Universal quantifier is a symbol of logical representation, which


specifies that the statement within its range is true for everything or
every instance of a particular thing.

The Universal quantifier is represented by a symbol ∀, which


resembles an inverted A.

Note: In universal quantifier we use implication "→".

If x is a variable, then ∀x is read as:

o For all x
o For each x
o For every x.

Example:

All man drink coffee.

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.

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:

o There exists a 'x.'


o For some 'x.'
o For at least one 'x.'

Example:

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.
Points to remember:

o The main connective for universal quantifier ∀ is implication →.


o The main connective for existential quantifier ∃ is and ∧.

Properties of Quantifiers:

o In universal quantifier, ∀x∀y is similar to ∀y∀x.


o In Existential quantifier, ∃x∃y is similar to ∃y∃x.
o ∃x∀y is not similar to ∀y∃x.

Some Examples of FOL using quantifier:

1. All birds fly.


In this question the predicate is "fly(bird)."
And since there are all birds who fly so it will be represented as
follows.
∀x bird(x) →fly(x).

2. Every man respects his parent.


In this question, the predicate is "respect(x, y)," where x=man, and
y= parent.
Since there is every man so will use ∀, and it will be represented as
follows:
∀x man(x) → respects (x, parent).
3. Some boys play cricket.
In this question, the predicate is "play(x, y)," where x= boys, and y=
game. Since there are some boys so we will use ∃, and it will be
represented as:
∃x boys(x) → play(x, cricket).

4. Not all students like both Mathematics and Science.


In this question, the predicate is "like(x, y)," where x= student, and
y= subject.
Since there are not all students, so we will use ∀ with negation,
so following representation for this:
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x,
Science)].

5. Only one student failed in Mathematics.


In this question, 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)].

Free and Bound Variables:

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:
Free Variable: A variable is said to be a free variable in a formula if
it occurs outside the scope of the quantifier.

Example: ∀x ∃(y)[P (x, y, z)], where z is a free variable.

Bound Variable: A variable is said to be a bound variable in a


formula if it occurs within the scope of the quantifier.

Example: ∀x [A (x) B( y)], here x and y are the bound


variables.
Forward Chaining and backward chaining in AI

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:

The inference engine is the component of the intelligent system in


artificial intelligence, which applies logical rules to the knowledge
base to infer new information from known facts. The first inference
engine was part of the expert system. Inference engine commonly
proceeds in two modes, which are:

1. Forward chaining
2. Backward chaining

Horn Clause and Definite clause:

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.
Definite clause: A clause which is a disjunction of literals
with exactly one positive literal is known as a definite clause or strict
horn 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.

Example: (¬ p V ¬ q V k). It has only one positive literal k.

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:

o It is a down-up approach, as it moves from bottom to top.


o It is a process of making a conclusion based on known facts or
data, by starting from the initial state and reaches the goal state.
o Forward-chaining approach is also called as data-driven as we
reach to the goal using available data.
o Forward -chaining approach is commonly used in the expert
system, such as CLIPS, business, and production rule systems.

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."

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:


o 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)
o 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)
o All of the missiles were sold to country A by Robert.
?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......
(4)
o Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
o Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
o Country A is an enemy of America.
Enemy (A, America) .........(7)
o 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.

Hence it is proved that Robert is Criminal using forward chaining


approach.

B. Backward Chaining:

Backward-chaining is also known as a backward deduction or


backward reasoning method when using an inference engine. A
backward chaining algorithm is a form of reasoning, which starts with
the goal and works backward, chaining through rules to find known
facts that support the goal.

Properties of backward chaining:

o It is known as a top-down approach.


o Backward-chaining is based on modus ponens inference rule.
o In backward chaining, the goal is broken into sub-goal or sub-
goals to prove the facts true.
o It is called a goal-driven approach, as a list of goals decides
which rules are selected and used.
o Backward -chaining algorithm is used in game theory,
automated theorem proving tools, inference engines, proof
assistants, and various AI applications.
o The backward-chaining method mostly used a depth-first
search strategy for proof.

Example:

In backward-chaining, we will use the same above example, and will


rewrite all the rules.

o American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) →


Criminal(p) ...(1)
Owns(A, T1) ........(2)
o Missile(T1)
o ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) .....
.(4)
o Missile(p) → Weapons (p) .......(5)
o Enemy(p, America) →Hostile(p) ........(6)
o Enemy (A, America) .........(7)
o 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy