I am trying to use HomotopyContinuation.jl to solve the central configuration problem. Below is a minimal working example of my code:
using HomotopyContinuation, LinearAlgebra
function gen_equations(m)
n = length(m)
@var r[1:n, 1:n]
@var u[1:n, 1:n]
S = Matrix(undef, n, n)
R = (i, j) -> (i == j ? zero(r[1, 1]) : (i < j ? r[i, j] : r[j, i]))
U = (i, j) -> (i == j ? zero(u[1, 1]) : (i < j ? u[i, j] : u[j, i]))
for i in 1:n
for j in 1:n
if i == j
S[i, j] = 0.0
else
S[i, j] = (U(i, j)^3) - 1
end
end
end
result = Matrix(undef, n, n)
for i in 1:n
for j in 1:n
a = 0
for k in 1:n
a = a + m[k] * (S[i, k] * (R(j, k)^2 - R(i, k)^2 - R(i, j)^2) + S[j, k] * (R(i, k)^2 - R(j, k)^2 - R(i, j)^2))
end
result[i, j] = a
end
end
eq = Expression[]
var = Variable[]
for i in 1:n
for j in 1:n
if i < j
push!(eq, result[i, j])
append!(var, [r[i,j],u[i,j]])
push!(eq, U(i, j) * R(i, j) - 1)
end
end
end
System(eq, variables=var)
end
m=[1.0,2.0,3.0,4.0,5.0]
sys = gen_equations(m)
result_hc = solve(sys)
For n = 4, the code runs successfully. However, when I increase the number of bodies to n = 5, I encounter the following error:
Computing mixed cells... 13742 Time: 0:00:19
mixed_volume: 133998561
ERROR: InexactError: trunc(Int32, 488183162732544)
Stacktrace:
[1] throw_inexacterror(func::Symbol, to::Type, val::Int64)
@ Core .\boot.jl:815
[2] checked_trunc_sint
@ .\boot.jl:829 [inlined]
[3] toInt32
@ .\boot.jl:866 [inlined]
[4] Int32
@ .\boot.jl:956 [inlined]
[5] convert
@ .\number.jl:7 [inlined]
[6] cconvert
@ .\essentials.jl:687 [inlined]
[7] set_si!
@ .\gmp.jl:217 [inlined]
[8] _broadcast_getindex_evalf
@ .\broadcast.jl:699 [inlined]
[9] _broadcast_getindex
@ .\broadcast.jl:672 [inlined]
[10] _getindex
@ .\broadcast.jl:620 [inlined]
[11] getindex
@ .\broadcast.jl:616 [inlined]
[12] macro expansion
@ .\broadcast.jl:995 [inlined]
[13] macro expansion
@ .\simdloop.jl:77 [inlined]
[14] copyto!
@ .\broadcast.jl:994 [inlined]
[15] copyto!
@ .\broadcast.jl:947 [inlined]
[16] copy
@ .\broadcast.jl:919 [inlined]
[17] materialize
@ .\broadcast.jl:894 [inlined]
[18] solve!(BSS::HomotopyContinuation.BinomialSystemSolver)
@ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\binomial_system.jl:178
[19] solve
@ C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\binomial_system.jl:162 [inlined]
[20] iterate(iter::PolyhedralStartSolutionsIterator{Vector{…}}, state::Tuple{MixedSubdivisions.MixedCell, Int64, Int64})
@ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\polyhedral.jl:94
[21] _collect(cont::UnitRange{…}, itr::PolyhedralStartSolutionsIterator{…}, ::Base.HasEltype, isz::Base.SizeUnknown)
@ Base .\array.jl:741
[22] collect
@ .\array.jl:728 [inlined]
[23] #solve#278
@ C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\solve.jl:535 [inlined]
[24] solve(args::System; show_progress::Bool, threading::Bool, catch_interrupt::Bool, target_parameters::Nothing, stop_early_cb::Function, transform_result::Nothing, transform_parameters::typeof(identity), flatten::Nothing, target_subspaces::Nothing, iterator_only::Bool, bitmask::Nothing, kwargs::@Kwargs{})
@ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\solve.jl:508
[25] solve(args::System)
@ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\07UGP\src\solve.jl:439
[26] top-level scope
@ c:\Users\PC\Desktop\同伦延拓\ask.jl:43
Some type information was truncated. Use `show(err)` to see complete types.
Question
It seems that the error is caused by an integer overflow when converting to Int32, likely due to the extremely large mixed volume.
Is there any way to make this computation work (even if it takes a very long time)? For example:
- Can this limitation be bypassed (e.g., using
Int64or arbitrary precision)? - Is there a recommended way to handle such large systems in
HomotopyContinuation.jl?
Any suggestions would be greatly appreciated.