Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert an univariate polynomial to a multivariate polynomial? #1503

Open
nsajko opened this issue Nov 22, 2023 · 3 comments
Open

How to convert an univariate polynomial to a multivariate polynomial? #1503

nsajko opened this issue Nov 22, 2023 · 3 comments

Comments

@nsajko
Copy link
Contributor

nsajko commented Nov 22, 2023

Basically the opposite of #220. I've got a univariate polynomial over a multivariate polynomial ring, and I'd like to convert it into a multivariate polynomial ring with one more variable. How to do this? The use case is that minpoly and charpoly return univariate polynomials, but I want a multivariate polynomial.

Example, in case it's not clear what I'm talking about:

julia> using AbstractAlgebra

julia> xy_ring, (x, y) = QQ["x", "y"]
(Multivariate polynomial ring in 2 variables over rationals, AbstractAlgebra.Generic.MPoly{Rational{BigInt}}[x, y])

julia> _, z = polynomial_ring(xy_ring, :z)
(Univariate polynomial ring in z over multivariate polynomial ring, z)

julia> x*z
x*z

julia> typeof(ans)
AbstractAlgebra.Generic.Poly{AbstractAlgebra.Generic.MPoly{Rational{BigInt}}}

So x*z is actually a univariate polynomial, according to AA's type system, and my question is how to convert it into a multivariate polynomial?

@nsajko
Copy link
Contributor Author

nsajko commented Nov 22, 2023

Figured it out:

julia> using AbstractAlgebra

julia> xyz_ring, (x, y, z) = QQ["x", "y", "z"]
(Multivariate polynomial ring in 3 variables over rationals, AbstractAlgebra.Generic.MPoly{Rational{BigInt}}[x, y, z])

julia> _, z_ = polynomial_ring(xyz_ring, :z)
(Univariate polynomial ring in z over multivariate polynomial ring, z)

julia> (x*z_)(z)
x*z

julia> typeof(ans)
AbstractAlgebra.Generic.MPoly{Rational{BigInt}}

Maybe there should be an example like this in the docs?

@thofma
Copy link
Member

thofma commented Dec 1, 2023

Where would you put in the docs?

@fingolfin
Copy link
Member

I am not sure what your problem is, exactly. You got exactly what you asked for.

Perhaps your problem is that you have a tower of ring extensions and would like to collapse it, i.e. you want the ring homomorphism Q[x,y][z] -> Q[x,y,z]. This is sometimes referred to as "flattening". I don't think we have that as a nice simple function in AA, though we do in Oscar (but only for multivariate polynomial rings -- shouldn't be hard to also do it for univariates, we just didn't need it, and you can workaround it by using a multivariate ringt with a single variable).

Example (in Oscar):

julia> xy_ring, (x, y) = QQ["x", "y"]
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])

julia> R,(z,) = polynomial_ring(xy_ring, [:z])
(Multivariate polynomial ring in 1 variable over xy_ring, AbstractAlgebra.Generic.MPoly{QQMPolyRingElem}[z])


julia> hom = Oscar.flatten(R)
Map
  from multivariate polynomial ring in 1 variable over xy_ring
  to multivariate polynomial ring in 3 variables over QQ

julia> hom(x*z)
z*x

julia> parent(ans)
Multivariate polynomial ring in 3 variables z, x, y
  over rational field

julia> parent(x*z)
Multivariate polynomial ring in 1 variable z
  over multivariate polynomial ring in 2 variables over QQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants