wangtongada / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

string representation of mpq wihich are integers #41

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In gmpy 1.11

>>> print mpq(3,1)
3/1

while in gmpy 1.0.3
>>> print mpq(3,1)
3

Why has this been changed? The latter is shorter and behaves as Fraction
>>> from fractions import Fraction
>>> print Fraction(3,1)
3

and as in Sage
sage: R.<x> = QQ[]
sage: 3*x + 2/3
3*x + 2/3
(not 3/1*x + 2/3)

I would like to suggest to go back to this form, or at least to allow
it setting an environment parameter.

Mario

Original issue reported on code.google.com by mario.pe...@gmail.com on 21 Jul 2010 at 8:28

GoogleCodeExporter commented 8 years ago
Mario,

The change was an error on my part. mpq is supposed to behave just like 
Fraction. I'll create tags/gmpy_1_13 with the fix in a day or two.

Thanks for the bug report.

Case

Original comment by casevh on 22 Jul 2010 at 6:03

GoogleCodeExporter commented 8 years ago
Thanks.

> mpq is supposed to behave just like Fraction.

Another difference between the two is
>>> a = mpq(1,3)
>>> print a.numer()
1

>>> b = Fraction(1,3)
>>> print b.numerator
1

similarly for the denominator.
Is it possible to add to gmpy.mpq something like

numerator = property(numer)

to allow the same call for both?

Mario

Original comment by mario.pe...@gmail.com on 22 Jul 2010 at 7:44

GoogleCodeExporter commented 8 years ago
I've committed tags/gmpy_1_13 and it should fix the formatting. I also added 
improved caching for mpq types. I'm curious if you notice any performance 
improvements.

I'll work on adding .numerator etc. next.

Case

Original comment by casevh on 23 Jul 2010 at 6:40

GoogleCodeExporter commented 8 years ago
Thank you.

With version 1.13 I get 1-3% speedup.

Mario

Original comment by mario.pe...@gmail.com on 24 Jul 2010 at 6:57

GoogleCodeExporter commented 8 years ago
I've added .numerator and .denominator to 1.13.

How soon do need this version officially released?

Case

Original comment by casevh on 26 Jul 2010 at 6:47

GoogleCodeExporter commented 8 years ago

> I've added .numerator and .denominator to 1.13.

Great!

Mario

Original comment by mario.pe...@gmail.com on 26 Jul 2010 at 2:45

GoogleCodeExporter commented 8 years ago
1.13 is officially released.

Original comment by casevh on 31 Aug 2010 at 5:23

GoogleCodeExporter commented 8 years ago
Mario,

While running some additional tests, I think my fix has a problem. Below is the 
behaviour of the Fractions module, gmpy, and gmpy2 (development branch).

>>> from fractions import Fraction
>>> str(Fraction(3,1))
'3'
>>> repr(Fraction(3,1))
'Fraction(3, 1)'
>>> from gmpy import mpq
>>> str(mpq(3,1))
'3'
>>> repr(mpq(3,1))
'mpq(3)'
>>> from gmpy2 import mpq
>>> str(mpq(3,1))
'3'
>>> repr(mpq(3,1))
'mpq(3,1)

Right now, gmpy 1.13 doesn't display the denominator of 1 even with repr. (The 
earlier bug displayed a denominator of 1 in all cases.) I'm planning a 1.14 
release within a few weeks. Will you have any problems if I use the gmpy2 
formatting rules since they match Fraction's?

casevh

Original comment by casevh on 26 Oct 2010 at 6:09

GoogleCodeExporter commented 8 years ago
Hi,

str(mpq(3,1))

 is quite fine.

Mario

Original comment by mario.pe...@gmail.com on 26 Oct 2010 at 8:37