UNIT IV First Order Logic
UNIT IV First Order Logic
a. Syntax
To represent the above statements, PL logic is not sufficient, so we required
b. Semantics
some more powerful logic, such as first-order logic.
Consider the statement: "x is an integer.", it consists of two parts, the first
Equality ==
part x is the subject of the statement and second part "is an integer," is
Quantifier ∀, ∃ known as a predicate.
Atomic sentences:
Complex Sentences: and quantification specifies the quantity of specimen in the universe of
discourse.
Universal Quantifier:
o For all x It will be read as: There are all x where x is a man who drink coffee.
o For each x
o For every x.
Existential Quantifier:
Example: Existential quantifiers are the type of quantifiers, which express that the
statement within its scope is true for at least one instance of something.
All man drink coffee.
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 is knowledge-engineering?
The next step of the process is to select functions, predicate, and constants 1. ∀ t1, t2 Terminal (t1) ∧ Terminal (t2) ∧ Connect (t1, t2) → Signal (t1) =
to represent the circuits, terminals, signals, and gates. Firstly we will Signal (2).
distinguish the gates from each other and from other objects. Each gate is
o Signal at every terminal will have either value 0 or 1, it will be
represented as an object which is named by a constant, such as, Gate(X1).
represented as:
The functionality of each gate is determined by its type, which is taken as
constants such as AND, OR, XOR, or NOT. Circuits will be identified by a 1. ∀ t Terminal (t) →Signal (t) = 1 ∨Signal (t) = 0.
predicate: Circuit (C1).
o Connect predicates are commutative:
For the terminal, we will use predicate: Terminal(x).
1. ∀ t1, t2 Connect(t1, t2) → Connect (t2, t1).
For gate input, we will use the function In(1, X1) for denoting the first input
terminal of the gate, and for output terminal we will use Out (1, X1). o Representation of types of gates:
o Output of AND gate will be zero if and only if any of its input is zero. 1. ∀ g Gate(g) → Circuit (g).
1. ∀ g Gate(g) ∧ Type(g) = AND →Signal (Out(1, g))= 0 ⇔ ∃n Signal (In( 5. Encode a description of the problem instance:
n, g))= 0.
Now we encode problem of circuit C1, firstly we categorize the circuit and its
o Output of OR gate is 1 if and only if any of its input is 1: gate components. This step is easy if ontology about the problem is already
thought. This step involves the writing simple atomics sentences of instances
1. ∀ g Gate(g) ∧ Type(g) = OR → Signal (Out(1, g))= 1 ⇔ ∃n Signal (In(
of concepts, which is known as ontology.
n, g))= 1
For the given circuit C1, we can encode the problem instance in atomic
o Output of XOR gate is 1 if and only if its inputs are different:
sentences as below:
1. ∀ g Gate(g) ∧ Type(g) = NOT → Signal (In(1, g)) ≠ Signal (Out(1, g)). 2. For AND gate: Type(A1) = AND, Type(A2)= AND
3. For OR gate: Type (O1) = OR.
o All the gates in the above circuit have two inputs and one output And then represent the connections between all the gates.
First-Order logic does not only use predicate and terms for making atomic
7. Debug the knowledge base:
sentences but also uses another way, which is equality in FOL. For this, we
Now we will debug the knowledge base, and this is the last step of the can use equality symbols which specify that the two terms refer to the same
complete process. In this step, we will try to debug the issues of knowledge object.
base.
Example: Brother (John) = Smith.
then we can have a conclusion as ∀ x P(x). "John likes ice-cream" => P(c)
Example: 2.
o It can be represented as: .
o This rule can be used if we want to show that every element has a
Let's take a famous example,
similar property.
o In this rule, x must not appear as a free variable. "All kings who are greedy are Evil." So let our knowledge base contains this
detail as in the form of FOL:
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. ∀x king(x) ∧ greedy (x) → Evil (x),
2. Universal Instantiation: So from this information, we can infer any of the following statements using
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 King(John) ∧ Greedy (John) → Evil (John),
o The new KB is logically equivalent to the previous KB. o King(Richard) ∧ Greedy (Richard) → Evil (Richard),
o As per UI, we can infer any sentence obtained by substituting a o King(Father(John)) ∧ Greedy (Father(John)) → Evil (Father(John)),
o Existential instantiation is also called as Existential Elimination, which o An existential introduction is also known as an existential
is a valid inference rule in first-order logic. generalization, which is a valid inference rule in first-order logic.
o It can be applied only once to replace the existential sentence. o This rule states that if there is some element c in the universe of
o The new KB is not logically equivalent to old KB, but it will be discourse which has a property P, then we can infer that there exists
satisfiable if old KB was satisfiable. something in the universe which has the property P.
o 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. o It can be represented as:
o The restriction with this rule is that c used in the rule must be a new o Example: Let's say that,
term for which P(c ) is true. "Priyanka got good marks in English."
"Therefore, someone got good marks in English."
o It can be represented as:
Generalized Modus Ponens Rule:
Example:
For the inference process in FOL, we have a single inference rule which is
From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),
called Generalized Modus Ponens. It is lifted version of Modus ponens.
We will use this rule for Kings are evil, so we will find some x such that x o The UNIFY algorithm is used for unification, which takes two atomic
is king, and x is greedy so we can infer that x is evil. sentences and returns a unifier for those sentences (If any exist).
o Unification is a key component of all first-order inference algorithms.
1. Here let say, p1' is king(John) p1 is king(x) o It returns fail if the expressions do not match with each other.
2. p2' is Greedy(y) p2 is Greedy(x) o The substitution variables are called Most General Unifier or MGU.
3. θ is {x/John, y/John} q is evil(x)
4. SUBST(θ,q). E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
What is Unification?
P(x, y)......... (i)
P(a, f(z))......... (ii)
o Unification is a process of making two different logical atomic
expressions identical by finding a substitution. Unification depends on the o Substitute x with a, and y with f(z) in the first expression, and it will be
substitution process. represented as a/x and f(z)/y.
o It takes two literals as input and makes them identical using o With both the substitutions, the first expression will be identical to
substitution. the second expression and the substitution set will be: [a/x, f(z)/y].
o 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). Conditions for Unification:
o Example: Find the MGU for Unify{King(x), King(John)}
o Predicate symbol must be same, atoms or expression with different Step. 4: Set Substitution set(SUBST) to NIL.
predicate symbol can never be unified.
Step. 5: For i=1 to the number of elements in Ψ1.
o Number of Arguments in both expressions must be identical.
o Unification will fail if there are two similar variables present in the a) Call Unify function with the ith element of Ψ1 and ith
element of Ψ2, and put the result into S.
same expression.
b) If S = failure then returns Failure
S1 => { p(b, X, f(g(b))); p(b, f(Y), f(Y))} 5. Find the MGU of Q(a, g(x, a), f(y)), Q(a, g(f(b), a), x)}
SUBST θ={f(Y) /X}
Here, Ψ1 = Q(a, g(x, a), f(y)), and Ψ2 = Q(a, g(f(b), a), x)
S2 => { p(b, f(Y), f(g(b))); p(b, f(Y), f(Y))} S0 => {Q(a, g(x, a), f(y)); Q(a, g(f(b), a), x)}
SUBST θ= {g(b) /Y}
Inference engine:
It is equivalent to p ∧ q → k.
A. Forward Chaining
15 | P a g e First-Order Logic in Artificial intelligence
Forward chaining is also known as a forward deduction or forward reasoning "As per the law, it is a crime for an American to sell weapons to hostile
method when using an inference engine. Forward chaining is a form of nations. Country A, an enemy of America, has some missiles, and all the
reasoning which start with atomic sentences in the knowledge base and missiles were sold to it by Robert, who is an American citizen."
applies inference rules (Modus Ponens) in the forward direction to extract
Prove that "Robert is criminal."
more data until a goal is reached.
To solve the above problem, first, we will convert all the above facts into first-
The Forward-chaining algorithm starts from known facts, triggers all rules
order definite clauses, and then we will use a forward-chaining algorithm to
whose premises are satisfied, and add their conclusion to the known facts. This
reach the goal.
process repeats until the problem is solved.
Properties of Forward-Chaining:
Facts Conversion into FOL:
Step-1:
In the first step we will start with the known facts and will choose the sentences Step-3:
which do not have implications, such as: American(Robert), Enemy(A,
America), Owns(A, T1), and Missile(T1). All these facts will be represented 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
as below.
facts. And hence we reached our goal statement.
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.
algorithm is a form of reasoning, which starts with the goal and works o ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
backward, chaining through rules to find known facts that support the goal. o Missile(p) → Weapons (p) .......(5)
o Enemy(p, America) →Hostile(p) ........(6)
Properties of backward chaining:
o Enemy (A, America) .........(7)
o American(Robert). ..........(8)
o It is known as a top-down approach.
o Backward-chaining is based on modus ponens inference rule.
Backward-Chaining proof:
o In backward chaining, the goal is broken into sub-goal or sub-goals to
prove the facts true.
In Backward chaining, we will start with our goal predicate, which
o It is called a goal-driven approach, as a list of goals decides which rules
is Criminal(Robert), and then infer further rules.
are selected and used.
o Backward -chaining algorithm is used in game theory, automated Step-1:
theorem proving tools, inference engines, proof assistants, and various AI
At the first step, we will take the goal fact. And from the goal fact, we will infer
applications.
other facts, and at last, we will prove those facts true. So our goal fact is "Robert
o The backward-chaining method mostly used a depth-first
is Criminal," so following is the predicate of it.
search strategy for proof.
Example:
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-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-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.
o Forward chaining as the name suggests, start from the known facts and
move forward by applying inference rules to extract more data, and it
continues until it reaches to the goal, whereas backward chaining starts from
the goal, move backward by using inference rules to determine the facts that
satisfy the goal.
Note: To better understand this topic, firstly learns the FOL in AI.
9. Forward chaining is aimed for Backward chaining is only aimed
any conclusion. for the required data.
The resolution inference rule:
The resolution rule for first-order logic is simply a lifted version of the
propositional rule. Resolution can resolve two clauses if they contain
Resolution in FOL
complementary literals, which are assumed to be standardized apart so that
they share no variables.
Resolution
Resolution is used, if there are various statements are given, and we need to This rule is also called the binary resolution rule because it only resolves
prove a conclusion of those statements. Unification is a key concept in proofs exactly two literals.
Where two complimentary literals are: Loves (f(x), x) and ¬ Loves (a, b)
To better understand all the above steps, we will take an example in which we Step-2: Conversion of FOL into CNF
**********