Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.7% → 99.7%
Time: 18.3s
Alternatives: 13
Speedup: 1.3×

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 13 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: 73.7% 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.7% accurate, 0.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;t_1 \leq 10^{+307}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY)) (- U) (if (<= t_1 1e+307) t_1 U))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U;
	} else if (t_1 <= 1e+307) {
		tmp = t_1;
	} else {
		tmp = U;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U;
	} else if (t_1 <= 1e+307) {
		tmp = t_1;
	} else {
		tmp = U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / (t_0 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U
	elif t_1 <= 1e+307:
		tmp = t_1
	else:
		tmp = U
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U);
	elseif (t_1 <= 1e+307)
		tmp = t_1;
	else
		tmp = U;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / (t_0 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U;
	elseif (t_1 <= 1e+307)
		tmp = t_1;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U), If[LessEqual[t$95$1, 1e+307], t$95$1, U]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U\\

\mathbf{elif}\;t_1 \leq 10^{+307}:\\
\;\;\;\;t_1\\

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


\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.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. Step-by-step derivation
      1. *-commutative5.7%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*5.7%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def55.6%

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

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

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

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

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

        \[\leadsto \color{blue}{-U} \]
    6. Simplified48.0%

      \[\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)))) < 9.99999999999999986e306

    1. Initial program 99.8%

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

    if 9.99999999999999986e306 < (*.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 4.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. Step-by-step derivation
      1. *-commutative4.8%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*4.8%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def57.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 10^{+307}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 57.0% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := \left(-2 \cdot J\right) \cdot t_0\\ \mathbf{if}\;K \leq 62000000:\\ \;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{elif}\;K \leq 5.3 \cdot 10^{+213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;K \leq 1.22 \cdot 10^{+240}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.25, \frac{U \cdot U}{J \cdot t_0}, t_1\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))) (t_1 (* (* -2.0 J) t_0)))
   (if (<= K 62000000.0)
     (*
      (hypot 1.0 (/ U (* J (* 2.0 (cos (/ K 2.0))))))
      (* J (+ -2.0 (* 0.25 (* K K)))))
     (if (<= K 5.3e+213)
       t_1
       (if (<= K 1.22e+240)
         (* -2.0 (+ (* J (/ J U)) (* U 0.5)))
         (fma -0.25 (/ (* U U) (* J t_0)) t_1))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = (-2.0 * J) * t_0;
	double tmp;
	if (K <= 62000000.0) {
		tmp = hypot(1.0, (U / (J * (2.0 * cos((K / 2.0)))))) * (J * (-2.0 + (0.25 * (K * K))));
	} else if (K <= 5.3e+213) {
		tmp = t_1;
	} else if (K <= 1.22e+240) {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	} else {
		tmp = fma(-0.25, ((U * U) / (J * t_0)), t_1);
	}
	return tmp;
}
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(Float64(-2.0 * J) * t_0)
	tmp = 0.0
	if (K <= 62000000.0)
		tmp = Float64(hypot(1.0, Float64(U / Float64(J * Float64(2.0 * cos(Float64(K / 2.0)))))) * Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K)))));
	elseif (K <= 5.3e+213)
		tmp = t_1;
	elseif (K <= 1.22e+240)
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	else
		tmp = fma(-0.25, Float64(Float64(U * U) / Float64(J * t_0)), t_1);
	end
	return tmp
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[K, 62000000.0], N[(N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[K, 5.3e+213], t$95$1, If[LessEqual[K, 1.22e+240], N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.25 * N[(N[(U * U), $MachinePrecision] / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := \left(-2 \cdot J\right) \cdot t_0\\
\mathbf{if}\;K \leq 62000000:\\
\;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\

\mathbf{elif}\;K \leq 5.3 \cdot 10^{+213}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;K \leq 1.22 \cdot 10^{+240}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.25, \frac{U \cdot U}{J \cdot t_0}, t_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if K < 6.2e7

    1. Initial program 71.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. Step-by-step derivation
      1. *-commutative71.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*71.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def86.8%

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} + -2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \]
      2. distribute-rgt-out58.4%

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

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

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

    if 6.2e7 < K < 5.2999999999999998e213

    1. Initial program 67.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. Step-by-step derivation
      1. *-commutative67.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*67.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def80.7%

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

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

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

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

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

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

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

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

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

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

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

    if 5.2999999999999998e213 < K < 1.2200000000000001e240

    1. Initial program 35.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. Step-by-step derivation
      1. *-commutative35.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*35.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 68.4%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow268.4%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified68.4%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef68.4%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \frac{J}{U} + \color{blue}{0.5 \cdot U}\right) \]
    11. Applied egg-rr69.3%

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

    if 1.2200000000000001e240 < K

    1. Initial program 67.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. *-commutative67.2%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*67.2%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def89.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{{U}^{2}}{\cos \left(0.5 \cdot K\right) \cdot J}, -2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)} \]
      2. unpow234.6%

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

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{U \cdot U}{\color{blue}{J \cdot \cos \left(0.5 \cdot K\right)}}, -2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right) \]
      4. associate-*r*34.6%

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

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

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{U \cdot U}{J \cdot \cos \left(0.5 \cdot K\right)}, \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot -2\right)} \cdot J\right) \]
      7. associate-*r*34.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 62000000:\\ \;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{elif}\;K \leq 5.3 \cdot 10^{+213}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;K \leq 1.22 \cdot 10^{+240}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.25, \frac{U \cdot U}{J \cdot \cos \left(K \cdot 0.5\right)}, \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 3: 88.3% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(J \cdot \left(-2 \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right) \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* (* J (* -2.0 t_0)) (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return (J * (-2.0 * t_0)) * Math.hypot(1.0, (U / (J * (2.0 * t_0))));
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return (J * (-2.0 * t_0)) * math.hypot(1.0, (U / (J * (2.0 * t_0))))
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(J * Float64(-2.0 * t_0)) * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(J * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(J \cdot \left(-2 \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 70.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. Step-by-step derivation
    1. *-commutative70.3%

      \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*70.3%

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

      \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
    4. hypot-1-def86.3%

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

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

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

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

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

Alternative 4: 57.1% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;K \leq 62000000:\\ \;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{elif}\;K \leq 6.5 \cdot 10^{+213} \lor \neg \left(K \leq 9.5 \cdot 10^{+239}\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= K 62000000.0)
   (*
    (hypot 1.0 (/ U (* J (* 2.0 (cos (/ K 2.0))))))
    (* J (+ -2.0 (* 0.25 (* K K)))))
   (if (or (<= K 6.5e+213) (not (<= K 9.5e+239)))
     (* (* -2.0 J) (cos (* K 0.5)))
     (* -2.0 (+ (* J (/ J U)) (* U 0.5))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (K <= 62000000.0) {
		tmp = hypot(1.0, (U / (J * (2.0 * cos((K / 2.0)))))) * (J * (-2.0 + (0.25 * (K * K))));
	} else if ((K <= 6.5e+213) || !(K <= 9.5e+239)) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (K <= 62000000.0) {
		tmp = Math.hypot(1.0, (U / (J * (2.0 * Math.cos((K / 2.0)))))) * (J * (-2.0 + (0.25 * (K * K))));
	} else if ((K <= 6.5e+213) || !(K <= 9.5e+239)) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if K <= 62000000.0:
		tmp = math.hypot(1.0, (U / (J * (2.0 * math.cos((K / 2.0)))))) * (J * (-2.0 + (0.25 * (K * K))))
	elif (K <= 6.5e+213) or not (K <= 9.5e+239):
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	else:
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5))
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (K <= 62000000.0)
		tmp = Float64(hypot(1.0, Float64(U / Float64(J * Float64(2.0 * cos(Float64(K / 2.0)))))) * Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K)))));
	elseif ((K <= 6.5e+213) || !(K <= 9.5e+239))
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	else
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (K <= 62000000.0)
		tmp = hypot(1.0, (U / (J * (2.0 * cos((K / 2.0)))))) * (J * (-2.0 + (0.25 * (K * K))));
	elseif ((K <= 6.5e+213) || ~((K <= 9.5e+239)))
		tmp = (-2.0 * J) * cos((K * 0.5));
	else
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[K, 62000000.0], N[(N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[K, 6.5e+213], N[Not[LessEqual[K, 9.5e+239]], $MachinePrecision]], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;K \leq 62000000:\\
\;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\

\mathbf{elif}\;K \leq 6.5 \cdot 10^{+213} \lor \neg \left(K \leq 9.5 \cdot 10^{+239}\right):\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\


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

    1. Initial program 71.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. Step-by-step derivation
      1. *-commutative71.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*71.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def86.8%

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} + -2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \]
      2. distribute-rgt-out58.4%

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

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

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

    if 6.2e7 < K < 6.49999999999999982e213 or 9.5000000000000008e239 < K

    1. Initial program 67.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. Step-by-step derivation
      1. *-commutative67.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*67.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def83.6%

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

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

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

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

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

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

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

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

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

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

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

    if 6.49999999999999982e213 < K < 9.5000000000000008e239

    1. Initial program 35.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. Step-by-step derivation
      1. *-commutative35.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*35.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 68.4%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow268.4%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified68.4%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef68.4%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \frac{J}{U} + \color{blue}{0.5 \cdot U}\right) \]
    11. Applied egg-rr69.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 62000000:\\ \;\;\;\;\mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right) \cdot \left(J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{elif}\;K \leq 6.5 \cdot 10^{+213} \lor \neg \left(K \leq 9.5 \cdot 10^{+239}\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \]

Alternative 5: 65.7% accurate, 3.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;J \leq -8 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -8.5 \cdot 10^{-53}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -7.8 \cdot 10^{-110}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.05 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5 \cdot 10^{-120}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 6.6 \cdot 10^{-89} \lor \neg \left(J \leq 12500000000000\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* (* -2.0 J) (cos (* K 0.5)))))
   (if (<= J -8e+16)
     t_0
     (if (<= J -8.5e-53)
       U
       (if (<= J -3.3e-92)
         t_0
         (if (<= J -7.8e-110)
           (- U)
           (if (<= J -1e-310)
             U
             (if (<= J 4.05e-243)
               (- U)
               (if (<= J 2.1e-229)
                 U
                 (if (<= J 5e-120)
                   (- U)
                   (if (or (<= J 6.6e-89) (not (<= J 12500000000000.0)))
                     t_0
                     (* -2.0 (+ (* J (/ J U)) (* U 0.5))))))))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = (-2.0 * J) * cos((K * 0.5));
	double tmp;
	if (J <= -8e+16) {
		tmp = t_0;
	} else if (J <= -8.5e-53) {
		tmp = U;
	} else if (J <= -3.3e-92) {
		tmp = t_0;
	} else if (J <= -7.8e-110) {
		tmp = -U;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 4.05e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 5e-120) {
		tmp = -U;
	} else if ((J <= 6.6e-89) || !(J <= 12500000000000.0)) {
		tmp = t_0;
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
NOTE: U should be positive before calling this function
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
    real(8) :: tmp
    t_0 = ((-2.0d0) * j) * cos((k * 0.5d0))
    if (j <= (-8d+16)) then
        tmp = t_0
    else if (j <= (-8.5d-53)) then
        tmp = u
    else if (j <= (-3.3d-92)) then
        tmp = t_0
    else if (j <= (-7.8d-110)) then
        tmp = -u
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 4.05d-243) then
        tmp = -u
    else if (j <= 2.1d-229) then
        tmp = u
    else if (j <= 5d-120) then
        tmp = -u
    else if ((j <= 6.6d-89) .or. (.not. (j <= 12500000000000.0d0))) then
        tmp = t_0
    else
        tmp = (-2.0d0) * ((j * (j / u)) + (u * 0.5d0))
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = (-2.0 * J) * Math.cos((K * 0.5));
	double tmp;
	if (J <= -8e+16) {
		tmp = t_0;
	} else if (J <= -8.5e-53) {
		tmp = U;
	} else if (J <= -3.3e-92) {
		tmp = t_0;
	} else if (J <= -7.8e-110) {
		tmp = -U;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 4.05e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 5e-120) {
		tmp = -U;
	} else if ((J <= 6.6e-89) || !(J <= 12500000000000.0)) {
		tmp = t_0;
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = (-2.0 * J) * math.cos((K * 0.5))
	tmp = 0
	if J <= -8e+16:
		tmp = t_0
	elif J <= -8.5e-53:
		tmp = U
	elif J <= -3.3e-92:
		tmp = t_0
	elif J <= -7.8e-110:
		tmp = -U
	elif J <= -1e-310:
		tmp = U
	elif J <= 4.05e-243:
		tmp = -U
	elif J <= 2.1e-229:
		tmp = U
	elif J <= 5e-120:
		tmp = -U
	elif (J <= 6.6e-89) or not (J <= 12500000000000.0):
		tmp = t_0
	else:
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5))
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (J <= -8e+16)
		tmp = t_0;
	elseif (J <= -8.5e-53)
		tmp = U;
	elseif (J <= -3.3e-92)
		tmp = t_0;
	elseif (J <= -7.8e-110)
		tmp = Float64(-U);
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 4.05e-243)
		tmp = Float64(-U);
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 5e-120)
		tmp = Float64(-U);
	elseif ((J <= 6.6e-89) || !(J <= 12500000000000.0))
		tmp = t_0;
	else
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = (-2.0 * J) * cos((K * 0.5));
	tmp = 0.0;
	if (J <= -8e+16)
		tmp = t_0;
	elseif (J <= -8.5e-53)
		tmp = U;
	elseif (J <= -3.3e-92)
		tmp = t_0;
	elseif (J <= -7.8e-110)
		tmp = -U;
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 4.05e-243)
		tmp = -U;
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 5e-120)
		tmp = -U;
	elseif ((J <= 6.6e-89) || ~((J <= 12500000000000.0)))
		tmp = t_0;
	else
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -8e+16], t$95$0, If[LessEqual[J, -8.5e-53], U, If[LessEqual[J, -3.3e-92], t$95$0, If[LessEqual[J, -7.8e-110], (-U), If[LessEqual[J, -1e-310], U, If[LessEqual[J, 4.05e-243], (-U), If[LessEqual[J, 2.1e-229], U, If[LessEqual[J, 5e-120], (-U), If[Or[LessEqual[J, 6.6e-89], N[Not[LessEqual[J, 12500000000000.0]], $MachinePrecision]], t$95$0, N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq -8 \cdot 10^{+16}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -8.5 \cdot 10^{-53}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq -3.3 \cdot 10^{-92}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -7.8 \cdot 10^{-110}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 4.05 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5 \cdot 10^{-120}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 6.6 \cdot 10^{-89} \lor \neg \left(J \leq 12500000000000\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -8e16 or -8.50000000000000044e-53 < J < -3.29999999999999998e-92 or 5.00000000000000007e-120 < J < 6.5999999999999993e-89 or 1.25e13 < J

    1. Initial program 93.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. Step-by-step derivation
      1. *-commutative93.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8e16 < J < -8.50000000000000044e-53 or -7.8e-110 < J < -9.999999999999969e-311 or 4.0499999999999999e-243 < J < 2.09999999999999983e-229

    1. Initial program 37.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. Step-by-step derivation
      1. *-commutative37.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*37.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def71.3%

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

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

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

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

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

    if -3.29999999999999998e-92 < J < -7.8e-110 or -9.999999999999969e-311 < J < 4.0499999999999999e-243 or 2.09999999999999983e-229 < J < 5.00000000000000007e-120

    1. Initial program 47.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. Step-by-step derivation
      1. *-commutative47.3%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*47.3%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def66.6%

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

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

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

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

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

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

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

    if 6.5999999999999993e-89 < J < 1.25e13

    1. Initial program 57.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. Step-by-step derivation
      1. *-commutative57.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*57.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def90.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 32.1%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow232.1%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified32.1%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef32.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -8 \cdot 10^{+16}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -8.5 \cdot 10^{-53}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-92}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -7.8 \cdot 10^{-110}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.05 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5 \cdot 10^{-120}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 6.6 \cdot 10^{-89} \lor \neg \left(J \leq 12500000000000\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \]

Alternative 6: 65.4% accurate, 3.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;J \leq -5.2 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -3.9 \cdot 10^{-53}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -6.5 \cdot 10^{-90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -8.8 \cdot 10^{-110}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.35 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-120}:\\ \;\;\;\;-2 \cdot \mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 1.6 \cdot 10^{-91} \lor \neg \left(J \leq 1.95 \cdot 10^{+25}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* (* -2.0 J) (cos (* K 0.5)))))
   (if (<= J -5.2e+16)
     t_0
     (if (<= J -3.9e-53)
       U
       (if (<= J -6.5e-90)
         t_0
         (if (<= J -8.8e-110)
           (- U)
           (if (<= J -1e-310)
             U
             (if (<= J 5.8e-243)
               (- U)
               (if (<= J 2.35e-229)
                 U
                 (if (<= J 5.6e-120)
                   (* -2.0 (fma U 0.5 (/ (* J J) U)))
                   (if (or (<= J 1.6e-91) (not (<= J 1.95e+25)))
                     t_0
                     (* -2.0 (+ (* J (/ J U)) (* U 0.5))))))))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = (-2.0 * J) * cos((K * 0.5));
	double tmp;
	if (J <= -5.2e+16) {
		tmp = t_0;
	} else if (J <= -3.9e-53) {
		tmp = U;
	} else if (J <= -6.5e-90) {
		tmp = t_0;
	} else if (J <= -8.8e-110) {
		tmp = -U;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 2.35e-229) {
		tmp = U;
	} else if (J <= 5.6e-120) {
		tmp = -2.0 * fma(U, 0.5, ((J * J) / U));
	} else if ((J <= 1.6e-91) || !(J <= 1.95e+25)) {
		tmp = t_0;
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (J <= -5.2e+16)
		tmp = t_0;
	elseif (J <= -3.9e-53)
		tmp = U;
	elseif (J <= -6.5e-90)
		tmp = t_0;
	elseif (J <= -8.8e-110)
		tmp = Float64(-U);
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = Float64(-U);
	elseif (J <= 2.35e-229)
		tmp = U;
	elseif (J <= 5.6e-120)
		tmp = Float64(-2.0 * fma(U, 0.5, Float64(Float64(J * J) / U)));
	elseif ((J <= 1.6e-91) || !(J <= 1.95e+25))
		tmp = t_0;
	else
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	end
	return tmp
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -5.2e+16], t$95$0, If[LessEqual[J, -3.9e-53], U, If[LessEqual[J, -6.5e-90], t$95$0, If[LessEqual[J, -8.8e-110], (-U), If[LessEqual[J, -1e-310], U, If[LessEqual[J, 5.8e-243], (-U), If[LessEqual[J, 2.35e-229], U, If[LessEqual[J, 5.6e-120], N[(-2.0 * N[(U * 0.5 + N[(N[(J * J), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[J, 1.6e-91], N[Not[LessEqual[J, 1.95e+25]], $MachinePrecision]], t$95$0, N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq -5.2 \cdot 10^{+16}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -3.9 \cdot 10^{-53}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq -6.5 \cdot 10^{-90}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -8.8 \cdot 10^{-110}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.35 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.6 \cdot 10^{-120}:\\
\;\;\;\;-2 \cdot \mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)\\

\mathbf{elif}\;J \leq 1.6 \cdot 10^{-91} \lor \neg \left(J \leq 1.95 \cdot 10^{+25}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if J < -5.2e16 or -3.9000000000000002e-53 < J < -6.4999999999999996e-90 or 5.59999999999999988e-120 < J < 1.59999999999999998e-91 or 1.9500000000000001e25 < J

    1. Initial program 93.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. Step-by-step derivation
      1. *-commutative93.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.2e16 < J < -3.9000000000000002e-53 or -8.7999999999999997e-110 < J < -9.999999999999969e-311 or 5.79999999999999953e-243 < J < 2.35000000000000017e-229

    1. Initial program 37.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. Step-by-step derivation
      1. *-commutative37.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*37.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def71.3%

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

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

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

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

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

    if -6.4999999999999996e-90 < J < -8.7999999999999997e-110 or -9.999999999999969e-311 < J < 5.79999999999999953e-243

    1. Initial program 43.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. Step-by-step derivation
      1. *-commutative43.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*43.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def65.7%

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

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

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

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

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

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

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

    if 2.35000000000000017e-229 < J < 5.59999999999999988e-120

    1. Initial program 50.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. Step-by-step derivation
      1. *-commutative50.7%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*50.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 45.1%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow245.1%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified45.1%

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

    if 1.59999999999999998e-91 < J < 1.9500000000000001e25

    1. Initial program 57.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. Step-by-step derivation
      1. *-commutative57.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*57.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def90.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 32.1%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow232.1%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified32.1%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef32.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.2 \cdot 10^{+16}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -3.9 \cdot 10^{-53}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -6.5 \cdot 10^{-90}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -8.8 \cdot 10^{-110}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.35 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-120}:\\ \;\;\;\;-2 \cdot \mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 1.6 \cdot 10^{-91} \lor \neg \left(J \leq 1.95 \cdot 10^{+25}\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \]

Alternative 7: 62.4% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;K \leq 8.5 \cdot 10^{-5}:\\ \;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{J}\right)\right)\\ \mathbf{elif}\;K \leq 6.2 \cdot 10^{+213} \lor \neg \left(K \leq 1.22 \cdot 10^{+240}\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= K 8.5e-5)
   (* -2.0 (* J (hypot 1.0 (/ (* U 0.5) J))))
   (if (or (<= K 6.2e+213) (not (<= K 1.22e+240)))
     (* (* -2.0 J) (cos (* K 0.5)))
     (* -2.0 (+ (* J (/ J U)) (* U 0.5))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (K <= 8.5e-5) {
		tmp = -2.0 * (J * hypot(1.0, ((U * 0.5) / J)));
	} else if ((K <= 6.2e+213) || !(K <= 1.22e+240)) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (K <= 8.5e-5) {
		tmp = -2.0 * (J * Math.hypot(1.0, ((U * 0.5) / J)));
	} else if ((K <= 6.2e+213) || !(K <= 1.22e+240)) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if K <= 8.5e-5:
		tmp = -2.0 * (J * math.hypot(1.0, ((U * 0.5) / J)))
	elif (K <= 6.2e+213) or not (K <= 1.22e+240):
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	else:
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5))
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (K <= 8.5e-5)
		tmp = Float64(-2.0 * Float64(J * hypot(1.0, Float64(Float64(U * 0.5) / J))));
	elseif ((K <= 6.2e+213) || !(K <= 1.22e+240))
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	else
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (K <= 8.5e-5)
		tmp = -2.0 * (J * hypot(1.0, ((U * 0.5) / J)));
	elseif ((K <= 6.2e+213) || ~((K <= 1.22e+240)))
		tmp = (-2.0 * J) * cos((K * 0.5));
	else
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[K, 8.5e-5], N[(-2.0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[K, 6.2e+213], N[Not[LessEqual[K, 1.22e+240]], $MachinePrecision]], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;K \leq 8.5 \cdot 10^{-5}:\\
\;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{J}\right)\right)\\

\mathbf{elif}\;K \leq 6.2 \cdot 10^{+213} \lor \neg \left(K \leq 1.22 \cdot 10^{+240}\right):\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if K < 8.500000000000001e-5

    1. Initial program 71.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. Step-by-step derivation
      1. *-commutative71.7%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*71.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt37.3%

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{hypot}\left(1, \sqrt{0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)}\right) \]
      3. *-commutative37.3%

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{\color{blue}{\frac{U \cdot U}{J \cdot J} \cdot 0.25}}\right)\right) \]
      4. times-frac52.4%

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{\color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.25}\right)\right) \]
    8. Applied egg-rr52.4%

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{hypot}\left(1, \sqrt{\left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.25}\right)}\right) \]
    9. Step-by-step derivation
      1. *-commutative52.4%

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{\color{blue}{0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right)\right) \]
      2. times-frac37.3%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{0.25 \cdot \frac{{U}^{2}}{\color{blue}{{J}^{2}}}}\right)\right) \]
      5. associate-*r/37.3%

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{\color{blue}{\frac{0.25 \cdot {U}^{2}}{{J}^{2}}}}\right)\right) \]
      6. associate-/l*37.3%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \sqrt{\frac{0.25}{\frac{J \cdot J}{\color{blue}{U \cdot U}}}}\right)\right) \]
      9. times-frac52.4%

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{hypot}\left(1, \sqrt{\frac{0.25}{\frac{J}{U} \cdot \frac{J}{U}}}\right)}\right) \]
    11. Step-by-step derivation
      1. expm1-log1p-u33.8%

        \[\leadsto -2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \sqrt{\frac{0.25}{\frac{J}{U} \cdot \frac{J}{U}}}\right)\right)\right)} \]
      2. expm1-udef17.7%

        \[\leadsto -2 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \sqrt{\frac{0.25}{\frac{J}{U} \cdot \frac{J}{U}}}\right)\right)} - 1\right)} \]
      3. sqrt-div18.4%

        \[\leadsto -2 \cdot \left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\sqrt{0.25}}{\sqrt{\frac{J}{U} \cdot \frac{J}{U}}}}\right)\right)} - 1\right) \]
      4. metadata-eval18.4%

        \[\leadsto -2 \cdot \left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{0.5}}{\sqrt{\frac{J}{U} \cdot \frac{J}{U}}}\right)\right)} - 1\right) \]
      5. sqrt-prod11.4%

        \[\leadsto -2 \cdot \left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \frac{0.5}{\color{blue}{\sqrt{\frac{J}{U}} \cdot \sqrt{\frac{J}{U}}}}\right)\right)} - 1\right) \]
      6. add-sqr-sqrt23.6%

        \[\leadsto -2 \cdot \left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \frac{0.5}{\color{blue}{\frac{J}{U}}}\right)\right)} - 1\right) \]
    12. Applied egg-rr23.6%

      \[\leadsto -2 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \frac{0.5}{\frac{J}{U}}\right)\right)} - 1\right)} \]
    13. Step-by-step derivation
      1. expm1-def41.6%

        \[\leadsto -2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(J \cdot \mathsf{hypot}\left(1, \frac{0.5}{\frac{J}{U}}\right)\right)\right)} \]
      2. expm1-log1p64.9%

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

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

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

    if 8.500000000000001e-5 < K < 6.19999999999999981e213 or 1.2200000000000001e240 < K

    1. Initial program 67.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. Step-by-step derivation
      1. *-commutative67.1%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*67.1%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def82.7%

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

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

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

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

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

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

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

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

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

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

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

    if 6.19999999999999981e213 < K < 1.2200000000000001e240

    1. Initial program 35.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. Step-by-step derivation
      1. *-commutative35.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*35.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 68.4%

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

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow268.4%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified68.4%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef68.4%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \frac{J}{U} + \color{blue}{0.5 \cdot U}\right) \]
    11. Applied egg-rr69.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 8.5 \cdot 10^{-5}:\\ \;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{J}\right)\right)\\ \mathbf{elif}\;K \leq 6.2 \cdot 10^{+213} \lor \neg \left(K \leq 1.22 \cdot 10^{+240}\right):\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \end{array} \]

Alternative 8: 49.4% accurate, 19.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -3.4 \cdot 10^{+42}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.4 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.6 \cdot 10^{+99}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J -3.4e+42)
   (* J (+ -2.0 (* 0.25 (* K K))))
   (if (<= J -1e-310)
     U
     (if (<= J 1.4e-243)
       (- U)
       (if (<= J 2.1e-229)
         U
         (if (<= J 3.6e+99)
           (* -2.0 (+ (* J (/ J U)) (* U 0.5)))
           (* -2.0 J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -3.4e+42) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 1.4e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 3.6e+99) {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-3.4d+42)) then
        tmp = j * ((-2.0d0) + (0.25d0 * (k * k)))
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 1.4d-243) then
        tmp = -u
    else if (j <= 2.1d-229) then
        tmp = u
    else if (j <= 3.6d+99) then
        tmp = (-2.0d0) * ((j * (j / u)) + (u * 0.5d0))
    else
        tmp = (-2.0d0) * j
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -3.4e+42) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 1.4e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 3.6e+99) {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -3.4e+42:
		tmp = J * (-2.0 + (0.25 * (K * K)))
	elif J <= -1e-310:
		tmp = U
	elif J <= 1.4e-243:
		tmp = -U
	elif J <= 2.1e-229:
		tmp = U
	elif J <= 3.6e+99:
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5))
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -3.4e+42)
		tmp = Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K))));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 1.4e-243)
		tmp = Float64(-U);
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 3.6e+99)
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -3.4e+42)
		tmp = J * (-2.0 + (0.25 * (K * K)));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 1.4e-243)
		tmp = -U;
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 3.6e+99)
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -3.4e+42], N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -1e-310], U, If[LessEqual[J, 1.4e-243], (-U), If[LessEqual[J, 2.1e-229], U, If[LessEqual[J, 3.6e+99], N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * J), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -3.4 \cdot 10^{+42}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.4 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 3.6 \cdot 10^{+99}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if J < -3.39999999999999975e42

    1. Initial program 95.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. *-commutative95.2%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative45.7%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*45.7%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out45.7%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow245.7%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified45.7%

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

    if -3.39999999999999975e42 < J < -9.999999999999969e-311 or 1.39999999999999997e-243 < J < 2.09999999999999983e-229

    1. Initial program 44.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. Step-by-step derivation
      1. *-commutative44.4%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*44.4%

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < J < 1.39999999999999997e-243

    1. Initial program 32.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. Step-by-step derivation
      1. *-commutative32.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*32.6%

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

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

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

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

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

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

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

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

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

    if 2.09999999999999983e-229 < J < 3.6000000000000002e99

    1. Initial program 68.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. Step-by-step derivation
      1. *-commutative68.1%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*68.1%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def84.8%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 28.3%

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U + \frac{{J}^{2}}{U}\right)} \]
    8. Step-by-step derivation
      1. *-commutative28.3%

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow228.3%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified28.3%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef28.3%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \frac{J}{U} + \color{blue}{0.5 \cdot U}\right) \]
    11. Applied egg-rr28.3%

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

    if 3.6000000000000002e99 < J

    1. Initial program 99.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. Step-by-step derivation
      1. *-commutative99.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*99.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around inf 41.4%

      \[\leadsto -2 \cdot \color{blue}{J} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification38.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.4 \cdot 10^{+42}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.4 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.6 \cdot 10^{+99}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 49.5% accurate, 19.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2.2 \cdot 10^{+35}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.7 \cdot 10^{+101}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J + \frac{U}{\frac{J}{U}} \cdot 0.125\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J -2.2e+35)
   (* J (+ -2.0 (* 0.25 (* K K))))
   (if (<= J -1e-310)
     U
     (if (<= J 5.8e-243)
       (- U)
       (if (<= J 2.1e-229)
         U
         (if (<= J 1.7e+101)
           (* -2.0 (+ (* J (/ J U)) (* U 0.5)))
           (* -2.0 (+ J (* (/ U (/ J U)) 0.125)))))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.2e+35) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 1.7e+101) {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	} else {
		tmp = -2.0 * (J + ((U / (J / U)) * 0.125));
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-2.2d+35)) then
        tmp = j * ((-2.0d0) + (0.25d0 * (k * k)))
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 5.8d-243) then
        tmp = -u
    else if (j <= 2.1d-229) then
        tmp = u
    else if (j <= 1.7d+101) then
        tmp = (-2.0d0) * ((j * (j / u)) + (u * 0.5d0))
    else
        tmp = (-2.0d0) * (j + ((u / (j / u)) * 0.125d0))
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.2e+35) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else if (J <= 1.7e+101) {
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	} else {
		tmp = -2.0 * (J + ((U / (J / U)) * 0.125));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2.2e+35:
		tmp = J * (-2.0 + (0.25 * (K * K)))
	elif J <= -1e-310:
		tmp = U
	elif J <= 5.8e-243:
		tmp = -U
	elif J <= 2.1e-229:
		tmp = U
	elif J <= 1.7e+101:
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5))
	else:
		tmp = -2.0 * (J + ((U / (J / U)) * 0.125))
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2.2e+35)
		tmp = Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K))));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = Float64(-U);
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 1.7e+101)
		tmp = Float64(-2.0 * Float64(Float64(J * Float64(J / U)) + Float64(U * 0.5)));
	else
		tmp = Float64(-2.0 * Float64(J + Float64(Float64(U / Float64(J / U)) * 0.125)));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -2.2e+35)
		tmp = J * (-2.0 + (0.25 * (K * K)));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = -U;
	elseif (J <= 2.1e-229)
		tmp = U;
	elseif (J <= 1.7e+101)
		tmp = -2.0 * ((J * (J / U)) + (U * 0.5));
	else
		tmp = -2.0 * (J + ((U / (J / U)) * 0.125));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -2.2e+35], N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -1e-310], U, If[LessEqual[J, 5.8e-243], (-U), If[LessEqual[J, 2.1e-229], U, If[LessEqual[J, 1.7e+101], N[(-2.0 * N[(N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision] + N[(U * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(J + N[(N[(U / N[(J / U), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2.2 \cdot 10^{+35}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.7 \cdot 10^{+101}:\\
\;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J + \frac{U}{\frac{J}{U}} \cdot 0.125\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if J < -2.1999999999999999e35

    1. Initial program 95.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. *-commutative95.2%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative45.7%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*45.7%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out45.7%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow245.7%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified45.7%

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

    if -2.1999999999999999e35 < J < -9.999999999999969e-311 or 5.79999999999999953e-243 < J < 2.09999999999999983e-229

    1. Initial program 44.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. Step-by-step derivation
      1. *-commutative44.4%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*44.4%

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < J < 5.79999999999999953e-243

    1. Initial program 32.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. Step-by-step derivation
      1. *-commutative32.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*32.6%

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

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

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

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

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

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

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

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

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

    if 2.09999999999999983e-229 < J < 1.70000000000000009e101

    1. Initial program 68.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. Step-by-step derivation
      1. *-commutative68.1%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*68.1%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def84.8%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around 0 28.3%

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U + \frac{{J}^{2}}{U}\right)} \]
    8. Step-by-step derivation
      1. *-commutative28.3%

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

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{{J}^{2}}{U}\right)} \]
      3. unpow228.3%

        \[\leadsto -2 \cdot \mathsf{fma}\left(U, 0.5, \frac{\color{blue}{J \cdot J}}{U}\right) \]
    9. Simplified28.3%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U, 0.5, \frac{J \cdot J}{U}\right)} \]
    10. Step-by-step derivation
      1. fma-udef28.3%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \frac{J}{U} + \color{blue}{0.5 \cdot U}\right) \]
    11. Applied egg-rr28.3%

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

    if 1.70000000000000009e101 < J

    1. Initial program 99.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. Step-by-step derivation
      1. *-commutative99.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*99.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around inf 40.7%

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

        \[\leadsto -2 \cdot \left(\color{blue}{\frac{{U}^{2}}{J} \cdot 0.125} + J\right) \]
      2. fma-def40.7%

        \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(\frac{{U}^{2}}{J}, 0.125, J\right)} \]
      3. unpow240.7%

        \[\leadsto -2 \cdot \mathsf{fma}\left(\frac{\color{blue}{U \cdot U}}{J}, 0.125, J\right) \]
      4. associate-*r/41.4%

        \[\leadsto -2 \cdot \mathsf{fma}\left(\color{blue}{U \cdot \frac{U}{J}}, 0.125, J\right) \]
    9. Simplified41.4%

      \[\leadsto -2 \cdot \color{blue}{\mathsf{fma}\left(U \cdot \frac{U}{J}, 0.125, J\right)} \]
    10. Step-by-step derivation
      1. fma-udef41.4%

        \[\leadsto -2 \cdot \color{blue}{\left(\left(U \cdot \frac{U}{J}\right) \cdot 0.125 + J\right)} \]
      2. clear-num41.4%

        \[\leadsto -2 \cdot \left(\left(U \cdot \color{blue}{\frac{1}{\frac{J}{U}}}\right) \cdot 0.125 + J\right) \]
      3. un-div-inv41.4%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\frac{U}{\frac{J}{U}} \cdot 0.125 + J\right)} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification38.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.2 \cdot 10^{+35}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.7 \cdot 10^{+101}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U} + U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J + \frac{U}{\frac{J}{U}} \cdot 0.125\right)\\ \end{array} \]

Alternative 10: 50.2% accurate, 31.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2.1 \cdot 10^{+64}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 3.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.7 \cdot 10^{+99}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J -2.1e+64)
   (* -2.0 J)
   (if (<= J -1e-310)
     U
     (if (<= J 5.8e-243)
       (- U)
       (if (<= J 3.1e-229) U (if (<= J 3.7e+99) (- U) (* -2.0 J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.1e+64) {
		tmp = -2.0 * J;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 3.1e-229) {
		tmp = U;
	} else if (J <= 3.7e+99) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-2.1d+64)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 5.8d-243) then
        tmp = -u
    else if (j <= 3.1d-229) then
        tmp = u
    else if (j <= 3.7d+99) then
        tmp = -u
    else
        tmp = (-2.0d0) * j
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.1e+64) {
		tmp = -2.0 * J;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 3.1e-229) {
		tmp = U;
	} else if (J <= 3.7e+99) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2.1e+64:
		tmp = -2.0 * J
	elif J <= -1e-310:
		tmp = U
	elif J <= 5.8e-243:
		tmp = -U
	elif J <= 3.1e-229:
		tmp = U
	elif J <= 3.7e+99:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2.1e+64)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = Float64(-U);
	elseif (J <= 3.1e-229)
		tmp = U;
	elseif (J <= 3.7e+99)
		tmp = Float64(-U);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -2.1e+64)
		tmp = -2.0 * J;
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = -U;
	elseif (J <= 3.1e-229)
		tmp = U;
	elseif (J <= 3.7e+99)
		tmp = -U;
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -2.1e+64], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1e-310], U, If[LessEqual[J, 5.8e-243], (-U), If[LessEqual[J, 3.1e-229], U, If[LessEqual[J, 3.7e+99], (-U), N[(-2.0 * J), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2.1 \cdot 10^{+64}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 3.1 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 3.7 \cdot 10^{+99}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.1e64 or 3.7000000000000001e99 < J

    1. Initial program 97.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. Step-by-step derivation
      1. *-commutative97.8%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*97.8%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.8%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around inf 46.0%

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

    if -2.1e64 < J < -9.999999999999969e-311 or 5.79999999999999953e-243 < J < 3.1000000000000001e-229

    1. Initial program 48.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. Step-by-step derivation
      1. *-commutative48.8%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*48.8%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def77.6%

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

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

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

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

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

    if -9.999999999999969e-311 < J < 5.79999999999999953e-243 or 3.1000000000000001e-229 < J < 3.7000000000000001e99

    1. Initial program 61.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. Step-by-step derivation
      1. *-commutative61.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*61.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def80.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.1 \cdot 10^{+64}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 3.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.7 \cdot 10^{+99}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 11: 49.5% accurate, 31.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -4.8 \cdot 10^{+40}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.6 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.2 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.9 \cdot 10^{+101}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J -4.8e+40)
   (* J (+ -2.0 (* 0.25 (* K K))))
   (if (<= J -1e-310)
     U
     (if (<= J 4.6e-243)
       (- U)
       (if (<= J 2.2e-229) U (if (<= J 1.9e+101) (- U) (* -2.0 J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -4.8e+40) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 4.6e-243) {
		tmp = -U;
	} else if (J <= 2.2e-229) {
		tmp = U;
	} else if (J <= 1.9e+101) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-4.8d+40)) then
        tmp = j * ((-2.0d0) + (0.25d0 * (k * k)))
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 4.6d-243) then
        tmp = -u
    else if (j <= 2.2d-229) then
        tmp = u
    else if (j <= 1.9d+101) then
        tmp = -u
    else
        tmp = (-2.0d0) * j
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -4.8e+40) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 4.6e-243) {
		tmp = -U;
	} else if (J <= 2.2e-229) {
		tmp = U;
	} else if (J <= 1.9e+101) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -4.8e+40:
		tmp = J * (-2.0 + (0.25 * (K * K)))
	elif J <= -1e-310:
		tmp = U
	elif J <= 4.6e-243:
		tmp = -U
	elif J <= 2.2e-229:
		tmp = U
	elif J <= 1.9e+101:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -4.8e+40)
		tmp = Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K))));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 4.6e-243)
		tmp = Float64(-U);
	elseif (J <= 2.2e-229)
		tmp = U;
	elseif (J <= 1.9e+101)
		tmp = Float64(-U);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -4.8e+40)
		tmp = J * (-2.0 + (0.25 * (K * K)));
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 4.6e-243)
		tmp = -U;
	elseif (J <= 2.2e-229)
		tmp = U;
	elseif (J <= 1.9e+101)
		tmp = -U;
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -4.8e+40], N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -1e-310], U, If[LessEqual[J, 4.6e-243], (-U), If[LessEqual[J, 2.2e-229], U, If[LessEqual[J, 1.9e+101], (-U), N[(-2.0 * J), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -4.8 \cdot 10^{+40}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 4.6 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.2 \cdot 10^{-229}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.9 \cdot 10^{+101}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -4.8e40

    1. Initial program 95.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. *-commutative95.2%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative45.7%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*45.7%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out45.7%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow245.7%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified45.7%

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

    if -4.8e40 < J < -9.999999999999969e-311 or 4.6e-243 < J < 2.1999999999999999e-229

    1. Initial program 44.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. Step-by-step derivation
      1. *-commutative44.4%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*44.4%

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < J < 4.6e-243 or 2.1999999999999999e-229 < J < 1.8999999999999999e101

    1. Initial program 61.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. Step-by-step derivation
      1. *-commutative61.0%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*61.0%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def80.0%

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

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

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

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

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

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

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

    if 1.8999999999999999e101 < J

    1. Initial program 99.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. Step-by-step derivation
      1. *-commutative99.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*99.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    7. Taylor expanded in J around inf 41.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -4.8 \cdot 10^{+40}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.6 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.2 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.9 \cdot 10^{+101}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 12: 39.1% accurate, 51.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq 10^{-308}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J 1e-308) U (if (<= J 5.8e-243) (- U) (if (<= J 2.1e-229) U (- U)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= 1e-308) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= 1d-308) then
        tmp = u
    else if (j <= 5.8d-243) then
        tmp = -u
    else if (j <= 2.1d-229) then
        tmp = u
    else
        tmp = -u
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= 1e-308) {
		tmp = U;
	} else if (J <= 5.8e-243) {
		tmp = -U;
	} else if (J <= 2.1e-229) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= 1e-308:
		tmp = U
	elif J <= 5.8e-243:
		tmp = -U
	elif J <= 2.1e-229:
		tmp = U
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= 1e-308)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = Float64(-U);
	elseif (J <= 2.1e-229)
		tmp = U;
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= 1e-308)
		tmp = U;
	elseif (J <= 5.8e-243)
		tmp = -U;
	elseif (J <= 2.1e-229)
		tmp = U;
	else
		tmp = -U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, 1e-308], U, If[LessEqual[J, 5.8e-243], (-U), If[LessEqual[J, 2.1e-229], U, (-U)]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq 10^{-308}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 9.9999999999999991e-309 or 5.79999999999999953e-243 < J < 2.09999999999999983e-229

    1. Initial program 67.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. Step-by-step derivation
      1. *-commutative67.1%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*67.1%

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

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

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

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

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

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

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

    if 9.9999999999999991e-309 < J < 5.79999999999999953e-243 or 2.09999999999999983e-229 < J

    1. Initial program 73.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. Step-by-step derivation
      1. *-commutative73.6%

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*73.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 10^{-308}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-243}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{-229}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 13: 26.6% accurate, 420.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ U \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 U)
U = abs(U);
double code(double J, double K, double U) {
	return U;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	return U;
}
U = abs(U)
def code(J, K, U):
	return U
U = abs(U)
function code(J, K, U)
	return U
end
U = abs(U)
function tmp = code(J, K, U)
	tmp = U;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := U
\begin{array}{l}
U = |U|\\
\\
U
\end{array}
Derivation
  1. Initial program 70.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. Step-by-step derivation
    1. *-commutative70.3%

      \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*70.3%

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

      \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
    4. hypot-1-def86.3%

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification30.3%

    \[\leadsto U \]

Reproduce

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