Average Error: 18.0 → 8.3
Time: 28.3s
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 := \frac{U}{t_0 \cdot \left(J \cdot 2\right)}\\ t_2 := \left(-2 \cdot J\right) \cdot t_0\\ \mathbf{if}\;t_2 \cdot \sqrt{1 + {t_1}^{2}} \leq 1.036085576853195 \cdot 10^{+305}:\\ \;\;\;\;t_2 \cdot \mathsf{hypot}\left(1, t_1\right)\\ \mathbf{else}:\\ \;\;\;\;-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(\frac{K}{2}\right)\\
t_1 := \frac{U}{t_0 \cdot \left(J \cdot 2\right)}\\
t_2 := \left(-2 \cdot J\right) \cdot t_0\\
\mathbf{if}\;t_2 \cdot \sqrt{1 + {t_1}^{2}} \leq 1.036085576853195 \cdot 10^{+305}:\\
\;\;\;\;t_2 \cdot \mathsf{hypot}\left(1, t_1\right)\\

\mathbf{else}:\\
\;\;\;\;-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 2.0)))
        (t_1 (/ U (* t_0 (* J 2.0))))
        (t_2 (* (* -2.0 J) t_0)))
   (if (<= (* t_2 (sqrt (+ 1.0 (pow t_1 2.0)))) 1.036085576853195e+305)
     (* t_2 (hypot 1.0 t_1))
     (- 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 / 2.0));
	double t_1 = U / (t_0 * (J * 2.0));
	double t_2 = (-2.0 * J) * t_0;
	double tmp;
	if ((t_2 * sqrt((1.0 + pow(t_1, 2.0)))) <= 1.036085576853195e+305) {
		tmp = t_2 * hypot(1.0, t_1);
	} else {
		tmp = -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 (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < 1.036085576853195e305

    1. Initial program 10.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. Simplified4.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 1.036085576853195e305 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 62.8

      \[\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.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 J around 0 31.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 1.036085576853195 \cdot 10^{+305}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Reproduce

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