The Devil of the Excluded Middle
The tale of the “Devil of the Excluded Middle” appears in [Wadl03] as a humorous sketch depicting the execution of a program typed by the law of the excluded middle. With apologies to Wadler, I reproduce it here:
Once upon a time, the devil approached a man and made an offer: “Either (a) I will give you one billion dollars, or (b) I will grant you any wish if you pay me one billion dollars. Of course, I get to choose whether I offer (a) or (b).”
The man was wary. Did he need to sign over his soul? “No”, said the devil, all the man need do is accept the offer.
The man pondered. If he was offered (b) it was unlikely that he would ever be able to buy the wish, but what was the harm in having the opportunity available?
“I accept,” said the man at last. “Do I get (a) or (b)?”
The devil paused. “I choose (b).”
The man was disappointed but not surprised. That was that, he thought. But the offer gnawed at him. Imagine what he could do with his wish! Many years passed, and the man began to accumulate money. To get the money he sometimes did bad things, and dimly he realized that this must be what the devil had in mind. Eventually he had his billion dollars, and the devil appeared again.
“Here is a billion dollars,” said the man, handing over a valise containing the money. “Grant me my wish!”
The devil took possession of the valise. Then he said, “Oh, did I say (b) before? I’m so sorry. I meant (a). It is my great pleasure to give you one billion dollars.”
And the devil handed back to the man the same valise that the man had just handed to him.
It seems obvious that the devil, being the spirit of evil, has cheated the man. We can interpret the devil’s choice of (b) as a change in the nature of his offer. Accordingly, the man acts on the belief that the offer is transactional, i.e., in exchange for a billion dollars, the devil would grant him anything he desired. It’s almost as though the devil merely created an illusion at the beginning by presenting two possibilities.
A more amenable (and more confusing) version of this tale (by Peter Selinger) appears as exercise (6.19) in [SøUr06]. In it, an evil king gives a shepherd the following orders:
“You must bring me the philosopher’s stone, or you have to find a way to turn the philosopher’s stone into gold. If you don’t, your head will be taken off tomorrow!”
[SøUr06] presents the following solution to the shepherd’s quandary:
The next day the poor shepherd brings to the king’s palace a huge machine. The machine has two openings. One is marked “Put the philosopher’s stone here!” and on the other it reads “The gold will fall out from here”. That will perfectly work as long as the king cannot put the philosopher’s stone into the machine. But what if, somehow, the king comes into the possession of the philosopher’s stone? Then the shepherd’s brother, hidden inside the machine, will grab the stone, and hand it discretely to the shepherd. The shepherd now can say: “Oops, Your Majesty, I’ve been mistaken. Here is the philosopher’s stone!”
Again, this seems wrong. The shepherd’s machine cannot produce gold from the philosopher’s stone, and it isn’t the philosopher’s stone (by virtue of not being a stone). The machine seems only capable of producing the philosopher’s stone from itself.
An infuriating (and therefore fascinating?) aspect of the computational interpretation of classical logic is that both these stories mirror the behaviour of a program of type
The contents of this post assumes some knowledge of typed
Preliminaries
It’s well known that the Law of the Excluded Middle (LEM) is not accepted as truth in constructive logics. This is unfortunate, as simply typed
In [Grif89], Griffin shows how control operators can be typed with the Double Negation Elimination (DNE) rule. These operators are based on the call/cc
subroutine in the programming language Scheme. [FFKD87] presents a syntax and a set of rewrite rules for Idealized Scheme, a language that captures this control operator. Griffin types terms in this language with DNE.
The syntax of Idealized Scheme is:
The operational semantics of Idealized Scheme uses a Call-By-Value (CBV) style evaluation strategy. The principle of CBV is to fully reduce all parameters of a function before beginning its evaluation. It’s also deterministic; the first valid reducible expression (redex) encountered in a left-to-right sweep of the term (i.e., the leftmost-outermost one) is the one to get reduced. Felleisen et. al. use the notion of Evaluation Contexts (or simply contexts) to capture this strategy. Its syntax is:
Any term call/cc
: the execution of
In [Grif89], Griffin argues for the consistency of the typing rules
Unfortunately, Griffin’s analysis requires the overall term
Typing and Evaluating LEM
As per Glivenko’s Theorem,
The evaluation must now proceed through a different redex. Suppose the only way this term can appear in a redex is in a
All this causes a different behaviour at the (eventual)
Issues
The earlier section assumes that a
The
All this gives the impression that a
Unfortunately, I can’t counter this objection with a technical argument. One possible approach would involve extending the syntax of Idealized Scheme with separate injection, pairing and case categories that play nice with the existing encoding schemes. Perhaps the Dual Calculus detailed in [Wadl03] achieves this.
I’ll only say this:
Explaining the tales
The devil’s actions were mostly explained in the previous section. To repeat, the devil, being (probably) omnipotent, has the ability to alter the state of the world at will. Martens gives the devil the simple power to turn back time. To faithfully simulate
The shepherd’s tale is less satisfying. His only way out is the approach suggested in [SøUr06]. To pull off this sleight-of-hand, he needs to acquire the philosopher’s stone from the king. Being the crafty man he is, he produces a list of instructions to be followed by the King’s trusted knights. He then informs the king that those instructions would provide the king with what he wants when augmented with the entire sequence of actions the king wishes to perform on what he wants. When the king hesitates, he points out that the instructions would be carried out by his trusted knights: men incapable of disloyalty.
Now convinced, the king begins preparing his instructions. Naturally, he must account for both possibilities: the shepherd creating a machine, or producing the stone. Therefore, his instructions would be something like:
private KING_STONE;
switch (shepherd_output.type) {
case STONE:
("It's the stone!");
printfreturn shepherd_output.stone;
case MACHINE:
("It's a machine. Inputting stone...\n");
printfif (shepherd_output.run(KING_STONE) != GOLD) {
();
kill_shepherd}
}
After receiving the augmented set of instructions, the knights begin their work. First, they duplicate the king’s instructions and embed the copy inside the shepherd’s list of instructions. Next, the shepherd requires the knights to execute the king’s instructions as though he had produced a machine that would convert the philosopher’s stone to gold. To do this, they retrieve the philosopher’s stone from the king’s quarters. The next step requires them to embed the stone into the list of instructions.
At this point, the knights encounter the copy of the king’s instructions. They are told to forget everything they’ve done so far and execute the king’s instructions with the stone they find (which they placed!) inside. If outputs could be logged in medieval Europe, they would say:
It's a machine. Inputting stone...
It's the stone!
Thus, the knights return to the king with the philosopher’s stone. The king, now satisfied, spares the shepherd.