Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.6% → 99.1%
Time: 17.8s
Alternatives: 8
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 8 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.6% 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.1% 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 5.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. Simplified60.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 58.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 5.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. Simplified52.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 32.7%

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

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

      \[\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.9% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := -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)\\ \mathbf{if}\;J \leq -1.9 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.36 \cdot 10^{-220}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\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 (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))))
   (if (<= J -1.9e-217)
     t_1
     (if (<= J 7e-285)
       (* -2.0 (* U -0.5))
       (if (<= J 1.36e-220) (* -2.0 (* U 0.5)) 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 * hypot(1.0, (U / (J * (2.0 * t_0))))));
	double tmp;
	if (J <= -1.9e-217) {
		tmp = t_1;
	} else if (J <= 7e-285) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.36e-220) {
		tmp = -2.0 * (U * 0.5);
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = -2.0 * (J * (t_0 * Math.hypot(1.0, (U / (J * (2.0 * t_0))))));
	double tmp;
	if (J <= -1.9e-217) {
		tmp = t_1;
	} else if (J <= 7e-285) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.36e-220) {
		tmp = -2.0 * (U * 0.5);
	} 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 * math.hypot(1.0, (U / (J * (2.0 * t_0))))))
	tmp = 0
	if J <= -1.9e-217:
		tmp = t_1
	elif J <= 7e-285:
		tmp = -2.0 * (U * -0.5)
	elif J <= 1.36e-220:
		tmp = -2.0 * (U * 0.5)
	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 * Float64(t_0 * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))))
	tmp = 0.0
	if (J <= -1.9e-217)
		tmp = t_1;
	elseif (J <= 7e-285)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 1.36e-220)
		tmp = Float64(-2.0 * Float64(U * 0.5));
	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 * hypot(1.0, (U / (J * (2.0 * t_0))))));
	tmp = 0.0;
	if (J <= -1.9e-217)
		tmp = t_1;
	elseif (J <= 7e-285)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 1.36e-220)
		tmp = -2.0 * (U * 0.5);
	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 * 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]}, If[LessEqual[J, -1.9e-217], t$95$1, If[LessEqual[J, 7e-285], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.36e-220], N[(-2.0 * N[(U * 0.5), $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 \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)\\
\mathbf{if}\;J \leq -1.9 \cdot 10^{-217}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.89999999999999993e-217 or 1.3600000000000001e-220 < J

    1. Initial program 83.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. Simplified94.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)} \]

    if -1.89999999999999993e-217 < J < 7.0000000000000007e-285

    1. Initial program 34.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. Simplified44.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 32.7%

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

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

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

    if 7.0000000000000007e-285 < J < 1.3600000000000001e-220

    1. Initial program 23.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. Simplified52.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 60.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.9 \cdot 10^{-217}:\\ \;\;\;\;-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)\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.36 \cdot 10^{-220}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-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)\\ \end{array} \]

Alternative 3: 77.3% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)\\ \mathbf{if}\;J \leq -6.4 \cdot 10^{-152}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J}{\frac{U}{J}}\right)\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-179}:\\ \;\;\;\;-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))) (hypot 1.0 (/ U (* J 2.0)))))))
   (if (<= J -6.4e-152)
     t_0
     (if (<= J 7e-285)
       (* -2.0 (- (* U -0.5) (/ J (/ U J))))
       (if (<= J 5.8e-179) (* -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))) * hypot(1.0, (U / (J * 2.0))));
	double tmp;
	if (J <= -6.4e-152) {
		tmp = t_0;
	} else if (J <= 7e-285) {
		tmp = -2.0 * ((U * -0.5) - (J / (U / J)));
	} else if (J <= 5.8e-179) {
		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 * ((J * Math.cos((K / 2.0))) * Math.hypot(1.0, (U / (J * 2.0))));
	double tmp;
	if (J <= -6.4e-152) {
		tmp = t_0;
	} else if (J <= 7e-285) {
		tmp = -2.0 * ((U * -0.5) - (J / (U / J)));
	} else if (J <= 5.8e-179) {
		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))) * math.hypot(1.0, (U / (J * 2.0))))
	tmp = 0
	if J <= -6.4e-152:
		tmp = t_0
	elif J <= 7e-285:
		tmp = -2.0 * ((U * -0.5) - (J / (U / J)))
	elif J <= 5.8e-179:
		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(Float64(J * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U / Float64(J * 2.0)))))
	tmp = 0.0
	if (J <= -6.4e-152)
		tmp = t_0;
	elseif (J <= 7e-285)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(J / Float64(U / J))));
	elseif (J <= 5.8e-179)
		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))) * hypot(1.0, (U / (J * 2.0))));
	tmp = 0.0;
	if (J <= -6.4e-152)
		tmp = t_0;
	elseif (J <= 7e-285)
		tmp = -2.0 * ((U * -0.5) - (J / (U / J)));
	elseif (J <= 5.8e-179)
		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[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.4e-152], t$95$0, If[LessEqual[J, 7e-285], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(J / N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 5.8e-179], 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(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)\\
\mathbf{if}\;J \leq -6.4 \cdot 10^{-152}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 5.8 \cdot 10^{-179}:\\
\;\;\;\;-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 < -6.40000000000000025e-152 or 5.7999999999999998e-179 < J

    1. Initial program 87.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*87.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*87.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. unpow287.1%

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

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

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

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

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

      \[\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)} \]
    4. Taylor expanded in K around 0 81.8%

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

    if -6.40000000000000025e-152 < J < 7.0000000000000007e-285

    1. Initial program 49.5%

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

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

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

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

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

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

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

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

      \[\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)} \]
    4. Taylor expanded in K around 0 35.1%

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

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

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

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

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

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

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

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

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

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

    if 7.0000000000000007e-285 < J < 5.7999999999999998e-179

    1. Initial program 24.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. Simplified69.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 J around 0 53.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6.4 \cdot 10^{-152}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J}{\frac{U}{J}}\right)\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{-179}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right)\\ \end{array} \]

Alternative 4: 62.6% accurate, 3.7× speedup?

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

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


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

    1. Initial program 78.3%

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

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

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

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

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

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

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

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

      \[\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)} \]
    4. Taylor expanded in K around 0 78.2%

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

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

    if 1e9 < (/.f64 K 2)

    1. Initial program 75.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. Simplified86.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 inf 49.6%

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

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

Alternative 5: 64.6% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -2 \cdot 10^{-117}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 4.4 \cdot 10^{-284}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-138}:\\ \;\;\;\;-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 0.5))))))
   (if (<= J -2e-117)
     t_0
     (if (<= J 4.4e-284)
       (* -2.0 (* U -0.5))
       (if (<= J 9.5e-138) (* -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 * 0.5)));
	double tmp;
	if (J <= -2e-117) {
		tmp = t_0;
	} else if (J <= 4.4e-284) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 9.5e-138) {
		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 * 0.5d0)))
    if (j <= (-2d-117)) then
        tmp = t_0
    else if (j <= 4.4d-284) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 9.5d-138) 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 * 0.5)));
	double tmp;
	if (J <= -2e-117) {
		tmp = t_0;
	} else if (J <= 4.4e-284) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 9.5e-138) {
		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 * 0.5)))
	tmp = 0
	if J <= -2e-117:
		tmp = t_0
	elif J <= 4.4e-284:
		tmp = -2.0 * (U * -0.5)
	elif J <= 9.5e-138:
		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 * 0.5))))
	tmp = 0.0
	if (J <= -2e-117)
		tmp = t_0;
	elseif (J <= 4.4e-284)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 9.5e-138)
		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 * 0.5)));
	tmp = 0.0;
	if (J <= -2e-117)
		tmp = t_0;
	elseif (J <= 4.4e-284)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 9.5e-138)
		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 * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -2e-117], t$95$0, If[LessEqual[J, 4.4e-284], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 9.5e-138], 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(K \cdot 0.5\right)\right)\\
\mathbf{if}\;J \leq -2 \cdot 10^{-117}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 9.5 \cdot 10^{-138}:\\
\;\;\;\;-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.00000000000000006e-117 or 9.49999999999999997e-138 < J

    1. Initial program 90.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. Simplified97.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 inf 68.6%

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

    if -2.00000000000000006e-117 < J < 4.4000000000000001e-284

    1. Initial program 46.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. Simplified58.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 U around -inf 34.8%

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

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

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

    if 4.4000000000000001e-284 < J < 9.49999999999999997e-138

    1. Initial program 30.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. Simplified74.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. Taylor expanded in J around 0 62.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2 \cdot 10^{-117}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq 4.4 \cdot 10^{-284}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-138}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 48.1% accurate, 37.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2.6 \cdot 10^{+102}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.65 \cdot 10^{-78}:\\ \;\;\;\;-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 -2.6e+102)
   (* -2.0 J)
   (if (<= J 7e-285)
     (* -2.0 (* U -0.5))
     (if (<= J 1.65e-78) (* -2.0 (* U 0.5)) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.6e+102) {
		tmp = -2.0 * J;
	} else if (J <= 7e-285) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.65e-78) {
		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 <= (-2.6d+102)) then
        tmp = (-2.0d0) * j
    else if (j <= 7d-285) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 1.65d-78) 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 <= -2.6e+102) {
		tmp = -2.0 * J;
	} else if (J <= 7e-285) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 1.65e-78) {
		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 <= -2.6e+102:
		tmp = -2.0 * J
	elif J <= 7e-285:
		tmp = -2.0 * (U * -0.5)
	elif J <= 1.65e-78:
		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 <= -2.6e+102)
		tmp = Float64(-2.0 * J);
	elseif (J <= 7e-285)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 1.65e-78)
		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 <= -2.6e+102)
		tmp = -2.0 * J;
	elseif (J <= 7e-285)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 1.65e-78)
		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, -2.6e+102], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, 7e-285], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.65e-78], 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 -2.6 \cdot 10^{+102}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq 1.65 \cdot 10^{-78}:\\
\;\;\;\;-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 < -2.60000000000000006e102 or 1.64999999999999991e-78 < J

    1. Initial program 97.8%

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

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

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

    if -2.60000000000000006e102 < J < 7.0000000000000007e-285

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

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

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

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

    if 7.0000000000000007e-285 < J < 1.64999999999999991e-78

    1. Initial program 49.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. Simplified79.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 46.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.6 \cdot 10^{+102}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-285}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 1.65 \cdot 10^{-78}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 7: 39.4% accurate, 59.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 3.4 \cdot 10^{-34}:\\ \;\;\;\;-2 \cdot J\\ \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 3.4e-34) (* -2.0 J) (* -2.0 (* U 0.5))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 3.4e-34) {
		tmp = -2.0 * J;
	} else {
		tmp = -2.0 * (U * 0.5);
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (u <= 3.4d-34) then
        tmp = (-2.0d0) * j
    else
        tmp = (-2.0d0) * (u * 0.5d0)
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (U <= 3.4e-34) {
		tmp = -2.0 * J;
	} else {
		tmp = -2.0 * (U * 0.5);
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 3.4e-34:
		tmp = -2.0 * J
	else:
		tmp = -2.0 * (U * 0.5)
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 3.4e-34)
		tmp = Float64(-2.0 * J);
	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 <= 3.4e-34)
		tmp = -2.0 * J;
	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, 3.4e-34], N[(-2.0 * J), $MachinePrecision], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 3.4 \cdot 10^{-34}:\\
\;\;\;\;-2 \cdot J\\

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


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

    1. Initial program 83.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. Simplified91.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 inf 60.1%

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

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

    if 3.4000000000000001e-34 < U

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 3.4 \cdot 10^{-34}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \end{array} \]

Alternative 8: 29.2% 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 77.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. Simplified89.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 inf 54.1%

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

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

    \[\leadsto -2 \cdot J \]

Reproduce

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