Average Error: 17.9 → 8.7
Time: 13.2s
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 := -2 \cdot \left(U \cdot -0.5\right)\\ t_1 := \cos \left(K \cdot 0.5\right)\\ t_2 := -2 \cdot \left(\left(J \cdot t_1\right) \cdot \mathsf{hypot}\left(1, \frac{U}{t_1 \cdot \left(J \cdot 2\right)}\right)\right)\\ \mathbf{if}\;J \leq -1.06 \cdot 10^{-197}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq 2.7 \cdot 10^{-303}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 4 \cdot 10^{-290}:\\ \;\;\;\;-2 \cdot \left(0.5 \cdot U\right)\\ \mathbf{elif}\;J \leq 1.6 \cdot 10^{-250}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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 (* -2.0 (* U -0.5)))
        (t_1 (cos (* K 0.5)))
        (t_2 (* -2.0 (* (* J t_1) (hypot 1.0 (/ U (* t_1 (* J 2.0))))))))
   (if (<= J -1.06e-197)
     t_2
     (if (<= J 2.7e-303)
       t_0
       (if (<= J 4e-290) (* -2.0 (* 0.5 U)) (if (<= J 1.6e-250) t_0 t_2))))))
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 = -2.0 * (U * -0.5);
	double t_1 = cos((K * 0.5));
	double t_2 = -2.0 * ((J * t_1) * hypot(1.0, (U / (t_1 * (J * 2.0)))));
	double tmp;
	if (J <= -1.06e-197) {
		tmp = t_2;
	} else if (J <= 2.7e-303) {
		tmp = t_0;
	} else if (J <= 4e-290) {
		tmp = -2.0 * (0.5 * U);
	} else if (J <= 1.6e-250) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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 = -2.0 * (U * -0.5);
	double t_1 = Math.cos((K * 0.5));
	double t_2 = -2.0 * ((J * t_1) * Math.hypot(1.0, (U / (t_1 * (J * 2.0)))));
	double tmp;
	if (J <= -1.06e-197) {
		tmp = t_2;
	} else if (J <= 2.7e-303) {
		tmp = t_0;
	} else if (J <= 4e-290) {
		tmp = -2.0 * (0.5 * U);
	} else if (J <= 1.6e-250) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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 = -2.0 * (U * -0.5)
	t_1 = math.cos((K * 0.5))
	t_2 = -2.0 * ((J * t_1) * math.hypot(1.0, (U / (t_1 * (J * 2.0)))))
	tmp = 0
	if J <= -1.06e-197:
		tmp = t_2
	elif J <= 2.7e-303:
		tmp = t_0
	elif J <= 4e-290:
		tmp = -2.0 * (0.5 * U)
	elif J <= 1.6e-250:
		tmp = t_0
	else:
		tmp = t_2
	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 = Float64(-2.0 * Float64(U * -0.5))
	t_1 = cos(Float64(K * 0.5))
	t_2 = Float64(-2.0 * Float64(Float64(J * t_1) * hypot(1.0, Float64(U / Float64(t_1 * Float64(J * 2.0))))))
	tmp = 0.0
	if (J <= -1.06e-197)
		tmp = t_2;
	elseif (J <= 2.7e-303)
		tmp = t_0;
	elseif (J <= 4e-290)
		tmp = Float64(-2.0 * Float64(0.5 * U));
	elseif (J <= 1.6e-250)
		tmp = t_0;
	else
		tmp = t_2;
	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 = -2.0 * (U * -0.5);
	t_1 = cos((K * 0.5));
	t_2 = -2.0 * ((J * t_1) * hypot(1.0, (U / (t_1 * (J * 2.0)))));
	tmp = 0.0;
	if (J <= -1.06e-197)
		tmp = t_2;
	elseif (J <= 2.7e-303)
		tmp = t_0;
	elseif (J <= 4e-290)
		tmp = -2.0 * (0.5 * U);
	elseif (J <= 1.6e-250)
		tmp = t_0;
	else
		tmp = t_2;
	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[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(-2.0 * N[(N[(J * t$95$1), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(t$95$1 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.06e-197], t$95$2, If[LessEqual[J, 2.7e-303], t$95$0, If[LessEqual[J, 4e-290], N[(-2.0 * N[(0.5 * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 1.6e-250], t$95$0, t$95$2]]]]]]]
\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 := -2 \cdot \left(U \cdot -0.5\right)\\
t_1 := \cos \left(K \cdot 0.5\right)\\
t_2 := -2 \cdot \left(\left(J \cdot t_1\right) \cdot \mathsf{hypot}\left(1, \frac{U}{t_1 \cdot \left(J \cdot 2\right)}\right)\right)\\
\mathbf{if}\;J \leq -1.06 \cdot 10^{-197}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;J \leq 2.7 \cdot 10^{-303}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq 4 \cdot 10^{-290}:\\
\;\;\;\;-2 \cdot \left(0.5 \cdot U\right)\\

\mathbf{elif}\;J \leq 1.6 \cdot 10^{-250}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\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 J < -1.05999999999999997e-197 or 1.60000000000000002e-250 < J

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

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

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

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

    if -1.05999999999999997e-197 < J < 2.69999999999999986e-303 or 4.0000000000000003e-290 < J < 1.60000000000000002e-250

    1. Initial program 43.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. Simplified27.5

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

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

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

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

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

    if 2.69999999999999986e-303 < J < 4.0000000000000003e-290

    1. Initial program 46.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. Simplified29.9

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

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

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

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

      \[\leadsto -2 \cdot \color{blue}{\left(U \cdot 0.5\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.06 \cdot 10^{-197}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)}\right)\right)\\ \mathbf{elif}\;J \leq 2.7 \cdot 10^{-303}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 4 \cdot 10^{-290}:\\ \;\;\;\;-2 \cdot \left(0.5 \cdot U\right)\\ \mathbf{elif}\;J \leq 1.6 \cdot 10^{-250}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)}\right)\right)\\ \end{array} \]

Reproduce

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