Le lundi 21 décembre 2015 17:32:03 UTC+1, Mark Bell a écrit :
>
> The __invert__ methods, which controls the behaviour of the ~ operator, of 
> Integers and ints are different.
>
> In Python, for an int x, its invert ~x is defined to be its two's 
> complement and is given by -1-x 
> <https://wiki.python.org/moin/BitwiseOperators>.
>
> On the other hand, in Sage for an Integer x 
> (from sage.rings.integer.Integer), its __invert__ is defined to be 1 / x 
> <https://github.com/sagemath/sage/blob/master/src/sage/rings/integer.pyx#L5999-L6011>
> .
>
> Unfortunately this difference means that ~x different results in Sage and 
> Python and so is causing some of my scripts and packages that run under 
> Python to break under Sage. Most notably, that under Sage ~0 raises a 
> "ZeroDivisionError: Rational division by zero" error rather than returning 
> -1.
>
> Looking through the git history it appears that this has been the 
> convention since at least October 2006 
> <https://github.com/sagemath/sage/blob/b94db547579596d7979e28aa9aff1cdb45193bcc/src/sage/rings/integer.pyx#L1590-L1593>.
>  
> Is there a reason why __invert__ was chosen to act this way rather than 
> match the Python convention?
>

maybe because :
sage: var("x")
x
sage: ~x
1/x
sage: var("a,b,c,d")
(a, b, c, d)
sage: M=matrix([[a,b],[c,d]])
sage: ~M
[1/a - b*c/(a^2*(b*c/a - d))           b/(a*(b*c/a - d))]
[          c/(a*(b*c/a - d))              -1/(b*c/a - d)]
were deemed useful ? 

HTH,
--
Emmanuel Charpentier

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to