Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

padic QpLC.random_element is broken #32126

Open
mwageringel opened this issue Jul 4, 2021 · 2 comments
Open

padic QpLC.random_element is broken #32126

mwageringel opened this issue Jul 4, 2021 · 2 comments

Comments

@mwageringel
Copy link

sage -t --long --random-seed=3113 src/sage/rings/padics/padic_base_leaves.py
**********************************************************************
File "src/sage/rings/padics/padic_base_leaves.py", line 1071, in sage.rings.padics.padic_base_leaves.pAdicFieldLattice.random_element
Failed example:
    K.random_element()   # random
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.padics.padic_base_leaves.pAdicFieldLattice.random_element[1]>", line 1, in <module>
        K.random_element()   # random
      File "/usr/lib/python3.9/site-packages/sage/rings/padics/padic_base_leaves.py", line 1093, in random_element
        x = ZZ.random_element(p**prec)
      File "sage/rings/integer_ring.pyx", line 718, in sage.rings.integer_ring.IntegerRing_class.random_element (build/cythonized/sage/rings/integer_ring.c:6533)
        self._randomize_mpz(z.value, x, y, distribution)
      File "sage/rings/integer_ring.pyx", line 749, in sage.rings.integer_ring.IntegerRing_class._randomize_mpz (build/cythonized/sage/rings/integer_ring.c:6764)
        n_max = x if isinstance(x, integer.Integer) else self(x)
      File "sage/structure/parent.pyx", line 898, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9341)
        return mor._call_(x)
      File "sage/rings/rational.pyx", line 4164, in sage.rings.rational.Q_to_Z._call_ (build/cythonized/sage/rings/rational.cpp:32503)
        raise TypeError("no conversion of this rational to integer")
    TypeError: no conversion of this rational to integer

where K = QpLC(2). Other possible seeds:

sage -t --long --random-seed=3098 src/sage/rings/padics/padic_base_leaves.py  # 1 doctest failed
sage -t --long --random-seed=3083 src/sage/rings/padics/padic_base_leaves.py  # 1 doctest failed

In #29979, a doctest was marked not tested because of this.

CC: @kliem @roed314

Component: padics

Issue created by migration from https://trac.sagemath.org/ticket/32126

@mwageringel mwageringel added this to the sage-9.4 milestone Jul 4, 2021
@mwageringel
Copy link
Author

comment:1

The offending code is

        if integral:
            val = 0
        else:
            val = ZZ.random_element()
        if prec is None:
            prec = self._prec_cap_absolute - val
        p = self.prime()
        x = ZZ.random_element(p**prec)

which is problematic as prec can be negative, so that ZZ.random_element gets called with a non-integral value. I am not sure what the intention is.

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mwageringel

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants