Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 72.2% → 99.1%
Time: 26.3s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 72.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.1% accurate, 0.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := \left(\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 4 \cdot 10^{+298}:\\ \;\;\;\;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 4e+298) 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 <= 4e+298) {
		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 <= 4e+298) {
		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 <= 4e+298:
		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 <= 4e+298)
		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 <= 4e+298)
		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, 4e+298], 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 4 \cdot 10^{+298}:\\
\;\;\;\;t\_1\\

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


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

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

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

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

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

      \[\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)))) < 3.9999999999999998e298

    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 3.9999999999999998e298 < (*.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 6.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. Simplified62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.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 4 \cdot 10^{+298}:\\ \;\;\;\;\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: 63.3% accurate, 0.8× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \left(1 + \left(\frac{U\_m}{J} \cdot \frac{U\_m}{J}\right) \cdot 0.125\right)\right)\\ \mathbf{if}\;t\_0 \leq -0.48:\\ \;\;\;\;U\_m\\ \mathbf{elif}\;t\_0 \leq 0.03:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 0.36:\\ \;\;\;\;-U\_m\\ \mathbf{elif}\;t\_0 \leq 0.75:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m \cdot 0.5}{J}\right)\\ \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 (* J (* (* -2.0 t_0) (+ 1.0 (* (* (/ U_m J) (/ U_m J)) 0.125))))))
   (if (<= t_0 -0.48)
     U_m
     (if (<= t_0 0.03)
       t_1
       (if (<= t_0 0.36)
         (- U_m)
         (if (<= t_0 0.75)
           t_1
           (* (* -2.0 J) (hypot 1.0 (/ (* U_m 0.5) J)))))))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double t_0 = cos((K / 2.0));
	double t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.48) {
		tmp = U_m;
	} else if (t_0 <= 0.03) {
		tmp = t_1;
	} else if (t_0 <= 0.36) {
		tmp = -U_m;
	} else if (t_0 <= 0.75) {
		tmp = t_1;
	} else {
		tmp = (-2.0 * J) * hypot(1.0, ((U_m * 0.5) / J));
	}
	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 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	double tmp;
	if (t_0 <= -0.48) {
		tmp = U_m;
	} else if (t_0 <= 0.03) {
		tmp = t_1;
	} else if (t_0 <= 0.36) {
		tmp = -U_m;
	} else if (t_0 <= 0.75) {
		tmp = t_1;
	} else {
		tmp = (-2.0 * J) * Math.hypot(1.0, ((U_m * 0.5) / J));
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	t_0 = math.cos((K / 2.0))
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)))
	tmp = 0
	if t_0 <= -0.48:
		tmp = U_m
	elif t_0 <= 0.03:
		tmp = t_1
	elif t_0 <= 0.36:
		tmp = -U_m
	elif t_0 <= 0.75:
		tmp = t_1
	else:
		tmp = (-2.0 * J) * math.hypot(1.0, ((U_m * 0.5) / J))
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(J * Float64(Float64(-2.0 * t_0) * Float64(1.0 + Float64(Float64(Float64(U_m / J) * Float64(U_m / J)) * 0.125))))
	tmp = 0.0
	if (t_0 <= -0.48)
		tmp = U_m;
	elseif (t_0 <= 0.03)
		tmp = t_1;
	elseif (t_0 <= 0.36)
		tmp = Float64(-U_m);
	elseif (t_0 <= 0.75)
		tmp = t_1;
	else
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U_m * 0.5) / J)));
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	t_1 = J * ((-2.0 * t_0) * (1.0 + (((U_m / J) * (U_m / J)) * 0.125)));
	tmp = 0.0;
	if (t_0 <= -0.48)
		tmp = U_m;
	elseif (t_0 <= 0.03)
		tmp = t_1;
	elseif (t_0 <= 0.36)
		tmp = -U_m;
	elseif (t_0 <= 0.75)
		tmp = t_1;
	else
		tmp = (-2.0 * J) * hypot(1.0, ((U_m * 0.5) / J));
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[(1.0 + N[(N[(N[(U$95$m / J), $MachinePrecision] * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.48], U$95$m, If[LessEqual[t$95$0, 0.03], t$95$1, If[LessEqual[t$95$0, 0.36], (-U$95$m), If[LessEqual[t$95$0, 0.75], t$95$1, N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
U_m = \left|U\right|

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

\mathbf{elif}\;t\_0 \leq 0.03:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 0.36:\\
\;\;\;\;-U\_m\\

\mathbf{elif}\;t\_0 \leq 0.75:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.47999999999999998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.47999999999999998 < (cos.f64 (/.f64 K 2)) < 0.029999999999999999 or 0.35999999999999999 < (cos.f64 (/.f64 K 2)) < 0.75

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

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right)\right) \]
    5. Step-by-step derivation
      1. *-commutative71.5%

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

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(1 + 0.125 \cdot \frac{{U}^{2}}{{J}^{2}}\right)}\right) \]
    8. Step-by-step derivation
      1. *-commutative57.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\frac{{U}^{2}}{{J}^{2}} \cdot 0.125}\right)\right) \]
    9. Simplified57.9%

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(1 + \frac{{U}^{2}}{{J}^{2}} \cdot 0.125\right)}\right) \]
    10. Step-by-step derivation
      1. unpow257.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \frac{\color{blue}{U \cdot U}}{{J}^{2}} \cdot 0.125\right)\right) \]
      2. unpow257.9%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \frac{U \cdot U}{\color{blue}{J \cdot J}} \cdot 0.125\right)\right) \]
      3. frac-times69.6%

        \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(1 + \color{blue}{\left(\frac{U}{J} \cdot \frac{U}{J}\right)} \cdot 0.125\right)\right) \]
    11. Applied egg-rr69.6%

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

    if 0.029999999999999999 < (cos.f64 (/.f64 K 2)) < 0.35999999999999999

    1. Initial program 52.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. Simplified89.9%

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

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

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

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

    if 0.75 < (cos.f64 (/.f64 K 2))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}} \]
      2. metadata-eval50.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. unpow250.3%

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

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

        \[\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)}} \]
      6. swap-sqr68.0%

        \[\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)}} \]
      7. unpow268.0%

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

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

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

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

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

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

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

Alternative 3: 63.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\
\mathbf{if}\;t\_0 \leq -0.48:\\
\;\;\;\;U\_m\\

\mathbf{elif}\;t\_0 \leq 0.03:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 0.36:\\
\;\;\;\;-U\_m\\

\mathbf{elif}\;t\_0 \leq 0.75:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.47999999999999998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.47999999999999998 < (cos.f64 (/.f64 K 2)) < 0.029999999999999999 or 0.35999999999999999 < (cos.f64 (/.f64 K 2)) < 0.75

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

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

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

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

        \[\leadsto \left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot -2 \]
      3. metadata-eval68.4%

        \[\leadsto \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \color{blue}{\left(-2\right)} \]
      4. distribute-rgt-neg-in68.4%

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

        \[\leadsto -\color{blue}{J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 2\right)} \]
      6. distribute-rgt-neg-in68.4%

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

        \[\leadsto J \cdot \left(-\color{blue}{2 \cdot \cos \left(K \cdot 0.5\right)}\right) \]
      8. distribute-lft-neg-in68.4%

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

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

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

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

    if 0.029999999999999999 < (cos.f64 (/.f64 K 2)) < 0.35999999999999999

    1. Initial program 52.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. Simplified89.9%

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

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

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

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

    if 0.75 < (cos.f64 (/.f64 K 2))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}} \]
      2. metadata-eval50.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. unpow250.3%

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

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

        \[\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)}} \]
      6. swap-sqr68.0%

        \[\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)}} \]
      7. unpow268.0%

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

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

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

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

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

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

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

Alternative 4: 70.9% accurate, 1.3× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 220000000000:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{J \cdot 2}\right)\right)\\ \mathbf{elif}\;U\_m \leq 2.1 \cdot 10^{+170}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m \cdot 0.5}{J}\right)\\ \mathbf{elif}\;U\_m \leq 3.6 \cdot 10^{+186}:\\ \;\;\;\;J \cdot \left(1 + \mathsf{fma}\left(-2, \cos \left(K \cdot 0.5\right) \cdot \mathsf{hypot}\left(1, 0.5 \cdot \frac{U\_m}{J}\right), -1\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 220000000000.0)
   (* J (* (* -2.0 (cos (/ K 2.0))) (hypot 1.0 (/ U_m (* J 2.0)))))
   (if (<= U_m 2.1e+170)
     (* (* -2.0 J) (hypot 1.0 (/ (* U_m 0.5) J)))
     (if (<= U_m 3.6e+186)
       (*
        J
        (+
         1.0
         (fma -2.0 (* (cos (* K 0.5)) (hypot 1.0 (* 0.5 (/ U_m J)))) -1.0)))
       (- U_m)))))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if (U_m <= 220000000000.0) {
		tmp = J * ((-2.0 * cos((K / 2.0))) * hypot(1.0, (U_m / (J * 2.0))));
	} else if (U_m <= 2.1e+170) {
		tmp = (-2.0 * J) * hypot(1.0, ((U_m * 0.5) / J));
	} else if (U_m <= 3.6e+186) {
		tmp = J * (1.0 + fma(-2.0, (cos((K * 0.5)) * hypot(1.0, (0.5 * (U_m / J)))), -1.0));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if (U_m <= 220000000000.0)
		tmp = Float64(J * Float64(Float64(-2.0 * cos(Float64(K / 2.0))) * hypot(1.0, Float64(U_m / Float64(J * 2.0)))));
	elseif (U_m <= 2.1e+170)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U_m * 0.5) / J)));
	elseif (U_m <= 3.6e+186)
		tmp = Float64(J * Float64(1.0 + fma(-2.0, Float64(cos(Float64(K * 0.5)) * hypot(1.0, Float64(0.5 * Float64(U_m / J)))), -1.0)));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[LessEqual[U$95$m, 220000000000.0], N[(J * N[(N[(-2.0 * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 2.1e+170], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 3.6e+186], N[(J * N[(1.0 + N[(-2.0 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(0.5 * N[(U$95$m / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-U$95$m)]]]
\begin{array}{l}
U_m = \left|U\right|

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

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

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

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


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

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

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right)\right) \]
    5. Step-by-step derivation
      1. *-commutative75.1%

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

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

    if 2.2e11 < U < 2.09999999999999998e170

    1. Initial program 60.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}} \]
      6. swap-sqr55.3%

        \[\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)}} \]
      7. unpow255.3%

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

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

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

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

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

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

    if 2.09999999999999998e170 < U < 3.6000000000000002e186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000002e186 < U

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

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

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

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

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

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

Alternative 5: 85.9% 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 1.95 \cdot 10^{+247}:\\ \;\;\;\;-2 \cdot \left(J \cdot \left(t\_0 \cdot \mathsf{hypot}\left(1, \frac{U\_m}{t\_0} \cdot \frac{0.5}{J}\right)\right)\right)\\ \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 1.95e+247)
     (* -2.0 (* J (* t_0 (hypot 1.0 (* (/ U_m t_0) (/ 0.5 J))))))
     (- 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 <= 1.95e+247) {
		tmp = -2.0 * (J * (t_0 * hypot(1.0, ((U_m / t_0) * (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 t_0 = Math.cos((K / 2.0));
	double tmp;
	if (U_m <= 1.95e+247) {
		tmp = -2.0 * (J * (t_0 * Math.hypot(1.0, ((U_m / t_0) * (0.5 / J)))));
	} 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 <= 1.95e+247:
		tmp = -2.0 * (J * (t_0 * math.hypot(1.0, ((U_m / t_0) * (0.5 / J)))))
	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 <= 1.95e+247)
		tmp = Float64(-2.0 * Float64(J * Float64(t_0 * hypot(1.0, Float64(Float64(U_m / t_0) * 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)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (U_m <= 1.95e+247)
		tmp = -2.0 * (J * (t_0 * hypot(1.0, ((U_m / t_0) * (0.5 / J)))));
	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, 1.95e+247], N[(-2.0 * N[(J * N[(t$95$0 * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / t$95$0), $MachinePrecision] * N[(0.5 / J), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-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 1.95 \cdot 10^{+247}:\\
\;\;\;\;-2 \cdot \left(J \cdot \left(t\_0 \cdot \mathsf{hypot}\left(1, \frac{U\_m}{t\_0} \cdot \frac{0.5}{J}\right)\right)\right)\\

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


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

    1. Initial program 74.3%

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

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

    if 1.95000000000000001e247 < U

    1. Initial program 32.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. Simplified54.8%

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

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

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

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

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

Alternative 6: 85.9% 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.6 \cdot 10^{+247}:\\ \;\;\;\;-2 \cdot \left(\left(J \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{J \cdot 2}}{t\_0}\right)\right)\\ \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.6e+247)
     (* -2.0 (* (* J t_0) (hypot 1.0 (/ (/ U_m (* J 2.0)) 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.6e+247) {
		tmp = -2.0 * ((J * t_0) * hypot(1.0, ((U_m / (J * 2.0)) / 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.6e+247) {
		tmp = -2.0 * ((J * t_0) * Math.hypot(1.0, ((U_m / (J * 2.0)) / 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.6e+247:
		tmp = -2.0 * ((J * t_0) * math.hypot(1.0, ((U_m / (J * 2.0)) / 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.6e+247)
		tmp = Float64(-2.0 * Float64(Float64(J * t_0) * hypot(1.0, Float64(Float64(U_m / Float64(J * 2.0)) / 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.6e+247)
		tmp = -2.0 * ((J * t_0) * hypot(1.0, ((U_m / (J * 2.0)) / 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.6e+247], N[(-2.0 * N[(N[(J * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-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.6 \cdot 10^{+247}:\\
\;\;\;\;-2 \cdot \left(\left(J \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{\frac{U\_m}{J \cdot 2}}{t\_0}\right)\right)\\

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


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

    1. Initial program 74.3%

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

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

    if 6.60000000000000003e247 < U

    1. Initial program 32.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. Simplified54.8%

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

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

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

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

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

Alternative 7: 85.9% 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 5.8 \cdot 10^{+246}:\\ \;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{t\_0 \cdot \left(J \cdot 2\right)}\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 5.8e+246)
     (* J (* (* -2.0 t_0) (hypot 1.0 (/ U_m (* t_0 (* J 2.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 <= 5.8e+246) {
		tmp = J * ((-2.0 * t_0) * hypot(1.0, (U_m / (t_0 * (J * 2.0)))));
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (U_m <= 5.8e+246) {
		tmp = J * ((-2.0 * t_0) * Math.hypot(1.0, (U_m / (t_0 * (J * 2.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 <= 5.8e+246:
		tmp = J * ((-2.0 * t_0) * math.hypot(1.0, (U_m / (t_0 * (J * 2.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 <= 5.8e+246)
		tmp = Float64(J * Float64(Float64(-2.0 * t_0) * hypot(1.0, Float64(U_m / Float64(t_0 * Float64(J * 2.0))))));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (U_m <= 5.8e+246)
		tmp = J * ((-2.0 * t_0) * hypot(1.0, (U_m / (t_0 * (J * 2.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, 5.8e+246], N[(J * N[(N[(-2.0 * t$95$0), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(U$95$m / N[(t$95$0 * N[(J * 2.0), $MachinePrecision]), $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 5.8 \cdot 10^{+246}:\\
\;\;\;\;J \cdot \left(\left(-2 \cdot t\_0\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m}{t\_0 \cdot \left(J \cdot 2\right)}\right)\right)\\

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


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

    1. Initial program 74.3%

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

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

    if 5.80000000000000028e246 < U

    1. Initial program 32.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. Simplified54.8%

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

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

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

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

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

Alternative 8: 71.0% 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{U\_m}{J \cdot 2}\right)\right)\\ \mathbf{if}\;U\_m \leq 4.6 \cdot 10^{+14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;U\_m \leq 1.3 \cdot 10^{+171}:\\ \;\;\;\;\left(-2 \cdot J\right) \cdot \mathsf{hypot}\left(1, \frac{U\_m \cdot 0.5}{J}\right)\\ \mathbf{elif}\;U\_m \leq 3.8 \cdot 10^{+186}:\\ \;\;\;\;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 (* J 2.0)))))))
   (if (<= U_m 4.6e+14)
     t_0
     (if (<= U_m 1.3e+171)
       (* (* -2.0 J) (hypot 1.0 (/ (* U_m 0.5) J)))
       (if (<= U_m 3.8e+186) 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 / (J * 2.0))));
	double tmp;
	if (U_m <= 4.6e+14) {
		tmp = t_0;
	} else if (U_m <= 1.3e+171) {
		tmp = (-2.0 * J) * hypot(1.0, ((U_m * 0.5) / J));
	} else if (U_m <= 3.8e+186) {
		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 / (J * 2.0))));
	double tmp;
	if (U_m <= 4.6e+14) {
		tmp = t_0;
	} else if (U_m <= 1.3e+171) {
		tmp = (-2.0 * J) * Math.hypot(1.0, ((U_m * 0.5) / J));
	} else if (U_m <= 3.8e+186) {
		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 / (J * 2.0))))
	tmp = 0
	if U_m <= 4.6e+14:
		tmp = t_0
	elif U_m <= 1.3e+171:
		tmp = (-2.0 * J) * math.hypot(1.0, ((U_m * 0.5) / J))
	elif U_m <= 3.8e+186:
		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(U_m / Float64(J * 2.0)))))
	tmp = 0.0
	if (U_m <= 4.6e+14)
		tmp = t_0;
	elseif (U_m <= 1.3e+171)
		tmp = Float64(Float64(-2.0 * J) * hypot(1.0, Float64(Float64(U_m * 0.5) / J)));
	elseif (U_m <= 3.8e+186)
		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 / (J * 2.0))));
	tmp = 0.0;
	if (U_m <= 4.6e+14)
		tmp = t_0;
	elseif (U_m <= 1.3e+171)
		tmp = (-2.0 * J) * hypot(1.0, ((U_m * 0.5) / J));
	elseif (U_m <= 3.8e+186)
		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[(U$95$m / N[(J * 2.0), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[U$95$m, 4.6e+14], t$95$0, If[LessEqual[U$95$m, 1.3e+171], N[(N[(-2.0 * J), $MachinePrecision] * N[Sqrt[1.0 ^ 2 + N[(N[(U$95$m * 0.5), $MachinePrecision] / J), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[U$95$m, 3.8e+186], 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{U\_m}{J \cdot 2}\right)\right)\\
\mathbf{if}\;U\_m \leq 4.6 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 4.6e14 or 1.3e171 < U < 3.7999999999999998e186

    1. Initial program 77.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. Simplified89.4%

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

      \[\leadsto J \cdot \left(\left(-2 \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \mathsf{hypot}\left(1, \frac{U}{\color{blue}{2 \cdot J}}\right)\right) \]
    5. Step-by-step derivation
      1. *-commutative75.2%

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

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

    if 4.6e14 < U < 1.3e171

    1. Initial program 60.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}} \]
      6. swap-sqr55.3%

        \[\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)}} \]
      7. unpow255.3%

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

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

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

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

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

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

    if 3.7999999999999998e186 < U

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

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

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

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

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

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

Alternative 9: 56.6% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 0.0036 \lor \neg \left(U\_m \leq 6.9 \cdot 10^{+171}\right) \land U\_m \leq 3.6 \cdot 10^{+186}:\\
\;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 0.0035999999999999999 or 6.90000000000000009e171 < U < 3.6000000000000002e186

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

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

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

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

        \[\leadsto \left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot -2 \]
      3. metadata-eval61.7%

        \[\leadsto \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \color{blue}{\left(-2\right)} \]
      4. distribute-rgt-neg-in61.7%

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

        \[\leadsto -\color{blue}{J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 2\right)} \]
      6. distribute-rgt-neg-in61.7%

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

        \[\leadsto J \cdot \left(-\color{blue}{2 \cdot \cos \left(K \cdot 0.5\right)}\right) \]
      8. distribute-lft-neg-in61.7%

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

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

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

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

    if 0.0035999999999999999 < U < 6.90000000000000009e171 or 3.6000000000000002e186 < U

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 0.0036 \lor \neg \left(U \leq 6.9 \cdot 10^{+171}\right) \land U \leq 3.6 \cdot 10^{+186}:\\ \;\;\;\;J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 56.6% accurate, 3.4× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} t_0 := J \cdot \left(-2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;U\_m \leq 0.0031:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;U\_m \leq 6.6 \cdot 10^{+171}:\\ \;\;\;\;\frac{-2 \cdot {J}^{2}}{U\_m} - U\_m\\ \mathbf{elif}\;U\_m \leq 3.6 \cdot 10^{+186}:\\ \;\;\;\;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 0.5))))))
   (if (<= U_m 0.0031)
     t_0
     (if (<= U_m 6.6e+171)
       (- (/ (* -2.0 (pow J 2.0)) U_m) U_m)
       (if (<= U_m 3.6e+186) 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 * 0.5)));
	double tmp;
	if (U_m <= 0.0031) {
		tmp = t_0;
	} else if (U_m <= 6.6e+171) {
		tmp = ((-2.0 * pow(J, 2.0)) / U_m) - U_m;
	} else if (U_m <= 3.6e+186) {
		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 = j * ((-2.0d0) * cos((k * 0.5d0)))
    if (u_m <= 0.0031d0) then
        tmp = t_0
    else if (u_m <= 6.6d+171) then
        tmp = (((-2.0d0) * (j ** 2.0d0)) / u_m) - u_m
    else if (u_m <= 3.6d+186) 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 = J * (-2.0 * Math.cos((K * 0.5)));
	double tmp;
	if (U_m <= 0.0031) {
		tmp = t_0;
	} else if (U_m <= 6.6e+171) {
		tmp = ((-2.0 * Math.pow(J, 2.0)) / U_m) - U_m;
	} else if (U_m <= 3.6e+186) {
		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 * 0.5)))
	tmp = 0
	if U_m <= 0.0031:
		tmp = t_0
	elif U_m <= 6.6e+171:
		tmp = ((-2.0 * math.pow(J, 2.0)) / U_m) - U_m
	elif U_m <= 3.6e+186:
		tmp = t_0
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	t_0 = Float64(J * Float64(-2.0 * cos(Float64(K * 0.5))))
	tmp = 0.0
	if (U_m <= 0.0031)
		tmp = t_0;
	elseif (U_m <= 6.6e+171)
		tmp = Float64(Float64(Float64(-2.0 * (J ^ 2.0)) / U_m) - U_m);
	elseif (U_m <= 3.6e+186)
		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 * 0.5)));
	tmp = 0.0;
	if (U_m <= 0.0031)
		tmp = t_0;
	elseif (U_m <= 6.6e+171)
		tmp = ((-2.0 * (J ^ 2.0)) / U_m) - U_m;
	elseif (U_m <= 3.6e+186)
		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[(-2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[U$95$m, 0.0031], t$95$0, If[LessEqual[U$95$m, 6.6e+171], N[(N[(N[(-2.0 * N[Power[J, 2.0], $MachinePrecision]), $MachinePrecision] / U$95$m), $MachinePrecision] - U$95$m), $MachinePrecision], If[LessEqual[U$95$m, 3.6e+186], t$95$0, (-U$95$m)]]]]
\begin{array}{l}
U_m = \left|U\right|

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if U < 0.00309999999999999989 or 6.59999999999999982e171 < U < 3.6000000000000002e186

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

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

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

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

        \[\leadsto \left(J \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right) \cdot -2 \]
      3. metadata-eval61.7%

        \[\leadsto \left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \color{blue}{\left(-2\right)} \]
      4. distribute-rgt-neg-in61.7%

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

        \[\leadsto -\color{blue}{J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 2\right)} \]
      6. distribute-rgt-neg-in61.7%

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

        \[\leadsto J \cdot \left(-\color{blue}{2 \cdot \cos \left(K \cdot 0.5\right)}\right) \]
      8. distribute-lft-neg-in61.7%

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

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

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

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

    if 0.00309999999999999989 < U < 6.59999999999999982e171

    1. Initial program 63.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-2 \cdot \frac{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}{U} - U} \]
      3. associate-*r/17.2%

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

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

        \[\leadsto \frac{-2 \cdot \left(\color{blue}{\left(J \cdot J\right)} \cdot {\cos \left(K \cdot 0.5\right)}^{2}\right)}{U} - U \]
      6. unpow217.2%

        \[\leadsto \frac{-2 \cdot \left(\left(J \cdot J\right) \cdot \color{blue}{\left(\cos \left(K \cdot 0.5\right) \cdot \cos \left(K \cdot 0.5\right)\right)}\right)}{U} - U \]
      7. swap-sqr17.2%

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

        \[\leadsto \frac{-2 \cdot \color{blue}{{\left(J \cdot \cos \left(K \cdot 0.5\right)\right)}^{2}}}{U} - U \]
    10. Simplified17.2%

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

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

    if 3.6000000000000002e186 < U

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

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

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

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

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

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

Alternative 11: 30.1% accurate, 19.0× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;U\_m \leq 10^{-99} \lor \neg \left(U\_m \leq 3.6 \cdot 10^{-53}\right) \land U\_m \leq 3.8 \cdot 10^{-38}:\\ \;\;\;\;J \cdot \left(\frac{U\_m}{J} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;-U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= U_m 1e-99) (and (not (<= U_m 3.6e-53)) (<= U_m 3.8e-38)))
   (* J (+ (/ U_m J) -1.0))
   (- U_m)))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((U_m <= 1e-99) || (!(U_m <= 3.6e-53) && (U_m <= 3.8e-38))) {
		tmp = J * ((U_m / J) + -1.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) :: tmp
    if ((u_m <= 1d-99) .or. (.not. (u_m <= 3.6d-53)) .and. (u_m <= 3.8d-38)) then
        tmp = j * ((u_m / j) + (-1.0d0))
    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 <= 1e-99) || (!(U_m <= 3.6e-53) && (U_m <= 3.8e-38))) {
		tmp = J * ((U_m / J) + -1.0);
	} else {
		tmp = -U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (U_m <= 1e-99) or (not (U_m <= 3.6e-53) and (U_m <= 3.8e-38)):
		tmp = J * ((U_m / J) + -1.0)
	else:
		tmp = -U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((U_m <= 1e-99) || (!(U_m <= 3.6e-53) && (U_m <= 3.8e-38)))
		tmp = Float64(J * Float64(Float64(U_m / J) + -1.0));
	else
		tmp = Float64(-U_m);
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((U_m <= 1e-99) || (~((U_m <= 3.6e-53)) && (U_m <= 3.8e-38)))
		tmp = J * ((U_m / J) + -1.0);
	else
		tmp = -U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[U$95$m, 1e-99], And[N[Not[LessEqual[U$95$m, 3.6e-53]], $MachinePrecision], LessEqual[U$95$m, 3.8e-38]]], N[(J * N[(N[(U$95$m / J), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], (-U$95$m)]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 10^{-99} \lor \neg \left(U\_m \leq 3.6 \cdot 10^{-53}\right) \land U\_m \leq 3.8 \cdot 10^{-38}:\\
\;\;\;\;J \cdot \left(\frac{U\_m}{J} + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 1e-99 or 3.5999999999999999e-53 < U < 3.8e-38

    1. Initial program 74.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. Simplified86.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-99 < U < 3.5999999999999999e-53 or 3.8e-38 < U

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 10^{-99} \lor \neg \left(U \leq 3.6 \cdot 10^{-53}\right) \land U \leq 3.8 \cdot 10^{-38}:\\ \;\;\;\;J \cdot \left(\frac{U}{J} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 26.4% accurate, 24.6× speedup?

\[\begin{array}{l} U_m = \left|U\right| \\ \begin{array}{l} \mathbf{if}\;K \leq 4.5 \cdot 10^{+74} \lor \neg \left(K \leq 6.4 \cdot 10^{+199}\right) \land K \leq 7 \cdot 10^{+224}:\\ \;\;\;\;-U\_m\\ \mathbf{else}:\\ \;\;\;\;U\_m\\ \end{array} \end{array} \]
U_m = (fabs.f64 U)
(FPCore (J K U_m)
 :precision binary64
 (if (or (<= K 4.5e+74) (and (not (<= K 6.4e+199)) (<= K 7e+224)))
   (- U_m)
   U_m))
U_m = fabs(U);
double code(double J, double K, double U_m) {
	double tmp;
	if ((K <= 4.5e+74) || (!(K <= 6.4e+199) && (K <= 7e+224))) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = abs(U)
real(8) function code(j, k, u_m)
    real(8), intent (in) :: j
    real(8), intent (in) :: k
    real(8), intent (in) :: u_m
    real(8) :: tmp
    if ((k <= 4.5d+74) .or. (.not. (k <= 6.4d+199)) .and. (k <= 7d+224)) then
        tmp = -u_m
    else
        tmp = u_m
    end if
    code = tmp
end function
U_m = Math.abs(U);
public static double code(double J, double K, double U_m) {
	double tmp;
	if ((K <= 4.5e+74) || (!(K <= 6.4e+199) && (K <= 7e+224))) {
		tmp = -U_m;
	} else {
		tmp = U_m;
	}
	return tmp;
}
U_m = math.fabs(U)
def code(J, K, U_m):
	tmp = 0
	if (K <= 4.5e+74) or (not (K <= 6.4e+199) and (K <= 7e+224)):
		tmp = -U_m
	else:
		tmp = U_m
	return tmp
U_m = abs(U)
function code(J, K, U_m)
	tmp = 0.0
	if ((K <= 4.5e+74) || (!(K <= 6.4e+199) && (K <= 7e+224)))
		tmp = Float64(-U_m);
	else
		tmp = U_m;
	end
	return tmp
end
U_m = abs(U);
function tmp_2 = code(J, K, U_m)
	tmp = 0.0;
	if ((K <= 4.5e+74) || (~((K <= 6.4e+199)) && (K <= 7e+224)))
		tmp = -U_m;
	else
		tmp = U_m;
	end
	tmp_2 = tmp;
end
U_m = N[Abs[U], $MachinePrecision]
code[J_, K_, U$95$m_] := If[Or[LessEqual[K, 4.5e+74], And[N[Not[LessEqual[K, 6.4e+199]], $MachinePrecision], LessEqual[K, 7e+224]]], (-U$95$m), U$95$m]
\begin{array}{l}
U_m = \left|U\right|

\\
\begin{array}{l}
\mathbf{if}\;K \leq 4.5 \cdot 10^{+74} \lor \neg \left(K \leq 6.4 \cdot 10^{+199}\right) \land K \leq 7 \cdot 10^{+224}:\\
\;\;\;\;-U\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 4.5e74 or 6.40000000000000011e199 < K < 7e224

    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. Simplified86.9%

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

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

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

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

    if 4.5e74 < K < 6.40000000000000011e199 or 7e224 < K

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 4.5 \cdot 10^{+74} \lor \neg \left(K \leq 6.4 \cdot 10^{+199}\right) \land K \leq 7 \cdot 10^{+224}:\\ \;\;\;\;-U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 31.1% accurate, 35.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;U\_m \leq 2.25 \cdot 10^{+17}:\\
\;\;\;\;J \cdot \left(-1 - \frac{U\_m}{J}\right)\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\color{blue}{\frac{-1 \cdot U}{J}} - 1\right) \]
      2. mul-1-neg18.7%

        \[\leadsto J \cdot \left(\frac{\color{blue}{-U}}{J} - 1\right) \]
    12. Simplified18.7%

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

    if 2.25e17 < U

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 2.25 \cdot 10^{+17}:\\ \;\;\;\;J \cdot \left(-1 - \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;-U\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 26.9% accurate, 420.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  9. Final simplification31.9%

    \[\leadsto U \]
  10. Add Preprocessing

Reproduce

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