On Tue, Apr 12, 2005 at 05:45:24PM -0700, Darren Duncan wrote: > At 8:27 PM -0400 4/12/05, John Macdonald wrote: > >The mathematical definition of xor for two arguments is "true if > >exactly one argument is true, false otherwise". > > Yes. > > >When that gets > >generalized to multiple arguments it means "true if an odd number > >of the arguments are true, false otherwise". > > Is this the official mathematics position? > > If not, I would generalize it like this: true If >= 1 arg is true > and >= 1 arg is false, otherwise false.
The above generalization is probably wrong. C<xor> and C<^^> are analogous to C<or> and C<||> in that they can return one of their operands as values, and not a boolean "true" value (unless of course that happens to be one of the operands). The returns-a-boolean form of xor is &infix:<?^> . Thus: $a = 0 ^^ 5; # $a == 5 $b = 7 ^^ 0; # $b == 7 $c = 7 ^^ 5; # $c == false or 0, could be argued either way $d = 0 ^^ 0; # $d == 0 but what to do with $e = 2 ^^ 4 ^^ 6; # $e == ?? One could treat it as $e = 2 ^^ (4 ^^ 6); # $e == 2 or maybe $e = (2 ^^ 4) ^^ 6; # $e == 6 or one could even be analogous to the one() junction (&infix:^) such that $e = 2 ^^ 4 ^^ 6; # $e == false or 0 > Of course, we should go with what the official mathematics standard is. Only if someone can define what the "mathematics standard" is here without saying that "xor returns 'true' or 'false'". (Of course, p6l is allowed to trump us on this one.) Pm