Introduction to Knowledge Representation and Logic
All our search programs seem quite special purpose. Even though the search algorithm may be general, we
have to code up the problem representation and heuristic function ourselves. This is true even of GPS -- the
general problem solver may (or may not) be a general search algorithm. But computing the differences and
representing the problem were left as a black art.
Wouldn't it be nice if we could build a more general purpose program. One way to do this is to build a
program that could learn by being told. (This idea goes back at least to John McCarthy's (1958) suggestion
of an “ .)
advice taker” Then we can just tell our program about the rules of checkers, and give it some ideas
about how to play well.
What we need is some language to express these things in. We'll call this a knowledge representation
One important characteristic of the language is that it should be expressive enough to say everything we
What about LISP? Seems reasonable for certain kinds of knowledge. But:
• But we might miss certain generalizations if everything was code. Imagine have a different program
for dialing each telephone number. It would seem better to have a single “ telephone dialing”
procedure, and have our numbers expressed as data to this program. Similarly, a program with a
telephone-number-as-data would have difficulty letting you what it knew (although it might run very
efficiently). It is this idea of expressing our knowledge as data that we usually mean when we talk
about a KRL.
• There is a procedural/declarative distinction about how we should represent knowledge, i.e., as
programs or as data. Declarative representations would seem to offer us the flexibility that we need
for AI. (Also, declarative representations seem more amenable to introspection and articulation than
• Procedural knowledge is still knowledge, though (“ know-how”versus “ ).
know-that” So some of our
knowledge is procedurally encoded. E.g., I can tell you my phone number, and if you paid attention,
you would know it, but if I tell you how to play tennis well, you probably wouldn't play much better
without some practice.
• Declarative representations still need to have a program that looks at them and does things. This is
called an interpreter. E.g., in our telephone dialing example, the telephone dialing program
interprets telephone numbers.
What about English, i.e., some natural language? Probably expressive enough. But:
• Ambiguity (“ saw her duck.”
• Context-dependent meanings (pronouns, deictic references)
• Non-compositionality (idioms)
(More on these later.) In general, we'd like a declarative language that is unambiguous, context-
independent, and compositional, in addition to being expressive enough. So we'll make one up!
It has been suggested that some sort of logic should be used. We'll investigate this idea.
2 Introduction to Logic
• We'll assume that we can describe the world in terms of sentences in our language.
A knowledge base is a set of sentences. I.e., it is partial description of the world (we hope).
Sentences can be completely disembodied; however, we can also use sentences to describe mental
states of agents. For example, we might say a sentence represents an agent's belief, or that a
knowledge base is what this agent knows. (Actually, there are lots of relations an agent can have
toward sentences: belief, doubt, thinking about. The philosophers call these propositional attitudes.
• Our sentences hopefully correspond to the world. Exactly how a sentence corresponds to the world
is its interpretation. For natural language, we have conventions that help us a lot. But since we are
making up a language, we don't have any conventions to rely on, and we'll have to specify this
ourselves. More on this latter.
• The “world”as we will talk about it will generally be fairly small part of the whole world. We call this
the universe of discourse (or domain of discourse).
• We'll say that a sentence is true if its interpretation corresponds to what's actually out there. E.g.,
Bush likes baseball.
is true given the normal interpretation of things.
• Some lucky sentences are true no matter what is out there, and no matter how we interpret them.
These usually aren't so interesting. E.g.:
Everyone who likes baseball likes basebll.
We say that such sentences valid; they are also called tautologies or analytic sentences.
What about the following?
Everyone who hates baseball doesn't like it.
Is it valid? No, because we could have an interpretation in which “hate”and “like”have nothing to
do with each other.
Of course, in the interpretation that corresponds to our normal understanding, this sentence would
be true. We say that sentences that are true in some interpretation are satisfiable.
Similarly, a sentence is unsatisfiable if it is false, no matter what. E.g.:
Bush likes baseball and Bush doesn't like baseball.
• Note that all our sentences are just descriptions. In natural language we can “ lots more. For
example, we can ask questions, give commands, express incredulity, etc. We don't have anything
that corresponds to these notions in the sort of logic we'll look at, so this is a big limitation. Note in
particular that “truth”per se doesn't apply to questions or commands.
Now, there are lots of different kinds of logics. A logic consists of
• A language. We can think of this as having a syntax, a vocabulary, plus some operators or
connectives, along with rules for combining them, all which we will have to formally define. We also
need some way of assigning meanings to the sentences of our language, for tell us how to interpret
them. For this we'll use something called model theory.
• An inference procedure. This is also called a proof theory. It tells us how to make valid inferences
from a set of sentences in our language (regardless of what they mean).
Note that the inference procedure of a logic is deductive, i.e., it is supposed to always produce valid
inferences. But there are other kinds of inference procedures: E.g., induction and abduction.
There are different reasons people are attracted to logic. One is that it has nice properties as a
representation language. But the other is that we can device logics that have sound and complete
inference procedures, i.e., where all the inferences are entailed by other sentences, and in which all entailed
sentences have proofs. This is an interesting property for reasoning, but whether it is an important one is
something to think about.
3 Propositional Calculus
Let's take a look at a very simple logic, propositional calculus. Its vocabulary is some set of symbols (e.g.,
P, Q, etc.) and a set of logical connectives (e.g., ∨ (or), ∧ (and), ¬ (not), and maybe → (implies)). (We also
allow parenthesis for grouping.)
We could write out a formal grammar of the language, but basically, all sentences are either
• A vocabulary symbol
• Sentences joined by logical connectives
For example: (P ∧ Q) → R is a sentence. So is ¬ P and P ∧ ¬ P
What do these mean? A symbol refers to some particular fact (any one you like). Thus we can say that P is
true when the fact it refers to is true, etc.
The bigger sentences are true or false as a function of the truth of their components and the logical
connectives. We can specify the way each connective works by a truth table:
P Q P→ Q
0 0 1
0 1 1
1 0 0
1 1 1
The connectives of a logic are like this, in that they are truth conditional, meaning you can tell the truth of a
sentence using them strictly from the truth of its parts. (This doesn't seem to be true for natural language,
even for the correspondingly named terms. For example, consider:
Bush having used heroin implies that he will legalize drugs.
This is presumably false in the usual interpretation of “ ,
implies” but true in the truth conditional one.
So the “model theory”for propositional calculus is real simple: Just assign a symbol to a fact, and the any
sentence is true or false depending on the assignment and the logical connection in it. That's all the
“meaning” we have.
What about a “proof theory”?
Note that it is possible to determine the proof of any sentence in propositional calculus by the use of a truth
table. We just build a truth table for the sentence and see if the sentence is true all the time.
However, it is generally convenient to capture some of these patterns in inference rules. For propositional
logic we sometimes just use “ ;
modus-ponens” usually we assume some more rules for convenience.
In general, while propositional logic inference procedures are complete, the problem of finding a proof is
generally regarded to be exponential. There are subcases which are better. For example, if we can express
all our knowledge in the form
P1 ∧ P2 ∧ P3 … ∧ Pn → Q
then there is a polynomial-time inference procedure. These are called Horn clauses. Not all knowledge
bases can be expressed this way.
In addition to the possible difficulty of making an inference, there is the problem that propositional calculus is
not expressive enough. For example, if P= “ is raining” Q= “, ,
Jan is outside” R = “ ,
Jan is wet” we can say
P ∧ Q → R. Then, by MP, if P ∧ Q, we could deduce R. But we would need an entirely different rule for Pat.
What we would like instead is to be able to say that this is true in general for things of people.