Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.3% → 99.6%
Time: 17.8s
Alternatives: 9
Speedup: 1.3×

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 9 alternatives:

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

Initial Program: 73.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.4× speedup?

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

\mathbf{elif}\;t_1 \leq 10^{+305}:\\
\;\;\;\;\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)\\

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


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

    1. Initial program 5.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. *-commutative5.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*5.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*5.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. *-commutative5.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*5.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. *-commutative5.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. unpow25.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-def67.9%

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

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

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

      \[\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 38.5%

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

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

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

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

    1. Initial program 99.8%

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

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

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

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

    if 9.9999999999999994e304 < (*.f64 (*.f64 (*.f64 -2 J) (cos.f64 (/.f64 K 2))) (sqrt.f64 (+.f64 1 (pow.f64 (/.f64 U (*.f64 (*.f64 2 J) (cos.f64 (/.f64 K 2)))) 2))))

    1. Initial program 5.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. *-commutative5.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*5.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*5.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. *-commutative5.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*5.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. *-commutative5.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. unpow25.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-def64.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. *-commutative64.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*64.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. Simplified64.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 53.7%

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

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

Alternative 2: 88.1% 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 77.2%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. *-commutative77.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*77.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*77.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. *-commutative77.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*77.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. *-commutative77.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. unpow277.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-def91.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. *-commutative91.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*91.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. Simplified91.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. Final simplification91.8%

    \[\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 3: 73.3% accurate, 1.9× speedup?

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

\mathbf{elif}\;U \leq 3 \cdot 10^{+251}:\\
\;\;\;\;U\\

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


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

    1. Initial program 80.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. *-commutative80.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*80.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*80.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. *-commutative80.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*80.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. *-commutative80.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. unpow280.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-def95.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. *-commutative95.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*95.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. Simplified95.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. Taylor expanded in K around 0 80.8%

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

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

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

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

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

    if 5.9999999999999995e173 < U < 2.9999999999999999e251

    1. Initial program 41.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. *-commutative41.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*41.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*41.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. *-commutative41.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*41.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. *-commutative41.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. unpow241.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-def52.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. *-commutative52.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*52.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. Simplified52.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 69.2%

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

    if 2.9999999999999999e251 < U

    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.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. *-commutative65.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. unpow265.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-def65.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. *-commutative65.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*65.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. Simplified65.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 62.5%

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

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

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

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

Alternative 4: 67.0% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;J \leq -3 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -5 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.8 \cdot 10^{-28}:\\ \;\;\;\;-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 -3e-29) t_0 (if (<= J -5e-310) U (if (<= J 2.8e-28) (- 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 <= -3e-29) {
		tmp = t_0;
	} else if (J <= -5e-310) {
		tmp = U;
	} else if (J <= 2.8e-28) {
		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 <= (-3d-29)) then
        tmp = t_0
    else if (j <= (-5d-310)) then
        tmp = u
    else if (j <= 2.8d-28) 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 <= -3e-29) {
		tmp = t_0;
	} else if (J <= -5e-310) {
		tmp = U;
	} else if (J <= 2.8e-28) {
		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 <= -3e-29:
		tmp = t_0
	elif J <= -5e-310:
		tmp = U
	elif J <= 2.8e-28:
		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 <= -3e-29)
		tmp = t_0;
	elseif (J <= -5e-310)
		tmp = U;
	elseif (J <= 2.8e-28)
		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 <= -3e-29)
		tmp = t_0;
	elseif (J <= -5e-310)
		tmp = U;
	elseif (J <= 2.8e-28)
		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, -3e-29], t$95$0, If[LessEqual[J, -5e-310], U, If[LessEqual[J, 2.8e-28], (-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 -3 \cdot 10^{-29}:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -3.0000000000000003e-29 or 2.7999999999999998e-28 < J

    1. Initial program 96.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. *-commutative96.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*96.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*96.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. *-commutative96.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*96.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. *-commutative96.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. unpow296.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-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 U around 0 77.9%

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

    if -3.0000000000000003e-29 < J < -4.999999999999985e-310

    1. Initial program 48.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. *-commutative48.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*48.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*48.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. *-commutative48.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*48.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. *-commutative48.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. unpow248.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-def80.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. *-commutative80.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*80.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. Simplified80.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 U around -inf 41.3%

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

    if -4.999999999999985e-310 < J < 2.7999999999999998e-28

    1. Initial program 59.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. *-commutative59.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*59.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*59.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. *-commutative59.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*59.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. *-commutative59.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. unpow259.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-def83.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. *-commutative83.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*83.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. Simplified83.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 J around 0 31.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -3 \cdot 10^{-29}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;J \leq -5 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2.8 \cdot 10^{-28}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 5: 50.3% accurate, 24.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -8.5000000000000008e47

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

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

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

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

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

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

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

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

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

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

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

    if -8.5000000000000008e47 < J < 4.999999999999985e-310

    1. Initial program 57.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. *-commutative57.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*57.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*57.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. *-commutative57.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*57.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. *-commutative57.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. unpow257.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-def84.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. *-commutative84.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*84.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. Simplified84.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. Taylor expanded in U around -inf 34.8%

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

    if 4.999999999999985e-310 < J < 5.5000000000000002e-5

    1. Initial program 62.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. *-commutative62.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*62.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*62.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. *-commutative62.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*62.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. *-commutative62.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. unpow262.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-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 K around 0 26.0%

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U} + -1 \cdot U} \]
    8. Step-by-step derivation
      1. mul-1-neg27.2%

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

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U} - U} \]
      3. associate-*r/27.2%

        \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]
      4. unpow227.2%

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

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

    if 5.5000000000000002e-5 < J

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot J} \]
    8. Step-by-step derivation
      1. *-commutative37.7%

        \[\leadsto \color{blue}{J \cdot -2} \]
    9. Simplified37.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -8.5 \cdot 10^{+47}:\\ \;\;\;\;J \cdot \left(-2 \cdot \left(1 + \left(U \cdot \frac{U}{J \cdot J}\right) \cdot 0.125\right)\right)\\ \mathbf{elif}\;J \leq 5 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.5 \cdot 10^{-5}:\\ \;\;\;\;\frac{-2 \cdot \left(J \cdot J\right)}{U} - U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 6: 50.2% accurate, 27.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -7.5000000000000003e46 or 3.59999999999999984e-6 < J

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

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

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

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

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

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

        \[\leadsto \color{blue}{J \cdot -2} \]
    9. Simplified41.4%

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

    if -7.5000000000000003e46 < J < -4.999999999999985e-310

    1. Initial program 57.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. *-commutative57.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*57.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*57.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. *-commutative57.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*57.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. *-commutative57.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. unpow257.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-def84.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. *-commutative84.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*84.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. Simplified84.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. Taylor expanded in U around -inf 34.8%

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

    if -4.999999999999985e-310 < J < 3.59999999999999984e-6

    1. Initial program 62.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. *-commutative62.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*62.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*62.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. *-commutative62.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*62.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. *-commutative62.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. unpow262.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-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 K around 0 26.0%

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U} + -1 \cdot U} \]
    8. Step-by-step derivation
      1. mul-1-neg27.2%

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

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2}}{U} - U} \]
      3. associate-*r/27.2%

        \[\leadsto \color{blue}{\frac{-2 \cdot {J}^{2}}{U}} - U \]
      4. unpow227.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -7.5 \cdot 10^{+46}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -5 \cdot 10^{-310}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 3.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{-2 \cdot \left(J \cdot J\right)}{U} - U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 7: 50.2% accurate, 45.7× speedup?

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

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

\mathbf{elif}\;J \leq 0.00185:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -7.1999999999999997e46 or 0.0018500000000000001 < J

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

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

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

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

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

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

        \[\leadsto \color{blue}{J \cdot -2} \]
    9. Simplified41.4%

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

    if -7.1999999999999997e46 < J < -4.999999999999985e-310

    1. Initial program 57.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. *-commutative57.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*57.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*57.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. *-commutative57.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*57.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. *-commutative57.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. unpow257.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-def84.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. *-commutative84.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*84.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. Simplified84.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. Taylor expanded in U around -inf 34.8%

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

    if -4.999999999999985e-310 < J < 0.0018500000000000001

    1. Initial program 62.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. *-commutative62.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*62.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*62.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. *-commutative62.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*62.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. *-commutative62.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. unpow262.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-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 J around 0 27.3%

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

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

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

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

Alternative 8: 39.7% accurate, 103.4× speedup?

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

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


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

    1. Initial program 74.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. *-commutative74.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*74.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*74.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. *-commutative74.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*74.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. *-commutative74.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. unpow274.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-def90.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. *-commutative90.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*90.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. Simplified90.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 26.0%

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

    if 6.4999999999999999e-308 < J

    1. Initial program 80.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. *-commutative80.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*80.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*80.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. *-commutative80.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*80.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. *-commutative80.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. unpow280.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-def92.9%

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

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

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

      \[\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 22.5%

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

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

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

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

Alternative 9: 26.8% accurate, 420.0× speedup?

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

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. *-commutative77.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*77.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*77.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. *-commutative77.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*77.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. *-commutative77.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. unpow277.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-def91.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. *-commutative91.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*91.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. Simplified91.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 28.5%

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

    \[\leadsto U \]

Reproduce

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