COMPSCI 367
Tutorial 1
LOGIC AND KNOWLEDGE
REPRESENTATION
By: Aashmeet Kalra
AGENDA
• Different types of logic representation
• 5 mins. brush up of concepts discussed in class
• Sample examples for Knowledge
Representation
• Practice questions
• Introduction to Prolog.
Why ???
The big problem for AI is what to say not how to
say it. The predicate calculus [formal logic]
does no more than provide a uniform
language in which knowledge about the world
can be expressed and reasoned about.
- Nils Nilsson
Propositional Logic
• Syntax
– Propositions, e.g. “it is wet”
– Connectives: and, or, not, implies, iff (equivalent)
– Brackets, T (true) and F (false)
• Semantics (Classical AKA Boolean)
– Define how connectives affect truth
• “P and Q” is true if and only if P is true and Q is true
– Use truth tables to work out the truth of statements
Predicate Logic
• Propositional logic combines atoms
– An atom contains no propositional connectives
– Have no structure (today_is_wet, john_likes_apples)
• Predicates allow us to talk about objects
– Properties: is_wet(today)
– Relations: likes(john, apples)
– True or false
• In predicate logic each atom is a predicate
– e.g. first order logic, higher-order logic
First Order Logic
• More expressive logic than propositional
– Used in this course (Lecture 6 on representation in FOL)
• Constants are objects: john, apples
• Predicates are properties and relations:
– likes(john, apples)
• Functions transform objects:
– likes(john, fruit_of(apple_tree))
• Variables represent any object: likes(X, apples)
• Quantifiers qualify values of variables
– True for all objects (Universal):
X. likes(X, apples)
– Exists at least one object (Existential): X. likes(X, apples)
Simple Examples
•
“Every rose has a thorn”
For all X
– if (X is a rose)
– then there exists Y
•
•
(X has Y) and (Y is a thorn)
Everyone who loves all animals is loved by someone:
∀x [∀y Animal(y) ⇒ Loves(x,y)] ⇒ [∃y Loves(y,x)]
Examples (contd)
• “You can fool some of the people all of the time.”
(Ǝx) (person(x) ^ (Ʉt)(time(t) => can-fool(x,t)))
• “ You can fool all of the people some of the time”
(Ʉx) (person(x) => (Ǝt) (time(t) ^ can-fool(x,t)))
• “Every team defeats some other team”
Ʉx: (IsTeam(x) => (Ǝ y: (IsTeam(y) ᶺ NOT(x=y) ᶺ Defeats(x,y))))
Examples(contd).
• “Any person who has an umbrella is not wet”
Ʉ x: (IsPerson(x) => ((Ǝ y: (Has(x, y) ᶺ IsUmbrella(y))) =>
NOT(IsWet(x)))) .
• “John has at least two umbrellas”.
Ǝ x: (Ǝ y: (Has(John, x) ᶺ IsUmbrella(x) ᶺ Has(John, y) ᶺ IsUmbrella(y)
ᶺNOT(x=y))
• “John has at most two umbrellas”.
Ʉ x, y, z: ((Has(John, x) ᶺ IsUmbrella(x) ᶺ Has(John, y) ᶺ IsUmbrella(y) ᶺ
Has(John, z) ᶺ IsUmbrella(z)) => (x=y ˅ x=z ˅ y=z))
Even more Examples…..
“X is above Y if X is on top of Y or else there is a pile of one or
more other objects directly on top of one another starting
with X and ending with Y.”
Ʉx Ʉy: above(x,y) (on(x,y) ˅ Ǝz (on(x,z) ᶺabove(z,y)))
“No mortal lives longer than 150 years”
Ʉx Ʉt1 Ʉt2 mortal(x) ᶺ born(x,t1) ᶺ gt(t2-t1,150) => dead(x,t2)
Applications
• Question-Answering
• Inferencing and Problem Solving
Sample Questions to Practice
Represent the following sentences in first-order logic, using a consistent vocabulary
• Some students took French in spring 2001.
• Every student who takes French passes it.
• Only one student took Greek in spring 2001.
• The best score in Greek is always higher than the best score in French.
• Every person who buys a policy is smart.
• No person buys an expensive policy.
• There is an agent who sells policies only to people wha are not insured.
• There is a barber who shaves all men in town who do not shave themselves
• A person born in the UK, each of whose parents is a UK citizen or a UK
resident, is a UK citizen by birth.
• A person born outside the UK, one of whose parents is a UK citizen by
birth, is a UK citizen by birth, is a UK citizen by descent.
• Politicians can fool some of the people all the time, and they can fool all
of the people some of the time, but they can’t fool all the people all the
time.
Refutation Proofs
(1) Cats like fish : cat (x) likes (x,fish)
(2) Cats eat everything they like :
cat (y) likes (y,z) eats (y,z)
(3) Josephine is a cat. :cat (jo)
(4) Prove: Josephine eats fish.
To Prove: eats (jo,fish)
Solution
Negation of goal wff: eats(jo, fish)
eats(jo, fish)
cat(y) likes(y, z) eats(y, z)
= {y/jo, z/fish}
cat(jo) likes(jo, fish)
cat(jo)
=
cat(x) likes(x, fish)
likes(jo, fish)
= {x/jo}
cat(jo)
cat(jo)
(contradiction)
Sample Problem to practice
• You know the following things:
You have exactly one other person living in your house, who is wet
If a person is wet, it is because of the rain, the sprinklers, or both
If a person is wet because of the sprinklers, the sprinklers must be on
If a person is wet because of rain, that person must not be carrying
any umbrella
– There is an umbrella that “lives in” your house, which is not in its
house
– An umbrella that is not in its house must be carried by some person
who lives in that house
– You are not carrying any umbrella
–
–
–
–
• Can you conclude that the sprinklers are on?
Logic is a Good Representation
• Fairly easy to do the translation when possible
• Branches of mathematics devoted to it
• It enables us to do logical reasoning
– Tools and techniques come for free
• Basis for programming languages
– Prolog uses logic programs (a subset of FOL)
– Prolog based on HOL
Introduction to Prolog
There are 2 major programming language used for AI
research
LISP (List Processing)
• older (1957), more established in the U.S.
• uses a functional style (but is still declarative)
• CLIPS is based on LISP
Prolog (Programming in Logic)
• newer (1971), more widely used in Europe & Asia
• uses a totally declarative style, a.k.a. logic programming
• attractive features: built-in notion of search
• general data structures
• powerful primitives for symbol manipulation
More Prolog Intro
• Prolog evolved out of the automated
deduction community – 2 drivers:
(1) focus on a subset of predicate calculus
programs are collections of logical statements & relations.
(2) implement a simple but efficient proof procedure
Prolog interpreter applies inference rules to perform
deduction
logic programming: computation = logical deduction from
program statements
Readings for Next Tutorial
Introduction
Reading: Read Chapter 1 of Bratko
© Copyright 2026 Paperzz