Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.2% → 99.6%
Time: 14.2s
Alternatives: 8
Speedup: 0.4×

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 8 alternatives:

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

Initial Program: 73.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.4× 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}}\\ t_2 := J \cdot t\_0\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;-U\_m\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+305}:\\ \;\;\;\;-2 \cdot \left(t\_2 \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{t\_2}\right)\right)\\ \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)))))
        (t_2 (* J t_0)))
   (if (<= t_1 (- INFINITY))
     (- U_m)
     (if (<= t_1 5e+305)
       (* -2.0 (* t_2 (hypot 1.0 (/ (/ U_m 2.0) t_2))))
       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 t_2 = J * t_0;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -U_m;
	} else if (t_1 <= 5e+305) {
		tmp = -2.0 * (t_2 * hypot(1.0, ((U_m / 2.0) / t_2)));
	} 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 t_2 = J * t_0;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = -U_m;
	} else if (t_1 <= 5e+305) {
		tmp = -2.0 * (t_2 * Math.hypot(1.0, ((U_m / 2.0) / t_2)));
	} 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)))
	t_2 = J * t_0
	tmp = 0
	if t_1 <= -math.inf:
		tmp = -U_m
	elif t_1 <= 5e+305:
		tmp = -2.0 * (t_2 * math.hypot(1.0, ((U_m / 2.0) / t_2)))
	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))))
	t_2 = Float64(J * t_0)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-U_m);
	elseif (t_1 <= 5e+305)
		tmp = Float64(-2.0 * Float64(t_2 * hypot(1.0, Float64(Float64(U_m / 2.0) / t_2))));
	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)));
	t_2 = J * t_0;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = -U_m;
	elseif (t_1 <= 5e+305)
		tmp = -2.0 * (t_2 * hypot(1.0, ((U_m / 2.0) / t_2)));
	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]}, Block[{t$95$2 = N[(J * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 5e+305], N[(-2.0 * N[(t$95$2 * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / t$95$2), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}}\\
t_2 := J \cdot t\_0\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;-U\_m\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;-2 \cdot \left(t\_2 \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{t\_2}\right)\right)\\

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

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

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

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

      \[\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)))) < 5.00000000000000009e305

    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. Step-by-step derivation
      1. unpow299.8%

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

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

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

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

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

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

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

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

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

    1. Initial program 7.9%

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

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

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.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 5 \cdot 10^{+305}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 41.6% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;J \leq 1.5 \cdot 10^{-95}:\\
\;\;\;\;-U\_m\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot t\_0\right) + -0.25 \cdot \left(\frac{U\_m}{t\_0} \cdot \frac{U\_m}{J}\right)\\


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

    1. Initial program 64.8%

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

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

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

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

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

    if 1.5e-95 < J

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

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + -0.25 \cdot \frac{U \cdot U}{\color{blue}{\cos \left(0.5 \cdot K\right) \cdot J}} \]
      3. times-frac71.4%

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + -0.25 \cdot \color{blue}{\left(\frac{U}{\cos \left(0.5 \cdot K\right)} \cdot \frac{U}{J}\right)} \]
      4. *-commutative71.4%

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + -0.25 \cdot \left(\frac{U}{\cos \color{blue}{\left(K \cdot 0.5\right)}} \cdot \frac{U}{J}\right) \]
    6. Applied egg-rr71.4%

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

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

Alternative 3: 41.4% accurate, 3.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right) + -0.25 \cdot \left(U\_m \cdot \frac{U\_m}{J}\right)\\


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

    1. Initial program 64.8%

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

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

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

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

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

    if 1.7499999999999999e-95 < J

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

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

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

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

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

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

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + \frac{\color{blue}{U \cdot U}}{J} \cdot -0.25 \]
      2. *-un-lft-identity63.5%

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

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

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

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

Alternative 4: 41.3% accurate, 3.7× speedup?

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

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

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


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

    1. Initial program 64.8%

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

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

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

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

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

    if 1.8999999999999999e-95 < J

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

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

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

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

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

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

Alternative 5: 40.4% accurate, 26.2× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 5.4 \cdot 10^{-45}:\\ \;\;\;\;-2 \cdot J + -0.25 \cdot \frac{U\_m \cdot U\_m}{J}\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 5.4e-45) (+ (* -2.0 J) (* -0.25 (/ (* U_m U_m) J))) (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 5.4e-45) {
		tmp = (-2.0 * J) + (-0.25 * ((U_m * U_m) / 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 <= 5.4d-45) then
        tmp = ((-2.0d0) * j) + ((-0.25d0) * ((u_m * u_m) / 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 <= 5.4e-45) {
		tmp = (-2.0 * J) + (-0.25 * ((U_m * 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 <= 5.4e-45:
		tmp = (-2.0 * J) + (-0.25 * ((U_m * 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 <= 5.4e-45)
		tmp = Float64(Float64(-2.0 * J) + Float64(-0.25 * Float64(Float64(U_m * 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 <= 5.4e-45)
		tmp = (-2.0 * J) + (-0.25 * ((U_m * 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, 5.4e-45], N[(N[(-2.0 * J), $MachinePrecision] + N[(-0.25 * N[(N[(U$95$m * U$95$m), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

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

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


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

    1. Initial program 77.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. Simplified77.3%

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

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

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

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

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

      \[\leadsto -2 \cdot \color{blue}{J} + \frac{{U}^{2}}{J} \cdot -0.25 \]
    9. Step-by-step derivation
      1. unpow234.5%

        \[\leadsto -2 \cdot J + \frac{\color{blue}{U \cdot U}}{J} \cdot -0.25 \]
    10. Applied egg-rr34.5%

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

    if 5.3999999999999997e-45 < U

    1. Initial program 59.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. Simplified59.8%

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

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

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

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

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

Alternative 6: 27.4% accurate, 34.9× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 4.7 \cdot 10^{+61} \lor \neg \left(K \leq 4.4 \cdot 10^{+169}\right):\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= K 4.7e+61) (not (<= K 4.4e+169))) (- U_m) U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((K <= 4.7e+61) || !(K <= 4.4e+169)) {
		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 <= 4.7d+61) .or. (.not. (k <= 4.4d+169))) 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 <= 4.7e+61) || !(K <= 4.4e+169)) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (K <= 4.7e+61) or not (K <= 4.4e+169):
		tmp = -U_m
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((K <= 4.7e+61) || !(K <= 4.4e+169))
		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 <= 4.7e+61) || ~((K <= 4.4e+169)))
		tmp = -U_m;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[K, 4.7e+61], N[Not[LessEqual[K, 4.4e+169]], $MachinePrecision]], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 4.7 \cdot 10^{+61} \lor \neg \left(K \leq 4.4 \cdot 10^{+169}\right):\\
\;\;\;\;-U\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 4.6999999999999998e61 or 4.4e169 < K

    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. Simplified73.1%

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

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

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

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

    if 4.6999999999999998e61 < K < 4.4e169

    1. Initial program 65.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. Simplified65.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 4.7 \cdot 10^{+61} \lor \neg \left(K \leq 4.4 \cdot 10^{+169}\right):\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 40.4% accurate, 52.4× speedup?

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

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

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


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

    1. Initial program 77.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. Simplified77.3%

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

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

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

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

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

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

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

    if 1.9500000000000001e-44 < U

    1. Initial program 59.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. Simplified59.8%

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

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

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

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

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

Alternative 8: 25.7% 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 72.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. Simplified72.6%

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

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

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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