Average Error: 18.4 → 9.7
Time: 33.0s
Precision: binary64
Cost: 20484
\[\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(0.5 \cdot K\right)\\ \mathbf{if}\;U \leq -4 \cdot 10^{+182}:\\ \;\;\;\;\left(\left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-2 \cdot t_0\right) \cdot J\right) \cdot \mathsf{hypot}\left(\frac{\frac{U}{J \cdot t_0}}{2}, 1\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 (* 0.5 K))))
   (if (<= U -4e+182)
     (* (* (* 2.0 (* J (cos (* K 0.5)))) U) (fabs (/ 0.5 J)))
     (* (* (* -2.0 t_0) J) (hypot (/ (/ U (* J t_0)) 2.0) 1.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((0.5 * K));
	double tmp;
	if (U <= -4e+182) {
		tmp = ((2.0 * (J * cos((K * 0.5)))) * U) * fabs((0.5 / J));
	} else {
		tmp = ((-2.0 * t_0) * J) * hypot(((U / (J * t_0)) / 2.0), 1.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((0.5 * K));
	double tmp;
	if (U <= -4e+182) {
		tmp = ((2.0 * (J * Math.cos((K * 0.5)))) * U) * Math.abs((0.5 / J));
	} else {
		tmp = ((-2.0 * t_0) * J) * Math.hypot(((U / (J * t_0)) / 2.0), 1.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((0.5 * K))
	tmp = 0
	if U <= -4e+182:
		tmp = ((2.0 * (J * math.cos((K * 0.5)))) * U) * math.fabs((0.5 / J))
	else:
		tmp = ((-2.0 * t_0) * J) * math.hypot(((U / (J * t_0)) / 2.0), 1.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(0.5 * K))
	tmp = 0.0
	if (U <= -4e+182)
		tmp = Float64(Float64(Float64(2.0 * Float64(J * cos(Float64(K * 0.5)))) * U) * abs(Float64(0.5 / J)));
	else
		tmp = Float64(Float64(Float64(-2.0 * t_0) * J) * hypot(Float64(Float64(U / Float64(J * t_0)) / 2.0), 1.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((0.5 * K));
	tmp = 0.0;
	if (U <= -4e+182)
		tmp = ((2.0 * (J * cos((K * 0.5)))) * U) * abs((0.5 / J));
	else
		tmp = ((-2.0 * t_0) * J) * hypot(((U / (J * t_0)) / 2.0), 1.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[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[U, -4e+182], N[(N[(N[(2.0 * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * U), $MachinePrecision] * N[Abs[N[(0.5 / J), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(-2.0 * t$95$0), $MachinePrecision] * J), $MachinePrecision] * N[Sqrt[N[(N[(U / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] ^ 2 + 1.0 ^ 2], $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(0.5 \cdot K\right)\\
\mathbf{if}\;U \leq -4 \cdot 10^{+182}:\\
\;\;\;\;\left(\left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\

\mathbf{else}:\\
\;\;\;\;\left(\left(-2 \cdot t_0\right) \cdot J\right) \cdot \mathsf{hypot}\left(\frac{\frac{U}{J \cdot t_0}}{2}, 1\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if U < -4.0000000000000003e182

    1. Initial program 41.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. Taylor expanded in K around 0 64.0

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}} \]
    3. Simplified64.0

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{0.25 \cdot \left(U \cdot U\right)}{J \cdot J}}} \]
      Proof
    4. Taylor expanded in U around -inf 51.0

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(-1 \cdot \left(\sqrt{\frac{0.25}{{J}^{2}}} \cdot U\right)\right)} \]
    5. Simplified51.0

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(-\sqrt{\frac{0.25}{J \cdot J}} \cdot U\right)} \]
      Proof
    6. Applied egg-rr41.6

      \[\leadsto \color{blue}{\left(\left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|} \]

    if -4.0000000000000003e182 < U

    1. Initial program 15.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. Applied egg-rr6.1

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

      \[\leadsto \color{blue}{\left(\left(-2 \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right) \cdot \mathsf{hypot}\left(\frac{\frac{U}{J \cdot \cos \left(0.5 \cdot K\right)}}{2}, 1\right)} \]
      Proof
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error9.7
Cost20484
\[\begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;U \leq -2.35 \cdot 10^{+182}:\\ \;\;\;\;\left(\left(2 \cdot \left(J \cdot t_0\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(\frac{\frac{U}{J}}{t_0 \cdot 2}, 1\right)\right)\\ \end{array} \]
Alternative 2
Error18.2
Cost13828
\[\begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;U \leq -3.4 \cdot 10^{+182}:\\ \;\;\;\;\left(\left(2 \cdot \left(J \cdot t_0\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(t_0 \cdot \mathsf{hypot}\left(\frac{U \cdot 0.5}{J}, 1\right)\right)\\ \end{array} \]
Alternative 3
Error18.2
Cost13828
\[\begin{array}{l} \mathbf{if}\;U \leq -2 \cdot 10^{+181}:\\ \;\;\;\;\left(\left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-2 \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right) \cdot \mathsf{hypot}\left(\frac{\frac{U}{J}}{2}, 1\right)\\ \end{array} \]
Alternative 4
Error28.8
Cost13764
\[\begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := t_0 \cdot U\\ t_2 := -t_1\\ t_3 := \left(-2 \cdot t_0\right) \cdot J\\ \mathbf{if}\;U \leq -7 \cdot 10^{+43}:\\ \;\;\;\;\left(\left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \cdot U\right) \cdot \left|\frac{0.5}{J}\right|\\ \mathbf{elif}\;U \leq -1.75 \cdot 10^{-40}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \frac{\left(U \cdot U\right) \cdot 0.125}{J \cdot J}\right)\\ \mathbf{elif}\;U \leq -3.4 \cdot 10^{-56}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;U \leq 2.9 \cdot 10^{+80}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;U \leq 8.8 \cdot 10^{+142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq 1.05 \cdot 10^{+201}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error29.8
Cost7640
\[\begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := t_0 \cdot U\\ t_2 := -t_1\\ t_3 := \left(-2 \cdot t_0\right) \cdot J\\ \mathbf{if}\;U \leq -4.6 \cdot 10^{+147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq -1.75 \cdot 10^{-40}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;U \leq -3.4 \cdot 10^{-56}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;U \leq 2.4 \cdot 10^{+82}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;U \leq 1.9 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq 1.15 \cdot 10^{+201}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error29.7
Cost7640
\[\begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := \left(-2 \cdot t_0\right) \cdot J\\ t_2 := t_0 \cdot U\\ t_3 := -t_2\\ \mathbf{if}\;U \leq -1.5 \cdot 10^{+127}:\\ \;\;\;\;\left(\sqrt{\frac{0.25}{J \cdot J}} \cdot \left(J \cdot U\right)\right) \cdot 2\\ \mathbf{elif}\;U \leq -1.75 \cdot 10^{-40}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq -3.4 \cdot 10^{-56}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;U \leq 1.56 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;U \leq 6.5 \cdot 10^{+142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;U \leq 1.05 \cdot 10^{+201}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error42.3
Cost7116
\[\begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right) \cdot U\\ \mathbf{if}\;J \leq -1.75 \cdot 10^{-66}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2.2 \cdot 10^{-187}:\\ \;\;\;\;-t_0\\ \mathbf{elif}\;J \leq 4.4 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]
Alternative 8
Error42.5
Cost6984
\[\begin{array}{l} \mathbf{if}\;J \leq -1.55 \cdot 10^{-44}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 3.6 \cdot 10^{-77}:\\ \;\;\;\;\cos \left(0.5 \cdot K\right) \cdot U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]
Alternative 9
Error45.2
Cost192
\[-2 \cdot J \]

Error

Reproduce

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