Lecture 1, Thursday August 31
Class Overview
This class is an introduction to a collection of formal tools that we
need to have in order to change "programming" into Computer Science.
In particular, we study:
- Logic. How to make concrete, specific statements about the world,
or about, say,the behavior of our programs. How to change these
statements into equivalent statements.
- Proofs. How to demonstate if such concrete, specific statements
are true.
- Sets. How to define and manipulate collections of objects.
These may be abstract objects like "possible inputs of a program", or
"easily cracked passwords".
- Counting. How to determine how many elements a set has. This is
easy if the set is, say, "members of your dorm floor". But it is
harder if it is "orders in which packets may be received in a
network", or "number of possible poker hands".
- Graphs and Relations. Beyond describing individual objects and
collections of objects, modern science has benefited more and more by
formal models of relationships between objects. Google, for example,
was the first search engine to look not just at the set of words that
was on a page, but instead at the "link to" structures of how pages
linked to each other.
Logic and Computer Science
Why is logic important for Computer Science? This class used to
be "Foundations of Computer Science", and it still is, the name just
changed so that if you don't know anything about Computer Science,
you'll still know what is to be taught. Logic plays a role at three
specific places in Computer Science.
First, languages like C, Java have logical operators such as
&& ("AND"), || ("OR"), and ! ("NOT"). In
order to read and write these expressions correctly, we need to
understand how to interpret and manipulate formulas like these (which
make up "Propositional Logic").
- Second, logic is a key to the lower level of how computers and
micro-processors work. This was not always the case, until the
1960's, the dominant form of electronic computation was
analog
computing. On these systems "writing a program" to simulate some
natural phenomenon such as the interactions of springs and masses
involves finding electrical components with analagous
interactions such as capacitors, inductors and resistors (then
simulate "speed = voltage" and "friction = resistance" and so on).
Perhaps (?) surprisingly, most physical properties and forces do have
analagous electrical components, and analog computers were used until
the end of the Vietnam war for diverse tasks such as predictive
bombsights
(that take into account known winds, plane speed, altitiude, etc.),
and systems to beat casinos
by predicting
roulette outcomes (this was also considered the first wearable
computer).
In the 70's, 80's and 90's, however, it became possible and more
efficient to simulate all these physical interactions using much
simpler electronic components, that could be made very small and very
fast. Instead of using the amount of voltage in an electronic circuit
to represent, say, the amount of force acting on an object, the system
just uses the binary value "is there voltage on this wire or not",
which we think of as ("0" or "1") or ("True" or "False"). Numbers,
forces, and other kinds of data (such as web pages and MySpace friend
comments) are represented as strings of 0's and 1's, and binary
operations are used to manipulate this data.
- Beyond Propositional Calculus (the theory of logic formulas with
AND, OR, NOT, and so no), Logic is the field of mathematics focussed
on understand whether a set of axioms, and rules for manipulating
those axioms are "sound" and "complete" --- starting with your axioms,
is everything that you can prove true ("soundness"), and is everything
that is true provable ("completeness"). In computer science we have
similar concerns --- we would like to know if a language (say C) is
enough to be able to write all the programs we need to (crikey, how
can we define this set?), and can we prove that particular program is
correct.
An Introduction to Logic
We will consider classical propositional logic. Wikipedia has a
fantastic page about
this that is completely incomprehensible if you don't already know it.
When it comes test time, see if you understand this page; if you do,
you'll probably do fine on the test.
Propositional logic deals with statements that have boolean values
(truth values). Each statement is either true or false, or has a
truth value of "T" or "F". For instance, "The Cardinals won the 2005
World Series" has a truth value (sadly) of "F". Larger statements, or
forumalas, can be made by combining propositions. This allows
statements such as: "The Cardinals will win the 2006 world series or
the cardinals will not win the world series". Such a statement, (P or
not P) is *always* true in classical logic, as a result of the "law of
the excluded middle".
There are several other logics that we don't consider.
- Constructive Logic. Does not have the law of the excluded middle,
any time you want to prove an "OR" statement you have to say which
part is true.
- Temporal Logic. Formal system for statements whose truth value
changes with time, (right now, "The cardinals win the 2006 world series"
should have a logic value saying I-don't-know-yet, and the proposition
"I am hungry" may change throughout the day).
- Inductive Logic. System that helps determine when it is
*reasonable* to believe something based on accumulation of evidence.
This is a different use of Induction that the proot technique we will
talk about this semester.
- Quantum Logic. Craziness.
Propositions
Propositions are statements that have a truth value. "Washington
University is in St. Louis" and "Online lecture notes are useful" are
examples of propositions. English statements like "Clean your Room",
"Do your homework", "Yikes" are not. In order to avoid several
paradoxes, we do not allow a proposition to refer to its own truth
value or the truth value of another proposition. That is we don't
allow "This sentence is false", "This sentence is true", or "The next
sentence is true", "The last sentence is false".
Using logical connectives (and, or, not), we can make
propositional formulas out of propositions. For exampe the combined
statement "Washington University is in St. Louis and Online lecture
notes are useful" has a truth value (perhaps True?).
Since we are mostly interested in "how" we can think about
propositional formulas, how we can combine and manipulate them
(instead of being interested in listing facts about the world), we can
shorten our formulas using variables. We will use letters P, Q, R to
refer to propositions. They have a truth value, it is either true or
false, but we may not know what it is.
We can make logical expression from propositional variables through
the use of connectives. The most common of these connectives are:
- NOT, with symbol ~,
- AND, with symbol ^,
- OR, with symbol v,
- IMPLIES, with symbol -->.
- IF AND ONLY IF, sometimes shortened as IFF, with symbol <-->
slightly less common are the following connectives
- EXCLUSIVE OR, with symbol (plus with a circle around it).
- NAND
- NOR
We can define the formal meaning of these connectives through the
use of a truth table.
1. Truth tables.
A logical expression, such as ((p AND q) or r), has a truth value that
depends on the truth values of the propositions (the p's, q's, and
r's) that make up the expression. A truth table is an organized way
of writing down the truth value of an expression, by exhaustively
considering every possible set of truth values for the propositions
that make up the expression.
Complete truth tables
in a complete truth table, every new column is made as the "and",
"or", "implies", "if and only if", or "not" of earlier columns.
How many rows are there in a complete truth table?
How many columns are there in a complete truth table?
Two expressions are called logically equivalent if their
truth value is the same in EVERY condition, that is, if their truth
value is the same in every row.
Now that we understand how to compute the logical meaning of
connectives and propositional formulas, we can thing about trying to
translate English sentences into logic *in a way that preserves their
truth*. Some information on translating between logic and english can be
found at the following fantastic
web page, although note that they use a different notation than we
do (a "dot" for and, and three horizontal lines for "<--->").
Some interesting questions for translating from english to logic and
back:
- You cause a memory overflow error if you use pointers incorrectly
- You use pointers correctly, but you cause a memory overflow error.
- You cause a memory overflow error unless you use pointers incorrectly
- You cause a memory overflow error only if you use pointers incorrectly
Chapter 1.1 of the book does a very good job of talking about
translating between english and logic. Please read that and Chapter
1.2 for the next class.
Web link to todays audio-visual event:
Pipe Dream