edgarcosta / amortizedHGM

GNU General Public License v3.0
1 stars 1 forks source link

int too big to convert (this is perhaps a bug in sage) #8

Open edgarcosta opened 6 months ago

edgarcosta commented 6 months ago

this should trigger it (after about 4h):

HJV = LAmortizingHypergeometricData(alpha_beta=[[1/2,1/3,2/3,1/6,5/6],
    [0,0,0,0,0]]);
foo = HJV.amortized_padic_H_values(-80^3, 2^26)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1934, in sage.misc.cachefunc.CachedMethodCaller.__call__()
   1933 try:
-> 1934     return cache[k]
   1935 except TypeError:  # k is not hashable
KeyError: ((-512000, 67108864, None, False), ())

During handling of the above exception, another exception occurred:
KeyError                                  Traceback (most recent call last)
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1934, in sage.misc.cachefunc.CachedMethodCaller.__call__()
   1933 try:
-> 1934     return cache[k]
   1935 except TypeError:  # k is not hashable
KeyError: ((6211, 2, -512000, None, False), ())

During handling of the above exception, another exception occurred:
TypeError                                 Traceback (most recent call last)
File /usr/local/sage/src/sage/modular/hypergeometric_misc.pyx:70, in sage.modular.hypergeometric_misc.hgm_coeffs()
     69     for r in range(q1):
---> 70         gtab2[r] = gtable[r]
     71 except TypeError:
TypeError: 'sage.rings.padics.padic_fixed_mod_element.pAdicFixedModElement' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:
OverflowError                             Traceback (most recent call last)
Cell In [7], line 7
      5 N = Integer(2)**e
      6 s = time()
----> 7 euler_factors = HJV.euler_factors(-Integer(80)**Integer(3), N)
      8 w = time() -s
      9 print(f"{e} {w:.2f} s\n")
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1939, in sage.misc.cachefunc.CachedMethodCaller.__call__()
   1937         return cache[k]
   1938 except KeyError:
-> 1939     w = self._instance_call(*args, **kwds)
   1940     cache[k] = w
   1941     return w
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1815, in sage.misc.cachefunc.CachedMethodCaller._instance_call()
   1813         True
   1814     """
-> 1815     return self.f(self._instance, *args, **kwds)
   1816 
   1817 cdef fix_args_kwds(self, tuple args, dict kwds):
Cell In [3], line 293, in LAmortizingHypergeometricData.euler_factors(self, t, N, chained, verbose)
    290     if f > Integer(1) and f <= n and p not in wild_primes and m%p:
    291         tmp.append((q,p,f))
--> 293 prime_power_traces = {q: self.padic_H_value(p=p,f=f,t=t) for (q,p,f) in tmp}
    294 if verbose:
    295     print("Computed prime power Frobenius traces")
Cell In [3], line 293, in <dictcomp>(.0)
    290     if f > Integer(1) and f <= n and p not in wild_primes and m%p:
    291         tmp.append((q,p,f))
--> 293 prime_power_traces = {q: self.padic_H_value(p=p,f=f,t=t) for (q,p,f) in tmp}
    294 if verbose:
    295     print("Computed prime power Frobenius traces")
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1939, in sage.misc.cachefunc.CachedMethodCaller.__call__()
   1937         return cache[k]
   1938 except KeyError:
-> 1939     w = self._instance_call(*args, **kwds)
   1940     cache[k] = w
   1941     return w
File /usr/local/sage/src/sage/misc/cachefunc.pyx:1815, in sage.misc.cachefunc.CachedMethodCaller._instance_call()
   1813         True
   1814     """
-> 1815     return self.f(self._instance, *args, **kwds)
   1816 
   1817 cdef fix_args_kwds(self, tuple args, dict kwds):
File /usr/local/sage/src/sage/modular/hypergeometric_motive.py:1294, in HypergeometricData.padic_H_value(self, p, f, t, prec, cache_p)
   1292 else:
   1293     gtab = gauss_table(p, f, prec, use_longs)
-> 1294     trcoeffs = hgm_coeffs(p, f, prec, gamma, m, D, gtab, prec, use_longs)
   1295 sigma = trcoeffs[p-2]
   1296 p_ring = sigma.parent()
File /usr/local/sage/src/sage/modular/hypergeometric_misc.pyx:9, in sage.modular.hypergeometric_misc.hgm_coeffs()
      7 
      8 
----> 9 cpdef hgm_coeffs(long long p, int f, int prec, gamma, m, int D,
     10                  gtable, int gtable_prec, bint use_longs):
     11     r"""
File /usr/local/sage/src/sage/modular/hypergeometric_misc.pyx:73, in sage.modular.hypergeometric_misc.hgm_coeffs()
     71     except TypeError:
     72         for r in range(q1):
---> 73             gtab2[r] = gtable[r].lift()
     74 if f == 1:
     75     for r in range(q1):
OverflowError: int too big to convert
edgarcosta commented 6 months ago

The method amortized_padic_H_values didn't trigger it, so I am back at rerunning it with euler_factors

kedlaya commented 6 months ago

From the traceback it looks like this came up when dealing with higher prime powers.

There is supposed to be a cutoff that prevents the user from requesting the Frobenius trace at a prime power greater than 2**31. I wonder if this is somehow being missed.

kedlaya commented 6 months ago

OK, this triggers:

sage: from amortizedHGM import AmortizingHypergeometricData
sage: H = AmortizingHypergeometricData(alpha_beta=[[1/2,1/3,2/3,1/6,5/6], [0,0,0,0,0]])
sage: H.padic_H_value(6211, 2, -512000)

The issue is that the internal code is trying to store the trace in a long long but in this case the trace is bigger than 2**63. This will be a bit of a pain to fix, I'm afraid.

kedlaya commented 6 months ago

Actually maybe this won't be so bad. Shifting to https://github.com/sagemath/sage/issues/37910.