Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.7% → 99.6%
Time: 20.4s
Alternatives: 10
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.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.6% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < -inf.0

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

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg52.7%

        \[\leadsto \color{blue}{-U} \]
    5. Simplified52.7%

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

    if -inf.0 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < 4.99999999999999993e306

    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. Simplified99.8%

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

    if 4.99999999999999993e306 < (*.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.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.0%

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

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

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

Alternative 2: 89.4% accurate, 1.3× speedup?

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

\mathbf{elif}\;J \leq -2.4 \cdot 10^{-306}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 3 \cdot 10^{-179}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -6.8000000000000004e-205 or 3.00000000000000006e-179 < J

    1. Initial program 84.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. Simplified96.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.8000000000000004e-205 < J < -2.3999999999999999e-306

    1. Initial program 25.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. Simplified52.2%

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

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

    if -2.3999999999999999e-306 < J < 3.00000000000000006e-179

    1. Initial program 17.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. Simplified43.6%

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg34.7%

        \[\leadsto \color{blue}{-U} \]
    5. Simplified34.7%

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

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

Alternative 3: 78.6% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq -2.5 \cdot 10^{-135}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.8 \cdot 10^{-91}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U}, -U\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(J \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\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 (<= J -2.5e-135)
     (* (* -2.0 J) (* t_0 (hypot 1.0 (* U (/ 0.5 J)))))
     (if (<= J -4e-310)
       U
       (if (<= J 3.8e-91)
         (fma -2.0 (/ (pow (* J (cos (* K 0.5))) 2.0) U) (- U))
         (* (* -2.0 (* J t_0)) (hypot 1.0 (/ (/ U 2.0) J))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (J <= -2.5e-135) {
		tmp = (-2.0 * J) * (t_0 * hypot(1.0, (U * (0.5 / J))));
	} else if (J <= -4e-310) {
		tmp = U;
	} else if (J <= 3.8e-91) {
		tmp = fma(-2.0, (pow((J * cos((K * 0.5))), 2.0) / U), -U);
	} else {
		tmp = (-2.0 * (J * t_0)) * hypot(1.0, ((U / 2.0) / J));
	}
	return tmp;
}
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (J <= -2.5e-135)
		tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * hypot(1.0, Float64(U * Float64(0.5 / J)))));
	elseif (J <= -4e-310)
		tmp = U;
	elseif (J <= 3.8e-91)
		tmp = fma(-2.0, Float64((Float64(J * cos(Float64(K * 0.5))) ^ 2.0) / U), Float64(-U));
	else
		tmp = Float64(Float64(-2.0 * Float64(J * t_0)) * hypot(1.0, Float64(Float64(U / 2.0) / J)));
	end
	return tmp
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[J, -2.5e-135], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -4e-310], U, If[LessEqual[J, 3.8e-91], N[(-2.0 * N[(N[Power[N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / U), $MachinePrecision] + (-U)), $MachinePrecision], N[(N[(-2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq -2.5 \cdot 10^{-135}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -2.5000000000000001e-135

    1. Initial program 91.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}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Taylor expanded in K around 0 85.8%

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

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

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

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

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

    if -2.5000000000000001e-135 < J < -3.999999999999988e-310

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

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

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

    if -3.999999999999988e-310 < J < 3.79999999999999978e-91

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.79999999999999978e-91 < J

    1. Initial program 87.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*87.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-/r*87.4%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.5 \cdot 10^{-135}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.8 \cdot 10^{-91}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U}, -U\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\ \end{array} \]

Alternative 4: 69.4% accurate, 1.9× speedup?

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

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


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

    1. Initial program 75.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. Simplified90.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(1 + \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.125\right)\right) \]
    10. Applied egg-rr58.1%

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

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

    1. Initial program 70.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*70.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-/r*70.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 78.9% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -6.2 \cdot 10^{-135}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8 \cdot 10^{-175}:\\ \;\;\;\;-U\\ \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 (/ 0.5 J)))))))
   (if (<= J -6.2e-135)
     t_0
     (if (<= J -4e-310) U (if (<= J 8e-175) (- U) 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 * (0.5 / J))));
	double tmp;
	if (J <= -6.2e-135) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if (J <= 8e-175) {
		tmp = -U;
	} 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 * (0.5 / J))));
	double tmp;
	if (J <= -6.2e-135) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if (J <= 8e-175) {
		tmp = -U;
	} 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 * (0.5 / J))))
	tmp = 0
	if J <= -6.2e-135:
		tmp = t_0
	elif J <= -4e-310:
		tmp = U
	elif J <= 8e-175:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(-2.0 * J) * Float64(cos(Float64(K / 2.0)) * hypot(1.0, Float64(U * Float64(0.5 / J)))))
	tmp = 0.0
	if (J <= -6.2e-135)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif (J <= 8e-175)
		tmp = Float64(-U);
	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 * (0.5 / J))));
	tmp = 0.0;
	if (J <= -6.2e-135)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif (J <= 8e-175)
		tmp = -U;
	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[(N[(-2.0 * J), $MachinePrecision] * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.2e-135], t$95$0, If[LessEqual[J, -4e-310], U, If[LessEqual[J, 8e-175], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -6.2 \cdot 10^{-135}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 8 \cdot 10^{-175}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -6.2000000000000001e-135 or 8e-175 < J

    1. Initial program 86.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. Simplified97.4%

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

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

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

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

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

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

    if -6.2000000000000001e-135 < J < -3.999999999999988e-310

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

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

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

    if -3.999999999999988e-310 < J < 8e-175

    1. Initial program 17.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. Simplified43.6%

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg34.7%

        \[\leadsto \color{blue}{-U} \]
    5. Simplified34.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6.2 \cdot 10^{-135}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8 \cdot 10^{-175}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]

Alternative 6: 78.9% accurate, 1.9× speedup?

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

\mathbf{elif}\;J \leq 4.3 \cdot 10^{-308}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 3.4 \cdot 10^{-174}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -2.9000000000000002e-135

    1. Initial program 91.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}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)\right)} \]
    3. Taylor expanded in K around 0 85.8%

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

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

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

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

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

    if -2.9000000000000002e-135 < J < 4.3000000000000002e-308

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

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

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

    if 4.3000000000000002e-308 < J < 3.4000000000000002e-174

    1. Initial program 17.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. Simplified43.6%

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg34.7%

        \[\leadsto \color{blue}{-U} \]
    5. Simplified34.7%

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

    if 3.4000000000000002e-174 < J

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.9 \cdot 10^{-135}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 4.3 \cdot 10^{-308}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.4 \cdot 10^{-174}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\ \end{array} \]

Alternative 7: 66.3% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;J \leq -7.5 \cdot 10^{-135}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.6 \cdot 10^{-68} \lor \neg \left(J \leq 4.1 \cdot 10^{-10}\right) \land J \leq 9 \cdot 10^{+26}:\\ \;\;\;\;-U\\ \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 -7.5e-135)
     t_0
     (if (<= J -4e-310)
       U
       (if (or (<= J 8.6e-68) (and (not (<= J 4.1e-10)) (<= J 9e+26)))
         (- U)
         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 <= -7.5e-135) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26))) {
		tmp = -U;
	} 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 <= (-7.5d-135)) then
        tmp = t_0
    else if (j <= (-4d-310)) then
        tmp = u
    else if ((j <= 8.6d-68) .or. (.not. (j <= 4.1d-10)) .and. (j <= 9d+26)) then
        tmp = -u
    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 <= -7.5e-135) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26))) {
		tmp = -U;
	} 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 <= -7.5e-135:
		tmp = t_0
	elif J <= -4e-310:
		tmp = U
	elif (J <= 8.6e-68) or (not (J <= 4.1e-10) and (J <= 9e+26)):
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (J <= -7.5e-135)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif ((J <= 8.6e-68) || (!(J <= 4.1e-10) && (J <= 9e+26)))
		tmp = Float64(-U);
	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 <= -7.5e-135)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif ((J <= 8.6e-68) || (~((J <= 4.1e-10)) && (J <= 9e+26)))
		tmp = -U;
	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[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -7.5e-135], t$95$0, If[LessEqual[J, -4e-310], U, If[Or[LessEqual[J, 8.6e-68], And[N[Not[LessEqual[J, 4.1e-10]], $MachinePrecision], LessEqual[J, 9e+26]]], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq -7.5 \cdot 10^{-135}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 8.6 \cdot 10^{-68} \lor \neg \left(J \leq 4.1 \cdot 10^{-10}\right) \land J \leq 9 \cdot 10^{+26}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -7.5e-135 or 8.6000000000000002e-68 < J < 4.0999999999999998e-10 or 8.99999999999999957e26 < J

    1. Initial program 91.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. Simplified99.8%

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

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

    if -7.5e-135 < J < -3.999999999999988e-310

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

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

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

    if -3.999999999999988e-310 < J < 8.6000000000000002e-68 or 4.0999999999999998e-10 < J < 8.99999999999999957e26

    1. Initial program 46.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. Simplified68.6%

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg39.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7.5 \cdot 10^{-135}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.6 \cdot 10^{-68} \lor \neg \left(J \leq 4.1 \cdot 10^{-10}\right) \land J \leq 9 \cdot 10^{+26}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 8: 63.2% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-5)
   (* (* -2.0 J) (hypot 1.0 (/ (/ U 2.0) J)))
   (* (* -2.0 J) (cos (* K 0.5)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-5) {
		tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J));
	} 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) <= 5e-5) {
		tmp = (-2.0 * J) * Math.hypot(1.0, ((U / 2.0) / J));
	} 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) <= 5e-5:
		tmp = (-2.0 * J) * math.hypot(1.0, ((U / 2.0) / J))
	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) <= 5e-5)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U / 2.0) / J)));
	else
		tmp = Float64(Float64(-2.0 * 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) <= 5e-5)
		tmp = (-2.0 * J) * hypot(1.0, ((U / 2.0) / J));
	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], 5e-5], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\\

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


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

    1. Initial program 72.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*72.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-/r*72.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000024e-5 < (/.f64 K 2)

    1. Initial program 71.2%

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

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

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

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

Alternative 9: 39.3% accurate, 103.4× speedup?

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

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


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

    1. Initial program 75.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. Simplified89.8%

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

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

    if 4.999999999999985e-310 < J

    1. Initial program 69.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. Simplified84.8%

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

      \[\leadsto \color{blue}{-1 \cdot U} \]
    4. Step-by-step derivation
      1. mul-1-neg27.6%

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

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

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

Alternative 10: 26.8% accurate, 420.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ U \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 U)
U = abs(U);
double code(double J, double K, double U) {
	return U;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	return U;
}
U = abs(U)
def code(J, K, U):
	return U
U = abs(U)
function code(J, K, U)
	return U
end
U = abs(U)
function tmp = code(J, K, U)
	tmp = U;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := U
\begin{array}{l}
U = |U|\\
\\
U
\end{array}
Derivation
  1. Initial program 72.2%

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

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

    \[\leadsto \color{blue}{U} \]
  4. Final simplification24.5%

    \[\leadsto U \]

Reproduce

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