2
$\begingroup$

I was running the following code

pts = {-0.0002982071829578971`, 0.0020978674014467125`, 0.00454757795374431`, -0.00040056752260654235`, \
   -0.007366648883367612`, 0.007300363592367062`, 0.003436765849222534`, 
   0.001474610688815707`, -0.00604661411313466`, 0.0025407914514535765`};
xs = Cos[pts];
ys = Sin[pts];
fi = FindInstance[{ Cos[t1] + Cos[t2] == 2 Mean[xs],
        Sin[t1] + Sin[t2] == 2 Mean[ys],
        -0.01 <= t1 <= 0.01, -0.01 <= t2 <= 0.01
       }, {t1, t2}, Reals]

Mathematica 13.0.1 returns the following result

{{t1 -> 1. (1. Root[{{Cos[1. (1. #1^2 - 0.01)] + 
            Cos[1. (1. #3^2 - 0.01)] - 1.9999810103927544 &, 
          Sin[1. (1. #1^2 - 0.01)] + Sin[1. (1. #3^2 - 0.01)] - 
            0.0014571901262632012 &, 1. #1^2 + 1. #2^2 - 0.02 &, 
          1. #3^2 + 1. #4^2 - 0.02 &}, {0.0802012, -0.1164808, 
          0.1225764, -0.0705339}}, 1]^2 - 0.01), 
  t2 -> 1. (1. Root[{{Cos[1. (1. #1^2 - 0.01)] + 
            Cos[1. (1. #3^2 - 0.01)] - 1.9999810103927544 &, 
          Sin[1. (1. #1^2 - 0.01)] + Sin[1. (1. #3^2 - 0.01)] - 
            0.0014571901262632012 &, 1. #1^2 + 1. #2^2 - 0.02 &, 
          1. #3^2 + 1. #4^2 - 0.02 &}, {0.0802012, -0.1164808, 
          0.1225764, -0.0705339}}, 3]^2 - 0.01)}}

with the Root[] functions displayed as red boxes with error messages Mathematica output

An unknown box name (ElisionsDump`toNumericalEllipsisedForm) was sent as the BoxForm for the expression. Check the format rules for the expression.

In the meanwhile, it is easy to find solutions to the equations using FindRoot as

In[127]:= fi = FindRoot[{Cos[t1] + Cos[t2] == 2 Mean[xs],
      Sin[t1] + Sin[t2] == 2 Mean[ys]
    }, {{t1, 0.01/2}, {t2, -0.01/2}}]]

Out[127]= {t1 -> 0.00502497, t2 -> -0.00356777}

The values of t_1 and t_2 are contained within $[-0.01,0.01]$. FindInstance could have found this.

I'd like to ask why FindInstance returns Root[] that cannot be evaluated, even numerically. Is this a bug? Is it possible to fix the issue using FindInstance? (It is also a bit surprising to me that FindInstance seems to use some symbolic computation internally.)

I am sorry that I do not have a smaller example -- I generated random points in pts and ran the code several times before I encountered the problem. I do not know of a pattern of pts that would trigger this problem.

$\endgroup$
3
  • $\begingroup$ pts = Rationalize[pts, 0]; $\endgroup$
    – cvgmt
    May 2, 2022 at 1:47
  • $\begingroup$ NSolve[Rationalize[{Cos[t1] + Cos[t2] == 2 Mean[xs], Sin[t1] + Sin[t2] == 2 Mean[ys], -0.01 <= t1 <= 0.01, -0.01 <= t2 <= 0.01}, 0], {t1, t2}] $\endgroup$
    – cvgmt
    May 2, 2022 at 1:58
  • 1
    $\begingroup$ I think this is a bug. Please report it to: [email protected] $\endgroup$ May 2, 2022 at 6:53

1 Answer 1

3
$\begingroup$

FindInstance is symbolic so it work with precise values.

Use Rationalize[#,0]&

FindInstance[
 Rationalize[{Cos[t1] + Cos[t2] == 2 Mean[xs], 
   Sin[t1] + Sin[t2] == 2 Mean[ys], -0.01 <= t1 <= 0.01, -0.01 <= t2 <=
     0.01}, 0], {t1, t2}, Reals]

enter image description here

Also work in Solve.

Solve[Rationalize[{Cos[t1] + Cos[t2] == 2 Mean[xs], 
   Sin[t1] + Sin[t2] == 2 Mean[ys], -0.01 <= t1 <= 0.01, -0.01 <= t2 <=
     0.01}, 0], {t1, t2}, Reals]
$\endgroup$
2
  • $\begingroup$ Thanks! However, it seems to me that rationalizing the expression sometimes causes FindInstance to become slower and return highly complicated expressions for the variables, and in such cases, FindInstance can return the answer very quickly without rationalization. Do you know how to resolve this? $\endgroup$
    – user58955
    May 2, 2022 at 5:33
  • 1
    $\begingroup$ Your claim "FindInstance is symbolic so it work with precise values" does not correspond to reality in view of FindInstance[Sin[x] == 0.4, x,Reals] which results in {{x -> -12.1549}}. $\endgroup$
    – user64494
    May 2, 2022 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.