Average Error: 18.1 → 10.0
Time: 20.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 := t_0 \cdot \left(J \cdot -2\right)\\ \mathbf{if}\;J \leq -3.733683180945843 \cdot 10^{-157}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{t_1}\right)\right)\right)\\ \mathbf{elif}\;J \leq -7.086648613513012 \cdot 10^{-283}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.096025868775934 \cdot 10^{-206}:\\ \;\;\;\;-\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 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\\ \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 := t_0 \cdot \left(J \cdot -2\right)\\
\mathbf{if}\;J \leq -3.733683180945843 \cdot 10^{-157}:\\
\;\;\;\;-2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{t_1}\right)\right)\right)\\

\mathbf{elif}\;J \leq -7.086648613513012 \cdot 10^{-283}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 9.096025868775934 \cdot 10^{-206}:\\
\;\;\;\;-\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 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\\


\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 (* t_0 (* J -2.0))))
   (if (<= J -3.733683180945843e-157)
     (* -2.0 (* J (* t_0 (hypot 1.0 (/ U t_1)))))
     (if (<= J -7.086648613513012e-283)
       U
       (if (<= J 9.096025868775934e-206)
         (- (fma 2.0 (/ (* (* J J) (pow (cos (* K 0.5)) 2.0)) U) U))
         (* t_1 (hypot 1.0 (/ U (* J (* 2.0 t_0))))))))))
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 = t_0 * (J * -2.0);
	double tmp;
	if (J <= -3.733683180945843e-157) {
		tmp = -2.0 * (J * (t_0 * hypot(1.0, (U / t_1))));
	} else if (J <= -7.086648613513012e-283) {
		tmp = U;
	} else if (J <= 9.096025868775934e-206) {
		tmp = -fma(2.0, (((J * J) * pow(cos(K * 0.5), 2.0)) / U), U);
	} else {
		tmp = t_1 * hypot(1.0, (U / (J * (2.0 * t_0))));
	}
	return tmp;
}

Error

Bits error versus J

Bits error versus K

Bits error versus U

Derivation

  1. Split input into 4 regimes
  2. if J < -3.7336831809458427e-157

    1. Initial program 11.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. Simplified2.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. Applied egg2.9

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

    if -3.7336831809458427e-157 < J < -7.08664861351301211e-283

    1. Initial program 38.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. 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 in U around -inf 35.3

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

    if -7.08664861351301211e-283 < J < 9.09602586877593381e-206

    1. Initial program 44.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. Simplified28.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 in J around 0 33.6

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

      \[\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 9.09602586877593381e-206 < J

    1. Initial program 12.6

      \[\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}{\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 egg4.2

      \[\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 2\right) \cdot J}}\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.733683180945843 \cdot 10^{-157}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot -2\right)}\right)\right)\right)\\ \mathbf{elif}\;J \leq -7.086648613513012 \cdot 10^{-283}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.096025868775934 \cdot 10^{-206}:\\ \;\;\;\;-\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(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot -2\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\\ \end{array} \]

Reproduce

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