Re: [sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread Jeroen Demeyer
On 2015-12-21 17:53, Volker Braun wrote: In any case, if you are serious about binary operations then the next question is going to be: why is ^ not bitwise xor like for Python ints. That's actually a different question since it involves the preparser. In Sage, the ^ operator is calling __pow_

Re: [sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread Sébastien Labbé
I often use ~ to get the multiplicative inverse of an element: sage: m = matrix.random(QQ,3,3) sage: m [-1 -2 1] [ 0 2 2] [ 1 -1 1] sage: ~m [ -2/5 -1/10 3/5] [ -1/5 1/5 -1/5] [ 1/5 3/10 1/5] sage: G = SymmetricGroup(4) sage: g = G.an_element() sage: g (1,2,3,4) sage: ~g (1,4,3,2) s

Re: [sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread David Roe
On Mon, Dec 21, 2015 at 8:53 AM, Volker Braun wrote: > On Monday, December 21, 2015 at 5:43:29 PM UTC+1, John Cremona wrote: >> >> Of course it does but no mathematician would ever write that in notation >> as ~x. >> > > Its still a minor optimization (avoids coercion in 1/x), so I'm not so > sur

Re: [sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread Volker Braun
On Monday, December 21, 2015 at 5:43:29 PM UTC+1, John Cremona wrote: > > Of course it does but no mathematician would ever write that in notation > as ~x. > Its still a minor optimization (avoids coercion in 1/x), so I'm not so sure that nobody ever used it. In any case, if you are serious ab

Re: [sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread John Cremona
On 21 December 2015 at 16:40, Volker Braun wrote: > Just to point out the obvious: In Mathematics, "inverting an integer" means > 1/x Of course it does but no mathematician would ever write that in notation as ~x. > > Though if you want to work with Python ints nothing is stopping you... > > sag

[sage-devel] Re: Inverting Integers gives different behaviour than in Python

2015-12-21 Thread Volker Braun
Just to point out the obvious: In Mathematics, "inverting an integer" means 1/x Though if you want to work with Python ints nothing is stopping you... sage: ~2r -3 sage: ~int(2) -3 sage: ~2 1/2 sage: ~ZZ(2) 1/2 On Monday, December 21, 2015 at 5:22:20 PM UTC+1, Mark Bell wrote: > > In Python for