Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 72.8% → 99.3%
Time: 24.9s
Alternatives: 12
Speedup: 1.9×

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 12 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.8% 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.3% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+295}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 5.4%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 40.4%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified40.4%

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

    if -inf.0 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < 2e295

    1. Initial program 99.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. Add Preprocessing

    if 2e295 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 7.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. Add Preprocessing
    3. Taylor expanded in J around 0 57.9%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified57.9%

      \[\leadsto \color{blue}{-U} \]
    6. Step-by-step derivation
      1. neg-sub057.9%

        \[\leadsto \color{blue}{0 - U} \]
      2. sub-neg57.9%

        \[\leadsto \color{blue}{0 + \left(-U\right)} \]
      3. add-sqr-sqrt57.0%

        \[\leadsto 0 + \color{blue}{\sqrt{-U} \cdot \sqrt{-U}} \]
      4. sqrt-unprod50.7%

        \[\leadsto 0 + \color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}} \]
      5. sqr-neg50.7%

        \[\leadsto 0 + \sqrt{\color{blue}{U \cdot U}} \]
      6. sqrt-unprod40.0%

        \[\leadsto 0 + \color{blue}{\sqrt{U} \cdot \sqrt{U}} \]
      7. add-sqr-sqrt40.9%

        \[\leadsto 0 + \color{blue}{U} \]
    7. Applied egg-rr40.9%

      \[\leadsto \color{blue}{0 + U} \]
    8. Step-by-step derivation
      1. +-lft-identity40.9%

        \[\leadsto \color{blue}{U} \]
    9. Simplified40.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\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(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 2 \cdot 10^{+295}:\\ \;\;\;\;\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 69.6% accurate, 0.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := \cos \left(\frac{K}{2}\right)\\ J\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -0.9956:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_1 \leq -0.5:\\ \;\;\;\;t\_0 \cdot \left(-2 \cdot J\_m\right)\\ \mathbf{elif}\;t\_1 \leq -0.05:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_1 \leq 0.86:\\ \;\;\;\;-2 \cdot \frac{{\left(J\_m \cdot t\_0\right)}^{2}}{U\_m} - U\_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J\_m \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J\_m}\right)\right)\\ \end{array} \end{array} \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))) (t_1 (cos (/ K 2.0))))
   (*
    J_s
    (if (<= t_1 -0.9956)
      U_m
      (if (<= t_1 -0.5)
        (* t_0 (* -2.0 J_m))
        (if (<= t_1 -0.05)
          U_m
          (if (<= t_1 0.86)
            (- (* -2.0 (/ (pow (* J_m t_0) 2.0) U_m)) U_m)
            (* -2.0 (* J_m (hypot 1.0 (* 0.5 (/ U_m J_m))))))))))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	double t_0 = cos((K * 0.5));
	double t_1 = cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.9956) {
		tmp = U_m;
	} else if (t_1 <= -0.5) {
		tmp = t_0 * (-2.0 * J_m);
	} else if (t_1 <= -0.05) {
		tmp = U_m;
	} else if (t_1 <= 0.86) {
		tmp = (-2.0 * (pow((J_m * t_0), 2.0) / U_m)) - U_m;
	} else {
		tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m))));
	}
	return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.9956) {
		tmp = U_m;
	} else if (t_1 <= -0.5) {
		tmp = t_0 * (-2.0 * J_m);
	} else if (t_1 <= -0.05) {
		tmp = U_m;
	} else if (t_1 <= 0.86) {
		tmp = (-2.0 * (Math.pow((J_m * t_0), 2.0) / U_m)) - U_m;
	} else {
		tmp = -2.0 * (J_m * Math.hypot(1.0, (0.5 * (U_m / J_m))));
	}
	return J_s * tmp;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	t_0 = math.cos((K * 0.5))
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if t_1 <= -0.9956:
		tmp = U_m
	elif t_1 <= -0.5:
		tmp = t_0 * (-2.0 * J_m)
	elif t_1 <= -0.05:
		tmp = U_m
	elif t_1 <= 0.86:
		tmp = (-2.0 * (math.pow((J_m * t_0), 2.0) / U_m)) - U_m
	else:
		tmp = -2.0 * (J_m * math.hypot(1.0, (0.5 * (U_m / J_m))))
	return J_s * tmp
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	t_0 = cos(Float64(K * 0.5))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_1 <= -0.9956)
		tmp = U_m;
	elseif (t_1 <= -0.5)
		tmp = Float64(t_0 * Float64(-2.0 * J_m));
	elseif (t_1 <= -0.05)
		tmp = U_m;
	elseif (t_1 <= 0.86)
		tmp = Float64(Float64(-2.0 * Float64((Float64(J_m * t_0) ^ 2.0) / U_m)) - U_m);
	else
		tmp = Float64(-2.0 * Float64(J_m * hypot(1.0, Float64(0.5 * Float64(U_m / J_m)))));
	end
	return Float64(J_s * tmp)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp_2 = code(J_s, J_m, K, U_m)
	t_0 = cos((K * 0.5));
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (t_1 <= -0.9956)
		tmp = U_m;
	elseif (t_1 <= -0.5)
		tmp = t_0 * (-2.0 * J_m);
	elseif (t_1 <= -0.05)
		tmp = U_m;
	elseif (t_1 <= 0.86)
		tmp = (-2.0 * (((J_m * t_0) ^ 2.0) / U_m)) - U_m;
	else
		tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m))));
	end
	tmp_2 = J_s * tmp;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(J$95$s * If[LessEqual[t$95$1, -0.9956], U$95$m, If[LessEqual[t$95$1, -0.5], N[(t$95$0 * N[(-2.0 * J$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.05], U$95$m, If[LessEqual[t$95$1, 0.86], N[(N[(-2.0 * N[(N[Power[N[(J$95$m * t$95$0), $MachinePrecision], 2.0], $MachinePrecision] / U$95$m), $MachinePrecision]), $MachinePrecision] - U$95$m), $MachinePrecision], N[(-2.0 * N[(J$95$m * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]]]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := \cos \left(\frac{K}{2}\right)\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -0.9956:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_1 \leq -0.5:\\
\;\;\;\;t\_0 \cdot \left(-2 \cdot J\_m\right)\\

\mathbf{elif}\;t\_1 \leq -0.05:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_1 \leq 0.86:\\
\;\;\;\;-2 \cdot \frac{{\left(J\_m \cdot t\_0\right)}^{2}}{U\_m} - U\_m\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.99560000000000004 or -0.5 < (cos.f64 (/.f64 K 2)) < -0.050000000000000003

    1. Initial program 63.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. Add Preprocessing
    3. Taylor expanded in J around 0 39.9%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified39.9%

      \[\leadsto \color{blue}{-U} \]
    6. Step-by-step derivation
      1. neg-sub039.9%

        \[\leadsto \color{blue}{0 - U} \]
      2. sub-neg39.9%

        \[\leadsto \color{blue}{0 + \left(-U\right)} \]
      3. add-sqr-sqrt19.9%

        \[\leadsto 0 + \color{blue}{\sqrt{-U} \cdot \sqrt{-U}} \]
      4. sqrt-unprod10.9%

        \[\leadsto 0 + \color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}} \]
      5. sqr-neg10.9%

        \[\leadsto 0 + \sqrt{\color{blue}{U \cdot U}} \]
      6. sqrt-unprod15.7%

        \[\leadsto 0 + \color{blue}{\sqrt{U} \cdot \sqrt{U}} \]
      7. add-sqr-sqrt39.4%

        \[\leadsto 0 + \color{blue}{U} \]
    7. Applied egg-rr39.4%

      \[\leadsto \color{blue}{0 + U} \]
    8. Step-by-step derivation
      1. +-lft-identity39.4%

        \[\leadsto \color{blue}{U} \]
    9. Simplified39.4%

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

    if -0.99560000000000004 < (cos.f64 (/.f64 K 2)) < -0.5

    1. Initial program 79.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. Add Preprocessing
    3. Taylor expanded in J around inf 63.6%

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

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

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

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

    if -0.050000000000000003 < (cos.f64 (/.f64 K 2)) < 0.859999999999999987

    1. Initial program 56.4%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 39.3%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg39.3%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative39.3%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow239.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative39.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow239.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr39.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow239.3%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative39.3%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified39.3%

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

    if 0.859999999999999987 < (cos.f64 (/.f64 K 2))

    1. Initial program 72.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. Simplified87.5%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right)\right) \]
    7. Step-by-step derivation
      1. add-log-exp8.0%

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

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

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

        \[\leadsto -2 \cdot \log \left({\left(e^{\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)}\right)}^{J}\right) \]
      5. metadata-eval5.7%

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

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

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

        \[\leadsto -2 \cdot \log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \color{blue}{\frac{U}{\frac{J}{0.5}}}\right)\right)}\right)}^{J}\right) \]
      9. div-inv5.7%

        \[\leadsto -2 \cdot \log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \frac{U}{\color{blue}{J \cdot \frac{1}{0.5}}}\right)\right)}\right)}^{J}\right) \]
      10. metadata-eval5.7%

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

      \[\leadsto -2 \cdot \color{blue}{\log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)}\right)}^{J}\right)} \]
    9. Step-by-step derivation
      1. log-pow49.7%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \left(\mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right) \cdot \log \left(e^{\cos \left(K \cdot 0.5\right)}\right)\right)\right) \]
    10. Simplified82.2%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 69.5% accurate, 0.8× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ J\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -0.9956:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq -0.5:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\_m\right)\\ \mathbf{elif}\;t\_0 \leq -0.05:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq 0.86:\\ \;\;\;\;\frac{-2 \cdot {J\_m}^{2}}{U\_m} - U\_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J\_m \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J\_m}\right)\right)\\ \end{array} \end{array} \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (*
    J_s
    (if (<= t_0 -0.9956)
      U_m
      (if (<= t_0 -0.5)
        (* (cos (* K 0.5)) (* -2.0 J_m))
        (if (<= t_0 -0.05)
          U_m
          (if (<= t_0 0.86)
            (- (/ (* -2.0 (pow J_m 2.0)) U_m) U_m)
            (* -2.0 (* J_m (hypot 1.0 (* 0.5 (/ U_m J_m))))))))))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.9956) {
		tmp = U_m;
	} else if (t_0 <= -0.5) {
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	} else if (t_0 <= -0.05) {
		tmp = U_m;
	} else if (t_0 <= 0.86) {
		tmp = ((-2.0 * pow(J_m, 2.0)) / U_m) - U_m;
	} else {
		tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m))));
	}
	return J_s * tmp;
}
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.9956) {
		tmp = U_m;
	} else if (t_0 <= -0.5) {
		tmp = Math.cos((K * 0.5)) * (-2.0 * J_m);
	} else if (t_0 <= -0.05) {
		tmp = U_m;
	} else if (t_0 <= 0.86) {
		tmp = ((-2.0 * Math.pow(J_m, 2.0)) / U_m) - U_m;
	} else {
		tmp = -2.0 * (J_m * Math.hypot(1.0, (0.5 * (U_m / J_m))));
	}
	return J_s * tmp;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= -0.9956:
		tmp = U_m
	elif t_0 <= -0.5:
		tmp = math.cos((K * 0.5)) * (-2.0 * J_m)
	elif t_0 <= -0.05:
		tmp = U_m
	elif t_0 <= 0.86:
		tmp = ((-2.0 * math.pow(J_m, 2.0)) / U_m) - U_m
	else:
		tmp = -2.0 * (J_m * math.hypot(1.0, (0.5 * (U_m / J_m))))
	return J_s * tmp
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= -0.9956)
		tmp = U_m;
	elseif (t_0 <= -0.5)
		tmp = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J_m));
	elseif (t_0 <= -0.05)
		tmp = U_m;
	elseif (t_0 <= 0.86)
		tmp = Float64(Float64(Float64(-2.0 * (J_m ^ 2.0)) / U_m) - U_m);
	else
		tmp = Float64(-2.0 * Float64(J_m * hypot(1.0, Float64(0.5 * Float64(U_m / J_m)))));
	end
	return Float64(J_s * tmp)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp_2 = code(J_s, J_m, K, U_m)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (t_0 <= -0.9956)
		tmp = U_m;
	elseif (t_0 <= -0.5)
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	elseif (t_0 <= -0.05)
		tmp = U_m;
	elseif (t_0 <= 0.86)
		tmp = ((-2.0 * (J_m ^ 2.0)) / U_m) - U_m;
	else
		tmp = -2.0 * (J_m * hypot(1.0, (0.5 * (U_m / J_m))));
	end
	tmp_2 = J_s * tmp;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(J$95$s * If[LessEqual[t$95$0, -0.9956], U$95$m, If[LessEqual[t$95$0, -0.5], N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.05], U$95$m, If[LessEqual[t$95$0, 0.86], N[(N[(N[(-2.0 * N[Power[J$95$m, 2.0], $MachinePrecision]), $MachinePrecision] / U$95$m), $MachinePrecision] - U$95$m), $MachinePrecision], N[(-2.0 * N[(J$95$m * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -0.9956:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_0 \leq -0.5:\\
\;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\_m\right)\\

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

\mathbf{elif}\;t\_0 \leq 0.86:\\
\;\;\;\;\frac{-2 \cdot {J\_m}^{2}}{U\_m} - U\_m\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.99560000000000004 or -0.5 < (cos.f64 (/.f64 K 2)) < -0.050000000000000003

    1. Initial program 63.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. Add Preprocessing
    3. Taylor expanded in J around 0 39.9%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified39.9%

      \[\leadsto \color{blue}{-U} \]
    6. Step-by-step derivation
      1. neg-sub039.9%

        \[\leadsto \color{blue}{0 - U} \]
      2. sub-neg39.9%

        \[\leadsto \color{blue}{0 + \left(-U\right)} \]
      3. add-sqr-sqrt19.9%

        \[\leadsto 0 + \color{blue}{\sqrt{-U} \cdot \sqrt{-U}} \]
      4. sqrt-unprod10.9%

        \[\leadsto 0 + \color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}} \]
      5. sqr-neg10.9%

        \[\leadsto 0 + \sqrt{\color{blue}{U \cdot U}} \]
      6. sqrt-unprod15.7%

        \[\leadsto 0 + \color{blue}{\sqrt{U} \cdot \sqrt{U}} \]
      7. add-sqr-sqrt39.4%

        \[\leadsto 0 + \color{blue}{U} \]
    7. Applied egg-rr39.4%

      \[\leadsto \color{blue}{0 + U} \]
    8. Step-by-step derivation
      1. +-lft-identity39.4%

        \[\leadsto \color{blue}{U} \]
    9. Simplified39.4%

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

    if -0.99560000000000004 < (cos.f64 (/.f64 K 2)) < -0.5

    1. Initial program 79.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. Add Preprocessing
    3. Taylor expanded in J around inf 63.6%

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

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

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

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

    if -0.050000000000000003 < (cos.f64 (/.f64 K 2)) < 0.859999999999999987

    1. Initial program 56.4%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 39.3%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg39.3%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative39.3%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow239.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative39.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow239.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr39.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow239.3%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative39.3%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified39.3%

      \[\leadsto \color{blue}{\frac{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}{U} \cdot -2 - U} \]
    6. Taylor expanded in K around 0 39.3%

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U}} - U \]
    7. Step-by-step derivation
      1. associate-*r/39.3%

        \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]
    8. Simplified39.3%

      \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]

    if 0.859999999999999987 < (cos.f64 (/.f64 K 2))

    1. Initial program 72.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. Simplified87.5%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right)\right)\right) \]
    7. Step-by-step derivation
      1. add-log-exp8.0%

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

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

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

        \[\leadsto -2 \cdot \log \left({\left(e^{\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)}\right)}^{J}\right) \]
      5. metadata-eval5.7%

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

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

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

        \[\leadsto -2 \cdot \log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \color{blue}{\frac{U}{\frac{J}{0.5}}}\right)\right)}\right)}^{J}\right) \]
      9. div-inv5.7%

        \[\leadsto -2 \cdot \log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \frac{U}{\color{blue}{J \cdot \frac{1}{0.5}}}\right)\right)}\right)}^{J}\right) \]
      10. metadata-eval5.7%

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

      \[\leadsto -2 \cdot \color{blue}{\log \left({\left({\left(e^{\cos \left(K \cdot 0.5\right)}\right)}^{\left(\mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)}\right)}^{J}\right)} \]
    9. Step-by-step derivation
      1. log-pow49.7%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \left(\mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right) \cdot \log \left(e^{\cos \left(K \cdot 0.5\right)}\right)\right)\right) \]
    10. Simplified82.2%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 88.9% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J\_m \cdot \cos \left(K \cdot 0.5\right)\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 1.06 \cdot 10^{-274}:\\
\;\;\;\;-2 \cdot \left(t\_1 \cdot \frac{t\_1}{U\_m}\right) - U\_m\\

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


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

    1. Initial program 65.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 32.8%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg32.8%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative32.8%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow232.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative32.8%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow232.8%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr32.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow232.8%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative32.8%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified32.8%

      \[\leadsto \color{blue}{\frac{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}{U} \cdot -2 - U} \]
    6. Step-by-step derivation
      1. unpow232.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)}}{U} \cdot -2 - U \]
      2. associate-/l*34.6%

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

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

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

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

        \[\leadsto \left(\left(\cos \left(K \cdot 0.5\right) \cdot J\right) \cdot \frac{\cos \color{blue}{\left(K \cdot 0.5\right)} \cdot J}{U}\right) \cdot -2 - U \]
    7. Applied egg-rr34.6%

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

    if 1.05999999999999997e-274 < J

    1. Initial program 76.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. Simplified93.5%

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

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

Alternative 5: 89.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J\_m \cdot \cos \left(K \cdot 0.5\right)\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 2.9 \cdot 10^{-275}:\\
\;\;\;\;-2 \cdot \left(t\_1 \cdot \frac{t\_1}{U\_m}\right) - U\_m\\

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


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

    1. Initial program 65.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 32.8%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg32.8%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative32.8%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow232.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative32.8%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow232.8%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr32.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow232.8%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative32.8%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified32.8%

      \[\leadsto \color{blue}{\frac{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}{U} \cdot -2 - U} \]
    6. Step-by-step derivation
      1. unpow232.8%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)}}{U} \cdot -2 - U \]
      2. associate-/l*34.6%

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

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

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

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

        \[\leadsto \left(\left(\cos \left(K \cdot 0.5\right) \cdot J\right) \cdot \frac{\cos \color{blue}{\left(K \cdot 0.5\right)} \cdot J}{U}\right) \cdot -2 - U \]
    7. Applied egg-rr34.6%

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

    if 2.9e-275 < J

    1. Initial program 76.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. Simplified93.6%

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

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

Alternative 6: 77.6% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := J\_m \cdot \cos \left(K \cdot 0.5\right)\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 1.2 \cdot 10^{-106}:\\
\;\;\;\;-2 \cdot \left(t\_0 \cdot \frac{t\_0}{U\_m}\right) - U\_m\\

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


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

    1. Initial program 60.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. Add Preprocessing
    3. Taylor expanded in J around 0 35.5%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg35.5%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative35.5%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow235.5%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative35.5%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow235.5%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr35.5%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow235.5%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative35.5%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified35.5%

      \[\leadsto \color{blue}{\frac{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}{U} \cdot -2 - U} \]
    6. Step-by-step derivation
      1. unpow235.5%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)}}{U} \cdot -2 - U \]
      2. associate-/l*37.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \frac{J \cdot \cos \left(0.5 \cdot K\right)}{U}\right)} \cdot -2 - U \]
      3. *-commutative37.0%

        \[\leadsto \left(\color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot J\right)} \cdot \frac{J \cdot \cos \left(0.5 \cdot K\right)}{U}\right) \cdot -2 - U \]
      4. *-commutative37.0%

        \[\leadsto \left(\left(\cos \color{blue}{\left(K \cdot 0.5\right)} \cdot J\right) \cdot \frac{J \cdot \cos \left(0.5 \cdot K\right)}{U}\right) \cdot -2 - U \]
      5. *-commutative37.0%

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

        \[\leadsto \left(\left(\cos \left(K \cdot 0.5\right) \cdot J\right) \cdot \frac{\cos \color{blue}{\left(K \cdot 0.5\right)} \cdot J}{U}\right) \cdot -2 - U \]
    7. Applied egg-rr37.0%

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

    if 1.1999999999999999e-106 < J

    1. Initial program 92.4%

      \[\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.6%

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

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

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

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

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

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

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

Alternative 7: 77.5% accurate, 1.9× speedup?

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

\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 4.8 \cdot 10^{-106}:\\
\;\;\;\;-2 \cdot \frac{{\left(J\_m \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U\_m} - U\_m\\

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


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

    1. Initial program 60.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. Add Preprocessing
    3. Taylor expanded in J around 0 35.5%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg35.5%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative35.5%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow235.5%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative35.5%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow235.5%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr35.5%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow235.5%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative35.5%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified35.5%

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

    if 4.7999999999999995e-106 < J

    1. Initial program 92.4%

      \[\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.6%

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

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

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

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

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

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

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

Alternative 8: 66.7% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ J\_s \cdot \begin{array}{l} \mathbf{if}\;J\_m \leq 8.5 \cdot 10^{-43}:\\ \;\;\;\;\frac{-2 \cdot {J\_m}^{2}}{U\_m} - U\_m\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\_m\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
 :precision binary64
 (*
  J_s
  (if (<= J_m 8.5e-43)
    (- (/ (* -2.0 (pow J_m 2.0)) U_m) U_m)
    (* (cos (* K 0.5)) (* -2.0 J_m)))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (J_m <= 8.5e-43) {
		tmp = ((-2.0 * pow(J_m, 2.0)) / U_m) - U_m;
	} else {
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	}
	return J_s * tmp;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
    real(8), intent (in) :: j_s
    real(8), intent (in) :: j_m
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (j_m <= 8.5d-43) then
        tmp = (((-2.0d0) * (j_m ** 2.0d0)) / u_m) - u_m
    else
        tmp = cos((k * 0.5d0)) * ((-2.0d0) * j_m)
    end if
    code = j_s * tmp
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (J_m <= 8.5e-43) {
		tmp = ((-2.0 * Math.pow(J_m, 2.0)) / U_m) - U_m;
	} else {
		tmp = Math.cos((K * 0.5)) * (-2.0 * J_m);
	}
	return J_s * tmp;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	tmp = 0
	if J_m <= 8.5e-43:
		tmp = ((-2.0 * math.pow(J_m, 2.0)) / U_m) - U_m
	else:
		tmp = math.cos((K * 0.5)) * (-2.0 * J_m)
	return J_s * tmp
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	tmp = 0.0
	if (J_m <= 8.5e-43)
		tmp = Float64(Float64(Float64(-2.0 * (J_m ^ 2.0)) / U_m) - U_m);
	else
		tmp = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J_m));
	end
	return Float64(J_s * tmp)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp_2 = code(J_s, J_m, K, U_m)
	tmp = 0.0;
	if (J_m <= 8.5e-43)
		tmp = ((-2.0 * (J_m ^ 2.0)) / U_m) - U_m;
	else
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	end
	tmp_2 = J_s * tmp;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[LessEqual[J$95$m, 8.5e-43], N[(N[(N[(-2.0 * N[Power[J$95$m, 2.0], $MachinePrecision]), $MachinePrecision] / U$95$m), $MachinePrecision] - U$95$m), $MachinePrecision], N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 8.5 \cdot 10^{-43}:\\
\;\;\;\;\frac{-2 \cdot {J\_m}^{2}}{U\_m} - U\_m\\

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in J around 0 35.3%

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

        \[\leadsto -2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + \color{blue}{\left(-U\right)} \]
      2. unsub-neg35.3%

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. *-commutative35.3%

        \[\leadsto \color{blue}{\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2} - U \]
      4. unpow235.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} \cdot -2 - U \]
      5. *-commutative35.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot {\cos \color{blue}{\left(K \cdot 0.5\right)}}^{2}}{U} \cdot -2 - U \]
      6. unpow235.3%

        \[\leadsto \frac{\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      7. swap-sqr35.3%

        \[\leadsto \frac{\color{blue}{\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)}}{U} \cdot -2 - U \]
      8. unpow235.3%

        \[\leadsto \frac{\color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} \cdot -2 - U \]
      9. *-commutative35.3%

        \[\leadsto \frac{{\left(J \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right)}^{2}}{U} \cdot -2 - U \]
    5. Simplified35.3%

      \[\leadsto \color{blue}{\frac{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}{U} \cdot -2 - U} \]
    6. Taylor expanded in K around 0 35.3%

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U}} - U \]
    7. Step-by-step derivation
      1. associate-*r/35.3%

        \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]
    8. Simplified35.3%

      \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]

    if 8.50000000000000056e-43 < J

    1. Initial program 95.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. Add Preprocessing
    3. Taylor expanded in J around inf 71.1%

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

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

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

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

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

Alternative 9: 66.6% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ J\_s \cdot \begin{array}{l} \mathbf{if}\;J\_m \leq 3.8 \cdot 10^{-44}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\_m\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
 :precision binary64
 (* J_s (if (<= J_m 3.8e-44) (- U_m) (* (cos (* K 0.5)) (* -2.0 J_m)))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (J_m <= 3.8e-44) {
		tmp = -U_m;
	} else {
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	}
	return J_s * tmp;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
    real(8), intent (in) :: j_s
    real(8), intent (in) :: j_m
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (j_m <= 3.8d-44) then
        tmp = -u_m
    else
        tmp = cos((k * 0.5d0)) * ((-2.0d0) * j_m)
    end if
    code = j_s * tmp
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (J_m <= 3.8e-44) {
		tmp = -U_m;
	} else {
		tmp = Math.cos((K * 0.5)) * (-2.0 * J_m);
	}
	return J_s * tmp;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	tmp = 0
	if J_m <= 3.8e-44:
		tmp = -U_m
	else:
		tmp = math.cos((K * 0.5)) * (-2.0 * J_m)
	return J_s * tmp
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	tmp = 0.0
	if (J_m <= 3.8e-44)
		tmp = Float64(-U_m);
	else
		tmp = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J_m));
	end
	return Float64(J_s * tmp)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp_2 = code(J_s, J_m, K, U_m)
	tmp = 0.0;
	if (J_m <= 3.8e-44)
		tmp = -U_m;
	else
		tmp = cos((K * 0.5)) * (-2.0 * J_m);
	end
	tmp_2 = J_s * tmp;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[LessEqual[J$95$m, 3.8e-44], (-U$95$m), N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;J\_m \leq 3.8 \cdot 10^{-44}:\\
\;\;\;\;-U\_m\\

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in J around 0 36.1%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified36.1%

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

    if 3.8000000000000001e-44 < J

    1. Initial program 95.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. Add Preprocessing
    3. Taylor expanded in J around inf 71.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 3.8 \cdot 10^{-44}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 50.4% accurate, 52.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ J\_s \cdot \begin{array}{l} \mathbf{if}\;U\_m \leq 1.15 \cdot 10^{-82}:\\ \;\;\;\;-2 \cdot J\_m\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m)
 :precision binary64
 (* J_s (if (<= U_m 1.15e-82) (* -2.0 J_m) (- U_m))))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (U_m <= 1.15e-82) {
		tmp = -2.0 * J_m;
	} else {
		tmp = -U_m;
	}
	return J_s * tmp;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
    real(8), intent (in) :: j_s
    real(8), intent (in) :: j_m
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (u_m <= 1.15d-82) then
        tmp = (-2.0d0) * j_m
    else
        tmp = -u_m
    end if
    code = j_s * tmp
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	double tmp;
	if (U_m <= 1.15e-82) {
		tmp = -2.0 * J_m;
	} else {
		tmp = -U_m;
	}
	return J_s * tmp;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	tmp = 0
	if U_m <= 1.15e-82:
		tmp = -2.0 * J_m
	else:
		tmp = -U_m
	return J_s * tmp
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	tmp = 0.0
	if (U_m <= 1.15e-82)
		tmp = Float64(-2.0 * J_m);
	else
		tmp = Float64(-U_m);
	end
	return Float64(J_s * tmp)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp_2 = code(J_s, J_m, K, U_m)
	tmp = 0.0;
	if (U_m <= 1.15e-82)
		tmp = -2.0 * J_m;
	else
		tmp = -U_m;
	end
	tmp_2 = J_s * tmp;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * If[LessEqual[U$95$m, 1.15e-82], N[(-2.0 * J$95$m), $MachinePrecision], (-U$95$m)]), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
J\_s \cdot \begin{array}{l}
\mathbf{if}\;U\_m \leq 1.15 \cdot 10^{-82}:\\
\;\;\;\;-2 \cdot J\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1.14999999999999998e-82

    1. Initial program 72.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. Add Preprocessing
    3. Taylor expanded in J around inf 52.9%

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot -2\right) \cdot \cos \left(0.5 \cdot K\right)} \]
    6. Taylor expanded in K around 0 36.2%

      \[\leadsto \color{blue}{-2 \cdot J} \]
    7. Step-by-step derivation
      1. *-commutative36.2%

        \[\leadsto \color{blue}{J \cdot -2} \]
    8. Simplified36.2%

      \[\leadsto \color{blue}{J \cdot -2} \]

    if 1.14999999999999998e-82 < U

    1. Initial program 64.1%

      \[\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. Add Preprocessing
    3. Taylor expanded in J around 0 37.7%

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

        \[\leadsto \color{blue}{-U} \]
    5. Simplified37.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.15 \cdot 10^{-82}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 39.4% accurate, 210.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ J\_s \cdot \left(-U\_m\right) \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m) :precision binary64 (* J_s (- U_m)))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	return J_s * -U_m;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
    real(8), intent (in) :: j_s
    real(8), intent (in) :: j_m
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    code = j_s * -u_m
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	return J_s * -U_m;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	return J_s * -U_m
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	return Float64(J_s * Float64(-U_m))
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp = code(J_s, J_m, K, U_m)
	tmp = J_s * -U_m;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * (-U$95$m)), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
J\_s \cdot \left(-U\_m\right)
\end{array}
Derivation
  1. Initial program 70.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. Add Preprocessing
  3. Taylor expanded in J around 0 31.3%

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

      \[\leadsto \color{blue}{-U} \]
  5. Simplified31.3%

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

    \[\leadsto -U \]
  7. Add Preprocessing

Alternative 12: 14.2% accurate, 420.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ J_m = \left|J\right| \\ J_s = \mathsf{copysign}\left(1, J\right) \\ J\_s \cdot U\_m \end{array} \]
U_m = (fabs.f64 U)
J_m = (fabs.f64 J)
J_s = (copysign.f64 1 J)
(FPCore (J_s J_m K U_m) :precision binary64 (* J_s U_m))
U_m = fabs(U);
J_m = fabs(J);
J_s = copysign(1.0, J);
double code(double J_s, double J_m, double K, double U_m) {
	return J_s * U_m;
}
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0d0, J)
real(8) function code(j_s, j_m, k, u_m)
    real(8), intent (in) :: j_s
    real(8), intent (in) :: j_m
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    code = j_s * u_m
end function
U_m = Math.abs(U);
J_m = Math.abs(J);
J_s = Math.copySign(1.0, J);
public static double code(double J_s, double J_m, double K, double U_m) {
	return J_s * U_m;
}
U_m = math.fabs(U)
J_m = math.fabs(J)
J_s = math.copysign(1.0, J)
def code(J_s, J_m, K, U_m):
	return J_s * U_m
U_m = abs(U)
J_m = abs(J)
J_s = copysign(1.0, J)
function code(J_s, J_m, K, U_m)
	return Float64(J_s * U_m)
end
U_m = abs(U);
J_m = abs(J);
J_s = sign(J) * abs(1.0);
function tmp = code(J_s, J_m, K, U_m)
	tmp = J_s * U_m;
end
U_m = N[Abs[U], $MachinePrecision]
J_m = N[Abs[J], $MachinePrecision]
J_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[J]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[J$95$s_, J$95$m_, K_, U$95$m_] := N[(J$95$s * U$95$m), $MachinePrecision]
\begin{array}{l}
U_m = \left|U\right|
\\
J_m = \left|J\right|
\\
J_s = \mathsf{copysign}\left(1, J\right)

\\
J\_s \cdot U\_m
\end{array}
Derivation
  1. Initial program 70.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. Add Preprocessing
  3. Taylor expanded in J around 0 31.3%

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

      \[\leadsto \color{blue}{-U} \]
  5. Simplified31.3%

    \[\leadsto \color{blue}{-U} \]
  6. Step-by-step derivation
    1. neg-sub031.3%

      \[\leadsto \color{blue}{0 - U} \]
    2. sub-neg31.3%

      \[\leadsto \color{blue}{0 + \left(-U\right)} \]
    3. add-sqr-sqrt17.1%

      \[\leadsto 0 + \color{blue}{\sqrt{-U} \cdot \sqrt{-U}} \]
    4. sqrt-unprod17.0%

      \[\leadsto 0 + \color{blue}{\sqrt{\left(-U\right) \cdot \left(-U\right)}} \]
    5. sqr-neg17.0%

      \[\leadsto 0 + \sqrt{\color{blue}{U \cdot U}} \]
    6. sqrt-unprod12.9%

      \[\leadsto 0 + \color{blue}{\sqrt{U} \cdot \sqrt{U}} \]
    7. add-sqr-sqrt27.2%

      \[\leadsto 0 + \color{blue}{U} \]
  7. Applied egg-rr27.2%

    \[\leadsto \color{blue}{0 + U} \]
  8. Step-by-step derivation
    1. +-lft-identity27.2%

      \[\leadsto \color{blue}{U} \]
  9. Simplified27.2%

    \[\leadsto \color{blue}{U} \]
  10. Final simplification27.2%

    \[\leadsto U \]
  11. Add Preprocessing

Reproduce

?
herbie shell --seed 2024046 
(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)))))