The Eight Logical Operations

advertisement
1.2 Logical Operations
In the previous section we looked at the two logical values 0 (false) and 1 (true). In this
section we shall look at the logical operations that take logical values, bits, propositions,
predicates or logical expressions and produce a new logical value, bit, proposition,
predicate or logical expression. These operations are used both in circuit design and also
in classical logic for the analysis of arguments in everyday discussions.
1.2.1 The Eight Logical Operations
There are 8 logical operations that we shall be interested in. They are
and
or
not
nor
nand
if-then
if-and-only-if
As indicated, these are used in logic design, classical logic and computer programming.
In the following p and q will denote two logical values, bits, propositions or logical
expressions.
And
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p and q
p.q
pq
pq
p&q
p && q
are all common ways of denoting the and operation applied to p and q. For example, we
tend to use “p and q” in everyday speech while p  q is used in classical logic. pq is used
in logic design and Boolean algebra while p & q and p && q are used in some
programming languages. We shall usually use pq, but sometimes we use p and q or p  q.
pq evaluates to 1 if both p and q both have the values 1. pq evaluates to 0 if either one or
both of p or q have the values 0.
Similarly, if 1 and 0 are replaced by true and false.
1.2.1 - 1
This definition of the and operation is often represented
by means of what is called a truth table. At the right is
a truth table for the and operation. Each row contains
one of the four possible combinations of truth values for
the variables p and q. These values are listed in the first
two columns with the first column having the value of p
and the second column having the value of q. The third
column has the value of pq when p and q have the values
in the first two columns. As one can see the only time pq
has the value 1 is when p and q both have the values 1. If
we use T and F for 1 and 0 then the truth table is at the
right.
p
0
0
1
1
q
0
1
0
1
p
F
F
T
T
pq
0
0
0
1
q
F
T
F
T
pq
F
F
F
T
If p and q are propositions or predicates then pq is the
proposition or predicate that is true only if p and q are both true. It is false otherwise.
Examples.
1.
If p is the statement "Lansing is the capital of Michigan" and q is "Toledo is the
capital of Ohio" then pq is "Lansing is the capital of Michigan and Toledo is the
capital of Ohio". pq is false since q is false since Columbus is the capital of Ohio.
On the other hand, the statement "Lansing is the capital of Michigan and
Columbus is the capital of Ohio" is true since both the statements "Lansing is the
capital of Michigan" and "Columbus is the capital of Ohio" are true.
For example, Billy’s teacher might say “Billy, what are the capitals of Michigan
and Ohio. If Billy answered "Lansing is the capital of Michigan and Toledo is
the capital of Ohio" we would regard this as a false statement, even though his
teacher might say “You are correct that Lansing is the capital of Michigan.
However, Columbus is the capital of Ohio”. The point is that we are being more
precise here that we might be in many everyday situations.
2.
Suppose
p = "I am wearing a raincoat"
q = "I am carrying an umbrella"
then
pq = "I am wearing a raincoat and I am carrying an umbrella"
Suppose we regard these as predicates so that they will become true or false when
we specify a time. When it comes time to evaluate this statement as to whether it
is true or false, then pq will be true if both the statements " I am wearing a
raincoat " and "I am carrying an umbrella" are true.
3.
(2 < 5) and (2*3  2 + 4)
This is true since both 2 < 5 and 2*3  2 + 4 are
true.
1.2.1 - 2
4.
(x < 5) and (3x  x + 4)
5.
Consider the following section of a computer program.
Whether or not this evaluates to true depends on
the value of x. For example, if x = 4 then it is
true. If x = 6 then it is false.
Temperature << cin;
Pressure << cin;
if ((temperature < 300) && (pressure < 30))
cout << "Everything is ok";
else
cout << "Turn engine off";
Here (temperature < 300) && (pressure < 30) is a logical expression that is
formed from the two simpler logical expressions "temperature < 300" and
"pressure < 30" using the and operation. When this section of code executes the
message "Everything is ok" will be displayed only if the value of the variable
temperature is less than 300 and the value of the variable pressure is less than 30.
Otherwise the message "Turn engine off" will be displayed.
6.
In circuit design there are devices called AND gates. They have two inputs and
one output. The electrical value of the output represents 1 if the electrical values
of both inputs represent 0. The electrical value of the output represents 0 if either
or both of the electrical values of the inputs represents 0. For example, it a
voltage near 0 volts represents 0 and a voltage near 5 volts
p
represents 1 and both inputs are near 5 volts then the output
pq
q
would be near 5 volts. The usual symbol for an AND gate
is at the right. The two lines going into the gate at the left
represent the inputs p and q and the line coming out of the gate represents the
output pq. A complete circuit using an AND gate is below. The light will be on
only if switches A and B are in the 1 position.
power
supply
5v
switch
A
1
line x
1
0
ground
switch
B
0
1.2.1 - 3
line y
line z = xy
light
Or
There are two different or operations. One we shall just call "or", while the other we
shall call "exclusive or". The first one which we just call "or" is sometimes called
"inclusive or". In everyday speech we use "or" for both of these operations and
sometimes we are not conscious of the distinction.
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p or q
p+q
pq
p|q
p || q
are all common ways of denoting the or operation
applied to p and q. We shall usually use p + q. p + q is
1 if either p or q or both are 1. p + q is 0 if both p and q
are 0. At the right is a truth table for the or operation.
In terms of true and false, p or q is true if either p or q or
both are true. p or q is false if both p and q are false. At
the right is the truth table expressed in terms of T and F.
p
0
0
1
1
q
0
1
0
1
p
F
F
T
T
p+q
0
1
1
1
q
F
T
F
T
p or q
F
T
T
T
If p and q are propositions or predicates then p or q is the proposition or predicate that is
true if either p or q or both are true. It is false only if both p and q are false.
Examples.
1.
If p is the statement "Lansing is the capital of Michigan" and q is "Toledo is the
capital of Ohio" then p or q is "Lansing is the capital of Michigan or Toledo is the
capital of Ohio". p or q is true since p is true. On the other hand, the statement
"Detroit is the capital of Michigan and Toledo is the capital of Ohio" is false
since both the statements "Detroit is the capital of Michigan" and "Toledo is the
capital of Ohio" are false.
2.
If p is the statement "I am wearing a raincoat" and q is "I am carrying an
umbrella" then p or q is "I am wearing a raincoat or I am carrying an umbrella".
When it comes time to evaluate this statement as to whether it is true or false,
then it will be true if either the statements " I am wearing a raincoat " or "I am
carrying an umbrella" or both are true.
3.
(2 > 5) or (2*3  2 + 4)
This is true since 2*3  2 + 4 is true.
1.2.1 - 4
4.
(x < 0) or (3x  x + 4)
5.
Consider the following section of a computer program.
Whether or not this evaluates to true depends on
the value of x. For example, if x = 4 then it is
true. If x = 1 then it is false.
Temperature << cin;
Pressure << cin;
if ((temperature >= 300) || (pressure >= 30))
cout << "Turn engine off";
else
cout << "Everything is ok";
Here (temperature >= 300) || (pressure >= 30) is a logical expression that is
formed from the two simpler logical expressions "temperature >= 300" and
"pressure >= 30" using the or operation. When this section of code executes the
message "Turn engine off" will be displayed if either the value of the variable
temperature is greater than or equal to 300 or the value of the variable pressure is
greater than or equal to 30. Otherwise the message "Everything is ok" will be
displayed.
6.
An OR gate in circuit design is pictured at the right. The electrical value of the
output represents 1 if either or both of the electrical values p
p+q
of both inputs represent 1. The electrical value of the
q
output represents 0 only if both of the electrical values of
the inputs represents 0. For example, it a voltage near 0 volts represents 0 and a
voltage near 5 volts represents 1 and if either or both inputs are near 5 volts then
the output would be near 5 volts. A complete circuit using an Or gate is below.
The light will be on only if either or both of the switches A and B are in the 1
position.
power
supply
5v
switch
A
1
line x
1
0
switch
B
0
ground
1.2.1 - 5
line y
line z = xy
light
Not
In contrast to the other logical operations, not is a unary operation. It operates on a single
operand instead of two. If p is a logical values, bit, proposition, predicates or logical
expression then
not p
p'
p
~p
_
p
!p
are all common ways of denoting the not operation applied to
p. We shall usually use p'.
p' is 1 if p is 0. p' is 0 if p is 1. If we apply the not operation
to p we often say we are inverting p. A truth table of the not
operation is at the right.
In terms of true and false, not p is true if p is false. not p is
false if p is true. At the right is the truth table expressed in
terms of T and F.
p
0
1
p'
1
0
p
F
T
not p
T
F
If p is a proposition or predicate then not p is the proposition or predicate that is true if p
is false. not p is false if p is true.
Examples.
1.
If p is the statement "Lansing is the capital of Michigan" then we would usually
express not p as "Lansing is not the capital of Michigan". This is a false
statement.
2.
If p is the statement "It is raining" then not p is the statement "It is not raining".
When it comes time to evaluate this statement as to whether it is true or false,
then it will be true if it is in fact not raining.
3.
not (2 > 5)
4.
not (x < 0)
This is true since since 2 > 5 is false.
Whether or not this evaluates to true depends on the value of x.
If x  0 then not (x < 0) is true. If x < 0 then
not (x < 0) is false.
1.2.1 - 6
5.
Consider the following section of a computer program.
Temperature << cin;
Pressure << cin;
if ( !(temperature < 300) )
cout << "Turn engine off";
else
cout << "Everything is ok";
Here !(temperature < 300) is a logical expression that is formed from the simpler
logical expression "temperature < 300" using the not operation. When this
section of code executes the message "Turn engine off" will be displayed if the
value of the variable temperature is greater than or equal to 300 . Otherwise the
message "Everything is ok" will be displayed. Most people would probably say
"if (temperature >= 300)" instead of "if not (temperature < 300)". However, there
are programming situations where it is convenient to use the not operator.
6.
An NOT gate in circuit design is pictured at the right.
p
p'
The electrical value of the output represents 1 if the
electrical value of the input represent 0. The electrical
value of the output represents 1 if the electrical value of the input represents 1.
For example, it a voltage near 0 volts represents 0 and a voltage near 5 volts
represents 1 and if the input is near 5 volts then the output would be near 0 volts.
A complete circuit using an OR gate is below. The light will be on only if
switche A is in the 0 position.
power
supply
5v
switch
A
1
line x
line z = x'
0
ground
Exclusive Or
Above we talked about the "regular" or operation or "inclusive or" operation. In this
course when we say or, we mean inclusive or. So p or q is true if either p is true or q is
true or both are true. Now we look at the "exclusive or" operation.
1.2.1 - 7
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p exor q
pq
pq
p != q
p <> q
p
q
pq
are common ways of denoting the exclusive or
0
0
0
operation applied to p and q. We shall usually use
0
1
1
p  q. p  q is 1 if one and only one of p and q is 1.
1
0
1
P  q is 0 if p and q are either both 0 or both 1.
1
1
0
Mathematically, exclusive or is the same as not equal,
but exclusive or tends to be used instead of not equal as
an operation on bits. At the right is a truth table for the exclusive or operation.
In terms of true and false, p exor q is true if either p or q
are true, but not both are true. p or q is false if either p
and q are both true or both false. At the right is the truth
table expressed in terms of T and F.
p
F
F
T
T
q
F
T
F
T
p exor q
F
T
T
F
If p and q are propositions or predicates then p exor q is
the proposition or predicate that is true if either p or q are
true, but not both are true. p or q is false if either p and q are both true or both false.
One problem is that in everyday speech we use or for both "inclusive or" or "exclusive
or". Usually the listener can tell from the context which is intended.
Examples.
1.
Suppose Billy comes home from school with a lot of homework. His mother says
"Billy you have a choice. Either you can watch your favorite TV show or you
can go out an play with your friends for an hour." In this case Billy's mother
means exclusive or instead of inclusive or.
2.
If p is the statement "Dallas is the capital of Texas" and q is "Houston is the
capital of Texas" then most people would probably say "Dallas is the capital of
Texas or Houston is the capital of Texas" for p exor q. The listener would
recognize that exor is intended since a state can't have two capitals. It turns out
that this statement is false since Austin is, in fact, the capital of Texas.
3.
Suppose p is the statement "I will be wearing a raincoat" and q is "I will be
carrying an umbrella". If Ellen says "Either I will be wearing a raincoat or I will
be carrying an umbrella" then she may mean the exclusive or of p and q implying
that she won’t be both wearing a raincoat and carrying an umbrella. When it
1.2.1 - 8
comes time to evaluate this statement as to whether it is true or false, then it will
be true if Ellen is wearing a raincoat or carrying an umbrella, but not both.
4.
(2 > 5)  (2*3  2 + 4)
This is true since 2 > 5 is false and 2*3  2 + 4 is
true.
5.
(x < 0)  (3x  x + 4)
Whether or not this evaluates to true depends on the
value of x. For example, if x = 4 then it is true.
If x = 1 then it is false.
6.
An EXOR gate in circuit design is pictured at the right. The electrical value of
the output represents 1 if either of the electrical values of
p
pq
the inputs represents 1, but not both. The electrical value
q
of the output represents 0 if either both of the electrical
values of the inputs represents 0 or both represents 1.
One can achieve the same result as the exclusive or operations by using the and, or and
not operations. There are several ways to do this. Two are
(p + q)(pq)'
pq' + p'q
p or q and not p and q
p and not q or q and not p
One can verify that these achieve the same result as exclusive or by means of a truth table.
p
0
0
1
1
q
0
1
0
1
pq
0
1
1
0
p+q
0
1
1
1
pq
0
0
0
1
(pq)'
1
1
1
0
(p + q)(pq)'
0
1
1
0
p'
1
1
0
0
q'
1
0
1
0
pq'
0
0
1
0
p'q
0
0
1
0
pq' + p'q
0
1
1
0
Note that the columns for p  q, (p + q)(pq)' and pq' + p'q are all the same. This says
they give the same logical value for the same values of p and q. So one can be used in
place of the other if all one cares about is the logical value of the result.
p  q, (p + q)(pq)' and pq' + p'q are examples of logical expressions, i.e. a combination of
logical variables and logical operators. Sometimes we use a capital letter, e.g. P or Q, to
denote a logical expression. For example, we might write P = (p + q)(pq)' or
Q = pq' + p'q.
Two logical expressions are equivalent if they give the same result for every possible
combination of logical values for the logical variables appearing in them. This occurs
precisely if they have the same truth table. We write P = Q if the two logical expressions
are equivalent. Thus, we would write
p  q = (p + q)(pq)' = pq' + p'q
1.2.1 - 9
Equivalent expressions are important in logic design because if you have a logic circuit
that implements a certain logical expression
p
then you can replace it by the circuit for an
(p + q)(pq)
equivalent expression. For example, if your
circuit calls for an exclusive-or gate and you
don’t have one available, then instead you can
q
use the circuit at the right for (p + q)(pq)'.
Nor
Nor is short for not-or. It is equivalent to first or'ing p and q and then inverting the result.
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p nor q
pq
are common ways of denoting the nor operation applied to
p and q. We shall usually use p nor q. p nor q is 1 if both
p and q are 0. p nor q is 0 if either one or both of p and q is
1. To the right is a truth table for nor.
In terms of true and false, p nor q is true if both p and q
are false. p or q is false if either p or q or both are true.
At the right is the truth table expressed in terms of T and F.
p
0
0
1
1
p
F
F
T
T
q
0
1
0
1
q
F
T
F
T
p nor q
1
0
0
0
p nor q
T
F
F
F
In everyday English speech we can specify the nor of two
propositions or predicates p, q by saying "Neither p nor q".
Examples.
1.
Suppose Billy comes home from school with a lot of homework. His mother says
"Billy, since you have a lot of homework, you may neither watch your favorite
TV show nor go out to play with your friends." Needless to say, Billy is not
happy about this.
2.
If p is the statement "I am wearing a raincoat" and q is "I am carrying an
umbrella" then p nor q is "I am not wearing a raincoat nor am I carrying an
umbrella". When it comes time to evaluate this statement as to whether it is true
or false, then it will be true only if I am not wearing a raincoat and I am not
carrying an umbrella.
Other examples:
Neither Toledo is the capital of Ohio nor is Cleveland the capital of Ohio.
I hate sci fi. I have neither seen 2001 or Aliens.
1.2.1 - 10
3.
(2 > 5) nor (2*3  2 + 4)
This is false since 2*3  2 + 4 is true.
(x2 < 0) nor (ex < 0)
In principle, this is a predicate since it involves a
variable x and presumably its truth value would
depend on the value of x. However, it happens to
be true for every real value of x.
4.
A NOR gate in circuit design is pictured at the right. The electrical value of the
output represents 1 if both of the electrical values of the
p nor q
p
inputs represent 0. The electrical value of the output
q
represents 0 if either one or both of the electrical values
of the inputs represents 1. NOR gates are important in
circuit design, because they are often simpler than AND or OR gates and hence
cheaper.
One can achieve the same result as p nor q either as not (p or q) or (not p) and (not q). In
other words one has the following logical equivalences.
p nor q = (p + q)' = p'q'
The second of these equivalences, (p + q)' = p'q', is one of DeMorgan's two laws. One
can verify p nor q = (p + q)' = p'q' by means of the following truth table.
p
0
0
1
1
q
0
1
0
1
p nor q
1
0
0
0
p+q
0
1
1
1
(p + q)'
1
0
0
0
p'
1
1
0
0
q'
1
0
1
0
p'q'
1
0
0
0
Since the columns for p nor q, (p + q)' and p'q' are all the same, they are equivalent.
Nand
Nand is short for not-and. It is equivalent to first and'ing p and q and inverting the result.
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p nand q
p|q
are common ways of denoting the nand operation applied to p and q. We shall usually
use p nand q. p nand q is 1 if one or both p of q are 0. p
p
q
p nand q
nand q is 0 if both of p and q are 1. At the right is a
0
0
1
truth table for the nand operation.
0
1
1
1
0
1
1
1
0
1.2.1 - 11
In terms of true and false, p nand q is true if either p or q or both are false. p or q is false
if both p and q are true. At the right is the truth table expressed in terms of T and F.
In everyday English speech there is no single word (like
nand) that can be used to specify the nand of two
propositions or predicates. Rather we have to achieve the
effect with some combination of and, or and not.
Examples.
p
F
F
T
T
q
F
T
F
T
p nand q
T
T
T
F
1.
Suppose Billy comes home from school with a lot of homework. His mother says
"Billy, since you have a lot of homework, you will not have enough time to both
watch your favorite TV show and go out and play with your friends for an hour."
If nand was a part of everyday English, then Billy's mother could have said "Billy,
since you have a lot of homework, you can watch your favorite TV show nand go
out and play with your friends for an hour."
2.
If p is the statement "Dallas is the capital of Texas" and q is "Houston is the
capital of Texas" then we could phrase p nand q as "Either Dallas is not the
capital of Texas or Houston is not the capital of Texas". Another possiblity
would be "It is not true that both Dallas is the capital of Texas and Houston is the
capital of Texas.
Someone might say. "I like sci fi. However, I have not seen both of the movies
2001 and Alien." If nand was part of everyday English that person might say "I
have seen 2001 nand I have seen Alien".
Probably the reason nand is not part of English is because us
3.
(2 > 5) nand (2*3  2 + 4)
(x > 5) nand (x < 4)
4.
This is true since 2 > 5 is false.
In principle, this is a predicate since it involves a
variable x and presumably its truth value would
depend on the value of x. However, it happens to
be true for every real value of x.
A NAND gate in circuit design is pictured at the right. The electrical value of the
output represents 1 if either or both of the electrical values of the inputs
represents 0. The electrical value of the output
p
p nand q
represents 0 if both of the electrical values of the
q
inputs represents 1. NAND gates are important in
circuit design, because they are often simpler to make out of transistors or other
electrical components than AND or OR gates and hence cheaper.
1.2.1 - 12
As indicated in the first two example, one can achieve the same result as p nand q either
as not (p and q) or (not p) or (not q). In other words one has the following logical
equivalences.
p nand q = (pq)' = p' + q'
The second of these equivalences, (pq)' = p' + q', is one of DeMorgan's two laws. The
other is (p + q)' = p'q' which we shall discuss more when we talk about the nor operation.
One can verify p nand q = (pq)' = p' + q' by means of the following truth table.
p
0
0
1
1
q
0
1
0
1
p nand q
1
1
1
0
pq
0
0
0
1
(pq)'
1
1
1
0
p'
1
1
0
0
q'
1
0
1
0
p' + q'
1
1
1
0
Since the columns for p nand q, (pq)' and p' + q' are all the same, they are equivalent.
If-then
This operation is the foundation of classical logic. However, it doesn't seem to be used
much in circuit design.
If p and q are two logical values, bits, propositions, predicates or logical expressions then
if p then q
pq
p implies q
p only if q
are common ways of denoting the if-then operation
applied to p and q. We shall usually use p  q. p  q is
1 if either p is 0 or p and q are both 1. p  q is 0 if p is 1
and q is 0. At the right is a truth table for the if-then
operation in terms of 0 and 1.
In terms of true and false, p  q is true if either p is false
or both p and q are true. p  q is false only if p is true
and q is false. At the right is the truth table expressed in
terms of T and F.
p
0
0
1
1
q
0
1
0
1
pq
1
1
0
1
p
F
F
T
T
q
F
T
F
T
pq
T
T
F
T
In everyday English speech if p and q are two
propositions or predicates then "If p then q" is how we often say p  q. We don't usually
use if-then with propositions whose truth table we can determine now. Instead it is
1.2.1 - 13
mainly used with predicates that we envision evaluating (perhaps many times) in the
future when the values of the variables are known. When we use it we usually have in
mind some connection between p and q such that the truth of p causes q to also be true.
These examples illustrate this.
Examples.
1.
If p is the statement "Lansing is the capital of Michigan" and q is "Columbus is
the capital of Ohio" then p  q is "If Lansing is the capital of Michigan then
Columbus is the capital of Ohio". It happens to be a true statement because both
p and q are true. However, it is not something people would normally say
because the truth values of p and q are already known.
In the same vein, the statements
"If Detroit is the capital of Michigan then Columbus is the capital of Ohio"
"If Detroit is the capital of Michigan then Toledo is the capital of Ohio"
are both regarded as true since "Detroit is the capital of Michigan" is false. On
the other hand
"If Lansing is the capital of Michigan then Toledo is the capital of Ohio"
is false.
2.
If p is the statement "It is raining" and q is "I am carrying my umbrella" then
If p then q is "If it is raining then I am carrying my umbrella". Suppose we
regard regard p and q as predicates so that "If it is raining then I am carrying my
umbrella" is also a predicate which will become true or false when we specify a
time. When it comes time to evaluate this statement as to whether it is true or
false, then it will be true if it is either not raining or if it is both raining and I am
carrying my umbrella. The only time it will be false if it is raining and I am not
carrying my umbrella. In this case we are regarding p and q as predicates.
3.
"If 2 < 3 then 4 < 9". This is true. This is another case where the truth value of p
and q are known, so p  q is not something people would normally say.
Similarly "If 3 < 2 then 4 < 9" and "If 3 < 2 then 9 < 4" are both regarded as true
while "If 2 < 3 then 9 < 4" is false.
4.
"If x < 3 then x2 < 9". This is something someone is more likely to say. This
statement involves a variable x, so in principle, its truth value might involve the
value of the variable x. Often people make statements like this when they believe
the statement is true for all values of the variables appearing. We shall discuss
this more when we get to predicate logic in a little while. Actually the statement
"If x < 3 then x2 < 9" is not true for all values of the variable x. For example, if
x = - 4 then it becomes "If - 4 < 3 then 16 < 9" which is false.
Note that p implies q is equivalent to not p or q, even though they don’t sound the same.
In symbols one has
1.2.1 - 14
p  q = p' + q
p
0
0
1
1
Here is a truth table showing this.
q
0
1
0
1
pq
1
1
0
1
p'
1
1
0
0
p' + q
1
1
0
1
If-and-only-if or Exclusive-Nor
If p and q are two logical values, bits, propositions, predicates or logical expressions then
p if and only if q
p xnor q
pq
p=q
p == q
are common ways of denoting the exclusive nor operation applied to p and q. p xnor q is
1 if either both p and q are 1 or both p and q are 0. p xnor q is 0 if either p is 1 and q is 0
or p is 0 and q is 1. Mathematically, xnor is the same as equal, but xnor if-and-only-if or
 are often used instead in order to emphasize that one is
taking two statements or bits and combining them to
p
q
p xnor q
produce a third. At the right is a truth table for the xnor
0
0
1
operation.
0
1
0
1
0
0
If-and-only-if is common in every day speech, classical
1
1
1
logic, mathematics and logic design. In terms of true and
false, p  q is true if either p and q are both true or both false. p  q is false if one is
true and the other is false. At the right is the truth table expressed in terms of T and F.
If p and q are propositions or predicates then p  q is the
proposition or predicate that is true only if p and q are
both true or both false. It is false if one is true and the
other is false.
Examples.
1.
p
F
F
T
T
q
F
T
F
T
pq
T
F
F
T
If p is the statement "It is raining" and q is "I am carrying an umbrella" then
p  q is "It is raining if and only if I am carrying an umbrella". Suppose we
regard this as a predicate so that it will become true or false when we specify a
time. When it comes time to evaluate this statement as to whether it is true or
false, then it will be true if either it is raining and I am carrying an umbrella or it
is not raining and I am not carrying an umbrella. It is false if either it is raining
and I am not carrying an umbrella or it is not raining and I am carrying an
umbrella.
1.2.1 - 15
If and only if is not very interesting when used with statements whose truth value
doesn’t change. For example the statement “Lansing is the capital or Michigan if
and only if Columbus is the capital or Ohio” is a true statement, but it is not a
very interesting one.
2.
"2 < 3 if and only if 4 < 9". This is true. This is another case where the truth
value of p and q are known, so p  q is not something people would normally
say.
In contrast "x < 3 if and only if x2 < 9" is something someone is more likely to
say. This statement involves a variable x, so its truth value might involve the
value of the variable x. In fact this statement is not true for all values of the
variable x. For example, if x = - 4 then it becomes "- 4 < 3 if and only if 16 < 9"
which is false. However, "-3 < x < 3 if and only if x2 < 9" is true for all real
values of x.
3.
In circuit design there is a gate that performs the xnor
p xnor
p
operation. It is pictured at the right. Occasionally it is
q
q
called an equivalence gate. The electrical value of the
output represents 1 if both of the inputs are the same. The
output is 0 if the inputs are different. This gate is quite useful, since we often
want to compare two bits to see if they are the same.
Two equivalent ways of expressing if-and-only-if in terms of other logical operations are
p  q = (p  q)(q  p) = (p  q)'
The first says that p if and only if q is true only if p implies q and q implies p. As usual
these can be verified by means of a truth table.
p
0
0
1
1
q
0
1
0
1
pq
1
0
0
1
pq
1
1
0
1
qp
1
0
1
1
(p  q)(q  p)
1
0
0
1
pq
0
1
1
0
(p  q)'
1
0
0
1
Summary
p
q
0
0
1
1
0
1
0
1
and
pq
0
0
0
1
or
p+q
0
1
1
1
not
p'
1
1
0
0
exclusive or
pq
0
1
1
0
p nand q
p nor q
1
1
1
0
1
0
0
0
1.2.1 - 16
if-then
pq
1
1
0
1
xnor
pq
1
0
0
1
Problems.
1.
Let p, q, and r be the following propositions.
p:
Bill graduates.
q:
Bill gets a job.
r:
Bill is happy.
Write the following propositions using p, q, r, and the logical operators.
a. Bill doesn’t graduate and he is not happy.
b. Bill would be happy if he graduates and he gets a job.
c. Bill will not be happy if and only if he doesn’t graduate or he doesn’t get a
job.
Solutions: a. p'r'
b. (pq)  r
1.2.1 - 17
c. r'  (p' + q')
Download