Opened 3 years ago

# Conversion error in Real Ball Fields

Reported by: Owned by: vklein major sage-8.3 basic arithmetic thursdaysbdx slabbe, vdelecroix, mmezzarobba Vincent Delecroix N/A u/vdelecroix/25456 2d4ff247c437fc4d04599357e609b9d47135624c

### Description

Calling RBF with two parameters and using a sage Integer as radius provoke a TypeError?.

sage: RBF(0,5.)
[+/- 5.01]
sage: RBF(0.,5.)
[+/- 5.01]
sage: RBF(0.,5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-d3ae2a7cd5cc> in <module>()
----> 1 RBF(RealNumber('0.'),Integer(5))

/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9761)()
920                 return mor._call_(x)
921             else:
--> 922                 return mor._call_with_args(x, args, kwds)
923
924         raise TypeError("No conversion defined from %s to %s"%(R, self))

/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (build/cythonized/sage/structure/coerce_maps.c:5093)()
162                 print(type(C), C)
163                 print(type(C._element_constructor), C._element_constructor)
--> 164             raise
165
166

/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (build/cythonized/sage/structure/coerce_maps.c:4933)()
155             else:
156                 if len(kwds) == 0:
--> 157                     return C._element_constructor(x, *args)
158                 else:
159                     return C._element_constructor(x, *args, **kwds)

/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/rings/real_arb.pyx in sage.rings.real_arb.RealBallField._element_constructor_ (build/cythonized/sage/rings/real_arb.c:6522)()
523         except TypeError:
524             pass
--> 525         raise TypeError("unable to convert {!r} to a RealBall".format(mid))
526
527     def _repr_option(self, key):

TypeError: unable to convert 0 to a RealBall

Same error with RBF(0,5).

### comment:1 Changed 3 years ago by vklein

• Status changed from new to needs_info

In the current RBF implementation rejecting Integers types as rad parameter seems intentional.

"""
Initialize the :class:`RealBall`.

INPUT:

- ``parent`` -- a :class:`RealBallField`.

- ``mid`` (optional) --  ball midpoint, see examples below. If omitted,
initialize the ball to zero, ignoring the ``rad`` argument.

- ``rad`` (optional) -- a :class:`RealNumber` or a Python float, ball
radius. If the midpoint is not exactly representable in
error.

Is there a good reason to keep it that way ? Any advices are welcome.

Last edited 3 years ago by vklein (previous) (diff)

### comment:3 Changed 3 years ago by vdelecroix

• Authors set to Vincent Delecroix
• Branch set to u/vdelecroix/25456
• Commit set to 2d4ff247c437fc4d04599357e609b9d47135624c
• Status changed from needs_info to needs_review

New commits:

 ​2d4ff24 25456: more generic real ball initialization

### comment:4 Changed 3 years ago by mmezzarobba

It would be nice to support more general radii, but:

• There is no guarantee that converting to RealField(RNDA) really will compute an upper-approximation (think of nontrivial symbolic expressions). I guess coercing should, but I'm not even sure.
• It would be more consistent with the current code to put the branch that goes though a (sage-level) conversion in _element_constructor_(), and reserve __init__() for initialization of the arb object.

### comment:5 Changed 3 years ago by mmezzarobba

• Status changed from needs_review to needs_work
Note: See TracTickets for help on using tickets.