Lesson 4 Logic and Knowledge Representation
Lesson 4 Logic and Knowledge Representation
LECTURE 4
KNOWLEDGE REPRESENTATION
Knowledge Representation
Examples:
“red” represents colour red.
“car1” represents my car.
“go” represents moving
KR assumptions
• E.g.
• Fact1: “If its raining John never goes out”
• Fact2: “It’s raining today”
• Logic
• Rules
• semantic networks
• Frames
• Objects
• Natural language (grammer)
Logic
• Logic is the a science of reasoning which seeks to identify and understand the
principles of valid demonstration and inference
• Logic examples : propositional logic, predicate logic, temporal logic, modal
logic, description logic etc.
Propositional logic
• Propositional logic is a formal language for making logical inferences using
propositions and Logical connectives.
• A proposition is a statement that is either true or false. Also known as fact
• • A compound proposition can be created from other propositions using
logical connectives
Propositional logic
• Suppose :
• “P” represents the fact “Andrew likes chocolate”
• “Q” represents the fact “Andrew has chocolate”
solutions
1 : ¬p
2: p ∧ ¬q
Propositional Logic examples
• If you are older than 13 or you are with your parents then you can
attend a PG-13 movie.
Propositional Logic examples
• solution
• Translation: A ∨ B → C
Truth Table
Negation
p ~p
T F
F T
Truth Table: Conjunction
Conjunction
Conjunction :
• Similar to “and” p q pq
• Only true when all
T T T
propositions are true
• The product of at least two T F F
propositions
F T F
F F F
Truth Table
Disjunction: Disjunction
- Similar to “or” p q pq
-Only false when all
Use truth table to determine the truth value for each of the
following compound propositions:
1. pq
2. ~pq
3. pq
4. ~p ~q
Example 3: Constructing a Truth Table
(~p q) ~q
Example 3: Constructing a Truth Table
solution
p q ~p ~p q ~q (~p q) ~q
T F F F T F
Truth Tables
Exercise:
Use the truth table to determine the truth value for
the expression ~(p q)
Where:
p is true and q is false.
Truth Table: Exercise
Given that the truth values of P and Q are false and g is true
Use truth table to determine the truth value for the following
expression.
(~p q) ~q ~g
Logic and AI
• Would like our AI to have knowledge about the
world, and logically draw conclusions from it
• For example,
Blue(sky)
Exercise
• Describe the meaning of the following atomic sentences.
• Red(car23)
• student(Tom)
• married(John,Ann)
Predicate logic: logic connectives
• Logic connectives are symbols used to combine facts or propositions.
• These include atomic sentences .
• Examples
• likes(john, mary) tall(mary)
• tall(john) nice(john)
Predicate logic: quantifiers
• It is distinguished from other techniques in that its formulas contain
variables which can be quantified.
1. Existential (∃) : To represent a specific number of objects but not all of them
2. universal (∀) : To represent all objects
Predicate logic: Quantifiers
• Examples:
Convert the following sentences into predicate logic.
1. Everything is lovely.
2. Something is lovely
3. Everything in the garden is lovely
• Solutions
• X lovely(X)
X lovely(X).
X in(X, garden) lovely(X)
Exercise
• No notion of objects
• No notion of relations among objects
• RoommateCarryingUmbrella0 is instructive to us,
suggesting
• there is an object we call Roommate,
• there is an object we call Umbrella0,
• there is a relationship Carrying between these two objects
• Formally, none of this meaning is there
• Might as well have replaced RoommateCarryingUmbrella0 by P
Elements of first-order logic
• for all x: a
• is equivalent to
• NOT(there exists x: NOT(a))
Axioms and theorems
• From
• there exists x: a
• we can obtain
• SUBST({x/k}, a)
• where k is a constant that does not appear elsewhere in the
knowledge base (Skolem constant)
• Don’t need original sentence anymore
Generalized modus ponens
• for all x: Loves(John, x)
• John loves every thing
• Example
Semantic networks: Common Relations
Example:
Semantic networks: Common Relations
2. is_a Relation is an inherence relation between two abstract concepts.
Also known as AKO (akind-of) relation
Example:
Example:
Semantic Networks: Example
Exercise:
Construct Semantic Net representations of the following
sentence:
Emus are birds and do run . Typically birds fly and have wings.
Semantic networks: Example
FRAMES
Frames
Example:
Frame hierarchy
• Frames are linked using values.
• E.g. in the previous example, hotel chair, hotel bed and hotel phone
values are used to form a link between hotel room frame and other
frames i.e. hotel chair frame, hotel bed frame and hotel phone.
Frame and predicate logic
Where:
S-slot
F-frame name
V-value
Frame and predicate logic
• Example:
• Translate the following predicate logic into a frame.
Solution
RULES
Rules
- In this approach knowledge is encoded as IF … THEN rules
-Each rule describes the relation between the premises and
the
conclusion
Example:
For example we may have the rule:
IF (hair) OR (drinks milk) THEN (mammal)
Rules: Mycin Sample Rule Example
• The following example shows one of the rules used by Mycin expert
system for representing knowledge
• Example
Rules: Traffic lights Example