Skip to content

Conversation

@SoongNoonien
Copy link
Collaborator

I noticed that _map just duplicates code which is already present for multivariate polynomials. So, let's just use the present code instead.

@SoongNoonien SoongNoonien requested a review from thofma November 5, 2025 14:30
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it passes all tests I am happy to trust your judgement

@SoongNoonien
Copy link
Collaborator Author

Ok, this is the usual problem with the exponent vector length of the universal polys. I'll look into it.

@SoongNoonien
Copy link
Collaborator Author

This additional upgrade can make the mapping slower. We could work around this by creating an appropriate intermediate mpoly ring over the new coefficient ring but with less variables, I'm not sure if this is worth it or even desired.

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.94%. Comparing base (82f6998) to head (7506950).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2206      +/-   ##
==========================================
- Coverage   88.01%   87.94%   -0.07%     
==========================================
  Files         127      127              
  Lines       31765    31749      -16     
==========================================
- Hits        27957    27923      -34     
- Misses       3808     3826      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.01%. Comparing base (82f6998) to head (2093761).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2206   +/-   ##
=======================================
  Coverage   88.01%   88.01%           
=======================================
  Files         127      127           
  Lines       31765    31746   -19     
=======================================
- Hits        27957    27941   -16     
+ Misses       3808     3805    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SoongNoonien
Copy link
Collaborator Author

As suggested by @lgoettgens I've adjusted the upgrade function to check for the number of variables before upgrading to a bigger ring.

return isless(data(a), data(b))
end
S = parent(a)
num = nvars(S)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num = nvars(S)

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)
Copy link
Member

Choose a reason for hiding this comment

The 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))
end

then calls to upgrade can further be simplified, e.g. here

Suggested change
return UnivPoly(change_base_ring(R, upgrade(AbstractAlgebra.parent(p), data(p)); parent = mpoly_ring(parent)), parent)
return UnivPoly(change_base_ring(R, upgrade(p); parent = mpoly_ring(parent)), parent)

Actually I still find this a bit difficult to untangle, splitting this up would help, e.g.

Suggested change
return UnivPoly(change_base_ring(R, upgrade(AbstractAlgebra.parent(p), data(p)); parent = mpoly_ring(parent)), parent)
p2 = upgrade(p)
p3 = change_base_ring(R, p2; parent = mpoly_ring(parent))
return UnivPoly(p3, parent)

and now I realize that there might be a problem, namely if nvars(mpoly_ring(parent)) and nvars(mpoly_ring(AA.parent(p))) differ (this is not a new problem of course, and perhaps best to ignore for now; my point is that the splitting enabled me to reason about the code in a way I couldn't when it was all in one line).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add this new upgrade method but #2198 changes this anyway.

t = upgrade(S, t)
end
return isless(s, t)
return isless(upgrade(S, data(a)), upgrade(S, data(b)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we upgrade the underlying polynomials of a and b and then throw this away... I always wondered if that's a good idea. Well, it is certainly wise not to change this in this PR, but perhaps in a future PR we could think about introducing another helper (distinct from the one I suggest in another comment) like this:

function upgrade!(p::UniversalPolyRingElem)
  p.p = upgrade(parent(p), data(p))
  return p
end

and then here we can do

Suggested change
return isless(upgrade(S, data(a)), upgrade(S, data(b)))
return isless(upgrade!(a), upgrade!(b))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 isless potentially modifies its inputs. Of course they would only be modified internally but shouldn't isless be named isless! then? (I'm not actually suggesting to rename isless, just wondering.)

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, alright then. I'll adjust the PR accordingly.

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can do this as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which order would you like to have the changes?

Copy link
Member

Choose a reason for hiding this comment

The 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?

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

Successfully merging this pull request may close these issues.

3 participants