Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.9% → 99.8%
Time: 23.2s
Alternatives: 11
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 11 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.3× speedup?

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

\mathbf{elif}\;t_1 \leq 6 \cdot 10^{+307}:\\
\;\;\;\;t_1\\

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


\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 4.8%

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

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

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

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

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

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

    if 5.9999999999999997e307 < (*.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 13.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq -\infty:\\ \;\;\;\;-U\\ \mathbf{elif}\;\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}} \leq 6 \cdot 10^{+307}:\\ \;\;\;\;\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(U \cdot -0.5 - \frac{J}{\frac{U}{J}}\right)\\ \end{array} \]

Alternative 2: 88.3% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ -2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right) \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (* -2.0 (* J (* t_0 (hypot 1.0 (/ U (* J (* 2.0 t_0)))))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K / 2.0));
	return -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	return -2.0 * (J * (t_0 * Math.hypot(1.0, (U / (J * (2.0 * t_0))))));
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K / 2.0))
	return -2.0 * (J * (t_0 * math.hypot(1.0, (U / (J * (2.0 * t_0))))))
U = abs(U)
function code(J, K, U)
	t_0 = cos(Float64(K / 2.0))
	return Float64(-2.0 * Float64(J * Float64(t_0 * hypot(1.0, Float64(U / Float64(J * Float64(2.0 * t_0)))))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = cos((K / 2.0));
	tmp = -2.0 * (J * (t_0 * hypot(1.0, (U / (J * (2.0 * t_0))))));
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(J * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(J * N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
-2 \cdot \left(J \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{J \cdot \left(2 \cdot t_0\right)}\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 77.0%

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

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

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

Alternative 3: 88.3% accurate, 1.3× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\ -2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_0}\right)\right) \end{array} \end{array} \]
NOTE: U should be positive before calling this function
(FPCore (J K U)
 :precision binary64
 (let* ((t_0 (* J (cos (/ K 2.0)))))
   (* -2.0 (* t_0 (hypot 1.0 (/ U (* 2.0 t_0)))))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = J * cos((K / 2.0));
	return -2.0 * (t_0 * hypot(1.0, (U / (2.0 * t_0))));
}
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = J * Math.cos((K / 2.0));
	return -2.0 * (t_0 * Math.hypot(1.0, (U / (2.0 * t_0))));
}
U = abs(U)
def code(J, K, U):
	t_0 = J * math.cos((K / 2.0))
	return -2.0 * (t_0 * math.hypot(1.0, (U / (2.0 * t_0))))
U = abs(U)
function code(J, K, U)
	t_0 = Float64(J * cos(Float64(K / 2.0)))
	return Float64(-2.0 * Float64(t_0 * hypot(1.0, Float64(U / Float64(2.0 * t_0)))))
end
U = abs(U)
function tmp = code(J, K, U)
	t_0 = J * cos((K / 2.0));
	tmp = -2.0 * (t_0 * hypot(1.0, (U / (2.0 * t_0))));
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(U / N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\
-2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{U}{2 \cdot t_0}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 77.0%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 74.0% accurate, 1.9× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1.50000000000000006e181

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

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

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

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

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

    if 1.50000000000000006e181 < U

    1. Initial program 48.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 73.9% accurate, 1.9× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1.27999999999999997e181

    1. Initial program 79.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. associate-*l*79.9%

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

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

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

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

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

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

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

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

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

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

    if 1.27999999999999997e181 < U

    1. Initial program 48.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 64.6% accurate, 3.7× speedup?

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

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

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


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

    1. Initial program 80.9%

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

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

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

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

    if 3.9499999999999999e-134 < U < 6.50000000000000052e179

    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. Taylor expanded in K around 0 43.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \color{blue}{\left(\sqrt{\frac{U}{J}} \cdot \sqrt{\frac{U}{J}}\right)}\right)\right) \cdot -2 \]
      7. add-sqr-sqrt68.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.50000000000000052e179 < U

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 66.3% accurate, 3.7× speedup?

\[\begin{array}{l} U = |U|\\ \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{if}\;J \leq -5.6 \cdot 10^{-98}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-82}:\\ \;\;\;\;-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 (* (cos (* K 0.5)) (* -2.0 J))))
   (if (<= J -5.6e-98)
     t_0
     (if (<= J -5.5e-306) U (if (<= J 1.05e-82) (- U) t_0)))))
U = abs(U);
double code(double J, double K, double U) {
	double t_0 = cos((K * 0.5)) * (-2.0 * J);
	double tmp;
	if (J <= -5.6e-98) {
		tmp = t_0;
	} else if (J <= -5.5e-306) {
		tmp = U;
	} else if (J <= 1.05e-82) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: U should be positive before calling this function
real(8) function code(j, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k * 0.5d0)) * ((-2.0d0) * j)
    if (j <= (-5.6d-98)) then
        tmp = t_0
    else if (j <= (-5.5d-306)) then
        tmp = u
    else if (j <= 1.05d-82) then
        tmp = -u
    else
        tmp = t_0
    end if
    code = tmp
end function
U = Math.abs(U);
public static double code(double J, double K, double U) {
	double t_0 = Math.cos((K * 0.5)) * (-2.0 * J);
	double tmp;
	if (J <= -5.6e-98) {
		tmp = t_0;
	} else if (J <= -5.5e-306) {
		tmp = U;
	} else if (J <= 1.05e-82) {
		tmp = -U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
U = abs(U)
def code(J, K, U):
	t_0 = math.cos((K * 0.5)) * (-2.0 * J)
	tmp = 0
	if J <= -5.6e-98:
		tmp = t_0
	elif J <= -5.5e-306:
		tmp = U
	elif J <= 1.05e-82:
		tmp = -U
	else:
		tmp = t_0
	return tmp
U = abs(U)
function code(J, K, U)
	t_0 = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J))
	tmp = 0.0
	if (J <= -5.6e-98)
		tmp = t_0;
	elseif (J <= -5.5e-306)
		tmp = U;
	elseif (J <= 1.05e-82)
		tmp = Float64(-U);
	else
		tmp = t_0;
	end
	return tmp
end
U = abs(U)
function tmp_2 = code(J, K, U)
	t_0 = cos((K * 0.5)) * (-2.0 * J);
	tmp = 0.0;
	if (J <= -5.6e-98)
		tmp = t_0;
	elseif (J <= -5.5e-306)
		tmp = U;
	elseif (J <= 1.05e-82)
		tmp = -U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: U should be positive before calling this function
code[J_, K_, U_] := Block[{t$95$0 = N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, -5.6e-98], t$95$0, If[LessEqual[J, -5.5e-306], U, If[LessEqual[J, 1.05e-82], (-U), t$95$0]]]]
\begin{array}{l}
U = |U|\\
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\
\mathbf{if}\;J \leq -5.6 \cdot 10^{-98}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 1.05 \cdot 10^{-82}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -5.5999999999999998e-98 or 1.05e-82 < J

    1. Initial program 90.2%

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

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

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

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

    if -5.5999999999999998e-98 < J < -5.49999999999999992e-306

    1. Initial program 52.5%

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

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

    if -5.49999999999999992e-306 < J < 1.05e-82

    1. Initial program 47.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -5.6 \cdot 10^{-98}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 1.05 \cdot 10^{-82}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \]

Alternative 8: 48.4% accurate, 24.4× speedup?

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

\mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\
\;\;\;\;U\\

\mathbf{elif}\;J \leq 5.5 \cdot 10^{-54}:\\
\;\;\;\;-U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.2999999999999999e121 or 5.50000000000000046e-54 < J

    1. Initial program 98.2%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.125 \cdot \frac{{U}^{2}}{J} + J\right)} \cdot -2 \]
      2. fma-def48.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.125, \frac{{U}^{2}}{J}, J\right)} \cdot -2 \]
      3. unpow248.7%

        \[\leadsto \mathsf{fma}\left(0.125, \frac{\color{blue}{U \cdot U}}{J}, J\right) \cdot -2 \]
      4. associate-*r/54.5%

        \[\leadsto \mathsf{fma}\left(0.125, \color{blue}{U \cdot \frac{U}{J}}, J\right) \cdot -2 \]
    7. Simplified54.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.125, U \cdot \frac{U}{J}, J\right)} \cdot -2 \]
    8. Step-by-step derivation
      1. fma-udef54.5%

        \[\leadsto \color{blue}{\left(0.125 \cdot \left(U \cdot \frac{U}{J}\right) + J\right)} \cdot -2 \]
    9. Applied egg-rr54.5%

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

    if -1.2999999999999999e121 < J < -5.49999999999999992e-306

    1. Initial program 67.8%

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

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

    if -5.49999999999999992e-306 < J < 5.50000000000000046e-54

    1. Initial program 47.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.3 \cdot 10^{+121}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \left(U \cdot \frac{U}{J}\right)\right)\\ \mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 5.5 \cdot 10^{-54}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J + 0.125 \cdot \left(U \cdot \frac{U}{J}\right)\right)\\ \end{array} \]

Alternative 9: 48.2% accurate, 45.7× speedup?

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

\mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\
\;\;\;\;U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < -1.7600000000000001e121 or 8.4e-54 < J

    1. Initial program 98.2%

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

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

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

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

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

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

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

    if -1.7600000000000001e121 < J < -5.49999999999999992e-306

    1. Initial program 67.8%

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

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

    if -5.49999999999999992e-306 < J < 8.4e-54

    1. Initial program 47.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.76 \cdot 10^{+121}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;J \leq -5.5 \cdot 10^{-306}:\\ \;\;\;\;U\\ \mathbf{elif}\;J \leq 8.4 \cdot 10^{-54}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]

Alternative 10: 38.8% accurate, 103.4× speedup?

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

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


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

    1. Initial program 77.3%

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

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

    if -7.6e-306 < J

    1. Initial program 76.7%

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

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

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

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

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

Alternative 11: 26.8% accurate, 420.0× speedup?

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

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification27.8%

    \[\leadsto U \]

Reproduce

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