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

tropical determinant via Hungarian method #3943

Merged
merged 10 commits into from
Jul 18, 2024
13 changes: 6 additions & 7 deletions src/TropicalGeometry/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
@doc raw"""
det(A::Generic.MatSpaceElem{<: TropicalSemiringElem})
benlorenz marked this conversation as resolved.
Show resolved Hide resolved

Return the tropical determinant of `A`.
Return the tropical determinant of `A`. That is, this function evaluates the tropicalization of the ordinary determinant considered as a multivariate polynomial at `A`.

That computation is equivalent to solving a linear assignment problem from combinatorial optimization. The implementation employs the Hungarian method, which is polynomial time. See Chapter 3 in [Jos21](@cite).

!!! note
This function effectively overwrites the `det` command for tropical matrices. This means that functions like `minors` will use the tropical determinant when used on a tropical matrix.
Expand All @@ -30,12 +32,9 @@ julia> det(A)
```
"""
function det(A::Generic.MatSpaceElem{R}) where {R<:Union{TropicalSemiringElem,MPolyRingElem{<:TropicalSemiringElem},PolyRingElem{<:TropicalSemiringElem}}}
YueRen marked this conversation as resolved.
Show resolved Hide resolved
detA = zero(base_ring(A))
nrows(A)!=ncols(A) && return detA # return tropical zero if matrix not square
for sigma in AbstractAlgebra.SymmetricGroup(nrows(A)) # otherwise follow Leibniz Formula
detA += prod([ A[i,sigma[i]] for i in 1:nrows(A) ])
end
return detA
T = base_ring(A)
nrows(A)!=ncols(A) && return zero(T) # return tropical zero if matrix not square
YueRen marked this conversation as resolved.
Show resolved Hide resolved
return T(Polymake.tropical.tdet(A))
end
YueRen marked this conversation as resolved.
Show resolved Hide resolved

function det(A::Matrix{R}) where {R<:Union{TropicalSemiringElem,MPolyRingElem{<:TropicalSemiringElem},PolyRingElem{<:TropicalSemiringElem}}}
Expand Down
Loading