Ticket #11854: 11854.patch

File 11854.patch, 20.3 KB (added by jdemeyer, 11 years ago)
  • c_lib/include/convert.h

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1317728758 -7200
    # Node ID 7a69ffa86a2848436e28225813d3f5babd96e83f
    # Parent  aeaa3a623defbcfee3305e6d9fdea55c7d24e8ce
    Rewrite various conversions to PARI, remove broken functions in convert.h
    
    diff --git a/c_lib/include/convert.h b/c_lib/include/convert.h
    a b  
    1313#include <stdio.h>
    1414
    1515void t_INT_to_ZZ ( mpz_t value, GEN g );
    16 
    17 void ZZ_to_t_INT ( GEN *g, mpz_t value );
    18 
    1916void t_FRAC_to_QQ ( mpq_t value, GEN g );
    20 
    21 void QQ_to_t_FRAC ( GEN *g, mpq_t value );
  • c_lib/include/stdsage.h

    diff --git a/c_lib/include/stdsage.h b/c_lib/include/stdsage.h
    a b  
    4343extern "C" {
    4444#endif
    4545
     46
    4647/*****************************************
    47           For PARI
    48           Memory management
     48   PARI array element assignment
     49 *****************************************/
     50#define set_gel(x, n, z)         (gel(x,n) = z)
     51#define set_gmael(x, i, j, z)    (gmael(x,i,j) = z)
     52#define set_gcoeff(x, i, j, z)   (gcoeff(x,i,j) = z)
    4953
    50  *****************************************/
    51 
    52 #define set_gel(x, n, z)  (gel(x,n) = z)
    5354
    5455/******************************************
    5556 Some macros exported for Pyrex in cdefs.pxi
  • c_lib/src/convert.c

    diff --git a/c_lib/src/convert.c b/c_lib/src/convert.c
    a b  
    3737  return;
    3838}
    3939
    40 void ZZ_to_t_INT ( GEN *g, mpz_t value )
    41 {
    42   long limbs = 0;
    43 
    44   limbs = mpz_size( value );
    45 
    46   *g = cgetg( limbs+2, t_INT );
    47   settyp( *g, t_INT );
    48   setlgefint( *g, limbs+2 );
    49   setsigne( *g, mpz_sgn(value) );
    50 
    51   mpz_export( int_LSW(*g), NULL, -1, sizeof(long), 0, 0, value );
    52 
    53   return;
    54 }
    55 
    5640
    5741/*
    5842
     
    7054    t_INT_to_ZZ(mpq_numref(value), numer(g));
    7155    t_INT_to_ZZ(mpq_denref(value), denom(g));
    7256}
    73 
    74 void QQ_to_t_FRAC ( GEN *g, mpq_t value )
    75 {
    76     GEN num, den;
    77     ZZ_to_t_INT(&num, mpq_numref(value));
    78     ZZ_to_t_INT(&den, mpq_denref(value));
    79     *g = gdiv(num, den);
    80 }
  • sage/libs/pari/decl.pxi

    diff --git a/sage/libs/pari/decl.pxi b/sage/libs/pari/decl.pxi
    a b  
    15731573    extern char* diffptr
    15741574
    15751575cdef extern from 'stdsage.h':
    1576     GEN set_gel(GEN x, long n, GEN z)    # gel(x,n) = z
     1576    GEN set_gel(GEN x, long n, GEN z)              # gel(x,n) = z
     1577    GEN set_gmael(GEN x, long i, long j, GEN z)    # gmael(x,i,j) = z
     1578    GEN set_gcoeff(GEN x, long i, long j, GEN z)   # gcoeff(x,i,j) = z
    15771579
    15781580
    15791581# Inline functions in separate file
  • sage/libs/pari/gen.pxd

    diff --git a/sage/libs/pari/gen.pxd b/sage/libs/pari/gen.pxd
    a b  
    2525    cdef gen new_gen_from_mpz_t(self, mpz_t value)
    2626    cdef inline GEN _new_GEN_from_mpz_t(self, mpz_t value)
    2727    cdef gen new_gen_from_mpq_t(self, mpq_t value)
     28    cdef inline GEN _new_GEN_from_mpq_t(self, mpq_t value)
    2829    cdef gen new_gen_from_int(self, int value)
    2930    cdef gen new_t_POL_from_int_star(self, int *vals, int length, long varnum)
    3031    cdef gen new_gen_from_padic(self, long ordp, long relprec, mpz_t prime, mpz_t p_pow, mpz_t unit)
     
    3637    cdef gen new_ref(self, GEN g, gen parent)
    3738    cdef gen _empty_vector(self, long n)
    3839    cdef long get_var(self, v)
    39     cdef GEN toGEN(self, x, int i) except NULL   
    40     cdef GEN integer_matrix_GEN(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0
    41     cdef GEN integer_matrix_permuted_for_hnf_GEN(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0
    42     cdef integer_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf)
    43     cdef GEN rational_matrix_GEN(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0
    44     cdef rational_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc)
    45 
    46    
    47    
    48    
     40    cdef GEN toGEN(self, x, int i) except NULL
     41    cdef GEN _new_GEN_from_mpz_t_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc)
     42    cdef GEN _new_GEN_from_mpz_t_matrix_rotate90(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc)
     43    cdef gen integer_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf)
     44    cdef GEN _new_GEN_from_mpq_t_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc)
     45    cdef gen rational_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc)
  • sage/libs/pari/gen.pyx

    diff --git a/sage/libs/pari/gen.pyx b/sage/libs/pari/gen.pyx
    a b  
    1515- Robert Bradshaw, Jeroen Demeyer, William Stein (2010-08-15):
    1616  Upgrade to PARI 2.4.3 (#9343)
    1717
     18- Jeroen Demeyer (2011-09-27): rewrite various conversion routines
     19  (#11611, #11854)
     20
     21
    1822EXAMPLES::
    1923
    2024    sage: pari('5! + 10/x')
     
    147151
    148152"""
    149153
     154#*****************************************************************************
     155#       Copyright (C) 2006,2010 William Stein <wstein@gmail.com>
     156#       Copyright (C) ???? Justin Walker
     157#       Copyright (C) ???? Gonzalo Tornaria
     158#       Copyright (C) 2010 Robert Bradshaw <robertwb@math.washington.edu>
     159#       Copyright (C) 2010,2011 Jeroen Demeyer <jdemeyer@cage.ugent.be>
     160#
     161#  Distributed under the terms of the GNU General Public License (GPL)
     162#  as published by the Free Software Foundation; either version 2 of
     163#  the License, or (at your option) any later version.
     164#                  http://www.gnu.org/licenses/
     165#*****************************************************************************
     166
     167
    150168import sys
    151169import math
    152170import types
     
    162180include 'pari_err.pxi'
    163181include '../../ext/stdsage.pxi'
    164182
    165 cdef extern from "convert.h":
    166     cdef void ZZ_to_t_INT( GEN *g, mpz_t value )
    167     cdef void QQ_to_t_FRAC( GEN *g, mpq_t value )
    168 
    169183# Make sure we don't use mpz_t_offset before initializing it by
    170184# putting in a value that's likely to provoke a segmentation fault,
    171185# rather than silently corrupting memory.
     
    90149028        """
    90159029        Create a new gen from a given MPIR-integer ``value``.
    90169030
     9031        EXAMPLES::
     9032
     9033            sage: pari(42)       # indirect doctest
     9034            42
     9035
    90179036        TESTS:
    90189037
    90199038        Check that the hash of an integer does not depend on existing
     
    90309049        return self.new_gen(self._new_GEN_from_mpz_t(value))
    90319050
    90329051    cdef inline GEN _new_GEN_from_mpz_t(self, mpz_t value):
    9033         # Create a new PARI GEN from a mpz_t.  For internal use only,
    9034         # this directly uses the PARI stack.
    9035         # One should call sig_on() before and sig_off() after.
    9036 
     9052        r"""
     9053        Create a new PARI ``t_INT`` from a ``mpz_t``.
     9054
     9055        For internal use only; this directly uses the PARI stack.
     9056        One should call ``sig_on()`` before and ``sig_off()`` after.
     9057        """
    90379058        cdef unsigned long limbs = mpz_size(value)
    90389059
    90399060        cdef GEN z = cgeti(limbs + 2)
     
    90499070
    90509071    cdef gen new_gen_from_mpq_t(self, mpq_t value):
    90519072        """
    9052         EXAMPLES::
    9053             sage: pari(2/3)       # indirect doctest
    9054             2/3
    9055         """
    9056         cdef GEN z
    9057         sig_on()
    9058         QQ_to_t_FRAC(&z, value)
    9059         return self.new_gen(z)
     9073        Create a new gen from a given MPIR-rational ``value``.
     9074
     9075        EXAMPLES::
     9076
     9077            sage: pari(-2/3)
     9078            -2/3
     9079            sage: pari(QQ(42))
     9080            42
     9081            sage: pari(QQ(42)).type()
     9082            't_INT'
     9083            sage: pari(QQ(1/42)).type()
     9084            't_FRAC'
     9085
     9086        TESTS:
     9087
     9088        Check that the hash of a rational does not depend on existing
     9089        garbage on the stack (#11854)::
     9090
     9091            sage: foo = pari(2^(32*1024));  # Create large integer to put PARI stack in known state
     9092            sage: a5 = pari(5/7);
     9093            sage: foo = pari(0xDEADBEEF * (2^(32*1024)-1)//(2^32 - 1));  # Dirty PARI stack
     9094            sage: b5 = pari(5/7);
     9095            sage: a5.__hash__() == b5.__hash__()
     9096            True
     9097        """
     9098        sig_on()
     9099        return self.new_gen(self._new_GEN_from_mpq_t(value))
     9100
     9101    cdef inline GEN _new_GEN_from_mpq_t(self, mpq_t value):
     9102        r"""
     9103        Create a new PARI ``t_INT`` or ``t_FRAC`` from a ``mpq_t``.
     9104
     9105        For internal use only; this directly uses the PARI stack.
     9106        One should call ``sig_on()`` before and ``sig_off()`` after.
     9107        """
     9108        cdef GEN num = self._new_GEN_from_mpz_t(mpq_numref(value))
     9109        if mpz_cmpabs_ui(mpq_denref(value), 1) == 0:
     9110            # Denominator is 1, return the numerator (an integer)
     9111            return num
     9112        cdef GEN denom = self._new_GEN_from_mpz_t(mpq_denref(value))
     9113        return mkfrac(num, denom)
    90609114
    90619115    cdef gen new_t_POL_from_int_star(self, int *vals, int length, long varnum):
    90629116        """
     
    92889342            return None
    92899343        return self.new_gen(g)
    92909344
    9291     cdef GEN integer_matrix_GEN(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0:
    9292         """
    9293         EXAMPLES::
    9294 
    9295             sage: matrix(ZZ,2,[1..6])._pari_()   # indirect doctest
    9296             [1, 2, 3; 4, 5, 6]
    9297        
    9298         """
    9299         cdef GEN x,  A = gtomat(zeromat(nr, nc))
     9345    cdef GEN _new_GEN_from_mpz_t_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc):
     9346        r"""
     9347        Create a new PARI ``t_MAT`` with ``nr`` rows and ``nc`` columns
     9348        from a ``mpz_t**``.
     9349
     9350        For internal use only; this directly uses the PARI stack.
     9351        One should call ``sig_on()`` before and ``sig_off()`` after.
     9352        """
     9353        cdef GEN x
     9354        cdef GEN A = zeromatcopy(nr, nc)
    93009355        cdef Py_ssize_t i, j
    93019356        for i in range(nr):
    93029357            for j in range(nc):
    9303                 ZZ_to_t_INT(&x, B[i][j])
    9304                 (<GEN>(A[j+1]))[i+1] = <long>x
     9358                x = self._new_GEN_from_mpz_t(B[i][j])
     9359                set_gcoeff(A, i+1, j+1, x)  # A[i+1, j+1] = x (using 1-based indexing)
    93059360        return A
    93069361
    9307     cdef GEN integer_matrix_permuted_for_hnf_GEN(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0:
    9308         cdef GEN x,  A = gtomat(zeromat(nc, nr))
     9362    cdef GEN _new_GEN_from_mpz_t_matrix_rotate90(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc):
     9363        r"""
     9364        Create a new PARI ``t_MAT`` with ``nr`` rows and ``nc`` columns
     9365        from a ``mpz_t**`` and rotate the matrix 90 degrees
     9366        counterclockwise.  So the resulting matrix will have ``nc`` rows
     9367        and ``nr`` columns.  This is useful for computing the Hermite
     9368        Normal Form because Sage and PARI use different definitions.
     9369
     9370        For internal use only; this directly uses the PARI stack.
     9371        One should call ``sig_on()`` before and ``sig_off()`` after.
     9372        """
     9373        cdef GEN x
     9374        cdef GEN A = zeromatcopy(nc, nr)
    93099375        cdef Py_ssize_t i, j
    93109376        for i in range(nr):
    93119377            for j in range(nc):
    9312                 ZZ_to_t_INT(&x, B[i][nc-j-1])
    9313                 (<GEN>(A[i+1]))[j+1] = <long>x
     9378                x = self._new_GEN_from_mpz_t(B[i][nc-j-1])
     9379                set_gcoeff(A, j+1, i+1, x)  # A[j+1, i+1] = x (using 1-based indexing)
    93149380        return A
    93159381
    9316     cdef integer_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf):
     9382    cdef gen integer_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf):
    93179383        """
    93189384        EXAMPLES::
    93199385
     
    93239389        sig_on()
    93249390        cdef GEN g
    93259391        if permute_for_hnf:
    9326             g = self.integer_matrix_permuted_for_hnf_GEN(B, nr, nc)
     9392            g = self._new_GEN_from_mpz_t_matrix_rotate90(B, nr, nc)
    93279393        else:
    9328             g = self.integer_matrix_GEN(B, nr, nc)
     9394            g = self._new_GEN_from_mpz_t_matrix(B, nr, nc)
    93299395        return self.new_gen(g)
    93309396   
    9331     cdef GEN rational_matrix_GEN(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc) except <GEN>0:
    9332         """
    9333         EXAMPLES::
    9334        
    9335             sage: matrix(QQ,2,[1..6])._pari_()   # indirect doctest
    9336             [1, 2, 3; 4, 5, 6]
    9337         """
    9338         cdef GEN x,  A = gtomat(zeromat(nr, nc))
     9397    cdef GEN _new_GEN_from_mpq_t_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc):
     9398        cdef GEN x
     9399        # Allocate zero matrix
     9400        cdef GEN A = zeromatcopy(nr, nc)
    93399401        cdef Py_ssize_t i, j
    93409402        for i in range(nr):
    93419403            for j in range(nc):
    9342                 QQ_to_t_FRAC(&x, B[i][j])
    9343                 (<GEN>(A[j+1]))[i+1] = <long>x
     9404                x = self._new_GEN_from_mpq_t(B[i][j])
     9405                set_gcoeff(A, i+1, j+1, x)  # A[i+1, j+1] = x (using 1-based indexing)
    93449406        return A
    93459407
    9346     cdef rational_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc):
     9408    cdef gen rational_matrix(self, mpq_t** B, Py_ssize_t nr, Py_ssize_t nc):
    93479409        """
    93489410        EXAMPLES::
    93499411       
     
    93519413            [1, 2, 3; 4, 5, 6]
    93529414        """
    93539415        sig_on()
    9354         cdef GEN g = self.rational_matrix_GEN(B, nr, nc)
     9416        cdef GEN g = self._new_GEN_from_mpq_t_matrix(B, nr, nc)
    93559417        return self.new_gen(g)
    93569418
    93579419    cdef _coerce_c_impl(self, x):
  • sage/libs/pari/misc.h

    diff --git a/sage/libs/pari/misc.h b/sage/libs/pari/misc.h
    a b  
    11/*****************************************
    2           For PARI
     2   PARI misc macros and functions
     3 *****************************************/
     4#ifndef SAGE_LIBS_PARI_MISC_H
     5#define SAGE_LIBS_PARI_MISC_H
    36
    4  *****************************************/
    57#include <pari/pari.h>
    68#include "interrupt.h"
    79
    8 #define set_gel(x, n, z)  gel(x,n)=z;
    910
     11/*****************************************
     12   Interrupts and PARI exception handling
     13 *****************************************/
    1014#define _pari_sig_on() sig_on(); _pari_catch;
    1115#define _pari_sig_str(s) sig_str(s); _pari_catch;
    1216#define _pari_sig_off() _pari_endcatch; sig_off();
    1317
     18
    1419inline int strcmp_to_cmp(int f) {
    1520    if (f > 0) {
    1621      return 1;
     
    108113  }
    109114  return 0;
    110115}
     116
     117#endif  /* SAGE_LIBS_PARI_MISC_H */
  • sage/matrix/matrix_integer_dense.pxd

    diff --git a/sage/matrix/matrix_integer_dense.pxd b/sage/matrix/matrix_integer_dense.pxd
    a b  
    4040cdef void four_dim_det(mpz_t, mpz_t *)
    4141
    4242################################################################
    43 # fast conversion to pari on the stack
     43# fast conversion to PARI on the stack
    4444################################################################
    45 cdef GEN pari_GEN(Matrix_integer_dense B)
     45cdef inline GEN pari_GEN(Matrix_integer_dense B)
  • sage/matrix/matrix_integer_dense.pyx

    diff --git a/sage/matrix/matrix_integer_dense.pyx b/sage/matrix/matrix_integer_dense.pyx
    a b  
    7575    long    rank(GEN x)
    7676   
    7777cdef extern from "convert.h":
    78     void ZZ_to_t_INT ( GEN *g, mpz_t value )
    7978    cdef void t_INT_to_ZZ( mpz_t value, long *g )
    8079
    8180#########################################################
     
    48124811            [0 0 0]
    48134812        """
    48144813        cdef PariInstance P = sage.libs.pari.gen.pari
    4815         cdef GEN x, A = gtomat(zeromat(self._ncols, self._nrows))
    4816         cdef Py_ssize_t i, j
    4817         # We make the matrix A got from self by reversing the order of
    4818         # the columns and transposing.  This is needed since PARI's
    4819         # hnf does column operations instead of row operations.
    4820         for i in range(self._nrows):
    4821             for j in range(self._ncols):
    4822                 ZZ_to_t_INT(&x, self._matrix[i][self._ncols-j-1])
    4823                 (<GEN>(A[i+1]))[j+1] = <long>x
    4824 
    4825         # Actually compute the HNF using PARI.
     4814        cdef GEN A
    48264815        sig_on()
     4816        A = P._new_GEN_from_mpz_t_matrix_rotate90(self._matrix, self._nrows, self._ncols)
    48274817        cdef GEN H = mathnf0(A, flag)
    48284818        B = self.extract_hnf_from_pari_matrix(H, flag, include_zero_rows)
    4829         P.clear_stack()
     4819        P.clear_stack()  # This calls sig_off()
    48304820        return B
    48314821
    48324822
     
    48734863                t_INT_to_ZZ(B._matrix[j][self._ncols-i-1], gcoeff(H, i+1, H_nc-j))
    48744864        return B
    48754865
    4876 cdef GEN pari_GEN(Matrix_integer_dense B):
    4877     """
     4866cdef inline GEN pari_GEN(Matrix_integer_dense B):
     4867    r"""
    48784868    Create the PARI GEN object on the stack defined by the integer
    48794869    matrix B. This is used internally by the function for conversion
    48804870    of matrices to PARI.
    4881    
    4882     EXAMPLES::
    4883    
    4884         sage: matrix(ZZ,1,[1..4])._pari_()            # implicit doctest
    4885         Mat([1, 2, 3, 4])
     4871
     4872    For internal use only; this directly uses the PARI stack.
     4873    One should call ``sig_on()`` before and ``sig_off()`` after.
    48864874    """
    4887     cdef GEN x,  A = gtomat(zeromat(B._nrows, B._ncols))
    4888     cdef Py_ssize_t i, j
    4889     for i in range(B._nrows):
    4890         for j in range(B._ncols):
    4891             ZZ_to_t_INT(&x, B._matrix[i][j])
    4892             (<GEN>(A[j+1]))[i+1] = <long>x
     4875    cdef PariInstance P = sage.libs.pari.gen.pari
     4876    cdef GEN A
     4877    A = P._new_GEN_from_mpz_t_matrix(B._matrix, B._nrows, B._ncols)
    48934878    return A
    48944879   
    48954880
  • sage/matrix/matrix_rational_dense.pxd

    diff --git a/sage/matrix/matrix_rational_dense.pxd b/sage/matrix/matrix_rational_dense.pxd
    a b  
    2828# fast conversion to pari on the stack
    2929################################################################
    3030ctypedef long* GEN
    31 cdef GEN pari_GEN(Matrix_rational_dense B)
     31cdef inline GEN pari_GEN(Matrix_rational_dense B)
  • sage/matrix/matrix_rational_dense.pyx

    diff --git a/sage/matrix/matrix_rational_dense.pyx b/sage/matrix/matrix_rational_dense.pyx
    a b  
    9696
    9797cdef extern from "convert.h":
    9898    void t_FRAC_to_QQ ( mpq_t value, GEN g )
    99     void QQ_to_t_FRAC ( GEN *g, mpq_t value )
    10099
    101100#########################################################
    102101
     
    27282727            t_FRAC_to_QQ(B._matrix[i][j], gcoeff(d, i+1, j+1))
    27292728    return B
    27302729
    2731 cdef GEN pari_GEN(Matrix_rational_dense B):
     2730cdef inline GEN pari_GEN(Matrix_rational_dense B):
     2731    r"""
     2732    Create the PARI GEN object on the stack defined by the rational
     2733    matrix B. This is used internally by the function for conversion
     2734    of matrices to PARI.
     2735
     2736    For internal use only; this directly uses the PARI stack.
     2737    One should call ``sig_on()`` before and ``sig_off()`` after.
    27322738    """
    2733     EXAMPLES::
    2734 
    2735         sage: matrix(QQ,2,3,[1..6])._rank_pari()           # indirect doctest
    2736         2
    2737     """
    2738     cdef GEN x,  A = gtomat(zeromat(B._nrows, B._ncols))
    2739     cdef Py_ssize_t i, j
    2740     for i in range(B._nrows):
    2741         for j in range(B._ncols):
    2742             QQ_to_t_FRAC(&x, B._matrix[i][j])
    2743             (<GEN>(A[j+1]))[i+1] = <long>x
     2739    cdef PariInstance P = sage.libs.pari.gen.pari
     2740    cdef GEN A
     2741    A = P._new_GEN_from_mpq_t_matrix(B._matrix, B._nrows, B._ncols)
    27442742    return A
    27452743
  • sage/rings/fast_arith.pyx

    diff --git a/sage/rings/fast_arith.pyx b/sage/rings/fast_arith.pyx
    a b  
    5353from sage.libs.pari.gen cimport gen as pari_gen
    5454from sage.rings.integer cimport Integer
    5555
    56 cdef extern from "convert.h":
    57     cdef void t_INT_to_ZZ(mpz_t value, long *g)
    58 
    5956cpdef prime_range(start, stop=None, algorithm="pari_primes", bint py_ints=False):
    6057    r"""
    6158    List of all primes between start and stop-1, inclusive.  If the
  • sage/rings/number_field/number_field_ideal.py

    diff --git a/sage/rings/number_field/number_field_ideal.py b/sage/rings/number_field/number_field_ideal.py
    a b  
    201201        EXAMPLES::
    202202
    203203            sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__()
    204             -288230376151711715                 # 64-bit
    205             -67108835                           # 32-bit
     204            -9223372036854775779                # 64-bit
     205            -2147483619                         # 32-bit
    206206        """
    207         try: return self._hash
    208         # At some point in the future (e.g., for relative extensions), we'll likely
    209         # have to consider other hashes, like the following.
    210         #except AttributeError: self._hash = hash(self.gens())
    211         except AttributeError: self._hash = self.pari_hnf().__hash__()
     207        try:
     208            return self._hash
     209        except AttributeError:
     210            # At some point in the future (e.g., for relative extensions),
     211            # we'll likely have to consider other hashes.
     212            self._hash = self.pari_hnf().__hash__()
    212213        return self._hash
    213214       
    214215    def _latex_(self):
  • sage/rings/rational.pyx

    diff --git a/sage/rings/rational.pyx b/sage/rings/rational.pyx
    a b  
    8585
    8686cdef extern from "convert.h":
    8787    ctypedef long* GEN   
    88     void QQ_to_t_FRAC (GEN *g, mpq_t value)
    8988    void t_FRAC_to_QQ ( mpq_t value, GEN g )
    9089    void t_INT_to_ZZ ( mpz_t value, GEN g )
    9190