Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.5% → 98.8%
Time: 18.1s
Alternatives: 10
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 73.5% 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: 98.8% accurate, 0.4× speedup?

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

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+297}:\\
\;\;\;\;-2 \cdot \left(t_1 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_1}\right)\right)\\

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


\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.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. Simplified49.5%

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

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

    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)))) < 2e297

    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. associate-*l*99.8%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. unpow299.8%

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

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

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

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

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

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

    if 2e297 < (*.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 6.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. Simplified49.5%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative54.6%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified54.6%

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

    \[\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:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \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 2 \cdot 10^{+297}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \end{array} \]

Alternative 2: 88.1% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ -2 \cdot \left(J \cdot \left(t_0 \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))))
   (* -2.0 (* J (* t_0 (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return -2.0 * (J * (t_0 * Math.hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return -2.0 * (J * (t_0 * math.hypot(1.0, (U / (J * (2.0 * t_0))))))
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(-2.0 * Float64(J * Float64(t_0 * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(J * N[(t$95$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)\\
-2 \cdot \left(J \cdot \left(t_0 \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 72.7%

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

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

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

Alternative 3: 77.2% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;J \leq 3.8 \cdot 10^{-147}:\\
\;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -5.1999999999999997e-52 or 3.80000000000000028e-147 < J

    1. Initial program 88.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. associate-*l*88.2%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative88.2%

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

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

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

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

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

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

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

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

    if -5.1999999999999997e-52 < J < 8.0000000000000003e-309

    1. Initial program 50.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. Simplified73.6%

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

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

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

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

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

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

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

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

        \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U - \frac{{J}^{2}}{U}\right)} \]
      4. *-commutative41.7%

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

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

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

    if 8.0000000000000003e-309 < J < 3.80000000000000028e-147

    1. Initial program 45.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. Simplified59.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.2 \cdot 10^{-52}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\ \mathbf{elif}\;J \leq 8 \cdot 10^{-309}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 3.8 \cdot 10^{-147}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\ \end{array} \]

Alternative 4: 64.1% accurate, 3.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{if}\;J \leq -6.1 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.7 \cdot 10^{-144}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 125000000 \lor \neg \left(J \leq 3.5 \cdot 10^{+153}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \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
 (let* ((t_0 (* -2.0 (* J (cos (/ K 2.0))))))
   (if (<= J -6.1e+16)
     t_0
     (if (<= J -4e-310)
       (* -2.0 (* U -0.5))
       (if (<= J 1.7e-144)
         (* -2.0 (* U 0.5))
         (if (or (<= J 125000000.0) (not (<= J 3.5e+153)))
           t_0
           (* -2.0 (* J (sqrt (+ 1.0 (* 0.25 (* (/ U J) (/ U J)))))))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * cos((K / 2.0)));
	double tmp;
	if (J <= -6.1e+16) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.7e-144) {
		tmp = -2.0 * (U * 0.5);
	} else if ((J <= 125000000.0) || !(J <= 3.5e+153)) {
		tmp = t_0;
	} else {
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / 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 = (-2.0d0) * (j * cos((k / 2.0d0)))
    if (j <= (-6.1d+16)) then
        tmp = t_0
    else if (j <= (-4d-310)) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 1.7d-144) then
        tmp = (-2.0d0) * (u * 0.5d0)
    else if ((j <= 125000000.0d0) .or. (.not. (j <= 3.5d+153))) then
        tmp = t_0
    else
        tmp = (-2.0d0) * (j * sqrt((1.0d0 + (0.25d0 * ((u / j) * (u / j))))))
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * Math.cos((K / 2.0)));
	double tmp;
	if (J <= -6.1e+16) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.7e-144) {
		tmp = -2.0 * (U * 0.5);
	} else if ((J <= 125000000.0) || !(J <= 3.5e+153)) {
		tmp = t_0;
	} else {
		tmp = -2.0 * (J * Math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (J * math.cos((K / 2.0)))
	tmp = 0
	if J <= -6.1e+16:
		tmp = t_0
	elif J <= -4e-310:
		tmp = -2.0 * (U * -0.5)
	elif J <= 1.7e-144:
		tmp = -2.0 * (U * 0.5)
	elif (J <= 125000000.0) or not (J <= 3.5e+153):
		tmp = t_0
	else:
		tmp = -2.0 * (J * math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))))
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * cos(Float64(K / 2.0))))
	tmp = 0.0
	if (J <= -6.1e+16)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 1.7e-144)
		tmp = Float64(-2.0 * Float64(U * 0.5));
	elseif ((J <= 125000000.0) || !(J <= 3.5e+153))
		tmp = t_0;
	else
		tmp = Float64(-2.0 * Float64(J * sqrt(Float64(1.0 + Float64(0.25 * Float64(Float64(U / J) * Float64(U / J)))))));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * (J * cos((K / 2.0)));
	tmp = 0.0;
	if (J <= -6.1e+16)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 1.7e-144)
		tmp = -2.0 * (U * 0.5);
	elseif ((J <= 125000000.0) || ~((J <= 3.5e+153)))
		tmp = t_0;
	else
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(-2.0 * N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.1e+16], t$95$0, If[LessEqual[J, -4e-310], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.7e-144], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[J, 125000000.0], N[Not[LessEqual[J, 3.5e+153]], $MachinePrecision]], t$95$0, N[(-2.0 * N[(J * N[Sqrt[N[(1.0 + N[(0.25 * N[(N[(U / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\
\mathbf{if}\;J \leq -6.1 \cdot 10^{+16}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;J \leq 125000000 \lor \neg \left(J \leq 3.5 \cdot 10^{+153}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -6.1e16 or 1.70000000000000009e-144 < J < 1.25e8 or 3.4999999999999999e153 < J

    1. Initial program 91.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. associate-*l*91.2%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative91.2%

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

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

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

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

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

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

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

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

    if -6.1e16 < J < -3.999999999999988e-310

    1. Initial program 51.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. Simplified77.0%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative38.1%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified38.1%

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

    if -3.999999999999988e-310 < J < 1.70000000000000009e-144

    1. Initial program 45.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. Simplified59.8%

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

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

    if 1.25e8 < J < 3.4999999999999999e153

    1. Initial program 95.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. Simplified99.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6.1 \cdot 10^{+16}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.7 \cdot 10^{-144}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 125000000 \lor \neg \left(J \leq 3.5 \cdot 10^{+153}\right):\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \end{array} \]

Alternative 5: 64.2% accurate, 3.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := -2 \cdot \left(J \cdot t_0\right)\\ \mathbf{if}\;J \leq -1.15 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3 \cdot 10^{-144}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 106000000:\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \left(J + 0.125 \cdot \frac{U \cdot U}{J}\right)\right)\\ \mathbf{elif}\;J \leq 2.7 \cdot 10^{+153}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \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 (cos (/ K 2.0))) (t_1 (* -2.0 (* J t_0))))
   (if (<= J -1.15e+18)
     t_1
     (if (<= J -4e-310)
       (* -2.0 (* U -0.5))
       (if (<= J 3e-144)
         (* -2.0 (* U 0.5))
         (if (<= J 106000000.0)
           (* -2.0 (* t_0 (+ J (* 0.125 (/ (* U U) J)))))
           (if (<= J 2.7e+153)
             (* -2.0 (* J (sqrt (+ 1.0 (* 0.25 (* (/ U J) (/ U J)))))))
             t_1)))))))
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);
	double tmp;
	if (J <= -1.15e+18) {
		tmp = t_1;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 3e-144) {
		tmp = -2.0 * (U * 0.5);
	} else if (J <= 106000000.0) {
		tmp = -2.0 * (t_0 * (J + (0.125 * ((U * U) / J))));
	} else if (J <= 2.7e+153) {
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} 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 = cos((k / 2.0d0))
    t_1 = (-2.0d0) * (j * t_0)
    if (j <= (-1.15d+18)) then
        tmp = t_1
    else if (j <= (-4d-310)) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 3d-144) then
        tmp = (-2.0d0) * (u * 0.5d0)
    else if (j <= 106000000.0d0) then
        tmp = (-2.0d0) * (t_0 * (j + (0.125d0 * ((u * u) / j))))
    else if (j <= 2.7d+153) then
        tmp = (-2.0d0) * (j * sqrt((1.0d0 + (0.25d0 * ((u / j) * (u / j))))))
    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 = Math.cos((K / 2.0));
	double t_1 = -2.0 * (J * t_0);
	double tmp;
	if (J <= -1.15e+18) {
		tmp = t_1;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 3e-144) {
		tmp = -2.0 * (U * 0.5);
	} else if (J <= 106000000.0) {
		tmp = -2.0 * (t_0 * (J + (0.125 * ((U * U) / J))));
	} else if (J <= 2.7e+153) {
		tmp = -2.0 * (J * Math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = -2.0 * (J * t_0)
	tmp = 0
	if J <= -1.15e+18:
		tmp = t_1
	elif J <= -4e-310:
		tmp = -2.0 * (U * -0.5)
	elif J <= 3e-144:
		tmp = -2.0 * (U * 0.5)
	elif J <= 106000000.0:
		tmp = -2.0 * (t_0 * (J + (0.125 * ((U * U) / J))))
	elif J <= 2.7e+153:
		tmp = -2.0 * (J * math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))))
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(-2.0 * Float64(J * t_0))
	tmp = 0.0
	if (J <= -1.15e+18)
		tmp = t_1;
	elseif (J <= -4e-310)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 3e-144)
		tmp = Float64(-2.0 * Float64(U * 0.5));
	elseif (J <= 106000000.0)
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J + Float64(0.125 * Float64(Float64(U * U) / J)))));
	elseif (J <= 2.7e+153)
		tmp = Float64(-2.0 * Float64(J * sqrt(Float64(1.0 + Float64(0.25 * Float64(Float64(U / J) * Float64(U / J)))))));
	else
		tmp = t_1;
	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);
	tmp = 0.0;
	if (J <= -1.15e+18)
		tmp = t_1;
	elseif (J <= -4e-310)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 3e-144)
		tmp = -2.0 * (U * 0.5);
	elseif (J <= 106000000.0)
		tmp = -2.0 * (t_0 * (J + (0.125 * ((U * U) / J))));
	elseif (J <= 2.7e+153)
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	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[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.15e+18], t$95$1, If[LessEqual[J, -4e-310], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 3e-144], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 106000000.0], N[(-2.0 * N[(t$95$0 * N[(J + N[(0.125 * N[(N[(U * U), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 2.7e+153], N[(-2.0 * N[(J * N[Sqrt[N[(1.0 + N[(0.25 * N[(N[(U / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := -2 \cdot \left(J \cdot t_0\right)\\
\mathbf{if}\;J \leq -1.15 \cdot 10^{+18}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;J \leq 3 \cdot 10^{-144}:\\
\;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\

\mathbf{elif}\;J \leq 106000000:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J + 0.125 \cdot \frac{U \cdot U}{J}\right)\right)\\

\mathbf{elif}\;J \leq 2.7 \cdot 10^{+153}:\\
\;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if J < -1.15e18 or 2.7000000000000001e153 < J

    1. Initial program 98.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. associate-*l*98.8%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative98.8%

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

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

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

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

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

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

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

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

    if -1.15e18 < J < -3.999999999999988e-310

    1. Initial program 51.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. Simplified77.0%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative38.1%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified38.1%

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

    if -3.999999999999988e-310 < J < 2.9999999999999999e-144

    1. Initial program 45.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. Simplified59.8%

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

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

    if 2.9999999999999999e-144 < J < 1.06e8

    1. Initial program 70.0%

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

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative70.0%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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)}}}\right) \]
      5. sqr-neg70.0%

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

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

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

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

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

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

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

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

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

    if 1.06e8 < J < 2.7000000000000001e153

    1. Initial program 95.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. Simplified99.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.15 \cdot 10^{+18}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3 \cdot 10^{-144}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 106000000:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J + 0.125 \cdot \frac{U \cdot U}{J}\right)\right)\\ \mathbf{elif}\;J \leq 2.7 \cdot 10^{+153}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \end{array} \]

Alternative 6: 65.2% accurate, 3.7× speedup?

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

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

\mathbf{elif}\;J \leq 3 \cdot 10^{-144}:\\
\;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -4.2e19 or 2.9999999999999999e-144 < J

    1. Initial program 92.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. associate-*l*92.0%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative92.0%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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)}}}\right) \]
      5. sqr-neg92.0%

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

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

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

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

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

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

    if -4.2e19 < J < -3.999999999999988e-310

    1. Initial program 51.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. Simplified77.0%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative38.1%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified38.1%

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

    if -3.999999999999988e-310 < J < 2.9999999999999999e-144

    1. Initial program 45.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. Simplified59.8%

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

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

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

Alternative 7: 53.5% accurate, 19.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \left(1 + -0.5 \cdot \frac{U}{J}\right)\right)\\ \mathbf{if}\;J \leq -2.3 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3 \cdot 10^{-144} \lor \neg \left(J \leq 4.2 \cdot 10^{-82}\right) \land J \leq 2.9 \cdot 10^{+68}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* -2.0 (* J (+ 1.0 (* -0.5 (/ U J)))))))
   (if (<= J -2.3e-33)
     t_0
     (if (<= J -4e-310)
       (* -2.0 (* U -0.5))
       (if (or (<= J 3e-144) (and (not (<= J 4.2e-82)) (<= J 2.9e+68)))
         (* -2.0 (* U 0.5))
         t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * (1.0 + (-0.5 * (U / J))));
	double tmp;
	if (J <= -2.3e-33) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if ((J <= 3e-144) || (!(J <= 4.2e-82) && (J <= 2.9e+68))) {
		tmp = -2.0 * (U * 0.5);
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-2.0d0) * (j * (1.0d0 + ((-0.5d0) * (u / j))))
    if (j <= (-2.3d-33)) then
        tmp = t_0
    else if (j <= (-4d-310)) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if ((j <= 3d-144) .or. (.not. (j <= 4.2d-82)) .and. (j <= 2.9d+68)) then
        tmp = (-2.0d0) * (u * 0.5d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * (1.0 + (-0.5 * (U / J))));
	double tmp;
	if (J <= -2.3e-33) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = -2.0 * (U * -0.5);
	} else if ((J <= 3e-144) || (!(J <= 4.2e-82) && (J <= 2.9e+68))) {
		tmp = -2.0 * (U * 0.5);
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (J * (1.0 + (-0.5 * (U / J))))
	tmp = 0
	if J <= -2.3e-33:
		tmp = t_0
	elif J <= -4e-310:
		tmp = -2.0 * (U * -0.5)
	elif (J <= 3e-144) or (not (J <= 4.2e-82) and (J <= 2.9e+68)):
		tmp = -2.0 * (U * 0.5)
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * Float64(1.0 + Float64(-0.5 * Float64(U / J)))))
	tmp = 0.0
	if (J <= -2.3e-33)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif ((J <= 3e-144) || (!(J <= 4.2e-82) && (J <= 2.9e+68)))
		tmp = Float64(-2.0 * Float64(U * 0.5));
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * (J * (1.0 + (-0.5 * (U / J))));
	tmp = 0.0;
	if (J <= -2.3e-33)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = -2.0 * (U * -0.5);
	elseif ((J <= 3e-144) || (~((J <= 4.2e-82)) && (J <= 2.9e+68)))
		tmp = -2.0 * (U * 0.5);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(-2.0 * N[(J * N[(1.0 + N[(-0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -2.3e-33], t$95$0, If[LessEqual[J, -4e-310], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[J, 3e-144], And[N[Not[LessEqual[J, 4.2e-82]], $MachinePrecision], LessEqual[J, 2.9e+68]]], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \left(1 + -0.5 \cdot \frac{U}{J}\right)\right)\\
\mathbf{if}\;J \leq -2.3 \cdot 10^{-33}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 3 \cdot 10^{-144} \lor \neg \left(J \leq 4.2 \cdot 10^{-82}\right) \land J \leq 2.9 \cdot 10^{+68}:\\
\;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.29999999999999986e-33 or 2.9999999999999999e-144 < J < 4.2000000000000001e-82 or 2.90000000000000011e68 < J

    1. Initial program 93.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. Simplified98.3%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)} \]
    3. Step-by-step derivation
      1. expm1-log1p-u90.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{0.5 \cdot \frac{U}{J}}{\cos \left(K \cdot 0.5\right)}\right)\right)\right)\right)}} - 1\right)\right) \]
      4. add-exp-log90.1%

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

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

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

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

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

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

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

    if -2.29999999999999986e-33 < J < -3.999999999999988e-310

    1. Initial program 49.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. Simplified72.8%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative41.7%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified41.7%

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

    if -3.999999999999988e-310 < J < 2.9999999999999999e-144 or 4.2000000000000001e-82 < J < 2.90000000000000011e68

    1. Initial program 58.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. Simplified74.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.3 \cdot 10^{-33}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + -0.5 \cdot \frac{U}{J}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3 \cdot 10^{-144} \lor \neg \left(J \leq 4.2 \cdot 10^{-82}\right) \land J \leq 2.9 \cdot 10^{+68}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + -0.5 \cdot \frac{U}{J}\right)\right)\\ \end{array} \]

Alternative 8: 49.5% accurate, 37.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -5.6e20 or 2.20000000000000001e43 < J

    1. Initial program 98.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. associate-*l*98.0%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative98.0%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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)}}}\right) \]
      5. sqr-neg98.0%

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

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

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

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

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

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

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

    if -5.6e20 < J < -3.999999999999988e-310

    1. Initial program 51.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. Simplified77.0%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative38.1%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified38.1%

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

    if -3.999999999999988e-310 < J < 2.20000000000000001e43

    1. Initial program 60.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.6 \cdot 10^{+20}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 2.2 \cdot 10^{+43}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 40.3% accurate, 46.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -5.6000000000000003e28 or 1.94999999999999997e56 < J

    1. Initial program 98.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. associate-*l*98.0%

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

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. *-commutative98.0%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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)}}}\right) \]
      5. sqr-neg98.0%

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

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

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

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

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

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

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

    if -5.6000000000000003e28 < J < 1.94999999999999997e56

    1. Initial program 57.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. Simplified76.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.6 \cdot 10^{+28}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 1.95 \cdot 10^{+56}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 10: 30.1% accurate, 140.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ -2 \cdot J \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 (* -2.0 J))
U = abs(U);
double code(double J, double K, double U) {
	return -2.0 * J;
}
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 = (-2.0d0) * j
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	return -2.0 * J;
}
U = abs(U)
def code(J, K, U):
	return -2.0 * J
U = abs(U)
function code(J, K, U)
	return Float64(-2.0 * J)
end
U = abs(U)
function tmp = code(J, K, U)
	tmp = -2.0 * J;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := N[(-2.0 * J), $MachinePrecision]
\begin{array}{l}
U = |U|\\
\\
-2 \cdot J
\end{array}
Derivation
  1. Initial program 72.7%

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
    3. *-commutative72.7%

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

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

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

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

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

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

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

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

    \[\leadsto -2 \cdot \color{blue}{J} \]
  6. Final simplification31.5%

    \[\leadsto -2 \cdot J \]

Reproduce

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