Average Error: 17.8 → 8.5
Time: 11.6s
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(K \cdot 0.5\right)\\ \mathbf{if}\;J \leq -9.456952117734688 \cdot 10^{-234} \lor \neg \left(J \leq 3.848224094713413 \cdot 10^{-273}\right):\\ \;\;\;\;\left(\left(J \cdot -2\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J \cdot t_0}\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{{t_0}^{2} \cdot {J}^{2}}{U} - 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}
t_0 := \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq -9.456952117734688 \cdot 10^{-234} \lor \neg \left(J \leq 3.848224094713413 \cdot 10^{-273}\right):\\
\;\;\;\;\left(\left(J \cdot -2\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J \cdot t_0}\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{{t_0}^{2} \cdot {J}^{2}}{U} - 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
 (let* ((t_0 (cos (* K 0.5))))
   (if (or (<= J -9.456952117734688e-234) (not (<= J 3.848224094713413e-273)))
     (* (* (* J -2.0) (cos (/ K 2.0))) (hypot 1.0 (* 0.5 (/ U (* J t_0)))))
     (- (* -2.0 (/ (* (pow t_0 2.0) (pow J 2.0)) U)) 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 t_0 = cos(K * 0.5);
	double tmp;
	if ((J <= -9.456952117734688e-234) || !(J <= 3.848224094713413e-273)) {
		tmp = ((J * -2.0) * cos(K / 2.0)) * hypot(1.0, (0.5 * (U / (J * t_0))));
	} else {
		tmp = (-2.0 * ((pow(t_0, 2.0) * pow(J, 2.0)) / U)) - 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 < -9.45695211773468832e-234 or 3.84822409471341332e-273 < 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)} \]
    3. Applied *-un-lft-identity_binary646.0

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

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{1}{\cos \left(\frac{K}{2}\right)} \cdot \frac{U}{J \cdot 2}}\right) \]
    5. Taylor expanded in K around inf 6.0

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

    if -9.45695211773468832e-234 < J < 3.84822409471341332e-273

    1. Initial program 41.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.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)} \]
    3. Applied *-un-lft-identity_binary6426.5

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

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{1}{\cos \left(\frac{K}{2}\right)} \cdot \frac{U}{J \cdot 2}}\right) \]
    5. Taylor expanded in U around inf 34.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -9.456952117734688 \cdot 10^{-234} \lor \neg \left(J \leq 3.848224094713413 \cdot 10^{-273}\right):\\ \;\;\;\;\left(\left(J \cdot -2\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J \cdot \cos \left(K \cdot 0.5\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{{\cos \left(K \cdot 0.5\right)}^{2} \cdot {J}^{2}}{U} - U\\ \end{array} \]

Reproduce

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