Average Error: 18.3 → 9.1
Time: 9.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)\\ t_1 := \cos \left(\frac{K}{2}\right)\\ t_2 := \left(\left(-2 \cdot J\right) \cdot t_1\right) \cdot \sqrt{1 + {\left(\frac{U}{t_1 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;t_2 \leq 10^{+307}:\\ \;\;\;\;-2 \cdot \left(\mathsf{hypot}\left(1, \frac{U}{\left(J \cdot 2\right) \cdot t_0}\right) \cdot \left(J \cdot t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {t_0}^{2}\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 0.5)))
        (t_1 (cos (/ K 2.0)))
        (t_2
         (*
          (* (* -2.0 J) t_1)
          (sqrt (+ 1.0 (pow (/ U (* t_1 (* J 2.0))) 2.0))))))
   (if (<= t_2 (- INFINITY))
     (* -2.0 (* U 0.5))
     (if (<= t_2 1e+307)
       (* -2.0 (* (hypot 1.0 (/ U (* (* J 2.0) t_0))) (* J t_1)))
       (* -2.0 (- (* U -0.5) (* (/ (* J J) U) (pow t_0 2.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 * 0.5));
	double t_1 = cos((K / 2.0));
	double t_2 = ((-2.0 * J) * t_1) * sqrt((1.0 + pow((U / (t_1 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = -2.0 * (U * 0.5);
	} else if (t_2 <= 1e+307) {
		tmp = -2.0 * (hypot(1.0, (U / ((J * 2.0) * t_0))) * (J * t_1));
	} else {
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * pow(t_0, 2.0)));
	}
	return tmp;
}
public static double code(double J, double K, double U) {
	return ((-2.0 * J) * Math.cos((K / 2.0))) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * Math.cos((K / 2.0)))), 2.0)));
}
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = Math.cos((K / 2.0));
	double t_2 = ((-2.0 * J) * t_1) * Math.sqrt((1.0 + Math.pow((U / (t_1 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = -2.0 * (U * 0.5);
	} else if (t_2 <= 1e+307) {
		tmp = -2.0 * (Math.hypot(1.0, (U / ((J * 2.0) * t_0))) * (J * t_1));
	} else {
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * Math.pow(t_0, 2.0)));
	}
	return tmp;
}
def code(J, K, U):
	return ((-2.0 * J) * math.cos((K / 2.0))) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * math.cos((K / 2.0)))), 2.0)))
def code(J, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = math.cos((K / 2.0))
	t_2 = ((-2.0 * J) * t_1) * math.sqrt((1.0 + math.pow((U / (t_1 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_2 <= -math.inf:
		tmp = -2.0 * (U * 0.5)
	elif t_2 <= 1e+307:
		tmp = -2.0 * (math.hypot(1.0, (U / ((J * 2.0) * t_0))) * (J * t_1))
	else:
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * math.pow(t_0, 2.0)))
	return tmp
function code(J, K, U)
	return Float64(Float64(Float64(-2.0 * J) * cos(Float64(K / 2.0))) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * cos(Float64(K / 2.0)))) ^ 2.0))))
end
function code(J, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = cos(Float64(K / 2.0))
	t_2 = Float64(Float64(Float64(-2.0 * J) * t_1) * sqrt(Float64(1.0 + (Float64(U / Float64(t_1 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(-2.0 * Float64(U * 0.5));
	elseif (t_2 <= 1e+307)
		tmp = Float64(-2.0 * Float64(hypot(1.0, Float64(U / Float64(Float64(J * 2.0) * t_0))) * Float64(J * t_1)));
	else
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(Float64(Float64(J * J) / U) * (t_0 ^ 2.0))));
	end
	return tmp
end
function tmp = code(J, K, U)
	tmp = ((-2.0 * J) * cos((K / 2.0))) * sqrt((1.0 + ((U / ((2.0 * J) * cos((K / 2.0)))) ^ 2.0)));
end
function tmp_2 = code(J, K, U)
	t_0 = cos((K * 0.5));
	t_1 = cos((K / 2.0));
	t_2 = ((-2.0 * J) * t_1) * sqrt((1.0 + ((U / (t_1 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = -2.0 * (U * 0.5);
	elseif (t_2 <= 1e+307)
		tmp = -2.0 * (hypot(1.0, (U / ((J * 2.0) * t_0))) * (J * t_1));
	else
		tmp = -2.0 * ((U * -0.5) - (((J * J) / U) * (t_0 ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, K_, U_] := N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(t$95$1 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(-2.0 * N[(U * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+307], N[(-2.0 * N[(N[Sqrt[1.0 ^ 2 + N[(U / N[(N[(J * 2.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] * N[(J * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(N[(N[(J * J), $MachinePrecision] / U), $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\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)\\
t_1 := \cos \left(\frac{K}{2}\right)\\
t_2 := \left(\left(-2 \cdot J\right) \cdot t_1\right) \cdot \sqrt{1 + {\left(\frac{U}{t_1 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\

\mathbf{elif}\;t_2 \leq 10^{+307}:\\
\;\;\;\;-2 \cdot \left(\mathsf{hypot}\left(1, \frac{U}{\left(J \cdot 2\right) \cdot t_0}\right) \cdot \left(J \cdot t_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {t_0}^{2}\right)\\


\end{array}

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 3 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)))) < -inf.0

    1. Initial program 64.0

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

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]

    if -inf.0 < (*.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)))) < 9.99999999999999986e306

    1. Initial program 0.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. Simplified0.1

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

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

    if 9.99999999999999986e306 < (*.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 63.7

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

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

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

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

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

    \[\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 -\infty:\\ \;\;\;\;-2 \cdot \left(U \cdot 0.5\right)\\ \mathbf{elif}\;\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 10^{+307}:\\ \;\;\;\;-2 \cdot \left(\mathsf{hypot}\left(1, \frac{U}{\left(J \cdot 2\right) \cdot \cos \left(K \cdot 0.5\right)}\right) \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U} \cdot {\cos \left(K \cdot 0.5\right)}^{2}\right)\\ \end{array} \]

Reproduce

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