On Thu, Jun 2, 2016 at 2:01 PM, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: > Summary: Python should have a unary division operator (a.k.a. reciprocal), > written "/x", analogous to unary subtraction (a.k.a. negation), written > "-x". And then "~x" should be what is intended by Python, namely bitwise > negation. > > Rationale: Mark Bell gave a talk at Sage Days 74 and he mentioned this as a > problem. His software (flipper) uses bitwise negation (the ~ operator) a lot > and that breaks when using Sage Integers, where ~ means reciprocal. > > Given that Python does not have a reciprocal operator, this problem cannot > really be fixed. So if we want operators both for bitwise negation and > reciprocal, we need to add a new operator to Python. > > I have no idea how feasible it is to actually get a new feature accepted by > Python, but it makes a lot of sense to me and the numpy people pulled it off > for the matrix multiplication @ operator.
I don't necessarily disagree--I'm all for more operators supported by syntax and this makes a lot of sense, especially in analogy to subtraction. But just to play devil's advocate: 1. If flipper makes heavy use of bitwise negation then to prevent errors should explicitly cast values to a type where ~x means bitwise negation and not reciprocal (or anything else) in the first place. 2. I know this is probably anathema to mathematicians, but couldn't "1/" be viewed as a two character unary operator meaning reciprocal? :) 3. Even if you managed to get / added as a unary operator in Python wouldn't you still have to support ~ for reciprocal for the foreseeable future if Sage is already using it that way? 4. Before going through the hazard that is adding new syntax to Python, would this be easier to implement just in the Sage interpreter as syntactic sugar instead? (Under the current preparser implementation maybe tricky, but see other recent threads where the topic has come up of turning the preparser into a real parser with its own grammar). Best, Erik -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.