Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.0% → 99.7%
Time: 16.2s
Alternatives: 10
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 73.0% 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.7% accurate, 0.4× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;\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
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY))
     (- U)
     (if (<= t_1 2e+307)
       (* (* 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 = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U;
	} else if (t_1 <= 2e+307) {
		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 = ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U;
	} else if (t_1 <= 2e+307) {
		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 = ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / (t_0 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U
	elif t_1 <= 2e+307:
		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(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U);
	elseif (t_1 <= 2e+307)
		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 = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / (t_0 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U;
	elseif (t_1 <= 2e+307)
		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[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U), If[LessEqual[t$95$1, 2e+307], 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(\left(-2 \cdot J\right) \cdot t_0\right) \cdot \sqrt{1 + {\left(\frac{U}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U\\

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

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

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

        \[\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-def49.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. *-commutative49.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*49.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. Simplified49.8%

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

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

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

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

    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 1.99999999999999997e307 < (*.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 6.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 2 \cdot 10^{+307}:\\ \;\;\;\;\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: 76.2% accurate, 1.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{if}\;J \leq -2.1 \cdot 10^{-113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{1 + \cos K}{2}}{\frac{U}{J \cdot J}}, U\right)\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-170}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* (* J (* -2.0 (cos (/ K 2.0)))) (hypot 1.0 (/ U (* J 2.0))))))
   (if (<= J -2.1e-113)
     t_0
     (if (<= J -8.4e-255)
       (fma 2.0 (/ (/ (+ 1.0 (cos K)) 2.0) (/ U (* J J))) U)
       (if (<= J 1.5e-170) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = (J * (-2.0 * cos((K / 2.0)))) * hypot(1.0, (U / (J * 2.0)));
	double tmp;
	if (J <= -2.1e-113) {
		tmp = t_0;
	} else if (J <= -8.4e-255) {
		tmp = fma(2.0, (((1.0 + cos(K)) / 2.0) / (U / (J * J))), U);
	} else if (J <= 1.5e-170) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
function code(J, K, U)
	t_0 = Float64(Float64(J * Float64(-2.0 * cos(Float64(K / 2.0)))) * hypot(1.0, Float64(U / Float64(J * 2.0))))
	tmp = 0.0
	if (J <= -2.1e-113)
		tmp = t_0;
	elseif (J <= -8.4e-255)
		tmp = fma(2.0, Float64(Float64(Float64(1.0 + cos(K)) / 2.0) / Float64(U / Float64(J * J))), U);
	elseif (J <= 1.5e-170)
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(J * N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -2.1e-113], t$95$0, If[LessEqual[J, -8.4e-255], N[(2.0 * N[(N[(N[(1.0 + N[Cos[K], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] / N[(U / N[(J * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[J, 1.5e-170], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\
\mathbf{if}\;J \leq -2.1 \cdot 10^{-113}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{\frac{1 + \cos K}{2}}{\frac{U}{J \cdot J}}, U\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -2.1e-113 or 1.50000000000000007e-170 < J

    1. Initial program 86.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. *-commutative86.4%

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

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

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

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

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

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

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

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

    if -2.1e-113 < J < -8.3999999999999999e-255

    1. Initial program 39.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. *-commutative39.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(2, \color{blue}{\frac{{\cos \left(0.5 \cdot K\right)}^{2}}{\frac{U}{{J}^{2}}}}, U\right) \]
      3. unpow254.7%

        \[\leadsto \mathsf{fma}\left(2, \frac{{\cos \left(0.5 \cdot K\right)}^{2}}{\frac{U}{\color{blue}{J \cdot J}}}, U\right) \]
    6. Simplified54.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(2, \frac{\frac{\cos \color{blue}{0} + \cos \left(K \cdot 0.5 + K \cdot 0.5\right)}{2}}{\frac{U}{J \cdot J}}, U\right) \]
      3. cos-054.7%

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

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

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

        \[\leadsto \mathsf{fma}\left(2, \frac{\frac{1 + \cos \color{blue}{K}}{2}}{\frac{U}{J \cdot J}}, U\right) \]
    10. Simplified54.7%

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

    if -8.3999999999999999e-255 < J < 1.50000000000000007e-170

    1. Initial program 42.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. *-commutative42.1%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -2.1 \cdot 10^{-113}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{\frac{1 + \cos K}{2}}{\frac{U}{J \cdot J}}, U\right)\\ \mathbf{elif}\;J \leq 1.5 \cdot 10^{-170}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot 2}\right)\\ \end{array} \]

Alternative 3: 60.0% accurate, 3.6× speedup?

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

\mathbf{elif}\;U \leq 3.2 \cdot 10^{-89}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;U \leq 1.45 \cdot 10^{+57}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;U \leq 1.8 \cdot 10^{+250}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;U \leq 3.4 \cdot 10^{+281}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if U < 2.9999999999999999e-193 or 3.19999999999999998e-89 < U < 1.4500000000000001e57

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)} \]
    5. Step-by-step derivation
      1. *-commutative58.6%

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

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

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

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

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

    if 2.9999999999999999e-193 < U < 3.19999999999999998e-89 or 1.4500000000000001e57 < U < 1.7999999999999999e250

    1. Initial program 77.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. *-commutative77.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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)}\right) \cdot \sqrt[3]{\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)}} \]
      2. pow382.1%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\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)}\right)}^{3}} \]
    5. Applied egg-rr82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.7999999999999999e250 < U < 3.40000000000000011e281

    1. Initial program 47.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. *-commutative47.1%

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

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

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

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

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

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

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

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

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

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

    if 3.40000000000000011e281 < U

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 3 \cdot 10^{-193}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U \leq 3.2 \cdot 10^{-89}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, -0.5 \cdot \frac{U}{J}\right)\\ \mathbf{elif}\;U \leq 1.45 \cdot 10^{+57}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U \leq 1.8 \cdot 10^{+250}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, -0.5 \cdot \frac{U}{J}\right)\\ \mathbf{elif}\;U \leq 3.4 \cdot 10^{+281}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 4: 58.9% accurate, 3.9× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;U \leq 1.66 \cdot 10^{+131}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U \leq 4.7 \cdot 10^{+231}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{U} - U\\ \mathbf{elif}\;U \leq 5.2 \cdot 10^{+255}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4 \cdot 10^{+281}:\\ \;\;\;\;-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 1.66e+131)
   (* (* -2.0 J) (cos (* K 0.5)))
   (if (<= U 4.7e+231)
     (- (* (* -2.0 J) (/ J U)) U)
     (if (<= U 5.2e+255) U (if (<= U 4e+281) (- U) U)))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (U <= 1.66e+131) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else if (U <= 4.7e+231) {
		tmp = ((-2.0 * J) * (J / U)) - U;
	} else if (U <= 5.2e+255) {
		tmp = U;
	} else if (U <= 4e+281) {
		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 (u <= 1.66d+131) then
        tmp = ((-2.0d0) * j) * cos((k * 0.5d0))
    else if (u <= 4.7d+231) then
        tmp = (((-2.0d0) * j) * (j / u)) - u
    else if (u <= 5.2d+255) then
        tmp = u
    else if (u <= 4d+281) 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 (U <= 1.66e+131) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else if (U <= 4.7e+231) {
		tmp = ((-2.0 * J) * (J / U)) - U;
	} else if (U <= 5.2e+255) {
		tmp = U;
	} else if (U <= 4e+281) {
		tmp = -U;
	} else {
		tmp = U;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	tmp = 0
	if U <= 1.66e+131:
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	elif U <= 4.7e+231:
		tmp = ((-2.0 * J) * (J / U)) - U
	elif U <= 5.2e+255:
		tmp = U
	elif U <= 4e+281:
		tmp = -U
	else:
		tmp = U
	return tmp
U = abs(U)
function code(J, K, U)
	tmp = 0.0
	if (U <= 1.66e+131)
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	elseif (U <= 4.7e+231)
		tmp = Float64(Float64(Float64(-2.0 * J) * Float64(J / U)) - U);
	elseif (U <= 5.2e+255)
		tmp = U;
	elseif (U <= 4e+281)
		tmp = Float64(-U);
	else
		tmp = U;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	tmp = 0.0;
	if (U <= 1.66e+131)
		tmp = (-2.0 * J) * cos((K * 0.5));
	elseif (U <= 4.7e+231)
		tmp = ((-2.0 * J) * (J / U)) - U;
	elseif (U <= 5.2e+255)
		tmp = U;
	elseif (U <= 4e+281)
		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, 1.66e+131], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[U, 4.7e+231], N[(N[(N[(-2.0 * J), $MachinePrecision] * N[(J / U), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision], If[LessEqual[U, 5.2e+255], U, If[LessEqual[U, 4e+281], (-U), U]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;U \leq 1.66 \cdot 10^{+131}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

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

\mathbf{elif}\;U \leq 5.2 \cdot 10^{+255}:\\
\;\;\;\;U\\

\mathbf{elif}\;U \leq 4 \cdot 10^{+281}:\\
\;\;\;\;-U\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.65999999999999992e131 < U < 4.70000000000000006e231

    1. Initial program 68.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. *-commutative68.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \frac{J}{U}\right)} - U \]
      5. associate-*r*46.1%

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

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

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

    if 4.70000000000000006e231 < U < 5.20000000000000019e255 or 4.0000000000000001e281 < U

    1. Initial program 51.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. *-commutative51.3%

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

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

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

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

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

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

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

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

    if 5.20000000000000019e255 < U < 4.0000000000000001e281

    1. Initial program 53.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. *-commutative53.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*53.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. unpow253.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-def61.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.66 \cdot 10^{+131}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U \leq 4.7 \cdot 10^{+231}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{U} - U\\ \mathbf{elif}\;U \leq 5.2 \cdot 10^{+255}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq 4 \cdot 10^{+281}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 5: 46.9% accurate, 21.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -6 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -3.8 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 7.2 \cdot 10^{+84}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{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 -6e+142)
   (* -2.0 J)
   (if (<= J -1.46e+41)
     U
     (if (<= J -3.8e-32)
       (* J (+ -2.0 (* 0.25 (* K K))))
       (if (<= J -8.4e-255)
         U
         (if (<= J 7.2e+84) (- (* (* -2.0 J) (/ J U)) U) (* -2.0 J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -6e+142) {
		tmp = -2.0 * J;
	} else if (J <= -1.46e+41) {
		tmp = U;
	} else if (J <= -3.8e-32) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -8.4e-255) {
		tmp = U;
	} else if (J <= 7.2e+84) {
		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 <= (-6d+142)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1.46d+41)) then
        tmp = u
    else if (j <= (-3.8d-32)) then
        tmp = j * ((-2.0d0) + (0.25d0 * (k * k)))
    else if (j <= (-8.4d-255)) then
        tmp = u
    else if (j <= 7.2d+84) 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 <= -6e+142) {
		tmp = -2.0 * J;
	} else if (J <= -1.46e+41) {
		tmp = U;
	} else if (J <= -3.8e-32) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -8.4e-255) {
		tmp = U;
	} else if (J <= 7.2e+84) {
		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 <= -6e+142:
		tmp = -2.0 * J
	elif J <= -1.46e+41:
		tmp = U
	elif J <= -3.8e-32:
		tmp = J * (-2.0 + (0.25 * (K * K)))
	elif J <= -8.4e-255:
		tmp = U
	elif J <= 7.2e+84:
		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 <= -6e+142)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1.46e+41)
		tmp = U;
	elseif (J <= -3.8e-32)
		tmp = Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K))));
	elseif (J <= -8.4e-255)
		tmp = U;
	elseif (J <= 7.2e+84)
		tmp = Float64(Float64(Float64(-2.0 * J) * Float64(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 <= -6e+142)
		tmp = -2.0 * J;
	elseif (J <= -1.46e+41)
		tmp = U;
	elseif (J <= -3.8e-32)
		tmp = J * (-2.0 + (0.25 * (K * K)));
	elseif (J <= -8.4e-255)
		tmp = U;
	elseif (J <= 7.2e+84)
		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, -6e+142], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1.46e+41], U, If[LessEqual[J, -3.8e-32], N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -8.4e-255], U, If[LessEqual[J, 7.2e+84], N[(N[(N[(-2.0 * J), $MachinePrecision] * N[(J / U), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision], N[(-2.0 * J), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -6 \cdot 10^{+142}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq -3.8 \cdot 10^{-32}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\
\;\;\;\;U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -5.99999999999999949e142 or 7.1999999999999999e84 < J

    1. Initial program 98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.99999999999999949e142 < J < -1.4600000000000001e41 or -3.80000000000000008e-32 < J < -8.3999999999999999e-255

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

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

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

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

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

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

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

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

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

    if -1.4600000000000001e41 < J < -3.80000000000000008e-32

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative72.3%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*72.3%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out72.3%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow272.3%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified72.3%

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

    if -8.3999999999999999e-255 < J < 7.1999999999999999e84

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \frac{J}{U}\right)} - U \]
      5. associate-*r*36.3%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \frac{J}{U}} - U \]
      6. *-commutative36.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -3.8 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 7.2 \cdot 10^{+84}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{U} - U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 6: 47.0% accurate, 21.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} \mathbf{if}\;J \leq -9.8 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.62 \cdot 10^{+34}:\\ \;\;\;\;J \cdot \left(-2 \cdot \left(\frac{U}{-2 \cdot J} - \frac{J}{U}\right)\right)\\ \mathbf{elif}\;J \leq -3.1 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.5 \cdot 10^{+85}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{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 -9.8e+142)
   (* -2.0 J)
   (if (<= J -1.62e+34)
     (* J (* -2.0 (- (/ U (* -2.0 J)) (/ J U))))
     (if (<= J -3.1e-32)
       (* J (+ -2.0 (* 0.25 (* K K))))
       (if (<= J -8.4e-255)
         U
         (if (<= J 6.5e+85) (- (* (* -2.0 J) (/ J U)) U) (* -2.0 J)))))))
U = abs(U);
double code(double J, double K, double U) {
	double tmp;
	if (J <= -9.8e+142) {
		tmp = -2.0 * J;
	} else if (J <= -1.62e+34) {
		tmp = J * (-2.0 * ((U / (-2.0 * J)) - (J / U)));
	} else if (J <= -3.1e-32) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -8.4e-255) {
		tmp = U;
	} else if (J <= 6.5e+85) {
		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 <= (-9.8d+142)) then
        tmp = (-2.0d0) * j
    else if (j <= (-1.62d+34)) then
        tmp = j * ((-2.0d0) * ((u / ((-2.0d0) * j)) - (j / u)))
    else if (j <= (-3.1d-32)) then
        tmp = j * ((-2.0d0) + (0.25d0 * (k * k)))
    else if (j <= (-8.4d-255)) then
        tmp = u
    else if (j <= 6.5d+85) 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 <= -9.8e+142) {
		tmp = -2.0 * J;
	} else if (J <= -1.62e+34) {
		tmp = J * (-2.0 * ((U / (-2.0 * J)) - (J / U)));
	} else if (J <= -3.1e-32) {
		tmp = J * (-2.0 + (0.25 * (K * K)));
	} else if (J <= -8.4e-255) {
		tmp = U;
	} else if (J <= 6.5e+85) {
		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 <= -9.8e+142:
		tmp = -2.0 * J
	elif J <= -1.62e+34:
		tmp = J * (-2.0 * ((U / (-2.0 * J)) - (J / U)))
	elif J <= -3.1e-32:
		tmp = J * (-2.0 + (0.25 * (K * K)))
	elif J <= -8.4e-255:
		tmp = U
	elif J <= 6.5e+85:
		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 <= -9.8e+142)
		tmp = Float64(-2.0 * J);
	elseif (J <= -1.62e+34)
		tmp = Float64(J * Float64(-2.0 * Float64(Float64(U / Float64(-2.0 * J)) - Float64(J / U))));
	elseif (J <= -3.1e-32)
		tmp = Float64(J * Float64(-2.0 + Float64(0.25 * Float64(K * K))));
	elseif (J <= -8.4e-255)
		tmp = U;
	elseif (J <= 6.5e+85)
		tmp = Float64(Float64(Float64(-2.0 * J) * Float64(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 <= -9.8e+142)
		tmp = -2.0 * J;
	elseif (J <= -1.62e+34)
		tmp = J * (-2.0 * ((U / (-2.0 * J)) - (J / U)));
	elseif (J <= -3.1e-32)
		tmp = J * (-2.0 + (0.25 * (K * K)));
	elseif (J <= -8.4e-255)
		tmp = U;
	elseif (J <= 6.5e+85)
		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, -9.8e+142], N[(-2.0 * J), $MachinePrecision], If[LessEqual[J, -1.62e+34], N[(J * N[(-2.0 * N[(N[(U / N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] - N[(J / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -3.1e-32], N[(J * N[(-2.0 + N[(0.25 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[J, -8.4e-255], U, If[LessEqual[J, 6.5e+85], N[(N[(N[(-2.0 * J), $MachinePrecision] * N[(J / U), $MachinePrecision]), $MachinePrecision] - U), $MachinePrecision], N[(-2.0 * J), $MachinePrecision]]]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
\mathbf{if}\;J \leq -9.8 \cdot 10^{+142}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;J \leq -3.1 \cdot 10^{-32}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\
\;\;\;\;U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if J < -9.80000000000000101e142 or 6.4999999999999994e85 < J

    1. Initial program 98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.80000000000000101e142 < J < -1.62000000000000006e34

    1. Initial program 93.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. *-commutative93.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*93.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. unpow293.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)} \]
    4. Taylor expanded in K around 0 43.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-2 \cdot \left(\color{blue}{\frac{1}{-2}} \cdot \frac{U}{J} - \frac{J}{U}\right)\right) \cdot J \]
      4. times-frac29.0%

        \[\leadsto \left(-2 \cdot \left(\color{blue}{\frac{1 \cdot U}{-2 \cdot J}} - \frac{J}{U}\right)\right) \cdot J \]
      5. *-lft-identity29.0%

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

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

    if -1.62000000000000006e34 < J < -3.10000000000000011e-32

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative72.3%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*72.3%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out72.3%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow272.3%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified72.3%

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

    if -3.10000000000000011e-32 < J < -8.3999999999999999e-255

    1. Initial program 50.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. *-commutative50.2%

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

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

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

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

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

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

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

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

    if -8.3999999999999999e-255 < J < 6.4999999999999994e85

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \frac{J}{U}\right)} - U \]
      5. associate-*r*36.3%

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \frac{J}{U}} - U \]
      6. *-commutative36.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -9.8 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1.62 \cdot 10^{+34}:\\ \;\;\;\;J \cdot \left(-2 \cdot \left(\frac{U}{-2 \cdot J} - \frac{J}{U}\right)\right)\\ \mathbf{elif}\;J \leq -3.1 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 6.5 \cdot 10^{+85}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \frac{J}{U} - U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 7: 46.9% accurate, 27.7× speedup?

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

\mathbf{elif}\;J \leq -9.8 \cdot 10^{+36}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq -2.25 \cdot 10^{-32}:\\
\;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\

\mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.8 \cdot 10^{+83}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if J < -1.4e142 or 5.79999999999999999e83 < J

    1. Initial program 98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.4e142 < J < -9.79999999999999962e36 or -2.25000000000000002e-32 < J < -8.3999999999999999e-255

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

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

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

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

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

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

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

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

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

    if -9.79999999999999962e36 < J < -2.25000000000000002e-32

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{0.25 \cdot \left({K}^{2} \cdot J\right) + -2 \cdot J} \]
    8. Step-by-step derivation
      1. +-commutative72.3%

        \[\leadsto \color{blue}{-2 \cdot J + 0.25 \cdot \left({K}^{2} \cdot J\right)} \]
      2. associate-*r*72.3%

        \[\leadsto -2 \cdot J + \color{blue}{\left(0.25 \cdot {K}^{2}\right) \cdot J} \]
      3. distribute-rgt-out72.3%

        \[\leadsto \color{blue}{J \cdot \left(-2 + 0.25 \cdot {K}^{2}\right)} \]
      4. unpow272.3%

        \[\leadsto J \cdot \left(-2 + 0.25 \cdot \color{blue}{\left(K \cdot K\right)}\right) \]
    9. Simplified72.3%

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

    if -8.3999999999999999e-255 < J < 5.79999999999999999e83

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.4 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -9.8 \cdot 10^{+36}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -2.25 \cdot 10^{-32}:\\ \;\;\;\;J \cdot \left(-2 + 0.25 \cdot \left(K \cdot K\right)\right)\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.8 \cdot 10^{+83}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 8: 46.6% accurate, 31.5× speedup?

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

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

\mathbf{elif}\;J \leq -1.85 \cdot 10^{-68}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\
\;\;\;\;U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -4.39999999999999974e142 or -1.00000000000000001e43 < J < -1.85000000000000001e-68 or 2.00000000000000012e84 < J

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.39999999999999974e142 < J < -1.00000000000000001e43 or -1.85000000000000001e-68 < J < -8.3999999999999999e-255

    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 \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*59.7%

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

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

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

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

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

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

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

    if -8.3999999999999999e-255 < J < 2.00000000000000012e84

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -4.4 \cdot 10^{+142}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -1 \cdot 10^{+43}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq -1.85 \cdot 10^{-68}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -8.4 \cdot 10^{-255}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 2 \cdot 10^{+84}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 9: 37.7% accurate, 103.4× speedup?

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

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


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

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

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def83.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. *-commutative83.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*83.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. Simplified83.8%

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

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

    if -8.3999999999999999e-255 < J

    1. Initial program 75.6%

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

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

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

        \[\leadsto \left(J \cdot \left(-2 \cdot \cos \left(\frac{K}{2}\right)\right)\right) \cdot \sqrt{1 + \color{blue}{\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)} \cdot \frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}}} \]
      4. hypot-1-def85.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. *-commutative85.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*85.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. Simplified85.8%

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

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

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

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

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

Alternative 10: 27.2% 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 76.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. *-commutative76.4%

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

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

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

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

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

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

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

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

    \[\leadsto U \]

Reproduce

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