Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.5% → 99.4%
Time: 21.7s
Alternatives: 8
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}} \end{array} \end{array} \]
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    t_0 = cos((k / 2.0d0))
    code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0))))
end
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0)));
end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}} \end{array} \end{array} \]
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    t_0 = cos((k / 2.0d0))
    code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0))))
end
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0)));
end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t_0}\right)}^{2}}
\end{array}
\end{array}

Alternative 1: 99.4% accurate, 0.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;t_1 \leq 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY)) (- U) (if (<= t_1 1e+303) t_1 U))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U;
	} else if (t_1 <= 1e+303) {
		tmp = t_1;
	} else {
		tmp = U;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U;
	} else if (t_1 <= 1e+303) {
		tmp = t_1;
	} else {
		tmp = U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / (t_0 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U
	elif t_1 <= 1e+303:
		tmp = t_1
	else:
		tmp = U
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U);
	elseif (t_1 <= 1e+303)
		tmp = t_1;
	else
		tmp = U;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	t_1 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / (t_0 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U;
	elseif (t_1 <= 1e+303)
		tmp = t_1;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U), If[LessEqual[t$95$1, 1e+303], t$95$1, U]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U\\

\mathbf{elif}\;t_1 \leq 10^{+303}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;U\\


\end{array}
\end{array}
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 5.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 J around 0 44.4%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-144.4%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified44.4%

      \[\leadsto \color{blue}{-U} \]

    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)))) < 1e303

    1. Initial program 99.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}} \]

    if 1e303 < (*.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 5.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. Taylor expanded in U around -inf 46.5%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.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 -\infty:\\ \;\;\;\;-U\\ \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^{+303}:\\ \;\;\;\;\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}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 88.8% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := -2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\right)\\ \mathbf{if}\;J \leq -6.9 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.2 \cdot 10^{-234}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (* -2.0 (* t_0 (* J (hypot 1.0 (/ (/ U (* J 2.0)) t_0)))))))
   (if (<= J -6.9e-161)
     t_1
     (if (<= J -2e-310) U (if (<= J 6.2e-234) (- U) t_1)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = -2.0 * (t_0 * (J * hypot(1.0, ((U / (J * 2.0)) / t_0))));
	double tmp;
	if (J <= -6.9e-161) {
		tmp = t_1;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 6.2e-234) {
		tmp = -U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = -2.0 * (t_0 * (J * Math.hypot(1.0, ((U / (J * 2.0)) / t_0))));
	double tmp;
	if (J <= -6.9e-161) {
		tmp = t_1;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 6.2e-234) {
		tmp = -U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = -2.0 * (t_0 * (J * math.hypot(1.0, ((U / (J * 2.0)) / t_0))))
	tmp = 0
	if J <= -6.9e-161:
		tmp = t_1
	elif J <= -2e-310:
		tmp = U
	elif J <= 6.2e-234:
		tmp = -U
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(Float64(U / Float64(J * 2.0)) / t_0)))))
	tmp = 0.0
	if (J <= -6.9e-161)
		tmp = t_1;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 6.2e-234)
		tmp = Float64(-U);
	else
		tmp = t_1;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	t_1 = -2.0 * (t_0 * (J * hypot(1.0, ((U / (J * 2.0)) / t_0))));
	tmp = 0.0;
	if (J <= -6.9e-161)
		tmp = t_1;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 6.2e-234)
		tmp = -U;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -6.9e-161], t$95$1, If[LessEqual[J, -2e-310], U, If[LessEqual[J, 6.2e-234], (-U), t$95$1]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := -2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\right)\\
\mathbf{if}\;J \leq -6.9 \cdot 10^{-161}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 6.2 \cdot 10^{-234}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -6.90000000000000002e-161 or 6.2000000000000003e-234 < J

    1. Initial program 81.6%

      \[\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. Simplified93.0%

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

    if -6.90000000000000002e-161 < J < -1.999999999999994e-310

    1. Initial program 26.5%

      \[\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 U around -inf 46.1%

      \[\leadsto \color{blue}{U} \]

    if -1.999999999999994e-310 < J < 6.2000000000000003e-234

    1. Initial program 19.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. Taylor expanded in J around 0 38.4%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-138.4%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified38.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6.9 \cdot 10^{-161}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)\right)\right)\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.2 \cdot 10^{-234}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)\right)\right)\\ \end{array} \]

Alternative 3: 77.3% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -1 \cdot 10^{-156}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -7 \cdot 10^{-308}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-49}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* -2.0 (* (* J (cos (/ K 2.0))) (hypot 1.0 (* U (/ 0.5 J)))))))
   (if (<= J -1e-156)
     t_0
     (if (<= J -7e-308) U (if (<= J 1.05e-49) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, (U * (0.5 / J))));
	double tmp;
	if (J <= -1e-156) {
		tmp = t_0;
	} else if (J <= -7e-308) {
		tmp = U;
	} else if (J <= 1.05e-49) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = -2.0 * ((J * Math.cos((K / 2.0))) * Math.hypot(1.0, (U * (0.5 / J))));
	double tmp;
	if (J <= -1e-156) {
		tmp = t_0;
	} else if (J <= -7e-308) {
		tmp = U;
	} else if (J <= 1.05e-49) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * ((J * math.cos((K / 2.0))) * math.hypot(1.0, (U * (0.5 / J))))
	tmp = 0
	if J <= -1e-156:
		tmp = t_0
	elif J <= -7e-308:
		tmp = U
	elif J <= 1.05e-49:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(Float64(J * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U * Float64(0.5 / J)))))
	tmp = 0.0
	if (J <= -1e-156)
		tmp = t_0;
	elseif (J <= -7e-308)
		tmp = U;
	elseif (J <= 1.05e-49)
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, (U * (0.5 / J))));
	tmp = 0.0;
	if (J <= -1e-156)
		tmp = t_0;
	elseif (J <= -7e-308)
		tmp = U;
	elseif (J <= 1.05e-49)
		tmp = -U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(-2.0 * N[(N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1e-156], t$95$0, If[LessEqual[J, -7e-308], U, If[LessEqual[J, 1.05e-49], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -1 \cdot 10^{-156}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -7 \cdot 10^{-308}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.05 \cdot 10^{-49}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.00000000000000004e-156 or 1.0499999999999999e-49 < J

    1. Initial program 85.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. Step-by-step derivation
      1. associate-*l*85.3%

        \[\leadsto \color{blue}{\left(-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
      2. associate-*l*85.3%

        \[\leadsto \color{blue}{-2 \cdot \left(\left(J \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}}\right)} \]
      3. unpow285.3%

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}}\right) \]
      4. hypot-1-def95.7%

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\mathsf{hypot}\left(1, \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}\right) \]
      5. associate-/r*95.6%

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

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2 \cdot J}}{\color{blue}{\cos \left(-\frac{K}{2}\right)}}\right)\right) \]
      7. distribute-frac-neg95.6%

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2 \cdot J}}{\cos \color{blue}{\left(\frac{-K}{2}\right)}}\right)\right) \]
      8. associate-/r*95.7%

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{-K}{2}\right)}}\right)\right) \]
      9. associate-/r*95.6%

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{\frac{U}{2 \cdot J}}{\cos \left(\frac{-K}{2}\right)}}\right)\right) \]
      10. distribute-frac-neg95.6%

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

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

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

      \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{0.5 \cdot \frac{U}{J}}\right)\right) \]
    5. Step-by-step derivation
      1. associate-*r/82.0%

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

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\color{blue}{U \cdot 0.5}}{J}\right)\right) \]
      3. associate-*r/81.9%

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

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

    if -1.00000000000000004e-156 < J < -7e-308

    1. Initial program 26.5%

      \[\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 U around -inf 46.1%

      \[\leadsto \color{blue}{U} \]

    if -7e-308 < J < 1.0499999999999999e-49

    1. Initial program 40.6%

      \[\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 J around 0 41.6%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-141.6%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified41.6%

      \[\leadsto \color{blue}{-U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1 \cdot 10^{-156}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq -7 \cdot 10^{-308}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-49}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]

Alternative 4: 67.0% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -2.75 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.5 \cdot 10^{-21}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 1.85 \cdot 10^{+149}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (* -2.0 (cos (* K 0.5))))))
   (if (<= J -2.75e-18)
     t_0
     (if (<= J -2e-310)
       U
       (if (<= J 8.5e-21)
         (- U)
         (if (<= J 1.85e+149)
           (* (* -2.0 J) (hypot 1.0 (* U (/ 0.5 J))))
           t_0))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * cos((K * 0.5)));
	double tmp;
	if (J <= -2.75e-18) {
		tmp = t_0;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 8.5e-21) {
		tmp = -U;
	} else if (J <= 1.85e+149) {
		tmp = (-2.0 * J) * hypot(1.0, (U * (0.5 / J)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * Math.cos((K * 0.5)));
	double tmp;
	if (J <= -2.75e-18) {
		tmp = t_0;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 8.5e-21) {
		tmp = -U;
	} else if (J <= 1.85e+149) {
		tmp = (-2.0 * J) * Math.hypot(1.0, (U * (0.5 / J)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (-2.0 * math.cos((K * 0.5)))
	tmp = 0
	if J <= -2.75e-18:
		tmp = t_0
	elif J <= -2e-310:
		tmp = U
	elif J <= 8.5e-21:
		tmp = -U
	elif J <= 1.85e+149:
		tmp = (-2.0 * J) * math.hypot(1.0, (U * (0.5 / J)))
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))))
	tmp = 0.0
	if (J <= -2.75e-18)
		tmp = t_0;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 8.5e-21)
		tmp = Float64(-U);
	elseif (J <= 1.85e+149)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(U * Float64(0.5 / J))));
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (-2.0 * cos((K * 0.5)));
	tmp = 0.0;
	if (J <= -2.75e-18)
		tmp = t_0;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 8.5e-21)
		tmp = -U;
	elseif (J <= 1.85e+149)
		tmp = (-2.0 * J) * hypot(1.0, (U * (0.5 / J)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -2.75e-18], t$95$0, If[LessEqual[J, -2e-310], U, If[LessEqual[J, 8.5e-21], (-U), If[LessEqual[J, 1.85e+149], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{if}\;J \leq -2.75 \cdot 10^{-18}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 8.5 \cdot 10^{-21}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 1.85 \cdot 10^{+149}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -2.75e-18 or 1.84999999999999989e149 < J

    1. Initial program 96.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. Taylor expanded in J around inf 86.7%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*r*86.7%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      2. *-commutative86.7%

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative86.7%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. associate-*r*86.7%

        \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      5. *-commutative86.7%

        \[\leadsto J \cdot \left(-2 \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right) \]
    4. Simplified86.7%

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

    if -2.75e-18 < J < -1.999999999999994e-310

    1. Initial program 43.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}} \]
    2. Taylor expanded in U around -inf 42.2%

      \[\leadsto \color{blue}{U} \]

    if -1.999999999999994e-310 < J < 8.4999999999999993e-21

    1. Initial program 41.5%

      \[\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 J around 0 40.3%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-140.3%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified40.3%

      \[\leadsto \color{blue}{-U} \]

    if 8.4999999999999993e-21 < J < 1.84999999999999989e149

    1. Initial program 94.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. Step-by-step derivation
      1. expm1-log1p-u23.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\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}}\right)\right)} \]
      2. expm1-udef20.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\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}}\right)} - 1} \]
    3. Applied egg-rr20.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, U \cdot \frac{0.5}{J \cdot \cos \left(K \cdot 0.5\right)}\right) \cdot \left(J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def23.4%

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

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

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

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

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

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

      \[\leadsto \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right) \cdot \color{blue}{\left(-2 \cdot J\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification62.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.75 \cdot 10^{-18}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.5 \cdot 10^{-21}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 1.85 \cdot 10^{+149}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 5: 66.7% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -7.6 \cdot 10^{-17}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.2 \cdot 10^{-48} \lor \neg \left(J \leq 1.4 \cdot 10^{+22}\right) \land J \leq 2.3 \cdot 10^{+57}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (* -2.0 (cos (* K 0.5))))))
   (if (<= J -7.6e-17)
     t_0
     (if (<= J -2e-310)
       U
       (if (or (<= J 9.2e-48) (and (not (<= J 1.4e+22)) (<= J 2.3e+57)))
         (- U)
         t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * cos((K * 0.5)));
	double tmp;
	if (J <= -7.6e-17) {
		tmp = t_0;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if ((J <= 9.2e-48) || (!(J <= 1.4e+22) && (J <= 2.3e+57))) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * ((-2.0d0) * cos((k * 0.5d0)))
    if (j <= (-7.6d-17)) then
        tmp = t_0
    else if (j <= (-2d-310)) then
        tmp = u
    else if ((j <= 9.2d-48) .or. (.not. (j <= 1.4d+22)) .and. (j <= 2.3d+57)) then
        tmp = -u
    else
        tmp = t_0
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * Math.cos((K * 0.5)));
	double tmp;
	if (J <= -7.6e-17) {
		tmp = t_0;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if ((J <= 9.2e-48) || (!(J <= 1.4e+22) && (J <= 2.3e+57))) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (-2.0 * math.cos((K * 0.5)))
	tmp = 0
	if J <= -7.6e-17:
		tmp = t_0
	elif J <= -2e-310:
		tmp = U
	elif (J <= 9.2e-48) or (not (J <= 1.4e+22) and (J <= 2.3e+57)):
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))))
	tmp = 0.0
	if (J <= -7.6e-17)
		tmp = t_0;
	elseif (J <= -2e-310)
		tmp = U;
	elseif ((J <= 9.2e-48) || (!(J <= 1.4e+22) && (J <= 2.3e+57)))
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (-2.0 * cos((K * 0.5)));
	tmp = 0.0;
	if (J <= -7.6e-17)
		tmp = t_0;
	elseif (J <= -2e-310)
		tmp = U;
	elseif ((J <= 9.2e-48) || (~((J <= 1.4e+22)) && (J <= 2.3e+57)))
		tmp = -U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -7.6e-17], t$95$0, If[LessEqual[J, -2e-310], U, If[Or[LessEqual[J, 9.2e-48], And[N[Not[LessEqual[J, 1.4e+22]], $MachinePrecision], LessEqual[J, 2.3e+57]]], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{if}\;J \leq -7.6 \cdot 10^{-17}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 9.2 \cdot 10^{-48} \lor \neg \left(J \leq 1.4 \cdot 10^{+22}\right) \land J \leq 2.3 \cdot 10^{+57}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -7.6000000000000002e-17 or 9.2000000000000003e-48 < J < 1.4e22 or 2.2999999999999999e57 < J

    1. Initial program 94.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. Taylor expanded in J around inf 79.9%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*r*79.9%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      2. *-commutative79.9%

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative79.9%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. associate-*r*79.9%

        \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      5. *-commutative79.9%

        \[\leadsto J \cdot \left(-2 \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right) \]
    4. Simplified79.9%

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

    if -7.6000000000000002e-17 < J < -1.999999999999994e-310

    1. Initial program 43.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}} \]
    2. Taylor expanded in U around -inf 42.2%

      \[\leadsto \color{blue}{U} \]

    if -1.999999999999994e-310 < J < 9.2000000000000003e-48 or 1.4e22 < J < 2.2999999999999999e57

    1. Initial program 49.5%

      \[\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 J around 0 44.8%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-144.8%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified44.8%

      \[\leadsto \color{blue}{-U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification61.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7.6 \cdot 10^{-17}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 9.2 \cdot 10^{-48} \lor \neg \left(J \leq 1.4 \cdot 10^{+22}\right) \land J \leq 2.3 \cdot 10^{+57}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 48.6% accurate, 45.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -1.05 \cdot 10^{+68}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.36 \cdot 10^{+159}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= J -1.05e+68)
   (* -2.0 J)
   (if (<= J -2e-310) U (if (<= J 1.36e+159) (- U) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -1.05e+68) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 1.36e+159) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-1.05d+68)) then
        tmp = (-2.0d0) * j
    else if (j <= (-2d-310)) then
        tmp = u
    else if (j <= 1.36d+159) then
        tmp = -u
    else
        tmp = (-2.0d0) * j
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -1.05e+68) {
		tmp = -2.0 * J;
	} else if (J <= -2e-310) {
		tmp = U;
	} else if (J <= 1.36e+159) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -1.05e+68:
		tmp = -2.0 * J
	elif J <= -2e-310:
		tmp = U
	elif J <= 1.36e+159:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -1.05e+68)
		tmp = Float64(-2.0 * J);
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 1.36e+159)
		tmp = Float64(-U);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -1.05e+68)
		tmp = -2.0 * J;
	elseif (J <= -2e-310)
		tmp = U;
	elseif (J <= 1.36e+159)
		tmp = -U;
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -1.05e+68], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -2e-310], U, If[LessEqual[J, 1.36e+159], (-U), N[(-2.0 * J), $MachinePrecision]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -1.05 \cdot 10^{+68}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.36 \cdot 10^{+159}:\\
\;\;\;\;-U\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.05e68 or 1.36e159 < J

    1. Initial program 99.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 J around inf 93.7%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*r*93.7%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      2. *-commutative93.7%

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative93.7%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. associate-*r*93.7%

        \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      5. *-commutative93.7%

        \[\leadsto J \cdot \left(-2 \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}\right) \]
    4. Simplified93.7%

      \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(0.5 \cdot K\right)\right)} \]
    5. Taylor expanded in K around 0 51.7%

      \[\leadsto \color{blue}{-2 \cdot J} \]

    if -1.05e68 < J < -1.999999999999994e-310

    1. Initial program 52.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. Taylor expanded in U around -inf 40.2%

      \[\leadsto \color{blue}{U} \]

    if -1.999999999999994e-310 < J < 1.36e159

    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. Taylor expanded in J around 0 37.0%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-137.0%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified37.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.05 \cdot 10^{+68}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.36 \cdot 10^{+159}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 7: 38.2% accurate, 103.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 (if (<= J -2e-310) U (- U)))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2e-310) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (j <= (-2d-310)) then
        tmp = u
    else
        tmp = -u
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double tmp;
	if (J <= -2e-310) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2e-310:
		tmp = U
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2e-310)
		tmp = U;
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (J <= -2e-310)
		tmp = U;
	else
		tmp = -U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[J, -2e-310], U, (-U)]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;-U\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -1.999999999999994e-310

    1. Initial program 67.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. Taylor expanded in U around -inf 29.7%

      \[\leadsto \color{blue}{U} \]

    if -1.999999999999994e-310 < J

    1. Initial program 73.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. Taylor expanded in J around 0 27.5%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    3. Step-by-step derivation
      1. neg-mul-127.5%

        \[\leadsto \color{blue}{-U} \]
    4. Simplified27.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 8: 26.8% accurate, 420.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ U \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 U)
U = abs(U);
double code(double J, double K, double U) {
	return U;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	return U;
}
U = abs(U)
def code(J, K, U):
	return U
U = abs(U)
function code(J, K, U)
	return U
end
U = abs(U)
function tmp = code(J, K, U)
	tmp = U;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := U
\begin{array}{l}
U = |U|\\
\\
U
\end{array}
Derivation
  1. Initial program 70.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. Taylor expanded in U around -inf 28.1%

    \[\leadsto \color{blue}{U} \]
  3. Final simplification28.1%

    \[\leadsto U \]

Reproduce

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