At first glance, it may not seem that the study of logic should be part of mathematics. For most of us, the word logic is associated with reasoning in a very nebulous way:

"If my car is out of gas, then I cannot drive it to work."seems logical enough, while

"If I am curious, then I am yellow."is clearly illogical. Yet our conclusions about what is or is not logical are most often unstructured and subjective. The purpose of logic is to enable the logician to construct valid arguments which satisfy the basic principle

"If all of the premises are true, then the conclusion must be true."It turns out that in order to reliably and objectively construct valid arguments, the logical operations which one uses must be clearly defined and must obey a set of consistent properties. Thus logic is quite rightly treated as a mathematical subject.

Up until now, you've probably considered mathematics as a set of rules for using numbers. The study of
logic as a branch of mathematics will require you to think more abstractly then you are perhaps used
to doing. For instance, in logic we use variables to represent **propositions** (or
premises),
in the same fashion that we use
variables to represent numbers in algebra. But while an algebraic variable can have any number as its value,
a logical variable can only have the value **True** or **False**. That is, True and False are the
"numerical constants" of logic. And instead of the usual arithmetic operators (addition, subtraction, etc.),
the logical operators are "AND", "OR", "NOT", "XOR" ("eXclusive OR"), "IMPLIES" and "EQUIVALENCE". Finally,
rather than constructing a series of algebraic steps in order to solve a problem, we will learn how to determine
whether a statement is always true (a **tautology**) or is a **contradiction** (never true), and whether
an argument is valid.

for statements with one variable,

pT F

for statements with two variables and

pqT T T F F T F F

for statements with three variables (where in every case, "T" stands for True and "F" for False). The extension to more than three variables should now be obvious:

pqrT T T T T F T F T T F F F T T F T F F F T F F F

- for the first variable, the first half of the rows are T while the second half are F
- for the second variable, the rows are split into four sections: the first and third quarters are T while the second and fourth quarters are F
- for the third variable, the rows are split into eighths, with alternating eighths having T's and F's
- in general, for the nth variable, the rows are split into 2
^{n}parts, with alternating T's and F's in each part

The first logical operator which we will discuss is the "**AND**", or **conjunction** operator.
For the computer
scientist, it is perhaps the most useful logical operator we will discuss. It is a "**binary**" operator (a
binary operator is defined as an operator that takes two operands; not binary in the sense of the
binary number system):

p AND qIt is traditionally represented using the following symbol:

but we will represent it using the ampersand ("

Notice that p & q is only T if both p and q are T. Thus the rigorous definition of AND is consistent with its colloquial definition. This will be very useful for us when we get to Boolean Algebra: there, we will use 1 in place of T and 0 in place of F, and the AND operator will be used to "

pqp & qT T T T F F F T F F F F

Perhaps the quintessential example of masking which you will encounter in your further studies is the use of the "network mask" in networking. An IP ("Internet Protocol") address is 32 bits long, and the first n bits are usually used to denote the "network address", while the remaining 32 - n bits denote the "host address":Suppose that on your network, the three most significant bits in the first byte of an IP address denote the network address, while the remaining 29 bits of the address are used for the host. To find the network address, we can AND the first byte with

n bits 32 - n bits Network Address Host Address 1 1 1 0 0 0 0 0since_{2}x x x y y y y y(x & 1 = x, but x & 0 = 0). Thus masking allows the system to separate the network address from the host address in order to identify which network information is to be sent to. Note that most network numbers have more than 3 bits. You will spend a lot of time working with network masks in your courses on networking.

&

1 1 1 0 0 0 0 0

=

x x x 0 0 0 0 0

We will represent OR using the stroke ("

p | q is true whenever either p is true, q is true or both p and q are true (so it too agrees with its colloquial counterpart).

pqp | qT T T T F T F T T F F F

The **NOT** (or **negation** or **inversion**) operator is a "**unary**" operator: it takes just
one operand, like the unary minus
in arithmetic (for instance, -x). NOT is traditionally represented
using either the tilde ("~") or the following symbol:

In a programming environment, NOT is frequently represented using the exclamation point ("

~ p is the negation of p, so it again agrees with its colloquial counterpart; it is essentially the 1's complement operation.

p~ pT F F T

p X q is T if either p is T or q is T,

pqp X qT T F T F T F T T F F F

XOR has a number of specific and essentially unrelated uses: for instance, in random numbers, in cryptography and in computer graphics. One common usage is as the quickest way to assign the value zero: p X p is always zero.The implication operator (

but we will denote it with an arrow ("

So p → q follows the following reasoning:

pqp → qT T T T F F F T T F F T

IMPLIES (

- a True premise implies a True conclusion, therefore T → T is T;
- a True premise cannot imply a False conclusion, therefore T → F is F; and
- you can conclude anything from a false assumption, so F → anything is T.

**EQUIVALENCE** is our final logical operator; it is a binary operator, and is traditionally notated by either
an equal sign, a three-lined equal sign or a double arrow ("**↔**"):

p ↔ q is T if p and q are the same (are equal), so it too follows our colloquial notion.

pqp ↔ qT T T T F F F T F F F T

Just as with arithmetic operators, the logical operators follow "**operator precedence**" (an implicit ordering).
In an arithmetic
expression with sums and products and no parentheses, the multiplications are performed
before the additions. In a similar fashion, if parentheses are not used, the operator precedence
for logical operators is:

Needless to say, it will behoove you to use parentheses whenever you have any doubts!

- First do the NOTs;
- then do the ANDs;
- then the ORs and XORs, and finally
- do the IMPLIES and EQUIVALENCEs.

A series of words or quoted phrases is interpreted by Google as a conjunction, but it is
possible to use negation and disjunctions in searches as well. Consider the following searches:

- argument
- argument -wiki
- -wiki argument
- modus ponens | tollens
- argument modus ponens | tollens
- -wiki modus ponens | tollens
- modus ponens | tollens argument -wiki
- "modus ponens" | "modus tollens"
- "modus ponens" | "modus tollens" argument -wiki
- "modus ponens" | "modus tollens" -wiki
- "modus ponens" -wiki | "modus tollens" -wiki

What logical expressions do they correspond to? Does Google treat them "correctly"? Are there searches which cannot be done using these operations?

Answer the last two questions again after studying the next section.In addition to words and phrases, one can restrict search results to, for example, .edu sites by including "site:.edu" in the search string; similarly, "-site:.com" will exclude commercial sites in the search.

Next we will examine the properties of the six logical operators.

Go to: Title Page Table of Contents Index

©2012, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.