How Lojban can help you with programming
Wednesday, 12 November 2003 16:45I had a test in a program I'm writing which tested three truth values; let's call them A, B, and C. At the moment, it's testing for A && B && C (that is, they all have to be true at once).
After debugging, I realise that that's not what I want; I actually want the test to be "if A, then if B then also C" [but if A and not-B, then I don't care about C], but I wasn't sure how to express an "if" relationship with logical operators.
Enter Lojban :) I remembered that "logical if" as in "if X, then Y" is "ganai X gi Y". Translated back into logics, that's "not-X or Y". (For the curious who are not familiar with Lojban, the "a" bit of "ganai" is responsible for the "or" meaning, and the "nai" bit for the "not" meaning. The "g" of "ganai", as well as the word "gi", are used for all forethought logical connectives.)
After a quick sanity check I realised that this is what I wanted—if A is true, and either B is not true or [B is true and] C is true, then the bit of code should be executed. Changed "if (A && B && C)" to "if (A && (!B || C))" and away I went!
no subject
Date: Wednesday, 12 November 2003 15:29 (UTC)Interpreting this sentence strictly logically, and assuming there was a => operator meaning implication, what you want is this:
if (A => (B => C))
which is the same as:
if (A => (!B || C))
if (!A || (!B || C))
if (!A || !B || C)
But if what you actually meant was that you wanted
if (A && (B => C))
then your answer is correct.
no subject
Date: Wednesday, 12 November 2003 22:05 (UTC)if (A && (B => C))was indeed what I wanted.