Skip to content

Missing functionality: converting coefficients #449

Open
@nsajko

Description

@nsajko

I have some code where I define multiple AbstractPolynomial subtypes. In some cases I'd like to be able to turn a polynomial over one ring to a polynomial over another ring, by converting all its coefficients. It would seem appropriate for a function with that functionality to live in the Polynomials module. Something like this:

over_ring(::Type{New}, p::AbstractPolynomial{Old, x})::AbstractPolynomial{New, x} where {New <: Number, Old <: Number, x}

For example, for Polynomial a possible implementation would be this:

over_ring(::Type{New}, p::Polynomial{Old, x}) where {New <: Number, Old <: Number, x} =
  Polynomial{New, x}(p)

Usage example:

julia> over_ring(Float64, Polynomial([3, 2, 1]))
Polynomial(3.0 + 2.0*x + 1.0*x^2)

I'd still need to define a method of this function for each subtype of AbstractPolynomial owned by me, but it would be much nicer and tidier if I could overload a Polynomials function.

Would an interface like this would fit well into Polynomials?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions