Average Error: 18.3 → 9.2
Time: 12.0s
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 -2.282917432201898 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -3.970878637552764 \cdot 10^{-219}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1.3007612218473472 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq 1.289364658539573 \cdot 10^{-207}:\\ \;\;\;\;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 -2.282917432201898 \cdot 10^{-180}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -3.970878637552764 \cdot 10^{-219}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq -1.3007612218473472 \cdot 10^{-306}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq 1.289364658539573 \cdot 10^{-207}:\\
\;\;\;\;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 -2.282917432201898e-180)
     t_1
     (if (<= J -3.970878637552764e-219)
       (- U)
       (if (<= J -1.3007612218473472e-306)
         t_1
         (if (<= J 1.289364658539573e-207) 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 <= -2.282917432201898e-180) {
		tmp = t_1;
	} else if (J <= -3.970878637552764e-219) {
		tmp = -U;
	} else if (J <= -1.3007612218473472e-306) {
		tmp = t_1;
	} else if (J <= 1.289364658539573e-207) {
		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 < -2.2829174322018979e-180 or -3.97087863755276417e-219 < J < -1.30076122184734721e-306 or 1.289364658539573e-207 < J

    1. Initial program 15.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. Simplified6.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 -2.2829174322018979e-180 < J < -3.97087863755276417e-219

    1. Initial program 38.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. Simplified21.8

      \[\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 in J around 0 36.4

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

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

    if -1.30076122184734721e-306 < J < 1.289364658539573e-207

    1. Initial program 43.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. Simplified29.8

      \[\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 in U around -inf 34.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.282917432201898 \cdot 10^{-180}:\\ \;\;\;\;\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 -3.970878637552764 \cdot 10^{-219}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq -1.3007612218473472 \cdot 10^{-306}:\\ \;\;\;\;\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 1.289364658539573 \cdot 10^{-207}:\\ \;\;\;\;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 2022103 
(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)))))