Solving many systems in a loop

What to do, if you have to solve system in a loop

Polynomial systems arising in application very often have a coefficients which are determined by some parameters.

We now want to show you how you can setup an efficient way to solve this polynomial system for many parameter values. Assume we have the following polynomial system:

using HomotopyContinuation
@var x y z p[1:3]

F = System(
[
x + 3 + 2y + 2y^2 - p,
(x - 2 + 5y) * z + 4 - p * z,
(x + 2 + 4y) * z + 5 - p * z,
];
parameters = p
)
System of length 3
3 variables: x, y, z
3 parameters: p₁, p₂, p₃

3 - p₁ + x + 2*y + 2*y^2
4 - z*p₂ + z*(-2 + x + 5*y)
5 - z*p₃ + z*(2 + x + 4*y)

First, we compute the solutions for generic parameters and then use a parameter homotopy.

# Generate generic parameters by sampling complex numbers from the normal distribution
p₀ = randn(ComplexF64, 3)
# Compute all solutions for F_p₀
result_p₀ = solve(F, target_parameters = p₀)
Result with 2 solutions
=======================
• 2 paths tracked
• 2 non-singular solutions (0 real)
• random_seed: 0x3f556de6
• start_system: :polyhedral

We see that our polynomial system $F$ has at most 2 isolated solutions. The idea is to use these two generic solutions to find the solutions for the specific parameters we are interested in. For this we are using a parameter homotopy from the generic parameters $p_0$ to the specific parameters.

This can be done as follows:

# generate some random data to simulate the parameters
data = [randn(3) for _ in 1:10_000]

# track p₀ towards the entries of data
data_points = solve(
F,
solutions(result_p₀);
start_parameters =  p₀,
target_parameters = data
)

It is also possible to immediately post-process the output. For instance, suppose that we are only interested in the real solutions. Then:

This can be done as follows:

data_points = solve(
F,
solutions(result_p₀);
start_parameters =  p₀,
target_parameters = data,
transform_result = (r,p) -> real_solutions(r),
flatten = true
)
{"ft_lang_label":"__label__en","ft_lang_prob":0.7070561,"math_prob":0.9985111,"size":1910,"snap":"2022-05-2022-21","text_gpt3_token_len":541,"char_repetition_ratio":0.16316894,"word_repetition_ratio":0.047477745,"special_character_ratio":0.3052356,"punctuation_ratio":0.11461318,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9985327,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-27T02:57:00Z\",\"WARC-Record-ID\":\"<urn:uuid:8797fd04-f8ad-43bb-96c2-e5b447611c83>\",\"Content-Length\":\"13224\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d2ab6ac8-b57c-4d37-936e-c4ad8097a70d>\",\"WARC-Concurrent-To\":\"<urn:uuid:fc4a8ddd-59b9-4305-97fd-2b8e05477e6b>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://www.juliahomotopycontinuation.org/guides/many-systems/\",\"WARC-Payload-Digest\":\"sha1:EBXD4BSBOTVIJCJ7DRPQWEJE6MLEHLYF\",\"WARC-Block-Digest\":\"sha1:35BI4RHYX4HCWUSBNS37GFWFNOKQ7VU5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320305052.56_warc_CC-MAIN-20220127012750-20220127042750-00644.warc.gz\"}"}