Propositional Calculus for Computer Programmers: Background and First Part
This post is the inaugural element in what I plan to be an ongoing project into attempting to develop a framework for translating philosophical propositional calculus (PC) into terms that computer programmers can easily understand.
Personally, I find the confluence of factors that motivate this project incredibly interesting; but of course that’s because they’re largely about my life. The next section will talk about some of my motivations, as well as some of the sources I plan to draw on for this project. If you want to skip this section, you can click here.
Background
- I told you before that my philosophical background is in the so-called continental tradition. What does this mean? Well, one thing that it means is that in my previous philosophical career, I never had to understand the sentential calculus. It’s just not a form of arugmentation that people in that tradition are prone to use.
- At the same time, I told you that I was applying for PhD studies in American philosophy programs. Most of these programs are couched in the analytic tradition, which is a tradition that is deeply enamored of propositional logic as an argumentation tool. American analytic philosophy in the Russelian tradition - at least in some (admittedly much rarer now) cases - actually situates logic as first philosophy. This is quite a change for a person who comes very distinctly from a tradition that has historically situated everything but logic (i.e. metaphysics, epistemology, ethics) in the big chair.
- Luckily, in addition to my philosophical interest, I have also been a computer programmer for ten years. This means that I have spent a lot of time negotiating symbolic logic, and as such I imagine or — at least hope — that there’s got to be a strategy to map these things together.
Pedagogy
When I was eighteen, I took a class called Formal Foundations of Computer Science, which was a symbolic logic class. I did rather poorly at this, which should confuse you, given the aforementioned. It confused the heck out of me for just long enough to be disastrous. Only recently, spurred by my partner Nick’s research project in programming pedagogy, did I understand this: the pedagogical model for teaching formal logic to computer programmers should be way more practical than it is (or at least was in my case).
Hence, the following attempt to make logic work. Throughout the following, I will be using the class notes and assignments most kindly provided by the Massachusetts Institute of Technology’s Open Courseware project. The syllabi will be provided courtesy of Prof. Vann McGee’s Logic I and Logic II classes in the MIT Linguistics and Philosophy department. The pedagogical materials will be provided courtesy of Delicious.com and Nicholas Senske of the University of Michigan.
Finally, expect this series to take some time to complete. Let’s get started.
Propositional Calculus for Computer Programmers: Part 1
Today’s course is easy. All we’re going to do is look at the basic syntax of the propositional calculus, and then the truth assignments for its basic operations. Really, nothing to it. I’ll be doing this using C-style syntax.
Syntax
| PC symbol | English | C Operator or Fragment |
|---|---|---|
| ∧ | and | && |
| ∨ | or (inclusive) | || |
| ¬ | not | ! |
| → | if…then (only if) | onlyIf(a,b) |
| ↔ | if and only iff | ifOnlyIf(a,b) |
You’ll notice that the last two rows above are logical operations that don’t have C operators. Programming languages usually handle these operations by selection statements. For brevity’s sake, I’ll be using the ternary operation.
function onlyIf(a,b) { a ? (b ? return true : return false) : return true; }
function ifOnlyIf(a,b) { a ? (b ? return true : return false) : (b ? return false : return true); }
Now, you may remember from way back in your beginning CS career drawing truth tables. Well, that’s what we’re going to be working on now. A final note on my conventions is that you should just assume, from now on that 1 == true and 0 == false.
Truth Assignments for simple PC operations
| a | b | (a ∧ b) | (a ¬ b) | (a → b) | (a ↔ b) | ¬a |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 |
One last thing to note that’s really convenient for programming types is that when you draw truth tables, an easy algorithm for mapping out your variable columns (in the above case, the first two columns: a, b), you just start from the bottom and count in binary (above: 00,01,10,11). This holds true for n variables.
So the plan is that in the next one of these, we’ll look at the axioms for the PC. I’m hoping that we can figure out ways to make this stuff feel more intuitive for the pragmatic programmer.