InexactError in HomotopyContinuation.jl when solving a 5-body central configuration system

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 Int64 or arbitrary precision)?
  • Is there a recommended way to handle such large systems in HomotopyContinuation.jl?

Any suggestions would be greatly appreciated.

Can you share more details about your platform and the julia/package versions? E.g. the output of versioninfo() and Pkg.status() in the corresponding environment.

I’m not familiar with the package or the underlying math, but I just tried to run your code on Linux with Julia 1.10.10 and HomotopyContinuation.jl version 2.18.0 and couldn’t reproduce the error (although I stopped the computation after a while, since the displayed ETA is over 20 days… so the error might appear much later (?) ).

Tracking 133998561 paths...   0%|                                        |  ETA: 24.62 days
                   # paths tracked: 8076
   # non-singular solutions (real): 6630 (0)
       # singular endpoints (real): 3 (0)
          # total solutions (real): 6633 (0)
versions
julia> versioninfo()
Julia Version 1.10.10
Commit 95f30e51f41 (2025-06-27 09:51 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 64 × AMD Ryzen Threadripper PRO 3975WX 32-Cores
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 64 virtual cores)
Environment:
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_MAX_NUM_PRECOMPILE_FILES = 50

(jl_acS1S7) pkg> st
Status `/tmp/jl_acS1S7/Project.toml`
  [f213a82b] HomotopyContinuation v2.18.0
  [37e2e46d] LinearAlgebra

Thanks for your attention to this issue. Below are my platform details and the versions of Julia and the relevant packages:

julia> versioninfo()
Julia Version 1.12.5
Commit 5fe89b8ddc (2026-02-09 16:05 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 28 × Intel(R) Core(TM) i7-14700KF
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
  GC: Built with stock GC
Threads: 28 default, 1 interactive, 28 GC (on 28 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1
  JULIA_NUM_THREADS = 28

(同伦延拓) pkg> st
Status `C:\Users\PC\Desktop\同伦延拓\Project.toml`
⌃ [0f109fa4] BifurcationKit v0.5.6
  [e9467ef8] GLMakie v0.13.9
⌃ [f213a82b] HomotopyContinuation v2.16.0
  [91a5bcdd] Plots v1.41.6
Info Packages marked with ⌃ have new versions available and may be upgradable.

I will give a try with julia 1.10.10 and HomotopyContinuation v2.18.0

I have tested this on my platform using Julia 1.10.10 together with HomotopyContinuation.jl v2.18.0, but I encountered the same error:

Computing mixed cells... 17171    Time: 0:00:05
   mixed_volume: 133998561
ERROR: InexactError: trunc(Int32, 327523762176)
Stacktrace:
  [1] throw_inexacterror(f::Symbol, ::Type{Int32}, val::Int64)
    @ Core .\boot.jl:634
  [2] checked_trunc_sint
    @ .\boot.jl:656 [inlined]
  [3] toInt32
    @ .\boot.jl:693 [inlined]
  [4] Int32
    @ .\boot.jl:783 [inlined]
  [5] convert
    @ .\number.jl:7 [inlined]
  [6] cconvert
    @ .\essentials.jl:543 [inlined]
  [7] set_si!
    @ .\gmp.jl:211 [inlined]
  [8] _broadcast_getindex_evalf
    @ .\broadcast.jl:709 [inlined]
  [9] _broadcast_getindex
    @ .\broadcast.jl:682 [inlined]
 [10] getindex
    @ .\broadcast.jl:636 [inlined]
 [11] macro expansion
    @ .\broadcast.jl:1004 [inlined]
 [12] macro expansion
    @ .\simdloop.jl:77 [inlined]
 [13] copyto!
    @ .\broadcast.jl:1003 [inlined]
 [14] copyto!
    @ .\broadcast.jl:956 [inlined]
 [15] copy
    @ .\broadcast.jl:928 [inlined]
 [16] materialize
    @ .\broadcast.jl:903 [inlined]
 [17] solve!(BSS::HomotopyContinuation.BinomialSystemSolver)
    @ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\3ppvs\src\binomial_system.jl:178
 [18] solve
    @ C:\Users\PC\.julia\packages\HomotopyContinuation\3ppvs\src\binomial_system.jl:162 [inlined]
 [19] iterate(iter::PolyhedralStartSolutionsIterator{Vector{…}}, state::Tuple{MixedSubdivisions.MixedCell, Int64, Int64})
    @ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\3ppvs\src\polyhedral.jl:94
 [20] _collect(cont::UnitRange{…}, itr::PolyhedralStartSolutionsIterator{…}, ::Base.HasEltype, isz::Base.SizeUnknown)
    @ Base .\array.jl:772
 [21] collect
    @ .\array.jl:759 [inlined]
 [22] #solve#306
    @ C:\Users\PC\.julia\packages\HomotopyContinuation\3ppvs\src\solve.jl:541 [inlined]
 [23] 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\3ppvs\src\solve.jl:514
 [24] solve(args::System)
    @ HomotopyContinuation C:\Users\PC\.julia\packages\HomotopyContinuation\3ppvs\src\solve.jl:445
 [25] top-level scope
    @ c:\Users\PC\Desktop\同伦延拓\ask.jl:43
Some type information was truncated. Use `show(err)` to see complete types.

I think maybe Clong === Int32 on this platform, but not on other platforms, such as Linux. That could be connected.

Possibly related piece of code:

cc @saschatimme @jonas-schulze

1 Like

Looks like it. I just tried to reproduce the error on a Windows VM and there indeed Clong === Int32:

julia> versioninfo()
Julia Version 1.12.5
Commit 5fe89b8ddc (2026-02-09 16:05 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × Common KVM processor
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, k8-sse3)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 16 virtual cores)

Following the stack trace: On Windows, if I just try this in a fresh Julia session and empty environment I get the same error (but not on Linux):

julia> using Base.GMP.MPZ: set_si!

julia> a = BigInt(1)
1

julia> set_si!(a, 2)
2

julia> set_si!(a, 13316210621153480)
ERROR: InexactError: trunc(Int32, 13316210621153480)
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!(x::BigInt, a::Int64)
   @ Base.GMP.MPZ .\gmp.jl:217
 [8] top-level scope

The function at Base.GMP.MPZ .\gmp.jl:217 looks like this:

(copied here for nicer syntax highlighting)

for (op, T) in ((:fac_ui, Culong), (:set_ui, Culong), (:set_si, Clong), (:set_d, Cdouble))
    op! = Symbol(op, :!)
    @eval begin
        $op!(x::BigInt, a) = (ccall($(gmpz(op)), Cvoid, (mpz_t, $T), x, a); x)
        $op(a) = $op!(BigInt(), a)
    end
end

Like @nsajko suspected, there is an attempt to convert the Julia integer to Clong which is Int32 and can’t hold the number from the argument. It basically boils down to trying

Base.cconvert(Clong, 13316210621153480)

which fails on the x86_64-w64-mingw32 system, but if Clong === Int64 (e.g. on my Linux machine).


I just learned that the various int, long, long long etc. types in C are not defined in terms of absolute sizes (bits), but they just have to respect that the next larger type can contain at least all the numbers from the smaller type. This is kind of unfortunate :sweat_smile: and makes me wonder if the problem with the above set_si! function is actually a bug or not?

For me it sounds reasonable that set_si! for arbitrary precision integers should convert to long long, not just long, but libgmp doesn’t seem to implement that internally, so that gives wrong results:

julia> Base.GMP.MPZ.gmpz(:set_si)
(:__gmpz_set_si, "libgmp-10.dll")

julia> a = BigInt(1)
1

julia> ccall((:__gmpz_set_si, "libgmp-10.dll"), Cvoid, (Base.GMP.MPZ.mpz_t, Clonglong), a, 13316210621153480); a
-472645432

So I’m not sure how to proceed here :sweat_smile: Is this an issue with the package or with Base/libgmp (or both)? At least the functions from HomotopyContinuation.jl quoted above by @nsajko also (wrongly) assumes that Clong is equal to Int64. Probably the way the low-level set_si! is used in the package assumes the same? In Base, the regular arithmetic with BigInt works fine, so it’s probably best to file an issue with the package (?)

2 Likes

Thank you very much for your helpful comments and suggestions. I found a related issue in the repository: InexactError on certain operating systems, which seems to describe a very similar behavior (especially the overflow in trunc(Int32, ...) and the dependence on mixed volume and platform). So this might not be specific to my example.
I will follow up there and, if needed, provide additional details for my example.

2 Likes

For a proper fix, I see two alternatives:

Will make a PR, if no one else does first.

My plan currently is to:

4 Likes

Thanks for tackling this, @nsajko! I am not working in the field of homotopy continuation anymore, unfortunately. Your action plan sounds reasonable to me, though would it be possible to make HC.jl use the logic from julia/base/gmp.jl you referenced?

1 Like

Sure, but MutableArithmetics.jl seems like the more appropriate place for that code to live. Then it can be reused across the ecosystem, instead of duplicated in each package that uses BigInt.