Skip to content

Strange slowdown on str() after handled FLINT exception #39224

@user202729

Description

@user202729
sage: R.<x> = Zmod(4)[]
sage: f = x^2 + 3 * x + 1
sage: g = x^2 + x + 1
sage: %time str(f)
CPU times: user 2.34 ms, sys: 0 ns, total: 2.34 ms
Wall time: 2.37 ms
'x^2 + 3*x + 1'
sage: f.gcd(g)
Flint exception (Impossible inverse):
    Cannot invert modulo 2*2
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File nmod_poly_linkage.pxi:599, in sage.rings.polynomial.polynomial_zmod_flint.celement_gcd()

RuntimeError: Aborted

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 f.gcd(g)

File element.pyx:4743, in sage.structure.element.coerce_binop.new_method()

File polynomial_template.pxi:390, in sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template.gcd()

File nmod_poly_linkage.pxi:605, in sage.rings.polynomial.polynomial_zmod_flint.celement_gcd()

RuntimeError: FLINT gcd calculation failed
sage: %time str(f)
CPU times: user 1.33 s, sys: 9.42 ms, total: 1.33 s
Wall time: 1.34 s
'x^2 + 3*x + 1'

Apparently it becomes fast again after accessing a nonexistent attribute

sage: %time f[0]
CPU times: user 304 ms, sys: 75 μs, total: 304 ms
Wall time: 305 ms
1
sage: %time f.xxx
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File <timed eval>:1

File element.pyx:495, in sage.structure.element.Element.__getattr__()

File element.pyx:508, in sage.structure.element.Element.getattr_from_category()

File getattr.pyx:363, in sage.cpython.getattr.getattr_from_other_class()

AttributeError: 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint' object has no at
tribute 'xxx'
sage: %time f[0]
CPU times: user 78.8 ms, sys: 0 ns, total: 78.8 ms
Wall time: 79.2 ms
1

Environment

  • OS: Linux
  • Sage Version: latest

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions