Next steps for Inform 6 compiler

Anyone have opinions about this I6 bug report? "or" operator violates DM4, DeMorgan's law · Issue #112 · DavidKinder/Inform6 · GitHub

The title on that report doesn’t get at the real issue (the DM4 doesn’t specify the “right” behavior). Here’s the whole situation:

The manual describes the “or” clause of comparisons (§1.8):

if (alpha == 3 or 4) ...
! true if (alpha==3 || alpha==4)

if (x > 100 or y) ...   
! true if (x > 100 || x > y)
! that is, if x is bigger than the minimum of 100 and y

if (x < 100 or y) ...   
! true if (x < 100 || x < y)
! that is, if x is less than the maximum of 100 and y
! (this is not mentioned in the manual, but it's implied)

The first form (== or) is sometimes useful. The other forms (> or, < or) are kind of contrived; I’ve never seen them used.

The manual also describes the converse of the first form:

if (alpha ~= 5 or 7 or 9) ...
! true if alpha is not equal to any of these values
! equivalent to ~~(alpha == 5 or 7 or 9)

This is the way we’d say it in English (“alpha is not five or seven or nine…”) It’s not strictly correct for Boolean logic. If you wrote out the condition, DeMorgan’s law says you should use “and”, not “or”:

if (alpha ~= 5 && alpha ~= 7 && alpha ~= 9) ...

The I6 compiler doesn’t require you to distinguish “and” and “or” in this way, because that would be fussy. It’s clear the way it is.

The problem comes when you use >= and <= with or:

if (x >= 100 or y) ...   
! equivalent to ~~(x < 100 or y)

if (x <= 100 or y) ...   
! equivalent to ~~(x > 100 or y)

In one sense this is perfectly consistent with the way ~= or is defined – it’s the converse of an existing operator. (notin or is also defined as the converse of in or.)

In another sense it’s very surprising, because (x > 100 or y) checks the minimum of 100 and y, but (x >= 100 or y) checks the maximum.

That is, you might expect these lines to be equivalent:

if (x >= 100 or y) ...   
if ((x > 100 or y) || (x == 100 or y)) ...   

But in fact they are not.

I agree this is an unhappy outcome. However, changing it would be unhappy in a different way. ((x >= 100 or y) would no longer be equivalent to ~~(x < 100 or y).) And while I’ve never seen these forms used in real life, there might be old game code that relies on them.

So is it worth making this change? I’m ambivalent. And I’m inclined to err on the side of “leave it alone” for ambivalent cases. But I wanted to pass the question around.

EDIT: I probably meant “inverse”, not “converse”. Sorry. Been a long time since the basic logic course.

EDIT: Bonus points if you first learned about De Morgan’s Law from the “Propositional Calculus” chapter of Godel Escher Bach.

3 Likes