Ask Your Question

convert expression to QuadraticField

asked 2013-05-16 11:52:39 +0100

updated 2013-05-16 11:55:39 +0100

I tried (in the Sage shell)

K = QuadraticField(-3)
a = K(sqrt(-3))

But that fails with a TypeError exception. What is the problem?

I know that I can get the generator by K.gen() but I want to be able to convert expressions to K.

edit retag flag offensive close merge delete


I don't know that it will be so easy to coerce from the symbolic ring to here in general, but more power to you if someone can... I do find the following behavior a little disturbing - try `sage: K.gen()`, which yields `a`, which no one ever asked for... this *is* documented in `QuadraticField?` but only as the default variable name, which of course isn't injected into the global namespace.

kcrisman gravatar imagekcrisman ( 2013-05-16 15:42:06 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-05-17 05:48:47 +0100

vdelecroix gravatar image


You should avoid usage of the symbolic ring as much as possible. It is useful to deal with functions, derivations and such but not to deal with arithmetic questions.

There is a class called AlgebraicConverter in sage.symbolic.expression_conversions which is implemented and called in such case. It works well for the field of algebraic numbers QQbar::

sage: QQbar(sqrt(-3))
sage: QQbar(sin(pi/4))

But not for other number fields. Nevertheless it is possible to do

sage: K = QuadraticField(-3)
sage: K(3).sqrt()

The method sqrt above actually uses Pari in the background: if your number field contains such a root it returns it, otherwise the answer will be an element of the symbolic ring.

sage: K(3).sqrt().sqrt()
edit flag offensive delete link more


vdelecroix gravatar imagevdelecroix ( 2013-05-17 05:51:46 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-16 11:52:39 +0100

Seen: 193 times

Last updated: May 17 '13