Given the following two equations with three unknowns $\eta_1, \eta_2$ and $\tau$:
$\frac{i e^{-i \phi/2}}{\sqrt{2}} = \cos(2 \tau - \eta_1 -\eta_2)\cos(\eta_1-\eta_2) - i\sin(2 \tau - \eta_1-\eta_2)\sin(\eta_1+\eta_2)$
$\frac{i e^{i \phi/2}}{\sqrt{2}} = \cos(2 \tau - \eta_1 -\eta_2)\sin(\eta_1-\eta_2) + i\sin(2 \tau - \eta_1-\eta_2)\cos(\eta_1+\eta_2)$
I'm trying to write code that numerically searches for $\eta_1, \eta_2$ and $\tau$, each taken from $[0, 2\pi]$ but am getting errors (freezes basically). Please advise if there is a simpler way of doing this type of search as compared to what I have. My prototype code is as follows:
(*Define the system of equations for each equation independently*) equation1[eta1_, eta2_, tau_] := I Exp[-I phi/2]/ Sqrt[2] - (Cos[2 tau - eta1 - eta2] Cos[eta1 - eta2] + I Sin[2 tau - eta1 - eta2] Sin[eta1 + eta2]) equation2[eta1_, eta2_, tau_] := I Exp[I phi/2]/Sqrt[2] - (Cos[2 tau - eta1 - eta2] Sin[eta1 - eta2] - I Sin[2 tau - eta1 - eta2] Cos[eta1 + eta2]) (*Set the value of phi*) phi = 2.; (*This parameter is fixed*) (*Range for eta1,eta2,and tau*) eta1Values = Subdivide[0, 2 Pi, 1000]; eta2Values = Subdivide[0, 2 Pi, 1000]; tauValues = Subdivide[0, 2 Pi, 1000]; (*Iterate over all combinations of eta1,eta2,and tau*) Do[Do[Do[(*Use NSolve to find the roots for each equation*) solution1 = NSolve[{equation1[eta1, eta2, tau] == 0, 0 <= eta1 <= 2 Pi, 0 <= eta2 <= 2 Pi, 0 <= tau <= 2 Pi}, {eta1, eta2, tau}, Reals]; solution2 = NSolve[{equation2[eta1, eta2, tau] == 0, 0 <= eta1 <= 2 Pi, 0 <= eta2 <= 2 Pi, 0 <= tau <= 2 Pi}, {eta1, eta2, tau}, Reals]; (*Print the solutions*) If[Length[solution1] > 0, Print["Solution for equation 1: ", solution1]]; If[Length[solution2] > 0, Print["Solution for equation 2: ", solution2]];, {tau, tauValues}], {eta2, eta2Values}], {eta1, eta1Values}] The solution should exist based on the Solovay-Kitaev decomposition. More specifically based on Eqs. (13)-(15) of the following paper, where I assume $u:= \frac{i e^{-i \phi/2}}{\sqrt{2}}$ and $w:= \frac{i e^{i \phi/2}}{\sqrt{2}}$.
I think part of the problem is that because I'm are choosing discrete values from [0, 2 Pi, 1000], unlikely we will find perfect roots. Hence the equations will never be satisfied. I might have to add some kind of tolerance like NSolve[{equation1[eta1, eta2, tau] <= 0.001 instead of NSolve[{equation1[eta1, eta2, tau] == 0. I'm not sure if there is anything else dodgy but the code simply freezes when I run it. Any advice on how to improve the code would be most appreciated.