Average Error: 18.6 → 9.6
Time: 11.2s
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 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\left(J \cdot -2\right) \cdot t_0\right) \cdot \mathsf{hypot}\left(1, \frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)\\ \mathbf{if}\;J \leq -5.636250867741126 \cdot 10^{-255}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -2.4993835334593255 \cdot 10^{-282}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 3.0750365055579345 \cdot 10^{-288}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.9339533218706902 \cdot 10^{-169}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\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 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(J \cdot -2\right) \cdot t_0\right) \cdot \mathsf{hypot}\left(1, \frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)\\
\mathbf{if}\;J \leq -5.636250867741126 \cdot 10^{-255}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -2.4993835334593255 \cdot 10^{-282}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 3.0750365055579345 \cdot 10^{-288}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.9339533218706902 \cdot 10^{-169}:\\
\;\;\;\;-U\\

\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 (cos (/ K 2.0)))
        (t_1 (* (* (* J -2.0) t_0) (hypot 1.0 (/ U (* t_0 (* J 2.0)))))))
   (if (<= J -5.636250867741126e-255)
     t_1
     (if (<= J -2.4993835334593255e-282)
       (- U)
       (if (<= J 3.0750365055579345e-288)
         U
         (if (<= J 1.9339533218706902e-169) (- U) 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 = cos(K / 2.0);
	double t_1 = ((J * -2.0) * t_0) * hypot(1.0, (U / (t_0 * (J * 2.0))));
	double tmp;
	if (J <= -5.636250867741126e-255) {
		tmp = t_1;
	} else if (J <= -2.4993835334593255e-282) {
		tmp = -U;
	} else if (J <= 3.0750365055579345e-288) {
		tmp = U;
	} else if (J <= 1.9339533218706902e-169) {
		tmp = -U;
	} else {
		tmp = t_1;
	}
	return tmp;
}

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.6362508677411259e-255 or 1.9339533218706902e-169 < J

    1. Initial program 14.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. Simplified5.0

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

    if -5.6362508677411259e-255 < J < -2.4993835334593255e-282 or 3.07503650555793452e-288 < J < 1.9339533218706902e-169

    1. Initial program 39.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. Simplified24.6

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

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

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

    if -2.4993835334593255e-282 < J < 3.07503650555793452e-288

    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. Simplified27.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.636250867741126 \cdot 10^{-255}:\\ \;\;\;\;\left(\left(J \cdot -2\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)\\ \mathbf{elif}\;J \leq -2.4993835334593255 \cdot 10^{-282}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 3.0750365055579345 \cdot 10^{-288}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.9339533218706902 \cdot 10^{-169}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(\left(J \cdot -2\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)\\ \end{array} \]

Reproduce

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