Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 74.2% → 99.8%
Time: 21.8s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 74.2% 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.8% accurate, 0.3× 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:\\ \;\;\;\;-2 \cdot \frac{{J}^{2}}{U} - U\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t_1\\ \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))
     (- (* -2.0 (/ (pow J 2.0) U)) U)
     (if (<= t_1 5e+307) t_1 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 = (-2.0 * (pow(J, 2.0) / U)) - U;
	} else if (t_1 <= 5e+307) {
		tmp = t_1;
	} 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 = (-2.0 * (Math.pow(J, 2.0) / U)) - U;
	} else if (t_1 <= 5e+307) {
		tmp = t_1;
	} 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 = (-2.0 * (math.pow(J, 2.0) / U)) - U
	elif t_1 <= 5e+307:
		tmp = t_1
	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(Float64(-2.0 * Float64((J ^ 2.0) / U)) - U);
	elseif (t_1 <= 5e+307)
		tmp = t_1;
	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 = (-2.0 * ((J ^ 2.0) / U)) - U;
	elseif (t_1 <= 5e+307)
		tmp = t_1;
	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)], N[(N[(-2.0 * N[(N[Power[J, 2.0], $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision], If[LessEqual[t$95$1, 5e+307], t$95$1, 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:\\
\;\;\;\;-2 \cdot \frac{{J}^{2}}{U} - U\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t_1\\

\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. Taylor expanded in J around 0 34.8%

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

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

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

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

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

        \[\leadsto -2 \cdot \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 \]
      6. swap-sqr34.8%

        \[\leadsto -2 \cdot \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 \]
      7. unpow234.8%

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

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

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

      \[\leadsto -2 \cdot \color{blue}{\frac{{J}^{2}}{U}} - 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)))) < 5e307

    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}} \]

    if 5e307 < (*.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.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. Taylor expanded in U around -inf 49.3%

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

    \[\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 \frac{{J}^{2}}{U} - 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^{+307}:\\ \;\;\;\;\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}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 88.8% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq -1.8 \cdot 10^{-245} \lor \neg \left(J \leq 1.7 \cdot 10^{-292}\right):\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\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))))
   (if (or (<= J -1.8e-245) (not (<= J 1.7e-292)))
     (* -2.0 (* t_0 (* J (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 tmp;
	if ((J <= -1.8e-245) || !(J <= 1.7e-292)) {
		tmp = -2.0 * (t_0 * (J * 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 tmp;
	if ((J <= -1.8e-245) || !(J <= 1.7e-292)) {
		tmp = -2.0 * (t_0 * (J * 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))
	tmp = 0
	if (J <= -1.8e-245) or not (J <= 1.7e-292):
		tmp = -2.0 * (t_0 * (J * 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))
	tmp = 0.0
	if ((J <= -1.8e-245) || !(J <= 1.7e-292))
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J * 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));
	tmp = 0.0;
	if ((J <= -1.8e-245) || ~((J <= 1.7e-292)))
		tmp = -2.0 * (t_0 * (J * 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]}, If[Or[LessEqual[J, -1.8e-245], N[Not[LessEqual[J, 1.7e-292]], $MachinePrecision]], N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq -1.8 \cdot 10^{-245} \lor \neg \left(J \leq 1.7 \cdot 10^{-292}\right):\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -1.8e-245 or 1.70000000000000009e-292 < J

    1. Initial program 76.5%

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

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

    if -1.8e-245 < J < 1.70000000000000009e-292

    1. Initial program 35.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. Taylor expanded in U around -inf 29.1%

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

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

Alternative 3: 88.8% accurate, 1.3× speedup?

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

\mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_1 \cdot \left(J \cdot t_0\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.8e-245

    1. Initial program 77.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. Simplified89.4%

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

    if -1.8e-245 < J < 2.5999999999999999e-294

    1. Initial program 35.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. Taylor expanded in U around -inf 29.1%

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

    if 2.5999999999999999e-294 < J

    1. Initial program 76.0%

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

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

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

        \[\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. hypot-1-def91.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.3%

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

Alternative 4: 74.6% accurate, 1.9× speedup?

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

\mathbf{elif}\;U \leq 8.6 \cdot 10^{+250}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 8.5000000000000001e197

    1. Initial program 76.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*76.7%

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

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

        \[\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. hypot-1-def89.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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)\right)} \]
    4. Taylor expanded in K around 0 75.5%

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

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

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

    if 8.5000000000000001e197 < U < 8.6e250

    1. Initial program 53.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. Taylor expanded in J around 0 63.5%

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

        \[\leadsto \color{blue}{-U} \]
    4. Simplified63.5%

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

    if 8.6e250 < U

    1. Initial program 27.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. Taylor expanded in U around -inf 72.1%

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

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

Alternative 5: 63.2% accurate, 3.7× speedup?

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

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


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

    1. Initial program 71.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. Simplified86.4%

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

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

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

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

        \[\leadsto -2 \cdot \color{blue}{{\left(\sqrt[3]{\left(J \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)}\right)}^{3}} \]
    4. Applied egg-rr84.9%

      \[\leadsto -2 \cdot \color{blue}{{\left(\sqrt[3]{J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{\frac{0.5}{J}}{\cos \left(K \cdot 0.5\right)}\right)\right)}\right)}^{3}} \]
    5. Step-by-step derivation
      1. rem-cube-cbrt86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000005e32 < (/.f64 K 2)

    1. Initial program 76.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. Simplified88.8%

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

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

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

Alternative 6: 66.1% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{if}\;J \leq -1.18 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-22}:\\ \;\;\;\;-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))))))
   (if (<= J -1.18e-7)
     t_0
     (if (<= J 2.6e-294) U (if (<= J 9.5e-22) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * cos((K / 2.0)));
	double tmp;
	if (J <= -1.18e-7) {
		tmp = t_0;
	} else if (J <= 2.6e-294) {
		tmp = U;
	} else if (J <= 9.5e-22) {
		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 / 2.0d0)))
    if (j <= (-1.18d-7)) then
        tmp = t_0
    else if (j <= 2.6d-294) then
        tmp = u
    else if (j <= 9.5d-22) 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 / 2.0)));
	double tmp;
	if (J <= -1.18e-7) {
		tmp = t_0;
	} else if (J <= 2.6e-294) {
		tmp = U;
	} else if (J <= 9.5e-22) {
		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)))
	tmp = 0
	if J <= -1.18e-7:
		tmp = t_0
	elif J <= 2.6e-294:
		tmp = U
	elif J <= 9.5e-22:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * cos(Float64(K / 2.0))))
	tmp = 0.0
	if (J <= -1.18e-7)
		tmp = t_0;
	elseif (J <= 2.6e-294)
		tmp = U;
	elseif (J <= 9.5e-22)
		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)));
	tmp = 0.0;
	if (J <= -1.18e-7)
		tmp = t_0;
	elseif (J <= 2.6e-294)
		tmp = U;
	elseif (J <= 9.5e-22)
		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[(-2.0 * N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.18e-7], t$95$0, If[LessEqual[J, 2.6e-294], U, If[LessEqual[J, 9.5e-22], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\
\mathbf{if}\;J \leq -1.18 \cdot 10^{-7}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 9.5 \cdot 10^{-22}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.18e-7 or 9.4999999999999994e-22 < J

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

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

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

    if -1.18e-7 < J < 2.5999999999999999e-294

    1. Initial program 45.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. Taylor expanded in U around -inf 41.8%

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

    if 2.5999999999999999e-294 < J < 9.4999999999999994e-22

    1. Initial program 54.8%

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

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

        \[\leadsto \color{blue}{-U} \]
    4. Simplified36.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.18 \cdot 10^{-7}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-22}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \end{array} \]

Alternative 7: 49.0% accurate, 45.7× speedup?

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

\mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 340000000:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -0.900000000000000022 or 3.4e8 < J

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

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

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

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

    if -0.900000000000000022 < J < 2.5999999999999999e-294

    1. Initial program 45.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. Taylor expanded in U around -inf 41.8%

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

    if 2.5999999999999999e-294 < J < 3.4e8

    1. Initial program 55.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. Taylor expanded in J around 0 33.5%

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

        \[\leadsto \color{blue}{-U} \]
    4. Simplified33.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -0.9:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 2.6 \cdot 10^{-294}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 340000000:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 8: 38.2% accurate, 103.4× speedup?

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

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


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

    1. Initial program 70.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. Taylor expanded in U around -inf 26.8%

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

    if 2.5999999999999999e-294 < J

    1. Initial program 76.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. Taylor expanded in J around 0 21.9%

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

        \[\leadsto \color{blue}{-U} \]
    4. Simplified21.9%

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

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

Alternative 9: 26.4% 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.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. Taylor expanded in U around -inf 26.2%

    \[\leadsto \color{blue}{U} \]
  3. Final simplification26.2%

    \[\leadsto U \]

Reproduce

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