Average Error: 18.1 → 8.4
Time: 12.7s
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 -3.678515660926543 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\ \mathbf{if}\;J \leq -2.0731189763801308 \cdot 10^{-263}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq 2.3963648443487414 \cdot 10^{-281}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.7554685803717827 \cdot 10^{-249}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \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 -3.678515660926543 \cdot 10^{-236}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\
\mathbf{if}\;J \leq -2.0731189763801308 \cdot 10^{-263}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;J \leq 2.3963648443487414 \cdot 10^{-281}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.7554685803717827 \cdot 10^{-249}:\\
\;\;\;\;t_2\\

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


\end{array}\\


\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 -3.678515660926543e-236)
     t_1
     (let* ((t_2 (fma 2.0 (/ (* (* J J) (pow (cos (* K 0.5)) 2.0)) U) U)))
       (if (<= J -2.0731189763801308e-263)
         t_2
         (if (<= J 2.3963648443487414e-281)
           (- U)
           (if (<= J 2.7554685803717827e-249) 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 = 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 <= -3.678515660926543e-236) {
		tmp = t_1;
	} else {
		double t_2 = fma(2.0, (((J * J) * pow(cos(K * 0.5), 2.0)) / U), U);
		double tmp_1;
		if (J <= -2.0731189763801308e-263) {
			tmp_1 = t_2;
		} else if (J <= 2.3963648443487414e-281) {
			tmp_1 = -U;
		} else if (J <= 2.7554685803717827e-249) {
			tmp_1 = t_2;
		} else {
			tmp_1 = t_1;
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus J

Bits error versus K

Bits error versus U

Derivation

  1. Split input into 3 regimes
  2. if J < -3.67851566092654312e-236 or 2.7554685803717827e-249 < J

    1. Initial program 15.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. Simplified5.5

      \[\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 -3.67851566092654312e-236 < J < -2.07311897638013076e-263 or 2.3963648443487414e-281 < J < 2.7554685803717827e-249

    1. Initial program 41.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. Simplified25.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 in U around -inf 35.9

      \[\leadsto \color{blue}{2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + U} \]
    4. Simplified35.9

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

    if -2.07311897638013076e-263 < J < 2.3963648443487414e-281

    1. Initial program 46.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. Simplified32.1

      \[\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 32.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.678515660926543 \cdot 10^{-236}:\\ \;\;\;\;\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.0731189763801308 \cdot 10^{-263}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\ \mathbf{elif}\;J \leq 2.3963648443487414 \cdot 10^{-281}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.7554685803717827 \cdot 10^{-249}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\ \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 2022019 
(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)))))