20CS16-Principals of Artificial Intelligence
By
Mrs. S.Jyothi
Asst Professor
Dept of IT LBRCE,Mylavaram
1
UNIT IV
Chapter I Knowledge Representation
using Predicate logic
2
Knowledge Representation using Predicate logic
3
Introduction
4
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:
5
Following are some basic facts about propositional logic:
"Where is Rohan", "How are you", "What is your name", are not propositions.
Syntax of propositional logic
6
The syntax of propositional logic defines the allowable sentences for the knowledge representation. There are two types of Propositions:
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.
Compound proposition: Compound propositions are constructed by combining simpler or atomic propositions, using parenthesis and logical connectives.
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
7
literal or negative literal.
Example: Rohan is intelligent and hardworking. It can be written as,
P= Rohan is intelligent,
Q= Rohan is hardworking. P𝖠 Q.
Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Engineer, so we can write it as P ∨ Q.
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is represented as P → Q
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.
8
9
10
Precedence of connectives
11
The is a precedence order for propositional connectors or logical operators. This order should be followed while evaluating a propositional problem. Following is the list of the precedence order for operators:
Precedence | Operators |
first Precedence | Parenthesis |
Second Precedence | Negation |
Third Precedence | Conjunction(AND) |
Fourth Precedence | Disjunction(OR) |
Fifth Precedence | Implication |
Six Precedence | Biconditional |
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
12
Properties of Operators
13
14
Limitations of Propositional logic:
Predicate logic/First-Order logic
15
an extension to propositional logic.
way.
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.
16
Basic Elements of First-order logic
17
Constant | 1, 2, A, John, Mumbai, cat,.... |
Variables | x, y, z, a, b,.... |
Predicates | Brother, Father, >,.... |
Function | sqrt, LeftLegOf, .... |
Connectives | 𝖠, ∨, ¬, ⇒, ⇔ |
Equality | == |
Quantifier | ∀, ∃ |
Atomic sentences
18
Chinky is a cat: => cat (Chinky).
Complex Sentences
First-order logic statements can be divided into two parts:
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.
19
Quantifiers in First-order logic
20
Universal Quantifier
21
If x is a variable, then ∀x is read as:
Example:
All man drink coffee.
Let a variable x which refers to a man 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. The main connective for universal quantifier ∀ is implication →.
22
Existential Quantifier
23
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
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. The main connective for existential quantifier ∃ is and 𝖠.
24
Properties of Quantifiers
25
Examples of FOL using quantifier
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).
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)
26
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).
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)].
In this question, the predicate is "failed(x, y)," where x= student, and y= subject.
How it will be represented?
Ans is
∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (x, Mathematics)].
�
Free and Bound Variables
28
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 ∀y [A (x) B( y)], here x and y are the bound variables.
Representing simple facts in logic
Using proportional logic:
Example1:
29
Example2:
Since the assertions are separate, it is not possible to draw any conclusion about similarities between Socrates and Plato.
It would be much better to represent these facts as
30
31
Propositional logic Vs Predicate logic
32
Consider the following statements
33
34
Pompeians(Marcus)
∀(x):Pompeians(x) →Roman(x) 4.Casear was a ruler
ruler(Casear)
5.All Romans were either loyal to Casear or hated him.
∀(x): Roman(x) →loyalto(x,Casear) V hate(x,Casear) 6.Every one is loyal to someone.
∀x: ∃(y):loyalto(x,y)
35
∀x :∀(y):person(x) 𝖠 ruler(y) 𝖠 tryassassinate(x,y) → ¬loyalto(x,y)
To Answer the question
Was Marcus loyal to Caesar?
To produce a formal proof, reasoning backward from the desired goal
¬ loyalto(Marcus, Caesar)
To prove the goal, rules of inference are to be used to transform into another goal that in turn to be transformed and so on, until there no unsatisfied goals remaining
36
37
9.All men are people
∀x :man(x) → person(x)
this satisfies the last goal and produces a proof that Marcus was not loyal to Ceasar.
38
Three important statements to be addressed in this process of converting English sentences to logical sentences to deduce new ones.
Representing Instance and Isa Relationships
39
Attributes " IsA " and " Instance " support property inheritance and play important role in knowledge representation. The ways these two attributes "instance" and "isa", are logically expressed are shown in the example below : Example : A simple sentence like "Joe is a musician" Here "is a" (called IsA) is a way of expressing what logically is called a class-instance relationship between the subjects represented by the terms "Joe" and "musician". "Joe" is an instance of the class of things called "musician". " Joe" plays the role of instance, "musician" plays the role of class in that sentence.
Note : In such a sentence, while for a human there is no confusion, but for computers each relationship have to be defined explicitly.
This can be specified as:
[Joe] Isa [Musician]
i.e [Instance] Isa [class]
40
41
Computable functions and predicates
42
tryassassinate(Marcus, Caesar)
Computable predicates greater-than(1, 0)
greater-than(2, 1)
greater-than(3, 2)
……
less-than(0, 1)
less-than(1, 2)
less-than(2, 3)
……
43
Consider the following set of facts, again involving Marcus:
44
45
Set of facts about Marcus
The numbering is changed slightly because sentence 5 has been split into two parts
46
The question is "Is Marcus alive?" This question can be answered by proving
¬alive(Marcus,now)
The term nil at the end of each proof indicates that the list of conditions remaining to be proved is empty and so the proof has succeeded.
47
Resolution
48
Rules to Convert into CNF
49
1.Eliminate implication (→) and double implication (↔) a →b can be converted as ¬ a V b
a↔b can be converted as a →b Λ b → a 2.Move negation( ¬) inward
¬(∀xp)=ⱻx ¬p
¬(ⱻxp)= ∀x ¬p
¬(a V b)= ¬ a Λ ¬ b
¬ (a Λb) = ¬ a V ¬ b
¬ ¬ a = a 3.Rename variable
4.Replace the existential quantifier by skolem constant
ⱻx rich(x)=rich(G) 5.Drop the universal quantifier
Steps for Resolution
50
1.Conversion of facts into first-order logic. 2.Convert FOL statements into CNF
3.Negate the statement which needs to prove (proof by contradiction) 4.Draw resolution graph (unification).
51
Example:
1.John likes all kind of food. 2.Apple and vegetable are food
3.Anything anyone eats and not killed is food. 4.Anil eats peanuts and still alive
Step-1: Conversion of Facts into FOL
In the first step we will convert all the given statements into its first order logic.
52
53
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.
54
55
Eliminate existential instantiation quantifier by elimination.
In this step, we will eliminate existential quantifier ∃, and this process is known as
Skolemization.
But in this example problem since there is no existential quantifier so all the statements will remain same in this step.
56
Drop Universal quantifiers.
In this step we will drop all universal quantifier since all the statements are not implicitly quantified, so we don't need it.
Distribute conjunction 𝖠 over disjunction ¬.
This step will not make any change in this problem.
57
Step-3: Negate the statement
statement,
to be proved
we
In this will apply
negation to the conclusion
which will be
as ¬likes(John,
statements, written Peanuts)
Step-4: Draw Resolution graph Now in this step, we will solve
the problem by resolution tree using substitution. For the above problem, it will be given as follows:
Explanation of Resolution graph
58
Unification
59
Example: Find the MGU for Unify{King(x), King(John)}
Let Ψ1 = King(x), Ψ2 = King(John),
Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and both expressions will be identical.
60
Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and
both expressions will be identical.
returns a unifier for those sentences (If any exist).
E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
In this example, we need to make both above statements identical to each other. For this, we will perform the substitution.
P(x, y)......... (i)
P(a, f(z))......... (ii)
and the substitution set will be: [a/x, f(z)/y].
Conditions for Unification
61
Following are some basic conditions for unification:
Unification Algorithm
62
Natural deduction
63
Problems with resolution:
The heuristic information contained in the original statements can be lost in the transformation.
Example: all judges who are not crooked are well-educated
∀x:judge(x) Λ ¬ crooked(x)→educated(x)
In this form, the statement suggests a way of deducing that someone is educated. But same statement is converted to clause form.
¬judge(x) V crooked(x) V educated(x)
It appears also to be a way of deducing that someone is not a judge by showing that he is not crooked and not educated.
64
UNIT IV
Chapter II Representing Knowledge Using Rules
65
Representing Knowledge Using Rules
66
Procedural versus declarative knowledge
67
Declarative representation
Example:
=> Logical assertions = Procedural representations of knowledge
68
Procedural representation
Kowalski's equation: Algorithm = Logic + Control
69
Procedural knowledge | Declarative knowledge |
Knowledge about "how to do something"; e.g., to determine if Peter or Robert is older, first find their ages. | Knowledge about "that something is true or false". e.g., A car has four tires; Peter is older than Robert |
focuses on tasks that must be performed to reach a particular objective or goal | Refers to representations of objects and events; knowledge about facts and relationships. |
Examples : procedures, rules, strategies, agendas, models. | Example : concepts, objects, facts, propositions, assertions, semantic nets, logic and descriptive models. |
71
The real difference between the declarative and procedural views of knowledge lies in where control information resides
Example: man(Marcus) man(Caesar) person(Cleopatra)
∀x: man(x)→ person(x)
Now consider trying to extract from this knowledge base the answer to the question
ⱻy: person(y)
We want bind x to a particular value for which person is true. Our knowledge base justifies any of the following answers.
y=Marcus y=Caesar y=Cleopatra
72
∀x: man(x)→ person(x)
73
Logic programming
74
Prolog program = {Horn Clauses}
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: disjunction of literals of which at most one(zero or one) is positive literal Hence all the definite clauses are horn clauses.
p, ¬pvq, and p→q are horn clauses.
Example: (¬ p V ¬ q V k). It has only one positive literal k.
It is equivalent to p ∧ q → k.
=>Prolog program is decidable
Control structure: Prolog interpreter = backward reasoning + depth-first with backtracking
75
A representation in logic
∀x:pet(x) Λ small(x) →apartmentpet(x)
∀x:cat(x) v dog(x) →pet(x)
∀x:poodle(x) →dog(x) Λ small(x) Poodle(fluffy)
A representation in PROLOG apartmentpet(x) :- pet(x),small(x) pet(x) :- cat(x)
pet(x) :-dog(x)
dog(x) :-poodle(x)
small(x):-poodle(x) poodle(fluffy)
77
Prolog vs logic
Constants: begin with lowercase letters or number
“p implies q" is written as q :- p
∀x:dog(x) → ¬cat(x)
Problem solving strategy: NEGATION AS FAILURE
?- cat(fullfy). => false because it is unable to prove Fluffy is a cat.
78
Forward vs. Backward Reasoning
82
83
Forward: from the start states. Backward: from the goal states.
84
Four factors influence forward or Backward?
S. No. | Forward Chaining | Backward Chaining |
1. | Forward chaining starts from known facts and applies inference rule to extract more data unit it reaches to the goal. | Backward chaining starts from the goal and works backward through inference rules to find the required facts that support the goal. |
2. | It is a bottom-up approach | It is a top-down approach |
3. | Forward chaining is known as data-driven inference technique as we reach to the goal using the available data. | Backward chaining is known as goal-driven technique as we start from the goal and divide into sub-goal to extract the facts. |
4. | Forward chaining reasoning applies a breadth-first search strategy. | Backward chaining reasoning applies a depth-first 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, monitoring, control, and interpretation application. | Backward chaining is suitable for diagnostic, prescription, and debugging application. |
7. | Forward chaining can generate an infinite number of possible conclusions. | Backward chaining generates a finite number of possible conclusions. |
8. | It operates in the forward direction. | It operates in the backward direction. |
9. | Forward chaining is aimed for any conclusion. | Backward chaining is only aimed for the required data. |
The knowledge base:�It contains the specialized expertise required for problem-solving. The information is represented as a set of rules in a rules-based system. Every rule has an IF (condition) THEN (action) structure and defines a relationship, suggestion, directive, strategy, or heuristic. The rule is activated, and the action portion is carried out as soon as the conditional portion of the rule is met.
The database:�The database contains a collection of facts compared to the knowledge base's rules IF (condition) clause.
The inference engine:�The expert system uses the inference engine to derive the logic and arrive at a conclusion. The inference engine's task is to connect the facts kept in the database with the rules specified in the knowledge base. The semantic reasoner is another name for the reasoning engine. It deduces information or executes necessary actions based on data and the rule base present in the knowledge base. For example, the match-resolve-act loop used by the semantic reasoner goes like this:
Match:�A portion of the production rule system is compared to the information in the working memory to create a conflict in which numerous examples of satisfied productions are present.
Conflict Resolution:�Following the matching of the production systems, one of the production cases involved in the conflict will be executed to gauge the procedure's status.
Act:�The production instance chosen in the step before is carried out, changing the information in the working memory.
KR using Rules
87
88
89
90
91
92
93
https://youtu.be/RYIjxRfOPWY?si=vPEsOOlKQdPma2eC refer this video
94
95
Preconditions :
Matching
97
How to extract from the entire collection of rules that can be applied at a given point?
=> Matching between current state and the precondition of the rules Indexing
98
Indexing
100
2. Matching with the variables
Many to many mapping algorithm–RETE Algoritham
RETE one efficient many-many match algorithm fot three main reasons.
a)The temporal nature of data.
Whenever u apply rules usually do not alter the state description radically.
If a rule did not match in the previous cycle ,it will most likely fail to apply in the current cycle
Instead a rule will add one or two elements or delete one or two elements but the state remains the same.
RETE maintains a network of rule conditions and (is filtering process )
It uses changes in the state description to determine which new rules might apply and which is no longer apply.(Many to Many matching) Many rules are matched against many elements in the state description simultaneously.
b)Structural similarity in rules.
Different rules may share a large number of pre-conditions
EX: one rule concludes jaguar(x) if mammal(x),feline(x),carnivorous(x) and has-spots(x). Another rule concludes tiger(x) and is identical to the first rule except that it replaces has-spots with has-stripes. If two rules are matched independently, a lot of work is repeated unnecessarily.
RETE stores rules so that they share structures in memory. Sets of conditions that appear in sever at rules are matched once per cycle.
101
102
3.Approximate matching (Complex and appropriate matching)
105
106
4. Conflict resolution:
The result of the matching process is a list of rules whose antecedents have matched the current state description along with the binding variables
The order of the rules
-Specificity the physical order of rules and give priority the first that appeear first
-Physical order of rules
-Importance of objects
-Position of objects
-Evaluation of states
Applying all the rules at a time and examine result is appropriate use it other things throw them out
Control knowledge
107
Knowledge about -Which states are more preferable to others.
-Which rule to apply in a given situation.
-The order in which to pursue sub goals
-Useful sequences of rules to apply.
Here we r acquiring
Search control knowledge = Meta knowledge(knowledge about knowledge)
108
There are a number of Al systems that represent their control knowledge with rules. Example SOAR,PRODIGY SOAR is a general architecture for building intelligent systems.
109
110
Two issues concerning control rules:
THE END
111