Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 74.3% → 99.2%
Time: 13.1s
Alternatives: 10
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 10 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: 74.3% 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.2% accurate, 0.4× 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 5 \cdot 10^{+300}:\\ \;\;\;\;\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)\\ \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 5e+300)
       (* (* J (* -2.0 t_0)) (hypot 1.0 (/ U (* J (* 2.0 t_0)))))
       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 <= 5e+300) {
		tmp = (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
	} 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 <= 5e+300) {
		tmp = (J * (-2.0 * t_0)) * Math.hypot(1.0, (U / (J * (2.0 * t_0))));
	} 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 <= 5e+300:
		tmp = (J * (-2.0 * t_0)) * math.hypot(1.0, (U / (J * (2.0 * t_0))))
	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 <= 5e+300)
		tmp = Float64(Float64(J * Float64(-2.0 * t_0)) * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))));
	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 <= 5e+300)
		tmp = (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
	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, 5e+300], 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], 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 5 \cdot 10^{+300}:\\
\;\;\;\;\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)\\

\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 6.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. *-commutative6.3%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*6.3%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def58.8%

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

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

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

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

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

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

      \[\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)))) < 5.00000000000000026e300

    1. Initial program 99.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. *-commutative99.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*99.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. unpow299.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)} \]

    if 5.00000000000000026e300 < (*.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 8.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*8.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def73.2%

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

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

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

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

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

    \[\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 5 \cdot 10^{+300}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 88.6% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ J \cdot \left(t_0 \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\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 (* t_0 (* -2.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 * (t_0 * (-2.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 * (t_0 * (-2.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 * (t_0 * (-2.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(J * Float64(t_0 * Float64(-2.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 * (t_0 * (-2.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[(J * N[(t$95$0 * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
J \cdot \left(t_0 \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 74.9%

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

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
    5. associate-*l*74.8%

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

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

      \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
    8. hypot-1-def90.3%

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

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

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

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

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

Alternative 3: 73.9% accurate, 1.9× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 2.65e182

    1. Initial program 78.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. *-commutative78.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*78.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. unpow278.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-def93.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. *-commutative93.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*93.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. Simplified93.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 K around 0 78.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}{2 \cdot J}}\right) \]

    if 2.65e182 < U

    1. Initial program 48.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. *-commutative48.3%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*48.2%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def65.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U}} - U \]
    8. Step-by-step derivation
      1. unpow245.5%

        \[\leadsto -2 \cdot \frac{\color{blue}{J \cdot J}}{U} - U \]
      2. associate-/l*52.2%

        \[\leadsto -2 \cdot \color{blue}{\frac{J}{\frac{U}{J}}} - U \]
      3. associate-/r/52.2%

        \[\leadsto -2 \cdot \color{blue}{\left(\frac{J}{U} \cdot J\right)} - U \]
    9. Simplified52.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 2.65 \cdot 10^{+182}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U}\right) - U\\ \end{array} \]

Alternative 4: 69.7% accurate, 2.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K 2)) < 0.52000000000000002

    1. Initial program 77.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. *-commutative77.6%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*77.6%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def91.5%

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

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

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

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

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

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

    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 \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      2. associate-*l*73.6%

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*73.6%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def89.8%

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

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

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

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

      \[\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. associate-*r*40.2%

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

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

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

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

        \[\leadsto \left(-2 \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) \cdot J \]
      2. hypot-1-def40.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.52:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\\ \end{array} \]

Alternative 5: 66.4% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \frac{J}{U}\\ t_1 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -1.25 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot t_0\\ \mathbf{elif}\;J \leq 2.3 \cdot 10^{-10}:\\ \;\;\;\;-2 \cdot t_0 - U\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (/ J U))) (t_1 (* J (* -2.0 (cos (* K 0.5))))))
   (if (<= J -1.25e-24)
     t_1
     (if (<= J -2e-310)
       (+ U (* 2.0 t_0))
       (if (<= J 2.3e-10) (- (* -2.0 t_0) U) t_1)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (J / U);
	double t_1 = J * (-2.0 * cos((K * 0.5)));
	double tmp;
	if (J <= -1.25e-24) {
		tmp = t_1;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * t_0);
	} else if (J <= 2.3e-10) {
		tmp = (-2.0 * t_0) - U;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = j * (j / u)
    t_1 = j * ((-2.0d0) * cos((k * 0.5d0)))
    if (j <= (-1.25d-24)) then
        tmp = t_1
    else if (j <= (-2d-310)) then
        tmp = u + (2.0d0 * t_0)
    else if (j <= 2.3d-10) then
        tmp = ((-2.0d0) * t_0) - u
    else
        tmp = t_1
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = J * (J / U);
	double t_1 = J * (-2.0 * Math.cos((K * 0.5)));
	double tmp;
	if (J <= -1.25e-24) {
		tmp = t_1;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * t_0);
	} else if (J <= 2.3e-10) {
		tmp = (-2.0 * t_0) - U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (J / U)
	t_1 = J * (-2.0 * math.cos((K * 0.5)))
	tmp = 0
	if J <= -1.25e-24:
		tmp = t_1
	elif J <= -2e-310:
		tmp = U + (2.0 * t_0)
	elif J <= 2.3e-10:
		tmp = (-2.0 * t_0) - U
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(J / U))
	t_1 = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))))
	tmp = 0.0
	if (J <= -1.25e-24)
		tmp = t_1;
	elseif (J <= -2e-310)
		tmp = Float64(U + Float64(2.0 * t_0));
	elseif (J <= 2.3e-10)
		tmp = Float64(Float64(-2.0 * t_0) - U);
	else
		tmp = t_1;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (J / U);
	t_1 = J * (-2.0 * cos((K * 0.5)));
	tmp = 0.0;
	if (J <= -1.25e-24)
		tmp = t_1;
	elseif (J <= -2e-310)
		tmp = U + (2.0 * t_0);
	elseif (J <= 2.3e-10)
		tmp = (-2.0 * t_0) - U;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(J * N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.25e-24], t$95$1, If[LessEqual[J, -2e-310], N[(U + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 2.3e-10], N[(N[(-2.0 * t$95$0), $MachinePrecision] - U), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \frac{J}{U}\\
t_1 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{if}\;J \leq -1.25 \cdot 10^{-24}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U + 2 \cdot t_0\\

\mathbf{elif}\;J \leq 2.3 \cdot 10^{-10}:\\
\;\;\;\;-2 \cdot t_0 - U\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.24999999999999995e-24 or 2.30000000000000007e-10 < J

    1. Initial program 93.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. *-commutative93.1%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*93.1%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def99.8%

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

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

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

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

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

    if -1.24999999999999995e-24 < J < -1.999999999999994e-310

    1. Initial program 53.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. *-commutative53.7%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*53.6%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def78.8%

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

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

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

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

      \[\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. associate-*r*23.1%

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{J}^{2}}{U} + U} \]
    8. Step-by-step derivation
      1. fma-def40.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{{J}^{2}}{U}, U\right)} \]
      2. unpow240.0%

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{J}{\frac{U}{J}}}, U\right) \]
    9. Simplified40.0%

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

        \[\leadsto \color{blue}{2 \cdot \frac{J}{\frac{U}{J}} + U} \]
      2. div-inv40.0%

        \[\leadsto 2 \cdot \color{blue}{\left(J \cdot \frac{1}{\frac{U}{J}}\right)} + U \]
      3. clear-num40.0%

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

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

    if -1.999999999999994e-310 < J < 2.30000000000000007e-10

    1. Initial program 53.9%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*53.9%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def79.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U}} - U \]
    8. Step-by-step derivation
      1. unpow238.6%

        \[\leadsto -2 \cdot \frac{\color{blue}{J \cdot J}}{U} - U \]
      2. associate-/l*38.6%

        \[\leadsto -2 \cdot \color{blue}{\frac{J}{\frac{U}{J}}} - U \]
      3. associate-/r/38.6%

        \[\leadsto -2 \cdot \color{blue}{\left(\frac{J}{U} \cdot J\right)} - U \]
    9. Simplified38.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.25 \cdot 10^{-24}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 2.3 \cdot 10^{-10}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U}\right) - U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 49.7% accurate, 27.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \frac{J}{U}\\ \mathbf{if}\;J \leq -1.8 \cdot 10^{-21}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot t_0\\ \mathbf{elif}\;J \leq 10^{+35}:\\ \;\;\;\;-2 \cdot t_0 - 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
 (let* ((t_0 (* J (/ J U))))
   (if (<= J -1.8e-21)
     (* -2.0 J)
     (if (<= J -2e-310)
       (+ U (* 2.0 t_0))
       (if (<= J 1e+35) (- (* -2.0 t_0) U) (* -2.0 J))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (J / U);
	double tmp;
	if (J <= -1.8e-21) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * t_0);
	} else if (J <= 1e+35) {
		tmp = (-2.0 * t_0) - 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) :: t_0
    real(8) :: tmp
    t_0 = j * (j / u)
    if (j <= (-1.8d-21)) then
        tmp = (-2.0d0) * j
    else if (j <= (-2d-310)) then
        tmp = u + (2.0d0 * t_0)
    else if (j <= 1d+35) then
        tmp = ((-2.0d0) * t_0) - 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 t_0 = J * (J / U);
	double tmp;
	if (J <= -1.8e-21) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * t_0);
	} else if (J <= 1e+35) {
		tmp = (-2.0 * t_0) - U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (J / U)
	tmp = 0
	if J <= -1.8e-21:
		tmp = -2.0 * J
	elif J <= -2e-310:
		tmp = U + (2.0 * t_0)
	elif J <= 1e+35:
		tmp = (-2.0 * t_0) - U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(J / U))
	tmp = 0.0
	if (J <= -1.8e-21)
		tmp = Float64(-2.0 * J);
	elseif (J <= -2e-310)
		tmp = Float64(U + Float64(2.0 * t_0));
	elseif (J <= 1e+35)
		tmp = Float64(Float64(-2.0 * t_0) - U);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (J / U);
	tmp = 0.0;
	if (J <= -1.8e-21)
		tmp = -2.0 * J;
	elseif (J <= -2e-310)
		tmp = U + (2.0 * t_0);
	elseif (J <= 1e+35)
		tmp = (-2.0 * t_0) - U;
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.8e-21], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -2e-310], N[(U + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1e+35], N[(N[(-2.0 * t$95$0), $MachinePrecision] - U), $MachinePrecision], N[(-2.0 * J), $MachinePrecision]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \frac{J}{U}\\
\mathbf{if}\;J \leq -1.8 \cdot 10^{-21}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U + 2 \cdot t_0\\

\mathbf{elif}\;J \leq 10^{+35}:\\
\;\;\;\;-2 \cdot t_0 - U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.79999999999999995e-21 or 9.9999999999999997e34 < J

    1. Initial program 96.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. *-commutative96.2%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*96.2%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def99.8%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)} \]
    4. Taylor expanded in K around 0 38.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. associate-*r*38.9%

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

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

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

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

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

    if -1.79999999999999995e-21 < J < -1.999999999999994e-310

    1. Initial program 53.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. *-commutative53.7%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*53.6%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def78.8%

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

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

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

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

      \[\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. associate-*r*23.1%

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{J}^{2}}{U} + U} \]
    8. Step-by-step derivation
      1. fma-def40.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{{J}^{2}}{U}, U\right)} \]
      2. unpow240.0%

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{J}{\frac{U}{J}}}, U\right) \]
    9. Simplified40.0%

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

        \[\leadsto \color{blue}{2 \cdot \frac{J}{\frac{U}{J}} + U} \]
      2. div-inv40.0%

        \[\leadsto 2 \cdot \color{blue}{\left(J \cdot \frac{1}{\frac{U}{J}}\right)} + U \]
      3. clear-num40.0%

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

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

    if -1.999999999999994e-310 < J < 9.9999999999999997e34

    1. Initial program 55.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*55.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def82.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U}} - U \]
    8. Step-by-step derivation
      1. unpow238.8%

        \[\leadsto -2 \cdot \frac{\color{blue}{J \cdot J}}{U} - U \]
      2. associate-/l*38.8%

        \[\leadsto -2 \cdot \color{blue}{\frac{J}{\frac{U}{J}}} - U \]
      3. associate-/r/38.8%

        \[\leadsto -2 \cdot \color{blue}{\left(\frac{J}{U} \cdot J\right)} - U \]
    9. Simplified38.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.8 \cdot 10^{-21}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 10^{+35}:\\ \;\;\;\;-2 \cdot \left(J \cdot \frac{J}{U}\right) - U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 7: 49.7% accurate, 32.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -1.1 \cdot 10^{-21}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\ \;\;\;\;-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 -1.1e-21)
   (* -2.0 J)
   (if (<= J -2e-310)
     (+ U (* 2.0 (* J (/ J U))))
     (if (<= J 1.15e+35) (- U) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -1.1e-21) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * (J * (J / U)));
	} else if (J <= 1.15e+35) {
		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 <= (-1.1d-21)) then
        tmp = (-2.0d0) * j
    else if (j <= (-2d-310)) then
        tmp = u + (2.0d0 * (j * (j / u)))
    else if (j <= 1.15d+35) 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 <= -1.1e-21) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U + (2.0 * (J * (J / U)));
	} else if (J <= 1.15e+35) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -1.1e-21:
		tmp = -2.0 * J
	elif J <= -2e-310:
		tmp = U + (2.0 * (J * (J / U)))
	elif J <= 1.15e+35:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -1.1e-21)
		tmp = Float64(-2.0 * J);
	elseif (J <= -2e-310)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(J / U))));
	elseif (J <= 1.15e+35)
		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 <= -1.1e-21)
		tmp = -2.0 * J;
	elseif (J <= -2e-310)
		tmp = U + (2.0 * (J * (J / U)));
	elseif (J <= 1.15e+35)
		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, -1.1e-21], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -2e-310], N[(U + N[(2.0 * N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.15e+35], (-U), N[(-2.0 * J), $MachinePrecision]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -1.1 \cdot 10^{-21}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.1e-21 or 1.1499999999999999e35 < J

    1. Initial program 96.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. *-commutative96.2%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*96.2%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def99.8%

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)} \]
    4. Taylor expanded in K around 0 38.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. associate-*r*38.9%

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

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

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

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

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

    if -1.1e-21 < J < -1.999999999999994e-310

    1. Initial program 53.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. *-commutative53.7%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*53.6%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def78.8%

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

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

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

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

      \[\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. associate-*r*23.1%

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{J}^{2}}{U} + U} \]
    8. Step-by-step derivation
      1. fma-def40.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{{J}^{2}}{U}, U\right)} \]
      2. unpow240.0%

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{J}{\frac{U}{J}}}, U\right) \]
    9. Simplified40.0%

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

        \[\leadsto \color{blue}{2 \cdot \frac{J}{\frac{U}{J}} + U} \]
      2. div-inv40.0%

        \[\leadsto 2 \cdot \color{blue}{\left(J \cdot \frac{1}{\frac{U}{J}}\right)} + U \]
      3. clear-num40.0%

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

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

    if -1.999999999999994e-310 < J < 1.1499999999999999e35

    1. Initial program 55.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*55.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def82.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.1 \cdot 10^{-21}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 8: 49.8% accurate, 45.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2.4 \cdot 10^{-15}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\ \;\;\;\;-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.4e-15)
   (* -2.0 J)
   (if (<= J -2e-310) U (if (<= J 1.15e+35) (- U) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.4e-15) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 1.15e+35) {
		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.4d-15)) then
        tmp = (-2.0d0) * j
    else if (j <= (-2d-310)) then
        tmp = u
    else if (j <= 1.15d+35) 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.4e-15) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 1.15e+35) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2.4e-15:
		tmp = -2.0 * J
	elif J <= -2e-310:
		tmp = U
	elif J <= 1.15e+35:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2.4e-15)
		tmp = Float64(-2.0 * J);
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 1.15e+35)
		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.4e-15)
		tmp = -2.0 * J;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 1.15e+35)
		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.4e-15], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -2e-310], U, If[LessEqual[J, 1.15e+35], (-U), N[(-2.0 * J), $MachinePrecision]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2.4 \cdot 10^{-15}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.39999999999999995e-15 or 1.1499999999999999e35 < J

    1. Initial program 96.9%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*96.9%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def99.8%

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

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

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

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

      \[\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. associate-*r*39.6%

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

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

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

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

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

    if -2.39999999999999995e-15 < J < -1.999999999999994e-310

    1. Initial program 53.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. *-commutative53.6%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*53.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def79.6%

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

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

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

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

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

    if -1.999999999999994e-310 < J < 1.1499999999999999e35

    1. Initial program 55.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*55.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def82.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.4 \cdot 10^{-15}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.15 \cdot 10^{+35}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 39.6% accurate, 103.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;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 -2e-310) U (- U)))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2e-310) {
		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 <= (-2d-310)) 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 <= -2e-310) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2e-310:
		tmp = U
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2e-310)
		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 <= -2e-310)
		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, -2e-310], U, (-U)]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

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


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

    1. Initial program 77.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. *-commutative77.6%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*77.5%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def90.5%

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

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

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

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

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

    if -1.999999999999994e-310 < J

    1. Initial program 72.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
      5. associate-*l*72.8%

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
      8. hypot-1-def90.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 10: 27.0% 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 74.9%

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

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot -2\right)} \]
    5. associate-*l*74.8%

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

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

      \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)}}}\right)\right) \]
    8. hypot-1-def90.3%

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

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

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

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

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

    \[\leadsto U \]

Reproduce

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