Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.5% → 98.4%
Time: 13.1s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 73.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.4% 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^{+291}:\\ \;\;\;\;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+291) 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+291) {
		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+291) {
		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+291:
		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+291)
		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+291)
		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+291], 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^{+291}:\\
\;\;\;\;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 6.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. Simplified56.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 41.1%

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

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

      \[\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))))) < 9.9999999999999996e290

    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 9.9999999999999996e290 < (*.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.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. Simplified44.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 37.8%

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

    \[\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^{+291}:\\ \;\;\;\;\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: 85.2% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 1.56 \cdot 10^{+206}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{J} \cdot \frac{0.5}{\cos \left(K \cdot 0.5\right)}\right)\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.56e+206)
   (*
    J
    (*
     (* -2.0 (cos (/ K 2.0)))
     (hypot 1.0 (* (/ U_m J) (/ 0.5 (cos (* K 0.5)))))))
   (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 1.56e+206) {
		tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, ((U_m / J) * (0.5 / cos((K * 0.5))))));
	} 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.56e+206) {
		tmp = J * ((-2.0 * Math.cos((K / 2.0))) * Math.hypot(1.0, ((U_m / J) * (0.5 / Math.cos((K * 0.5))))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 1.56e+206:
		tmp = J * ((-2.0 * math.cos((K / 2.0))) * math.hypot(1.0, ((U_m / J) * (0.5 / math.cos((K * 0.5))))))
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 1.56e+206)
		tmp = Float64(J * Float64(Float64(-2.0 * cos(Float64(K / 2.0))) * hypot(1.0, Float64(Float64(U_m / J) * Float64(0.5 / cos(Float64(K * 0.5)))))));
	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.56e+206)
		tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, ((U_m / J) * (0.5 / cos((K * 0.5))))));
	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.56e+206], 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 / J), $MachinePrecision] * N[(0.5 / N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

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

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


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

    1. Initial program 78.0%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Simplified89.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. Step-by-step derivation
      1. div-inv89.3%

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

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

        \[\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 \frac{0.5}{\cos \left(\frac{K}{2}\right)}}\right)\right) \]
      4. div-inv89.3%

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

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

      \[\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 \frac{0.5}{\cos \left(K \cdot 0.5\right)}}\right)\right) \]

    if 1.5599999999999999e206 < U

    1. Initial program 50.2%

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

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

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

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

Alternative 3: 62.9% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 2.1000000000000001e-4

    1. Initial program 74.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. Simplified86.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 K around 0 43.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{1}{\frac{\color{blue}{-2 \cdot \left(\sqrt{J} \cdot \sqrt{J}\right)}}{U}}\right) \]
      20. add-sqr-sqrt67.0%

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

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

    if 2.1000000000000001e-4 < K

    1. Initial program 82.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. Simplified90.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 U around 0 59.4%

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

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

        \[\leadsto J \cdot \left(-2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(K \cdot 0.5\right)\right)\right)}\right) \]
    6. Applied egg-rr59.5%

      \[\leadsto J \cdot \left(-2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(K \cdot 0.5\right)\right)\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 63.0% accurate, 3.6× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 0.00185:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{1}{\frac{-2 \cdot J}{U\_m}}\right)\\ \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 (<= K 0.00185)
   (* (* -2.0 J) (hypot 1.0 (/ 1.0 (/ (* -2.0 J) 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 (K <= 0.00185) {
		tmp = (-2.0 * J) * hypot(1.0, (1.0 / ((-2.0 * J) / U_m)));
	} else {
		tmp = 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 (K <= 0.00185) {
		tmp = (-2.0 * J) * Math.hypot(1.0, (1.0 / ((-2.0 * J) / 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 K <= 0.00185:
		tmp = (-2.0 * J) * math.hypot(1.0, (1.0 / ((-2.0 * J) / 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 (K <= 0.00185)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(1.0 / Float64(Float64(-2.0 * J) / 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 (K <= 0.00185)
		tmp = (-2.0 * J) * hypot(1.0, (1.0 / ((-2.0 * J) / 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[K, 0.00185], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(1.0 / N[(N[(-2.0 * J), $MachinePrecision] / U$95$m), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $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}\;K \leq 0.00185:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{1}{\frac{-2 \cdot J}{U\_m}}\right)\\

\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 K < 0.0018500000000000001

    1. Initial program 74.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. Simplified86.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 K around 0 43.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{1}{\frac{\color{blue}{-2 \cdot \left(\sqrt{J} \cdot \sqrt{J}\right)}}{U}}\right) \]
      20. add-sqr-sqrt67.0%

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

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

    if 0.0018500000000000001 < K

    1. Initial program 82.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. Simplified90.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 U around 0 59.4%

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

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

Alternative 5: 63.0% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 0.00036:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\\ \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 (<= K 0.00036)
   (* (* -2.0 J) (hypot 1.0 (* U_m (/ 0.5 J))))
   (* J (* -2.0 (cos (* K 0.5))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (K <= 0.00036) {
		tmp = (-2.0 * J) * hypot(1.0, (U_m * (0.5 / J)));
	} else {
		tmp = 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 (K <= 0.00036) {
		tmp = (-2.0 * J) * Math.hypot(1.0, (U_m * (0.5 / J)));
	} 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 K <= 0.00036:
		tmp = (-2.0 * J) * math.hypot(1.0, (U_m * (0.5 / J)))
	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 (K <= 0.00036)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(U_m * Float64(0.5 / J))));
	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 (K <= 0.00036)
		tmp = (-2.0 * J) * hypot(1.0, (U_m * (0.5 / J)));
	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[K, 0.00036], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $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}\;K \leq 0.00036:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, U\_m \cdot \frac{0.5}{J}\right)\\

\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 K < 3.60000000000000023e-4

    1. Initial program 74.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. Simplified86.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 K around 0 43.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.60000000000000023e-4 < K

    1. Initial program 82.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. Simplified90.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 U around 0 59.4%

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

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

Alternative 6: 59.0% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 6.7 \cdot 10^{+75}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 6.7e+75) (* J (* -2.0 (cos (* K 0.5)))) (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 6.7e+75) {
		tmp = J * (-2.0 * cos((K * 0.5)));
	} 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 <= 6.7d+75) then
        tmp = j * ((-2.0d0) * cos((k * 0.5d0)))
    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 <= 6.7e+75) {
		tmp = J * (-2.0 * Math.cos((K * 0.5)));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if U_m <= 6.7e+75:
		tmp = J * (-2.0 * math.cos((K * 0.5)))
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 6.7e+75)
		tmp = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))));
	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 <= 6.7e+75)
		tmp = J * (-2.0 * cos((K * 0.5)));
	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, 6.7e+75], N[(J * N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

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

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


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

    1. Initial program 79.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. Simplified90.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 U around 0 62.0%

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

    if 6.7000000000000001e75 < U

    1. Initial program 57.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. Simplified71.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 47.5%

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

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

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

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

Alternative 7: 39.8% accurate, 52.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 7 \cdot 10^{+75}:\\ \;\;\;\;-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 7e+75) (* -2.0 J) (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 7e+75) {
		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 <= 7d+75) 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 <= 7e+75) {
		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 <= 7e+75:
		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 <= 7e+75)
		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 <= 7e+75)
		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, 7e+75], N[(-2.0 * J), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 7 \cdot 10^{+75}:\\
\;\;\;\;-2 \cdot J\\

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


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

    1. Initial program 79.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. Simplified90.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 U around 0 62.0%

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

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

    if 6.9999999999999997e75 < U

    1. Initial program 57.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. Simplified71.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 47.5%

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

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

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

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

Alternative 8: 26.2% accurate, 59.9× speedup?

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

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

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


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

    1. Initial program 75.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. Simplified87.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 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 1.60000000000000006e122 < K

    1. Initial program 84.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 U around -inf 24.4%

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

Alternative 9: 27.3% 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 76.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. Simplified87.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 U around -inf 25.4%

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

Reproduce

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