Re: should the new coercion model treat this sort of thing?

4 views
Skip to first unread message

William Stein

unread,
Nov 6, 2007, 5:22:41 PM11/6/07
to Robert Bradshaw, sage-...@googlegroups.com
On 11/6/07, Robert Bradshaw <robe...@math.washington.edu> wrote:
> On Nov 6, 2007, at 1:59 PM, William Stein wrote:
>
> > Hi Robert (cc: sage-devel),
> >
> > Should the new coercion model address this sort of thing?
>
> Yes, it doesn't yet though, but shouldn't be too hard to add--the
> construction method of ComplexField needs to be implemented.

Please explain how to do this. This will help other people start
filling in the coercion implementations all over in Sage.

>
> > sage: ComplexField(200)(1) + RealField(53)(1)
> > Traceback (most recent call last):
> > ...
> > TypeError: unsupported operand parent(s) for '+': 'Complex Field with
> > 200 bits of precision' and 'Real Field with 53 bits of precision'
> >
> >
> > It would make sense for the answer to be an element of RealField(53)
>
> Shouldn't be in ComplexField(53)?

Yes, I definitely meant ComplexField(53). I just mistyped RealField
for some reason.

William

Robert Bradshaw

unread,
Nov 6, 2007, 6:19:38 PM11/6/07
to sage-...@googlegroups.com
On Nov 6, 2007, at 2:22 PM, William Stein wrote:

> On 11/6/07, Robert Bradshaw <robe...@math.washington.edu> wrote:
>> On Nov 6, 2007, at 1:59 PM, William Stein wrote:
>>
>>> Hi Robert (cc: sage-devel),
>>>
>>> Should the new coercion model address this sort of thing?
>>
>> Yes, it doesn't yet though, but shouldn't be too hard to add--the
>> construction method of ComplexField needs to be implemented.
>
> Please explain how to do this. This will help other people start
> filling in the coercion implementations all over in Sage.

The construction method of a parent tells one how to "construct" the
object out of more basic types. For example.

sage: RR.construction()
(CompletionFunctor, Rational Field)
sage: QQ.construction()
(FractionField, Integer Ring)
sage: Qp(7).construction()
(CompletionFunctor, Rational Field)
sage: QQ['x'].construction()
(PolynomialFunctor, Rational Field)

A.construction() returns a tuple F, B such that F(B) == A. Here F is
an instance of sage.categories.pushout.ConstructionFunctor and B is
another parent. F often caries other information with it (the __str__
method could be made much more explicit for printing).

sage: F, B = RR.construction()
sage: F.prec
53
sage: F.p
+Infinity
sage: F.extras
{'rnd': 'RNDN', 'sci_not': False}

One can get a feel for this by playing with

sage: from sage.categories.pushout import construction_tower
sage: construction_tower(Qp(7)['x'][['y']])

[(None,
Power Series Ring in y over Univariate Polynomial Ring in x over 7-
adic Field with capped relative precision 20),
(CompletionFunctor,
Univariate Polynomial Ring in y over Univariate Polynomial Ring in
x over 7-adic Field with capped relative precision 20),
(PolynomialFunctor,
Univariate Polynomial Ring in x over 7-adic Field with capped
relative precision 20),
(PolynomialFunctor, 7-adic Field with capped relative precision 20),
(CompletionFunctor, Rational Field),
(FractionField, Integer Ring)]

The idea is that in computing a+b, the construction tower for parent
(a) and parent(b) will be merged. The problem is that ComplexField
(or CDF) does not have a construction.

sage: print CC.construction()
None

I suppose there should be an AlgebraicClosureFunctor that calls
algebraic_closure() with no arguments (which, for the moment, would
only be implemented for RR, RDF, RQDF). Then one would have

sage: print CC.construction()
AlgebraicClosureFunctor, Real Field with 53 bits of precision
sage: print CDF.construction()
AlgebraicClosureFunctor, Real Double Field
sage: print ComplexField(500).construction()
AlgebraicClosureFunctor, Real Field with 500 bits of precision

and stuff like RealField(100)(1) + ComplexField(200)(5) should work
fine.

Well, that took longer to write up than implement, but this is the
start of some documentation on the process, which needs to get done.

- Robert

Reply all
Reply to author
Forward
0 new messages