Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 72.7% → 99.7%
Time: 22.0s
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: 72.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.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 10^{+307}:\\ \;\;\;\;-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 1e+307)
       (* -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 <= 1e+307) {
		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 <= 1e+307) {
		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 <= 1e+307:
		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 <= 1e+307)
		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 <= 1e+307)
		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, 1e+307], 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 10^{+307}:\\
\;\;\;\;-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 5.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. Simplified55.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 47.8%

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

    1. Initial program 99.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    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 9.99999999999999986e306 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 8.5%

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

      \[\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 50.4%

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

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

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

    \[\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 10^{+307}:\\ \;\;\;\;-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: 87.6% 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 74.5%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Simplified90.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 simplification90.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: 73.7% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 3 \cdot 10^{+234}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\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
 (if (<= U 3e+234)
   (* -2.0 (* J (* (cos (/ K 2.0)) (hypot 1.0 (/ U (* J 2.0))))))
   (* -2.0 (* U 0.5))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 3e+234) {
		tmp = -2.0 * (J * (cos((K / 2.0)) * hypot(1.0, (U / (J * 2.0)))));
	} else {
		tmp = -2.0 * (U * 0.5);
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (U <= 3e+234) {
		tmp = -2.0 * (J * (Math.cos((K / 2.0)) * Math.hypot(1.0, (U / (J * 2.0)))));
	} else {
		tmp = -2.0 * (U * 0.5);
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 3e+234:
		tmp = -2.0 * (J * (math.cos((K / 2.0)) * math.hypot(1.0, (U / (J * 2.0)))))
	else:
		tmp = -2.0 * (U * 0.5)
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 3e+234)
		tmp = Float64(-2.0 * Float64(J * Float64(cos(Float64(K / 2.0)) * hypot(1.0, Float64(U / Float64(J * 2.0))))));
	else
		tmp = Float64(-2.0 * Float64(U * 0.5));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (U <= 3e+234)
		tmp = -2.0 * (J * (cos((K / 2.0)) * hypot(1.0, (U / (J * 2.0)))));
	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_] := If[LessEqual[U, 3e+234], N[(-2.0 * N[(J * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 3 \cdot 10^{+234}:\\
\;\;\;\;-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)\right)\\

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


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

    1. Initial program 77.4%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified92.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 K around 0 74.5%

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

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

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

    if 2.9999999999999999e234 < U

    1. Initial program 37.6%

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

      \[\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 52.7%

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

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

Alternative 4: 68.7% accurate, 2.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t_0 \leq 0.232:\\ \;\;\;\;-2 \cdot \left(J \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{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 (cos (/ K 2.0))))
   (if (<= t_0 0.232)
     (* -2.0 (* J t_0))
     (* -2.0 (* J (hypot 1.0 (/ (* U 0.5) J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.232) {
		tmp = -2.0 * (J * t_0);
	} else {
		tmp = -2.0 * (J * hypot(1.0, ((U * 0.5) / J)));
	}
	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 tmp;
	if (t_0 <= 0.232) {
		tmp = -2.0 * (J * t_0);
	} else {
		tmp = -2.0 * (J * Math.hypot(1.0, ((U * 0.5) / J)));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.232:
		tmp = -2.0 * (J * t_0)
	else:
		tmp = -2.0 * (J * math.hypot(1.0, ((U * 0.5) / J)))
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.232)
		tmp = Float64(-2.0 * Float64(J * t_0));
	else
		tmp = Float64(-2.0 * Float64(J * hypot(1.0, Float64(Float64(U * 0.5) / J))));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (t_0 <= 0.232)
		tmp = -2.0 * (J * t_0);
	else
		tmp = -2.0 * (J * hypot(1.0, ((U * 0.5) / J)));
	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]}, If[LessEqual[t$95$0, 0.232], N[(-2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.232:\\
\;\;\;\;-2 \cdot \left(J \cdot t_0\right)\\

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


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

    1. Initial program 75.1%

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

        \[\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*75.1%

        \[\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. *-commutative75.1%

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

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

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

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

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

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

      \[\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 53.7%

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

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

    1. Initial program 74.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. Simplified89.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 K around 0 46.6%

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

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

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

      \[\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. expm1-log1p-u46.0%

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)\right)}\right) \]
      2. expm1-udef46.0%

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} - 1\right)}\right) \]
      3. add-sqr-sqrt46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 63.6% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(U \cdot -0.5\right)\\ t_1 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ t_2 := -2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{if}\;J \leq -3.9 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -9 \cdot 10^{-82}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -1.05 \cdot 10^{-168}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq -3.4 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 1.1 \cdot 10^{-49}:\\ \;\;\;\;t_2\\ \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 (* -2.0 (* U -0.5)))
        (t_1 (* -2.0 (* J (cos (/ K 2.0)))))
        (t_2 (* -2.0 (* U 0.5))))
   (if (<= J -3.9e+57)
     t_1
     (if (<= J -9e-82)
       t_0
       (if (<= J -1.05e-168)
         t_2
         (if (<= J -3.4e-301) t_0 (if (<= J 1.1e-49) t_2 t_1)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (U * -0.5);
	double t_1 = -2.0 * (J * cos((K / 2.0)));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -3.9e+57) {
		tmp = t_1;
	} else if (J <= -9e-82) {
		tmp = t_0;
	} else if (J <= -1.05e-168) {
		tmp = t_2;
	} else if (J <= -3.4e-301) {
		tmp = t_0;
	} else if (J <= 1.1e-49) {
		tmp = t_2;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = (-2.0d0) * (u * (-0.5d0))
    t_1 = (-2.0d0) * (j * cos((k / 2.0d0)))
    t_2 = (-2.0d0) * (u * 0.5d0)
    if (j <= (-3.9d+57)) then
        tmp = t_1
    else if (j <= (-9d-82)) then
        tmp = t_0
    else if (j <= (-1.05d-168)) then
        tmp = t_2
    else if (j <= (-3.4d-301)) then
        tmp = t_0
    else if (j <= 1.1d-49) then
        tmp = t_2
    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 = -2.0 * (U * -0.5);
	double t_1 = -2.0 * (J * Math.cos((K / 2.0)));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -3.9e+57) {
		tmp = t_1;
	} else if (J <= -9e-82) {
		tmp = t_0;
	} else if (J <= -1.05e-168) {
		tmp = t_2;
	} else if (J <= -3.4e-301) {
		tmp = t_0;
	} else if (J <= 1.1e-49) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (U * -0.5)
	t_1 = -2.0 * (J * math.cos((K / 2.0)))
	t_2 = -2.0 * (U * 0.5)
	tmp = 0
	if J <= -3.9e+57:
		tmp = t_1
	elif J <= -9e-82:
		tmp = t_0
	elif J <= -1.05e-168:
		tmp = t_2
	elif J <= -3.4e-301:
		tmp = t_0
	elif J <= 1.1e-49:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(U * -0.5))
	t_1 = Float64(-2.0 * Float64(J * cos(Float64(K / 2.0))))
	t_2 = Float64(-2.0 * Float64(U * 0.5))
	tmp = 0.0
	if (J <= -3.9e+57)
		tmp = t_1;
	elseif (J <= -9e-82)
		tmp = t_0;
	elseif (J <= -1.05e-168)
		tmp = t_2;
	elseif (J <= -3.4e-301)
		tmp = t_0;
	elseif (J <= 1.1e-49)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * (U * -0.5);
	t_1 = -2.0 * (J * cos((K / 2.0)));
	t_2 = -2.0 * (U * 0.5);
	tmp = 0.0;
	if (J <= -3.9e+57)
		tmp = t_1;
	elseif (J <= -9e-82)
		tmp = t_0;
	elseif (J <= -1.05e-168)
		tmp = t_2;
	elseif (J <= -3.4e-301)
		tmp = t_0;
	elseif (J <= 1.1e-49)
		tmp = t_2;
	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[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -3.9e+57], t$95$1, If[LessEqual[J, -9e-82], t$95$0, If[LessEqual[J, -1.05e-168], t$95$2, If[LessEqual[J, -3.4e-301], t$95$0, If[LessEqual[J, 1.1e-49], t$95$2, t$95$1]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(U \cdot -0.5\right)\\
t_1 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\
t_2 := -2 \cdot \left(U \cdot 0.5\right)\\
\mathbf{if}\;J \leq -3.9 \cdot 10^{+57}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -9 \cdot 10^{-82}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -1.05 \cdot 10^{-168}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;J \leq -3.4 \cdot 10^{-301}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq 1.1 \cdot 10^{-49}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -3.89999999999999968e57 or 1.09999999999999995e-49 < J

    1. Initial program 92.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*92.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*92.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. *-commutative92.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. unpow292.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-neg92.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-neg92.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-neg92.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. unpow292.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.1%

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

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

    if -3.89999999999999968e57 < J < -8.9999999999999997e-82 or -1.04999999999999997e-168 < J < -3.4000000000000002e-301

    1. Initial program 54.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. Simplified84.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 44.0%

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

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

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

    if -8.9999999999999997e-82 < J < -1.04999999999999997e-168 or -3.4000000000000002e-301 < J < 1.09999999999999995e-49

    1. Initial program 55.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified77.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 46.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.9 \cdot 10^{+57}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;J \leq -9 \cdot 10^{-82}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq -1.05 \cdot 10^{-168}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -3.4 \cdot 10^{-301}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.1 \cdot 10^{-49}:\\ \;\;\;\;-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 6: 47.7% accurate, 19.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(U \cdot -0.5\right)\\ t_1 := -2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ t_2 := -2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{if}\;J \leq -9.5 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -5.2 \cdot 10^{-85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -1.45 \cdot 10^{-168}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 2.4 \cdot 10^{+29}:\\ \;\;\;\;t_2\\ \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 (* -2.0 (* U -0.5)))
        (t_1 (* -2.0 (+ J (* 0.125 (/ U (/ J U))))))
        (t_2 (* -2.0 (* U 0.5))))
   (if (<= J -9.5e+63)
     t_1
     (if (<= J -5.2e-85)
       t_0
       (if (<= J -1.45e-168)
         t_2
         (if (<= J -3.3e-301) t_0 (if (<= J 2.4e+29) t_2 t_1)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (U * -0.5);
	double t_1 = -2.0 * (J + (0.125 * (U / (J / U))));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -9.5e+63) {
		tmp = t_1;
	} else if (J <= -5.2e-85) {
		tmp = t_0;
	} else if (J <= -1.45e-168) {
		tmp = t_2;
	} else if (J <= -3.3e-301) {
		tmp = t_0;
	} else if (J <= 2.4e+29) {
		tmp = t_2;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = (-2.0d0) * (u * (-0.5d0))
    t_1 = (-2.0d0) * (j + (0.125d0 * (u / (j / u))))
    t_2 = (-2.0d0) * (u * 0.5d0)
    if (j <= (-9.5d+63)) then
        tmp = t_1
    else if (j <= (-5.2d-85)) then
        tmp = t_0
    else if (j <= (-1.45d-168)) then
        tmp = t_2
    else if (j <= (-3.3d-301)) then
        tmp = t_0
    else if (j <= 2.4d+29) then
        tmp = t_2
    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 = -2.0 * (U * -0.5);
	double t_1 = -2.0 * (J + (0.125 * (U / (J / U))));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -9.5e+63) {
		tmp = t_1;
	} else if (J <= -5.2e-85) {
		tmp = t_0;
	} else if (J <= -1.45e-168) {
		tmp = t_2;
	} else if (J <= -3.3e-301) {
		tmp = t_0;
	} else if (J <= 2.4e+29) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (U * -0.5)
	t_1 = -2.0 * (J + (0.125 * (U / (J / U))))
	t_2 = -2.0 * (U * 0.5)
	tmp = 0
	if J <= -9.5e+63:
		tmp = t_1
	elif J <= -5.2e-85:
		tmp = t_0
	elif J <= -1.45e-168:
		tmp = t_2
	elif J <= -3.3e-301:
		tmp = t_0
	elif J <= 2.4e+29:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(U * -0.5))
	t_1 = Float64(-2.0 * Float64(J + Float64(0.125 * Float64(U / Float64(J / U)))))
	t_2 = Float64(-2.0 * Float64(U * 0.5))
	tmp = 0.0
	if (J <= -9.5e+63)
		tmp = t_1;
	elseif (J <= -5.2e-85)
		tmp = t_0;
	elseif (J <= -1.45e-168)
		tmp = t_2;
	elseif (J <= -3.3e-301)
		tmp = t_0;
	elseif (J <= 2.4e+29)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * (U * -0.5);
	t_1 = -2.0 * (J + (0.125 * (U / (J / U))));
	t_2 = -2.0 * (U * 0.5);
	tmp = 0.0;
	if (J <= -9.5e+63)
		tmp = t_1;
	elseif (J <= -5.2e-85)
		tmp = t_0;
	elseif (J <= -1.45e-168)
		tmp = t_2;
	elseif (J <= -3.3e-301)
		tmp = t_0;
	elseif (J <= 2.4e+29)
		tmp = t_2;
	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[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(J + N[(0.125 * N[(U / N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -9.5e+63], t$95$1, If[LessEqual[J, -5.2e-85], t$95$0, If[LessEqual[J, -1.45e-168], t$95$2, If[LessEqual[J, -3.3e-301], t$95$0, If[LessEqual[J, 2.4e+29], t$95$2, t$95$1]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(U \cdot -0.5\right)\\
t_1 := -2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\
t_2 := -2 \cdot \left(U \cdot 0.5\right)\\
\mathbf{if}\;J \leq -9.5 \cdot 10^{+63}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -5.2 \cdot 10^{-85}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -1.45 \cdot 10^{-168}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;J \leq 2.4 \cdot 10^{+29}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -9.5000000000000003e63 or 2.4000000000000001e29 < J

    1. Initial program 96.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.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 K around 0 45.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. unpow245.4%

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

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

      \[\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 J around inf 45.9%

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

        \[\leadsto -2 \cdot \left(J + 0.125 \cdot \frac{\color{blue}{U \cdot U}}{J}\right) \]
      2. associate-/l*49.5%

        \[\leadsto -2 \cdot \left(J + 0.125 \cdot \color{blue}{\frac{U}{\frac{J}{U}}}\right) \]
    8. Simplified49.5%

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

    if -9.5000000000000003e63 < J < -5.20000000000000023e-85 or -1.4499999999999999e-168 < J < -3.3e-301

    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. Simplified85.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 42.0%

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

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

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

    if -5.20000000000000023e-85 < J < -1.4499999999999999e-168 or -3.3e-301 < J < 2.4000000000000001e29

    1. Initial program 57.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified80.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 44.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -9.5 \cdot 10^{+63}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ \mathbf{elif}\;J \leq -5.2 \cdot 10^{-85}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq -1.45 \cdot 10^{-168}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-301}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 2.4 \cdot 10^{+29}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ \end{array} \]

Alternative 7: 47.5% accurate, 19.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ t_1 := -2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{if}\;J \leq -3 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -1.8 \cdot 10^{-80}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq -8.8 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-301}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.1 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \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 (* 0.125 (/ U (/ J U)))))) (t_1 (* -2.0 (* U 0.5))))
   (if (<= J -3e+62)
     t_0
     (if (<= J -1.8e-80)
       (* -2.0 (- (* U -0.5) (* J (/ J U))))
       (if (<= J -8.8e-169)
         t_1
         (if (<= J -3.3e-301)
           (* -2.0 (* U -0.5))
           (if (<= J 1.1e+30) t_1 t_0)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J + (0.125 * (U / (J / U))));
	double t_1 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -3e+62) {
		tmp = t_0;
	} else if (J <= -1.8e-80) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= -8.8e-169) {
		tmp = t_1;
	} else if (J <= -3.3e-301) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.1e+30) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = (-2.0d0) * (j + (0.125d0 * (u / (j / u))))
    t_1 = (-2.0d0) * (u * 0.5d0)
    if (j <= (-3d+62)) then
        tmp = t_0
    else if (j <= (-1.8d-80)) then
        tmp = (-2.0d0) * ((u * (-0.5d0)) - (j * (j / u)))
    else if (j <= (-8.8d-169)) then
        tmp = t_1
    else if (j <= (-3.3d-301)) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 1.1d+30) then
        tmp = t_1
    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 + (0.125 * (U / (J / U))));
	double t_1 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -3e+62) {
		tmp = t_0;
	} else if (J <= -1.8e-80) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= -8.8e-169) {
		tmp = t_1;
	} else if (J <= -3.3e-301) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.1e+30) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (J + (0.125 * (U / (J / U))))
	t_1 = -2.0 * (U * 0.5)
	tmp = 0
	if J <= -3e+62:
		tmp = t_0
	elif J <= -1.8e-80:
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)))
	elif J <= -8.8e-169:
		tmp = t_1
	elif J <= -3.3e-301:
		tmp = -2.0 * (U * -0.5)
	elif J <= 1.1e+30:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J + Float64(0.125 * Float64(U / Float64(J / U)))))
	t_1 = Float64(-2.0 * Float64(U * 0.5))
	tmp = 0.0
	if (J <= -3e+62)
		tmp = t_0;
	elseif (J <= -1.8e-80)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(J * Float64(J / U))));
	elseif (J <= -8.8e-169)
		tmp = t_1;
	elseif (J <= -3.3e-301)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 1.1e+30)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * (J + (0.125 * (U / (J / U))));
	t_1 = -2.0 * (U * 0.5);
	tmp = 0.0;
	if (J <= -3e+62)
		tmp = t_0;
	elseif (J <= -1.8e-80)
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	elseif (J <= -8.8e-169)
		tmp = t_1;
	elseif (J <= -3.3e-301)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 1.1e+30)
		tmp = t_1;
	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[(0.125 * N[(U / N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -3e+62], t$95$0, If[LessEqual[J, -1.8e-80], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -8.8e-169], t$95$1, If[LessEqual[J, -3.3e-301], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.1e+30], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\
t_1 := -2 \cdot \left(U \cdot 0.5\right)\\
\mathbf{if}\;J \leq -3 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq -8.8 \cdot 10^{-169}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;J \leq 1.1 \cdot 10^{+30}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -3e62 or 1.1e30 < J

    1. Initial program 96.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.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 K around 0 45.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. unpow245.4%

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

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

      \[\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 J around inf 45.9%

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

        \[\leadsto -2 \cdot \left(J + 0.125 \cdot \frac{\color{blue}{U \cdot U}}{J}\right) \]
      2. associate-/l*49.5%

        \[\leadsto -2 \cdot \left(J + 0.125 \cdot \color{blue}{\frac{U}{\frac{J}{U}}}\right) \]
    8. Simplified49.5%

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

    if -3e62 < J < -1.8e-80

    1. Initial program 68.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. Simplified97.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 42.9%

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

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

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

      \[\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 35.4%

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(-0.5 \cdot \frac{U}{J} - \frac{J}{U}\right)}\right) \]
    9. Taylor expanded in J around 0 37.6%

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

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

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

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

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

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

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

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

    if -1.8e-80 < J < -8.80000000000000029e-169 or -3.3e-301 < J < 1.1e30

    1. Initial program 57.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified80.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 44.9%

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

    if -8.80000000000000029e-169 < J < -3.3e-301

    1. Initial program 38.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. Simplified65.7%

      \[\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 48.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3 \cdot 10^{+62}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ \mathbf{elif}\;J \leq -1.8 \cdot 10^{-80}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq -8.8 \cdot 10^{-169}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -3.3 \cdot 10^{-301}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.1 \cdot 10^{+30}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\\ \end{array} \]

Alternative 8: 47.5% accurate, 27.4× speedup?

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

\mathbf{elif}\;J \leq -2.8 \cdot 10^{-85}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -1.45 \cdot 10^{-168}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -4.7 \cdot 10^{-299}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq 1200000000000:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -5.60000000000000029e62 or 1.2e12 < J

    1. Initial program 95.8%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified99.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 K around 0 44.6%

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

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

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

      \[\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 J around inf 48.2%

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

    if -5.60000000000000029e62 < J < -2.80000000000000017e-85 or -1.4499999999999999e-168 < J < -4.6999999999999997e-299

    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. Simplified85.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 42.0%

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

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

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

    if -2.80000000000000017e-85 < J < -1.4499999999999999e-168 or -4.6999999999999997e-299 < J < 1.2e12

    1. Initial program 57.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified80.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 43.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.6 \cdot 10^{+62}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2.8 \cdot 10^{-85}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq -1.45 \cdot 10^{-168}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -4.7 \cdot 10^{-299}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1200000000000:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 40.2% accurate, 46.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -7500000000000:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 63000000000000:\\ \;\;\;\;-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 -7500000000000.0)
   (* -2.0 J)
   (if (<= J 63000000000000.0) (* -2.0 (* U 0.5)) (* -2.0 J))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -7500000000000.0) {
		tmp = -2.0 * J;
	} else if (J <= 63000000000000.0) {
		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 <= (-7500000000000.0d0)) then
        tmp = (-2.0d0) * j
    else if (j <= 63000000000000.0d0) 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 <= -7500000000000.0) {
		tmp = -2.0 * J;
	} else if (J <= 63000000000000.0) {
		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 <= -7500000000000.0:
		tmp = -2.0 * J
	elif J <= 63000000000000.0:
		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 <= -7500000000000.0)
		tmp = Float64(-2.0 * J);
	elseif (J <= 63000000000000.0)
		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 <= -7500000000000.0)
		tmp = -2.0 * J;
	elseif (J <= 63000000000000.0)
		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, -7500000000000.0], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, 63000000000000.0], 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 -7500000000000:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq 63000000000000:\\
\;\;\;\;-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 < -7.5e12 or 6.3e13 < J

    1. Initial program 94.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. Simplified99.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 K around 0 47.1%

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

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

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

      \[\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 J around inf 46.7%

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

    if -7.5e12 < J < 6.3e13

    1. Initial program 54.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. Simplified81.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 J around 0 41.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7500000000000:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 63000000000000:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 10: 29.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 74.5%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Simplified90.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 K around 0 31.2%

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

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

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

    \[\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 J around inf 29.1%

    \[\leadsto -2 \cdot \color{blue}{J} \]
  7. Final simplification29.1%

    \[\leadsto -2 \cdot J \]

Reproduce

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