Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.2% → 99.2%
Time: 17.6s
Alternatives: 9
Speedup: 0.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

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

\[\begin{array}{l} U_m = \left|U\right| \\ \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_m}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U_m\\ \mathbf{elif}\;t_1 \leq 10^{+299}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1
         (*
          (* t_0 (* -2.0 J))
          (sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY)) (- U_m) (if (<= t_1 1e+299) t_1 U_m))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = (t_0 * (-2.0 * J)) * sqrt((1.0 + pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U_m;
	} else if (t_1 <= 1e+299) {
		tmp = t_1;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = (t_0 * (-2.0 * J)) * Math.sqrt((1.0 + Math.pow((U_m / (t_0 * (J * 2.0))), 2.0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U_m;
	} else if (t_1 <= 1e+299) {
		tmp = t_1;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = (t_0 * (-2.0 * J)) * math.sqrt((1.0 + math.pow((U_m / (t_0 * (J * 2.0))), 2.0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U_m
	elif t_1 <= 1e+299:
		tmp = t_1
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(Float64(t_0 * Float64(-2.0 * J)) * sqrt(Float64(1.0 + (Float64(U_m / Float64(t_0 * Float64(J * 2.0))) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U_m);
	elseif (t_1 <= 1e+299)
		tmp = t_1;
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = (t_0 * (-2.0 * J)) * sqrt((1.0 + ((U_m / (t_0 * (J * 2.0))) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U_m;
	elseif (t_1 <= 1e+299)
		tmp = t_1;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := 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$95$m / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 1e+299], t$95$1, U$95$m]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\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_m}{t_0 \cdot \left(J \cdot 2\right)}\right)}^{2}}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U_m\\

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

\mathbf{else}:\\
\;\;\;\;U_m\\


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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 69.4%

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

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

      \[\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.0000000000000001e299

    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. Add Preprocessing

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

    1. Initial program 7.9%

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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 52.8%

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

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

Alternative 2: 50.9% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq 4.2 \cdot 10^{-199}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{t_0}\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (* J (cos (/ K 2.0)))))
   (if (<= J 4.2e-199)
     (- U_m)
     (* -2.0 (* t_0 (hypot 1.0 (/ (/ U_m 2.0) t_0)))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = J * cos((K / 2.0));
	double tmp;
	if (J <= 4.2e-199) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * (t_0 * hypot(1.0, ((U_m / 2.0) / t_0)));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = J * Math.cos((K / 2.0));
	double tmp;
	if (J <= 4.2e-199) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * (t_0 * Math.hypot(1.0, ((U_m / 2.0) / t_0)));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = J * math.cos((K / 2.0))
	tmp = 0
	if J <= 4.2e-199:
		tmp = -U_m
	else:
		tmp = -2.0 * (t_0 * math.hypot(1.0, ((U_m / 2.0) / t_0)))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = Float64(J * cos(Float64(K / 2.0)))
	tmp = 0.0
	if (J <= 4.2e-199)
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * Float64(t_0 * hypot(1.0, Float64(Float64(U_m / 2.0) / t_0))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = J * cos((K / 2.0));
	tmp = 0.0;
	if (J <= 4.2e-199)
		tmp = -U_m;
	else
		tmp = -2.0 * (t_0 * hypot(1.0, ((U_m / 2.0) / t_0)));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[J, 4.2e-199], (-U$95$m), N[(-2.0 * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := J \cdot \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;J \leq 4.2 \cdot 10^{-199}:\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{t_0}\right)\right)\\


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

    1. Initial program 63.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. Simplified63.2%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 32.4%

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

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

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

    if 4.20000000000000004e-199 < J

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 4.2 \cdot 10^{-199}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 45.0% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \mathsf{hypot}\left(1, U_m \cdot \frac{0.5}{J}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 9e-82)
   (- U_m)
   (* -2.0 (* (* J (hypot 1.0 (* U_m (/ 0.5 J)))) (cos (* K 0.5))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 9e-82) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * ((J * hypot(1.0, (U_m * (0.5 / J)))) * cos((K * 0.5)));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 9e-82) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * ((J * Math.hypot(1.0, (U_m * (0.5 / J)))) * Math.cos((K * 0.5)));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 9e-82:
		tmp = -U_m
	else:
		tmp = -2.0 * ((J * math.hypot(1.0, (U_m * (0.5 / J)))) * math.cos((K * 0.5)))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 9e-82)
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * Float64(Float64(J * hypot(1.0, Float64(U_m * Float64(0.5 / J)))) * cos(Float64(K * 0.5))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 9e-82)
		tmp = -U_m;
	else
		tmp = -2.0 * ((J * hypot(1.0, (U_m * (0.5 / J)))) * cos((K * 0.5)));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 9e-82], (-U$95$m), N[(-2.0 * N[(N[(J * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(J \cdot \mathsf{hypot}\left(1, U_m \cdot \frac{0.5}{J}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\


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

    1. Initial program 62.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. Simplified62.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 34.9%

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

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

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

    if 8.9999999999999997e-82 < J

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 45.0% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J}\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 9e-82)
   (- U_m)
   (* -2.0 (* (* J (cos (/ K 2.0))) (hypot 1.0 (/ (/ U_m 2.0) J))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 9e-82) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, ((U_m / 2.0) / J)));
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 9e-82) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * ((J * Math.cos((K / 2.0))) * Math.hypot(1.0, ((U_m / 2.0) / J)));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 9e-82:
		tmp = -U_m
	else:
		tmp = -2.0 * ((J * math.cos((K / 2.0))) * math.hypot(1.0, ((U_m / 2.0) / J)))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 9e-82)
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * Float64(Float64(J * cos(Float64(K / 2.0))) * hypot(1.0, Float64(Float64(U_m / 2.0) / J))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 9e-82)
		tmp = -U_m;
	else
		tmp = -2.0 * ((J * cos((K / 2.0))) * hypot(1.0, ((U_m / 2.0) / J)));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 9e-82], (-U$95$m), N[(-2.0 * N[(N[(J * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J}\right)\right)\\


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

    1. Initial program 62.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. Simplified62.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 34.9%

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

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

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

    if 8.9999999999999997e-82 < J

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 9 \cdot 10^{-82}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 40.9% accurate, 3.5× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 2.45 \cdot 10^{-80}:\\ \;\;\;\;-U_m\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{+81}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U_m}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 2.45e-80)
   (- U_m)
   (if (<= J 2.1e+81)
     (* (* -2.0 J) (hypot 1.0 (* 0.5 (/ U_m J))))
     (* (cos (* K 0.5)) (* -2.0 J)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 2.45e-80) {
		tmp = -U_m;
	} else if (J <= 2.1e+81) {
		tmp = (-2.0 * J) * hypot(1.0, (0.5 * (U_m / J)));
	} else {
		tmp = cos((K * 0.5)) * (-2.0 * J);
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 2.45e-80) {
		tmp = -U_m;
	} else if (J <= 2.1e+81) {
		tmp = (-2.0 * J) * Math.hypot(1.0, (0.5 * (U_m / J)));
	} else {
		tmp = Math.cos((K * 0.5)) * (-2.0 * J);
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 2.45e-80:
		tmp = -U_m
	elif J <= 2.1e+81:
		tmp = (-2.0 * J) * math.hypot(1.0, (0.5 * (U_m / J)))
	else:
		tmp = math.cos((K * 0.5)) * (-2.0 * J)
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 2.45e-80)
		tmp = Float64(-U_m);
	elseif (J <= 2.1e+81)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(0.5 * Float64(U_m / J))));
	else
		tmp = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 2.45e-80)
		tmp = -U_m;
	elseif (J <= 2.1e+81)
		tmp = (-2.0 * J) * hypot(1.0, (0.5 * (U_m / J)));
	else
		tmp = cos((K * 0.5)) * (-2.0 * J);
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 2.45e-80], (-U$95$m), If[LessEqual[J, 2.1e+81], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 2.45 \cdot 10^{-80}:\\
\;\;\;\;-U_m\\

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

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


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

    1. Initial program 62.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. Simplified62.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 34.9%

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

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

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

    if 2.44999999999999995e-80 < J < 2.0999999999999999e81

    1. Initial program 64.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. Simplified64.8%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 25.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-2 \cdot J\right) \cdot \sqrt{1 + {\left(0.5 \cdot \frac{U}{J}\right)}^{2}}\right)} - 1} \]
      3. associate-*l*7.9%

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

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

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

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

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

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

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

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

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

    if 2.0999999999999999e81 < J

    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. Simplified99.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 88.6%

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

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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification49.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 2.45 \cdot 10^{-80}:\\ \;\;\;\;-U\\ \mathbf{elif}\;J \leq 2.1 \cdot 10^{+81}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 39.2% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 2.8 \cdot 10^{+38}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 2.8e+38) (- U_m) (* (cos (* K 0.5)) (* -2.0 J))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 2.8e+38) {
		tmp = -U_m;
	} else {
		tmp = cos((K * 0.5)) * (-2.0 * J);
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (j <= 2.8d+38) then
        tmp = -u_m
    else
        tmp = cos((k * 0.5d0)) * ((-2.0d0) * j)
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 2.8e+38) {
		tmp = -U_m;
	} else {
		tmp = Math.cos((K * 0.5)) * (-2.0 * J);
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 2.8e+38:
		tmp = -U_m
	else:
		tmp = math.cos((K * 0.5)) * (-2.0 * J)
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 2.8e+38)
		tmp = Float64(-U_m);
	else
		tmp = Float64(cos(Float64(K * 0.5)) * Float64(-2.0 * J));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 2.8e+38)
		tmp = -U_m;
	else
		tmp = cos((K * 0.5)) * (-2.0 * J);
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 2.8e+38], (-U$95$m), N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 2.8 \cdot 10^{+38}:\\
\;\;\;\;-U_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 2.8e38

    1. Initial program 62.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. Simplified62.3%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 36.6%

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

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

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

    if 2.8e38 < J

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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 82.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 2.8 \cdot 10^{+38}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(-2 \cdot J\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 26.3% accurate, 19.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 3.2 \lor \neg \left(K \leq 2.7 \cdot 10^{+98}\right) \land \left(K \leq 7.8 \cdot 10^{+193} \lor \neg \left(K \leq 1.05 \cdot 10^{+225}\right)\right):\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;U_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= K 3.2)
         (and (not (<= K 2.7e+98))
              (or (<= K 7.8e+193) (not (<= K 1.05e+225)))))
   (- U_m)
   U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((K <= 3.2) || (!(K <= 2.7e+98) && ((K <= 7.8e+193) || !(K <= 1.05e+225)))) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if ((k <= 3.2d0) .or. (.not. (k <= 2.7d+98)) .and. (k <= 7.8d+193) .or. (.not. (k <= 1.05d+225))) then
        tmp = -u_m
    else
        tmp = u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if ((K <= 3.2) || (!(K <= 2.7e+98) && ((K <= 7.8e+193) || !(K <= 1.05e+225)))) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (K <= 3.2) or (not (K <= 2.7e+98) and ((K <= 7.8e+193) or not (K <= 1.05e+225))):
		tmp = -U_m
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((K <= 3.2) || (!(K <= 2.7e+98) && ((K <= 7.8e+193) || !(K <= 1.05e+225))))
		tmp = Float64(-U_m);
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((K <= 3.2) || (~((K <= 2.7e+98)) && ((K <= 7.8e+193) || ~((K <= 1.05e+225)))))
		tmp = -U_m;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[K, 3.2], And[N[Not[LessEqual[K, 2.7e+98]], $MachinePrecision], Or[LessEqual[K, 7.8e+193], N[Not[LessEqual[K, 1.05e+225]], $MachinePrecision]]]], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 3.2 \lor \neg \left(K \leq 2.7 \cdot 10^{+98}\right) \land \left(K \leq 7.8 \cdot 10^{+193} \lor \neg \left(K \leq 1.05 \cdot 10^{+225}\right)\right):\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;U_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 3.2000000000000002 or 2.7e98 < K < 7.79999999999999999e193 or 1.05e225 < K

    1. Initial program 72.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. Simplified72.1%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 29.4%

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

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

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

    if 3.2000000000000002 < K < 2.7e98 or 7.79999999999999999e193 < K < 1.05e225

    1. Initial program 64.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. Simplified63.9%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 22.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 3.2 \lor \neg \left(K \leq 2.7 \cdot 10^{+98}\right) \land \left(K \leq 7.8 \cdot 10^{+193} \lor \neg \left(K \leq 1.05 \cdot 10^{+225}\right)\right):\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 31.7% accurate, 52.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 5.9 \cdot 10^{+84}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 (if (<= J 5.9e+84) (- U_m) (* -2.0 J)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 5.9e+84) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if (j <= 5.9d+84) then
        tmp = -u_m
    else
        tmp = (-2.0d0) * j
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if (J <= 5.9e+84) {
		tmp = -U_m;
	} else {
		tmp = -2.0 * J;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if J <= 5.9e+84:
		tmp = -U_m
	else:
		tmp = -2.0 * J
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (J <= 5.9e+84)
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * J);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (J <= 5.9e+84)
		tmp = -U_m;
	else
		tmp = -2.0 * J;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[J, 5.9e+84], (-U$95$m), N[(-2.0 * J), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 5.9 \cdot 10^{+84}:\\
\;\;\;\;-U_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < 5.89999999999999984e84

    1. Initial program 63.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. Simplified63.0%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 36.5%

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

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

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

    if 5.89999999999999984e84 < J

    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. Simplified99.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 42.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 5.9 \cdot 10^{+84}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot J\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 27.4% accurate, 420.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ U_m \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 U_m)
U_m = fabs(U);
double code(double J, double K, double U_m) {
	return U_m;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    code = u_m
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	return U_m;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	return U_m
U_m = abs(U)
function code(J, K, U_m)
	return U_m
end
U_m = abs(U);
function tmp = code(J, K, U_m)
	tmp = U_m;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := U$95$m
\begin{array}{l}
U_m = \left|U\right|

\\
U_m
\end{array}
Derivation
  1. Initial program 71.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. Simplified71.1%

    \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{\frac{U}{J \cdot 2}}{\cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in U around -inf 23.5%

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

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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