Maksimov and Kolovsky, Equation (3)

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < -inf.0

    1. Initial program 6.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 41.5%

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

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

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

    if -inf.0 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2)))) < 1e303

    1. Initial program 99.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 1e303 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 5.1%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around -inf 50.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 10^{+303}:\\ \;\;\;\;-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}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 88.8% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq -2.85 \cdot 10^{-218} \lor \neg \left(J \leq -6.8 \cdot 10^{-304}\right):\\ \;\;\;\;-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 (or (<= J -2.85e-218) (not (<= J -6.8e-304)))
     (* -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 ((J <= -2.85e-218) || !(J <= -6.8e-304)) {
		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 ((J <= -2.85e-218) || !(J <= -6.8e-304)) {
		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 (J <= -2.85e-218) or not (J <= -6.8e-304):
		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 ((J <= -2.85e-218) || !(J <= -6.8e-304))
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(Float64(U / Float64(J * t_0)) * 0.5)))));
	else
		tmp = 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 ((J <= -2.85e-218) || ~((J <= -6.8e-304)))
		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[Or[LessEqual[J, -2.85e-218], N[Not[LessEqual[J, -6.8e-304]], $MachinePrecision]], 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}\;J \leq -2.85 \cdot 10^{-218} \lor \neg \left(J \leq -6.8 \cdot 10^{-304}\right):\\
\;\;\;\;-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 J < -2.8499999999999999e-218 or -6.7999999999999997e-304 < J

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

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

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

        \[\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. unpow271.6%

        \[\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-neg71.6%

        \[\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-neg71.6%

        \[\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-neg71.6%

        \[\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. unpow271.6%

        \[\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. Simplified90.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)} \]

    if -2.8499999999999999e-218 < J < -6.7999999999999997e-304

    1. Initial program 24.0%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around -inf 45.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.85 \cdot 10^{-218} \lor \neg \left(J \leq -6.8 \cdot 10^{-304}\right):\\ \;\;\;\;-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 3: 77.0% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -9 \cdot 10^{-209}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 4.2 \cdot 10^{-155} \lor \neg \left(J \leq 3.8 \cdot 10^{-107}\right) \land J \leq 2.6 \cdot 10^{-71}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* -2.0 (* (* J (cos (/ K 2.0))) (hypot 1.0 (* U (/ 0.5 J)))))))
   (if (<= J -9e-209)
     t_0
     (if (<= J -1e-310)
       (* -2.0 (- (* U -0.5) (* J (/ J U))))
       (if (or (<= J 4.2e-155) (and (not (<= J 3.8e-107)) (<= J 2.6e-71)))
         (- U)
         t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, (U * (0.5 / J))));
	double tmp;
	if (J <= -9e-209) {
		tmp = t_0;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if ((J <= 4.2e-155) || (!(J <= 3.8e-107) && (J <= 2.6e-71))) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = -2.0 * ((J * Math.cos((K / 2.0))) * Math.hypot(1.0, (U * (0.5 / J))));
	double tmp;
	if (J <= -9e-209) {
		tmp = t_0;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if ((J <= 4.2e-155) || (!(J <= 3.8e-107) && (J <= 2.6e-71))) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = -2.0 * ((J * math.cos((K / 2.0))) * math.hypot(1.0, (U * (0.5 / J))))
	tmp = 0
	if J <= -9e-209:
		tmp = t_0
	elif J <= -1e-310:
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)))
	elif (J <= 4.2e-155) or (not (J <= 3.8e-107) and (J <= 2.6e-71)):
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(-2.0 * Float64(Float64(J * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U * Float64(0.5 / J)))))
	tmp = 0.0
	if (J <= -9e-209)
		tmp = t_0;
	elseif (J <= -1e-310)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(J * Float64(J / U))));
	elseif ((J <= 4.2e-155) || (!(J <= 3.8e-107) && (J <= 2.6e-71)))
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, (U * (0.5 / J))));
	tmp = 0.0;
	if (J <= -9e-209)
		tmp = t_0;
	elseif (J <= -1e-310)
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	elseif ((J <= 4.2e-155) || (~((J <= 3.8e-107)) && (J <= 2.6e-71)))
		tmp = -U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(-2.0 * N[(N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -9e-209], t$95$0, If[LessEqual[J, -1e-310], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[J, 4.2e-155], And[N[Not[LessEqual[J, 3.8e-107]], $MachinePrecision], LessEqual[J, 2.6e-71]]], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := -2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -9 \cdot 10^{-209}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 4.2 \cdot 10^{-155} \lor \neg \left(J \leq 3.8 \cdot 10^{-107}\right) \land J \leq 2.6 \cdot 10^{-71}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -8.9999999999999996e-209 or 4.2000000000000003e-155 < J < 3.8000000000000002e-107 or 2.5999999999999999e-71 < J

    1. Initial program 83.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. associate-*l*83.3%

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

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

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

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

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

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

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

      \[\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)} \]
    4. Taylor expanded in K around 0 84.3%

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

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

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

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

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

    if -8.9999999999999996e-209 < J < -9.999999999999969e-311

    1. Initial program 26.4%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 3.7%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(-0.5 \cdot \frac{U}{J} + -1 \cdot \frac{J}{U}\right)}\right) \]
    6. Taylor expanded in J around 0 46.6%

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

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

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

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

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

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
      6. associate-*r/46.6%

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

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

    if -9.999999999999969e-311 < J < 4.2000000000000003e-155 or 3.8000000000000002e-107 < J < 2.5999999999999999e-71

    1. Initial program 33.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 32.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -9 \cdot 10^{-209}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 4.2 \cdot 10^{-155} \lor \neg \left(J \leq 3.8 \cdot 10^{-107}\right) \land J \leq 2.6 \cdot 10^{-71}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]

Alternative 4: 77.0% accurate, 1.9× 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 \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\\ \mathbf{if}\;J \leq -1.05 \cdot 10^{-208}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 9 \cdot 10^{-155}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-108}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot t_0\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 4.7 \cdot 10^{-73}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (* (* (* -2.0 J) t_0) (hypot 1.0 (* 0.5 (/ U J))))))
   (if (<= J -1.05e-208)
     t_1
     (if (<= J -1e-310)
       (* -2.0 (- (* U -0.5) (* J (/ J U))))
       (if (<= J 9e-155)
         (- U)
         (if (<= J 9.5e-108)
           (* -2.0 (* (* J t_0) (hypot 1.0 (* U (/ 0.5 J)))))
           (if (<= J 4.7e-73) (- U) t_1)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * hypot(1.0, (0.5 * (U / J)));
	double tmp;
	if (J <= -1.05e-208) {
		tmp = t_1;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= 9e-155) {
		tmp = -U;
	} else if (J <= 9.5e-108) {
		tmp = -2.0 * ((J * t_0) * hypot(1.0, (U * (0.5 / J))));
	} else if (J <= 4.7e-73) {
		tmp = -U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = ((-2.0 * J) * t_0) * Math.hypot(1.0, (0.5 * (U / J)));
	double tmp;
	if (J <= -1.05e-208) {
		tmp = t_1;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= 9e-155) {
		tmp = -U;
	} else if (J <= 9.5e-108) {
		tmp = -2.0 * ((J * t_0) * Math.hypot(1.0, (U * (0.5 / J))));
	} else if (J <= 4.7e-73) {
		tmp = -U;
	} else {
		tmp = t_1;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = ((-2.0 * J) * t_0) * math.hypot(1.0, (0.5 * (U / J)))
	tmp = 0
	if J <= -1.05e-208:
		tmp = t_1
	elif J <= -1e-310:
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)))
	elif J <= 9e-155:
		tmp = -U
	elif J <= 9.5e-108:
		tmp = -2.0 * ((J * t_0) * math.hypot(1.0, (U * (0.5 / J))))
	elif J <= 4.7e-73:
		tmp = -U
	else:
		tmp = t_1
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(Float64(-2.0 * J) * t_0) * hypot(1.0, Float64(0.5 * Float64(U / J))))
	tmp = 0.0
	if (J <= -1.05e-208)
		tmp = t_1;
	elseif (J <= -1e-310)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(J * Float64(J / U))));
	elseif (J <= 9e-155)
		tmp = Float64(-U);
	elseif (J <= 9.5e-108)
		tmp = Float64(-2.0 * Float64(Float64(J * t_0) * hypot(1.0, Float64(U * Float64(0.5 / J)))));
	elseif (J <= 4.7e-73)
		tmp = Float64(-U);
	else
		tmp = t_1;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K / 2.0));
	t_1 = ((-2.0 * J) * t_0) * hypot(1.0, (0.5 * (U / J)));
	tmp = 0.0;
	if (J <= -1.05e-208)
		tmp = t_1;
	elseif (J <= -1e-310)
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	elseif (J <= 9e-155)
		tmp = -U;
	elseif (J <= 9.5e-108)
		tmp = -2.0 * ((J * t_0) * hypot(1.0, (U * (0.5 / J))));
	elseif (J <= 4.7e-73)
		tmp = -U;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.05e-208], t$95$1, If[LessEqual[J, -1e-310], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 9e-155], (-U), If[LessEqual[J, 9.5e-108], N[(-2.0 * N[(N[(J * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 4.7e-73], (-U), t$95$1]]]]]]]
\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 \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\\
\mathbf{if}\;J \leq -1.05 \cdot 10^{-208}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;J \leq 9 \cdot 10^{-155}:\\
\;\;\;\;-U\\

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

\mathbf{elif}\;J \leq 4.7 \cdot 10^{-73}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -1.05000000000000006e-208 or 4.69999999999999994e-73 < J

    1. Initial program 83.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. Step-by-step derivation
      1. metadata-eval83.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.05000000000000006e-208 < J < -9.999999999999969e-311

    1. Initial program 26.4%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 3.7%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(-0.5 \cdot \frac{U}{J} + -1 \cdot \frac{J}{U}\right)}\right) \]
    6. Taylor expanded in J around 0 46.6%

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

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

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

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

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

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
      6. associate-*r/46.6%

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

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

    if -9.999999999999969e-311 < J < 9.0000000000000007e-155 or 9.5000000000000005e-108 < J < 4.69999999999999994e-73

    1. Initial program 33.2%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 32.7%

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

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

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

    if 9.0000000000000007e-155 < J < 9.5000000000000005e-108

    1. Initial program 78.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*78.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*78.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. unpow278.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.05 \cdot 10^{-208}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 9 \cdot 10^{-155}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 9.5 \cdot 10^{-108}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 4.7 \cdot 10^{-73}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\\ \end{array} \]

Alternative 5: 70.0% accurate, 2.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K 2)) < 0.69999999999999996

    1. Initial program 70.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around inf 53.0%

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

        \[\leadsto \color{blue}{\left(-2 \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J} \]
      2. metadata-eval53.0%

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

        \[\leadsto \left(\left(-2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot J \]
      4. distribute-lft-neg-in53.0%

        \[\leadsto \color{blue}{\left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \cdot J \]
      5. distribute-lft-neg-in53.0%

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

        \[\leadsto -\color{blue}{J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      7. distribute-rgt-neg-in53.0%

        \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      8. distribute-lft-neg-in53.0%

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

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

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

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

    if 0.69999999999999996 < (cos.f64 (/.f64 K 2))

    1. Initial program 66.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 41.6%

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u41.2%

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

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{1 + 0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)} - 1\right)}\right) \]
      3. add-sqr-sqrt41.2%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\sqrt{1 + \color{blue}{\sqrt{0.25 \cdot \frac{U \cdot U}{J \cdot J}} \cdot \sqrt{0.25 \cdot \frac{U \cdot U}{J \cdot J}}}}\right)} - 1\right)\right) \]
      4. hypot-1-def41.2%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\mathsf{hypot}\left(1, \sqrt{0.25 \cdot \frac{U \cdot U}{J \cdot J}}\right)}\right)} - 1\right)\right) \]
      5. *-commutative41.2%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{\frac{U \cdot U}{J \cdot J} \cdot 0.25}}\right)\right)} - 1\right)\right) \]
      6. sqrt-prod41.2%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \color{blue}{\sqrt{\frac{U \cdot U}{J \cdot J}} \cdot \sqrt{0.25}}\right)\right)} - 1\right)\right) \]
      7. times-frac58.4%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \sqrt{\color{blue}{\frac{U}{J} \cdot \frac{U}{J}}} \cdot \sqrt{0.25}\right)\right)} - 1\right)\right) \]
      8. sqrt-prod40.7%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \color{blue}{\left(\sqrt{\frac{U}{J}} \cdot \sqrt{\frac{U}{J}}\right)} \cdot \sqrt{0.25}\right)\right)} - 1\right)\right) \]
      9. add-sqr-sqrt74.8%

        \[\leadsto -2 \cdot \left(J \cdot \left(e^{\mathsf{log1p}\left(\mathsf{hypot}\left(1, \color{blue}{\frac{U}{J}} \cdot \sqrt{0.25}\right)\right)} - 1\right)\right) \]
      10. metadata-eval74.8%

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

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U \cdot 0.5}{J}}\right)\right) \]
    8. Simplified78.2%

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

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

Alternative 6: 64.8% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -4.5 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 7 \cdot 10^{+93}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (* -2.0 (cos (* K 0.5))))))
   (if (<= J -4.5e-58)
     t_0
     (if (<= J -1e-310)
       (* -2.0 (- (* U -0.5) (* J (/ J U))))
       (if (<= J 7e+93) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * cos((K * 0.5)));
	double tmp;
	if (J <= -4.5e-58) {
		tmp = t_0;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= 7e+93) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * ((-2.0d0) * cos((k * 0.5d0)))
    if (j <= (-4.5d-58)) then
        tmp = t_0
    else if (j <= (-1d-310)) then
        tmp = (-2.0d0) * ((u * (-0.5d0)) - (j * (j / u)))
    else if (j <= 7d+93) then
        tmp = -u
    else
        tmp = t_0
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = J * (-2.0 * Math.cos((K * 0.5)));
	double tmp;
	if (J <= -4.5e-58) {
		tmp = t_0;
	} else if (J <= -1e-310) {
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	} else if (J <= 7e+93) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (-2.0 * math.cos((K * 0.5)))
	tmp = 0
	if J <= -4.5e-58:
		tmp = t_0
	elif J <= -1e-310:
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)))
	elif J <= 7e+93:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))))
	tmp = 0.0
	if (J <= -4.5e-58)
		tmp = t_0;
	elseif (J <= -1e-310)
		tmp = Float64(-2.0 * Float64(Float64(U * -0.5) - Float64(J * Float64(J / U))));
	elseif (J <= 7e+93)
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (-2.0 * cos((K * 0.5)));
	tmp = 0.0;
	if (J <= -4.5e-58)
		tmp = t_0;
	elseif (J <= -1e-310)
		tmp = -2.0 * ((U * -0.5) - (J * (J / U)));
	elseif (J <= 7e+93)
		tmp = -U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -4.5e-58], t$95$0, If[LessEqual[J, -1e-310], N[(-2.0 * N[(N[(U * -0.5), $MachinePrecision] - N[(J * N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 7e+93], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{if}\;J \leq -4.5 \cdot 10^{-58}:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -4.5000000000000003e-58 or 6.99999999999999996e93 < J

    1. Initial program 95.0%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around inf 78.6%

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

        \[\leadsto \color{blue}{\left(-2 \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J} \]
      2. metadata-eval78.6%

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

        \[\leadsto \left(\left(-2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot J \]
      4. distribute-lft-neg-in78.6%

        \[\leadsto \color{blue}{\left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \cdot J \]
      5. distribute-lft-neg-in78.6%

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

        \[\leadsto -\color{blue}{J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      7. distribute-rgt-neg-in78.6%

        \[\leadsto \color{blue}{J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)} \]
      8. distribute-lft-neg-in78.6%

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

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

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

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

    if -4.5000000000000003e-58 < J < -9.999999999999969e-311

    1. Initial program 42.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 17.5%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(-0.5 \cdot \frac{U}{J} + -1 \cdot \frac{J}{U}\right)}\right) \]
    6. Taylor expanded in J around 0 46.0%

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

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

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

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

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

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
      6. associate-*r/45.9%

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

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

    if -9.999999999999969e-311 < J < 6.99999999999999996e93

    1. Initial program 47.7%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 34.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -4.5 \cdot 10^{-58}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 7 \cdot 10^{+93}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 7: 49.1% accurate, 27.8× speedup?

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

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

\mathbf{elif}\;J \leq 1.7 \cdot 10^{+108}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.50000000000000008e-54 or 1.69999999999999998e108 < J

    1. Initial program 94.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 40.9%

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

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

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

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

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

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

    if -2.50000000000000008e-54 < J < -9.999999999999969e-311

    1. Initial program 42.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 17.5%

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

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

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

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

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

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\left(-0.5 \cdot \frac{U}{J} + -1 \cdot \frac{J}{U}\right)}\right) \]
    6. Taylor expanded in J around 0 46.0%

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

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

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

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

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

        \[\leadsto -2 \cdot \left(U \cdot -0.5 - \frac{\color{blue}{J \cdot J}}{U}\right) \]
      6. associate-*r/45.9%

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

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

    if -9.999999999999969e-311 < J < 1.69999999999999998e108

    1. Initial program 48.7%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 34.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.5 \cdot 10^{-54}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - J \cdot \frac{J}{U}\right)\\ \mathbf{elif}\;J \leq 1.7 \cdot 10^{+108}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 8: 49.1% accurate, 45.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -2.4 \cdot 10^{-54}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.8 \cdot 10^{+108}:\\ \;\;\;\;-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 -2.4e-54)
   (* -2.0 J)
   (if (<= J -1e-310) U (if (<= J 6.8e+108) (- U) (* -2.0 J)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -2.4e-54) {
		tmp = -2.0 * J;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 6.8e+108) {
		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 <= (-2.4d-54)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1d-310)) then
        tmp = u
    else if (j <= 6.8d+108) 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 <= -2.4e-54) {
		tmp = -2.0 * J;
	} else if (J <= -1e-310) {
		tmp = U;
	} else if (J <= 6.8e+108) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -2.4e-54:
		tmp = -2.0 * J
	elif J <= -1e-310:
		tmp = U
	elif J <= 6.8e+108:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -2.4e-54)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 6.8e+108)
		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 <= -2.4e-54)
		tmp = -2.0 * J;
	elseif (J <= -1e-310)
		tmp = U;
	elseif (J <= 6.8e+108)
		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, -2.4e-54], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1e-310], U, If[LessEqual[J, 6.8e+108], (-U), N[(-2.0 * J), $MachinePrecision]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -2.4 \cdot 10^{-54}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq 6.8 \cdot 10^{+108}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.40000000000000013e-54 or 6.79999999999999992e108 < J

    1. Initial program 94.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0 40.9%

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

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

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

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

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

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

    if -2.40000000000000013e-54 < J < -9.999999999999969e-311

    1. Initial program 42.3%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around -inf 46.0%

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

    if -9.999999999999969e-311 < J < 6.79999999999999992e108

    1. Initial program 48.7%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 34.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.4 \cdot 10^{-54}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.8 \cdot 10^{+108}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 39.3% accurate, 103.4× speedup?

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

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


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

    1. Initial program 75.1%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around -inf 25.6%

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

    if -9.999999999999969e-311 < J

    1. Initial program 61.5%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in J around 0 27.3%

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

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

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

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

Alternative 10: 27.1% accurate, 420.0× speedup?

\[\begin{array}{l} U = |U|\\ \\ U \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U) :precision binary64 U)
U = abs(U);
double code(double J, double K, double U) {
	return U;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	return U;
}
U = abs(U)
def code(J, K, U):
	return U
U = abs(U)
function code(J, K, U)
	return U
end
U = abs(U)
function tmp = code(J, K, U)
	tmp = U;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := U
\begin{array}{l}
U = |U|\\
\\
U
\end{array}
Derivation
  1. Initial program 67.8%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Taylor expanded in U around -inf 31.1%

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

    \[\leadsto U \]

Reproduce

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