Skip to content

Make parent(a)(a.mid(), a.rad()) the same as a for RBF elements #40376

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
43 changes: 35 additions & 8 deletions src/sage/rings/real_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,26 @@
Traceback (most recent call last):
...
TypeError: no canonical coercion...

Check that if ``a`` is a ball then ``parent(a)(a.mid(), a.rad())`` is exactly ``a``
(this behavior is not guaranteed by flint, but it is useful for us).
Also check the same when ``rad`` is an integer no more than ``2^29``::

sage: for prec1 in (5, 30, 53):
....: RB = RealBallField(prec1)
....: for prec2 in (5, 29, 30, 53):
....: R = RealField(prec2)
....: for i in range(100):
....: mid = R.random_element()
....: for rad in (R.random_element(), R(ZZ.random_element(0, 2**prec2-1))):
....: a = RB(mid, rad)
....: if prec2 <= 30: assert a.rad() == abs(rad)
....: assert RB(a.mid(), a.rad()).rad() == a.rad(), (a.mid().str(), a.rad().str())
....: for rad in (ZZ.random_element(0, 2**prec2-1),):
....: assert ZZ(R(rad)) == rad
....: a = RB(mid, rad)
....: if prec2 <= 29: assert ZZ(a.rad()) == abs(rad) # strangely enough this doesn't work with 30
....: assert RB(a.mid(), a.rad()).rad() == a.rad(), (a.mid().str(), a.rad().str())
"""
cdef fmpz_t tmpz
cdef fmpq_t tmpq
Expand Down Expand Up @@ -1464,15 +1484,22 @@
if rad is not None:
mag_init(tmpm)
if isinstance(rad, RealNumber):
arf_init(tmpr)
arf_set_mpfr(tmpr, (<RealNumber> rad).value)
arf_get_mag(tmpm, tmpr)
arf_clear(tmpr)
if rad.parent().prec() <= 62:
sign, mantissa, exponent = rad.sign_mantissa_exponent()
t = mantissa.trailing_zero_bits()
mantissa >>= t
exponent += t
mag_set_ui_2exp_si(tmpm, <Integer> mantissa, <Integer> exponent)
else:
arf_init(tmpr)
arf_set_mpfr(tmpr, (<RealNumber> rad).value)
arf_get_mag(tmpm, tmpr)
arf_clear(tmpr)
elif isinstance(rad, Integer):
arf_init(tmpr)
arf_set_mpz(tmpr, (<Integer> rad).value)
arf_get_mag(tmpm, tmpr)
arf_clear(tmpr)
fmpz_init(tmpz)
fmpz_set_mpz(tmpz, (<Integer> rad).value)
mag_set_fmpz(tmpm, tmpz)
fmpz_clear(tmpz)
elif isinstance(rad, Rational):
arf_init(tmpr)
arf_set_mpz(tmpr, (<Integer> rad.numerator()).value)
Expand Down Expand Up @@ -2148,7 +2175,7 @@

sage: RBF(1).add_error(-1)
1.000000000000000
sage: RBF(0).add_error(RBF(1, rad=2.)).endpoints()

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)

Check failure on line 2178 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: (-3.00000000372530, 3.00000000372530)
(-3.00000000745059, 3.00000000745059)
"""
cdef RealBall res = self._new()
Expand Down Expand Up @@ -2444,7 +2471,7 @@
sage: RBF(1, rad=.5).min(0)
0

sage: RBF(0, rad=2.).min(RBF(0, rad=1.)).endpoints()

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)

Check failure on line 2474 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: (-2.00000000186265, 1.00000000186265)
(-2.00000000651926, 1.00000000465662)

sage: RBF(infinity).min(3, 1/3)
Expand Down Expand Up @@ -2481,7 +2508,7 @@
sage: RBF(-1, rad=.5).max(0)
0

sage: RBF(0, rad=2.).max(RBF(0, rad=1.)).endpoints()

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)

Check failure on line 2511 in src/sage/rings/real_arb.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: (-1.00000000186265, 2.00000000186265)
(-1.00000000465662, 2.00000000651926)

sage: RBF(-infinity).max(-3, 1/3)
Expand Down
Loading