Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 74.1% → 99.7%
Time: 16.0s
Alternatives: 8
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 74.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \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_m}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ t_2 := J \cdot t_0\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U_m\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+306}:\\ \;\;\;\;-2 \cdot \left(t_2 \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{t_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J 2.0))) 2.0)))))
        (t_2 (* J t_0)))
   (if (<= t_1 (- INFINITY))
     (- U_m)
     (if (<= t_1 4e+306)
       (* -2.0 (* t_2 (hypot 1.0 (/ (/ U_m 2.0) t_2))))
       U_m))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double t_2 = J * t_0;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U_m;
	} else if (t_1 <= 4e+306) {
		tmp = -2.0 * (t_2 * hypot(1.0, ((U_m / 2.0) / t_2)));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double t_2 = J * t_0;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U_m;
	} else if (t_1 <= 4e+306) {
		tmp = -2.0 * (t_2 * Math.hypot(1.0, ((U_m / 2.0) / t_2)));
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J * 2.0))), 2.0)))
	t_2 = J * t_0
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U_m
	elif t_1 <= 4e+306:
		tmp = -2.0 * (t_2 * math.hypot(1.0, ((U_m / 2.0) / t_2)))
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U_m / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	t_2 = Float64(J * t_0)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U_m);
	elseif (t_1 <= 4e+306)
		tmp = Float64(-2.0 * Float64(t_2 * hypot(1.0, Float64(Float64(U_m / 2.0) / t_2))));
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U_m / (t_0 * (J * 2.0))) ^ 2.0)));
	t_2 = J * t_0;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U_m;
	elseif (t_1 <= 4e+306)
		tmp = -2.0 * (t_2 * hypot(1.0, ((U_m / 2.0) / t_2)));
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := 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$95$m / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(J * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 4e+306], N[(-2.0 * N[(t$95$2 * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / t$95$2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U$95$m]]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\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_m}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
t_2 := J \cdot t_0\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U_m\\

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

\mathbf{else}:\\
\;\;\;\;U_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 82.1% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;U_m \leq 3.5 \cdot 10^{+139}:\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J \cdot t_0}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= U_m 3.5e+139)
     (* -2.0 (* t_0 (* J (hypot 1.0 (/ (/ U_m 2.0) (* J t_0))))))
     (- U_m))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (U_m <= 3.5e+139) {
		tmp = -2.0 * (t_0 * (J * hypot(1.0, ((U_m / 2.0) / (J * t_0)))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (U_m <= 3.5e+139) {
		tmp = -2.0 * (t_0 * (J * Math.hypot(1.0, ((U_m / 2.0) / (J * t_0)))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if U_m <= 3.5e+139:
		tmp = -2.0 * (t_0 * (J * math.hypot(1.0, ((U_m / 2.0) / (J * t_0)))))
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (U_m <= 3.5e+139)
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J * t_0))))));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (U_m <= 3.5e+139)
		tmp = -2.0 * (t_0 * (J * hypot(1.0, ((U_m / 2.0) / (J * t_0)))));
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[U$95$m, 3.5e+139], N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;U_m \leq 3.5 \cdot 10^{+139}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J \cdot t_0}\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 47.0% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 8.3 \cdot 10^{-181} \lor \neg \left(J \leq 1.85 \cdot 10^{-137}\right) \land J \leq 2.05 \cdot 10^{-113}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U_m}{J}\right)\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= J 8.3e-181) (and (not (<= J 1.85e-137)) (<= J 2.05e-113)))
   (- U_m)
   (* -2.0 (* (cos (/ K 2.0)) (* J (hypot 1.0 (* 0.5 (/ U_m J))))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((J <= 8.3e-181) || (!(J <= 1.85e-137) && (J <= 2.05e-113))) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * (cos((K / 2.0)) * (J * hypot(1.0, (0.5 * (U_m / J)))));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if ((J <= 8.3e-181) || (!(J <= 1.85e-137) && (J <= 2.05e-113))) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * (Math.cos((K / 2.0)) * (J * Math.hypot(1.0, (0.5 * (U_m / J)))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (J <= 8.3e-181) or (not (J <= 1.85e-137) and (J <= 2.05e-113)):
		tmp = -U_m
	else:
		tmp = -2.0 * (math.cos((K / 2.0)) * (J * math.hypot(1.0, (0.5 * (U_m / J)))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((J <= 8.3e-181) || (!(J <= 1.85e-137) && (J <= 2.05e-113)))
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * Float64(cos(Float64(K / 2.0)) * Float64(J * hypot(1.0, Float64(0.5 * Float64(U_m / J))))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((J <= 8.3e-181) || (~((J <= 1.85e-137)) && (J <= 2.05e-113)))
		tmp = -U_m;
	else
		tmp = -2.0 * (cos((K / 2.0)) * (J * hypot(1.0, (0.5 * (U_m / J)))));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[J, 8.3e-181], And[N[Not[LessEqual[J, 1.85e-137]], $MachinePrecision], LessEqual[J, 2.05e-113]]], (-U$95$m), N[(-2.0 * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 8.3 \cdot 10^{-181} \lor \neg \left(J \leq 1.85 \cdot 10^{-137}\right) \land J \leq 2.05 \cdot 10^{-113}:\\
\;\;\;\;-U_m\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 60.7% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U_m \leq 1.45 \cdot 10^{-149}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U_m \leq 1.25 \cdot 10^{+66}:\\ \;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U_m}{\frac{J}{0.5}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 1.45e-149)
   (* (* -2.0 J) (cos (* K 0.5)))
   (if (<= U_m 1.25e+66)
     (* -2.0 (* J (hypot 1.0 (/ U_m (/ J 0.5)))))
     (- U_m))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.45e-149) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else if (U_m <= 1.25e+66) {
		tmp = -2.0 * (J * hypot(1.0, (U_m / (J / 0.5))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.45e-149) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else if (U_m <= 1.25e+66) {
		tmp = -2.0 * (J * Math.hypot(1.0, (U_m / (J / 0.5))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 1.45e-149:
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	elif U_m <= 1.25e+66:
		tmp = -2.0 * (J * math.hypot(1.0, (U_m / (J / 0.5))))
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 1.45e-149)
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	elseif (U_m <= 1.25e+66)
		tmp = Float64(-2.0 * Float64(J * hypot(1.0, Float64(U_m / Float64(J / 0.5)))));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 1.45e-149)
		tmp = (-2.0 * J) * cos((K * 0.5));
	elseif (U_m <= 1.25e+66)
		tmp = -2.0 * (J * hypot(1.0, (U_m / (J / 0.5))));
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 1.45e-149], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 1.25e+66], N[(-2.0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(U$95$m / N[(J / 0.5), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U_m \leq 1.45 \cdot 10^{-149}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

\mathbf{elif}\;U_m \leq 1.25 \cdot 10^{+66}:\\
\;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U_m}{\frac{J}{0.5}}\right)\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 59.9% accurate, 3.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U_m \leq 1.2 \cdot 10^{+63}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 1.2e+63) (* (* -2.0 J) (cos (* K 0.5))) (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.2e+63) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (u_m <= 1.2d+63) then
        tmp = ((-2.0d0) * j) * cos((k * 0.5d0))
    else
        tmp = -u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.2e+63) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 1.2e+63:
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 1.2e+63)
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 1.2e+63)
		tmp = (-2.0 * J) * cos((K * 0.5));
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 1.2e+63], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U_m \leq 1.2 \cdot 10^{+63}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 38.8% accurate, 83.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U_m \leq 2.05 \cdot 10^{-113}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 2.05e-113) (* -2.0 J) (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 2.05e-113) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (u_m <= 2.05d-113) then
        tmp = (-2.0d0) * j
    else
        tmp = -u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 2.05e-113) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 2.05e-113:
		tmp = -2.0 * J
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 2.05e-113)
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 2.05e-113)
		tmp = -2.0 * J;
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 2.05e-113], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U_m \leq 2.05 \cdot 10^{-113}:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 27.3% accurate, 103.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 3.9 \cdot 10^{+148}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 (if (<= K 3.9e+148) (- U_m) U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 3.9e+148) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (k <= 3.9d+148) then
        tmp = -u_m
    else
        tmp = u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 3.9e+148) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if K <= 3.9e+148:
		tmp = -U_m
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (K <= 3.9e+148)
		tmp = Float64(-U_m);
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (K <= 3.9e+148)
		tmp = -U_m;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[K, 3.9e+148], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 3.9 \cdot 10^{+148}:\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;U_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 25.8% accurate, 420.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ U_m \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 U_m)
U_m = fabs(U);
double code(double J, double K, double U_m) {
	return U_m;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    code = u_m
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	return U_m;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	return U_m
U_m = abs(U)
function code(J, K, U_m)
	return U_m
end
U_m = abs(U);
function tmp = code(J, K, U_m)
	tmp = U_m;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := U$95$m
\begin{array}{l}
U_m = \left|U\right|

\\
U_m
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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