-
Notifications
You must be signed in to change notification settings - Fork 72
Remove _map for universal polys
#2206
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,11 +68,9 @@ end | |||||||||||||
| function set_exponent_vector!(p::UnivPoly, i::Int, exps::Vector{Int}) | ||||||||||||||
| S = parent(p) | ||||||||||||||
| len = length(exps) | ||||||||||||||
| if len != nvars(parent(data(p))) | ||||||||||||||
| p.p = upgrade(S, data(p)) | ||||||||||||||
| if len < nvars(S) | ||||||||||||||
| exps = vcat(exps, zeros(Int, nvars(S) - len)) | ||||||||||||||
| end | ||||||||||||||
| p.p = upgrade(S, data(p)) | ||||||||||||||
| if len < nvars(S) | ||||||||||||||
| exps = vcat(exps, zeros(Int, nvars(S) - len)) | ||||||||||||||
| end | ||||||||||||||
| p.p = set_exponent_vector!(data(p), i, exps) | ||||||||||||||
| return p | ||||||||||||||
|
|
@@ -99,11 +97,9 @@ function setcoeff!(p::UnivPoly, exps::Vector{Int}, c::T) where T <: RingElement | |||||||||||||
| c = base_ring(data(p))(c) | ||||||||||||||
| S = parent(p) | ||||||||||||||
| len = length(exps) | ||||||||||||||
| if len != nvars(parent(data(p))) | ||||||||||||||
| p.p = upgrade(S, data(p)) | ||||||||||||||
| if len < nvars(S) | ||||||||||||||
| exps = vcat(exps, zeros(Int, nvars(S) - len)) | ||||||||||||||
| end | ||||||||||||||
| p.p = upgrade(S, data(p)) | ||||||||||||||
| if len < nvars(S) | ||||||||||||||
| exps = vcat(exps, zeros(Int, nvars(S) - len)) | ||||||||||||||
| end | ||||||||||||||
| p.p = setcoeff!(data(p), exps, c) | ||||||||||||||
| return p | ||||||||||||||
|
|
@@ -620,15 +616,7 @@ function isless(a::UnivPoly{T}, b::UnivPoly{T}) where {T} | |||||||||||||
| end | ||||||||||||||
| S = parent(a) | ||||||||||||||
| num = nvars(S) | ||||||||||||||
| s = data(a) | ||||||||||||||
| t = data(b) | ||||||||||||||
| if nvars(parent(s)) != num | ||||||||||||||
| s = upgrade(S, s) | ||||||||||||||
| end | ||||||||||||||
| if nvars(parent(t)) != num | ||||||||||||||
| t = upgrade(S, t) | ||||||||||||||
| end | ||||||||||||||
| return isless(s, t) | ||||||||||||||
| return isless(upgrade(S, data(a)), upgrade(S, data(b))) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we upgrade the underlying polynomials of function upgrade!(p::UniversalPolyRingElem)
p.p = upgrade(parent(p), data(p))
return p
endand then here we can do
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I thought about this too. I wasn't sure if it is a good idea that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The internal representation may change at any point, as it is internal. We try to not change it during printing as that may lead to hard to track down bugs, but otherwise that is fine to do in a non-! function
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, alright then. I'll adjust the PR accordingly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put this, and also the change that upgrade checks if it needs to do anything, into its own PR to not clutter this one here with mostly unrelated changes?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can do this as well.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which order would you like to have the changes?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe first do the other PR about upgrade, we merge that and then update the one here? |
||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| ############################################################################### | ||||||||||||||
|
|
@@ -673,10 +661,8 @@ function deflate(p::UnivPoly{T}, shift::Vector{Int}, defl::Vector{Int}) where {T | |||||||||||||
| if vlen == num | ||||||||||||||
| return UnivPoly{T}(deflate(pp, shift, defl), S) | ||||||||||||||
| end | ||||||||||||||
| if vlen > num | ||||||||||||||
| pp = upgrade(S, pp) | ||||||||||||||
| num = nvars(parent(pp)) | ||||||||||||||
| end | ||||||||||||||
| pp = upgrade(S, pp) | ||||||||||||||
| num = nvars(parent(pp)) | ||||||||||||||
| if vlen < num | ||||||||||||||
| shift = vcat(shift, zeros(Int, num - vlen)) | ||||||||||||||
| defl = vcat(defl, ones(Int, num - vlen)) | ||||||||||||||
|
|
@@ -697,10 +683,8 @@ function inflate(p::UnivPoly{T}, shift::Vector{Int}, defl::Vector{Int}) where {T | |||||||||||||
| if vlen == num | ||||||||||||||
| return UnivPoly{T}(inflate(pp, shift, defl), S) | ||||||||||||||
| end | ||||||||||||||
| if vlen > num | ||||||||||||||
| pp = upgrade(S, pp) | ||||||||||||||
| num = nvars(parent(pp)) | ||||||||||||||
| end | ||||||||||||||
| pp = upgrade(S, pp) | ||||||||||||||
| num = nvars(parent(pp)) | ||||||||||||||
| if vlen < num | ||||||||||||||
| shift = vcat(shift, zeros(Int, num - vlen)) | ||||||||||||||
| defl = vcat(defl, ones(Int, num - vlen)) | ||||||||||||||
|
|
@@ -958,8 +942,7 @@ end | |||||||||||||
| _change_univ_poly_ring(R, Rx, cached::Bool) = universal_polynomial_ring(R, symbols(Rx); internal_ordering=internal_ordering(Rx), cached)[1] | ||||||||||||||
|
|
||||||||||||||
| function change_base_ring(R::Ring, p::UnivPoly{T}; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(R, parent(p), cached)) where {T <: RingElement} | ||||||||||||||
| base_ring(parent) != R && error("Base rings do not match.") | ||||||||||||||
| return _map(R, p, parent) | ||||||||||||||
| return UnivPoly(change_base_ring(R, upgrade(AbstractAlgebra.parent(p), data(p)); parent = mpoly_ring(parent)), parent) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about introducing a new helper, like this (untested code) function upgrade(p::UniversalPolyRingElem)
return upgrade(parent(p), data(p))
endthen calls to
Suggested change
Actually I still find this a bit difficult to untangle, splitting this up would help, e.g.
Suggested change
and now I realize that there might be a problem, namely if
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add this new |
||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| function change_coefficient_ring(R::Ring, p::UnivPoly{T}; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(R, parent(p), cached)) where {T <: RingElement} | ||||||||||||||
|
|
@@ -973,17 +956,7 @@ end | |||||||||||||
| ################################################################################ | ||||||||||||||
|
|
||||||||||||||
| function map_coefficients(f::T, p::UnivPoly; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(parent(f(zero(base_ring(p)))), parent(p), cached)) where T | ||||||||||||||
| return _map(f, p, parent) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| function _map(g::T, p::UnivPoly, Rx) where T | ||||||||||||||
| cvzip = zip(coefficients(p), exponent_vectors(p)) | ||||||||||||||
| M = MPolyBuildCtx(Rx) | ||||||||||||||
| for (c, v) in cvzip | ||||||||||||||
| push_term!(M, g(c), v) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| return finish(M) | ||||||||||||||
| return UnivPoly(map_coefficients(f, upgrade(AbstractAlgebra.parent(p), data(p)); parent = mpoly_ring(parent)), parent) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| ############################################################################### | ||||||||||||||
|
|
@@ -1172,12 +1145,16 @@ end | |||||||||||||
|
|
||||||||||||||
| function upgrade(S::UniversalPolyRing{T}, pp::MPolyRingElem{T}) where {T} | ||||||||||||||
| n = nvars(S) - nvars(parent(pp)) | ||||||||||||||
| ctx = MPolyBuildCtx(mpoly_ring(S)) | ||||||||||||||
| v0 = zeros(Int, n) | ||||||||||||||
| for (c, v) in zip(coefficients(pp), exponent_vectors(pp)) | ||||||||||||||
| push_term!(ctx, c, vcat(v, v0)) | ||||||||||||||
| if n > 0 | ||||||||||||||
| ctx = MPolyBuildCtx(mpoly_ring(S)) | ||||||||||||||
| v0 = zeros(Int, n) | ||||||||||||||
| for (c, v) in zip(coefficients(pp), exponent_vectors(pp)) | ||||||||||||||
| push_term!(ctx, c, vcat(v, v0)) | ||||||||||||||
| end | ||||||||||||||
| return finish(ctx) | ||||||||||||||
| else | ||||||||||||||
| return pp | ||||||||||||||
| end | ||||||||||||||
| return finish(ctx) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| function (a::UniversalPolyRing{T})(b::RingElement) where {T <: RingElement} | ||||||||||||||
|
|
@@ -1198,11 +1175,7 @@ end | |||||||||||||
|
|
||||||||||||||
| function (S::UniversalPolyRing{T})(p::UnivPoly{T}) where {T <: RingElement} | ||||||||||||||
| parent(p) !== S && error("Unable to coerce") | ||||||||||||||
| n = nvars(S) - nvars(parent(data(p))) | ||||||||||||||
| if n != 0 | ||||||||||||||
| p = UnivPoly{T}(upgrade(S, data(p)), S) | ||||||||||||||
| end | ||||||||||||||
| return p | ||||||||||||||
| return UnivPoly{T}(upgrade(S, data(p)), S) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| function (a::UniversalPolyRing{T})(b::Vector{T}, m::Vector{Vector{Int}}) where {T <: RingElement} | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.