Average Error: 17.6 → 8.8
Time: 11.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 := \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 5.7011378908621385 \cdot 10^{+302}:\\ \;\;\;\;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 5.7011378908621385 \cdot 10^{+302}:\\
\;\;\;\;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)))) 5.7011378908621385e+302)
     (* 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))) <= 5.7011378908621385e+302) {
		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)))) < 5.70113789086213847e302

    1. Initial program 10.3

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

      \[\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 5.70113789086213847e302 < (*.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 61.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. Simplified27.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. Taylor expanded in J around 0 33.4

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

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

    \[\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 5.7011378908621385 \cdot 10^{+302}:\\ \;\;\;\;\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 2021313 
(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)))))