ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 22 Apr 2021 10:06:15 +0200Convert element from fraction field of polynomial ring to number fieldhttps://ask.sagemath.org/question/56762/convert-element-from-fraction-field-of-polynomial-ring-to-number-field/Consider the following
F.<u> = NumberField(x^2-3)
R.<y> = PolynomialRing(F)
Q = R.fraction_field()
Then, `F(Q(2*u))` yields an error since
> TypeError: unable to convert 2*u to
> Number Field in u with defining
> polynomial x^2 - 3
Of course one could expect that this conversion should be not a problem. Doing the same over the base field `QQ` instead of a number field works as expected.
This problem can be fixed (in this case) by converting first to the polynomial ring and then to the number field, i.e., `F(R(Q(2*u)))` works fine. However, in practice, if we want to convert some `a` (where we know it "should" be in `F` but it might technically not) to `F`, it is very unpractical to check first whether `a` belongs in some certain ring and then convert it by going via the polynomial ring.
Is there a good built in way to do this? So we are given some `a` (which might be already in `F` or in some construction built upon `F`) and want to have `a` in `F`.philipp7Thu, 22 Apr 2021 10:06:15 +0200https://ask.sagemath.org/question/56762/Unable to convert string to rational when plus sign is addedhttps://ask.sagemath.org/question/49537/unable-to-convert-string-to-rational-when-plus-sign-is-added/This looks like a bug. The code
QQ('+1')
gives the exception
> TypeError: unable to convert '+1' to a
> rational
This happens with any positive rational, not just 1.
Also, this does not happen with neither
ZZ('+1')
nor
PolynomialRing(QQ,names='x')('+1')
Is this actually a bug? If it is, can someone investigate it and write a trac ticket? I'm quite new to Sagemath and Python and quite unskilled yet to do it properly. Thank you!Jose BroxMon, 13 Jan 2020 23:24:53 +0100https://ask.sagemath.org/question/49537/