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

random doctest error in QuaternionFractionalIdeal_rational.is_principal #38947

Closed
2 tasks done
dcoudert opened this issue Nov 9, 2024 · 3 comments · Fixed by #38963
Closed
2 tasks done

random doctest error in QuaternionFractionalIdeal_rational.is_principal #38947

dcoudert opened this issue Nov 9, 2024 · 3 comments · Fixed by #38963
Labels

Comments

@dcoudert
Copy link
Contributor

dcoudert commented Nov 9, 2024

Steps To Reproduce

sage -t --warn-long 5.0 --random-seed=64954994004742655361672586966720031388 src/sage/algebras/quatalg/quaternion_algebra.py

Expected Behavior

All tests passed!

Actual Behavior

sage -t --warn-long 5.0 --random-seed=64954994004742655361672586966720031388 src/sage/algebras/quatalg/quaternion_algebra.py
**********************************************************************
File "src/sage/algebras/quatalg/quaternion_algebra.py", line 3716, in sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal
Failed example:
    bool, alpha = I.is_principal(True)
Exception raised:
    Traceback (most recent call last):
      File "sage/misc/misc_c.pyx", line 726, in sage.misc.misc_c.sized_iter.__next__
        x = next(self.iterator)
    StopIteration

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Users/dcoudert/sage/src/sage/doctest/forker.py", line 715, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage/src/sage/doctest/forker.py", line 1136, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal[4]>", line 1, in <module>
        bool, alpha = I.is_principal(True)
      File "/Users/dcoudert/sage/src/sage/algebras/quatalg/quaternion_algebra.py", line 3726, in is_principal
        c = self.theta_series_vector(2)[1]
      File "/Users/dcoudert/sage/src/sage/algebras/quatalg/quaternion_algebra.py", line 3010, in theta_series_vector
        Q = self.quadratic_form()
      File "sage/misc/cachefunc.pyx", line 2316, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__
        self.cache = f(self._instance)
      File "/Users/dcoudert/sage/src/sage/algebras/quatalg/quaternion_algebra.py", line 3037, in quadratic_form
        gram_matrix = self.gram_matrix()
      File "sage/misc/cachefunc.pyx", line 2316, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__
        self.cache = f(self._instance)
      File "/Users/dcoudert/sage/src/sage/algebras/quatalg/quaternion_algebra.py", line 3142, in gram_matrix
        return M44(m, coerce=False)
      File "sage/structure/parent.pyx", line 903, in sage.structure.parent.Parent.__call__
        return mor._call_with_args(x, args, kwds)
      File "sage/structure/coerce_maps.pyx", line 183, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args
        raise
      File "sage/structure/coerce_maps.pyx", line 173, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args
        return C._element_constructor(x, **kwds)
      File "/Users/dcoudert/sage/src/sage/matrix/matrix_space.py", line 1154, in _element_constructor_
        return self.element_class(self, entries, **kwds)
      File "sage/matrix/matrix_rational_dense.pyx", line 189, in sage.matrix.matrix_rational_dense.Matrix_rational_dense.__init__
        for t in ma.iter(coerce, True):
      File "sage/matrix/args.pyx", line 606, in iter
        x = next(it)
      File "sage/misc/misc_c.pyx", line 728, in sage.misc.misc_c.sized_iter.__next__
        raise ValueError(f"sequence too short (expected length {self.size}, got {self.index})")
    ValueError: sequence too short (expected length 16, got 1)
**********************************************************************
File "src/sage/algebras/quatalg/quaternion_algebra.py", line 3717, in sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal
Failed example:
    bool
Expected:
    True
Got:
    <class 'bool'>
**********************************************************************
File "src/sage/algebras/quatalg/quaternion_algebra.py", line 3719, in sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal
Failed example:
    I == O*alpha
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage/src/sage/doctest/forker.py", line 715, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage/src/sage/doctest/forker.py", line 1136, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal[6]>", line 1, in <module>
        I == O*alpha
    NameError: name 'alpha' is not defined
**********************************************************************
File "src/sage/algebras/quatalg/quaternion_algebra.py", line 3954, in sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.primitive_decomposition
Warning: slow doctest:
    for d in ( m for m in range(400, 750) if is_squarefree(m) ):
        A = QuaternionAlgebra(d)
        O = A.maximal_order()
        for _ in range(10):
            a = O.random_element()
            if not a.is_constant(): # avoids a = 0
                I = a*O + a.reduced_norm()*O
                if I.is_integral():
                    J,g = I.primitive_decomposition()
                    assert J*g == I
                    assert J.is_primitive()
Test ran for 5.55s cpu, 5.57s wall
Check ran for 0.00s cpu, 0.00s wall
**********************************************************************
1 item had failures:
   3 of   8 in sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational.is_principal
    [686 tests, 3 failures, 10.63s wall]
----------------------------------------------------------------------
sage -t --warn-long 5.0 --random-seed=64954994004742655361672586966720031388 src/sage/algebras/quatalg/quaternion_algebra.py  # 3 doctests failed
----------------------------------------------------------------------

Additional Information

observed in https://github.com/sagemath/sage/actions/runs/11755696820/job/32751042118?pr=38941

Environment

  • OS: macOS 14.7.1
  • Sage Version: 10.5.beta9

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@dcoudert dcoudert added the t: bug label Nov 9, 2024
@dcoudert dcoudert mentioned this issue Nov 9, 2024
5 tasks
@dcoudert
Copy link
Contributor Author

dcoudert commented Nov 9, 2024

use this method to identify the failing case:

def foo():
    B.<i,j,k> = QuaternionAlgebra(419)
    O = B.quaternion_order([1/2 + 3/2*j, 1/6*i + 2/3*j + 1/2*k, 3*j, k])
    while True:
        beta = O.random_element()
        I = O*beta
        try:
            bool, alpha = I.is_principal(True)
        except:
            return beta

then

sage: beta = foo()
sage: type(beta)
<class 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_rational_field'>
sage: beta
0

@yyyyx4
Copy link
Member

yyyyx4 commented Nov 10, 2024

@S17A05, this may be of interest to you?

@S17A05
Copy link
Member

S17A05 commented Nov 13, 2024

At first glance it seems that one just needs to exclude the zero ideal here - I'll take a closer look at it.

vbraun pushed a commit to vbraun/sage that referenced this issue Nov 14, 2024
… zero

    
This PR disallows the scaling of quaternion fractional ideals by the
zero element of the surrounding quaternion algebra (throwing a
`ValueError` in the process), as the result will by definition not be a
fractional ideal. It also adds additional checks to avoid scaling by
zero in other tests, which came up in the issue mentioned below, and it
adds a missing warning for a long doctest.

Fixes sagemath#38947.
    
URL: sagemath#38963
Reported by: Sebastian A. Spindler
Reviewer(s): Giacomo Pope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants