Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Question abour numerical coercions

I do not understand this :

sage: t,u=(1.4,0.7)
sage: z=complex(t,u)

This works :

sage: QQ(t)
7/5

But :

sage: AA(t)
---------------------------------------------------------------------------
TypeError
# Redacted...    
TypeError: Illegal initializer for algebraic number

Similarly :

sage: QQbar(t)
---------------------------------------------------------------------------
TypeError
## Redacted...
TypeError: Illegal initializer for algebraic number

However, this works :

sage: QQbar(QQ(t))
7/5

Similarly :

sage: QQbar(z)
---------------------------------------------------------------------------
TypeError
# Redacted...
TypeError: Illegal initializer for algebraic number

One has to do ! sage: QQbar(QQ(real_part(z))+IQQ(imag_part(z))) 7/10I + 7/5

The same happens when you try to use other numerical types (RDF, CDF, etc...)

There must be (good) reasons to have direct coercions from numerical real types to QQ but not to have a direct coercion from numerical complex types to algebraic types (AA and QQbar), but I do not know them.

Or does it happen to be an oversight ?

Question abour numerical coercions

I do not understand this :

sage: t,u=(1.4,0.7)
sage: z=complex(t,u)

This works :

sage: QQ(t)
7/5

But :

sage: AA(t)
---------------------------------------------------------------------------
TypeError
# Redacted...    
TypeError: Illegal initializer for algebraic number

Similarly :

sage: QQbar(t)
---------------------------------------------------------------------------
TypeError
## Redacted...
TypeError: Illegal initializer for algebraic number

However, this works :

sage: QQbar(QQ(t))
7/5

Similarly :

sage: QQbar(z)
---------------------------------------------------------------------------
TypeError
# Redacted...
TypeError: Illegal initializer for algebraic number

One has to do ! sage: QQbar(QQ(real_part(z))+IQQ(imag_part(z))) 7/10I :

sage: QQbar(QQ(real_part(z))+I*QQ(imag_part(z)))
7/10*I + 7/5

7/5

The same happens when you try to use other numerical types (RDF, CDF, etc...)

There must be (good) reasons to have direct coercions from numerical real types to QQ but not to have a direct coercion from numerical complex types to algebraic types (AA and QQbar), but I do not know them.

Or does it happen to be an oversight ?