Unit4 Secondhalf
Unit4 Secondhalf
1. Logic
The knowledge bases consist of sentences and these sentences are expressed
according to the syntax of the representation language, which specifies all the sentences that
are well formed. The notion of syntax is clear enough in ordinary arithmetic: “x + y = 4” is a
well-formed sentence, whereas “x4y+ =” is not.
Logic must also define the semantics or meaning of sentences. The semantics
defines the truth of each sentence with respect to each possible world. For example, the
semantics for arithmetic specifies that the sentence “x + y =4” is true in a world where x is 2
and y is 2, but false in a world where x is 1 and y is 1. In standard logics, every sentence
must be either true or false in each possible world there is no “in between.”. Types of Logic are
propositional Logic and First order Logic.
Propositional Logic
The syntax of propositional logic and its semantics are the way in which the
truth of sentences is determined. Then we look at entailment the relation between a sentence
and another sentence that follows from it and see how this leads to a simple algorithm for
logical inference.
We used propositional logic as our representation language because it sufficed to illustrate the
basic concepts of logic and knowledge-based agents. Unfortunately, propositional logic is too
puny a language to represent knowledge of complex environments in a concise way. we
examine first-order logic, which is sufficiently expressive to represent a good deal of our
commonsense knowledge.
• Propositional logic deals with simple declarative propositions, while first-order logic
additionally covers predicates and quantification.
• A proposition is a collection of declarative statements that has either a truth
value “true” or a truth value “false”. While a predicate logic is an expression
of one or more variables defined on some specific domain.
• Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games,
wars, centuries . . .
• Relations: these can be unary relations or properties such as red, round, bogus, prime,
multistoried . . ., or more general n-ary relations such as brother of, bigger than, inside, part
of, has color, occurred after, owns, comes between, . . .
• Functions: father of, best friend, third inning of, one more than, beginning of . . .
Fig 3.2 A model containing five objects, two binary relations, three unary
relations(indicated by labels on the objects), and one unary function, left-leg
The crown is on King John’s head, so the “on head” relation contains just one tuple, _the
crown, King John_. 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; the “king” property is true only of John
(presumably because Richard is dead at this point); and the “crown” property is true only of
the crown. For example, each person has one left leg, so the model has a unary “left leg”
function that includes the following mappings:
• Richard refers to Richard the Lionheart and John refers to the evil King John.
• Brother refers to the brotherhood relation, that is, the set of tuples of objects. 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.
• LeftLeg refers to the “left leg” function, that is, the mapping .
A term is a logical expression that refers to an object. Constant symbols are
therefore terms, but it is not always convenient to have a distinct symbol to name every
object. For example, in English we might use the expression “King John’s left leg” rather
than giving a name to his leg. This is what function symbols are for: instead of using a
constant symbol, we use LeftLeg (John). In the general case, a complex term is formed by a
function symbol followed by a parenthesized list of terms as arguments to the function
symbol. An atomic sentence (or atom for short) is ATOMIC SENTENCE formed from a
predicate symbol optionally followed by aparenthesized list of terms, such as
Brother (Richard , John).
This states, under the intended interpretation given earlier, that Richard theLionheart is
the brother of King John.
We can use logical connectives to construct more complex sentences, with the same syntax
and semantics as in propositional calculus.
¬Brother (LeftLeg(Richard), John)
Brother (Richard , John) 𝖠Brother (John,Richard)
King(Richard ) ∨King(John)
¬King(Richard) ⇒ King(John) .
3.2.5 Quantifiers
First-order logic contains two standard quantifiers, called universal and existential
∀x King(x) ⇒ Person(x) .
∀ is usually pronounced “For all . . .”. (Remember that the upside-down A stands for “all.”)
Thus, the sentence says, “For all x, if x is a king, then x is a person.” The symbol x is called a
variable. By convention, variables are lowercase letters. A variable is a term all by itself, and
as such can also serve as the argument of a function—for example, LeftLeg(x). A term with no
variables is called a ground term .
The sentence ∀x P, where P is any logical expression, says that P is true for every object x.
More precisely, ∀x P is true in a given model if P is true in all possible extended
interpretations constructed from the interpretation given in the model, where each extended
interpretation specifies a domain element to which x refers
→ the crown.
The universally quantified sentence ∀ x King(x) ⇒ Person(x) is true in the original model of
the sentence King(x) ⇒ Person(x) is true under each of the five extended interpretations. That
is, the universally quantified sentence is equivalent to asserting the following five sentences:
Richard the Lionheart is a king ⇒ Richard the Lionheart is a person.King
John is a king ⇒ King John is a person.
Nested quantifiers
The simplest case is where the quantifiers are of the same type. For example, “Brothers are
siblings” can be written as
In other cases we will have mixtures. “Everybody loves somebody” means that for
every person, there is someone that person loves:
∀x Ǝy Loves(x, y) .
On the other hand, to say “There is someone who is loved by everyone,” we write
Ǝy∀x Loves(x, y) .
The order of quantification is therefore very important. It becomes clearer if we insert
parentheses. ∀ x (Ǝy Loves(x, y)) says that everyone has a particular property, namely, the
property that they love someone.
∀x P ≡ ¬Ǝx ¬P P𝖠 Q ≡¬(¬P
¬P 𝖠¬Q)
Equality
First-order logic includes one more way to make atomic sentences, other than using
a predicate and terms as described earlier. We can use the equality symbol 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. One proposal that is very popular in database systems works as follows.
First, we insist that every constant symbol refer to a distinct object—the so- called
unique-names assumption. Second, we assume that atomic sentences not known to be
true are in fact false the closed-world assumption.
KNOWLEDGE ENGINEERING IN FIRST ORDER LOGIC
What is knowledge-engineering?
In this topic, we will understand the Knowledge engineering process in an electronic circuit
domain, which is already familiar. This approach is mainly suitable for creating special-purpose
knowledge base.
Following are some main steps of the knowledge-engineering process. Using these steps, we will
develop a knowledge base which will allow us to reason about digital circuit (One-bit full
adder) which is given below
The first step of the process is to identify the task, and for the digital circuit, there are various
reasoning tasks.
At the first level or highest level, we will examine the functionality of the circuit:
At the second level, we will examine the circuit structure details such as:
o Which gate is connected to the first input terminal?
o Does the circuit have feedback loops?
In the second step, we will assemble the relevant knowledge which is required for digital
circuits. So for digital circuits, we have the following required knowledge:
3. Decide on vocabulary:
The next step of the process is to select functions, predicate, and constants to represent the
circuits, terminals, signals, and gates. Firstly we will distinguish the gates from each other and
from other objects. Each gate is represented as an object which is named by a constant, such
as, Gate(X1). 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 predicate: Circuit
(C1).
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).
The function Arity(c, i, j) is used to denote that circuit c has i input, j output.
The connectivity between gates can be represented by predicate Connect(Out(1, X1), In(1,
X1)).
We use a unary predicate On (t), which is true if the signal at a terminal is on.
To encode the general knowledge about the logic circuit, we need some following rules:
o If two terminals are connected then they have the same input signal, it can be represented
as:
∀ t1, t2 Terminal (t1) ∧ Terminal (t2) ∧ Connect (t1, t2) → Signal (t1) = Signal (2).
o Signal at every terminal will have either value 0 or 1, it will be represented as:
∀ g Gate(g) ∧ Type(g) = XOR → Signal (Out(1, g)) = 1 ⇔ Signal (In(1, g)) ≠ Signal (In(2, g
)).
o Output of NOT gate is invert of its input:
Now we encode problem of circuit C1, firstly we categorize the circuit and its gate components.
This step is easy if ontology about the problem is already thought. This step involves the writing
simple atomics sentences of instances of concepts, which is known as ontology.
For the given circuit C1, we can encode the problem instance in atomic sentences as below:
Since in the circuit there are two XOR, two AND, and one OR gate so atomic sentences for these
gates will be:
In this step, we will find all the possible set of values of all the terminal for the adder circuit. The
first query will be:
What should be the combination of input which would generate the first output of circuit C1, as 0
and a second output to be 1?
1. ∃ i1, i2, i3 Signal (In(1, C1))=i1 ∧ Signal (In(2, C1))=i2 ∧ Signal (In(3, C1))= i3
2. ∧ Signal (Out(1, C1)) =0 ∧ Signal (Out(2, C1))=1
Now we will debug the knowledge base, and this is the last step of the complete process. In this
step, we will try to debug the issues of knowledge base.
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:
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.
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.
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:
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."
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.
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).
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.
BACKWARD CHAINING
Example:
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.
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.
1. Forward chaining starts from known facts and Backward chaining starts from the goal and works
applies inference rule to extract more data unit it backward through inference rules to find the required
reaches to the goal. facts that support the goal.
4. Forward chaining reasoning applies a breadth- Backward chaining reasoning applies a depth-first
first search strategy. search strategy.
5. Forward chaining tests for all the available rules Backward chaining only tests for few required rules.
6. Forward chaining is suitable for the planning, Backward chaining is suitable for diagnostic,
monitoring, control, and interpretation prescription, and debugging application.
application.
7. Forward chaining can generate an infinite Backward chaining generates a finite number of
number of possible conclusions. possible conclusions.
9. Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the required
data.
Resolution in FOL
Resolution
Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e.,
proofs by contradictions. It was invented by a Mathematician John Alan Robinson in the year
1965.
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.
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:
a. John likes all kind of food.
b. Apple and vegetable are food
c. Anything anyone eats and not killed is food.
d. Anil eats peanuts and still alive
e. Harry eats everything that Anil eats.
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.
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.
o In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get
resolved(canceled) by substitution of {Peanuts/x}, and we are left with ¬ food(Peanuts)
o In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get resolved
(canceled) by substitution of { Peanuts/z}, and we are left with ¬ eats(y, Peanuts) V
killed(y) .
o In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil, Peanuts) get
resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
o In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve by
substitution {Anil/k}, and we are left with ¬ alive(Anil) .
o In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.