Ask Your Question
1

Converting a symbolic expression to an element of a number field

asked 2016-10-19 05:35:58 +0100

rlg23 gravatar image

updated 2019-06-30 17:27:40 +0100

slelievre gravatar image

At some point in a calculation in the symbolic ring I end up with some numbers which are complex rationals of the form (a/b + I*(c/d). At this point I would like to no longer treat them as symbolic expressions and rather work with them in a more well behaved field. Since all of the computation I will be doing will keep things as complex rationals it seems like the number field QQ[I] is my best option.

My question is: How can I convert a symbolic expression like SR(2/3+4/5*I) to an element of QQ[I]. In general, there is no coercion from the symbolic ring to a number field, but in this special case there is a pretty clear map I would like to use.

Edit: I suppose since the map from the symbolic ring to the number field depends on an assumed embedding of the number field in the complex numbers, this might not be doable in any clean way. For now the following helper function works

def SRtoQQI(v, imGen):      # imGen = the immaginary unit in a ring QQ[I]
    rp = QQ(v.real_part())  # get real part of input
    ip = QQ(v.imag_part())  # get immaginary part of input
    return rp + ip*imGen    # combine parts to get output

I am still interested to know if there is a build in way, maybe making use of the embedding maps from QQ[I] to SR.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-10-19 16:22:35 +0100

slelievre gravatar image

One solution is to convert complex rationals to QQbar.

I hope QQbar is well-behaved enough for you needs.

This might not be as good as QQ[i], maybe you can then convert to QQ[i].

By the way, you didn't specify how you define QQ[I].

sage: version()
'SageMath version 7.3, Release Date: 2016-08-04'
sage: a = SR(2/3+4/5*I); a
4/5*I + 2/3
sage: aa = QQbar(a); aa
4/5*I + 2/3
sage: aa.minpoly()
x^2 - 4/3*x + 244/225
edit flag offensive delete link more

Comments

Samuel, I tried the same way, and I wonder whether the following behavior is a bug. What do you think:

sage: K = QQ[I]
sage: K
Number Field in I with defining polynomial x^2 + 1
sage: K(I)
Traceback (most recent call last):
...
TypeError: <type 'sage.symbolic.expression.Expression'>
sage: K(QQbar(I))
Traceback (most recent call last):
...
ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real
B r u n o gravatar imageB r u n o ( 2016-10-19 16:52:04 +0100 )edit

QQbar works okay for some basic calculations but when doing something like finding eigenvectors of matrices, sage seems to like to move to floating point numbers even when all entries are rational. In addition, the Groebner basis computations over QQbar fall back to toy Buchberger, which is very, very slow.

rlg23 gravatar imagerlg23 ( 2016-10-19 18:30:01 +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

1 follower

Stats

Asked: 2016-10-19 05:35:58 +0100

Seen: 978 times

Last updated: Jun 30 '19