Average Error: 17.8 → 8.7
Time: 11.1s
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} \mathbf{if}\;J \leq -2.8689791562071003 \cdot 10^{-208} \lor \neg \left(J \leq 2.176564396023258 \cdot 10^{-255}\right):\\ \;\;\;\;\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \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) \end{array}\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \frac{{J}^{2} \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}\\ \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}
\mathbf{if}\;J \leq -2.8689791562071003 \cdot 10^{-208} \lor \neg \left(J \leq 2.176564396023258 \cdot 10^{-255}\right):\\
\;\;\;\;\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\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)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \frac{{J}^{2} \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}\\


\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
 (if (or (<= J -2.8689791562071003e-208) (not (<= J 2.176564396023258e-255)))
   (let* ((t_0 (cos (/ K 2.0))))
     (* (* (* J -2.0) t_0) (hypot 1.0 (/ U (* t_0 (* J 2.0))))))
   (+ U (* 2.0 (/ (* (pow J 2.0) (pow (cos (* K 0.5)) 2.0)) U)))))
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 tmp;
	if ((J <= -2.8689791562071003e-208) || !(J <= 2.176564396023258e-255)) {
		double t_0_1 = cos(K / 2.0);
		tmp = ((J * -2.0) * t_0_1) * hypot(1.0, (U / (t_0_1 * (J * 2.0))));
	} else {
		tmp = U + (2.0 * ((pow(J, 2.0) * pow(cos(K * 0.5), 2.0)) / U));
	}
	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 2 regimes
  2. if J < -2.8689791562071003e-208 or 2.176564396023258e-255 < J

    1. Initial program 14.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. Simplified5.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)} \]

    if -2.8689791562071003e-208 < J < 2.176564396023258e-255

    1. Initial program 42.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. Simplified26.9

      \[\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.5

      \[\leadsto \color{blue}{2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} + U} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.8689791562071003 \cdot 10^{-208} \lor \neg \left(J \leq 2.176564396023258 \cdot 10^{-255}\right):\\ \;\;\;\;\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{else}:\\ \;\;\;\;U + 2 \cdot \frac{{J}^{2} \cdot {\cos \left(K \cdot 0.5\right)}^{2}}{U}\\ \end{array} \]

Reproduce

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