Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.6% → 99.8%
Time: 10.4s
Alternatives: 17
Speedup: 2.7×

Specification

?
\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\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 17 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: 86.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Alternative 1: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{-\ell}\\ t_2 := e^{\ell} - t\_1\\ \mathbf{if}\;t\_2 \leq -\infty:\\ \;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\ \mathbf{elif}\;t\_2 \leq 0.0005:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(t\_2 \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (exp (- l))) (t_2 (- (exp l) t_1)))
   (if (<= t_2 (- INFINITY))
     (+ (* (* J (- 27.0 t_1)) t_0) U)
     (if (<= t_2 0.0005)
       (+ U (* t_0 (* l (+ (* 0.3333333333333333 (* J (* l l))) (* J 2.0)))))
       (+ U (* t_0 (* t_2 J)))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(-l);
	double t_2 = exp(l) - t_1;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (t_2 <= 0.0005) {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else {
		tmp = U + (t_0 * (t_2 * J));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(-l);
	double t_2 = Math.exp(l) - t_1;
	double tmp;
	if (t_2 <= -Double.POSITIVE_INFINITY) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (t_2 <= 0.0005) {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else {
		tmp = U + (t_0 * (t_2 * J));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(-l)
	t_2 = math.exp(l) - t_1
	tmp = 0
	if t_2 <= -math.inf:
		tmp = ((J * (27.0 - t_1)) * t_0) + U
	elif t_2 <= 0.0005:
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))))
	else:
		tmp = U + (t_0 * (t_2 * J))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = exp(Float64(-l))
	t_2 = Float64(exp(l) - t_1)
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(J * Float64(27.0 - t_1)) * t_0) + U);
	elseif (t_2 <= 0.0005)
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * Float64(l * l))) + Float64(J * 2.0)))));
	else
		tmp = Float64(U + Float64(t_0 * Float64(t_2 * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(-l);
	t_2 = exp(l) - t_1;
	tmp = 0.0;
	if (t_2 <= -Inf)
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	elseif (t_2 <= 0.0005)
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	else
		tmp = U + (t_0 * (t_2 * J));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[l], $MachinePrecision] - t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(N[(J * N[(27.0 - t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[t$95$2, 0.0005], N[(U + N[(t$95$0 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(t$95$2 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_2 \leq 0.0005:\\
\;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(t\_2 \cdot J\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

      \[\leadsto \left(J \cdot \left(\color{blue}{27} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000001e-4

    1. Initial program 71.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.9%

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

        \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr99.9%

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

    if 5.0000000000000001e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

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

Alternative 2: 94.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(\frac{K}{2}\right)\\ t_2 := U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+77}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq -0.015:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 210:\\ \;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+93}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J)))
        (t_1 (cos (/ K 2.0)))
        (t_2 (+ U (* t_1 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l)))))))))
   (if (<= l -1.95e+77)
     t_2
     (if (<= l -0.015)
       t_0
       (if (<= l 210.0)
         (+ U (* t_1 (* l (+ (* 0.3333333333333333 (* J (* l l))) (* J 2.0)))))
         (if (<= l 2.4e+93) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((exp(l) - exp(-l)) * J);
	double t_1 = cos((K / 2.0));
	double t_2 = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	double tmp;
	if (l <= -1.95e+77) {
		tmp = t_2;
	} else if (l <= -0.015) {
		tmp = t_0;
	} else if (l <= 210.0) {
		tmp = U + (t_1 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else if (l <= 2.4e+93) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = u + ((exp(l) - exp(-l)) * j)
    t_1 = cos((k / 2.0d0))
    t_2 = u + (t_1 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
    if (l <= (-1.95d+77)) then
        tmp = t_2
    else if (l <= (-0.015d0)) then
        tmp = t_0
    else if (l <= 210.0d0) then
        tmp = u + (t_1 * (l * ((0.3333333333333333d0 * (j * (l * l))) + (j * 2.0d0))))
    else if (l <= 2.4d+93) then
        tmp = t_0
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double t_1 = Math.cos((K / 2.0));
	double t_2 = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	double tmp;
	if (l <= -1.95e+77) {
		tmp = t_2;
	} else if (l <= -0.015) {
		tmp = t_0;
	} else if (l <= 210.0) {
		tmp = U + (t_1 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else if (l <= 2.4e+93) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((math.exp(l) - math.exp(-l)) * J)
	t_1 = math.cos((K / 2.0))
	t_2 = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	tmp = 0
	if l <= -1.95e+77:
		tmp = t_2
	elif l <= -0.015:
		tmp = t_0
	elif l <= 210.0:
		tmp = U + (t_1 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))))
	elif l <= 2.4e+93:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	t_1 = cos(Float64(K / 2.0))
	t_2 = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))))
	tmp = 0.0
	if (l <= -1.95e+77)
		tmp = t_2;
	elseif (l <= -0.015)
		tmp = t_0;
	elseif (l <= 210.0)
		tmp = Float64(U + Float64(t_1 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * Float64(l * l))) + Float64(J * 2.0)))));
	elseif (l <= 2.4e+93)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((exp(l) - exp(-l)) * J);
	t_1 = cos((K / 2.0));
	t_2 = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	tmp = 0.0;
	if (l <= -1.95e+77)
		tmp = t_2;
	elseif (l <= -0.015)
		tmp = t_0;
	elseif (l <= 210.0)
		tmp = U + (t_1 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	elseif (l <= 2.4e+93)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.95e+77], t$95$2, If[LessEqual[l, -0.015], t$95$0, If[LessEqual[l, 210.0], N[(U + N[(t$95$1 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.4e+93], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
t_1 := \cos \left(\frac{K}{2}\right)\\
t_2 := U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\
\mathbf{if}\;\ell \leq -1.95 \cdot 10^{+77}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\ell \leq -0.015:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 210:\\
\;\;\;\;U + t\_1 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.9499999999999999e77 or 2.4000000000000001e93 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.1%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. unpow290.2%

        \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr99.1%

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

    if -1.9499999999999999e77 < l < -0.014999999999999999 or 210 < l < 2.4000000000000001e93

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 80.0%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]

    if -0.014999999999999999 < l < 210

    1. Initial program 71.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.1%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + 2 \cdot J\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. unpow299.1%

        \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr99.1%

      \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.95 \cdot 10^{+77}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.015:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 210:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{-\ell}\\ \mathbf{if}\;\ell \leq -4:\\ \;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\ \mathbf{elif}\;\ell \leq 210:\\ \;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - t\_1\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (exp (- l))))
   (if (<= l -4.0)
     (+ (* (* J (- 27.0 t_1)) t_0) U)
     (if (<= l 210.0)
       (+ U (* t_0 (* l (+ (* 0.3333333333333333 (* J (* l l))) (* J 2.0)))))
       (if (<= l 3.2e+93)
         (+ U (* (- (exp l) t_1) J))
         (+ U (* t_0 (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(-l);
	double tmp;
	if (l <= -4.0) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (l <= 210.0) {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else if (l <= 3.2e+93) {
		tmp = U + ((exp(l) - t_1) * J);
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(-l)
    if (l <= (-4.0d0)) then
        tmp = ((j * (27.0d0 - t_1)) * t_0) + u
    else if (l <= 210.0d0) then
        tmp = u + (t_0 * (l * ((0.3333333333333333d0 * (j * (l * l))) + (j * 2.0d0))))
    else if (l <= 3.2d+93) then
        tmp = u + ((exp(l) - t_1) * j)
    else
        tmp = u + (t_0 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(-l);
	double tmp;
	if (l <= -4.0) {
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	} else if (l <= 210.0) {
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	} else if (l <= 3.2e+93) {
		tmp = U + ((Math.exp(l) - t_1) * J);
	} else {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(-l)
	tmp = 0
	if l <= -4.0:
		tmp = ((J * (27.0 - t_1)) * t_0) + U
	elif l <= 210.0:
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))))
	elif l <= 3.2e+93:
		tmp = U + ((math.exp(l) - t_1) * J)
	else:
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = exp(Float64(-l))
	tmp = 0.0
	if (l <= -4.0)
		tmp = Float64(Float64(Float64(J * Float64(27.0 - t_1)) * t_0) + U);
	elseif (l <= 210.0)
		tmp = Float64(U + Float64(t_0 * Float64(l * Float64(Float64(0.3333333333333333 * Float64(J * Float64(l * l))) + Float64(J * 2.0)))));
	elseif (l <= 3.2e+93)
		tmp = Float64(U + Float64(Float64(exp(l) - t_1) * J));
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(-l);
	tmp = 0.0;
	if (l <= -4.0)
		tmp = ((J * (27.0 - t_1)) * t_0) + U;
	elseif (l <= 210.0)
		tmp = U + (t_0 * (l * ((0.3333333333333333 * (J * (l * l))) + (J * 2.0))));
	elseif (l <= 3.2e+93)
		tmp = U + ((exp(l) - t_1) * J);
	else
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[l, -4.0], N[(N[(N[(J * N[(27.0 - t$95$1), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 210.0], N[(U + N[(t$95$0 * N[(l * N[(N[(0.3333333333333333 * N[(J * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.2e+93], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - t$95$1), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -4:\\
\;\;\;\;\left(J \cdot \left(27 - t\_1\right)\right) \cdot t\_0 + U\\

\mathbf{elif}\;\ell \leq 210:\\
\;\;\;\;U + t\_0 \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+93}:\\
\;\;\;\;U + \left(e^{\ell} - t\_1\right) \cdot J\\

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

      \[\leadsto \left(J \cdot \left(\color{blue}{27} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -4 < l < 210

    1. Initial program 71.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.1%

      \[\leadsto \color{blue}{\left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{2}\right) + 2 \cdot J\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. unpow299.1%

        \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr99.1%

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

    if 210 < l < 3.2000000000000001e93

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 83.3%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]

    if 3.2000000000000001e93 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 100.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. unpow287.4%

        \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr100.0%

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 4 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4:\\ \;\;\;\;\left(J \cdot \left(27 - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{elif}\;\ell \leq 210:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \left(\ell \cdot \ell\right)\right) + J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+93}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 80.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.01)
   (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))
   (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.01) {
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (cos((k / 2.0d0)) <= 0.01d0) then
        tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
    else
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= 0.01) {
		tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.01:
		tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.01)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (cos((K / 2.0)) <= 0.01)
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.01], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.0100000000000000002

    1. Initial program 79.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.9%

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

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.9%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 51.6%

      \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right) + \frac{U}{\ell}\right)} \]
    7. Taylor expanded in U around inf 69.7%

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

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
      2. *-commutative74.7%

        \[\leadsto U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}}{U}\right)\right) \]
    9. Simplified74.7%

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

    if 0.0100000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 89.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 89.8%

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\ \;\;\;\;J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right) + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.01)
   (* J (+ (* 2.0 (* l (cos (* K 0.5)))) (/ U J)))
   (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.01) {
		tmp = J * ((2.0 * (l * cos((K * 0.5)))) + (U / J));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (cos((k / 2.0d0)) <= 0.01d0) then
        tmp = j * ((2.0d0 * (l * cos((k * 0.5d0)))) + (u / j))
    else
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= 0.01) {
		tmp = J * ((2.0 * (l * Math.cos((K * 0.5)))) + (U / J));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.01:
		tmp = J * ((2.0 * (l * math.cos((K * 0.5)))) + (U / J))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.01)
		tmp = Float64(J * Float64(Float64(2.0 * Float64(l * cos(Float64(K * 0.5)))) + Float64(U / J)));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (cos((K / 2.0)) <= 0.01)
		tmp = J * ((2.0 * (l * cos((K * 0.5)))) + (U / J));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.01], N[(J * N[(N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\
\;\;\;\;J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right) + \frac{U}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.0100000000000000002

    1. Initial program 79.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.9%

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

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.9%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in J around inf 68.0%

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

    if 0.0100000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 89.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 89.8%

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.9%

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

Alternative 6: 79.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.01:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.01)
     (+ U (* t_0 (* J (* l 2.0))))
     (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.01) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= 0.01d0) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.01) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.01:
		tmp = U + (t_0 * (J * (l * 2.0)))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.01)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (t_0 <= 0.01)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.01], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq 0.01:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.0100000000000000002

    1. Initial program 79.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.9%

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

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*64.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified64.9%

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

    if 0.0100000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 89.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 89.8%

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.01:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 67.6% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \left(J \cdot 2\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ t_2 := \ell \cdot \frac{U}{\ell}\\ \mathbf{if}\;\ell \leq -6.5 \cdot 10^{+136}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -1.75 \cdot 10^{+19}:\\ \;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\ \mathbf{elif}\;\ell \leq 100:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (* J 2.0)))
        (t_1 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
        (t_2 (* l (/ U l))))
   (if (<= l -6.5e+136)
     t_1
     (if (<= l -1.75e+19)
       (/ (- (* t_0 t_0) (* t_2 t_2)) (- t_0 t_2))
       (if (<= l 100.0) (+ U (* (cos (/ K 2.0)) (* J (* l 2.0)))) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -6.5e+136) {
		tmp = t_1;
	} else if (l <= -1.75e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 100.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = l * (j * 2.0d0)
    t_1 = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    t_2 = l * (u / l)
    if (l <= (-6.5d+136)) then
        tmp = t_1
    else if (l <= (-1.75d+19)) then
        tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
    else if (l <= 100.0d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -6.5e+136) {
		tmp = t_1;
	} else if (l <= -1.75e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 100.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * (J * 2.0)
	t_1 = U * (1.0 + (2.0 * (J * (l / U))))
	t_2 = l * (U / l)
	tmp = 0
	if l <= -6.5e+136:
		tmp = t_1
	elif l <= -1.75e+19:
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
	elif l <= 100.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * Float64(J * 2.0))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
	t_2 = Float64(l * Float64(U / l))
	tmp = 0.0
	if (l <= -6.5e+136)
		tmp = t_1;
	elseif (l <= -1.75e+19)
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(t_2 * t_2)) / Float64(t_0 - t_2));
	elseif (l <= 100.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = l * (J * 2.0);
	t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	t_2 = l * (U / l);
	tmp = 0.0;
	if (l <= -6.5e+136)
		tmp = t_1;
	elseif (l <= -1.75e+19)
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	elseif (l <= 100.0)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(l * N[(U / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6.5e+136], t$95$1, If[LessEqual[l, -1.75e+19], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 100.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \ell \cdot \left(J \cdot 2\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
t_2 := \ell \cdot \frac{U}{\ell}\\
\mathbf{if}\;\ell \leq -6.5 \cdot 10^{+136}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -1.75 \cdot 10^{+19}:\\
\;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\

\mathbf{elif}\;\ell \leq 100:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.4999999999999998e136 or 100 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 26.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative26.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*26.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified26.9%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 26.0%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Taylor expanded in U around inf 33.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*41.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    10. Simplified41.8%

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

    if -6.4999999999999998e136 < l < -1.75e19

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 4.7%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative4.7%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*4.7%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified4.7%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 4.7%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Step-by-step derivation
      1. distribute-lft-in3.9%

        \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J\right) + \ell \cdot \frac{U}{\ell}} \]
      2. flip-+34.6%

        \[\leadsto \color{blue}{\frac{\left(\ell \cdot \left(2 \cdot J\right)\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}}} \]
      3. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      4. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      5. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \color{blue}{\left(J \cdot 2\right)} - \ell \cdot \frac{U}{\ell}} \]
    9. Applied egg-rr34.6%

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

    if -1.75e19 < l < 100

    1. Initial program 72.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*98.0%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified98.0%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.5%

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

Alternative 8: 67.7% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \left(J \cdot 2\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ t_2 := \ell \cdot \frac{U}{\ell}\\ \mathbf{if}\;\ell \leq -3.05 \cdot 10^{+131}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+19}:\\ \;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\ \mathbf{elif}\;\ell \leq 30:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (* J 2.0)))
        (t_1 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
        (t_2 (* l (/ U l))))
   (if (<= l -3.05e+131)
     t_1
     (if (<= l -1.5e+19)
       (/ (- (* t_0 t_0) (* t_2 t_2)) (- t_0 t_2))
       (if (<= l 30.0) (+ U (* J (* 2.0 (* l (cos (* K 0.5)))))) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -3.05e+131) {
		tmp = t_1;
	} else if (l <= -1.5e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 30.0) {
		tmp = U + (J * (2.0 * (l * cos((K * 0.5)))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = l * (j * 2.0d0)
    t_1 = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    t_2 = l * (u / l)
    if (l <= (-3.05d+131)) then
        tmp = t_1
    else if (l <= (-1.5d+19)) then
        tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
    else if (l <= 30.0d0) then
        tmp = u + (j * (2.0d0 * (l * cos((k * 0.5d0)))))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -3.05e+131) {
		tmp = t_1;
	} else if (l <= -1.5e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 30.0) {
		tmp = U + (J * (2.0 * (l * Math.cos((K * 0.5)))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * (J * 2.0)
	t_1 = U * (1.0 + (2.0 * (J * (l / U))))
	t_2 = l * (U / l)
	tmp = 0
	if l <= -3.05e+131:
		tmp = t_1
	elif l <= -1.5e+19:
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
	elif l <= 30.0:
		tmp = U + (J * (2.0 * (l * math.cos((K * 0.5)))))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * Float64(J * 2.0))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
	t_2 = Float64(l * Float64(U / l))
	tmp = 0.0
	if (l <= -3.05e+131)
		tmp = t_1;
	elseif (l <= -1.5e+19)
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(t_2 * t_2)) / Float64(t_0 - t_2));
	elseif (l <= 30.0)
		tmp = Float64(U + Float64(J * Float64(2.0 * Float64(l * cos(Float64(K * 0.5))))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = l * (J * 2.0);
	t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	t_2 = l * (U / l);
	tmp = 0.0;
	if (l <= -3.05e+131)
		tmp = t_1;
	elseif (l <= -1.5e+19)
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	elseif (l <= 30.0)
		tmp = U + (J * (2.0 * (l * cos((K * 0.5)))));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(l * N[(U / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.05e+131], t$95$1, If[LessEqual[l, -1.5e+19], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 30.0], N[(U + N[(J * N[(2.0 * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \ell \cdot \left(J \cdot 2\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
t_2 := \ell \cdot \frac{U}{\ell}\\
\mathbf{if}\;\ell \leq -3.05 \cdot 10^{+131}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+19}:\\
\;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\

\mathbf{elif}\;\ell \leq 30:\\
\;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.0499999999999999e131 or 30 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 26.0%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative26.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*26.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified26.9%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 26.0%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Taylor expanded in U around inf 33.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*41.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    10. Simplified41.8%

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

    if -3.0499999999999999e131 < l < -1.5e19

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 4.7%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative4.7%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*4.7%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified4.7%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 4.7%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Step-by-step derivation
      1. distribute-lft-in3.9%

        \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J\right) + \ell \cdot \frac{U}{\ell}} \]
      2. flip-+34.6%

        \[\leadsto \color{blue}{\frac{\left(\ell \cdot \left(2 \cdot J\right)\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}}} \]
      3. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      4. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      5. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \color{blue}{\left(J \cdot 2\right)} - \ell \cdot \frac{U}{\ell}} \]
    9. Applied egg-rr34.6%

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

    if -1.5e19 < l < 30

    1. Initial program 72.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 97.9%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
      2. associate-*l*97.9%

        \[\leadsto \color{blue}{J \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
      3. *-commutative97.9%

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

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)}\right) + U \]
    5. Simplified97.9%

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

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

Alternative 9: 88.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ U (* (cos (/ K 2.0)) (* J (* l (+ 2.0 (* 0.3333333333333333 (* l l))))))))
double code(double J, double l, double K, double U) {
	return U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (cos((k / 2.0d0)) * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l * l))))))
end function
public static double code(double J, double l, double K, double U) {
	return U + (Math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
}
def code(J, l, K, U):
	return U + (math.cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))))
function code(J, l, K, U)
	return Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))))
end
function tmp = code(J, l, K, U)
	tmp = U + (cos((K / 2.0)) * (J * (l * (2.0 + (0.3333333333333333 * (l * l))))));
end
code[J_, l_, K_, U_] := N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 89.1%

    \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. unpow285.3%

      \[\leadsto \left(\ell \cdot \left(0.3333333333333333 \cdot \left(J \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Applied egg-rr89.1%

    \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Final simplification89.1%

    \[\leadsto U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \]
  7. Add Preprocessing

Alternative 10: 61.3% accurate, 6.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \left(J \cdot 2\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ t_2 := \ell \cdot \frac{U}{\ell}\\ \mathbf{if}\;\ell \leq -2.25 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+19}:\\ \;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{-39}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (* J 2.0)))
        (t_1 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
        (t_2 (* l (/ U l))))
   (if (<= l -2.25e+128)
     t_1
     (if (<= l -1.5e+19)
       (/ (- (* t_0 t_0) (* t_2 t_2)) (- t_0 t_2))
       (if (<= l 2e-39) (+ U (* 2.0 (* l J))) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -2.25e+128) {
		tmp = t_1;
	} else if (l <= -1.5e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 2e-39) {
		tmp = U + (2.0 * (l * J));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = l * (j * 2.0d0)
    t_1 = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    t_2 = l * (u / l)
    if (l <= (-2.25d+128)) then
        tmp = t_1
    else if (l <= (-1.5d+19)) then
        tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
    else if (l <= 2d-39) then
        tmp = u + (2.0d0 * (l * j))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = l * (J * 2.0);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double t_2 = l * (U / l);
	double tmp;
	if (l <= -2.25e+128) {
		tmp = t_1;
	} else if (l <= -1.5e+19) {
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	} else if (l <= 2e-39) {
		tmp = U + (2.0 * (l * J));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * (J * 2.0)
	t_1 = U * (1.0 + (2.0 * (J * (l / U))))
	t_2 = l * (U / l)
	tmp = 0
	if l <= -2.25e+128:
		tmp = t_1
	elif l <= -1.5e+19:
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2)
	elif l <= 2e-39:
		tmp = U + (2.0 * (l * J))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * Float64(J * 2.0))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
	t_2 = Float64(l * Float64(U / l))
	tmp = 0.0
	if (l <= -2.25e+128)
		tmp = t_1;
	elseif (l <= -1.5e+19)
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(t_2 * t_2)) / Float64(t_0 - t_2));
	elseif (l <= 2e-39)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = l * (J * 2.0);
	t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	t_2 = l * (U / l);
	tmp = 0.0;
	if (l <= -2.25e+128)
		tmp = t_1;
	elseif (l <= -1.5e+19)
		tmp = ((t_0 * t_0) - (t_2 * t_2)) / (t_0 - t_2);
	elseif (l <= 2e-39)
		tmp = U + (2.0 * (l * J));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(l * N[(U / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.25e+128], t$95$1, If[LessEqual[l, -1.5e+19], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2e-39], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \ell \cdot \left(J \cdot 2\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
t_2 := \ell \cdot \frac{U}{\ell}\\
\mathbf{if}\;\ell \leq -2.25 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+19}:\\
\;\;\;\;\frac{t\_0 \cdot t\_0 - t\_2 \cdot t\_2}{t\_0 - t\_2}\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{-39}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.2500000000000001e128 or 1.99999999999999986e-39 < l

    1. Initial program 97.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 29.4%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative29.4%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*30.1%

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

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 29.4%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Taylor expanded in U around inf 33.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*41.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    10. Simplified41.8%

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

    if -2.2500000000000001e128 < l < -1.5e19

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 4.7%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative4.7%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*4.7%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified4.7%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 4.7%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Step-by-step derivation
      1. distribute-lft-in3.9%

        \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J\right) + \ell \cdot \frac{U}{\ell}} \]
      2. flip-+34.6%

        \[\leadsto \color{blue}{\frac{\left(\ell \cdot \left(2 \cdot J\right)\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}}} \]
      3. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      4. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \color{blue}{\left(J \cdot 2\right)}\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \left(2 \cdot J\right) - \ell \cdot \frac{U}{\ell}} \]
      5. *-commutative34.6%

        \[\leadsto \frac{\left(\ell \cdot \left(J \cdot 2\right)\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right) - \left(\ell \cdot \frac{U}{\ell}\right) \cdot \left(\ell \cdot \frac{U}{\ell}\right)}{\ell \cdot \color{blue}{\left(J \cdot 2\right)} - \ell \cdot \frac{U}{\ell}} \]
    9. Applied egg-rr34.6%

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

    if -1.5e19 < l < 1.99999999999999986e-39

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.2%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative98.2%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*98.2%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified98.2%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 84.4%

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

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

Alternative 11: 46.7% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1150 \lor \neg \left(\ell \leq 0.00013\right):\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -1150.0) (not (<= l 0.00013))) (* J (* l 2.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1150.0) || !(l <= 0.00013)) {
		tmp = J * (l * 2.0);
	} else {
		tmp = U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-1150.0d0)) .or. (.not. (l <= 0.00013d0))) then
        tmp = j * (l * 2.0d0)
    else
        tmp = u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1150.0) || !(l <= 0.00013)) {
		tmp = J * (l * 2.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -1150.0) or not (l <= 0.00013):
		tmp = J * (l * 2.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -1150.0) || !(l <= 0.00013))
		tmp = Float64(J * Float64(l * 2.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -1150.0) || ~((l <= 0.00013)))
		tmp = J * (l * 2.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1150.0], N[Not[LessEqual[l, 0.00013]], $MachinePrecision]], N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1150 \lor \neg \left(\ell \leq 0.00013\right):\\
\;\;\;\;J \cdot \left(\ell \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1150 or 1.29999999999999989e-4 < l

    1. Initial program 99.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 23.3%

      \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative23.3%

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*24.0%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified24.0%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 23.3%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Taylor expanded in l around inf 17.6%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
    9. Step-by-step derivation
      1. associate-*r*17.6%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
      2. *-commutative17.6%

        \[\leadsto \color{blue}{\left(J \cdot 2\right)} \cdot \ell \]
      3. associate-*r*18.3%

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell\right)} \]
    10. Simplified18.3%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell\right)} \]

    if -1150 < l < 1.29999999999999989e-4

    1. Initial program 71.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr50.0%

      \[\leadsto \color{blue}{-4} + U \]
    4. Taylor expanded in U around inf 71.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1150 \lor \neg \left(\ell \leq 0.00013\right):\\ \;\;\;\;J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 56.0% accurate, 22.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+19}:\\ \;\;\;\;J \cdot \left(\frac{U}{J} + \ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1e+19) (* J (+ (/ U J) (* l 2.0))) (+ U (* 2.0 (* l J)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1e+19) {
		tmp = J * ((U / J) + (l * 2.0));
	} else {
		tmp = U + (2.0 * (l * J));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-1d+19)) then
        tmp = j * ((u / j) + (l * 2.0d0))
    else
        tmp = u + (2.0d0 * (l * j))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1e+19) {
		tmp = J * ((U / J) + (l * 2.0));
	} else {
		tmp = U + (2.0 * (l * J));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -1e+19:
		tmp = J * ((U / J) + (l * 2.0))
	else:
		tmp = U + (2.0 * (l * J))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1e+19)
		tmp = Float64(J * Float64(Float64(U / J) + Float64(l * 2.0)));
	else
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -1e+19)
		tmp = J * ((U / J) + (l * 2.0));
	else
		tmp = U + (2.0 * (l * J));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1e+19], N[(J * N[(N[(U / J), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1e19

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 24.8%

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

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*26.2%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified26.2%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 24.8%

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

      \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
    8. Taylor expanded in J around inf 30.7%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if -1e19 < l

    1. Initial program 82.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 70.5%

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

        \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*70.5%

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified70.5%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in K around 0 58.7%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.0%

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

Alternative 13: 60.6% accurate, 28.4× speedup?

\[\begin{array}{l} \\ U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))
double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * (l / U))));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u * (1.0d0 + (2.0d0 * (j * (l / u))))
end function
public static double code(double J, double l, double K, double U) {
	return U * (1.0 + (2.0 * (J * (l / U))));
}
def code(J, l, K, U):
	return U * (1.0 + (2.0 * (J * (l / U))))
function code(J, l, K, U)
	return Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
end
function tmp = code(J, l, K, U)
	tmp = U * (1.0 + (2.0 * (J * (l / U))));
end
code[J_, l_, K_, U_] := N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 58.0%

    \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. *-commutative58.0%

      \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. associate-*l*58.4%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Simplified58.4%

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Taylor expanded in l around inf 47.7%

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

    \[\leadsto \ell \cdot \left(\color{blue}{2 \cdot J} + \frac{U}{\ell}\right) \]
  8. Taylor expanded in U around inf 51.6%

    \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
  9. Step-by-step derivation
    1. associate-/l*55.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
  10. Simplified55.3%

    \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)} \]
  11. Add Preprocessing

Alternative 14: 54.5% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + 2 \cdot \left(\ell \cdot J\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* l J))))
double code(double J, double l, double K, double U) {
	return U + (2.0 * (l * J));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (2.0d0 * (l * j))
end function
public static double code(double J, double l, double K, double U) {
	return U + (2.0 * (l * J));
}
def code(J, l, K, U):
	return U + (2.0 * (l * J))
function code(J, l, K, U)
	return Float64(U + Float64(2.0 * Float64(l * J)))
end
function tmp = code(J, l, K, U)
	tmp = U + (2.0 * (l * J));
end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + 2 \cdot \left(\ell \cdot J\right)
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 58.0%

    \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. *-commutative58.0%

      \[\leadsto \color{blue}{\left(\left(J \cdot \ell\right) \cdot 2\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. associate-*l*58.4%

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Simplified58.4%

    \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot 2\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Taylor expanded in K around 0 47.7%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
  7. Final simplification47.7%

    \[\leadsto U + 2 \cdot \left(\ell \cdot J\right) \]
  8. Add Preprocessing

Alternative 15: 37.4% accurate, 312.0× speedup?

\[\begin{array}{l} \\ U \end{array} \]
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
	return U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
public static double code(double J, double l, double K, double U) {
	return U;
}
def code(J, l, K, U):
	return U
function code(J, l, K, U)
	return U
end
function tmp = code(J, l, K, U)
	tmp = U;
end
code[J_, l_, K_, U_] := U
\begin{array}{l}

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

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr24.0%

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around inf 33.7%

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Alternative 16: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 8 \end{array} \]
(FPCore (J l K U) :precision binary64 8.0)
double code(double J, double l, double K, double U) {
	return 8.0;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = 8.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 8.0;
}
def code(J, l, K, U):
	return 8.0
function code(J, l, K, U)
	return 8.0
end
function tmp = code(J, l, K, U)
	tmp = 8.0;
end
code[J_, l_, K_, U_] := 8.0
\begin{array}{l}

\\
8
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr24.1%

    \[\leadsto \color{blue}{8} + U \]
  4. Taylor expanded in U around 0 2.7%

    \[\leadsto \color{blue}{8} \]
  5. Add Preprocessing

Alternative 17: 2.7% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -4 \end{array} \]
(FPCore (J l K U) :precision binary64 -4.0)
double code(double J, double l, double K, double U) {
	return -4.0;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = -4.0d0
end function
public static double code(double J, double l, double K, double U) {
	return -4.0;
}
def code(J, l, K, U):
	return -4.0
function code(J, l, K, U)
	return -4.0
end
function tmp = code(J, l, K, U)
	tmp = -4.0;
end
code[J_, l_, K_, U_] := -4.0
\begin{array}{l}

\\
-4
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr24.0%

    \[\leadsto \color{blue}{-4} + U \]
  4. Taylor expanded in U around 0 2.7%

    \[\leadsto \color{blue}{-4} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2024145 
(FPCore (J l K U)
  :name "Maksimov and Kolovsky, Equation (4)"
  :precision binary64
  (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))