John Macdonald wrote:

if ($a xor $b xor $c) {...}

should succeed only when exactly one of ($a, $b, $c) is true.

That's not the definition of xor that I learned in school.
It's taking a simplified form of the definition that works
for two arguments and then expanding it to multiple
arguments - but the result is different from the original
definition of xor.

To which Paul Johnson added:


> I think it is generally accepted that xor is true iff an odd nnumber of
> its argumnets are true.

There are *two* generally accepted extensions of xor as an n-adic operator: the one John learned in school, and the one Austin was describing. *Both* are consistent with the definition of the binary form -- depending, of course, on how the binary form is defined. ;-)

The "parity" version John described is the obvious extension of the binary logic of an xor (as illustrated in John's truth-table). But it's at least arguable that n-ary operators should not always be generated from binary ones in this manner.

One could equally well argue that the binary xor truth table is really just a convenient encoding of the semantics: "exactly one of these operands is true". And indeed many have done so, and thus generalized xor that way. For example, this second definition is the basis of the "exists uniquely (a.k.a. "big-xor") quantifier of predicate calculus.

And, indeed, that's how junctional xor (C<^>) is generalized in Perl 6 to create the C<one> function.

In practice, the parity-checking version of n-ary xor has proved extremely useful in a number of practical low-level domains (low-level, at least, compared to predicate calculus ;-). And that utility has meant that the parity-checking definition has come to predominate.

But that doesn't make it the One True Xor, or even the best choice for a high-level programming language.

Of course, I'm not going to argue that the various Perl 6 *bit-wise* xors ought to be anything other than parity-checking, but the case for logical xor isn't nearly so clear-cut.

Nor is "exists uniquely" the only alternative semantics. At an even higher level, one could argue that xor means "my operands all have different truth values". Which implies that n-ary xor (for n>2) should always return false...unless, of course, we decide to implement Simon's 12 distinct boolean values.

However I do think that, now we have C<one> to carry the load of "exists uniquely", Larry will probably decide that C<xor> is strictly binary, and hence generalizes to the "parity" form in the n-ary case. I just don't want people to think we neglected to consider the other valid alternatives.

Damian

Reply via email to