Average Error: 18.1 → 8.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 -7.46424867012432 \cdot 10^{-294}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq 4.5127680789433535 \cdot 10^{-253}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\ \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 -7.46424867012432 \cdot 10^{-294}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq 4.5127680789433535 \cdot 10^{-253}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{\left(J \cdot J\right) \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}, U\right)\\

\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 -7.46424867012432e-294)
     t_1
     (if (<= J 4.5127680789433535e-253)
       (fma 2.0 (/ (* (* J J) (pow (cos (* K 0.5)) 2.0)) U) 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 <= -7.46424867012432e-294) {
		tmp = t_1;
	} else if (J <= 4.5127680789433535e-253) {
		tmp = fma(2.0, (((J * J) * pow(cos(K * 0.5), 2.0)) / U), U);
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus J

Bits error versus K

Bits error versus U

Derivation

  1. Split input into 2 regimes
  2. if J < -7.46424867012432064e-294 or 4.51276807894335345e-253 < J

    1. Initial program 16.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.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. Applied pow1_binary646.6

      \[\leadsto \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 \color{blue}{{2}^{1}}\right)}\right) \]
    4. Applied pow1_binary646.6

      \[\leadsto \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(\color{blue}{{J}^{1}} \cdot {2}^{1}\right)}\right) \]
    5. Applied pow-prod-down_binary646.6

      \[\leadsto \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 \color{blue}{{\left(J \cdot 2\right)}^{1}}}\right) \]
    6. Applied pow1_binary646.6

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{{\cos \left(\frac{K}{2}\right)}^{1}} \cdot {\left(J \cdot 2\right)}^{1}}\right) \]
    7. Applied pow-prod-down_binary646.6

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

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

    if -7.46424867012432064e-294 < J < 4.51276807894335345e-253

    1. Initial program 42.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. Simplified28.4

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

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

      \[\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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7.46424867012432 \cdot 10^{-294}:\\ \;\;\;\;\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 4.5127680789433535 \cdot 10^{-253}:\\ \;\;\;\;\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 2022087 
(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)))))