Average Error: 17.6 → 8.6
Time: 10.3s
Precision: binary64
\[\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}} \]
\[\begin{array}{l} t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\ t_1 := -2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_0}\right)\right)\\ t_2 := -2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{if}\;J \leq -5.5 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-296}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-238}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {\cos \left(K \cdot 0.5\right)}^{2}\right)\\ \mathbf{elif}\;J \leq 1.56 \cdot 10^{-226}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (J K U)
 :precision binary64
 (*
  (* (* -2.0 J) (cos (/ K 2.0)))
  (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (cos (/ K 2.0))))
        (t_1 (* -2.0 (* t_0 (hypot 1.0 (/ U (* 2.0 t_0))))))
        (t_2 (* -2.0 (* U 0.5))))
   (if (<= J -5.5e-199)
     t_1
     (if (<= J 1.5e-296)
       t_2
       (if (<= J 1.05e-238)
         (* -2.0 (- (* U -0.5) (* (/ (* J J) U) (pow (cos (* K 0.5)) 2.0))))
         (if (<= J 1.56e-226) t_2 t_1))))))
double code(double J, double K, double U) {
	return ((-2.0 * J) * cos((K / 2.0))) * sqrt((1.0 + pow((U / ((2.0 * J) * cos((K / 2.0)))), 2.0)));
}
double code(double J, double K, double U) {
	double t_0 = J * cos((K / 2.0));
	double t_1 = -2.0 * (t_0 * hypot(1.0, (U / (2.0 * t_0))));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -5.5e-199) {
		tmp = t_1;
	} else if (J <= 1.5e-296) {
		tmp = t_2;
	} else if (J <= 1.05e-238) {
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * pow(cos((K * 0.5)), 2.0)));
	} else if (J <= 1.56e-226) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double K, double U) {
	return ((-2.0 * J) * Math.cos((K / 2.0))) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * Math.cos((K / 2.0)))), 2.0)));
}
public static double code(double J, double K, double U) {
	double t_0 = J * Math.cos((K / 2.0));
	double t_1 = -2.0 * (t_0 * Math.hypot(1.0, (U / (2.0 * t_0))));
	double t_2 = -2.0 * (U * 0.5);
	double tmp;
	if (J <= -5.5e-199) {
		tmp = t_1;
	} else if (J <= 1.5e-296) {
		tmp = t_2;
	} else if (J <= 1.05e-238) {
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * Math.pow(Math.cos((K * 0.5)), 2.0)));
	} else if (J <= 1.56e-226) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, K, U):
	return ((-2.0 * J) * math.cos((K / 2.0))) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * math.cos((K / 2.0)))), 2.0)))
def code(J, K, U):
	t_0 = J * math.cos((K / 2.0))
	t_1 = -2.0 * (t_0 * math.hypot(1.0, (U / (2.0 * t_0))))
	t_2 = -2.0 * (U * 0.5)
	tmp = 0
	if J <= -5.5e-199:
		tmp = t_1
	elif J <= 1.5e-296:
		tmp = t_2
	elif J <= 1.05e-238:
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * math.pow(math.cos((K * 0.5)), 2.0)))
	elif J <= 1.56e-226:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, K, U)
	return Float64(Float64(Float64(-2.0 * J) * cos(Float64(K / 2.0))) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * cos(Float64(K / 2.0)))) ^ 2.0))))
end
function code(J, K, U)
	t_0 = Float64(J * cos(Float64(K / 2.0)))
	t_1 = Float64(-2.0 * Float64(t_0 * hypot(1.0, Float64(U / Float64(2.0 * t_0)))))
	t_2 = Float64(-2.0 * Float64(U * 0.5))
	tmp = 0.0
	if (J <= -5.5e-199)
		tmp = t_1;
	elseif (J <= 1.5e-296)
		tmp = t_2;
	elseif (J <= 1.05e-238)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(Float64(Float64(J * J) / U) * (cos(Float64(K * 0.5)) ^ 2.0))));
	elseif (J <= 1.56e-226)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(J, K, U)
	tmp = ((-2.0 * J) * cos((K / 2.0))) * sqrt((1.0 + ((U / ((2.0 * J) * cos((K / 2.0)))) ^ 2.0)));
end
function tmp_2 = code(J, K, U)
	t_0 = J * cos((K / 2.0));
	t_1 = -2.0 * (t_0 * hypot(1.0, (U / (2.0 * t_0))));
	t_2 = -2.0 * (U * 0.5);
	tmp = 0.0;
	if (J <= -5.5e-199)
		tmp = t_1;
	elseif (J <= 1.5e-296)
		tmp = t_2;
	elseif (J <= 1.05e-238)
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * (cos((K * 0.5)) ^ 2.0)));
	elseif (J <= 1.56e-226)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, K_, U_] := N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -5.5e-199], t$95$1, If[LessEqual[J, 1.5e-296], t$95$2, If[LessEqual[J, 1.05e-238], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(N[(N[(J * J), $MachinePrecision] / U), $MachinePrecision] * N[Power[N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.56e-226], t$95$2, t$95$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}}
\begin{array}{l}
t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\
t_1 := -2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_0}\right)\right)\\
t_2 := -2 \cdot \left(U \cdot 0.5\right)\\
\mathbf{if}\;J \leq -5.5 \cdot 10^{-199}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq 1.5 \cdot 10^{-296}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;J \leq 1.05 \cdot 10^{-238}:\\
\;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {\cos \left(K \cdot 0.5\right)}^{2}\right)\\

\mathbf{elif}\;J \leq 1.56 \cdot 10^{-226}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Bits error versus J

Bits error versus K

Bits error versus U

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if J < -5.5000000000000001e-199 or 1.56e-226 < J

    1. Initial program 13.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. Simplified4.2

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

    if -5.5000000000000001e-199 < J < 1.4999999999999999e-296 or 1.0500000000000001e-238 < J < 1.56e-226

    1. Initial program 42.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. Simplified26.9

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

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

    if 1.4999999999999999e-296 < J < 1.0500000000000001e-238

    1. Initial program 45.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. Simplified26.4

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

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

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

      \[\leadsto -2 \cdot \color{blue}{\left(-\left(\frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + 0.5 \cdot U\right)\right)} \]
    6. Simplified32.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.5 \cdot 10^{-199}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-296}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-238}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {\cos \left(K \cdot 0.5\right)}^{2}\right)\\ \mathbf{elif}\;J \leq 1.56 \cdot 10^{-226}:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\\ \end{array} \]

Reproduce

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