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

Issues dealing with BigFloat coefficients #528

Open
luanborelli opened this issue Feb 28, 2023 · 6 comments
Open

Issues dealing with BigFloat coefficients #528

luanborelli opened this issue Feb 28, 2023 · 6 comments

Comments

@luanborelli
Copy link

I have a system where the coefficients of the polynomials are huge integers. When declaring these polynomials, their coefficients are stored as BigFloat. When trying to solve the system, the package seems to be unable to handle such coefficients.

solution = solve(F)

F is a System whose polynomials coefficients have BigFloat type. Output:

ERROR: MethodError: no method matching HomotopyContinuation.ToricHomotopy(::MixedSystem{Int32, (0x436dfc9bd00f36be, 1)}, ::Vector{Vector{Complex{BigFloat}}})
Closest candidates are:
  HomotopyContinuation.ToricHomotopy(::AbstractSystem, ::Vector{Vector{ComplexF64}}) at D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\homotopies\toric_homotopy.jl:37
  HomotopyContinuation.ToricHomotopy(::S, ::Vector{ComplexF64}, ::Vector{Float64}, ::Vector{Float64}, ::StructArrays.StructVector{ComplexF64, NamedTuple{(:re, :im), Tuple{Vector{Float64}, Vector{Float64}}}, Int64}, ::Vector{ComplexF64}, ::Vector{ComplexF64}, ::Vector{ComplexF64}, ::Base.RefValue{ComplexF64}, ::Base.RefValue{ComplexF64}, ::TaylorVector{5, ComplexF64}, ::TaylorVector{4, ComplexF64}, ::TaylorVector{3, ComplexF64}) where S<:AbstractSystem at D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\homotopies\toric_homotopy.jl:16
Stacktrace:
 [1] polyhedral(support::Vector{Matrix{Int32}}, start_coeffs::Vector{Vector{Complex{BigFloat}}}, target_coeffs::Vector{Vector{BigFloat}}; endgame_options::EndgameOptions, tracker_options::TrackerOptions, only_torus::Bool, only_non_zero::Bool, compile::Symbol, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HomotopyContinuation D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\polyhedral.jl:320
 [2] #polyhedral#226
   @ D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\polyhedral.jl:268 [inlined]
 [3] polyhedral(f::System; compile::Symbol, target_parameters::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HomotopyContinuation D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\polyhedral.jl:201
 [4] solver_startsolutions(F::System, starts::Nothing; seed::UInt32, start_system::Symbol, generic_parameters::Nothing, p₁::Nothing, start_parameters::Nothing, p₀::Nothing, target_parameters::Nothing, compile::Symbol, start_subspace::Nothing, target_subspace::Nothing, intrinsic::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HomotopyContinuation D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\solve.jl:160
 [5] solver_startsolutions (repeats 2 times)
   @ D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\solve.jl:115 [inlined]
 [6] 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, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HomotopyContinuation D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\solve.jl:472
 [7] solve(args::System)
   @ HomotopyContinuation D:\Users\b46525\.julia\packages\HomotopyContinuation\I1faM\src\solve.jl:432
 [8] top-level scope
   @ Untitled-1:83
@gescholt
Copy link

gescholt commented Aug 6, 2024

Hello
I think I ran into the same issue, I have two very similar systems, but system 1 runs fine, system2 returns the same error as you. At first I thought the error has to do with constant coefficients appearing in the system, but then I generated some random polynomial and that doesn't seem to be the issue.
Maybe it has to do with the differentiate command?

using HomotopyContinuation
using DynamicPolynomials
using Random

# Set random seed 
Random.seed!(134)

@polyvar x[1:2]

# Function to generate a random polynomial with BigFloat coefficients
function random_polynomial(variables, degree::Int, num_terms::Int)
    polynomial = zero(BigFloat) # Initialize the polynomial with a BigFloat zero
    for _ in 1:num_terms
        coeff = BigFloat(rand(-10.0:0.1:10.0))
        powers = rand(0:degree, length(variables))
        monomial = prod(v^p for (v, p) in zip(variables, powers))
        polynomial += coeff * monomial
    end
    return polynomial
end

# Generate two random polynomials of degree 2 with 5 terms each
poly1 = random_polynomial(x, 4, 10) 
poly2 = poly1 + BigFloat(1.0) * x[1] + BigFloat(1.0) * x[2]

grad_p1 = differentiate.(poly1, x)
grad_p2 = differentiate.(poly2, x)

# Define the system of equations
system_1 = System(grad_p1)
system_2 = System(grad_p2)

# Solve the system
R1 = HomotopyContinuation.solve(system_1)
println("Result: ", R1)

R2 = HomotopyContinuation.solve(system_2)
println("Result: ", R2)

@PBrdng
Copy link
Collaborator

PBrdng commented Aug 7, 2024

Hi all,

all I can say is that we never tested against BigFloat. In principle, everything should be abstractified to an extend that allows any number type. But there is always a chance a bug slipped through. I think, one has to test all functions with BigFloat input to understasnd what goes wrong.

@gescholt Can you try @var instead of @polyvar ?

@gescholt
Copy link

gescholt commented Aug 7, 2024

@PBrdng @var gives the same output:

ERROR: MethodError: no method matching HomotopyContinuation.ToricHomotopy(::MixedSystem{(0xd448607d78e104ed, 1)}, ::Vector{Vector{Complex{BigFloat}}})

Closest candidates are:
  HomotopyContinuation.ToricHomotopy(::S, ::Vector{ComplexF64}, ::Vector{Float64}, ::Vector{Float64}, ::StructArrays.StructVector{ComplexF64, @NamedTuple{re::Vector{Float64}, im::Vector{Float64}}, Int64}, ::Vector{ComplexF64}, ::Vector{ComplexF64}, ::Vector{ComplexF64}, ::Base.RefValue{ComplexF64}, ::Base.RefValue{ComplexF64}, ::TaylorVector{5, ComplexF64}, ::TaylorVector{4, ComplexF64}, ::TaylorVector{3, ComplexF64}) where S<:AbstractSystem
   @ HomotopyContinuation ~/.julia/packages/HomotopyContinuation/NcbGJ/src/homotopies/toric_homotopy.jl:16
  HomotopyContinuation.ToricHomotopy(::AbstractSystem, ::Vector{Vector{ComplexF64}})
   @ HomotopyContinuation ~/.julia/packages/HomotopyContinuation/NcbGJ/src/homotopies/toric_homotopy.jl:37

@gescholt
Copy link

gescholt commented Aug 7, 2024

@PBrdng, switching the method to HomotopyContinuation.solve(system_2; start_system=:total_degree) indeed make the computation work.

@PBrdng
Copy link
Collaborator

PBrdng commented Aug 13, 2024

@PBrdng, switching the method to HomotopyContinuation.solve(system_2; start_system=:total_degree) indeed make the computation work.

Then, the problem is the overflow in the polyhedral homotopy.

It could be, though, that BigFloats are converted to usual floats in the implementation. Like I said, no one has ever tested this against BigFloats.

@saschatimme
Copy link
Member

Numerically we will not make use of any of the additional precision provided by big floats. So any fix would just truncate the coefficients .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants