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/Changing Parent on multivariable polynomial ringhttps://ask.sagemath.org/question/53403/changing-parent-on-multivariable-polynomial-ring/ This question is similar to
https://ask.sagemath.org/question/8035/changing-parent-rings-of-polynomials/
R.<x,y,z,w> = QQ[]
f=x*y*z*w
f1=derivative(f,x)
f2=derivative(f,y)
f3=derivative(f,z)
f4=derivative(f,w)
J = R.ideal([f1, f2, f3,f4])
Now f is in its Jacobian by Euler identity so we can lift f as follows.
f in J
returns true.
f.lift(J)
returns the lift of f. Now consider h=f^(2)/ (x*y*z). Although this seems like a rational function, this is actually a polynomial.
h in J
returns true. However, I get an error when doing
h.lift(J)
The reason for this is Sage reads h as living not in the multivariable ring, but the fraction field of it because I divided by x*y*z. Apparently, there is no lift function for polynomials living in the fraction field. However, it is still an honest polynomial as it divides cleanly with no remainder. To be more clear,
f.parent()
returns Multivariate Polynomial Ring in x, y, z, w over Rational Field.
h.parent()
returns Fraction Field of Multivariate Polynomial Ring in x, y, z, w over Rational Field. Is there a way to make h belong to the multivariate ring instead of its fraction field so I can apply the lift function?whatupmattFri, 11 Sep 2020 19:28:25 +0200https://ask.sagemath.org/question/53403/Converting polynomials between ringshttps://ask.sagemath.org/question/24207/converting-polynomials-between-rings/ I have two polynomials, each one explicitly created as members of different multivariate polynomial rings. So for example I might have
R1.<a,b,c,t> = PolynomialRing(QQ)
L = (a*t^2+b*t+c).subs(a=2,b=3,c=4)
R2.<A,B,C,D,t> = PolynomialRing(QQ)
p = (A*t+B)^2+(C*t+D)^2
Now I want to compare the coefficients of the two polynomials, which means converting L to be a polynomial in the ring R2.
However, I'm not sure (or more to the point, can't remember) how to do this. Is there some simple, canonical way to do this? Thanks!AlasdairFri, 19 Sep 2014 14:44:21 +0200https://ask.sagemath.org/question/24207/Cannot convert int to sage.rings.integer.Integerhttps://ask.sagemath.org/question/8099/cannot-convert-int-to-sageringsintegerinteger/I created a minimal example in the file bad.py
from sage.all import *
j = 0
m = matrix(3,3)
m.insert_row(j, [1,1,1])
Then from sage:
sage: load bad.py
TypeError: Cannot convert int to sage.rings.integer.Integer
I think I can see an easy workaround, I can wrap all the 1's in Integer() (or change the name of the file to .sage so the preparser does it), but why is that necessary? Is this a bug? Why would sage not be able to convert int to Integer? Isn't that a pretty obvious conversion?
paragonMon, 02 May 2011 14:23:12 +0200https://ask.sagemath.org/question/8099/