Cs262a 1 Logic
Cs262a 1 Logic
Propositional Logic
A logic is defined by its syntax and semantics. The syntax of a logic defines the
class of statements that can be used to convey information. The semantics of a
logic defines properties of logical statements, such as satisfiability and validity,
in addition to relationships among these statements, such as equivalence and
implication. The goal of this chapter is to define the syntax and semantics of
propositional logic: one of the simplest and most commonly used logics.
1.1 Syntax
Propositional logic statements are formed using a set of propositional variables,
P1 , . . . , Pn . These variableswhich are also called Boolean variables, proposi-
tional symbols, atomic propositions, and atomsare variables that assume one
of two values, typically indicated by true and false. The simplest statement
one can write in propositional logic has the form Pi . It is called an atomic
statement and is interpreted as saying that variable Pi takes on the value true.
More complex statements in propositional logic are formed using logical con-
nectives. Specifically, sentences in propositional logic are formed according to
the following rules:
Every propositional variable is a sentence.
If and are sentences, then , , and are also sentences.
The symbols , and are called logical connectives and they stand for nega-
tion, conjunction and disjunction, respectively. Other connectives can also be
introduced such as implication and equivalence but these are defined in
terms of the three primitive connectives given above. In particular, the sentence
is a shorthand for . Similarly, the sentence is a shorthand for
() ().
An important syntactic notion in propositional logic is the propositional lit-
eral, which is a propositional variable Pi , called a positive literal, or the negation
of a propositional variable Pi , called a negative literal.
1
2 Class Notes for CS264A, UCLA
A B
X Y
1
2
..
.
Consider now the digital circuit in Figure 1.1, which has two inputs and one
output. Suppose that we want to write down a propositional knowledge base
that captures our knowledge, or some of it, about the behavior of this circuit.
The very first step we have to consider is that of choosing the set of propositional
variables. There are a number of choices here. First, we may take the set of
propositional variables to be 1 = A, B and write the simple knowledge base:
1 = A B
A third knowledge base one can write involves the set of propositional vari-
ables 3 = A, B, C, X, Y :
A X
A X
AB Y
3 =
(A B) Y
X Y C
(X Y ) C,
which includes propositional variables for the internal wires in the circuit. Ob-
viously, these knowledge base vary in the amount of information they convey,
where knowledge base 3 is the most informative, yet also the most complex.
Which one of these knowledge bases is most suitable depends on the application
we have in mind. For example, if our goal is to check whether two circuits over
inputs A and B have the same functionality, then knowledge base 1 is sufficient
since it completely characterizes the functionality of given circuit. However, if
we are interested in reasoning about the internal behavior of the circuitsuch as
whether X being high implies that Y is lowthen knowledge base 3 is what
we need since the other two knowledge bases do not even allow us to phrase
logical questions about the state of internal wires in the circuit.
The main point behind the previous example is that the choice of proposi-
tional variables is quite important, and must be made in the context of given
application, which in turns fixes the kind of logical questions one may want to
pose with respect to the knowledge base.
1.2 Semantics
The syntax of propositional logic specifies rules for composing grammatically
correct sentences. The semantics of propositional logic defines logical properties
of such sentences, including consistency and validity, and logical relationships
among sentences, including implication and equivalence.
These logical properties and relationships are easy to figure out for simple
sentences. For example, most people would agree that
A A is inconsistent,
A A is valid,
A and AB imply B, and
A B is equivalent to B A.
Yet, it may not be as obvious that AB and BA are equivalent, or that
(AB)(AB) implies A.1 For this reason, one needs a formal definition of
logical properties and relationship, especially if one is to automate the decision
of these notions.
1 It is not uncommon for people to claim that (AB) (AB) is inconsistent, which is
not correct.
4 Class Notes for CS264A, UCLA
|= iff 6|= .
|= iff |= or |= .
|= iff |= and |= .
Alarm((Earthquake Burglary)Alarm).
6 Class Notes for CS264A, UCLA
The symbol true is often used to denote a sentence which is valid.3 Moreover,
it is common to write |= in order to indicate that sentence is valid.
We close this section by defining a third logical property of sentences, that
of completeness. Specifically, we say that a sentence is complete iff it is true
at exactly one world. Intuitively, a complete sentence is very affirmative as
it communicates knowledge of the exact state of the world. Going back to our
previous example, the sentence EarthquakeBurglary is not complete as it is true
at six possible worlds, 1 , . . . , 6 . The sentence Earthquake Burglary Alarm
is complete though as it is true at exactly one world, 7 .
Mods() = Mods().
The function Mods is very useful. First, it allows us to define logical notions
tersely. If denotes the set of all worlds, then
Second, the function Mods plays an important role in providing insights into
the semantics of propositional logic. The key concept here is to view ones
knowledge as a set of worlds that characterize all possibilities. In a complete
state of ignorance, every world is a possibility and, hence, our knowledge consists
in the set of all worlds . As we know more, some of these worlds are deemed as
impossible and, hence, the set of possible worlds starts shrinking. Specifically,
when someone communicates sentence to us, they are telling us that only
worlds in Mods() are possible, and every world outside Mods() is impossible.
Therefore, our state of knowledge in this case is Mods(). If we learn in
addition, our state of knowledge will be Mods( ) = Mods() Mods()
since only these worlds are possible, and every other world is impossible. We
reach a complete state of knowledge when we deem all worlds as impossible,
except for exactly one world.
Let us illustrate this concept of knowledge as a set of possible worlds using
the earthquakeburglaryalarm example that we introduced earlier. There are
eight worlds in this example, corresponding to eight possible ways the world
4 This can be generalized to an arbitrary number of sentences as follows. Sentences
1 , . . . , n are mutually exclusive iff Mods(i ) Mods(j ) = for i 6= j.
5 This can be generalized to an arbitrary number of sentences as follows. Sentences
1 , . . . , n are exhaustive iff Mods(1 ) . . . Mods(n ) = .
8 Class Notes for CS264A, UCLA
could be. For example, the second world 2 corresponds to the situation where
we have an earthquake and a burglary, but the alarm did not go off. In a
complete state of ignorance about this example, all of these eight situations are
possible. Hence, our state of knowledge is the set of all eight worlds 1 , . . . , 8 .
Suppose now that someone communicates to us the following sentence,
: (Earthquake Burglary)Alarm.
Mods() = {1 , 3 , 5 , 7 , 8 }.
This is depicted in the following table, in which the sentence can be viewed
as having ruled out all worlds that are outside Mods():
: EarthquakeBurglary,
which is one less world than it used to be. This is depicted by the following
table:
Table 1.1: Some equivalences among sentence schemas. The last two can be
viewed as definitions of the and connectives.
Mods ( )
Mods( )
Figure 1.2: The relationship between the models of and assuming that
implies .
Relationship Property
implies is unsatisfiable
implies is valid
and are equivalent is valid
and are mutually exclusive is unsatisfiable
and are exhaustive is valid
If |= , then is equivalent to .
These equivalences and others can be usually proven using the Mods function
and its properties. We will now provide an example proof of the following: If
|= , then is equivalent to .
Suppose that |= . We then have Mods() Mods(), leading to the
picture in Figure 1.2. It should be clear now that Mods()Mods() = Mods()
and, hence, Mods( ) = Mods() by the properties of Mods. It then follows
immediately that is equivalent to by definition of equivalence.
Mods ( )
Mods( )
Figure 1.3: The relationship between the models of arbitrary sentence and .
The shaded area represents the set of worlds Mods() Mods().
One can also prove these reductions using the Mods function and its prop-
erties. To illustrate this technique, we will next prove two of the reductions in
Table 1.2, which are known as the Refutation and Deduction theorems.
This theorem is quite commonly used in mathematical proofs under the label
proof by contradiction. That is, to show that implies , we assume ,
assume , and then try to show a contradiction. When one is found, we
declare that implies . This method of reducing the implication test to a
satisfiability test is also predominant in automated reasoning systems as we
shall discuss later.
To prove this theorem we recall that
We will now prove this theorem assuming that we have accepted the Refutation
theorem, and by showing that is valid iff is inconsistent.
First, we recall that sentence is valid iff its negation is inconsistent:
This follows immediately from the properties of Mods since Mods() = Mods().
All we have to show now is that is equivalent to the negation of ,
which proves that is valid iff is inconsistent:
Conditioning
The first of these operators is known as conditioning and allows one to eliminate
a variable from a knowledge base, given that we know the value of that variables.
Specifically, to condition a knowledge base on a positive literal P is to replace
every occurrence of P in by true. Moreover, to condition a knowledge base
on a negative literal P is to replace every occurrence of P in by false.
The result of conditioning knowledge base on literal is denoted by | and
a key property of | is that it does not mention the variable of literal .
Using the conditioning operator, one can define Booles expansion which
has major applications in recursive algorithms that we discuss later. Given a
knowledge base and a variable P , Booles expansion allows us to rewrite
as follows:
P |P P |P .
The key property of this expansion is that both |P and |P do not mention
variable P . Therefore, this expansion allows us to reduce a query with respect
to a knowledge base over n variables into two queries on knowledge bases over
n 1 variables. If Booles expansion is applied recursively to the newly created
knowledge bases, it can then be used to decompose a complex knowledge base
down to trivial knowledge bases that are equivalent to either true or false. We
will see many examples of such application in future chapters.
If the value of a variable is not known, we can still eliminate it from a
knowledge base while preserving important properties of the original knowledge
base. There are two methods for eliminating a variable in this case, which we
discuss next.
c 2004
Adnan Darwiche 13
Existential quantification
The first operator for eliminating a variable P from a knowledge given
that the value of P is unknownis to existentially quantify variable P out of
knowledge base :
def
P = |P |P .
Consider the knowledge base
A B
=
B C,
which can be written as
A B
=
B C.
We then have
|B = (A true) (true C) = C,
and
|B = (A false) (false C) = A,
leading to
B = A C = AC.
Note here that B is implied by . This is true in general for any knowledge
base and any variable:
|= P .
We even have a stronger property for existential quantification. Let be the set
of all propositional variables. Then not only is P implied by , but it also
contains all the information that contains about the variables \ P . That is,
if is a sentence which is constructed using the variables \ P , then
|= iff P |= .
XY |C = A B,
which is even a less informative description of the given circuit as it only char-
acterizes circuit input under which the circuit will produce a high output.
Universal quantification
The other method for eliminating a variable P from a propositional knowledge
base is by universally quantifying P out of knowledge base :
def
P = |P |P .
|= iff |= P .
Duality
Existential and universal quantifiers are related by the following dualities:
P = (P ),
P = (P ).
It is always possible to quantify over more than one variable and the order of
quantification does not matter for the same quantifier. Hence, P Q is equiv-
alent to QP and similarly for universal quantification. We will therefore
simply write P, Q and P, Q instead of P Q and P Q, respectively,
whenever convenient.
c 2004
Adnan Darwiche 15
|= |P iff [P ] |= .
|= |P iff [P ] |= .
|= P iff [P ] |= or [P ] |= .
|= P iff [P ] |= and [P ] |= .
Given the above extensions to the satisfiability relationship between worlds and
sentences, one can immediately extend the function Mods to sentences that
include conditioning and quantification operators. All logical properties and re-
lationships are then defined, therefore, providing formal semantics to quantified
propositional logic.
Queries
The set of queries we have identified are as follows, where and are knowledge
bases:
CO Testing whether a is satisfiable.
Probably the key observation about the above queries is that their difficulty
depends on the syntactic form of given knowledge bases. For example, CO is
hard on arbitrary propositional sentences, but becomes easy if the sentence is
a disjunction of terms, known as Disjunctive Normal Form (DNF). Moreover,
validity is also quite difficult on arbitrary sentences, but becomes easy if the
sentence is a conjunction of clauses, known as Conjunctive Normal Form (CNF).
Another observation about the above queries is that some are more general
than others. For example, enumerating models is more general than counting
these models as one can count models as a side effect of enumeration. Moreover,
IM is more general than IP since clauses are a special case of knowledge bases.
We make this distinction, however, since IM is much more difficult than IP,
yet IP is quite useful in many applications.
Transformations
We now turn to transformations of knowledge bases, where and are knowl-
edge bases:
NEG Negating .
Given the definition of these transformations, it may appear that they are easy
to perform as they all can be implemented in time linear in the size of given
KBs. This ceases to be true, however, once we restrict the syntactic form of
KBs. For example, negating a KB is straightforward, but becomes difficult if
we insist that both the original and negated KB are in CNF. We will in later
chapters discuss a large number of syntactic forms and enumerate the difficulty
of the above operations on each of these forms.
c 2004
Adnan Darwiche 17
{A, C, ok (X), ok (Y )}
is satisfiable. The answer is no in this case, indicating that the observed be-
havior is abnormal. Hence, we used the satisfiability query to decide whether a
particular device behavior is abnormal.
Let us now define a device state to be an assignment of true/false to the
health variables ok (X) and ok (Y ). And suppose that our goal is to count the
number of states that the circuit can be in, given that we have observed the
input A to be high, and the output C to be low. One way to do this is using
two more operations on the KB: existential quantification and model counting.
Specifically, we existentially quantify variables A, B and C out of the KB
{A, C}, leading to the new KB, {ok (X) ok (Y )}, which characterizes the
circuit health under given observation. We then count the models of this new
18 Class Notes for CS264A, UCLA
KB, which turns out to be 3. These models correspond to the possible states
of given circuit and we may want to enumerate them, leading to the following:
{ok (X), ok (Y )}, {ok (X), ok (Y )}, and {ok (X), ok (Y )}.
If b1 and b2 are Boolean values, then b1 .b2 is the product of these values,
and b1 + b2 is the maximum of these values.
Using these operations, one can build complex Boolean functions from simpler
ones. For example, if f (X1 , . . . , Xn ) and g(X1 , . . . , Xn ) are two Boolean func-
tions, then f (X1 , . . . , Xn ), f (X1 , . . . , Xn ).g(X1 , . . . , Xn ), and f (X1 , . . . , Xn ) +
g(X1 , . . . , Xn ) are Boolean functions.
The conditioning and quantification operators have parallels on Boolean
functions. Specifically, the conditioning operator corresponds to the restriction
operator, where the restriction of function f (X1 , . . . , Xn ) to Xi = b, denoted
f |Xi =b , is the function f (X1 , . . . , Xi1 , b, Xi+1 , . . . , Xn ), which results from fix-
ing the value of variable Xi to b. Note that the restriction f |Xi =b is a Boolean
function over n 1 variables.
The Shannon expansion of Boolean function f (X1 , . . . , Xn ) with respect to
variable Xi is given by the following identity:
f = Xi .f |Xi =1 + Xi .f |Xi =0 .
c 2004
Adnan Darwiche 19
A B
X Y
A B fC (A, B)
0 0 1
0 1 1
1 0 0
1 1 1
A Type II Boolean function for a circuit is a function over the circuit inputs
and outputs. When evaluated under a particular assignment of values to inputs
and outputs, the Boolean function returns 1 iff the circuit generates the given
outputs under the given inputs. The Type II Boolean function for the circuit
in Figure 1.5 is:
A B C g(A, B, C)
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
A Type I Boolean function for a circuit is a function over the circuit inputs,
outputs, and all internal wires (that are neither inputs nor outputs). When
evaluated under a particular assignment of values to wires, the Boolean function
returns 1 iff the given assignment is compatible with the circuit behavior. The
Type I Boolean function for the circuit in Figure 1.5 is a function h over variables
A, B, C, X, Y . It is shown partially below:
c 2004
Adnan Darwiche 21
A B C X Y h(A, B, C, X, Y )
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 1 0
.. .. .. .. .. ..
. . . . . .
0 0 1 1 0 1
.. .. .. .. .. ..
. . . . . .
We can always obtain Type III and Type II functions from a Type I function
using existential quantification. For the above circuit, we have g = XY h.
Moreover, we have fC = XY h|C=1 . The Type III function fC can also be
obtained from the Type II function using fC = g|C=1 . These constructions are
general and work for other circuits as well.
A B f (i )
1 : 1 1 0
2 : 1 0 1
3 : 0 1 1
4 : 0 0 1
The solutions of this function are 2 , 3 , 4 . Consider now the knowledge base
= (A B) and its corresponding set of possible worlds:
world A B
1 true true
2 true false
3 false true
4 false false
The knowledge base corresponds to the Boolean function f since Mods() =
2 , 3 , 4 . The knowledge base = A B also corresponds to function f
since is equivalent to .
The language of propositional logic can therefore be viewed as a specification
language for Boolean functions, since each knowledge base corresponds to a
22 Class Notes for CS264A, UCLA
unique Boolean function which we shall denote by f . Moreover, the tools for
reasoning within propositional logic can be viewed as an apparatus for reasoning
about Boolean functions.
One can also define [Pi=v] to be a world that agrees with on all variables,
except possibly on P where [Pi =v] assigns the value v to Pi . We can then
extend the satisfiability relationship |= as follows:
|= Pi = v iff (Pi ) = v.
|= iff 6|= .
|= iff |= or |= .
|= iff |= and |= .
|= |(Pi=v) iff [Pi=v] |= .
|= P iff [Pi=v] |= for some value v.
|= P iff [Pi=v] |= for all value v.
Based on this relationship, other logical notions such as satisfiability, validity,
implication and equivalence can be defined, therefore, providing formal seman-
tics to propositional logic with discrete variables.