Skip to content

Commit

Permalink
tropical determinant via Hungarian method (#3943)
Browse files Browse the repository at this point in the history
  • Loading branch information
micjoswig committed Jul 18, 2024
1 parent e3f1503 commit 2bca928
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/TropicalGeometry/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
################################################################################

@doc raw"""
det(A::Generic.MatSpaceElem{<: TropicalSemiringElem})
det(A::MatrixElem{<: TropicalSemiringElem})
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 @@ -29,15 +31,13 @@ julia> det(A)
(5)
```
"""
function det(A::Generic.MatSpaceElem{R}) where {R<:Union{TropicalSemiringElem,MPolyRingElem{<:TropicalSemiringElem},PolyRingElem{<:TropicalSemiringElem}}}
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
function det(A::MatrixElem{<:TropicalSemiringElem})
@req nrows(A) == ncols(A) "Non-square matrix"
T = base_ring(A)
return T(Polymake.tropical.tdet(A))
end

function det(A::Matrix{R}) where {R<:Union{TropicalSemiringElem,MPolyRingElem{<:TropicalSemiringElem},PolyRingElem{<:TropicalSemiringElem}}}
return det(matrix(parent(first(A)),A))
function det(A::Matrix{<:TropicalSemiringElem})
@req 0 < nrows(A) == ncols(A) "Non-square or empty matrix"
return det(matrix(parent(first(A)),A))
end
3 changes: 0 additions & 3 deletions test/TropicalGeometry/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
@testset "det(A::Generic.MatSpaceElem{<:TropicalSemiringElem})" begin
A = Matrix(T[1 2; 3 5]) # (julia) matrix over tropical numbers
@test det(A) == (minOrMax==min ? T(5) : T(6))
R, (x,y) = T[:x,:y]
A = Matrix(identity_matrix(R,2)) # (julia) matrix over tropical polynomials
@test det(A) == one(R)
end
end

Expand Down

0 comments on commit 2bca928

Please sign in to comment.