Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.6% → 99.5%
Time: 21.5s
Alternatives: 9
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 73.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 6.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. Simplified50.4%

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

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

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

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

    if -inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < 4.9999999999999997e304

    1. Initial program 99.8%

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

    if 4.9999999999999997e304 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64)))))

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

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

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

    \[\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^{+304}:\\ \;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot 2\right)}\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;U\_m \leq 6.4 \cdot 10^{+198}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J \cdot t\_0}\right)\right)\\

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


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

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

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

    if 6.3999999999999997e198 < U

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

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

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

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

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

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

Alternative 3: 70.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J}\right)\right)\\
\mathbf{if}\;U\_m \leq 1.8 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;U\_m \leq 1.15 \cdot 10^{+82}:\\
\;\;\;\;\frac{J \cdot U\_m}{-J}\\

\mathbf{elif}\;U\_m \leq 1.2 \cdot 10^{+184}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 1.8e35 or 1.14999999999999994e82 < U < 1.19999999999999998e184

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

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

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

    if 1.8e35 < U < 1.14999999999999994e82

    1. Initial program 72.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. Simplified99.8%

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

      \[\leadsto J \cdot \color{blue}{\left(-1 \cdot \frac{U}{J}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/29.4%

        \[\leadsto J \cdot \color{blue}{\frac{-1 \cdot U}{J}} \]
      2. neg-mul-129.4%

        \[\leadsto J \cdot \frac{\color{blue}{-U}}{J} \]
    6. Simplified29.4%

      \[\leadsto J \cdot \color{blue}{\frac{-U}{J}} \]
    7. Step-by-step derivation
      1. distribute-frac-neg29.4%

        \[\leadsto J \cdot \color{blue}{\left(-\frac{U}{J}\right)} \]
      2. distribute-frac-neg229.4%

        \[\leadsto J \cdot \color{blue}{\frac{U}{-J}} \]
      3. associate-*r/29.2%

        \[\leadsto \color{blue}{\frac{J \cdot U}{-J}} \]
    8. Applied egg-rr29.2%

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

    if 1.19999999999999998e184 < U

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.8 \cdot 10^{+35}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U}{2}}{J}\right)\right)\\ \mathbf{elif}\;U \leq 1.15 \cdot 10^{+82}:\\ \;\;\;\;\frac{J \cdot U}{-J}\\ \mathbf{elif}\;U \leq 1.2 \cdot 10^{+184}:\\ \;\;\;\;J \cdot \left(\left(-2 \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 4: 71.0% accurate, 1.8× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 1.8 \cdot 10^{+35}:\\ \;\;\;\;\left(-2 \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J}\right)\right)\\ \mathbf{elif}\;U\_m \leq 1.2 \cdot 10^{+75}:\\ \;\;\;\;\frac{J \cdot U\_m}{-J}\\ \mathbf{elif}\;U\_m \leq 1.08 \cdot 10^{+184}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{2}}{J}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (<= U_m 1.8e+35)
   (* (* -2.0 (cos (* K 0.5))) (* J (hypot 1.0 (* 0.5 (/ U_m J)))))
   (if (<= U_m 1.2e+75)
     (/ (* J U_m) (- J))
     (if (<= U_m 1.08e+184)
       (* J (* (* -2.0 (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 <= 1.8e+35) {
		tmp = (-2.0 * cos((K * 0.5))) * (J * hypot(1.0, (0.5 * (U_m / J))));
	} else if (U_m <= 1.2e+75) {
		tmp = (J * U_m) / -J;
	} else if (U_m <= 1.08e+184) {
		tmp = J * ((-2.0 * 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 <= 1.8e+35) {
		tmp = (-2.0 * Math.cos((K * 0.5))) * (J * Math.hypot(1.0, (0.5 * (U_m / J))));
	} else if (U_m <= 1.2e+75) {
		tmp = (J * U_m) / -J;
	} else if (U_m <= 1.08e+184) {
		tmp = J * ((-2.0 * 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 <= 1.8e+35:
		tmp = (-2.0 * math.cos((K * 0.5))) * (J * math.hypot(1.0, (0.5 * (U_m / J))))
	elif U_m <= 1.2e+75:
		tmp = (J * U_m) / -J
	elif U_m <= 1.08e+184:
		tmp = J * ((-2.0 * 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 <= 1.8e+35)
		tmp = Float64(Float64(-2.0 * cos(Float64(K * 0.5))) * Float64(J * hypot(1.0, Float64(0.5 * Float64(U_m / J)))));
	elseif (U_m <= 1.2e+75)
		tmp = Float64(Float64(J * U_m) / Float64(-J));
	elseif (U_m <= 1.08e+184)
		tmp = Float64(J * Float64(Float64(-2.0 * 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 <= 1.8e+35)
		tmp = (-2.0 * cos((K * 0.5))) * (J * hypot(1.0, (0.5 * (U_m / J))));
	elseif (U_m <= 1.2e+75)
		tmp = (J * U_m) / -J;
	elseif (U_m <= 1.08e+184)
		tmp = J * ((-2.0 * 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, 1.8e+35], N[(N[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(J * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 1.2e+75], N[(N[(J * U$95$m), $MachinePrecision] / (-J)), $MachinePrecision], If[LessEqual[U$95$m, 1.08e+184], N[(J * N[(N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / 2.0), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]]]
\begin{array}{l}
U_m = \left|U\right|

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

\mathbf{elif}\;U\_m \leq 1.2 \cdot 10^{+75}:\\
\;\;\;\;\frac{J \cdot U\_m}{-J}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if U < 1.8e35

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.8e35 < U < 1.2e75

    1. Initial program 72.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. Simplified99.8%

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

      \[\leadsto J \cdot \color{blue}{\left(-1 \cdot \frac{U}{J}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/29.4%

        \[\leadsto J \cdot \color{blue}{\frac{-1 \cdot U}{J}} \]
      2. neg-mul-129.4%

        \[\leadsto J \cdot \frac{\color{blue}{-U}}{J} \]
    6. Simplified29.4%

      \[\leadsto J \cdot \color{blue}{\frac{-U}{J}} \]
    7. Step-by-step derivation
      1. distribute-frac-neg29.4%

        \[\leadsto J \cdot \color{blue}{\left(-\frac{U}{J}\right)} \]
      2. distribute-frac-neg229.4%

        \[\leadsto J \cdot \color{blue}{\frac{U}{-J}} \]
      3. associate-*r/29.2%

        \[\leadsto \color{blue}{\frac{J \cdot U}{-J}} \]
    8. Applied egg-rr29.2%

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

    if 1.2e75 < U < 1.07999999999999993e184

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

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

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

    if 1.07999999999999993e184 < U

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 1.8 \cdot 10^{+35}:\\ \;\;\;\;\left(-2 \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U}{J}\right)\right)\\ \mathbf{elif}\;U \leq 1.2 \cdot 10^{+75}:\\ \;\;\;\;\frac{J \cdot U}{-J}\\ \mathbf{elif}\;U \leq 1.08 \cdot 10^{+184}:\\ \;\;\;\;J \cdot \left(\left(-2 \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: 63.3% accurate, 3.2× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J}\right)\right)\\ t_1 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;U\_m \leq 4.5 \cdot 10^{-139}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;U\_m \leq 7.8 \cdot 10^{-115}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;U\_m \leq 22000000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;U\_m \leq 1.4 \cdot 10^{+180}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (* -2.0 (* J (hypot 1.0 (* 0.5 (/ U_m J))))))
        (t_1 (* (* -2.0 J) (cos (* K 0.5)))))
   (if (<= U_m 4.5e-139)
     t_1
     (if (<= U_m 7.8e-115)
       t_0
       (if (<= U_m 22000000000.0) t_1 (if (<= U_m 1.4e+180) t_0 (- U_m)))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = -2.0 * (J * hypot(1.0, (0.5 * (U_m / J))));
	double t_1 = (-2.0 * J) * cos((K * 0.5));
	double tmp;
	if (U_m <= 4.5e-139) {
		tmp = t_1;
	} else if (U_m <= 7.8e-115) {
		tmp = t_0;
	} else if (U_m <= 22000000000.0) {
		tmp = t_1;
	} else if (U_m <= 1.4e+180) {
		tmp = t_0;
	} 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 = -2.0 * (J * Math.hypot(1.0, (0.5 * (U_m / J))));
	double t_1 = (-2.0 * J) * Math.cos((K * 0.5));
	double tmp;
	if (U_m <= 4.5e-139) {
		tmp = t_1;
	} else if (U_m <= 7.8e-115) {
		tmp = t_0;
	} else if (U_m <= 22000000000.0) {
		tmp = t_1;
	} else if (U_m <= 1.4e+180) {
		tmp = t_0;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = -2.0 * (J * math.hypot(1.0, (0.5 * (U_m / J))))
	t_1 = (-2.0 * J) * math.cos((K * 0.5))
	tmp = 0
	if U_m <= 4.5e-139:
		tmp = t_1
	elif U_m <= 7.8e-115:
		tmp = t_0
	elif U_m <= 22000000000.0:
		tmp = t_1
	elif U_m <= 1.4e+180:
		tmp = t_0
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = Float64(-2.0 * Float64(J * hypot(1.0, Float64(0.5 * Float64(U_m / J)))))
	t_1 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (U_m <= 4.5e-139)
		tmp = t_1;
	elseif (U_m <= 7.8e-115)
		tmp = t_0;
	elseif (U_m <= 22000000000.0)
		tmp = t_1;
	elseif (U_m <= 1.4e+180)
		tmp = t_0;
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = -2.0 * (J * hypot(1.0, (0.5 * (U_m / J))));
	t_1 = (-2.0 * J) * cos((K * 0.5));
	tmp = 0.0;
	if (U_m <= 4.5e-139)
		tmp = t_1;
	elseif (U_m <= 7.8e-115)
		tmp = t_0;
	elseif (U_m <= 22000000000.0)
		tmp = t_1;
	elseif (U_m <= 1.4e+180)
		tmp = t_0;
	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[(-2.0 * N[(J * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[U$95$m, 4.5e-139], t$95$1, If[LessEqual[U$95$m, 7.8e-115], t$95$0, If[LessEqual[U$95$m, 22000000000.0], t$95$1, If[LessEqual[U$95$m, 1.4e+180], t$95$0, (-U$95$m)]]]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := -2 \cdot \left(J \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J}\right)\right)\\
t_1 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;U\_m \leq 4.5 \cdot 10^{-139}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;U\_m \leq 7.8 \cdot 10^{-115}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;U\_m \leq 22000000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;U\_m \leq 1.4 \cdot 10^{+180}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 4.50000000000000023e-139 or 7.7999999999999997e-115 < U < 2.2e10

    1. Initial program 83.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. Simplified92.6%

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

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

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

        \[\leadsto \color{blue}{\left(J \cdot -2\right)} \cdot \cos \left(0.5 \cdot K\right) \]
      3. *-commutative65.5%

        \[\leadsto \left(J \cdot -2\right) \cdot \cos \color{blue}{\left(K \cdot 0.5\right)} \]
      4. *-commutative65.5%

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

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

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

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

    if 4.50000000000000023e-139 < U < 7.7999999999999997e-115 or 2.2e10 < U < 1.40000000000000006e180

    1. Initial program 62.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. Simplified85.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.40000000000000006e180 < U

    1. Initial program 37.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. Simplified61.9%

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

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

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

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

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

Alternative 6: 56.8% accurate, 3.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{if}\;U\_m \leq 1.65 \cdot 10^{+27}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;U\_m \leq 10^{+121}:\\ \;\;\;\;\frac{J \cdot U\_m}{-J}\\ \mathbf{elif}\;U\_m \leq 9 \cdot 10^{+158}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (let* ((t_0 (* (* -2.0 J) (cos (* K 0.5)))))
   (if (<= U_m 1.65e+27)
     t_0
     (if (<= U_m 1e+121)
       (/ (* J U_m) (- J))
       (if (<= U_m 9e+158) t_0 (- U_m))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = (-2.0 * J) * cos((K * 0.5));
	double tmp;
	if (U_m <= 1.65e+27) {
		tmp = t_0;
	} else if (U_m <= 1e+121) {
		tmp = (J * U_m) / -J;
	} else if (U_m <= 9e+158) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((-2.0d0) * j) * cos((k * 0.5d0))
    if (u_m <= 1.65d+27) then
        tmp = t_0
    else if (u_m <= 1d+121) then
        tmp = (j * u_m) / -j
    else if (u_m <= 9d+158) then
        tmp = t_0
    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 t_0 = (-2.0 * J) * Math.cos((K * 0.5));
	double tmp;
	if (U_m <= 1.65e+27) {
		tmp = t_0;
	} else if (U_m <= 1e+121) {
		tmp = (J * U_m) / -J;
	} else if (U_m <= 9e+158) {
		tmp = t_0;
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = (-2.0 * J) * math.cos((K * 0.5))
	tmp = 0
	if U_m <= 1.65e+27:
		tmp = t_0
	elif U_m <= 1e+121:
		tmp = (J * U_m) / -J
	elif U_m <= 9e+158:
		tmp = t_0
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5)))
	tmp = 0.0
	if (U_m <= 1.65e+27)
		tmp = t_0;
	elseif (U_m <= 1e+121)
		tmp = Float64(Float64(J * U_m) / Float64(-J));
	elseif (U_m <= 9e+158)
		tmp = t_0;
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = (-2.0 * J) * cos((K * 0.5));
	tmp = 0.0;
	if (U_m <= 1.65e+27)
		tmp = t_0;
	elseif (U_m <= 1e+121)
		tmp = (J * U_m) / -J;
	elseif (U_m <= 9e+158)
		tmp = t_0;
	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[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[U$95$m, 1.65e+27], t$95$0, If[LessEqual[U$95$m, 1e+121], N[(N[(J * U$95$m), $MachinePrecision] / (-J)), $MachinePrecision], If[LessEqual[U$95$m, 9e+158], t$95$0, (-U$95$m)]]]]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;U\_m \leq 1.65 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;U\_m \leq 10^{+121}:\\
\;\;\;\;\frac{J \cdot U\_m}{-J}\\

\mathbf{elif}\;U\_m \leq 9 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 1.6499999999999999e27 or 1.00000000000000004e121 < U < 9.00000000000000092e158

    1. Initial program 82.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. Simplified92.2%

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

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

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

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

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

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

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

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

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

    if 1.6499999999999999e27 < U < 1.00000000000000004e121

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

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

      \[\leadsto J \cdot \color{blue}{\left(-1 \cdot \frac{U}{J}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/23.2%

        \[\leadsto J \cdot \color{blue}{\frac{-1 \cdot U}{J}} \]
      2. neg-mul-123.2%

        \[\leadsto J \cdot \frac{\color{blue}{-U}}{J} \]
    6. Simplified23.2%

      \[\leadsto J \cdot \color{blue}{\frac{-U}{J}} \]
    7. Step-by-step derivation
      1. distribute-frac-neg23.2%

        \[\leadsto J \cdot \color{blue}{\left(-\frac{U}{J}\right)} \]
      2. distribute-frac-neg223.2%

        \[\leadsto J \cdot \color{blue}{\frac{U}{-J}} \]
      3. associate-*r/28.2%

        \[\leadsto \color{blue}{\frac{J \cdot U}{-J}} \]
    8. Applied egg-rr28.2%

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

    if 9.00000000000000092e158 < U

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

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

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

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

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

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

Alternative 7: 39.8% accurate, 52.4× speedup?

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

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


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

    1. Initial program 83.1%

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

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

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

      \[\leadsto {\color{blue}{\left(\sqrt[3]{J \cdot \cos \left(0.5 \cdot K\right)} \cdot \sqrt[3]{-2}\right)}}^{3} \]
    6. Taylor expanded in K around 0 38.3%

      \[\leadsto \color{blue}{J \cdot {\left(\sqrt[3]{-2}\right)}^{3}} \]
    7. Step-by-step derivation
      1. rem-cube-cbrt39.5%

        \[\leadsto J \cdot \color{blue}{-2} \]
    8. Simplified39.5%

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

    if 1.7000000000000001e26 < U

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

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

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

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

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

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

Alternative 8: 26.6% accurate, 210.0× speedup?

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

\\
-U\_m
\end{array}
Derivation
  1. Initial program 74.1%

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

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

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

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

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

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

Alternative 9: 26.6% 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 74.1%

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification25.2%

    \[\leadsto U \]
  6. Add Preprocessing

Reproduce

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