Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 72.6% → 99.1%
Time: 32.3s
Alternatives: 10
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 10 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: 72.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.1% accurate, 0.3× speedup?

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

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

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

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


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

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

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

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

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

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

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

Alternative 2: 88.2% accurate, 1.3× speedup?

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

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

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

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

Alternative 3: 88.3% accurate, 1.3× speedup?

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

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

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

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

Alternative 4: 68.2% accurate, 1.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 8 \cdot 10^{+66}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{J \cdot 2}\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 8e+66)
   (* J (* (* -2.0 (cos (/ K 2.0))) (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 <= 8e+66) {
		tmp = J * ((-2.0 * cos((K / 2.0))) * 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 <= 8e+66) {
		tmp = J * ((-2.0 * Math.cos((K / 2.0))) * 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 <= 8e+66:
		tmp = J * ((-2.0 * math.cos((K / 2.0))) * 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 <= 8e+66)
		tmp = Float64(J * Float64(Float64(-2.0 * cos(Float64(K / 2.0))) * 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 <= 8e+66)
		tmp = J * ((-2.0 * cos((K / 2.0))) * 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, 8e+66], 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[(J * 2.0), $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 8 \cdot 10^{+66}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{J \cdot 2}\right)\right)\\

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


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

    1. Initial program 73.5%

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

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right)\right) \]
    5. Step-by-step derivation
      1. *-commutative76.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 2}}\right)\right) \]
    6. Simplified76.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 2}}\right)\right) \]

    if 7.99999999999999956e66 < U

    1. Initial program 50.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. Simplified80.0%

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

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

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

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

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

Alternative 5: 60.5% accurate, 3.5× speedup?

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

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

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


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

    1. Initial program 73.5%

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

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

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

    if 1.74999999999999987e-70 < U < 7.99999999999999956e66

    1. Initial program 73.5%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. expm1-log1p-u34.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.99999999999999956e66 < U

    1. Initial program 50.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. Simplified80.0%

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

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

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

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

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

Alternative 6: 57.2% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 9.6 \cdot 10^{+32}:\\ \;\;\;\;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 9.6e+32) (* 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 <= 9.6e+32) {
		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 <= 9.6d+32) 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 <= 9.6e+32) {
		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 <= 9.6e+32:
		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 <= 9.6e+32)
		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 <= 9.6e+32)
		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, 9.6e+32], 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 9.6 \cdot 10^{+32}:\\
\;\;\;\;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 < 9.59999999999999965e32

    1. Initial program 74.1%

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

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

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

    if 9.59999999999999965e32 < U

    1. Initial program 50.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. Simplified80.3%

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

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

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

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

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

Alternative 7: 38.7% accurate, 52.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 4.2999999999999997e-71

    1. Initial program 73.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.2999999999999997e-71 < U

    1. Initial program 56.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. Simplified84.2%

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

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

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

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

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

Alternative 8: 38.6% accurate, 52.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1.65e-87

    1. Initial program 73.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. Simplified90.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. expm1-log1p-u27.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2 \cdot J} \]
    12. Step-by-step derivation
      1. *-commutative31.3%

        \[\leadsto \color{blue}{J \cdot -2} \]
    13. Simplified31.3%

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

    if 1.65e-87 < U

    1. Initial program 58.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. Simplified84.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J + \color{blue}{\left(-U\right)} \]
    12. Simplified36.4%

      \[\leadsto J + \color{blue}{\left(-U\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification32.9%

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

Alternative 9: 26.3% accurate, 59.9× speedup?

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

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

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


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

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

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

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

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

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

    if 5.49999999999999974e40 < K

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 5.5 \cdot 10^{+40}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 27.2% 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 68.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. Simplified88.7%

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

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

    \[\leadsto \color{blue}{U} \]
  6. Final simplification30.6%

    \[\leadsto U \]
  7. Add Preprocessing

Reproduce

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