Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.5% → 98.9%
Time: 13.8s
Alternatives: 11
Speedup: 0.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 73.5% 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: 98.9% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 10^{+297}:\\
\;\;\;\;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 4.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified70.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 0 33.8%

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

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

      \[\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))))) < 1e297

    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 1e297 < (*.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.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. Simplified56.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 U around -inf 69.4%

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

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

Alternative 2: 50.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 2.2 \cdot 10^{-249}:\\
\;\;\;\;-U\_m\\

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


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

    1. Initial program 70.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. Simplified87.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 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 2.2e-249 < J

    1. Initial program 83.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. Simplified95.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. Step-by-step derivation
      1. clear-num95.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \color{blue}{\frac{U}{-J \cdot 2}} \cdot \frac{1}{-\cos \left(\frac{K}{2}\right)}\right)\right) \]
      14. distribute-rgt-neg-in95.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 50.8% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;J \leq 1.55 \cdot 10^{-249}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;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))))
   (if (<= J 1.55e-249)
     (- U_m)
     (* 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));
	double tmp;
	if (J <= 1.55e-249) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	}
	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 tmp;
	if (J <= 1.55e-249) {
		tmp = -U_m;
	} else {
		tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if J <= 1.55e-249:
		tmp = -U_m
	else:
		tmp = J * ((-2.0 * t_0) * math.hypot(1.0, ((U_m / 2.0) / (J * t_0))))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (J <= 1.55e-249)
		tmp = Float64(-U_m);
	else
		tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(Float64(U_m / 2.0) / Float64(J * t_0)))));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (J <= 1.55e-249)
		tmp = -U_m;
	else
		tmp = J * ((-2.0 * t_0) * hypot(1.0, ((U_m / 2.0) / (J * t_0))));
	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]}, If[LessEqual[J, 1.55e-249], (-U$95$m), 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)\\
\mathbf{if}\;J \leq 1.55 \cdot 10^{-249}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;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. Split input into 2 regimes
  2. if J < 1.54999999999999993e-249

    1. Initial program 70.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. Simplified87.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 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 1.54999999999999993e-249 < J

    1. Initial program 83.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. Simplified95.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
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 50.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 1.2 \cdot 10^{-247}:\\
\;\;\;\;-U\_m\\

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


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

    1. Initial program 70.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. Simplified87.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 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 1.20000000000000005e-247 < J

    1. Initial program 83.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. Simplified95.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. Step-by-step derivation
      1. associate-/r*95.4%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq 1.2 \cdot 10^{-247}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\left(-2 \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)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 45.1% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 5 \cdot 10^{-202}:\\ \;\;\;\;-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 5e-202)
   (- 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 <= 5e-202) {
		tmp = -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 <= 5e-202) {
		tmp = -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 <= 5e-202:
		tmp = -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 <= 5e-202)
		tmp = Float64(-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 <= 5e-202)
		tmp = -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, 5e-202], (-U$95$m), 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 5 \cdot 10^{-202}:\\
\;\;\;\;-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 < 4.99999999999999973e-202

    1. Initial program 69.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. Simplified87.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 0 26.0%

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

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

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

    if 4.99999999999999973e-202 < J

    1. Initial program 86.9%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified96.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 K around 0 82.9%

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

Alternative 6: 65.2% accurate, 3.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 4.8 \cdot 10^{-118}:\\
\;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\

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

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


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

    1. Initial program 81.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. Simplified93.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 0 60.2%

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

    if 4.8000000000000003e-118 < U < 1.65999999999999996e224

    1. Initial program 67.3%

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\sqrt{1 + \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)}}} \]
      8. unpow267.3%

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

      \[\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. Step-by-step derivation
      1. add-sqr-sqrt75.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right)} \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{J \cdot 2}}{1}\right) \]
    9. Step-by-step derivation
      1. *-commutative73.2%

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

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

    if 1.65999999999999996e224 < U

    1. Initial program 34.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. Simplified50.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 36.4%

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

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

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

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

Alternative 7: 65.1% accurate, 3.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 1.4 \cdot 10^{-119}:\\
\;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\

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

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


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

    1. Initial program 81.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. Simplified93.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 0 60.2%

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

    if 1.4e-119 < U < 1.65999999999999996e224

    1. Initial program 67.3%

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\sqrt{1 + \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)}}} \]
      8. unpow267.3%

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

      \[\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. Step-by-step derivation
      1. add-sqr-sqrt75.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{hypot}\left(1, \color{blue}{U \cdot \frac{0.5}{J}}\right) \cdot \left(J \cdot {\left(\sqrt[3]{-2}\right)}^{3}\right) \]
      15. rem-cube-cbrt73.1%

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

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

    if 1.65999999999999996e224 < U

    1. Initial program 34.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. Simplified50.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 36.4%

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

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

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

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

Alternative 8: 39.8% accurate, 3.7× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.60000000000000014e-10 < J

    1. Initial program 96.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.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 0 86.1%

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

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

Alternative 9: 40.3% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 8.8 \cdot 10^{-11}:\\
\;\;\;\;-U\_m\\

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


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

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

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

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

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

    if 8.8000000000000006e-11 < J

    1. Initial program 96.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.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 0 86.1%

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

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

Alternative 10: 25.9% accurate, 210.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 Float64(-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 75.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. Simplified91.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 20.3%

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

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

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

Alternative 11: 27.4% accurate, 420.0× speedup?

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

\\
U\_m
\end{array}
Derivation
  1. Initial program 75.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. Simplified91.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 30.9%

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

Reproduce

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