Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 74.1% → 99.8%
Time: 22.6s
Alternatives: 12
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 74.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: 99.8% accurate, 0.3× speedup?

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

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;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 6.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. *-commutative6.1%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def56.1%

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

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

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

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

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

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

      \[\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)))) < 5e307

    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 5e307 < (*.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.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. *-commutative7.7%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def55.1%

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

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

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

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

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.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 5 \cdot 10^{+307}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 2: 77.6% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ t_2 := \left(\left(-2 \cdot J\right) \cdot t_1\right) \cdot t_0\\ \mathbf{if}\;J \leq -7.8 \cdot 10^{-125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.6 \cdot 10^{-159}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 5.5 \cdot 10^{-121}:\\ \;\;\;\;J \cdot \left(1 + \mathsf{fma}\left(t_1, -2 \cdot t_0, -1\right)\right)\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-65}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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)))
        (t_1 (hypot 1.0 (/ U (* J 2.0))))
        (t_2 (* (* (* -2.0 J) t_1) t_0)))
   (if (<= J -7.8e-125)
     t_2
     (if (<= J 8.2e-298)
       U
       (if (<= J 8.6e-159)
         (- U)
         (if (<= J 5.5e-121)
           (* J (+ 1.0 (fma t_1 (* -2.0 t_0) -1.0)))
           (if (<= J 5.6e-65) (- U) t_2)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = hypot(1.0, (U / (J * 2.0)));
	double t_2 = ((-2.0 * J) * t_1) * t_0;
	double tmp;
	if (J <= -7.8e-125) {
		tmp = t_2;
	} else if (J <= 8.2e-298) {
		tmp = U;
	} else if (J <= 8.6e-159) {
		tmp = -U;
	} else if (J <= 5.5e-121) {
		tmp = J * (1.0 + fma(t_1, (-2.0 * t_0), -1.0));
	} else if (J <= 5.6e-65) {
		tmp = -U;
	} else {
		tmp = t_2;
	}
	return tmp;
}
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = hypot(1.0, Float64(U / Float64(J * 2.0)))
	t_2 = Float64(Float64(Float64(-2.0 * J) * t_1) * t_0)
	tmp = 0.0
	if (J <= -7.8e-125)
		tmp = t_2;
	elseif (J <= 8.2e-298)
		tmp = U;
	elseif (J <= 8.6e-159)
		tmp = Float64(-U);
	elseif (J <= 5.5e-121)
		tmp = Float64(J * Float64(1.0 + fma(t_1, Float64(-2.0 * t_0), -1.0)));
	elseif (J <= 5.6e-65)
		tmp = Float64(-U);
	else
		tmp = t_2;
	end
	return tmp
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[1.0 ^ 2 + N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[J, -7.8e-125], t$95$2, If[LessEqual[J, 8.2e-298], U, If[LessEqual[J, 8.6e-159], (-U), If[LessEqual[J, 5.5e-121], N[(J * N[(1.0 + N[(t$95$1 * N[(-2.0 * t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, 5.6e-65], (-U), t$95$2]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\
t_2 := \left(\left(-2 \cdot J\right) \cdot t_1\right) \cdot t_0\\
\mathbf{if}\;J \leq -7.8 \cdot 10^{-125}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\
\;\;\;\;U\\

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

\mathbf{elif}\;J \leq 5.5 \cdot 10^{-121}:\\
\;\;\;\;J \cdot \left(1 + \mathsf{fma}\left(t_1, -2 \cdot t_0, -1\right)\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -7.79999999999999965e-125 or 5.6000000000000001e-65 < J

    1. Initial program 88.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. Step-by-step derivation
      1. *-commutative88.9%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.79999999999999965e-125 < J < 8.1999999999999997e-298

    1. Initial program 28.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. Step-by-step derivation
      1. *-commutative28.5%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def62.2%

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

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

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

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

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

    if 8.1999999999999997e-298 < J < 8.6e-159 or 5.50000000000000031e-121 < J < 5.6000000000000001e-65

    1. Initial program 54.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. Step-by-step derivation
      1. *-commutative54.9%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def67.6%

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

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

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

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

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

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

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

    if 8.6e-159 < J < 5.50000000000000031e-121

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(e^{\color{blue}{\log \left(1 + -2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)}\right)\right)\right)}} + \left(-1\right)\right) \]
      4. add-exp-log99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7.8 \cdot 10^{-125}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.6 \cdot 10^{-159}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 5.5 \cdot 10^{-121}:\\ \;\;\;\;J \cdot \left(1 + \mathsf{fma}\left(\mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right), -2 \cdot \cos \left(K \cdot 0.5\right), -1\right)\right)\\ \mathbf{elif}\;J \leq 5.6 \cdot 10^{-65}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 3: 88.6% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ J \cdot \left(t_0 \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\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))))
   (* J (* t_0 (* -2.0 (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return J * (t_0 * (-2.0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return J * (t_0 * (-2.0 * Math.hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return J * (t_0 * (-2.0 * math.hypot(1.0, (U / (J * (2.0 * t_0))))))
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(J * Float64(t_0 * Float64(-2.0 * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = J * (t_0 * (-2.0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
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]}, N[(J * N[(t$95$0 * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
J \cdot \left(t_0 \cdot \left(-2 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 72.2%

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

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

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

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

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

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

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

      \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
    8. hypot-1-def86.6%

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

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

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

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

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

Alternative 4: 88.6% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \left(J \cdot \left(-2 \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \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))))
   (* (* J (* -2.0 t_0)) (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return (J * (-2.0 * t_0)) * Math.hypot(1.0, (U / (J * (2.0 * t_0))));
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return (J * (-2.0 * t_0)) * math.hypot(1.0, (U / (J * (2.0 * t_0))))
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(Float64(J * Float64(-2.0 * t_0)) * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = (J * (-2.0 * t_0)) * hypot(1.0, (U / (J * (2.0 * t_0))));
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]}, N[(N[(J * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(J \cdot \left(-2 \cdot t_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 72.2%

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

      \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*72.2%

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

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

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

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

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

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

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

Alternative 5: 77.7% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{if}\;J \leq -1.5 \cdot 10^{-124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.25 \cdot 10^{-150} \lor \neg \left(J \leq 8.5 \cdot 10^{-122}\right) \land J \leq 6.8 \cdot 10^{-65}:\\ \;\;\;\;-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 2.0)))) (hypot 1.0 (/ U (* J 2.0))))))
   (if (<= J -1.5e-124)
     t_0
     (if (<= J 8.2e-298)
       U
       (if (or (<= J 2.25e-150) (and (not (<= J 8.5e-122)) (<= J 6.8e-65)))
         (- U)
         t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = (J * (-2.0 * cos((K / 2.0)))) * hypot(1.0, (U / (J * 2.0)));
	double tmp;
	if (J <= -1.5e-124) {
		tmp = t_0;
	} else if (J <= 8.2e-298) {
		tmp = U;
	} else if ((J <= 2.25e-150) || (!(J <= 8.5e-122) && (J <= 6.8e-65))) {
		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 = (J * (-2.0 * Math.cos((K / 2.0)))) * Math.hypot(1.0, (U / (J * 2.0)));
	double tmp;
	if (J <= -1.5e-124) {
		tmp = t_0;
	} else if (J <= 8.2e-298) {
		tmp = U;
	} else if ((J <= 2.25e-150) || (!(J <= 8.5e-122) && (J <= 6.8e-65))) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = (J * (-2.0 * math.cos((K / 2.0)))) * math.hypot(1.0, (U / (J * 2.0)))
	tmp = 0
	if J <= -1.5e-124:
		tmp = t_0
	elif J <= 8.2e-298:
		tmp = U
	elif (J <= 2.25e-150) or (not (J <= 8.5e-122) and (J <= 6.8e-65)):
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(J * Float64(-2.0 * cos(Float64(K / 2.0)))) * hypot(1.0, Float64(U / Float64(J * 2.0))))
	tmp = 0.0
	if (J <= -1.5e-124)
		tmp = t_0;
	elseif (J <= 8.2e-298)
		tmp = U;
	elseif ((J <= 2.25e-150) || (!(J <= 8.5e-122) && (J <= 6.8e-65)))
		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 / 2.0)))) * hypot(1.0, (U / (J * 2.0)));
	tmp = 0.0;
	if (J <= -1.5e-124)
		tmp = t_0;
	elseif (J <= 8.2e-298)
		tmp = U;
	elseif ((J <= 2.25e-150) || (~((J <= 8.5e-122)) && (J <= 6.8e-65)))
		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[(N[(J * N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.5e-124], t$95$0, If[LessEqual[J, 8.2e-298], U, If[Or[LessEqual[J, 2.25e-150], And[N[Not[LessEqual[J, 8.5e-122]], $MachinePrecision], LessEqual[J, 6.8e-65]]], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\
\mathbf{if}\;J \leq -1.5 \cdot 10^{-124}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 2.25 \cdot 10^{-150} \lor \neg \left(J \leq 8.5 \cdot 10^{-122}\right) \land J \leq 6.8 \cdot 10^{-65}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.5e-124 or 2.2500000000000001e-150 < J < 8.50000000000000003e-122 or 6.79999999999999973e-65 < J

    1. Initial program 88.4%

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

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*88.4%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\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)}}} \]
      4. hypot-1-def98.6%

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

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

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

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

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

    if -1.5e-124 < J < 8.1999999999999997e-298

    1. Initial program 28.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. Step-by-step derivation
      1. *-commutative28.5%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def62.2%

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

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

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

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

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

    if 8.1999999999999997e-298 < J < 2.2500000000000001e-150 or 8.50000000000000003e-122 < J < 6.79999999999999973e-65

    1. Initial program 54.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. Step-by-step derivation
      1. *-commutative54.9%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def67.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.5 \cdot 10^{-124}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.25 \cdot 10^{-150} \lor \neg \left(J \leq 8.5 \cdot 10^{-122}\right) \land J \leq 6.8 \cdot 10^{-65}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \end{array} \]

Alternative 6: 77.6% accurate, 1.9× speedup?

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

\mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\
\;\;\;\;U\\

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

\mathbf{elif}\;J \leq 5.5 \cdot 10^{-122}:\\
\;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot t_0\\

\mathbf{elif}\;J \leq 1.6 \cdot 10^{-64}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -1.29999999999999998e-123 or 1.59999999999999988e-64 < J

    1. Initial program 88.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. Step-by-step derivation
      1. *-commutative88.9%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.29999999999999998e-123 < J < 8.1999999999999997e-298

    1. Initial program 28.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. Step-by-step derivation
      1. *-commutative28.5%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def62.2%

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

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

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

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

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

    if 8.1999999999999997e-298 < J < 7.0000000000000001e-154 or 5.50000000000000053e-122 < J < 1.59999999999999988e-64

    1. Initial program 54.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. Step-by-step derivation
      1. *-commutative54.9%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def67.6%

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

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

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

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

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

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

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

    if 7.0000000000000001e-154 < J < 5.50000000000000053e-122

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

        \[\leadsto \left(\color{blue}{\left(J \cdot -2\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. associate-*l*78.6%

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\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)}}} \]
      4. hypot-1-def99.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.3 \cdot 10^{-123}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 7 \cdot 10^{-154}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 5.5 \cdot 10^{-122}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{elif}\;J \leq 1.6 \cdot 10^{-64}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]

Alternative 7: 64.5% accurate, 3.6× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -4.5 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -6.2 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(1 + \frac{U}{J}\right)\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.3 \cdot 10^{-296}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.5 \cdot 10^{-61}:\\ \;\;\;\;-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+32)
     t_0
     (if (<= J -6.2e-32)
       (* J (+ 1.0 (/ U J)))
       (if (<= J -2.1e-122)
         (- U)
         (if (<= J 2.3e-296) U (if (<= J 4.5e-61) (- 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+32) {
		tmp = t_0;
	} else if (J <= -6.2e-32) {
		tmp = J * (1.0 + (U / J));
	} else if (J <= -2.1e-122) {
		tmp = -U;
	} else if (J <= 2.3e-296) {
		tmp = U;
	} else if (J <= 4.5e-61) {
		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+32)) then
        tmp = t_0
    else if (j <= (-6.2d-32)) then
        tmp = j * (1.0d0 + (u / j))
    else if (j <= (-2.1d-122)) then
        tmp = -u
    else if (j <= 2.3d-296) then
        tmp = u
    else if (j <= 4.5d-61) 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+32) {
		tmp = t_0;
	} else if (J <= -6.2e-32) {
		tmp = J * (1.0 + (U / J));
	} else if (J <= -2.1e-122) {
		tmp = -U;
	} else if (J <= 2.3e-296) {
		tmp = U;
	} else if (J <= 4.5e-61) {
		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+32:
		tmp = t_0
	elif J <= -6.2e-32:
		tmp = J * (1.0 + (U / J))
	elif J <= -2.1e-122:
		tmp = -U
	elif J <= 2.3e-296:
		tmp = U
	elif J <= 4.5e-61:
		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+32)
		tmp = t_0;
	elseif (J <= -6.2e-32)
		tmp = Float64(J * Float64(1.0 + Float64(U / J)));
	elseif (J <= -2.1e-122)
		tmp = Float64(-U);
	elseif (J <= 2.3e-296)
		tmp = U;
	elseif (J <= 4.5e-61)
		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+32)
		tmp = t_0;
	elseif (J <= -6.2e-32)
		tmp = J * (1.0 + (U / J));
	elseif (J <= -2.1e-122)
		tmp = -U;
	elseif (J <= 2.3e-296)
		tmp = U;
	elseif (J <= 4.5e-61)
		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+32], t$95$0, If[LessEqual[J, -6.2e-32], N[(J * N[(1.0 + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -2.1e-122], (-U), If[LessEqual[J, 2.3e-296], U, If[LessEqual[J, 4.5e-61], (-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^{+32}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -6.2 \cdot 10^{-32}:\\
\;\;\;\;J \cdot \left(1 + \frac{U}{J}\right)\\

\mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 2.3 \cdot 10^{-296}:\\
\;\;\;\;U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -4.5000000000000003e32 or 4.5e-61 < J

    1. Initial program 94.0%

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def99.7%

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

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

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

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

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

    if -4.5000000000000003e32 < J < -6.20000000000000021e-32

    1. Initial program 61.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(e^{\color{blue}{\log \left(1 + -2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)}\right)\right)\right)}} + \left(-1\right)\right) \]
      4. add-exp-log99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.20000000000000021e-32 < J < -2.09999999999999992e-122 or 2.30000000000000004e-296 < J < 4.5e-61

    1. Initial program 59.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. *-commutative59.3%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def74.6%

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

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

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

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

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

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

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

    if -2.09999999999999992e-122 < J < 2.30000000000000004e-296

    1. Initial program 28.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. Step-by-step derivation
      1. *-commutative28.5%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def62.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -4.5 \cdot 10^{+32}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -6.2 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(1 + \frac{U}{J}\right)\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.3 \cdot 10^{-296}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 4.5 \cdot 10^{-61}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 8: 62.3% accurate, 3.7× speedup?

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

\mathbf{elif}\;K \leq 2.9 \cdot 10^{+183} \lor \neg \left(K \leq 6 \cdot 10^{+200}\right):\\
\;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if K < 0.95999999999999996

    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. Step-by-step derivation
      1. *-commutative74.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-2 \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) \cdot J \]
      4. hypot-1-def38.2%

        \[\leadsto \left(-2 \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) \cdot J \]
      5. sqrt-prod38.2%

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

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

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

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

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

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

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

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

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

    if 0.95999999999999996 < K < 2.9000000000000001e183 or 5.99999999999999982e200 < K

    1. Initial program 65.2%

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def80.8%

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

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

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

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

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

    if 2.9000000000000001e183 < K < 5.99999999999999982e200

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def81.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 0.96:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\\ \mathbf{elif}\;K \leq 2.9 \cdot 10^{+183} \lor \neg \left(K \leq 6 \cdot 10^{+200}\right):\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]

Alternative 9: 45.6% accurate, 24.1× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(1 + \frac{U}{J}\right)\\ \mathbf{if}\;J \leq -1.55 \cdot 10^{+247}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.6 \cdot 10^{+180}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -8 \cdot 10^{+37}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.55 \cdot 10^{-42}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{+88}:\\ \;\;\;\;-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
 (let* ((t_0 (* J (+ 1.0 (/ U J)))))
   (if (<= J -1.55e+247)
     (* -2.0 J)
     (if (<= J -1.6e+180)
       t_0
       (if (<= J -8e+37)
         (* -2.0 J)
         (if (<= J -1.55e-42)
           t_0
           (if (<= J -2.1e-122)
             (- U)
             (if (<= J 8.2e-298) U (if (<= J 2.1e+88) (- U) (* -2.0 J))))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * (1.0 + (U / J));
	double tmp;
	if (J <= -1.55e+247) {
		tmp = -2.0 * J;
	} else if (J <= -1.6e+180) {
		tmp = t_0;
	} else if (J <= -8e+37) {
		tmp = -2.0 * J;
	} else if (J <= -1.55e-42) {
		tmp = t_0;
	} else if (J <= -2.1e-122) {
		tmp = -U;
	} else if (J <= 8.2e-298) {
		tmp = U;
	} else if (J <= 2.1e+88) {
		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) :: t_0
    real(8) :: tmp
    t_0 = j * (1.0d0 + (u / j))
    if (j <= (-1.55d+247)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1.6d+180)) then
        tmp = t_0
    else if (j <= (-8d+37)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1.55d-42)) then
        tmp = t_0
    else if (j <= (-2.1d-122)) then
        tmp = -u
    else if (j <= 8.2d-298) then
        tmp = u
    else if (j <= 2.1d+88) 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 t_0 = J * (1.0 + (U / J));
	double tmp;
	if (J <= -1.55e+247) {
		tmp = -2.0 * J;
	} else if (J <= -1.6e+180) {
		tmp = t_0;
	} else if (J <= -8e+37) {
		tmp = -2.0 * J;
	} else if (J <= -1.55e-42) {
		tmp = t_0;
	} else if (J <= -2.1e-122) {
		tmp = -U;
	} else if (J <= 8.2e-298) {
		tmp = U;
	} else if (J <= 2.1e+88) {
		tmp = -U;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = J * (1.0 + (U / J))
	tmp = 0
	if J <= -1.55e+247:
		tmp = -2.0 * J
	elif J <= -1.6e+180:
		tmp = t_0
	elif J <= -8e+37:
		tmp = -2.0 * J
	elif J <= -1.55e-42:
		tmp = t_0
	elif J <= -2.1e-122:
		tmp = -U
	elif J <= 8.2e-298:
		tmp = U
	elif J <= 2.1e+88:
		tmp = -U
	else:
		tmp = -2.0 * J
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * Float64(1.0 + Float64(U / J)))
	tmp = 0.0
	if (J <= -1.55e+247)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1.6e+180)
		tmp = t_0;
	elseif (J <= -8e+37)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1.55e-42)
		tmp = t_0;
	elseif (J <= -2.1e-122)
		tmp = Float64(-U);
	elseif (J <= 8.2e-298)
		tmp = U;
	elseif (J <= 2.1e+88)
		tmp = Float64(-U);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = J * (1.0 + (U / J));
	tmp = 0.0;
	if (J <= -1.55e+247)
		tmp = -2.0 * J;
	elseif (J <= -1.6e+180)
		tmp = t_0;
	elseif (J <= -8e+37)
		tmp = -2.0 * J;
	elseif (J <= -1.55e-42)
		tmp = t_0;
	elseif (J <= -2.1e-122)
		tmp = -U;
	elseif (J <= 8.2e-298)
		tmp = U;
	elseif (J <= 2.1e+88)
		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_] := Block[{t$95$0 = N[(J * N[(1.0 + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -1.55e+247], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1.6e+180], t$95$0, If[LessEqual[J, -8e+37], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1.55e-42], t$95$0, If[LessEqual[J, -2.1e-122], (-U), If[LessEqual[J, 8.2e-298], U, If[LessEqual[J, 2.1e+88], (-U), N[(-2.0 * J), $MachinePrecision]]]]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \left(1 + \frac{U}{J}\right)\\
\mathbf{if}\;J \leq -1.55 \cdot 10^{+247}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq -8 \cdot 10^{+37}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -1.55 \cdot 10^{-42}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\
\;\;\;\;-U\\

\mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 2.1 \cdot 10^{+88}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -1.5499999999999999e247 or -1.59999999999999997e180 < J < -7.99999999999999963e37 or 2.1e88 < J

    1. Initial program 98.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. *-commutative98.7%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def99.8%

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

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

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

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

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

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

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

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

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

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

    if -1.5499999999999999e247 < J < -1.59999999999999997e180 or -7.99999999999999963e37 < J < -1.5500000000000001e-42

    1. Initial program 82.4%

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(e^{\color{blue}{\log \left(1 + -2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)}\right)\right)\right)}} + \left(-1\right)\right) \]
      4. add-exp-log99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5500000000000001e-42 < J < -2.09999999999999992e-122 or 8.1999999999999997e-298 < J < 2.1e88

    1. Initial program 65.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. *-commutative65.6%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def82.3%

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

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

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

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

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

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

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

    if -2.09999999999999992e-122 < J < 8.1999999999999997e-298

    1. Initial program 28.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. Step-by-step derivation
      1. *-commutative28.5%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def62.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.55 \cdot 10^{+247}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.6 \cdot 10^{+180}:\\ \;\;\;\;J \cdot \left(1 + \frac{U}{J}\right)\\ \mathbf{elif}\;J \leq -8 \cdot 10^{+37}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.55 \cdot 10^{-42}:\\ \;\;\;\;J \cdot \left(1 + \frac{U}{J}\right)\\ \mathbf{elif}\;J \leq -2.1 \cdot 10^{-122}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{+88}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 10: 49.6% accurate, 45.7× speedup?

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

\mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 2.5 \cdot 10^{+89}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.34999999999999998e38 or 2.49999999999999992e89 < J

    1. Initial program 98.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. *-commutative98.8%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def99.7%

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

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

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

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

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

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

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

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

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

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

    if -1.34999999999999998e38 < J < 8.1999999999999997e-298

    1. Initial program 41.5%

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def73.7%

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

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

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

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

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

    if 8.1999999999999997e-298 < J < 2.49999999999999992e89

    1. Initial program 66.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. *-commutative66.3%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def82.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.35 \cdot 10^{+38}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq 8.2 \cdot 10^{-298}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.5 \cdot 10^{+89}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 11: 38.1% accurate, 103.4× speedup?

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

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


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

    1. Initial program 68.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. Step-by-step derivation
      1. *-commutative68.0%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def85.8%

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

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

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

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

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

    if 8.1999999999999997e-298 < J

    1. Initial program 76.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. *-commutative76.1%

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
      8. hypot-1-def87.2%

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

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

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

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

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

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

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

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

Alternative 12: 26.5% 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 72.2%

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

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

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

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

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

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

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

      \[\leadsto J \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \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)\right) \]
    8. hypot-1-def86.6%

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification31.7%

    \[\leadsto U \]

Reproduce

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