Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.2% → 99.5%
Time: 16.3s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 73.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.5% 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(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}}\\ t_2 := J \cdot t_0\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-U_m\\ \mathbf{elif}\;t_1 \leq 2 \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
         (*
          (* t_0 (* -2.0 J))
          (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 2e+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 = (t_0 * (-2.0 * J)) * 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 <= 2e+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 = (t_0 * (-2.0 * J)) * 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 <= 2e+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 = (t_0 * (-2.0 * J)) * 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 <= 2e+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(t_0 * Float64(-2.0 * J)) * 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 <= 2e+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 = (t_0 * (-2.0 * J)) * 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 <= 2e+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[(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]}, Block[{t$95$2 = N[(J * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-U$95$m), If[LessEqual[t$95$1, 2e+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(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}}\\
t_2 := J \cdot t_0\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-U_m\\

\mathbf{elif}\;t_1 \leq 2 \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 5.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. Simplified5.4%

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

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

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

      \[\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.9999999999999999e305

    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. 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}} \]
      2. 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. unpow299.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow299.8%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\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 1.9999999999999999e305 < (*.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 5.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. Simplified5.0%

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

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

    \[\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 2 \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: 52.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 4.1 \cdot 10^{-225}:\\
\;\;\;\;-U_m\\

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


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

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

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

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

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

    if 4.10000000000000022e-225 < J

    1. Initial program 86.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. Step-by-step derivation
      1. associate-*l*86.2%

        \[\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}} \]
      2. associate-*l*86.2%

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

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg86.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg86.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg86.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow286.2%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\right) \]
    3. Simplified92.7%

      \[\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
    5. Step-by-step derivation
      1. div-inv92.7%

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

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

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

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

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

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

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

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

Alternative 3: 71.0% accurate, 1.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;-U_m\\


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

    1. Initial program 77.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. Step-by-step derivation
      1. associate-*l*77.2%

        \[\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}} \]
      2. associate-*l*77.2%

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

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow277.2%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\right) \]
    3. Simplified92.0%

      \[\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
    5. Step-by-step derivation
      1. div-inv92.0%

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

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

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

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

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

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

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

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

    if 5.79999999999999974e97 < U

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

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

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

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

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

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

Alternative 4: 71.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U_m \leq 7.5 \cdot 10^{+97}:\\
\;\;\;\;-2 \cdot \left(\left(J \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U_m}{2}}{J}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-U_m\\


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

    1. Initial program 77.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. Step-by-step derivation
      1. associate-*l*77.2%

        \[\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}} \]
      2. associate-*l*77.2%

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

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg77.2%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow277.2%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\right) \]
    3. Simplified92.0%

      \[\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
    5. Taylor expanded in K around 0 77.8%

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

    if 7.5000000000000004e97 < U

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

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

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

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

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

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

Alternative 5: 41.5% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 4.2 \cdot 10^{-130}:\\
\;\;\;\;-U_m\\

\mathbf{elif}\;J \leq 10^{-16}:\\
\;\;\;\;-2 \cdot \left(J \cdot \mathsf{hypot}\left(1, U_m \cdot \frac{-0.5}{J}\right)\right)\\

\mathbf{elif}\;J \leq 1.85 \cdot 10^{-14}:\\
\;\;\;\;-U_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if J < 4.20000000000000004e-130 or 9.9999999999999998e-17 < J < 1.85000000000000001e-14

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

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

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

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

    if 4.20000000000000004e-130 < J < 9.9999999999999998e-17

    1. Initial program 71.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. Step-by-step derivation
      1. associate-*l*71.9%

        \[\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}} \]
      2. associate-*l*71.9%

        \[\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. unpow271.9%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg71.9%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg71.9%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg71.9%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow271.9%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\right) \]
    3. Simplified90.9%

      \[\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
    5. Step-by-step derivation
      1. add-cbrt-cube66.8%

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

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

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

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

      \[\leadsto -2 \cdot \left(\mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J \cdot \cos \left(\frac{K}{2}\right)}\right) \cdot \color{blue}{\sqrt[3]{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{3}}}\right) \]
    7. Step-by-step derivation
      1. rem-cbrt-cube90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.85000000000000001e-14 < J

    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. 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}} \]
      2. 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. unpow299.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg99.8%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow299.8%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\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
    5. Taylor expanded in U around 0 86.3%

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

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

Alternative 6: 40.8% accurate, 3.7× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;J \leq 5.2 \cdot 10^{-51}:\\ \;\;\;\;-U_m\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= J 5.2e-51) (- 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 <= 5.2e-51) {
		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 <= 5.2d-51) 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 <= 5.2e-51) {
		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 <= 5.2e-51:
		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 <= 5.2e-51)
		tmp = Float64(-U_m);
	else
		tmp = Float64(-2.0 * Float64(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 <= 5.2e-51)
		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, 5.2e-51], (-U$95$m), N[(-2.0 * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;J \leq 5.2 \cdot 10^{-51}:\\
\;\;\;\;-U_m\\

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


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

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

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

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

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

    if 5.2e-51 < J

    1. Initial program 97.1%

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

        \[\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}} \]
      2. associate-*l*97.1%

        \[\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. unpow297.1%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      4. sqr-neg97.1%

        \[\leadsto -2 \cdot \left(\left(J \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)}}\right) \]
      5. distribute-frac-neg97.1%

        \[\leadsto -2 \cdot \left(\left(J \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)}\right) \]
      6. distribute-frac-neg97.1%

        \[\leadsto -2 \cdot \left(\left(J \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)}}}\right) \]
      7. unpow297.1%

        \[\leadsto -2 \cdot \left(\left(J \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}}}\right) \]
    3. Simplified98.5%

      \[\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
    5. Taylor expanded in U around 0 82.1%

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

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

Alternative 7: 31.8% accurate, 43.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq 3 \cdot 10^{-13}:\\
\;\;\;\;-U_m\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot J\\


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

    1. Initial program 64.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. Simplified64.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 30.7%

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

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

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

    if 2.99999999999999984e-13 < J

    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. Simplified99.7%

      \[\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 K around 0 48.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \sqrt{1 + {\left(0.5 \cdot \frac{U}{J}\right)}^{2}}} \]
    7. Taylor expanded in J around inf 47.2%

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

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

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

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

Alternative 8: 26.8% accurate, 109.5× speedup?

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

\\
-U_m
\end{array}
Derivation
  1. Initial program 72.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. Simplified72.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 25.8%

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

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

    \[\leadsto \color{blue}{-U} \]
  7. Final simplification25.8%

    \[\leadsto -U \]
  8. Add Preprocessing

Alternative 9: 26.5% accurate, 438.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.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. Simplified72.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 U around -inf 26.1%

    \[\leadsto \color{blue}{U} \]
  5. Final simplification26.1%

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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