JuliaHomotopyContinuation / HomotopyContinuation.jl

A Julia package for solving systems of polynomials via homotopy continuation.
https://www.JuliaHomotopyContinuation.org
MIT License
178 stars 30 forks source link

e not defined for sqrt() #518

Open harrybooth opened 1 year ago

harrybooth commented 1 year ago

Hi

@var x y a b F = System([sqrt(x^2 - a), x * y - a + b]; variables=[x,y], parameters =[a,b]) solve(F, target_parameters=[2, 5])

produces the error

UndefVarError: e not defined

I believe it is the sqrt() which is causing the issue.

saschatimme commented 1 year ago
  1. we can only solve polynomial system, so the square root is not allowed
  2. Your system has the same zeros if you just omit the sqrt :)
harrybooth commented 1 year ago

Hi,

Thanks for the reply @saschatimme .

Regarding 1) - I thought in this issue: https://github.com/JuliaHomotopyContinuation/HomotopyContinuation.jl/issues/498 it was stated that there was support for sqrt on main?

No this is unfortunately not so straightforward. We internally have a fairly complex system for the evaluation of systems where the input are taylor polynomials. We need this for the predictor step to compute higher order derivatives of x(t). See Chapter 13 of Evaluating Derivatives from Griewank and Walther.

On the main branch we have already support for sqrt but not for general real powers. For this we need to first implement the taylor polynomial expansions of exp and log since you can rewrite x^a as exp(a * log(x)) and reuse the exp and log primitives. Here are the recursive relationships for exp and log (p. 306)

Screenshot 2022-10-19 at 21 30 11

If somebody is interested in giving this a shot I can also provide more guidance.

and re 2) - Yes true, although I was just providing a minimal example to show the error. My actual system is more complex..

saschatimme commented 1 year ago

Regarding 1) - I thought in this issue: https://github.com/JuliaHomotopyContinuation/HomotopyContinuation.jl/issues/498 it was stated that there was support for sqrt on main?

Mhm maybe there is a bug then. I will look more into this over the weekend. As for whether you can use sqrt or not: Our math only works when sqrt is used for parameters. So no variables inside sqrt allowed.

harrybooth commented 1 year ago

Suppose I can rearrange my system so that the square roots are on one side of the equation, is it valid in general to square both sides and solve the new system using homotopy continuation methods? I really need to solve a system where the variables sit inside the square root and this is the only way I can think of, but I'm not sure if its valid...

saschatimme commented 1 year ago

I think this should be a valid way to rewrite the system. A more general way of rewriting a system with a sqrt is the following pattern:

Starting from

f(x) + sqrt(g(x)) = 0

add one additional variable y and write the system

f(x) + a = 0
a^2 = g(x)

Your approach as well as mine both increases the number of solution but this is unavoidable.

I wrote some time ago a paper where the true problem also had a sqrt in it's formulation. Maybe the general techniques used there can be useful for you https://arxiv.org/pdf/2009.13408.pdf

Otherwise, if you can share more about your problem (here or via email) with me or @PBrdng, then we can maybe give more concrete advice. We are both always happy to learn about applications of HC :)

harrybooth commented 1 year ago

Sure, would be great to discuss with you. I will send you an email to sascha@timme.xyz ?