CS 540 Lecture Notes - Logic
CS 540 Lecture Notes - Logic
Dyer
Logic (Chapter 7)
Logic for Knowledge Representation and Reasoning
One of the core problems in developing an intelligent system is knowledge representation, i.e.,
solving the problems of (1) how to represent the knowledge one has about a problem domain, and (2)
how to reason using that knowledge in order to answer questions or make decisions
Knowledge representation deals with the problem of how to model the world sufficiently for intelligent
action
Logic is one of the oldest representation languages studied for AI, and is the foundation for many
existing systems that use logic as either inspiration or the basis for the tools in that system (e.g., rule-
based expert systems and the Prolog programming language)
For a knowledge-based intelligent agent, we need:
To represent knowledge about the world in a formal language
To reason about the world using inferences in the language
To decide what action to take by inferring that the selected action is good
Representation Languages
Logic
Logic is a formal system in which the formulas or sentences have true or false values
A logic includes:
Syntax: Specifies the symbols in the language and how they can be combined to form sentences.
Hence facts about the world are represented as sentences in logic
Semantics: Specifies what facts in the world a sentence refers to. Hence, also specifies how you
assign a truth value to a sentence based on its meaning in the world. A fact is a claim about the
world, and may be true or false.
Inference Procedure: Mechanical method for computing (deriving) new (true) sentences from
existing sentences
Facts are claims about the world that are True or False, whereas a representation is an expression
(sentence) in some language that can be encoded in a computer program and stands for the objects and
relations in the world
We need to ensure that the representation is consistent with reality, so that the following figure holds:
entails
Representation: Sentences --------------> Sentences
| |
| |
| Semantics | Semantics
| refer to | refer to
| |
\/ follows \/
World: Facts ------------------> Facts
Truth: A sentence is True if the state of affairs it describes is actually the case in the world. So, truth
can only be assessed with respect to the semantics. Yet the computer does not know the semantics of
the knowledge representation language, so we need some way of performing inferences to derive valid
conclusions even when the computer does not know what the semantics (the interpretation) is
To build a logic-based representation:
User defines a set of primitive symbols and the associated semantics
Logic defines the ways of putting these symbols together so that the user can define legal
sentences in the language that represent true facts in the world
Logic defines ways of inferring new sentences from existing ones
Let KB = { S1, S2,..., SM } be the set of all sentences in our Knowledge Base, where each Si is a sentence in
Propositional Logic. Let { X1, X2, ..., XN } be the set of all the symbols (i.e., variables) that are contained in
all of the M sentences in KB. Say we want to know if a goal (aka query, conclusion, or theorem) sentence G
follows from KB.
Since the computer doesn't know the interpretation of these sentences in the world, we don't know whether
the constituent symbols represent facts in the world that are True or False. So, instead, consider all possible
combinations of truth values for all the symbols, hence enumerating all logically distinct cases:
X1 X2 ... XN | S1 S2 ... SM | S1 ^ S2 ^...^ SM | G | (S1 ^...^ SM) => G
-------------|--------------|------------------|---|-------------------
F F ... F | | | |
F F ... T | | | |
... | | | |
T T ... T | | | |
The truth table method of inference is complete for PL (Propositional Logic) because we can always
enumerate all 2^n rows for the n propositional symbols that occur. But this is exponential in n. In
general, it has been shown that the problem of checking if a set of sentences in PL is satisfiable is NP-
complete. (The truth table method of inference is not complete for FOL (First-Order Logic).)
Example
Using the "weather" sentences from above, let KB = (((P ^ Q) => R) ^ (Q => P) ^ Q) corresponding to the
three facts we know about the weather: (1) "If it is hot and humid, then it is raining," (2) "If it is humid, then
it is hot," and (3) "It is humid." Now let's ask the query "Is it raining?" That is, is the query sentence R
entailed by KB? Using the truth-table approach to answering this query we have:
P Q R | (P ^ Q) => R | Q => P | Q | KB | R | KB => R
-----------------------------------------------------
T T T T T T T T T
T T F F T T F F T
T F T T T F F T T
T F F T T F F F T
F T T T F T F T T
F T F T F T F F T
F F T T T F F T T
F F F T T F F F T
Hence, in this problem there is only one model of KB, when P, Q, and R are all True. And in this case R is
also True, so R is entailed by KB. Also, you can see that the last column is all True values, so the sentence
KB => R is valid.
Instead of an exponential length proof by truth table construction, is there a faster way to implement the
inference process? Yes, using a proof procedure or inference procedure that uses sound rules of inference
to deduce (i.e., derive) new sentences that are true in all cases where the premises are true. For example,
consider the following:
Since whenever P and P => Q are both true (last row only), Q is true too, Q is said to be derived from these
two premise sentences. We write this as KB |- Q. This local pattern referencing only two of the M sentences
in KB is called the Modus Ponens inference rule. The truth table shows that this inference rule is sound. It
specifies how to make one kind of step in deriving a conclusion sentence from a KB.
Therefore, given the sentences in KB, construct a proof that a given conclusion sentence can be derived from
KB by applying a sequence of sound inferences using either sentences in KB or sentences derived earlier in
the proof, until the conclusion sentence is derived. This method is called the Natural Deduction procedure.
(Note: This step-by-step, local proof process also relies on the monotonicity property of PL and FOL. That
is, adding a new sentence to KB does not affect what can be entailed from the original KB and does not
invalidate old sentences.)
A proof is a sequence of sentences, where each sentence is either a premise or a sentence derived from earlier
sentences in the proof by one of the rules of inference. The last sentence is the query (also called goal or
theorem) that we want to prove.
1. Q Premise
2. Q => P Premise
3. P Modus Ponens(1,2)
4. (P ^ Q) => R Premise
5. P^Q And Introduction(1,3)
6. R Modus Ponens(4,5)
Completeness: If KB |= Q then KB |- Q
That is, if Q is entailed by a set of sentences KB, then Q can be derived from KB using the rules of
inference. Hence, inference produces all entailments, or all valid sentences can be proved from the
premises.
How can these sentences be represented so that we can infer the third sentence from the first two? In PL we
have to create propositional symbols to stand for all or part of each sentence. For example, we might do:
That is, we have used four symbols to represent the three given sentences. But, given this representation, the
third sentence is not entailed by the first two.
A different representation would be to use three symbols to represent the three sentences as
In this case the third sentence is entailed by the first two, but we needed an explicit symbol, Confucius, to
represent an individual who is a member of the classes "person" and "mortal." So, to represent other
individuals we must introduce separate symbols for each one, with means for representing the fact that all
individuals who are "people" are also "mortal." First-Order Logic (abbreviated FOL or FOPC) is
expressive enough to concisely represent this kind of situation.