Skip to content

Add roots_with_multiplicity ? #2119

@fingolfin

Description

@fingolfin

Feature request by @laurentbartholdi from issue #2112:

Also, I don't think it's so useful to return many times a root; just as factor(100) returns an iterable [2 => 2, 5 => 2], it would certainly be useful to return roots with their multiplicity in the same format?

Rough implementation:

gcd_quo(a::PolyRingElem{T},b::PolyRingElem{T}) where T = let g = gcd(a,b)
    g,divexact(a,g),divexact(b,g)
end

function yun_algorithm(callback::Function,f)
    g, c, d = gcd_quo(f,derivative(f))
    d -= derivative(c)
    i = 1
    while !isone(c)
        g, c, d = gcd_quo(c,d)
        d -= derivative(c)
        callback(g,i)
        i += 1
    end
end

function roots_with_multiplicity(p::PolyRingElem{T}) where T
    r = Pair{T,Int}[]
    yun_algorithm(p) do g, i
        degree(g)>0 && for w=roots(g)
            push!(r,w=>i)
        end
    end
    r
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions