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

Fix compilation and doctests with flintlib 3.2 #39413

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/libs/flint/flint.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ cdef extern from "flint_wrap.h":
void * flint_realloc(void * ptr, size_t size) noexcept
void * flint_calloc(size_t num, size_t size) noexcept
void flint_free(void * ptr) noexcept
flint_rand_s * flint_rand_alloc() noexcept
void flint_rand_free(flint_rand_s * state) noexcept
flint_rand_struct * flint_rand_alloc() noexcept
void flint_rand_free(flint_rand_struct * state) noexcept
void flint_randinit(flint_rand_t state) noexcept
void flint_randclear(flint_rand_t state) noexcept
void flint_set_num_threads(int num_threads) noexcept
Expand Down
4 changes: 4 additions & 0 deletions src/sage/libs/flint/flint_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#pragma push_macro("I")
#define I Iv

/* flint 3.2 will rename flint_rand_s to flint_rand_struct
* the following line can be removed when flint 3.1 is gone */
#define flint_rand_s flint_rand_struct

#include <flint/flint.h>

/* If flint was already previously included via another header (e.g.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/flint/types.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ cdef extern from "flint_wrap.h":


# flint/flint.h
ctypedef struct flint_rand_s:
ctypedef struct flint_rand_struct:
pass
ctypedef flint_rand_s flint_rand_t[1]
ctypedef flint_rand_struct flint_rand_t[1]

cdef long FLINT_BITS
cdef long FLINT_D_BITS
Expand Down
71 changes: 36 additions & 35 deletions src/sage/rings/complex_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -787,27 +787,28 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
...
ValueError: polynomial with interval coefficients, use multiplicities=False

sage: (x^4 - 1/3).roots(multiplicities=False) # indirect doctest
[[-0.759835685651593 +/- ...e-16] + [+/- ...e-16]*I,
[0.759835685651593 +/- ...e-16] + [+/- ...e-16]*I,
[+/- ...e-16] + [0.759835685651593 +/- ...e-16]*I,
[+/- ...e-16] + [-0.759835685651593 +/- ...e-16]*I]
sage: set((x^4 - 1/3).roots(multiplicities=False)) # indirect doctest
{[+/- 1.27e-16] + [-0.759835685651593 +/- 5.90e-16]*I,
[+/- 1.27e-16] + [0.759835685651593 +/- 5.90e-16]*I,
[-0.759835685651593 +/- 5.90e-16] + [+/- 1.27e-16]*I,
[0.759835685651593 +/- 5.90e-16] + [+/- 1.27e-16]*I}

sage: (x^4 - 1/3).roots(RBF, multiplicities=False)
[[-0.759835685651593 +/- ...e-16], [0.759835685651593 +/- ...e-16]]
sage: set((x^4 - 1/3).roots(RBF, multiplicities=False))
{[-0.759835685651593 +/- 5.90e-16], [0.759835685651593 +/- 5.90e-16]}

sage: (x^4 - 3).roots(RealBallField(100), multiplicities=False)
[[-1.316074012952492460819218901797 +/- ...e-34],
[1.316074012952492460819218901797 +/- ...e-34]]
sage: set((x^4 - 3).roots(RealBallField(100), multiplicities=False))
{[-1.316074012952492460819218901797 +/- 9.7e-34],
[1.316074012952492460819218901797 +/- 9.7e-34]}

sage: (x^4 - 3).roots(ComplexIntervalField(100), multiplicities=False)
sage: sorted((x^4 - 3).roots(ComplexIntervalField(100),
....: multiplicities=False), key=repr)
[-1.31607401295249246081921890180? + 0.?e-37*I,
1.31607401295249246081921890180? + 0.?e-37*I,
0.?e-37 + 1.31607401295249246081921890180?*I,
0.?e-37 - 1.31607401295249246081921890180?*I]
0.?e-37 - 1.31607401295249246081921890180?*I,
1.31607401295249246081921890180? + 0.?e-37*I]

sage: (x^2 - i/3).roots(ComplexBallField(2), multiplicities=False)
[[+/- 0.409] + [+/- 0.409]*I, [+/- 0.409] + [+/- 0.409]*I]
sage: set((x^2 - i/3).roots(ComplexBallField(2), multiplicities=False))
{[+/- 0.409] + [+/- 0.409]*I, [+/- 0.409] + [+/- 0.409]*I}

sage: ((x - 1)^2).roots(multiplicities=False)
Traceback (most recent call last):
Expand All @@ -817,8 +818,8 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
sage: ((x - 1)^2).roots(multiplicities=False, proof=False)
doctest:...
UserWarning: roots may have been lost...
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
[[1.000000000... +/- ...] + [+/- ...]*I,
[1.000000000... +/- ...] + [+/- ...]*I]

sage: pol = x^7 - 2*(1000*x - 1)^2 # Mignotte polynomial
sage: pol.roots(multiplicities=False)
Expand All @@ -843,7 +844,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField):
sage: ((x - 1)^2 + 2^(-70)*i/3).roots(RBF, multiplicities=False)
Traceback (most recent call last):
...
ValueError: unable to determine which roots are real
ValueError: ...

TESTS::

Expand Down Expand Up @@ -4199,14 +4200,14 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).Ei()
[1.76462598556385 +/- ...e-15] + [2.38776985151052 +/- ...e-15]*I
sage: CBF(1, 1).Ei() # abs tol 6e-15
[1.76462598556385 +/- 6.03e-15] + [2.38776985151052 +/- 4.23e-15]*I
sage: CBF(0).Ei()
nan
nan...

TESTS:

sage: CBF(Ei(I)) # abs tol 1e-16 # needs sage.symbolic
sage: CBF(Ei(I)) # abs tol 2e-15 # needs sage.symbolic
[0.337403922900968 +/- 3.76e-16] + [2.51687939716208 +/- 2.01e-15]*I
"""
cdef ComplexBall result = self._new()
Expand All @@ -4221,14 +4222,14 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).Si()
[1.10422265823558 +/- ...e-15] + [0.88245380500792 +/- ...e-15]*I
sage: CBF(1, 1).Si() # abs tol 3e-15
[1.10422265823558 +/- 2.48e-15] + [0.88245380500792 +/- 3.36e-15]*I
sage: CBF(0).Si()
0

TESTS:

sage: CBF(Si(I)) # needs sage.symbolic
sage: CBF(Si(I)) # abs tol 3e-15 # needs sage.symbolic
[1.05725087537573 +/- 2.77e-15]*I
"""
cdef ComplexBall result = self._new()
Expand All @@ -4245,14 +4246,14 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).Ci()
[0.882172180555936 +/- ...e-16] + [0.287249133519956 +/- ...e-16]*I
sage: CBF(1, 1).Ci() # abs tol 5e-16
[0.882172180555936 +/- 5.89e-16] + [0.287249133519956 +/- 3.37e-16]*I
sage: CBF(0).Ci()
nan + nan*I

TESTS:

sage: CBF(Ci(I)) # abs tol 1e-17 # needs sage.symbolic
sage: CBF(Ci(I)) # abs tol 5e-16 # needs sage.symbolic
[0.837866940980208 +/- 4.72e-16] + [1.570796326794897 +/- 5.54e-16]*I
"""
cdef ComplexBall result = self._new()
Expand All @@ -4269,8 +4270,8 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).Shi()
[0.88245380500792 +/- ...e-15] + [1.10422265823558 +/- ...e-15]*I
sage: CBF(1, 1).Shi() # abs tol 3e-15
[0.88245380500792 +/- 3.36e-15] + [1.10422265823558 +/- 2.48e-15]*I
sage: CBF(0).Shi()
0

Expand All @@ -4293,14 +4294,14 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).Chi()
[0.882172180555936 +/- ...e-16] + [1.28354719327494 +/- ...e-15]*I
sage: CBF(1, 1).Chi() # abs tol 1e-15
[0.882172180555936 +/- 5.89e-16] + [1.28354719327494 +/- 1.01e-15]*I
sage: CBF(0).Chi()
nan + nan*I

TESTS:

sage: CBF(Chi(I)) # abs tol 1e-16 # needs sage.symbolic
sage: CBF(Chi(I)) # abs tol 5e-16 # needs sage.symbolic
[0.337403922900968 +/- 3.25e-16] + [1.570796326794897 +/- 5.54e-16]*I
"""
cdef ComplexBall result = self._new()
Expand All @@ -4319,8 +4320,8 @@ cdef class ComplexBall(RingElement):

EXAMPLES::

sage: CBF(1, 1).li()
[0.61391166922120 +/- ...e-15] + [2.05958421419258 +/- ...e-15]*I
sage: CBF(1, 1).li() # abs tol 6e-15
[0.61391166922120 +/- 6.23e-15] + [2.05958421419258 +/- 5.59e-15]*I
sage: CBF(0).li()
0
sage: CBF(0).li(offset=True)
Expand Down
14 changes: 7 additions & 7 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8398,19 +8398,19 @@ cdef class Polynomial(CommutativePolynomial):

sage: # needs sage.libs.flint
sage: Pol.<x> = CBF[]
sage: (x^2 + 2).roots(multiplicities=False)
[[+/- ...e-19] + [-1.414213562373095 +/- ...e-17]*I,
[+/- ...e-19] + [1.414213562373095 +/- ...e-17]*I]
sage: set((x^2 + 2).roots(multiplicities=False))
{[+/- ...e-19] + [-1.414213562373095 +/- ...e-17]*I,
[+/- ...e-19] + [1.414213562373095 +/- ...e-17]*I}
sage: (x^3 - 1/2).roots(RBF, multiplicities=False)
[[0.7937005259840997 +/- ...e-17]]
sage: ((x - 1)^2).roots(multiplicities=False, proof=False)
doctest:...
UserWarning: roots may have been lost...
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
[[1.000000000... +/- ...] + [+/- ...]*I,
[1.000000000... +/- ...] + [+/- ...]*I]
sage: ((x - 1)^2).roots(multiplicities=False, proof=False, warn=False)
[[1.00000000000 +/- ...e-12] + [+/- ...e-11]*I,
[1.0000000000 +/- ...e-12] + [+/- ...e-12]*I]
[[1.000000000... +/- ...] + [+/- ...]*I,
[1.000000000... +/- ...] + [+/- ...]*I]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using abs tol like what you used above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but it refuses to work because of the doctest:... above.


Note that coefficients in a number field with defining polynomial
`x^2 + 1` are considered to be Gaussian rationals (with the
Expand Down
18 changes: 9 additions & 9 deletions src/sage/rings/real_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3531,12 +3531,12 @@ cdef class RealBall(RingElement):

EXAMPLES::

sage: RBF(1).Ei() # abs tol 5e-16
sage: RBF(1).Ei() # abs tol 5e-15
[1.89511781635594 +/- 4.94e-15]

TESTS::

sage: RBF(Ei(1)) # abs tol 5e-16 # needs sage.symbolic
sage: RBF(Ei(1)) # abs tol 5e-15 # needs sage.symbolic
[1.89511781635594 +/- 4.94e-15]
"""
cdef RealBall res = self._new()
Expand Down Expand Up @@ -3595,12 +3595,12 @@ cdef class RealBall(RingElement):

EXAMPLES::

sage: RBF(1).Shi()
sage: RBF(1).Shi() # abs tol 5e-15
[1.05725087537573 +/- 2.77e-15]

TESTS::

sage: RBF(Shi(1)) # needs sage.symbolic
sage: RBF(Shi(1)) # abs tol 5e-15 # needs sage.symbolic
[1.05725087537573 +/- 2.77e-15]
"""
cdef RealBall res = self._new()
Expand All @@ -3617,12 +3617,12 @@ cdef class RealBall(RingElement):

EXAMPLES::

sage: RBF(1).Chi() # abs tol 1e-17
sage: RBF(1).Chi() # abs tol 5e-16
[0.837866940980208 +/- 4.72e-16]

TESTS::

sage: RBF(Chi(1)) # abs tol 1e-17 # needs sage.symbolic
sage: RBF(Chi(1)) # abs tol 5e-16 # needs sage.symbolic
[0.837866940980208 +/- 4.72e-16]
"""
cdef RealBall res = self._new()
Expand All @@ -3639,14 +3639,14 @@ cdef class RealBall(RingElement):

EXAMPLES::

sage: RBF(3).li() # abs tol 1e-15
sage: RBF(3).li() # abs tol 5e-15
[2.16358859466719 +/- 4.72e-15]

TESTS::

sage: RBF(li(0)) # needs sage.symbolic
0
sage: RBF(Li(0)) # needs sage.symbolic
sage: RBF(Li(0)) # abs tol 5e-15 # needs sage.symbolic
[-1.04516378011749 +/- 4.23e-15]
"""
cdef RealBall res = self._new()
Expand All @@ -3663,7 +3663,7 @@ cdef class RealBall(RingElement):

EXAMPLES::

sage: RBF(3).Li() # abs tol 1e-15
sage: RBF(3).Li() # abs tol 5e-15
[1.11842481454970 +/- 7.61e-15]
"""
cdef RealBall res = self._new()
Expand Down
1 change: 1 addition & 0 deletions src/sage/symbolic/ginac/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "gmp.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like flint bug to me? Surely the header should be usable standalone?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's by design: With
flintlib/flint@3604bb2 one needs to include the gmp header before using fmpz_get_mpz.

#include "flint/fmpz.h"
#include "flint/fmpz_factor.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Import this module::

sage: import sage.libs.flint.flint_sage

We verify that :trac:`6919` is correctly fixed::
We verify that :issue:`6919` is correctly fixed::

sage: R.<x> = PolynomialRing(ZZ)
sage: A = 2^(2^17+2^15)
Expand Down
4 changes: 4 additions & 0 deletions src/sage_setup/autogen/flint/templates/flint_wrap.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#pragma push_macro("I")
#define I Iv

/* flint 3.2 will rename flint_rand_s to flint_rand_struct
* the following line can be removed when flint 3.1 is gone */
#define flint_rand_s flint_rand_struct

#include <flint/flint.h>

/* If flint was already previously included via another header (e.g.
Expand Down
4 changes: 2 additions & 2 deletions src/sage_setup/autogen/flint/templates/types.pxd.template
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ cdef extern from "flint_wrap.h":


# flint/flint.h
ctypedef struct flint_rand_s:
ctypedef struct flint_rand_struct:
pass
ctypedef flint_rand_s flint_rand_t[1]
ctypedef flint_rand_struct flint_rand_t[1]

cdef long FLINT_BITS
cdef long FLINT_D_BITS
Expand Down
Loading