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
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ version = "1.2.0-DEV"
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
AlgebraicSolving = "66b61cbe-0446-4d5d-9090-1ff510639f9d"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GAP = "c863536a-3901-11e9-33e7-d5cd0df7b904"
Hecke = "3e1990a7-5d81-5526-99ce-9ba3ff248f21"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Polymake = "d720cf60-89b5-51f5-aff5-213f193123e7"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RandomExtensions = "fb686558-2515-59ef-acaa-46db3789a887"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Expand Down
19 changes: 7 additions & 12 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 @@ -29,15 +31,8 @@ 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
end

function det(A::Matrix{R}) where {R<:Union{TropicalSemiringElem,MPolyRingElem{<:TropicalSemiringElem},PolyRingElem{<:TropicalSemiringElem}}}
return det(matrix(parent(first(A)),A))
function det(A::Generic.MatSpaceElem{<:TropicalSemiringElem})
benlorenz marked this conversation as resolved.
Show resolved Hide resolved
nrows(A)!=ncols(A) && error("Non-square matrix")
T = base_ring(A)
return T(Polymake.tropical.tdet(A))
end
YueRen marked this conversation as resolved.
Show resolved Hide resolved
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
Loading