Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.3% → 99.8%
Time: 22.9s
Alternatives: 14
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 73.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% 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(\left(-2 \cdot J\right) \cdot t\_0\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^{+308}:\\ \;\;\;\;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
         (*
          (* (* -2.0 J) t_0)
          (sqrt (+ 1.0 (pow (/ U_m (* t_0 (* J 2.0))) 2.0))))))
   (if (<= t_1 (- INFINITY)) (- U_m) (if (<= t_1 1e+308) 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 = ((-2.0 * J) * t_0) * 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+308) {
		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 = ((-2.0 * J) * t_0) * 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+308) {
		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 = ((-2.0 * J) * t_0) * 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+308:
		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(Float64(-2.0 * J) * t_0) * 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+308)
		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 = ((-2.0 * J) * t_0) * 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+308)
		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[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $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+308], 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(\left(-2 \cdot J\right) \cdot t\_0\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^{+308}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 5.5%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 50.3%

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

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

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

    if -inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < 1e308

    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 1e308 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64)))))

    1. Initial program 5.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. Simplified64.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 59.0%

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

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

Alternative 2: 68.2% accurate, 0.6× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{if}\;t\_0 \leq -0.84:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq -0.75:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq -0.4:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;t\_0 \leq -0.246:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq 0.77:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\right)\\ \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 (* J (* (* -2.0 t_0) (+ 1.0 (* (* (/ U_m J) (/ U_m J)) 0.125))))))
   (if (<= t_0 -0.84)
     t_1
     (if (<= t_0 -0.75)
       U_m
       (if (<= t_0 -0.4)
         (* (* -2.0 J) (cos (* K 0.5)))
         (if (<= t_0 -0.246)
           U_m
           (if (<= t_0 0.77)
             t_1
             (* J (* -2.0 (hypot 1.0 (* U_m (/ 0.5 J))))))))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.84) {
		tmp = t_1;
	} else if (t_0 <= -0.75) {
		tmp = U_m;
	} else if (t_0 <= -0.4) {
		tmp = (-2.0 * J) * cos((K * 0.5));
	} else if (t_0 <= -0.246) {
		tmp = U_m;
	} else if (t_0 <= 0.77) {
		tmp = t_1;
	} else {
		tmp = J * (-2.0 * hypot(1.0, (U_m * (0.5 / J))));
	}
	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 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.84) {
		tmp = t_1;
	} else if (t_0 <= -0.75) {
		tmp = U_m;
	} else if (t_0 <= -0.4) {
		tmp = (-2.0 * J) * Math.cos((K * 0.5));
	} else if (t_0 <= -0.246) {
		tmp = U_m;
	} else if (t_0 <= 0.77) {
		tmp = t_1;
	} else {
		tmp = J * (-2.0 * Math.hypot(1.0, (U_m * (0.5 / J))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)))
	tmp = 0
	if t_0 <= -0.84:
		tmp = t_1
	elif t_0 <= -0.75:
		tmp = U_m
	elif t_0 <= -0.4:
		tmp = (-2.0 * J) * math.cos((K * 0.5))
	elif t_0 <= -0.246:
		tmp = U_m
	elif t_0 <= 0.77:
		tmp = t_1
	else:
		tmp = J * (-2.0 * math.hypot(1.0, (U_m * (0.5 / J))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(J * Float64(Float64(-2.0 * t_0) * Float64(1.0 + Float64(Float64(Float64(U_m / J) * Float64(U_m / J)) * 0.125))))
	tmp = 0.0
	if (t_0 <= -0.84)
		tmp = t_1;
	elseif (t_0 <= -0.75)
		tmp = U_m;
	elseif (t_0 <= -0.4)
		tmp = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)));
	elseif (t_0 <= -0.246)
		tmp = U_m;
	elseif (t_0 <= 0.77)
		tmp = t_1;
	else
		tmp = Float64(J * Float64(-2.0 * hypot(1.0, Float64(U_m * Float64(0.5 / J)))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	tmp = 0.0;
	if (t_0 <= -0.84)
		tmp = t_1;
	elseif (t_0 <= -0.75)
		tmp = U_m;
	elseif (t_0 <= -0.4)
		tmp = (-2.0 * J) * cos((K * 0.5));
	elseif (t_0 <= -0.246)
		tmp = U_m;
	elseif (t_0 <= 0.77)
		tmp = t_1;
	else
		tmp = J * (-2.0 * hypot(1.0, (U_m * (0.5 / J))));
	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[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[(1.0 + N[(N[(N[(U$95$m / J), $MachinePrecision] * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.84], t$95$1, If[LessEqual[t$95$0, -0.75], U$95$m, If[LessEqual[t$95$0, -0.4], N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.246], U$95$m, If[LessEqual[t$95$0, 0.77], t$95$1, N[(J * N[(-2.0 * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\
\mathbf{if}\;t\_0 \leq -0.84:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq -0.75:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_0 \leq -0.4:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\

\mathbf{elif}\;t\_0 \leq -0.246:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_0 \leq 0.77:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.839999999999999969 or -0.246 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.77000000000000002

    1. Initial program 82.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. Simplified94.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 67.5%

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

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

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(1 + \frac{{U}^{2}}{{J}^{2}} \cdot 0.125\right)}\right) \]
    8. Step-by-step derivation
      1. add-sqr-sqrt59.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.125\right)\right) \]
    9. Applied egg-rr62.7%

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

    if -0.839999999999999969 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.75 or -0.40000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.246

    1. Initial program 45.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. Simplified92.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 65.3%

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

    if -0.75 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.40000000000000002

    1. Initial program 94.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. Simplified99.4%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 83.8%

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

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

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

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

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

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

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

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

    if 0.77000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 77.4%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 82.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.84:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.75:\\ \;\;\;\;U\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.4:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.246:\\ \;\;\;\;U\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.77:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \left(\frac{U}{J} \cdot \frac{U}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U \cdot \frac{0.5}{J}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 88.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t\_0 \cdot \left(\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{t\_0 \cdot \left(J \cdot 2\right)}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 78.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. Simplified91.7%

    \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
  3. Add Preprocessing
  4. Applied egg-rr46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 88.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(J \cdot \left(-2 \cdot t\_0\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{J \cdot 2}}{t\_0}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 78.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 88.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J \cdot t\_0}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 78.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. Simplified91.7%

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

Alternative 6: 45.7% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 1.9 \cdot 10^{-124}:\\ \;\;\;\;\frac{-2 \cdot {\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U\_m} - U\_m\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \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 1.9e-124)
   (- (/ (* -2.0 (pow (* J (cos (* K 0.5))) 2.0)) U_m) U_m)
   (* J (* (* -2.0 (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 <= 1.9e-124) {
		tmp = ((-2.0 * pow((J * cos((K * 0.5))), 2.0)) / U_m) - U_m;
	} else {
		tmp = J * ((-2.0 * 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 <= 1.9e-124) {
		tmp = ((-2.0 * Math.pow((J * Math.cos((K * 0.5))), 2.0)) / U_m) - U_m;
	} else {
		tmp = J * ((-2.0 * 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 <= 1.9e-124:
		tmp = ((-2.0 * math.pow((J * math.cos((K * 0.5))), 2.0)) / U_m) - U_m
	else:
		tmp = J * ((-2.0 * 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 <= 1.9e-124)
		tmp = Float64(Float64(Float64(-2.0 * (Float64(J * cos(Float64(K * 0.5))) ^ 2.0)) / U_m) - U_m);
	else
		tmp = Float64(J * Float64(Float64(-2.0 * 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 <= 1.9e-124)
		tmp = ((-2.0 * ((J * cos((K * 0.5))) ^ 2.0)) / U_m) - U_m;
	else
		tmp = J * ((-2.0 * 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, 1.9e-124], N[(N[(N[(-2.0 * N[Power[N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / U$95$m), $MachinePrecision] - U$95$m), $MachinePrecision], N[(J * N[(N[(-2.0 * 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 1.9 \cdot 10^{-124}:\\
\;\;\;\;\frac{-2 \cdot {\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U\_m} - U\_m\\

\mathbf{else}:\\
\;\;\;\;J \cdot \left(\left(-2 \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 < 1.90000000000000006e-124

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 25.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1.90000000000000006e-124 < J

    1. Initial program 90.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. Simplified99.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 1.9 \cdot 10^{-124}:\\ \;\;\;\;\frac{-2 \cdot {\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}{U} - U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \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 7: 58.7% accurate, 3.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;U\_m \leq 2.4 \cdot 10^{-99}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;U\_m \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(\frac{J - U\_m}{J} + -1\right)\\ \mathbf{elif}\;U\_m \leq 1.52 \cdot 10^{+63}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (* (* -2.0 J) (cos (* K 0.5)))))
   (if (<= U_m 2.4e-99)
     t_0
     (if (<= U_m 1.18e-92)
       (* J (+ (/ (- J U_m) J) -1.0))
       (if (<= U_m 1.52e+63) t_0 (- U_m))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = (-2.0 * J) * cos((K * 0.5));
	double tmp;
	if (U_m <= 2.4e-99) {
		tmp = t_0;
	} else if (U_m <= 1.18e-92) {
		tmp = J * (((J - U_m) / J) + -1.0);
	} else if (U_m <= 1.52e+63) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((-2.0d0) * j) * cos((k * 0.5d0))
    if (u_m <= 2.4d-99) then
        tmp = t_0
    else if (u_m <= 1.18d-92) then
        tmp = j * (((j - u_m) / j) + (-1.0d0))
    else if (u_m <= 1.52d+63) then
        tmp = t_0
    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 t_0 = (-2.0 * J) * Math.cos((K * 0.5));
	double tmp;
	if (U_m <= 2.4e-99) {
		tmp = t_0;
	} else if (U_m <= 1.18e-92) {
		tmp = J * (((J - U_m) / J) + -1.0);
	} else if (U_m <= 1.52e+63) {
		tmp = t_0;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = (-2.0 * J) * math.cos((K * 0.5))
	tmp = 0
	if U_m <= 2.4e-99:
		tmp = t_0
	elif U_m <= 1.18e-92:
		tmp = J * (((J - U_m) / J) + -1.0)
	elif U_m <= 1.52e+63:
		tmp = t_0
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (U_m <= 2.4e-99)
		tmp = t_0;
	elseif (U_m <= 1.18e-92)
		tmp = Float64(J * Float64(Float64(Float64(J - U_m) / J) + -1.0));
	elseif (U_m <= 1.52e+63)
		tmp = t_0;
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = (-2.0 * J) * cos((K * 0.5));
	tmp = 0.0;
	if (U_m <= 2.4e-99)
		tmp = t_0;
	elseif (U_m <= 1.18e-92)
		tmp = J * (((J - U_m) / J) + -1.0);
	elseif (U_m <= 1.52e+63)
		tmp = t_0;
	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[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[U$95$m, 2.4e-99], t$95$0, If[LessEqual[U$95$m, 1.18e-92], N[(J * N[(N[(N[(J - U$95$m), $MachinePrecision] / J), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 1.52e+63], t$95$0, (-U$95$m)]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;U\_m \leq 2.4 \cdot 10^{-99}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;U\_m \leq 1.52 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 2.4e-99 or 1.18e-92 < U < 1.51999999999999993e63

    1. Initial program 84.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. Simplified95.5%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 63.2%

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

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

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

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

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

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

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

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

    if 2.4e-99 < U < 1.18e-92

    1. Initial program 67.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. Simplified100.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Applied egg-rr0.0%

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

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

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

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

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

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

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

    if 1.51999999999999993e63 < U

    1. Initial program 52.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. Simplified75.9%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 32.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 2.4 \cdot 10^{-99}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;U \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(\frac{J - U}{J} + -1\right)\\ \mathbf{elif}\;U \leq 1.52 \cdot 10^{+63}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 62.8% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;K \leq 1.6:\\
\;\;\;\;J \cdot \left(-2 \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\right)\\

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


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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.6000000000000001 < K

    1. Initial program 71.6%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around inf 46.4%

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

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

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

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

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

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

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

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

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

Alternative 9: 39.9% accurate, 18.2× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 1.15 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U\_m \leq 1.2 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(U\_m \cdot \left(\frac{1}{U\_m} + \frac{-1}{J}\right) + -1\right)\\ \mathbf{elif}\;U\_m \leq 1.06 \cdot 10^{-58}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 1.15e-109)
   (* -2.0 J)
   (if (<= U_m 1.2e-92)
     (* J (+ (* U_m (+ (/ 1.0 U_m) (/ -1.0 J))) -1.0))
     (if (<= U_m 1.06e-58) (* -2.0 J) (- U_m)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.15e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.2e-92) {
		tmp = J * ((U_m * ((1.0 / U_m) + (-1.0 / J))) + -1.0);
	} else if (U_m <= 1.06e-58) {
		tmp = -2.0 * J;
	} 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 (u_m <= 1.15d-109) then
        tmp = (-2.0d0) * j
    else if (u_m <= 1.2d-92) then
        tmp = j * ((u_m * ((1.0d0 / u_m) + ((-1.0d0) / j))) + (-1.0d0))
    else if (u_m <= 1.06d-58) then
        tmp = (-2.0d0) * j
    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 (U_m <= 1.15e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.2e-92) {
		tmp = J * ((U_m * ((1.0 / U_m) + (-1.0 / J))) + -1.0);
	} else if (U_m <= 1.06e-58) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 1.15e-109:
		tmp = -2.0 * J
	elif U_m <= 1.2e-92:
		tmp = J * ((U_m * ((1.0 / U_m) + (-1.0 / J))) + -1.0)
	elif U_m <= 1.06e-58:
		tmp = -2.0 * J
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 1.15e-109)
		tmp = Float64(-2.0 * J);
	elseif (U_m <= 1.2e-92)
		tmp = Float64(J * Float64(Float64(U_m * Float64(Float64(1.0 / U_m) + Float64(-1.0 / J))) + -1.0));
	elseif (U_m <= 1.06e-58)
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 1.15e-109)
		tmp = -2.0 * J;
	elseif (U_m <= 1.2e-92)
		tmp = J * ((U_m * ((1.0 / U_m) + (-1.0 / J))) + -1.0);
	elseif (U_m <= 1.06e-58)
		tmp = -2.0 * J;
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 1.15e-109], N[(-2.0 * J), $MachinePrecision], If[LessEqual[U$95$m, 1.2e-92], N[(J * N[(N[(U$95$m * N[(N[(1.0 / U$95$m), $MachinePrecision] + N[(-1.0 / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 1.06e-58], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 1.15 \cdot 10^{-109}:\\
\;\;\;\;-2 \cdot J\\

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

\mathbf{elif}\;U\_m \leq 1.06 \cdot 10^{-58}:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 1.1500000000000001e-109 or 1.2000000000000001e-92 < U < 1.0600000000000001e-58

    1. Initial program 84.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. Simplified94.9%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1500000000000001e-109 < U < 1.2000000000000001e-92

    1. Initial program 86.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. Simplified100.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Applied egg-rr0.0%

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

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

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

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

    if 1.0600000000000001e-58 < U

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 32.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.15 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U \leq 1.2 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(U \cdot \left(\frac{1}{U} + \frac{-1}{J}\right) + -1\right)\\ \mathbf{elif}\;U \leq 1.06 \cdot 10^{-58}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 39.9% accurate, 23.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 3.8 \cdot 10^{-109} \lor \neg \left(U\_m \leq 1.18 \cdot 10^{-92}\right) \land U\_m \leq 1.3 \cdot 10^{-58}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= U_m 3.8e-109) (and (not (<= U_m 1.18e-92)) (<= U_m 1.3e-58)))
   (* -2.0 J)
   (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((U_m <= 3.8e-109) || (!(U_m <= 1.18e-92) && (U_m <= 1.3e-58))) {
		tmp = -2.0 * J;
	} 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 ((u_m <= 3.8d-109) .or. (.not. (u_m <= 1.18d-92)) .and. (u_m <= 1.3d-58)) then
        tmp = (-2.0d0) * j
    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 ((U_m <= 3.8e-109) || (!(U_m <= 1.18e-92) && (U_m <= 1.3e-58))) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (U_m <= 3.8e-109) or (not (U_m <= 1.18e-92) and (U_m <= 1.3e-58)):
		tmp = -2.0 * J
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((U_m <= 3.8e-109) || (!(U_m <= 1.18e-92) && (U_m <= 1.3e-58)))
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((U_m <= 3.8e-109) || (~((U_m <= 1.18e-92)) && (U_m <= 1.3e-58)))
		tmp = -2.0 * J;
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[U$95$m, 3.8e-109], And[N[Not[LessEqual[U$95$m, 1.18e-92]], $MachinePrecision], LessEqual[U$95$m, 1.3e-58]]], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 3.8 \cdot 10^{-109} \lor \neg \left(U\_m \leq 1.18 \cdot 10^{-92}\right) \land U\_m \leq 1.3 \cdot 10^{-58}:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 3.80000000000000002e-109 or 1.18e-92 < U < 1.30000000000000003e-58

    1. Initial program 84.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. Simplified94.9%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.80000000000000002e-109 < U < 1.18e-92 or 1.30000000000000003e-58 < U

    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. Simplified85.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 34.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 3.8 \cdot 10^{-109} \lor \neg \left(U \leq 1.18 \cdot 10^{-92}\right) \land U \leq 1.3 \cdot 10^{-58}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 40.1% accurate, 23.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 2.5 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U\_m \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(-1 - \frac{U\_m}{J}\right)\\ \mathbf{elif}\;U\_m \leq 5 \cdot 10^{-59}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 2.5e-109)
   (* -2.0 J)
   (if (<= U_m 1.18e-92)
     (* J (- -1.0 (/ U_m J)))
     (if (<= U_m 5e-59) (* -2.0 J) (- U_m)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 2.5e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.18e-92) {
		tmp = J * (-1.0 - (U_m / J));
	} else if (U_m <= 5e-59) {
		tmp = -2.0 * J;
	} 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 (u_m <= 2.5d-109) then
        tmp = (-2.0d0) * j
    else if (u_m <= 1.18d-92) then
        tmp = j * ((-1.0d0) - (u_m / j))
    else if (u_m <= 5d-59) then
        tmp = (-2.0d0) * j
    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 (U_m <= 2.5e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.18e-92) {
		tmp = J * (-1.0 - (U_m / J));
	} else if (U_m <= 5e-59) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 2.5e-109:
		tmp = -2.0 * J
	elif U_m <= 1.18e-92:
		tmp = J * (-1.0 - (U_m / J))
	elif U_m <= 5e-59:
		tmp = -2.0 * J
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 2.5e-109)
		tmp = Float64(-2.0 * J);
	elseif (U_m <= 1.18e-92)
		tmp = Float64(J * Float64(-1.0 - Float64(U_m / J)));
	elseif (U_m <= 5e-59)
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 2.5e-109)
		tmp = -2.0 * J;
	elseif (U_m <= 1.18e-92)
		tmp = J * (-1.0 - (U_m / J));
	elseif (U_m <= 5e-59)
		tmp = -2.0 * J;
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 2.5e-109], N[(-2.0 * J), $MachinePrecision], If[LessEqual[U$95$m, 1.18e-92], N[(J * N[(-1.0 - N[(U$95$m / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 5e-59], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 2.5 \cdot 10^{-109}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;U\_m \leq 1.18 \cdot 10^{-92}:\\
\;\;\;\;J \cdot \left(-1 - \frac{U\_m}{J}\right)\\

\mathbf{elif}\;U\_m \leq 5 \cdot 10^{-59}:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 2.5000000000000001e-109 or 1.18e-92 < U < 5.0000000000000001e-59

    1. Initial program 84.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. Simplified94.9%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5000000000000001e-109 < U < 1.18e-92

    1. Initial program 86.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. Simplified100.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Applied egg-rr0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto J \cdot \left(\color{blue}{-1 \cdot \frac{U}{J}} - 1\right) \]
    12. Step-by-step derivation
      1. associate-*r/63.4%

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

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

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

    if 5.0000000000000001e-59 < U

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 32.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 2.5 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;J \cdot \left(-1 - \frac{U}{J}\right)\\ \mathbf{elif}\;U \leq 5 \cdot 10^{-59}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 39.8% accurate, 23.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 1.1 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U\_m \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;\frac{U\_m}{J} \cdot \left(-J\right)\\ \mathbf{elif}\;U\_m \leq 2.2 \cdot 10^{-59}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 1.1e-109)
   (* -2.0 J)
   (if (<= U_m 1.18e-92)
     (* (/ U_m J) (- J))
     (if (<= U_m 2.2e-59) (* -2.0 J) (- U_m)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.1e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.18e-92) {
		tmp = (U_m / J) * -J;
	} else if (U_m <= 2.2e-59) {
		tmp = -2.0 * J;
	} 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 (u_m <= 1.1d-109) then
        tmp = (-2.0d0) * j
    else if (u_m <= 1.18d-92) then
        tmp = (u_m / j) * -j
    else if (u_m <= 2.2d-59) then
        tmp = (-2.0d0) * j
    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 (U_m <= 1.1e-109) {
		tmp = -2.0 * J;
	} else if (U_m <= 1.18e-92) {
		tmp = (U_m / J) * -J;
	} else if (U_m <= 2.2e-59) {
		tmp = -2.0 * J;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 1.1e-109:
		tmp = -2.0 * J
	elif U_m <= 1.18e-92:
		tmp = (U_m / J) * -J
	elif U_m <= 2.2e-59:
		tmp = -2.0 * J
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 1.1e-109)
		tmp = Float64(-2.0 * J);
	elseif (U_m <= 1.18e-92)
		tmp = Float64(Float64(U_m / J) * Float64(-J));
	elseif (U_m <= 2.2e-59)
		tmp = Float64(-2.0 * J);
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if (U_m <= 1.1e-109)
		tmp = -2.0 * J;
	elseif (U_m <= 1.18e-92)
		tmp = (U_m / J) * -J;
	elseif (U_m <= 2.2e-59)
		tmp = -2.0 * J;
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 1.1e-109], N[(-2.0 * J), $MachinePrecision], If[LessEqual[U$95$m, 1.18e-92], N[(N[(U$95$m / J), $MachinePrecision] * (-J)), $MachinePrecision], If[LessEqual[U$95$m, 2.2e-59], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 1.1 \cdot 10^{-109}:\\
\;\;\;\;-2 \cdot J\\

\mathbf{elif}\;U\_m \leq 1.18 \cdot 10^{-92}:\\
\;\;\;\;\frac{U\_m}{J} \cdot \left(-J\right)\\

\mathbf{elif}\;U\_m \leq 2.2 \cdot 10^{-59}:\\
\;\;\;\;-2 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 1.1e-109 or 1.18e-92 < U < 2.1999999999999999e-59

    1. Initial program 84.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. Simplified94.9%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in K around 0 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1e-109 < U < 1.18e-92

    1. Initial program 86.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. Simplified100.0%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around inf 57.9%

      \[\leadsto J \cdot \color{blue}{\left(-1 \cdot \frac{U}{J}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/57.9%

        \[\leadsto J \cdot \color{blue}{\frac{-1 \cdot U}{J}} \]
      2. neg-mul-157.9%

        \[\leadsto J \cdot \frac{\color{blue}{-U}}{J} \]
    6. Simplified57.9%

      \[\leadsto J \cdot \color{blue}{\frac{-U}{J}} \]

    if 2.1999999999999999e-59 < U

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 32.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.1 \cdot 10^{-109}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{elif}\;U \leq 1.18 \cdot 10^{-92}:\\ \;\;\;\;\frac{U}{J} \cdot \left(-J\right)\\ \mathbf{elif}\;U \leq 2.2 \cdot 10^{-59}:\\ \;\;\;\;-2 \cdot J\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 26.8% accurate, 59.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 3.4 \cdot 10^{+26}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m) :precision binary64 (if (<= K 3.4e+26) (- U_m) U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 3.4e+26) {
		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.4d+26) 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.4e+26) {
		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.4e+26:
		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.4e+26)
		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.4e+26)
		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[LessEqual[K, 3.4e+26], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 3.4 \cdot 10^{+26}:\\
\;\;\;\;-U\_m\\

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


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

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in J around 0 24.8%

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

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

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

    if 3.4000000000000003e26 < K

    1. Initial program 69.6%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
    3. Add Preprocessing
    4. Taylor expanded in U around -inf 41.2%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 26.6% 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 78.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. Simplified91.7%

    \[\leadsto \color{blue}{J \cdot \left(\left(-2 \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)} \]
  3. Add Preprocessing
  4. Taylor expanded in U around -inf 28.0%

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Reproduce

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