Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.1% → 98.6%
Time: 18.4s
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.1% 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.6% accurate, 0.3× speedup?

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

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

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


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

    1. Initial program 5.8%

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

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

        \[\leadsto \color{blue}{-U} \]
    4. Simplified60.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)))) < 9.9999999999999996e290

    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}} \]

    if 9.9999999999999996e290 < (*.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 7.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 U around -inf 48.0%

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

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

Alternative 2: 88.3% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq -3.2 \cdot 10^{-180} \lor \neg \left(J \leq -2.7 \cdot 10^{-301}\right):\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\right)\\ \mathbf{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 -3.2e-180) (not (<= J -2.7e-301)))
     (* -2.0 (* t_0 (* J (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 ((J <= -3.2e-180) || !(J <= -2.7e-301)) {
		tmp = -2.0 * (t_0 * (J * 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 ((J <= -3.2e-180) || !(J <= -2.7e-301)) {
		tmp = -2.0 * (t_0 * (J * 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 (J <= -3.2e-180) or not (J <= -2.7e-301):
		tmp = -2.0 * (t_0 * (J * 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 ((J <= -3.2e-180) || !(J <= -2.7e-301))
		tmp = Float64(-2.0 * Float64(t_0 * Float64(J * hypot(1.0, Float64(Float64(U / Float64(J * 2.0)) / t_0)))));
	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 <= -3.2e-180) || ~((J <= -2.7e-301)))
		tmp = -2.0 * (t_0 * (J * 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[Or[LessEqual[J, -3.2e-180], N[Not[LessEqual[J, -2.7e-301]], $MachinePrecision]], N[(-2.0 * N[(t$95$0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], U]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq -3.2 \cdot 10^{-180} \lor \neg \left(J \leq -2.7 \cdot 10^{-301}\right):\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{t_0}\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -3.20000000000000015e-180 or -2.7e-301 < J

    1. Initial program 74.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. Simplified92.1%

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

    if -3.20000000000000015e-180 < J < -2.7e-301

    1. Initial program 32.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3.2 \cdot 10^{-180} \lor \neg \left(J \leq -2.7 \cdot 10^{-301}\right):\\ \;\;\;\;-2 \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 3: 88.3% accurate, 1.3× speedup?

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

\mathbf{elif}\;J \leq -2.7 \cdot 10^{-301}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_1 \cdot \left(J \cdot t_0\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.29999999999999996e-180

    1. Initial program 81.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. Simplified91.8%

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

    if -2.29999999999999996e-180 < J < -2.7e-301

    1. Initial program 32.2%

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

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

    if -2.7e-301 < J

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 77.7% accurate, 1.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.4499999999999999e-69 or 1.99999999999999987e-124 < J

    1. Initial program 87.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*87.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*87.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. unpow287.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.4499999999999999e-69 < J < -3.999999999999988e-310

    1. Initial program 37.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 U around -inf 39.3%

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

    if -3.999999999999988e-310 < J < 1.99999999999999987e-124

    1. Initial program 43.6%

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

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

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

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

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

Alternative 5: 77.7% 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, \frac{U \cdot 0.5}{J}\right)\right)\\ \mathbf{if}\;J \leq -1.45 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 6 \cdot 10^{-309}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-124}:\\ \;\;\;\;-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 -1.45e-69)
     t_0
     (if (<= J 6e-309) U (if (<= J 1.5e-124) (- 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 <= -1.45e-69) {
		tmp = t_0;
	} else if (J <= 6e-309) {
		tmp = U;
	} else if (J <= 1.5e-124) {
		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 <= -1.45e-69) {
		tmp = t_0;
	} else if (J <= 6e-309) {
		tmp = U;
	} else if (J <= 1.5e-124) {
		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 <= -1.45e-69:
		tmp = t_0
	elif J <= 6e-309:
		tmp = U
	elif J <= 1.5e-124:
		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(Float64(U * 0.5) / J))))
	tmp = 0.0
	if (J <= -1.45e-69)
		tmp = t_0;
	elseif (J <= 6e-309)
		tmp = U;
	elseif (J <= 1.5e-124)
		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 <= -1.45e-69)
		tmp = t_0;
	elseif (J <= 6e-309)
		tmp = U;
	elseif (J <= 1.5e-124)
		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[(N[(U * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.45e-69], t$95$0, If[LessEqual[J, 6e-309], U, If[LessEqual[J, 1.5e-124], (-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, \frac{U \cdot 0.5}{J}\right)\right)\\
\mathbf{if}\;J \leq -1.45 \cdot 10^{-69}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq 6 \cdot 10^{-309}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.5 \cdot 10^{-124}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.4499999999999999e-69 or 1.5e-124 < J

    1. Initial program 87.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*87.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*87.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. unpow287.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.4499999999999999e-69 < J < 6.000000000000001e-309

    1. Initial program 37.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 U around -inf 39.3%

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

    if 6.000000000000001e-309 < J < 1.5e-124

    1. Initial program 43.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.45 \cdot 10^{-69}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{J}\right)\right)\\ \mathbf{elif}\;J \leq 6 \cdot 10^{-309}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-124}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U \cdot 0.5}{J}\right)\right)\\ \end{array} \]

Alternative 6: 66.2% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{if}\;J \leq -1.7 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.9 \cdot 10^{-95}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.15 \cdot 10^{-6} \lor \neg \left(J \leq 4.5 \cdot 10^{+23}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\frac{J}{U} + 0.5 \cdot \frac{U}{J}\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 0.5)) (* -2.0 J))))
   (if (<= J -1.7e-69)
     t_0
     (if (<= J -4e-310)
       U
       (if (<= J 2.9e-95)
         (- U)
         (if (or (<= J 2.15e-6) (not (<= J 4.5e+23)))
           t_0
           (* (* -2.0 J) (+ (/ J U) (* 0.5 (/ U J))))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K * 0.5)) * (-2.0 * J);
	double tmp;
	if (J <= -1.7e-69) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if (J <= 2.9e-95) {
		tmp = -U;
	} else if ((J <= 2.15e-6) || !(J <= 4.5e+23)) {
		tmp = t_0;
	} else {
		tmp = (-2.0 * J) * ((J / U) + (0.5 * (U / 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) :: t_0
    real(8) :: tmp
    t_0 = cos((k * 0.5d0)) * ((-2.0d0) * j)
    if (j <= (-1.7d-69)) then
        tmp = t_0
    else if (j <= (-4d-310)) then
        tmp = u
    else if (j <= 2.9d-95) then
        tmp = -u
    else if ((j <= 2.15d-6) .or. (.not. (j <= 4.5d+23))) then
        tmp = t_0
    else
        tmp = ((-2.0d0) * j) * ((j / u) + (0.5d0 * (u / j)))
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K * 0.5)) * (-2.0 * J);
	double tmp;
	if (J <= -1.7e-69) {
		tmp = t_0;
	} else if (J <= -4e-310) {
		tmp = U;
	} else if (J <= 2.9e-95) {
		tmp = -U;
	} else if ((J <= 2.15e-6) || !(J <= 4.5e+23)) {
		tmp = t_0;
	} else {
		tmp = (-2.0 * J) * ((J / U) + (0.5 * (U / J)));
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K * 0.5)) * (-2.0 * J)
	tmp = 0
	if J <= -1.7e-69:
		tmp = t_0
	elif J <= -4e-310:
		tmp = U
	elif J <= 2.9e-95:
		tmp = -U
	elif (J <= 2.15e-6) or not (J <= 4.5e+23):
		tmp = t_0
	else:
		tmp = (-2.0 * J) * ((J / U) + (0.5 * (U / J)))
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J))
	tmp = 0.0
	if (J <= -1.7e-69)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif (J <= 2.9e-95)
		tmp = Float64(-U);
	elseif ((J <= 2.15e-6) || !(J <= 4.5e+23))
		tmp = t_0;
	else
		tmp = Float64(Float64(-2.0 * J) * Float64(Float64(J / U) + Float64(0.5 * Float64(U / J))));
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K * 0.5)) * (-2.0 * J);
	tmp = 0.0;
	if (J <= -1.7e-69)
		tmp = t_0;
	elseif (J <= -4e-310)
		tmp = U;
	elseif (J <= 2.9e-95)
		tmp = -U;
	elseif ((J <= 2.15e-6) || ~((J <= 4.5e+23)))
		tmp = t_0;
	else
		tmp = (-2.0 * J) * ((J / U) + (0.5 * (U / J)));
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.7e-69], t$95$0, If[LessEqual[J, -4e-310], U, If[LessEqual[J, 2.9e-95], (-U), If[Or[LessEqual[J, 2.15e-6], N[Not[LessEqual[J, 4.5e+23]], $MachinePrecision]], t$95$0, N[(N[(-2.0 * J), $MachinePrecision] * N[(N[(J / U), $MachinePrecision] + N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\
\mathbf{if}\;J \leq -1.7 \cdot 10^{-69}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;J \leq 2.9 \cdot 10^{-95}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.15 \cdot 10^{-6} \lor \neg \left(J \leq 4.5 \cdot 10^{+23}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -1.70000000000000004e-69 or 2.90000000000000002e-95 < J < 2.15000000000000017e-6 or 4.49999999999999979e23 < J

    1. Initial program 93.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 76.3%

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

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

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

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

    if -1.70000000000000004e-69 < J < -3.999999999999988e-310

    1. Initial program 37.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 U around -inf 39.3%

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

    if -3.999999999999988e-310 < J < 2.90000000000000002e-95

    1. Initial program 44.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 53.5%

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

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

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

    if 2.15000000000000017e-6 < J < 4.49999999999999979e23

    1. Initial program 28.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 K around 0 26.8%

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

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

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

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

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

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

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{\left(0.5 \cdot \frac{U}{J}\right) \cdot \left(0.5 \cdot \frac{U}{J}\right)}} \]
      8. associate-*r/26.8%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \frac{\color{blue}{U \cdot 0.5}}{J} \cdot \left(0.5 \cdot \frac{U}{J}\right)} \]
      10. associate-*r/26.8%

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{\left(U \cdot \frac{0.5}{J}\right)} \cdot \left(0.5 \cdot \frac{U}{J}\right)} \]
      11. associate-*r/26.8%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \left(U \cdot \frac{0.5}{J}\right) \cdot \frac{\color{blue}{U \cdot 0.5}}{J}} \]
      13. associate-*r/26.8%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{{\left(U \cdot \frac{0.5}{J}\right)}^{2}}} \]
      15. associate-*r/26.8%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + {\left(\frac{\color{blue}{0.5 \cdot U}}{J}\right)}^{2}} \]
      17. associate-*r/26.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.7 \cdot 10^{-69}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.9 \cdot 10^{-95}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.15 \cdot 10^{-6} \lor \neg \left(J \leq 4.5 \cdot 10^{+23}\right):\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \left(\frac{J}{U} + 0.5 \cdot \frac{U}{J}\right)\\ \end{array} \]

Alternative 7: 64.9% accurate, 3.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 1.66e-91

    1. Initial program 79.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 inf 61.5%

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

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

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

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

    if 1.66e-91 < U < 1.45999999999999992e169

    1. Initial program 60.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 34.7%

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

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

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

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

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

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

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{\left(0.5 \cdot \frac{U}{J}\right) \cdot \left(0.5 \cdot \frac{U}{J}\right)}} \]
      8. associate-*r/36.7%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \frac{\color{blue}{U \cdot 0.5}}{J} \cdot \left(0.5 \cdot \frac{U}{J}\right)} \]
      10. associate-*r/36.7%

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{\left(U \cdot \frac{0.5}{J}\right)} \cdot \left(0.5 \cdot \frac{U}{J}\right)} \]
      11. associate-*r/36.7%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \left(U \cdot \frac{0.5}{J}\right) \cdot \frac{\color{blue}{U \cdot 0.5}}{J}} \]
      13. associate-*r/36.6%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + \color{blue}{{\left(U \cdot \frac{0.5}{J}\right)}^{2}}} \]
      15. associate-*r/36.7%

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 + {\left(\frac{\color{blue}{0.5 \cdot U}}{J}\right)}^{2}} \]
      17. associate-*r/36.7%

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

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

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

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 \cdot 1 + \color{blue}{\left(0.5 \cdot \frac{U}{J}\right) \cdot \left(0.5 \cdot \frac{U}{J}\right)}} \]
      3. associate-*r/36.7%

        \[\leadsto \left(J \cdot -2\right) \cdot \sqrt{1 \cdot 1 + \color{blue}{\frac{0.5 \cdot U}{J}} \cdot \left(0.5 \cdot \frac{U}{J}\right)} \]
      4. associate-*r/36.7%

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

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

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

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

    if 1.45999999999999992e169 < U

    1. Initial program 33.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 0 55.4%

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

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

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

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

Alternative 8: 49.6% accurate, 45.7× speedup?

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

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

\mathbf{elif}\;J \leq 3.2 \cdot 10^{+22}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.6000000000000002e-69 or 3.2e22 < J

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot J} \]
    6. Step-by-step derivation
      1. *-commutative49.4%

        \[\leadsto \color{blue}{J \cdot -2} \]
    7. Simplified49.4%

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

    if -2.6000000000000002e-69 < J < -3.999999999999988e-310

    1. Initial program 37.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 U around -inf 39.3%

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

    if -3.999999999999988e-310 < J < 3.2e22

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.6 \cdot 10^{-69}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -4 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.2 \cdot 10^{+22}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 40.0% accurate, 103.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -4 \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 -4e-310) U (- U)))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -4e-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 <= (-4d-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 <= -4e-310) {
		tmp = U;
	} else {
		tmp = -U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if J <= -4e-310:
		tmp = U
	else:
		tmp = -U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (J <= -4e-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 <= -4e-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, -4e-310], U, (-U)]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -4 \cdot 10^{-310}:\\
\;\;\;\;U\\

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


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

    1. Initial program 68.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 27.4%

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

    if -3.999999999999988e-310 < J

    1. Initial program 70.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 J around 0 30.9%

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

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

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

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

Alternative 10: 26.4% 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 69.6%

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

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

    \[\leadsto U \]

Reproduce

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