Dear William: I've sent you a patch for improving the rational numbers and integer implementations, more precisely:
-fixing multiplicative_order so that it returns +Infinity instead of raising an exception. - fixing bugs (still present in sage-2.4.2) like sage: a=1/2 sage: a.is_one() True sage: a.multiplicative_order() 1 - improving the documentation of lcm, gcd for rational numbers. (This functions are not standards and their documentation was not clear enough) Have you received it? Just in case, I sent here an updated version, both as a patch (clear text) and as a bundle. best regards Pablo > Hello, > > > > I've released sage-2.4.2. This is just a fairly minimal > > bugfix release, though there are number of important optimizations > > in it. There are probably about 10-15 patches from people > > in my patch inbox that I haven't included yet due to a > > lack of time. Those will be in the next SAGE release, > > which is planned for Sunday: > > http://www.sagemath.org:9002/sage_trac/milestone/sage-2.5 > > > > Here's the high-level changelog for this release: > > > > 2.4.2: > > * r bradshaw: very very fast sagex new implementation of > > graph plotting code. > > * t boothby: added compression of javascript so notebook > > loads more quickly. > > * r miller: optimization to graph automorphism code > > * k minola and m albrecht: build fixes to linbox and > sage_c_lib. > > * y qiang: transitioned dsage to use sqlite; many minor > bugfixes > > * w stein: wrote a MuPAD interface for SAGE. > > * w stein: added restore and reset commands to SAGE, to > (mostly) > > reset the state of SAGE and all interfaces very very > > > quickly without having to quit and restart SAGE. > > * w stein: p-adic L-series (numerous improvements) > > * c witty (referee by r bradshaw): improvements to floating > > point <---> rational conversions. > > Hello, > > I have a compilation failure with gdmodule-0.56.p2 on cygwin: > > Making script relocatable > sage-spkg gdmodule-0.56.p2 2>&1 > gdmodule-0.56.p2 > Machine: > CYGWIN_NT-5.1 SPROCKET2 1.5.19(0.150/4/2) 2006-01-20 13:28 i686 Cygwin > Deleting directories from past builds of previous/current versions of > gdmodule-0.56.p2 > Extracting package /cygdrive/d/sage- 2.4.2/spkg/standard/ > gdmodule-0.56.p2.spkg ... > -rwx------+ 1 test Kein 22331 Jan 10 19:24 /cygdrive/d/sage-2.4.2/spkg/ > standard/gdmodule-0.56.p2.spkg > gdmodule-0.56.p2/ > gdmodule-0.56.p2/_gdmodule.c > gdmodule-0.56.p2 /gd-ref.html > gdmodule-0.56.p2/gd.py > gdmodule-0.56.p2/install_notes.html > gdmodule-0.56.p2/PKG-INFO > gdmodule-0.56.p2/README > gdmodule-0.56.p2/sage/ > gdmodule-0.56.p2/sage/_gdmodule.c > gdmodule-0.56.p2/sage/Setup.py > gdmodule-0.56.p2/sage/Setup.py.cygwin > gdmodule-0.56.p2/SAGE.txt > gdmodule-0.56.p2/SAGE.txt~ > gdmodule-0.56.p2/Setup.py > gdmodule-0.56.p2/Setup.py~ > gdmodule-0.56.p2/spkg-install > gdmodule-0.56.p2/spkg-install~ > Finished extraction > **************************************************** > Host system > uname -a: > CYGWIN_NT-5.1 SPROCKET2 1.5.19(0.150/4/2) 2006-01-20 13:28 i686 Cygwin > **************************************************** > **************************************************** > GCC Version > gcc -v > Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs > Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose -- > prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib -- > libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info > --enable-languages=c,ada,c++,d,f77,java,objc --enable-nls --without- > included-gettext --enable-version-specific-runtime-libs --without-x -- > enable-libgcj --disable-java-awt --with-system-zlib --enable- > interpreter --disable-libgcj-debug --enable-threads=posix --enable- > java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions -- > enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured) > Thread model: posix > gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) > **************************************************** > WARNING: Missing libiconv Libraries > running build > running build_py > creating build > creating build/lib.cygwin-1.5.19-i686-2.5 > copying gd.py -> build/lib.cygwin-1.5.19-i686-2.5 > running build_ext > building '_gd' extension > creating build/temp.cygwin-1.5.19-i686-2.5 > gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes - > DHAVE_LIBGD -DHAVE_LIBPNG -DHAVE_LIBZ -DHAVE_LIBFREETYPE - > DHAVE_LIBLIBICONV -I/cygdrive/d/sage-2.4.2/local/include -I/usr/local/ > include -I/usr/include -I/usr/include/X11 -I/usr/X11R6/include -I/ > cygdrive/d/sage-2.4.2/local/include/python2.5 -c _gdmodule.c -o build/ > temp.cygwin-1.5.19-i686-2.5/_gdmodule.o > _gdmodule.c:152: warning: function declaration isn't a prototype > _gdmodule.c:169: warning: function declaration isn't a prototype > gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.5.19- > i686-2.5/_gdmodule.o -L/cygdrive/d/sage-2.4.2/local/lib -L/usr/local/ > lib -L/usr/lib -L/usr/lib/X11 -L/usr/X11R6/lib -L/cygdrive/d/ > sage-2.4.2 /local/lib/python2.5/config -lgd -lpng -lz -lfreetype - > llibiconv -lpython2.5 -o build/lib.cygwin-1.5.19-i686-2.5/_gd.dll > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1e90): undefined reference to `_FcConfigSubstitute' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1eab): undefined reference to `_FcConfigSubstitute' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1eb6): undefined reference to `_FcDefaultSubstitute' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1ed0): undefined reference to `_FcFontMatch' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1f82): undefined reference to `_FcPatternBuild' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1f9e): undefined reference to `_FcPatternDestroy' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x1fc6): undefined reference to `_FcPatternGetString' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x2005): undefined reference to `_FcPatternDestroy' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x2079): undefined reference to `_FcNameParse' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x2095): undefined reference to `_FcPatternDestroy' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x20bd): undefined reference to `_FcPatternGetString' > /cygdrive/d/sage-2.4.2/local/lib/libgd.a(gdft.o):gdft.c:(.text > +0x20e9): undefined reference to `_FcPatternDestroy' > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > Failure to build gdmodule > > real 0m2.750s > user 0m1.519s > sys 0m0.477s > sage: An error occured while installing gdmodule-0.56.p2 > Please email William Stein < [EMAIL PROTECTED]> explaining the > problem and send him the relevant part of > of /cygdrive/d/sage-2.4.2/install.log. Don't send the whole thing. > If you want to try to fix the problem, yourself *don't* just cd to > /cygdrive/d/sage-2.4.2/spkg/build/gdmodule-0.56.p2 and type 'make'. > Instead (using bash) type "source local/bin/sage-env" from the > directory > /cygdrive/d/sage-2.4.2 > in order to set all environment variables correctly, then cd to > /cygdrive/d/sage-2.4.2/spkg/build/gdmodule-0.56.p2 > make[1]: *** [installed/gdmodule-0.56.p2] Error 1 > make[1]: Leaving directory `/cygdrive/d/sage-2.4.2/spkg' > > real 22m45.250s > user 28m8.575s > sys 10m3.163s > > The problem has happened in the past (there is a thread regarding this > with the 1.6 release), but I have fontconfig installed (from sources). > Might that be related to "WARNING: Missing libiconv Libraries"? > According to the link failure the missing symbols are not from > libiconv. > > Cheers, > > Michael > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [EMAIL PROTECTED] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---
diff -r 58f0060fc358 -r 3e505971184e sage/ext/cdefs.pxi
--- a/sage/ext/cdefs.pxi Sat Mar 31 23:53:27 2007 -0700
+++ b/sage/ext/cdefs.pxi Fri Apr 13 12:29:59 2007 -0300
@@ -47,6 +47,7 @@ cdef extern from "gmp.h":
void mpz_ior (mpz_t rop, mpz_t op1, mpz_t op2)
void mpz_clear(mpz_t integer)
int mpz_cmp(mpz_t op1, mpz_t op2)
+ int mpz_cmpabs(mpz_t op1, mpz_t op2)
int mpz_cmp_si(mpz_t op1, signed long int op2)
int mpz_cmp_ui(mpz_t op1, unsigned long int op2)
void mpz_divexact (mpz_t q, mpz_t n, mpz_t d)
diff -r 58f0060fc358 -r 3e505971184e sage/rings/integer.pyx
--- a/sage/rings/integer.pyx Sat Mar 31 23:53:27 2007 -0700
+++ b/sage/rings/integer.pyx Fri Apr 13 12:29:59 2007 -0300
@@ -12,6 +12,7 @@ AUTHORS:
-- David Harvey (2006-09-16): attempt to optimise Integer constructor
-- Rishikesh (2007-02-25): changed quo_rem so that the rem is positive
-- David Harvey, Martin Albrecht, Robert Bradshaw (2007-03-01): optimized Integer constructor and pool
+ -- Pablo De Napoli (2007-04-01): multiplicative_order should return +infinity for non zero numbers
EXAMPLES:
Add 2 integers:
@@ -1450,8 +1451,7 @@ cdef class Integer(sage.structure.elemen
def multiplicative_order(self):
r"""
- Return the multiplicative order of self, if self is a unit, or raise
- \code{ArithmeticError} otherwise.
+ Return the multiplicative order of self.
EXAMPLES:
sage: ZZ(1).multiplicative_order()
@@ -1459,20 +1459,17 @@ cdef class Integer(sage.structure.elemen
sage: ZZ(-1).multiplicative_order()
2
sage: ZZ(0).multiplicative_order()
- Traceback (most recent call last):
- ...
- ArithmeticError: no power of 0 is a unit
+ +Infinity
sage: ZZ(2).multiplicative_order()
- Traceback (most recent call last):
- ...
- ArithmeticError: no power of 2 is a unit
- """
- if mpz_cmp_si(self.value, 1) == 0:
- return Integer(1)
+ +Infinity
+ """
+ import sage.rings.infinity
+ if mpz_cmp_si(self.value, 1) == 0:
+ return Integer(1)
elif mpz_cmp_si(self.value, -1) == 0:
- return Integer(2)
+ return Integer(2)
else:
- raise ArithmeticError, "no power of %s is a unit"%self
+ return sage.rings.infinity.infinity
def is_squarefree(self):
"""
diff -r 58f0060fc358 -r 3e505971184e sage/rings/rational.pyx
--- a/sage/rings/rational.pyx Sat Mar 31 23:53:27 2007 -0700
+++ b/sage/rings/rational.pyx Fri Apr 13 12:29:59 2007 -0300
@@ -9,6 +9,8 @@ AUTHORS:
-- William Stein and Naqi Jaffery (2006-03-06): height, sqrt examples,
and improve behavior of sqrt.
-- David Harvey (2006-09-15): added nth_root
+ -- Pablo De Napoli (2007-04-01): corrected the implementations of
+ multiplicative_order, is_one; optimzed __nonzero__ ; documented: lcm,gcd
"""
@@ -322,21 +324,61 @@ cdef class Rational(sage.structure.eleme
return codomain._coerce_(self)
def lcm(self, Rational other):
- """
+ r"""
Return the least common multiple of self and other.
-
- Our hopefully interesting notion of LCM for rational numbers
- is illustrated in the examples below.
-
- EXAMPLES:
+
+ One way to define this notion is the following:
+
+ Note that each rational positive rational number can be written
+ as a product of primes with integer (positive or negative)
+ powers in a unique way.
+
+ Then, the LCM of two rational numbers x,y can be defined by
+ specifying that the exponent of every prime p in lcm(x,y)
+ is the maximum of the exponents of p in x,
+ and the exponent of p in y
+ (The primes that does not appear in the decomposition of x
+ or y are considered to have exponent zero).
+
+ This definition is consistent with the definition of the LCM
+ in the rational integers. Our hopefully interesting notion of LCM
+ for rational numbers is illustrated in the examples below.
+
+ EXAMPLES:
+
sage: lcm(2/3,1/5)
2
+
+ This is consistent with the definition above, since:
+ 2/3 = 2^1 * 3^{-1}*5^0
+ 1/5 = 2^0 * 3^0 *5^{-1}
+ and hence,
+ lcm(2/3,1/5)= 2^1*3^0*5^0 = 2
+
sage: lcm(2/3,7/5)
14
+
+ In this example:
+ 2/3 = 2^1*3^{-1}*5^0 * 7^0
+ 7/5 = 2^0*3^0 *5^{-1} * 7^1
+ lcm(2/3,7/5) = 2^1*3^0*5^0*7^1 = 14
+
sage: lcm(1/3,1/5)
1
+
+ In this example:
+ 1/3 = 3^{-1}*5^0
+ 1/5 = 3^0 * 5^{-1}
+ lcm(1/3,1/5)=3^0*5^0=1
+
sage: lcm(1/3,1/6)
1/3
+
+ In this example:
+ 1/3 = 2^0*3^{-1}
+ 1/6 = 2^{-1}*3^{-1}
+ lcm(1/3,1/6)=2^0*3^{-1}=1/3
+
"""
d = self.denom()*other.denom()
self_d = self.numer()*other.denom()
@@ -346,19 +388,58 @@ cdef class Rational(sage.structure.eleme
def gcd(self, Rational other):
"""
Return the least common multiple of self and other.
-
- Our hopefully interesting notion of GCD for rational numbers
- is illustrated in the examples below.
-
- EXAMPLES:
+
+ One way to define this notion is the following:
+
+ Note that each rational positive rational number can be written
+ as a product of primes with integer (positive or negative)
+ powers in a unique way.
+
+ Then, the GCD of two rational numbers x,y can be defined by
+ specifying that the exponent of every prime p in gcd(x,y) is
+ the minimum of the exponents of p in x,
+ and the exponent of p in y
+ (The primes that does not appear in the decomposition of x or y
+ are considered to have exponent zero).
+
+ This definition is consistent with the definition of the GCD
+ in the rational integers. Our hopefully interesting notion of GCD
+ for rational numbers is illustrated in the examples below.
+
+ EXAMPLES:
+
sage: gcd(2/3,1/5)
1/15
+
+ This is consistent with the definition above, since:
+ 2/3 = 2^1 * 3^{-1}*5^0
+ 1/5 = 2^0 * 3^0 *5^{-1}
+ and hence,
+ gcd(2/3,1/5)= 2^0*3^{-1}*5^{-1} = 1/15
+
sage: gcd(2/3,7/5)
1/15
+
+ In this example:
+ 2/3 = 2^1*3^{-1}*5^0 * 7^0
+ 7/5 = 2^0*3^0 *5^{-1} * 7^1
+ gcd(2/3,7/5) = 2^0*3^{-1}*5^{-1}*7^0 = 1/15
+
sage: gcd(1/3,1/6)
1/6
+
+ In this example:
+ 1/3 = 2^0*3^{-1}
+ 1/6 = 2^{-1}*3^{-1}
+ gcd(1/3,1/6)=2^{-1}*3^{-1}=1/6
+
sage: gcd(6/7,9/7)
3/7
+
+ In this example:
+ 6/7 = 2^1*3^1*7^{-1}
+ 9/7 = 2^0*3^2*7^{-1}
+ gcd(6/7,9/7)=2^0*3^1*7^{-1}=3/7
"""
d = self.denom()*other.denom()
self_d = self.numer()*other.denom()
@@ -695,7 +776,8 @@ cdef class Rational(sage.structure.eleme
return x
def __nonzero__(self):
- return not self.numerator().is_zero()
+ # A rational number is zero iff its numerator is zero.
+ return bool(mpz_cmp_si(mpq_numref(self.value), 0) != 0)
def __abs__(self):
cdef Rational x
@@ -1018,8 +1100,7 @@ cdef class Rational(sage.structure.eleme
def multiplicative_order(self):
"""
- Return the multiplicative order of self, if self is a unit, or raise
- \code{ArithmeticError} otherwise.
+ Return the multiplicative order of self.
EXAMPLES:
sage: QQ(1).multiplicative_order()
@@ -1027,25 +1108,47 @@ cdef class Rational(sage.structure.eleme
sage: QQ('1/-1').multiplicative_order()
2
sage: QQ(0).multiplicative_order()
- Traceback (most recent call last):
- ...
- ArithmeticError: no power of 0 is a unit
+ +Infinity
sage: QQ('2/3').multiplicative_order()
- Traceback (most recent call last):
- ...
- ArithmeticError: no power of 2/3 is a unit
- """
- if mpz_cmp_si(mpq_numref(self.value), 1) == 0:
+ +Infinity
+ sage: QQ('1/2').multiplicative_order()
+ +Infinity
+ """
+ import sage.rings.infinity
+ if self.is_one():
return integer.Integer(1)
- elif mpz_cmp_si(mpq_numref(self.value), -1) == 0:
+ elif bool(mpz_cmpabs(mpq_numref(self.value),mpq_denref(self.value))==0):
+ # if the numerator and the denominator are equal in absolute value,
+ # then the rational number is -1
return integer.Integer(2)
else:
- raise ArithmeticError, "no power of %s is a unit"%self
-
+ return sage.rings.infinity.infinity
+
def is_one(self):
- return bool(mpz_cmp_si(mpq_numref(self.value), 1) == 0)
+ r"""
+ Determine if a rational number is one.
+
+ EXAMPLES:
+
+ sage: QQ(1/2).is_one()
+ False
+ sage: QQ(4/4).is_one()
+ True
+ """
+ # A rational number is equal to 1 iff its numerator and denominator are equal
+ return bool(mpz_cmp(mpq_numref(self.value),mpq_denref(self.value))==0)
def is_zero(self):
+ r"""Test if a rational number is zero
+
+ EXAMPLES:
+
+ sage: QQ(1/2).is_zero()
+ False
+ sage: QQ(0/4).is_zero()
+ True
+ """
+ # A rational number is zero iff its numerator is zero.
return bool(mpz_cmp_si(mpq_numref(self.value), 0) == 0)
cdef _lshift(self, long int exp):
sage_fixes.bundle
Description: Binary data
