Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 72.9% → 99.4%
Time: 24.4s
Alternatives: 8
Speedup: 0.4×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}} \end{array} \end{array} \]
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    t_0 = cos((k / 2.0d0))
    code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0))))
end
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0)));
end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 72.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}} \end{array} \end{array} \]
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    t_0 = cos((k / 2.0d0))
    code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0))))
end
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0)));
end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}}
\end{array}
\end{array}

Alternative 1: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U\_m}{t\_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;-U\_m\\ \mathbf{elif}\;t\_1 \leq 10^{+302}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{-2 \cdot J}}{\cos \left(K \cdot 0.5\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY))
     (- U_m)
     (if (<= t_1 1e+302)
       (*
        J
        (* (* -2.0 t_0) (hypot 1.0 (/ (/ U_m (* -2.0 J)) (cos (* K 0.5))))))
       U_m))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U_m;
	} else if (t_1 <= 1e+302) {
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / (-2.0 * J)) / cos((K * 0.5)))));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U_m;
	} else if (t_1 <= 1e+302) {
		tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / (-2.0 * J)) / Math.cos((K * 0.5)))));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U_m
	elif t_1 <= 1e+302:
		tmp = J * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / (-2.0 * J)) / math.cos((K * 0.5)))))
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U_m / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U_m);
	elseif (t_1 <= 1e+302)
		tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / Float64(-2.0 * J)) / cos(Float64(K * 0.5))))));
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U_m / (t_0 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U_m;
	elseif (t_1 <= 1e+302)
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / (-2.0 * J)) / cos((K * 0.5)))));
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U$95$m / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 1e+302], N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] / N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U$95$m]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U\_m}{t\_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;-U\_m\\

\mathbf{elif}\;t\_1 \leq 10^{+302}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{-2 \cdot J}}{\cos \left(K \cdot 0.5\right)}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < -inf.0

    1. Initial program 5.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified63.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 50.4%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-150.4%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified50.4%

      \[\leadsto \color{blue}{-U} \]

    if -inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < 1.0000000000000001e302

    1. Initial program 99.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.7%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. associate-/r*99.7%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)\right) \]
      2. associate-*l*99.7%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      3. add-cube-cbrt99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \sqrt[3]{U}}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      4. associate-/l*99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      5. pow299.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2}} \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      6. *-commutative99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\color{blue}{\cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot J\right)}}\right)\right) \]
      7. *-commutative99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(J \cdot 2\right)}}\right)\right) \]
      8. add-sqr-sqrt50.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}}\right)\right) \]
      9. div-inv50.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      10. metadata-eval50.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot \color{blue}{0.5}\right) \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      11. sqrt-unprod85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\sqrt{\left(J \cdot 2\right) \cdot \left(J \cdot 2\right)}}}\right)\right) \]
      12. swap-sqr85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot J\right) \cdot \left(2 \cdot 2\right)}}}\right)\right) \]
      13. metadata-eval85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{4}}}\right)\right) \]
      14. metadata-eval85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{\left(-2 \cdot -2\right)}}}\right)\right) \]
      15. swap-sqr85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot -2\right) \cdot \left(J \cdot -2\right)}}}\right)\right) \]
      16. *-commutative85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(-2 \cdot J\right)} \cdot \left(J \cdot -2\right)}}\right)\right) \]
      17. *-commutative85.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(-2 \cdot J\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}}\right)\right) \]
      18. sqrt-unprod48.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{-2 \cdot J} \cdot \sqrt{-2 \cdot J}\right)}}\right)\right) \]
      19. add-sqr-sqrt99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}\right)\right) \]
      20. *-commutative99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(J \cdot -2\right)}}\right)\right) \]
    5. Applied egg-rr99.2%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot -2\right)}}\right)\right) \]
    6. Step-by-step derivation
      1. associate-/r*99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \color{blue}{\frac{\frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      2. associate-*r/99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      3. associate-*l/99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      4. associate-*r/99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      5. associate-*l/99.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \sqrt[3]{U}}{J \cdot -2}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      6. unpow299.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right)} \cdot \sqrt[3]{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      7. rem-3cbrt-lft99.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      8. *-commutative99.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{\color{blue}{-2 \cdot J}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      9. *-commutative99.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{-2 \cdot J}}{\cos \color{blue}{\left(0.5 \cdot K\right)}}\right)\right) \]
    7. Simplified99.8%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{U}{-2 \cdot J}}{\cos \left(0.5 \cdot K\right)}}\right)\right) \]

    if 1.0000000000000001e302 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64)))))

    1. Initial program 4.7%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified61.8%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 51.5%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 10^{+302}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{-2 \cdot J}}{\cos \left(K \cdot 0.5\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 67.4% accurate, 0.6× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{if}\;t\_0 \leq -0.55:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq -0.25:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq 0.5:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 0.786:\\ \;\;\;\;-U\_m\\ \mathbf{elif}\;t\_0 \leq 0.998:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (* J (* (* -2.0 t_0) (+ 1.0 (* (* (/ U_m J) (/ U_m J)) 0.125))))))
   (if (<= t_0 -0.55)
     t_1
     (if (<= t_0 -0.25)
       U_m
       (if (<= t_0 0.5)
         t_1
         (if (<= t_0 0.786)
           (- U_m)
           (if (<= t_0 0.998)
             t_1
             (* J (* -2.0 (hypot 1.0 (* U_m (/ -0.5 J))))))))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.55) {
		tmp = t_1;
	} else if (t_0 <= -0.25) {
		tmp = U_m;
	} else if (t_0 <= 0.5) {
		tmp = t_1;
	} else if (t_0 <= 0.786) {
		tmp = -U_m;
	} else if (t_0 <= 0.998) {
		tmp = t_1;
	} else {
		tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.55) {
		tmp = t_1;
	} else if (t_0 <= -0.25) {
		tmp = U_m;
	} else if (t_0 <= 0.5) {
		tmp = t_1;
	} else if (t_0 <= 0.786) {
		tmp = -U_m;
	} else if (t_0 <= 0.998) {
		tmp = t_1;
	} else {
		tmp = J * (-2.0 * Math.hypot(1.0, (U_m * (-0.5 / J))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)))
	tmp = 0
	if t_0 <= -0.55:
		tmp = t_1
	elif t_0 <= -0.25:
		tmp = U_m
	elif t_0 <= 0.5:
		tmp = t_1
	elif t_0 <= 0.786:
		tmp = -U_m
	elif t_0 <= 0.998:
		tmp = t_1
	else:
		tmp = J * (-2.0 * math.hypot(1.0, (U_m * (-0.5 / J))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(J * Float64(Float64(-2.0 * t_0) * Float64(1.0 + Float64(Float64(Float64(U_m / J) * Float64(U_m / J)) * 0.125))))
	tmp = 0.0
	if (t_0 <= -0.55)
		tmp = t_1;
	elseif (t_0 <= -0.25)
		tmp = U_m;
	elseif (t_0 <= 0.5)
		tmp = t_1;
	elseif (t_0 <= 0.786)
		tmp = Float64(-U_m);
	elseif (t_0 <= 0.998)
		tmp = t_1;
	else
		tmp = Float64(J * Float64(-2.0 * hypot(1.0, Float64(U_m * Float64(-0.5 / J)))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	tmp = 0.0;
	if (t_0 <= -0.55)
		tmp = t_1;
	elseif (t_0 <= -0.25)
		tmp = U_m;
	elseif (t_0 <= 0.5)
		tmp = t_1;
	elseif (t_0 <= 0.786)
		tmp = -U_m;
	elseif (t_0 <= 0.998)
		tmp = t_1;
	else
		tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[(1.0 + N[(N[(N[(U$95$m / J), $MachinePrecision] * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.55], t$95$1, If[LessEqual[t$95$0, -0.25], U$95$m, If[LessEqual[t$95$0, 0.5], t$95$1, If[LessEqual[t$95$0, 0.786], (-U$95$m), If[LessEqual[t$95$0, 0.998], t$95$1, N[(J * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(-0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\
\mathbf{if}\;t\_0 \leq -0.55:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq -0.25:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 0.786:\\
\;\;\;\;-U\_m\\

\mathbf{elif}\;t\_0 \leq 0.998:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.55000000000000004 or -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.5 or 0.78600000000000003 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.998

    1. Initial program 71.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified88.1%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 67.0%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{0.5 \cdot \frac{U}{J}}\right)\right) \]
    5. Step-by-step derivation
      1. associate-*r/67.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{0.5 \cdot U}{J}}\right)\right) \]
      2. *-commutative67.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{U \cdot 0.5}}{J}\right)\right) \]
      3. associate-*r/67.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right) \]
    6. Simplified67.0%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right) \]
    7. Taylor expanded in U around 0 53.4%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(1 + 0.125 \cdot \frac{{U}^{2}}{{J}^{2}}\right)}\right) \]
    8. Step-by-step derivation
      1. *-commutative53.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\frac{{U}^{2}}{{J}^{2}} \cdot 0.125}\right)\right) \]
    9. Simplified53.4%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(1 + \frac{{U}^{2}}{{J}^{2}} \cdot 0.125\right)}\right) \]
    10. Step-by-step derivation
      1. unpow253.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \frac{\color{blue}{U \cdot U}}{{J}^{2}} \cdot 0.125\right)\right) \]
      2. unpow253.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \frac{U \cdot U}{\color{blue}{J \cdot J}} \cdot 0.125\right)\right) \]
      3. times-frac62.2%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.125\right)\right) \]
    11. Applied egg-rr62.2%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.125\right)\right) \]

    if -0.55000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25

    1. Initial program 57.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified78.7%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 34.9%

      \[\leadsto \color{blue}{U} \]

    if 0.5 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.78600000000000003

    1. Initial program 62.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified83.5%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 18.5%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-118.5%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified18.5%

      \[\leadsto \color{blue}{-U} \]

    if 0.998 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 71.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified90.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. associate-/r*90.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)\right) \]
      2. associate-*l*90.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      3. add-cube-cbrt89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \sqrt[3]{U}}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      4. associate-/l*89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      5. pow289.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2}} \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      6. *-commutative89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\color{blue}{\cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot J\right)}}\right)\right) \]
      7. *-commutative89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(J \cdot 2\right)}}\right)\right) \]
      8. add-sqr-sqrt42.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}}\right)\right) \]
      9. div-inv42.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      10. metadata-eval42.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot \color{blue}{0.5}\right) \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      11. sqrt-unprod69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\sqrt{\left(J \cdot 2\right) \cdot \left(J \cdot 2\right)}}}\right)\right) \]
      12. swap-sqr69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot J\right) \cdot \left(2 \cdot 2\right)}}}\right)\right) \]
      13. metadata-eval69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{4}}}\right)\right) \]
      14. metadata-eval69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{\left(-2 \cdot -2\right)}}}\right)\right) \]
      15. swap-sqr69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot -2\right) \cdot \left(J \cdot -2\right)}}}\right)\right) \]
      16. *-commutative69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(-2 \cdot J\right)} \cdot \left(J \cdot -2\right)}}\right)\right) \]
      17. *-commutative69.1%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(-2 \cdot J\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}}\right)\right) \]
      18. sqrt-unprod46.6%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{-2 \cdot J} \cdot \sqrt{-2 \cdot J}\right)}}\right)\right) \]
      19. add-sqr-sqrt89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}\right)\right) \]
      20. *-commutative89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(J \cdot -2\right)}}\right)\right) \]
    5. Applied egg-rr89.0%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot -2\right)}}\right)\right) \]
    6. Step-by-step derivation
      1. associate-/r*89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \color{blue}{\frac{\frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      2. associate-*r/89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      3. associate-*l/89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      4. associate-*r/89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      5. associate-*l/89.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \sqrt[3]{U}}{J \cdot -2}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      6. unpow289.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right)} \cdot \sqrt[3]{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      7. rem-3cbrt-lft90.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      8. *-commutative90.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{\color{blue}{-2 \cdot J}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      9. *-commutative90.0%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{-2 \cdot J}}{\cos \color{blue}{\left(0.5 \cdot K\right)}}\right)\right) \]
    7. Simplified90.0%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{U}{-2 \cdot J}}{\cos \left(0.5 \cdot K\right)}}\right)\right) \]
    8. Taylor expanded in K around 0 51.4%

      \[\leadsto J \cdot \color{blue}{\left(-2 \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
    9. Step-by-step derivation
      1. metadata-eval51.4%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{\color{blue}{1 \cdot 1} + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right) \]
      2. metadata-eval51.4%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(-0.5 \cdot -0.5\right)} \cdot \frac{{U}^{2}}{{J}^{2}}}\right) \]
      3. unpow251.4%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \frac{\color{blue}{U \cdot U}}{{J}^{2}}}\right) \]
      4. unpow251.4%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
      5. times-frac70.7%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]
      6. swap-sqr70.7%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(-0.5 \cdot \frac{U}{J}\right) \cdot \left(-0.5 \cdot \frac{U}{J}\right)}}\right) \]
      7. associate-*r/70.7%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\frac{-0.5 \cdot U}{J}} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      8. *-commutative70.7%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \frac{\color{blue}{U \cdot -0.5}}{J} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      9. associate-*r/70.6%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(U \cdot \frac{-0.5}{J}\right)} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      10. associate-*r/70.6%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \color{blue}{\frac{-0.5 \cdot U}{J}}}\right) \]
      11. *-commutative70.6%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \frac{\color{blue}{U \cdot -0.5}}{J}}\right) \]
      12. associate-*r/70.6%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \color{blue}{\left(U \cdot \frac{-0.5}{J}\right)}}\right) \]
      13. hypot-undefine89.4%

        \[\leadsto J \cdot \left(-2 \cdot \color{blue}{\mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)}\right) \]
    10. Simplified89.4%

      \[\leadsto J \cdot \color{blue}{\left(-2 \cdot \mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification70.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.55:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.25:\\ \;\;\;\;U\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.5:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.786:\\ \;\;\;\;-U\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.998:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 50.7% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq 1.5 \cdot 10^{-205}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J \cdot t\_0}\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= J 1.5e-205)
     (- U_m)
     (* J (* (* -2.0 t_0) (hypot 1.0 (/ (/ U_m 2.0) (* J t_0))))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (J <= 1.5e-205) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (J <= 1.5e-205) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if J <= 1.5e-205:
		tmp = -U_m
	else:
		tmp = J * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / 2.0) / (J * t_0))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (J <= 1.5e-205)
		tmp = Float64(-U_m);
	else
		tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J * t_0)))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (J <= 1.5e-205)
		tmp = -U_m;
	else
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, 1.5e-205], (-U$95$m), N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq 1.5 \cdot 10^{-205}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J \cdot t\_0}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 1.5e-205

    1. Initial program 65.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified82.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 27.5%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-127.5%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified27.5%

      \[\leadsto \color{blue}{-U} \]

    if 1.5e-205 < J

    1. Initial program 76.0%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified95.5%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification57.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 1.5 \cdot 10^{-205}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 45.3% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 6.4 \cdot 10^{-145}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 6.4e-145)
   (- U_m)
   (* J (* (* -2.0 (cos (/ K 2.0))) (hypot 1.0 (* U_m (/ 0.5 J)))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 6.4e-145) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J))));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 6.4e-145) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * Math.cos((K / 2.0))) * Math.hypot(1.0, (U_m * (0.5 / J))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 6.4e-145:
		tmp = -U_m
	else:
		tmp = J * ((-2.0 * math.cos((K / 2.0))) * math.hypot(1.0, (U_m * (0.5 / J))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 6.4e-145)
		tmp = Float64(-U_m);
	else
		tmp = Float64(J * Float64(Float64(-2.0 * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U_m * Float64(0.5 / J)))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 6.4e-145)
		tmp = -U_m;
	else
		tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, (U_m * (0.5 / J))));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 6.4e-145], (-U$95$m), N[(J * N[(N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 6.4 \cdot 10^{-145}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 6.40000000000000017e-145

    1. Initial program 61.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified80.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 29.2%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-129.2%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified29.2%

      \[\leadsto \color{blue}{-U} \]

    if 6.40000000000000017e-145 < J

    1. Initial program 83.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.7%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 83.7%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{0.5 \cdot \frac{U}{J}}\right)\right) \]
    5. Step-by-step derivation
      1. associate-*r/83.7%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{0.5 \cdot U}{J}}\right)\right) \]
      2. *-commutative83.7%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{U \cdot 0.5}}{J}\right)\right) \]
      3. associate-*r/83.6%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right) \]
    6. Simplified83.6%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 6.4 \cdot 10^{-145}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.0% accurate, 3.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 0.11:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\ \mathbf{elif}\;K \leq 6.2 \cdot 10^{+206} \lor \neg \left(K \leq 5 \cdot 10^{+261}\right) \land K \leq 2.02 \cdot 10^{+298}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= K 0.11)
   (* J (* -2.0 (hypot 1.0 (* U_m (/ -0.5 J)))))
   (if (or (<= K 6.2e+206) (and (not (<= K 5e+261)) (<= K 2.02e+298)))
     (* (* -2.0 J) (cos (* K 0.5)))
     U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 0.11) {
		tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
	} else if ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298))) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 0.11) {
		tmp = J * (-2.0 * Math.hypot(1.0, (U_m * (-0.5 / J))));
	} else if ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298))) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if K <= 0.11:
		tmp = J * (-2.0 * math.hypot(1.0, (U_m * (-0.5 / J))))
	elif (K <= 6.2e+206) or (not (K <= 5e+261) and (K <= 2.02e+298)):
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (K <= 0.11)
		tmp = Float64(J * Float64(-2.0 * hypot(1.0, Float64(U_m * Float64(-0.5 / J)))));
	elseif ((K <= 6.2e+206) || (!(K <= 5e+261) && (K <= 2.02e+298)))
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (K <= 0.11)
		tmp = J * (-2.0 * hypot(1.0, (U_m * (-0.5 / J))));
	elseif ((K <= 6.2e+206) || (~((K <= 5e+261)) && (K <= 2.02e+298)))
		tmp = (-2.0 * J) * cos((K * 0.5));
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[K, 0.11], N[(J * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(-0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[K, 6.2e+206], And[N[Not[LessEqual[K, 5e+261]], $MachinePrecision], LessEqual[K, 2.02e+298]]], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], U$95$m]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 0.11:\\
\;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{-0.5}{J}\right)\right)\\

\mathbf{elif}\;K \leq 6.2 \cdot 10^{+206} \lor \neg \left(K \leq 5 \cdot 10^{+261}\right) \land K \leq 2.02 \cdot 10^{+298}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;U\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if K < 0.110000000000000001

    1. Initial program 70.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified89.3%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. associate-/r*89.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}}\right)\right) \]
      2. associate-*l*89.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      3. add-cube-cbrt88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \sqrt[3]{U}}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      4. associate-/l*88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right) \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}\right)\right) \]
      5. pow288.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2}} \cdot \frac{\sqrt[3]{U}}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)\right) \]
      6. *-commutative88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\color{blue}{\cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot J\right)}}\right)\right) \]
      7. *-commutative88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(J \cdot 2\right)}}\right)\right) \]
      8. add-sqr-sqrt46.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}}\right)\right) \]
      9. div-inv46.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      10. metadata-eval46.8%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot \color{blue}{0.5}\right) \cdot \left(\sqrt{J \cdot 2} \cdot \sqrt{J \cdot 2}\right)}\right)\right) \]
      11. sqrt-unprod72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\sqrt{\left(J \cdot 2\right) \cdot \left(J \cdot 2\right)}}}\right)\right) \]
      12. swap-sqr72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot J\right) \cdot \left(2 \cdot 2\right)}}}\right)\right) \]
      13. metadata-eval72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{4}}}\right)\right) \]
      14. metadata-eval72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(J \cdot J\right) \cdot \color{blue}{\left(-2 \cdot -2\right)}}}\right)\right) \]
      15. swap-sqr72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(J \cdot -2\right) \cdot \left(J \cdot -2\right)}}}\right)\right) \]
      16. *-commutative72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\color{blue}{\left(-2 \cdot J\right)} \cdot \left(J \cdot -2\right)}}\right)\right) \]
      17. *-commutative72.3%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \sqrt{\left(-2 \cdot J\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}}\right)\right) \]
      18. sqrt-unprod41.7%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{-2 \cdot J} \cdot \sqrt{-2 \cdot J}\right)}}\right)\right) \]
      19. add-sqr-sqrt88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(-2 \cdot J\right)}}\right)\right) \]
      20. *-commutative88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \color{blue}{\left(J \cdot -2\right)}}\right)\right) \]
    5. Applied egg-rr88.5%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot -2\right)}}\right)\right) \]
    6. Step-by-step derivation
      1. associate-/r*88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, {\left(\sqrt[3]{U}\right)}^{2} \cdot \color{blue}{\frac{\frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      2. associate-*r/88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}{J \cdot -2}}\right)\right) \]
      3. associate-*l/88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \frac{\sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      4. associate-*r/88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{{\left(\sqrt[3]{U}\right)}^{2}}{J \cdot -2} \cdot \sqrt[3]{U}}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]
      5. associate-*l/88.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{\frac{{\left(\sqrt[3]{U}\right)}^{2} \cdot \sqrt[3]{U}}{J \cdot -2}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      6. unpow288.5%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{\left(\sqrt[3]{U} \cdot \sqrt[3]{U}\right)} \cdot \sqrt[3]{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      7. rem-3cbrt-lft89.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{\color{blue}{U}}{J \cdot -2}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      8. *-commutative89.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{\color{blue}{-2 \cdot J}}}{\cos \left(K \cdot 0.5\right)}\right)\right) \]
      9. *-commutative89.4%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{-2 \cdot J}}{\cos \color{blue}{\left(0.5 \cdot K\right)}}\right)\right) \]
    7. Simplified89.4%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{U}{-2 \cdot J}}{\cos \left(0.5 \cdot K\right)}}\right)\right) \]
    8. Taylor expanded in K around 0 36.2%

      \[\leadsto J \cdot \color{blue}{\left(-2 \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
    9. Step-by-step derivation
      1. metadata-eval36.2%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{\color{blue}{1 \cdot 1} + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right) \]
      2. metadata-eval36.2%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(-0.5 \cdot -0.5\right)} \cdot \frac{{U}^{2}}{{J}^{2}}}\right) \]
      3. unpow236.2%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \frac{\color{blue}{U \cdot U}}{{J}^{2}}}\right) \]
      4. unpow236.2%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
      5. times-frac49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(-0.5 \cdot -0.5\right) \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]
      6. swap-sqr49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(-0.5 \cdot \frac{U}{J}\right) \cdot \left(-0.5 \cdot \frac{U}{J}\right)}}\right) \]
      7. associate-*r/49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\frac{-0.5 \cdot U}{J}} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      8. *-commutative49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \frac{\color{blue}{U \cdot -0.5}}{J} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      9. associate-*r/49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(U \cdot \frac{-0.5}{J}\right)} \cdot \left(-0.5 \cdot \frac{U}{J}\right)}\right) \]
      10. associate-*r/49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \color{blue}{\frac{-0.5 \cdot U}{J}}}\right) \]
      11. *-commutative49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \frac{\color{blue}{U \cdot -0.5}}{J}}\right) \]
      12. associate-*r/49.1%

        \[\leadsto J \cdot \left(-2 \cdot \sqrt{1 \cdot 1 + \left(U \cdot \frac{-0.5}{J}\right) \cdot \color{blue}{\left(U \cdot \frac{-0.5}{J}\right)}}\right) \]
      13. hypot-undefine62.7%

        \[\leadsto J \cdot \left(-2 \cdot \color{blue}{\mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)}\right) \]
    10. Simplified62.7%

      \[\leadsto J \cdot \color{blue}{\left(-2 \cdot \mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)\right)} \]

    if 0.110000000000000001 < K < 6.19999999999999981e206 or 5.0000000000000001e261 < K < 2.01999999999999994e298

    1. Initial program 72.7%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified84.1%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 52.1%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    5. Step-by-step derivation
      1. associate-*r*52.1%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      2. *-commutative52.1%

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative52.1%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. *-commutative52.1%

        \[\leadsto \color{blue}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot -2\right)} \]
      5. *-commutative52.1%

        \[\leadsto \cos \color{blue}{\left(0.5 \cdot K\right)} \cdot \left(J \cdot -2\right) \]
      6. *-commutative52.1%

        \[\leadsto \cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(-2 \cdot J\right)} \]
    6. Simplified52.1%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)} \]

    if 6.19999999999999981e206 < K < 5.0000000000000001e261 or 2.01999999999999994e298 < K

    1. Initial program 39.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified82.4%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 36.9%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 0.11:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U \cdot \frac{-0.5}{J}\right)\right)\\ \mathbf{elif}\;K \leq 6.2 \cdot 10^{+206} \lor \neg \left(K \leq 5 \cdot 10^{+261}\right) \land K \leq 2.02 \cdot 10^{+298}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 38.9% accurate, 3.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 1.26 \cdot 10^{-56} \lor \neg \left(J \leq 1.16 \cdot 10^{-26}\right) \land J \leq 3.9 \cdot 10^{+43}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= J 1.26e-56) (and (not (<= J 1.16e-26)) (<= J 3.9e+43)))
   (- U_m)
   (* (* -2.0 J) (cos (* K 0.5)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43))) {
		tmp = -U_m;
	} else {
		tmp = (-2.0 * J) * cos((K * 0.5));
	}
	return tmp;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if ((j <= 1.26d-56) .or. (.not. (j <= 1.16d-26)) .and. (j <= 3.9d+43)) then
        tmp = -u_m
    else
        tmp = ((-2.0d0) * j) * cos((k * 0.5d0))
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43))) {
		tmp = -U_m;
	} else {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (J <= 1.26e-56) or (not (J <= 1.16e-26) and (J <= 3.9e+43)):
		tmp = -U_m
	else:
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((J <= 1.26e-56) || (!(J <= 1.16e-26) && (J <= 3.9e+43)))
		tmp = Float64(-U_m);
	else
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((J <= 1.26e-56) || (~((J <= 1.16e-26)) && (J <= 3.9e+43)))
		tmp = -U_m;
	else
		tmp = (-2.0 * J) * cos((K * 0.5));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[J, 1.26e-56], And[N[Not[LessEqual[J, 1.16e-26]], $MachinePrecision], LessEqual[J, 3.9e+43]]], (-U$95$m), N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 1.26 \cdot 10^{-56} \lor \neg \left(J \leq 1.16 \cdot 10^{-26}\right) \land J \leq 3.9 \cdot 10^{+43}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 1.26000000000000008e-56 or 1.16000000000000002e-26 < J < 3.9000000000000001e43

    1. Initial program 60.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified83.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 29.3%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-129.3%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified29.3%

      \[\leadsto \color{blue}{-U} \]

    if 1.26000000000000008e-56 < J < 1.16000000000000002e-26 or 3.9000000000000001e43 < J

    1. Initial program 93.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.7%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 71.6%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    5. Step-by-step derivation
      1. associate-*r*71.6%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      2. *-commutative71.6%

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative71.6%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. *-commutative71.6%

        \[\leadsto \color{blue}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot -2\right)} \]
      5. *-commutative71.6%

        \[\leadsto \cos \color{blue}{\left(0.5 \cdot K\right)} \cdot \left(J \cdot -2\right) \]
      6. *-commutative71.6%

        \[\leadsto \cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(-2 \cdot J\right)} \]
    6. Simplified71.6%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification41.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 1.26 \cdot 10^{-56} \lor \neg \left(J \leq 1.16 \cdot 10^{-26}\right) \land J \leq 3.9 \cdot 10^{+43}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 26.6% accurate, 59.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 2.9 \cdot 10^{+206}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 (if (<= K 2.9e+206) (- U_m) U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 2.9e+206) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (k <= 2.9d+206) then
        tmp = -u_m
    else
        tmp = u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 2.9e+206) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if K <= 2.9e+206:
		tmp = -U_m
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (K <= 2.9e+206)
		tmp = Float64(-U_m);
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (K <= 2.9e+206)
		tmp = -U_m;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[K, 2.9e+206], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 2.9 \cdot 10^{+206}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;U\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 2.9e206

    1. Initial program 71.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified88.1%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 24.8%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. neg-mul-124.8%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified24.8%

      \[\leadsto \color{blue}{-U} \]

    if 2.9e206 < K

    1. Initial program 49.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified87.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 27.4%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 2.9 \cdot 10^{+206}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 27.6% accurate, 420.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ U\_m \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 U_m)
U_m = fabs(U);
double code(double J, double K, double U_m) {
	return U_m;
}
U_m = abs(u)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    code = u_m
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	return U_m;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	return U_m
U_m = abs(U)
function code(J, K, U_m)
	return U_m
end
U_m = abs(U);
function tmp = code(J, K, U_m)
	tmp = U_m;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := U$95$m
\begin{array}{l}
U_m = \left|U\right|

\\
U\_m
\end{array}
Derivation
  1. Initial program 69.9%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Simplified88.0%

    \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in U around -inf 28.6%

    \[\leadsto \color{blue}{U} \]
  5. Final simplification28.6%

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024067 
(FPCore (J K U)
  :name "Maksimov and Kolovsky, Equation (3)"
  :precision binary64
  (* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))