sage: def xor(a,b): return eval("%s^%s"%(a,b))
....:
sage: xor(1,0)
1
sage: xor(1,1)
0
which mimics the native Python behavior:
Python 2.5.1 (r251:54863, Oct 5 2007, 13:50:07)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1^0
1
>>> 1^1
0
John
--
John Cremona
"and" and "or" in python are not binary operators, they are control
flow keywords. (Specifically, they short circuit).
I think we should have something. 10r is a "raw" python integer, 2.3r
a python float, but ^r looks like "raising to the r." ^^ seems like
the most reasonable syntax.
- Robert
+1
Unless somebody thinks of something better, I like ^^ as well.
William
I don't like ^^. Since ~ is a unary operator, we could safely use it as a binary operator, as well. I don't really like a~b to denote xor... but I like it better than ^^.
John
--
John Cremona
> I was only half serious when I suggested ^^, and was surprised that
> others quote liked it.
I don't think it's that pretty, but I think it's the best of many
other bad alternatives, and it at least somewhat ties in to the
python choice of xor. Also, I don't see xor being used very often,
and so is an allowable wart to let 2^5 = 32 (which is used all over).
> But I *really* don't like ~. The only similar
> symbol ever used in logic means "not" (negation) so this is completely
> unintuitive.
I would echo this. On another note, a~b is much a harder to preparse
as it must detect whether ~ is being used as a binary or unary
operation.