Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.3% → 98.7%
Time: 19.5s
Alternatives: 12
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 12 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.3% 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: 98.7% accurate, 0.4× 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}}\\ t_2 := J \cdot t_0\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+294}:\\ \;\;\;\;-2 \cdot \left(t_2 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \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)))))
        (t_2 (* J t_0)))
   (if (<= t_1 (- INFINITY))
     (- U)
     (if (<= t_1 5e+294)
       (* -2.0 (* t_2 (hypot 1.0 (/ U (* 2.0 t_2)))))
       (* -2.0 (* U -0.5))))))
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 t_2 = J * t_0;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U;
	} else if (t_1 <= 5e+294) {
		tmp = -2.0 * (t_2 * hypot(1.0, (U / (2.0 * t_2))));
	} else {
		tmp = -2.0 * (U * -0.5);
	}
	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 t_2 = J * t_0;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U;
	} else if (t_1 <= 5e+294) {
		tmp = -2.0 * (t_2 * Math.hypot(1.0, (U / (2.0 * t_2))));
	} else {
		tmp = -2.0 * (U * -0.5);
	}
	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)))
	t_2 = J * t_0
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U
	elif t_1 <= 5e+294:
		tmp = -2.0 * (t_2 * math.hypot(1.0, (U / (2.0 * t_2))))
	else:
		tmp = -2.0 * (U * -0.5)
	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))))
	t_2 = Float64(J * t_0)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U);
	elseif (t_1 <= 5e+294)
		tmp = Float64(-2.0 * Float64(t_2 * hypot(1.0, Float64(U / Float64(2.0 * t_2)))));
	else
		tmp = Float64(-2.0 * Float64(U * -0.5));
	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)));
	t_2 = J * t_0;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U;
	elseif (t_1 <= 5e+294)
		tmp = -2.0 * (t_2 * hypot(1.0, (U / (2.0 * t_2))));
	else
		tmp = -2.0 * (U * -0.5);
	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]}, Block[{t$95$2 = N[(J * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U), If[LessEqual[t$95$1, 5e+294], N[(-2.0 * N[(t$95$2 * N[Sqrt[1.0 ^ 2 + N[(U / N[(2.0 * t$95$2), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision]]]]]]
\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}}\\
t_2 := J \cdot t_0\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U\\

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

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


\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 6.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. Simplified52.3%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 56.7%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg56.7%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified56.7%

      \[\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)))) < 4.9999999999999999e294

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

        \[\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*99.8%

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

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

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{\left(-\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right) \cdot \left(-\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}}\right) \]
      5. distribute-frac-neg99.8%

        \[\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 \left(-\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}\right) \]
      6. distribute-frac-neg99.8%

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

        \[\leadsto -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + \color{blue}{{\left(\frac{-U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}}\right) \]
    3. Simplified99.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)} \]

    if 4.9999999999999999e294 < (*.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.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. Simplified51.3%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative55.9%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified55.9%

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

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

Alternative 2: 88.2% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;U \leq 1.4 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)\\ \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))))
   (if (<= U 1.4e+293)
     (* -2.0 (* J (* t_0 (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))
     (- U))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (U <= 1.4e+293) {
		tmp = -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
	} 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 tmp;
	if (U <= 1.4e+293) {
		tmp = -2.0 * (J * (t_0 * Math.hypot(1.0, (U / (J * (2.0 * t_0))))));
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if U <= 1.4e+293:
		tmp = -2.0 * (J * (t_0 * math.hypot(1.0, (U / (J * (2.0 * t_0))))))
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (U <= 1.4e+293)
		tmp = Float64(-2.0 * Float64(J * Float64(t_0 * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))));
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (U <= 1.4e+293)
		tmp = -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
	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]}, If[LessEqual[U, 1.4e+293], N[(-2.0 * N[(J * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U)]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;U \leq 1.4 \cdot 10^{+293}:\\
\;\;\;\;-2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1.39999999999999993e293

    1. Initial program 77.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. Simplified88.8%

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

    if 1.39999999999999993e293 < U

    1. Initial program 11.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. Simplified26.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 83.3%

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

        \[\leadsto \color{blue}{-U} \]
    6. Simplified83.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.4 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 3: 88.2% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;U \leq 3.1 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot t_0} \cdot 0.5\right)\right)\right)\\ \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))))
   (if (<= U 3.1e+293)
     (* -2.0 (* t_0 (* J (hypot 1.0 (* (/ U (* J t_0)) 0.5)))))
     (- U))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (U <= 3.1e+293) {
		tmp = -2.0 * (t_0 * (J * hypot(1.0, ((U / (J * t_0)) * 0.5))));
	} 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 tmp;
	if (U <= 3.1e+293) {
		tmp = -2.0 * (t_0 * (J * Math.hypot(1.0, ((U / (J * t_0)) * 0.5))));
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if U <= 3.1e+293:
		tmp = -2.0 * (t_0 * (J * math.hypot(1.0, ((U / (J * t_0)) * 0.5))))
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (U <= 3.1e+293)
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(Float64(U / Float64(J * t_0)) * 0.5)))));
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (U <= 3.1e+293)
		tmp = -2.0 * (t_0 * (J * hypot(1.0, ((U / (J * t_0)) * 0.5))));
	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]}, If[LessEqual[U, 3.1e+293], N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U / N[(J * t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U)]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;U \leq 3.1 \cdot 10^{+293}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot t_0} \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 3.0999999999999999e293

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

        \[\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*77.2%

        \[\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. *-commutative77.2%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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) \]
      5. sqr-neg77.2%

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\right) \cdot \sqrt{1 + \color{blue}{\left(-\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right) \cdot \left(-\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}}\right) \]
      6. distribute-frac-neg77.2%

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

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

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

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

    if 3.0999999999999999e293 < U

    1. Initial program 11.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. Simplified26.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 83.3%

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

        \[\leadsto \color{blue}{-U} \]
    6. Simplified83.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 3.1 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \cos \left(\frac{K}{2}\right)} \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 4: 76.7% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\ \mathbf{if}\;J \leq -3.2 \cdot 10^{-186}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3.5 \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 (* -2.0 (* (cos (/ K 2.0)) (* J (hypot 1.0 (* 0.5 (/ U J))))))))
   (if (<= J -3.2e-186)
     t_0
     (if (<= J 7.6e-297) (* -2.0 (* U -0.5)) (if (<= J 3.5e-57) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (cos((K / 2.0)) * (J * hypot(1.0, (0.5 * (U / J)))));
	double tmp;
	if (J <= -3.2e-186) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 3.5e-57) {
		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 * (Math.cos((K / 2.0)) * (J * Math.hypot(1.0, (0.5 * (U / J)))));
	double tmp;
	if (J <= -3.2e-186) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 3.5e-57) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (math.cos((K / 2.0)) * (J * math.hypot(1.0, (0.5 * (U / J)))))
	tmp = 0
	if J <= -3.2e-186:
		tmp = t_0
	elif J <= 7.6e-297:
		tmp = -2.0 * (U * -0.5)
	elif J <= 3.5e-57:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(cos(Float64(K / 2.0)) * Float64(J * hypot(1.0, Float64(0.5 * Float64(U / J))))))
	tmp = 0.0
	if (J <= -3.2e-186)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 3.5e-57)
		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 * (cos((K / 2.0)) * (J * hypot(1.0, (0.5 * (U / J)))));
	tmp = 0.0;
	if (J <= -3.2e-186)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 3.5e-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[(-2.0 * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -3.2e-186], t$95$0, If[LessEqual[J, 7.6e-297], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 3.5e-57], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\
\mathbf{if}\;J \leq -3.2 \cdot 10^{-186}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 3.5 \cdot 10^{-57}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -3.2e-186 or 3.49999999999999991e-57 < J

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

        \[\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*88.4%

        \[\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. *-commutative88.4%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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) \]
      5. sqr-neg88.4%

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

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

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

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

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

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

    if -3.2e-186 < J < 7.6000000000000001e-297

    1. Initial program 40.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. Simplified54.4%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative60.5%

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

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

    if 7.6000000000000001e-297 < J < 3.49999999999999991e-57

    1. Initial program 49.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. Simplified69.9%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 47.2%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg47.2%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified47.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.2 \cdot 10^{-186}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 3.5 \cdot 10^{-57}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\right)\\ \end{array} \]

Alternative 5: 57.6% accurate, 3.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 1.2 \cdot 10^{-29}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;U \leq 8 \cdot 10^{+205}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \mathbf{elif}\;U \leq 3 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= U 1.2e-29)
   (* -2.0 (* J (cos (/ K 2.0))))
   (if (<= U 8e+205)
     (* -2.0 (* J (sqrt (+ 1.0 (* 0.25 (* (/ U J) (/ U J)))))))
     (if (<= U 3e+293) (* -2.0 (* U -0.5)) (- U)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 1.2e-29) {
		tmp = -2.0 * (J * cos((K / 2.0)));
	} else if (U <= 8e+205) {
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} else if (U <= 3e+293) {
		tmp = -2.0 * (U * -0.5);
	} 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 (u <= 1.2d-29) then
        tmp = (-2.0d0) * (j * cos((k / 2.0d0)))
    else if (u <= 8d+205) then
        tmp = (-2.0d0) * (j * sqrt((1.0d0 + (0.25d0 * ((u / j) * (u / j))))))
    else if (u <= 3d+293) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    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 (U <= 1.2e-29) {
		tmp = -2.0 * (J * Math.cos((K / 2.0)));
	} else if (U <= 8e+205) {
		tmp = -2.0 * (J * Math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} else if (U <= 3e+293) {
		tmp = -2.0 * (U * -0.5);
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 1.2e-29:
		tmp = -2.0 * (J * math.cos((K / 2.0)))
	elif U <= 8e+205:
		tmp = -2.0 * (J * math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))))
	elif U <= 3e+293:
		tmp = -2.0 * (U * -0.5)
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 1.2e-29)
		tmp = Float64(-2.0 * Float64(J * cos(Float64(K / 2.0))));
	elseif (U <= 8e+205)
		tmp = Float64(-2.0 * Float64(J * sqrt(Float64(1.0 + Float64(0.25 * Float64(Float64(U / J) * Float64(U / J)))))));
	elseif (U <= 3e+293)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (U <= 1.2e-29)
		tmp = -2.0 * (J * cos((K / 2.0)));
	elseif (U <= 8e+205)
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	elseif (U <= 3e+293)
		tmp = -2.0 * (U * -0.5);
	else
		tmp = -U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[U, 1.2e-29], N[(-2.0 * N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 8e+205], N[(-2.0 * N[(J * N[Sqrt[N[(1.0 + N[(0.25 * N[(N[(U / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 3e+293], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], (-U)]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 1.2 \cdot 10^{-29}:\\
\;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\

\mathbf{elif}\;U \leq 8 \cdot 10^{+205}:\\
\;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\

\mathbf{elif}\;U \leq 3 \cdot 10^{+293}:\\
\;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if U < 1.19999999999999996e-29

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

        \[\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*83.7%

        \[\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. *-commutative83.7%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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) \]
      5. sqr-neg83.7%

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

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

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

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

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

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

    if 1.19999999999999996e-29 < U < 8.00000000000000013e205

    1. Initial program 72.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. Simplified90.4%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative46.1%

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
      2. unpow246.1%

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

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified46.1%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Step-by-step derivation
      1. times-frac56.9%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]
    7. Applied egg-rr56.9%

      \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]

    if 8.00000000000000013e205 < U < 3.00000000000000013e293

    1. Initial program 36.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. Simplified65.9%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative63.7%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified63.7%

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

    if 3.00000000000000013e293 < U

    1. Initial program 11.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. Simplified26.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 83.3%

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

        \[\leadsto \color{blue}{-U} \]
    6. Simplified83.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.2 \cdot 10^{-29}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;U \leq 8 \cdot 10^{+205}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \mathbf{elif}\;U \leq 3 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 6: 57.6% accurate, 3.5× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 1.65 \cdot 10^{-29}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\right)\\ \mathbf{elif}\;U \leq 1.05 \cdot 10^{+206}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \mathbf{elif}\;U \leq 2.8 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (if (<= U 1.65e-29)
   (* -2.0 (* (cos (/ K 2.0)) (+ J (* 0.125 (/ U (/ J U))))))
   (if (<= U 1.05e+206)
     (* -2.0 (* J (sqrt (+ 1.0 (* 0.25 (* (/ U J) (/ U J)))))))
     (if (<= U 2.8e+293) (* -2.0 (* U -0.5)) (- U)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 1.65e-29) {
		tmp = -2.0 * (cos((K / 2.0)) * (J + (0.125 * (U / (J / U)))));
	} else if (U <= 1.05e+206) {
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} else if (U <= 2.8e+293) {
		tmp = -2.0 * (U * -0.5);
	} 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 (u <= 1.65d-29) then
        tmp = (-2.0d0) * (cos((k / 2.0d0)) * (j + (0.125d0 * (u / (j / u)))))
    else if (u <= 1.05d+206) then
        tmp = (-2.0d0) * (j * sqrt((1.0d0 + (0.25d0 * ((u / j) * (u / j))))))
    else if (u <= 2.8d+293) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    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 (U <= 1.65e-29) {
		tmp = -2.0 * (Math.cos((K / 2.0)) * (J + (0.125 * (U / (J / U)))));
	} else if (U <= 1.05e+206) {
		tmp = -2.0 * (J * Math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	} else if (U <= 2.8e+293) {
		tmp = -2.0 * (U * -0.5);
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 1.65e-29:
		tmp = -2.0 * (math.cos((K / 2.0)) * (J + (0.125 * (U / (J / U)))))
	elif U <= 1.05e+206:
		tmp = -2.0 * (J * math.sqrt((1.0 + (0.25 * ((U / J) * (U / J))))))
	elif U <= 2.8e+293:
		tmp = -2.0 * (U * -0.5)
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 1.65e-29)
		tmp = Float64(-2.0 * Float64(cos(Float64(K / 2.0)) * Float64(J + Float64(0.125 * Float64(U / Float64(J / U))))));
	elseif (U <= 1.05e+206)
		tmp = Float64(-2.0 * Float64(J * sqrt(Float64(1.0 + Float64(0.25 * Float64(Float64(U / J) * Float64(U / J)))))));
	elseif (U <= 2.8e+293)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (U <= 1.65e-29)
		tmp = -2.0 * (cos((K / 2.0)) * (J + (0.125 * (U / (J / U)))));
	elseif (U <= 1.05e+206)
		tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U / J) * (U / J))))));
	elseif (U <= 2.8e+293)
		tmp = -2.0 * (U * -0.5);
	else
		tmp = -U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[U, 1.65e-29], N[(-2.0 * N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J + N[(0.125 * N[(U / N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 1.05e+206], N[(-2.0 * N[(J * N[Sqrt[N[(1.0 + N[(0.25 * N[(N[(U / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 2.8e+293], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], (-U)]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 1.65 \cdot 10^{-29}:\\
\;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\right)\\

\mathbf{elif}\;U \leq 1.05 \cdot 10^{+206}:\\
\;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\

\mathbf{elif}\;U \leq 2.8 \cdot 10^{+293}:\\
\;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if U < 1.65000000000000014e-29

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

        \[\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*83.7%

        \[\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. *-commutative83.7%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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) \]
      5. sqr-neg83.7%

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

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

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

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

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

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

      \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(0.125 \cdot \frac{{U}^{2}}{J} + J\right)}\right) \]
    6. Step-by-step derivation
      1. fma-def64.0%

        \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\mathsf{fma}\left(0.125, \frac{{U}^{2}}{J}, J\right)}\right) \]
      2. unpow264.0%

        \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{fma}\left(0.125, \frac{\color{blue}{U \cdot U}}{J}, J\right)\right) \]
    7. Simplified64.0%

      \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\mathsf{fma}\left(0.125, \frac{U \cdot U}{J}, J\right)}\right) \]
    8. Step-by-step derivation
      1. fma-udef64.0%

        \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(0.125 \cdot \frac{U \cdot U}{J} + J\right)}\right) \]
      2. associate-/l*64.6%

        \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(0.125 \cdot \color{blue}{\frac{U}{\frac{J}{U}}} + J\right)\right) \]
    9. Applied egg-rr64.6%

      \[\leadsto -2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \color{blue}{\left(0.125 \cdot \frac{U}{\frac{J}{U}} + J\right)}\right) \]

    if 1.65000000000000014e-29 < U < 1.04999999999999993e206

    1. Initial program 72.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. Simplified90.4%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative46.1%

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
      2. unpow246.1%

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

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified46.1%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Step-by-step derivation
      1. times-frac56.9%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]
    7. Applied egg-rr56.9%

      \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)}}\right) \]

    if 1.04999999999999993e206 < U < 2.79999999999999986e293

    1. Initial program 36.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. Simplified65.9%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative63.7%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified63.7%

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

    if 2.79999999999999986e293 < U

    1. Initial program 11.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. Simplified26.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 83.3%

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

        \[\leadsto \color{blue}{-U} \]
    6. Simplified83.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.65 \cdot 10^{-29}:\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J + 0.125 \cdot \frac{U}{\frac{J}{U}}\right)\right)\\ \mathbf{elif}\;U \leq 1.05 \cdot 10^{+206}:\\ \;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \left(\frac{U}{J} \cdot \frac{U}{J}\right)}\right)\\ \mathbf{elif}\;U \leq 2.8 \cdot 10^{+293}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 7: 66.1% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{if}\;J \leq -9.5 \cdot 10^{-51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 9.2 \cdot 10^{-25}:\\ \;\;\;\;-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))))))
   (if (<= J -9.5e-51)
     t_0
     (if (<= J 7.6e-297)
       (* -2.0 (- (* U -0.5) (/ (* J J) U)))
       (if (<= J 9.2e-25) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * cos((K / 2.0)));
	double tmp;
	if (J <= -9.5e-51) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	} else if (J <= 9.2e-25) {
		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 = (-2.0d0) * (j * cos((k / 2.0d0)))
    if (j <= (-9.5d-51)) then
        tmp = t_0
    else if (j <= 7.6d-297) then
        tmp = (-2.0d0) * ((u * (-0.5d0)) - ((j * j) / u))
    else if (j <= 9.2d-25) 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 = -2.0 * (J * Math.cos((K / 2.0)));
	double tmp;
	if (J <= -9.5e-51) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	} else if (J <= 9.2e-25) {
		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)))
	tmp = 0
	if J <= -9.5e-51:
		tmp = t_0
	elif J <= 7.6e-297:
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U))
	elif J <= 9.2e-25:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * cos(Float64(K / 2.0))))
	tmp = 0.0
	if (J <= -9.5e-51)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(Float64(J * J) / U)));
	elseif (J <= 9.2e-25)
		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)));
	tmp = 0.0;
	if (J <= -9.5e-51)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	elseif (J <= 9.2e-25)
		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[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -9.5e-51], t$95$0, If[LessEqual[J, 7.6e-297], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(N[(J * J), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 9.2e-25], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\
\mathbf{if}\;J \leq -9.5 \cdot 10^{-51}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 9.2 \cdot 10^{-25}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -9.4999999999999998e-51 or 9.1999999999999997e-25 < J

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

        \[\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*93.7%

        \[\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. *-commutative93.7%

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

        \[\leadsto -2 \cdot \left(\left(\cos \left(\frac{K}{2}\right) \cdot J\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) \]
      5. sqr-neg93.7%

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

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

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

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

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

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

    if -9.4999999999999998e-51 < J < 7.6000000000000001e-297

    1. Initial program 58.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. Simplified73.2%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative24.9%

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
      2. unpow224.9%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{\color{blue}{U \cdot U}}{{J}^{2}}}\right) \]
      3. unpow224.9%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified24.9%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Taylor expanded in U around -inf 41.3%

      \[\leadsto -2 \cdot \color{blue}{\left(-1 \cdot \frac{{J}^{2}}{U} + -0.5 \cdot U\right)} \]
    7. Step-by-step derivation
      1. +-commutative41.3%

        \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U + -1 \cdot \frac{{J}^{2}}{U}\right)} \]
      2. mul-1-neg41.3%

        \[\leadsto -2 \cdot \left(-0.5 \cdot U + \color{blue}{\left(-\frac{{J}^{2}}{U}\right)}\right) \]
      3. unsub-neg41.3%

        \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U - \frac{{J}^{2}}{U}\right)} \]
      4. *-commutative41.3%

        \[\leadsto -2 \cdot \left(\color{blue}{U \cdot -0.5} - \frac{{J}^{2}}{U}\right) \]
      5. unpow241.3%

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
    8. Simplified41.3%

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

    if 7.6000000000000001e-297 < J < 9.1999999999999997e-25

    1. Initial program 51.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. Simplified73.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 45.9%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg45.9%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified45.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -9.5 \cdot 10^{-51}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 9.2 \cdot 10^{-25}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(\frac{K}{2}\right)\right)\\ \end{array} \]

Alternative 8: 55.8% accurate, 24.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -4.2 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 4.5 \cdot 10^{-98}:\\ \;\;\;\;-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 (+ 1.0 (* U (/ 0.5 J)))))))
   (if (<= J -4.2e-5)
     t_0
     (if (<= J 7.6e-297) (* -2.0 (* U -0.5)) (if (<= J 4.5e-98) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * (1.0 + (U * (0.5 / J))));
	double tmp;
	if (J <= -4.2e-5) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 4.5e-98) {
		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 = (-2.0d0) * (j * (1.0d0 + (u * (0.5d0 / j))))
    if (j <= (-4.2d-5)) then
        tmp = t_0
    else if (j <= 7.6d-297) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 4.5d-98) 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 = -2.0 * (J * (1.0 + (U * (0.5 / J))));
	double tmp;
	if (J <= -4.2e-5) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 4.5e-98) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (J * (1.0 + (U * (0.5 / J))))
	tmp = 0
	if J <= -4.2e-5:
		tmp = t_0
	elif J <= 7.6e-297:
		tmp = -2.0 * (U * -0.5)
	elif J <= 4.5e-98:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * Float64(1.0 + Float64(U * Float64(0.5 / J)))))
	tmp = 0.0
	if (J <= -4.2e-5)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 4.5e-98)
		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 * (1.0 + (U * (0.5 / J))));
	tmp = 0.0;
	if (J <= -4.2e-5)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 4.5e-98)
		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[(J * N[(1.0 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -4.2e-5], t$95$0, If[LessEqual[J, 7.6e-297], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 4.5e-98], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -4.2 \cdot 10^{-5}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 4.5 \cdot 10^{-98}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -4.19999999999999977e-5 or 4.49999999999999997e-98 < J

    1. Initial program 92.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. Simplified99.0%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)} \]
    3. Step-by-step derivation
      1. add-cube-cbrt98.1%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt[3]{\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{0.5 \cdot \frac{U}{J}}{\cos \left(K \cdot 0.5\right)}\right)}\right)}^{3}\right)\right)}\right) \]
      2. rem-cube-cbrt90.3%

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

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{hypot}\left(1, \frac{0.5 \cdot \frac{U}{J}}{\cos \left(K \cdot 0.5\right)}\right) \cdot \cos \left(K \cdot 0.5\right)}\right)\right)\right) \]
      4. associate-/l*90.3%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \frac{0.5}{\frac{\cos \left(K \cdot 0.5\right)}{\frac{U}{J}}}\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + \left(-1\right)\right)}\right) \]
    8. Applied egg-rr98.9%

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(\left(1 + \cos \left(0.5 \cdot K\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{\frac{U}{J}}{\cos \left(0.5 \cdot K\right)}\right)\right) + -1\right)}\right) \]
    9. Step-by-step derivation
      1. metadata-eval98.9%

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

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{0.5 \cdot \frac{U}{J}}\right)\right) \]
    12. Step-by-step derivation
      1. metadata-eval51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{0.5}{1}} \cdot \frac{U}{J}\right)\right) \]
      2. times-frac51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{0.5 \cdot U}{1 \cdot J}}\right)\right) \]
      3. *-commutative51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \frac{\color{blue}{U \cdot 0.5}}{1 \cdot J}\right)\right) \]
      4. times-frac51.7%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{U}{1} \cdot \frac{0.5}{J}}\right)\right) \]
      5. /-rgt-identity51.7%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{U} \cdot \frac{0.5}{J}\right)\right) \]
    13. Simplified51.7%

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

    if -4.19999999999999977e-5 < J < 7.6000000000000001e-297

    1. Initial program 61.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. Simplified77.5%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative42.5%

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

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

    if 7.6000000000000001e-297 < J < 4.49999999999999997e-98

    1. Initial program 42.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. Simplified63.9%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 47.4%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg47.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -4.2 \cdot 10^{-5}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 4.5 \cdot 10^{-98}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]

Alternative 9: 55.8% accurate, 24.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -0.15:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 2.8 \cdot 10^{-105}:\\ \;\;\;\;-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 (+ 1.0 (* U (/ 0.5 J)))))))
   (if (<= J -0.15)
     t_0
     (if (<= J 7.6e-297)
       (* -2.0 (- (* U -0.5) (/ (* J J) U)))
       (if (<= J 2.8e-105) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * (J * (1.0 + (U * (0.5 / J))));
	double tmp;
	if (J <= -0.15) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	} else if (J <= 2.8e-105) {
		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 = (-2.0d0) * (j * (1.0d0 + (u * (0.5d0 / j))))
    if (j <= (-0.15d0)) then
        tmp = t_0
    else if (j <= 7.6d-297) then
        tmp = (-2.0d0) * ((u * (-0.5d0)) - ((j * j) / u))
    else if (j <= 2.8d-105) 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 = -2.0 * (J * (1.0 + (U * (0.5 / J))));
	double tmp;
	if (J <= -0.15) {
		tmp = t_0;
	} else if (J <= 7.6e-297) {
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	} else if (J <= 2.8e-105) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * (J * (1.0 + (U * (0.5 / J))))
	tmp = 0
	if J <= -0.15:
		tmp = t_0
	elif J <= 7.6e-297:
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U))
	elif J <= 2.8e-105:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(J * Float64(1.0 + Float64(U * Float64(0.5 / J)))))
	tmp = 0.0
	if (J <= -0.15)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(Float64(J * J) / U)));
	elseif (J <= 2.8e-105)
		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 * (1.0 + (U * (0.5 / J))));
	tmp = 0.0;
	if (J <= -0.15)
		tmp = t_0;
	elseif (J <= 7.6e-297)
		tmp = -2.0 * ((U * -0.5) - ((J * J) / U));
	elseif (J <= 2.8e-105)
		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[(J * N[(1.0 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -0.15], t$95$0, If[LessEqual[J, 7.6e-297], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(N[(J * J), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 2.8e-105], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -0.15:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 2.8 \cdot 10^{-105}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -0.149999999999999994 or 2.8e-105 < J

    1. Initial program 92.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. Simplified99.0%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot \cos \left(\frac{K}{2}\right)\right)}\right)\right)\right)} \]
    3. Step-by-step derivation
      1. add-cube-cbrt98.1%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt[3]{\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{0.5 \cdot \frac{U}{J}}{\cos \left(K \cdot 0.5\right)}\right)}\right)}^{3}\right)\right)}\right) \]
      2. rem-cube-cbrt90.3%

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

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\mathsf{hypot}\left(1, \frac{0.5 \cdot \frac{U}{J}}{\cos \left(K \cdot 0.5\right)}\right) \cdot \cos \left(K \cdot 0.5\right)}\right)\right)\right) \]
      4. associate-/l*90.3%

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \frac{0.5}{\frac{\cos \left(K \cdot 0.5\right)}{\frac{U}{J}}}\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + \left(-1\right)\right)}\right) \]
    8. Applied egg-rr98.9%

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(\left(1 + \cos \left(0.5 \cdot K\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{\frac{U}{J}}{\cos \left(0.5 \cdot K\right)}\right)\right) + -1\right)}\right) \]
    9. Step-by-step derivation
      1. metadata-eval98.9%

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

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{0.5 \cdot \frac{U}{J}}\right)\right) \]
    12. Step-by-step derivation
      1. metadata-eval51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{0.5}{1}} \cdot \frac{U}{J}\right)\right) \]
      2. times-frac51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{0.5 \cdot U}{1 \cdot J}}\right)\right) \]
      3. *-commutative51.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \frac{\color{blue}{U \cdot 0.5}}{1 \cdot J}\right)\right) \]
      4. times-frac51.7%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{\frac{U}{1} \cdot \frac{0.5}{J}}\right)\right) \]
      5. /-rgt-identity51.7%

        \[\leadsto -2 \cdot \left(J \cdot \left(1 + \color{blue}{U} \cdot \frac{0.5}{J}\right)\right) \]
    13. Simplified51.7%

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

    if -0.149999999999999994 < J < 7.6000000000000001e-297

    1. Initial program 61.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. Simplified77.5%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative29.3%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified29.3%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Taylor expanded in U around -inf 42.9%

      \[\leadsto -2 \cdot \color{blue}{\left(-1 \cdot \frac{{J}^{2}}{U} + -0.5 \cdot U\right)} \]
    7. Step-by-step derivation
      1. +-commutative42.9%

        \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U + -1 \cdot \frac{{J}^{2}}{U}\right)} \]
      2. mul-1-neg42.9%

        \[\leadsto -2 \cdot \left(-0.5 \cdot U + \color{blue}{\left(-\frac{{J}^{2}}{U}\right)}\right) \]
      3. unsub-neg42.9%

        \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U - \frac{{J}^{2}}{U}\right)} \]
      4. *-commutative42.9%

        \[\leadsto -2 \cdot \left(\color{blue}{U \cdot -0.5} - \frac{{J}^{2}}{U}\right) \]
      5. unpow242.9%

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
    8. Simplified42.9%

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

    if 7.6000000000000001e-297 < J < 2.8e-105

    1. Initial program 42.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. Simplified63.9%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 47.4%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg47.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -0.15:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 7.6 \cdot 10^{-297}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J \cdot J}{U}\right)\\ \mathbf{elif}\;J \leq 2.8 \cdot 10^{-105}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(1 + U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]

Alternative 10: 48.5% accurate, 45.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -1.9 \cdot 10^{+177}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-296}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-19}:\\ \;\;\;\;-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.9e+177)
   (* -2.0 J)
   (if (<= J 1.05e-296)
     (* -2.0 (* U -0.5))
     (if (<= J 5.6e-19) (- U) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -1.9e+177) {
		tmp = -2.0 * J;
	} else if (J <= 1.05e-296) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 5.6e-19) {
		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.9d+177)) then
        tmp = (-2.0d0) * j
    else if (j <= 1.05d-296) then
        tmp = (-2.0d0) * (u * (-0.5d0))
    else if (j <= 5.6d-19) 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.9e+177) {
		tmp = -2.0 * J;
	} else if (J <= 1.05e-296) {
		tmp = -2.0 * (U * -0.5);
	} else if (J <= 5.6e-19) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -1.9e+177:
		tmp = -2.0 * J
	elif J <= 1.05e-296:
		tmp = -2.0 * (U * -0.5)
	elif J <= 5.6e-19:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -1.9e+177)
		tmp = Float64(-2.0 * J);
	elseif (J <= 1.05e-296)
		tmp = Float64(-2.0 * Float64(U * -0.5));
	elseif (J <= 5.6e-19)
		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.9e+177)
		tmp = -2.0 * J;
	elseif (J <= 1.05e-296)
		tmp = -2.0 * (U * -0.5);
	elseif (J <= 5.6e-19)
		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.9e+177], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, 1.05e-296], N[(-2.0 * N[(U * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 5.6e-19], (-U), N[(-2.0 * J), $MachinePrecision]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -1.9 \cdot 10^{+177}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq 5.6 \cdot 10^{-19}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.8999999999999999e177 or 5.60000000000000005e-19 < J

    1. Initial program 97.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. Simplified99.7%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative49.3%

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

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

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified49.3%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Taylor expanded in J around inf 51.4%

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

    if -1.8999999999999999e177 < J < 1.05e-296

    1. Initial program 71.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. Simplified85.0%

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

      \[\leadsto -2 \cdot \color{blue}{\left(-0.5 \cdot U\right)} \]
    4. Step-by-step derivation
      1. *-commutative34.7%

        \[\leadsto -2 \cdot \color{blue}{\left(U \cdot -0.5\right)} \]
    5. Simplified34.7%

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

    if 1.05e-296 < J < 5.60000000000000005e-19

    1. Initial program 51.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. Simplified73.1%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 45.9%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg45.9%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified45.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.9 \cdot 10^{+177}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-296}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5\right)\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-19}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 11: 40.8% accurate, 83.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 18:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 (if (<= U 18.0) (* -2.0 J) (- U)))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 18.0) {
		tmp = -2.0 * J;
	} 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 (u <= 18.0d0) then
        tmp = (-2.0d0) * j
    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 (U <= 18.0) {
		tmp = -2.0 * J;
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 18.0:
		tmp = -2.0 * J
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 18.0)
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (U <= 18.0)
		tmp = -2.0 * J;
	else
		tmp = -U;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := If[LessEqual[U, 18.0], N[(-2.0 * J), $MachinePrecision], (-U)]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 18:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 18

    1. Initial program 83.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. Simplified91.6%

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

      \[\leadsto -2 \cdot \color{blue}{\left(\sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}} \cdot J\right)} \]
    4. Step-by-step derivation
      1. *-commutative39.6%

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)} \]
      2. unpow239.6%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{\color{blue}{U \cdot U}}{{J}^{2}}}\right) \]
      3. unpow239.6%

        \[\leadsto -2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{\color{blue}{J \cdot J}}}\right) \]
    5. Simplified39.6%

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    6. Taylor expanded in J around inf 34.2%

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

    if 18 < U

    1. Initial program 55.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. Simplified76.3%

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

      \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
    4. Taylor expanded in U around 0 42.2%

      \[\leadsto \color{blue}{-1 \cdot U} \]
    5. Step-by-step derivation
      1. mul-1-neg42.2%

        \[\leadsto \color{blue}{-U} \]
    6. Simplified42.2%

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

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

Alternative 12: 27.2% accurate, 210.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 Float64(-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 75.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. Simplified87.4%

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

    \[\leadsto -2 \cdot \color{blue}{\left(0.5 \cdot U\right)} \]
  4. Taylor expanded in U around 0 25.6%

    \[\leadsto \color{blue}{-1 \cdot U} \]
  5. Step-by-step derivation
    1. mul-1-neg25.6%

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

    \[\leadsto \color{blue}{-U} \]
  7. Final simplification25.6%

    \[\leadsto -U \]

Reproduce

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