Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.5%
Time: 13.9s
Alternatives: 16
Speedup: 1.5×

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 16 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.3% 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.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := e^{\ell} - t_0\\ t_2 := \cos \left(0.5 \cdot K\right)\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;J \cdot \left(t_1 \cdot t_2\right)\\ \mathbf{elif}\;t_1 \leq 10^{-13}:\\ \;\;\;\;\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U - J \cdot \left(t_2 \cdot \left(t_0 - e^{\ell}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (- (exp l) t_0)) (t_2 (cos (* 0.5 K))))
   (if (<= t_1 -20.0)
     (* J (* t_1 t_2))
     (if (<= t_1 1e-13)
       (+
        (*
         (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))
         (cos (/ K 2.0)))
        U)
       (- U (* J (* t_2 (- t_0 (exp l)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(-l);
	double t_1 = exp(l) - t_0;
	double t_2 = cos((0.5 * K));
	double tmp;
	if (t_1 <= -20.0) {
		tmp = J * (t_1 * t_2);
	} else if (t_1 <= 1e-13) {
		tmp = ((J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * cos((K / 2.0))) + U;
	} else {
		tmp = U - (J * (t_2 * (t_0 - exp(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) :: t_2
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = exp(l) - t_0
    t_2 = cos((0.5d0 * k))
    if (t_1 <= (-20.0d0)) then
        tmp = j * (t_1 * t_2)
    else if (t_1 <= 1d-13) then
        tmp = ((j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))) * cos((k / 2.0d0))) + u
    else
        tmp = u - (j * (t_2 * (t_0 - exp(l))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.exp(l) - t_0;
	double t_2 = Math.cos((0.5 * K));
	double tmp;
	if (t_1 <= -20.0) {
		tmp = J * (t_1 * t_2);
	} else if (t_1 <= 1e-13) {
		tmp = ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U - (J * (t_2 * (t_0 - Math.exp(l))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(-l)
	t_1 = math.exp(l) - t_0
	t_2 = math.cos((0.5 * K))
	tmp = 0
	if t_1 <= -20.0:
		tmp = J * (t_1 * t_2)
	elif t_1 <= 1e-13:
		tmp = ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) * math.cos((K / 2.0))) + U
	else:
		tmp = U - (J * (t_2 * (t_0 - math.exp(l))))
	return tmp
function code(J, l, K, U)
	t_0 = exp(Float64(-l))
	t_1 = Float64(exp(l) - t_0)
	t_2 = cos(Float64(0.5 * K))
	tmp = 0.0
	if (t_1 <= -20.0)
		tmp = Float64(J * Float64(t_1 * t_2));
	elseif (t_1 <= 1e-13)
		tmp = Float64(Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U - Float64(J * Float64(t_2 * Float64(t_0 - exp(l)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(-l);
	t_1 = exp(l) - t_0;
	t_2 = cos((0.5 * K));
	tmp = 0.0;
	if (t_1 <= -20.0)
		tmp = J * (t_1 * t_2);
	elseif (t_1 <= 1e-13)
		tmp = ((J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) * cos((K / 2.0))) + U;
	else
		tmp = U - (J * (t_2 * (t_0 - exp(l))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -20.0], N[(J * N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-13], N[(N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U - N[(J * N[(t$95$2 * N[(t$95$0 - N[Exp[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := e^{\ell} - t_0\\
t_2 := \cos \left(0.5 \cdot K\right)\\
\mathbf{if}\;t_1 \leq -20:\\
\;\;\;\;J \cdot \left(t_1 \cdot t_2\right)\\

\mathbf{elif}\;t_1 \leq 10^{-13}:\\
\;\;\;\;\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;U - J \cdot \left(t_2 \cdot \left(t_0 - e^{\ell}\right)\right)\\


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Taylor expanded in J around inf 100.0%

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

    if -20 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1e-13

    1. Initial program 73.0%

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

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

    if 1e-13 < (-.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. Taylor expanded in J around 0 100.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -20:\\ \;\;\;\;J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(0.5 \cdot K\right)\right)\\ \mathbf{elif}\;e^{\ell} - e^{-\ell} \leq 10^{-13}:\\ \;\;\;\;\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U - J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{-\ell} - e^{\ell}\right)\right)\\ \end{array} \]

Alternative 2: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -20 \lor \neg \left(t_0 \leq 0.2\right):\\ \;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -20.0) (not (<= t_0 0.2)))
     (* J (* t_0 (cos (* 0.5 K))))
     (+
      (*
       (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))
       (cos (/ K 2.0)))
      U))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -20.0) || !(t_0 <= 0.2)) {
		tmp = J * (t_0 * cos((0.5 * K)));
	} else {
		tmp = ((J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * cos((K / 2.0))) + 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) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-20.0d0)) .or. (.not. (t_0 <= 0.2d0))) then
        tmp = j * (t_0 * cos((0.5d0 * k)))
    else
        tmp = ((j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))) * cos((k / 2.0d0))) + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -20.0) || !(t_0 <= 0.2)) {
		tmp = J * (t_0 * Math.cos((0.5 * K)));
	} else {
		tmp = ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) * Math.cos((K / 2.0))) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -20.0) or not (t_0 <= 0.2):
		tmp = J * (t_0 * math.cos((0.5 * K)))
	else:
		tmp = ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) * math.cos((K / 2.0))) + U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -20.0) || !(t_0 <= 0.2))
		tmp = Float64(J * Float64(t_0 * cos(Float64(0.5 * K))));
	else
		tmp = Float64(Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 2.0))) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -20.0) || ~((t_0 <= 0.2)))
		tmp = J * (t_0 * cos((0.5 * K)));
	else
		tmp = ((J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) * cos((K / 2.0))) + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -20.0], N[Not[LessEqual[t$95$0, 0.2]], $MachinePrecision]], N[(J * N[(t$95$0 * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -20 \lor \neg \left(t_0 \leq 0.2\right):\\
\;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -20 or 0.20000000000000001 < (-.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. Taylor expanded in J around 0 100.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Taylor expanded in J around inf 100.0%

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

    if -20 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.20000000000000001

    1. Initial program 73.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -20 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.2\right):\\ \;\;\;\;J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(0.5 \cdot K\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \end{array} \]

Alternative 3: 93.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\\ t_1 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -3.1:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 0.0235:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.2 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* (* J 0.3333333333333333) (* (cos (* 0.5 K)) (pow l 3.0)))))
        (t_1 (+ U (* (- (exp l) (exp (- l))) J))))
   (if (<= l -2.8e+134)
     t_0
     (if (<= l -3.1)
       t_1
       (if (<= l 0.0235)
         (+ U (* (cos (/ K 2.0)) (* l (* J 2.0))))
         (if (<= l 2.2e+66) t_1 t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * 0.3333333333333333) * (cos((0.5 * K)) * pow(l, 3.0)));
	double t_1 = U + ((exp(l) - exp(-l)) * J);
	double tmp;
	if (l <= -2.8e+134) {
		tmp = t_0;
	} else if (l <= -3.1) {
		tmp = t_1;
	} else if (l <= 0.0235) {
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	} else if (l <= 2.2e+66) {
		tmp = t_1;
	} else {
		tmp = t_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) :: t_1
    real(8) :: tmp
    t_0 = u + ((j * 0.3333333333333333d0) * (cos((0.5d0 * k)) * (l ** 3.0d0)))
    t_1 = u + ((exp(l) - exp(-l)) * j)
    if (l <= (-2.8d+134)) then
        tmp = t_0
    else if (l <= (-3.1d0)) then
        tmp = t_1
    else if (l <= 0.0235d0) then
        tmp = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
    else if (l <= 2.2d+66) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * 0.3333333333333333) * (Math.cos((0.5 * K)) * Math.pow(l, 3.0)));
	double t_1 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double tmp;
	if (l <= -2.8e+134) {
		tmp = t_0;
	} else if (l <= -3.1) {
		tmp = t_1;
	} else if (l <= 0.0235) {
		tmp = U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
	} else if (l <= 2.2e+66) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((J * 0.3333333333333333) * (math.cos((0.5 * K)) * math.pow(l, 3.0)))
	t_1 = U + ((math.exp(l) - math.exp(-l)) * J)
	tmp = 0
	if l <= -2.8e+134:
		tmp = t_0
	elif l <= -3.1:
		tmp = t_1
	elif l <= 0.0235:
		tmp = U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
	elif l <= 2.2e+66:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * 0.3333333333333333) * Float64(cos(Float64(0.5 * K)) * (l ^ 3.0))))
	t_1 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	tmp = 0.0
	if (l <= -2.8e+134)
		tmp = t_0;
	elseif (l <= -3.1)
		tmp = t_1;
	elseif (l <= 0.0235)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0))));
	elseif (l <= 2.2e+66)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((J * 0.3333333333333333) * (cos((0.5 * K)) * (l ^ 3.0)));
	t_1 = U + ((exp(l) - exp(-l)) * J);
	tmp = 0.0;
	if (l <= -2.8e+134)
		tmp = t_0;
	elseif (l <= -3.1)
		tmp = t_1;
	elseif (l <= 0.0235)
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	elseif (l <= 2.2e+66)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(J * 0.3333333333333333), $MachinePrecision] * N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.8e+134], t$95$0, If[LessEqual[l, -3.1], t$95$1, If[LessEqual[l, 0.0235], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.2e+66], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\\
t_1 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -2.8 \cdot 10^{+134}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -3.1:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\ell \leq 2.2 \cdot 10^{+66}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.7999999999999999e134 or 2.1999999999999998e66 < 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. Taylor expanded in l around 0 99.0%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*99.0%

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

        \[\leadsto \color{blue}{\left(J \cdot 0.3333333333333333\right)} \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right) + U \]
    5. Simplified99.0%

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

    if -2.7999999999999999e134 < l < -3.10000000000000009 or 0.0235 < l < 2.1999999999999998e66

    1. Initial program 100.0%

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

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

    if -3.10000000000000009 < l < 0.0235

    1. Initial program 73.2%

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

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

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

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

      \[\leadsto \color{blue}{\left(\ell \cdot \left(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 -2.8 \cdot 10^{+134}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -3.1:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.0235:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.2 \cdot 10^{+66}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 4: 88.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+
  (* (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))) (cos (/ K 2.0)))
  U))
double code(double J, double l, double K, double U) {
	return ((J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * 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 * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

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

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

    \[\leadsto \left(J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Final simplification90.7%

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

Alternative 5: 87.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.1 \lor \neg \left(\ell \leq 0.00145\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -3.1) (not (<= l 0.00145)))
   (+ U (* (- (exp l) (exp (- l))) J))
   (+ U (* (cos (/ K 2.0)) (* l (* J 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.1) || !(l <= 0.00145)) {
		tmp = U + ((exp(l) - exp(-l)) * J);
	} else {
		tmp = U + (cos((K / 2.0)) * (l * (J * 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 ((l <= (-3.1d0)) .or. (.not. (l <= 0.00145d0))) then
        tmp = u + ((exp(l) - exp(-l)) * j)
    else
        tmp = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.1) || !(l <= 0.00145)) {
		tmp = U + ((Math.exp(l) - Math.exp(-l)) * J);
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -3.1) or not (l <= 0.00145):
		tmp = U + ((math.exp(l) - math.exp(-l)) * J)
	else:
		tmp = U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -3.1) || !(l <= 0.00145))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -3.1) || ~((l <= 0.00145)))
		tmp = U + ((exp(l) - exp(-l)) * J);
	else
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3.1], N[Not[LessEqual[l, 0.00145]], $MachinePrecision]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.1 \lor \neg \left(\ell \leq 0.00145\right):\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.10000000000000009 or 0.00145 < 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. Taylor expanded in K around 0 68.5%

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

    if -3.10000000000000009 < l < 0.00145

    1. Initial program 73.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.1 \lor \neg \left(\ell \leq 0.00145\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \end{array} \]

Alternative 6: 78.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -3 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1.15 \cdot 10^{+16}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* 0.3333333333333333 (pow l 3.0)))))
   (if (<= l -3e+81)
     t_0
     (if (<= l -1.15e+16)
       (pow U -4.0)
       (if (<= l 3.3e+34) (+ U (* l (* 2.0 (* J (cos (* 0.5 K)))))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * pow(l, 3.0));
	double tmp;
	if (l <= -3e+81) {
		tmp = t_0;
	} else if (l <= -1.15e+16) {
		tmp = pow(U, -4.0);
	} else if (l <= 3.3e+34) {
		tmp = U + (l * (2.0 * (J * cos((0.5 * K)))));
	} else {
		tmp = t_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 = j * (0.3333333333333333d0 * (l ** 3.0d0))
    if (l <= (-3d+81)) then
        tmp = t_0
    else if (l <= (-1.15d+16)) then
        tmp = u ** (-4.0d0)
    else if (l <= 3.3d+34) then
        tmp = u + (l * (2.0d0 * (j * cos((0.5d0 * k)))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * Math.pow(l, 3.0));
	double tmp;
	if (l <= -3e+81) {
		tmp = t_0;
	} else if (l <= -1.15e+16) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 3.3e+34) {
		tmp = U + (l * (2.0 * (J * Math.cos((0.5 * K)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (0.3333333333333333 * math.pow(l, 3.0))
	tmp = 0
	if l <= -3e+81:
		tmp = t_0
	elif l <= -1.15e+16:
		tmp = math.pow(U, -4.0)
	elif l <= 3.3e+34:
		tmp = U + (l * (2.0 * (J * math.cos((0.5 * K)))))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))
	tmp = 0.0
	if (l <= -3e+81)
		tmp = t_0;
	elseif (l <= -1.15e+16)
		tmp = U ^ -4.0;
	elseif (l <= 3.3e+34)
		tmp = Float64(U + Float64(l * Float64(2.0 * Float64(J * cos(Float64(0.5 * K))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (0.3333333333333333 * (l ^ 3.0));
	tmp = 0.0;
	if (l <= -3e+81)
		tmp = t_0;
	elseif (l <= -1.15e+16)
		tmp = U ^ -4.0;
	elseif (l <= 3.3e+34)
		tmp = U + (l * (2.0 * (J * cos((0.5 * K)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3e+81], t$95$0, If[LessEqual[l, -1.15e+16], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 3.3e+34], N[(U + N[(l * N[(2.0 * N[(J * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -3 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -1.15 \cdot 10^{+16}:\\
\;\;\;\;{U}^{-4}\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.99999999999999997e81 or 3.29999999999999988e34 < 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. Taylor expanded in l around 0 91.1%

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

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)} + U \]
    4. Taylor expanded in l around inf 60.1%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    5. Step-by-step derivation
      1. *-commutative60.1%

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

        \[\leadsto \color{blue}{J \cdot \left({\ell}^{3} \cdot 0.3333333333333333\right)} \]
      3. *-commutative60.1%

        \[\leadsto J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]
    6. Simplified60.1%

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]

    if -2.99999999999999997e81 < l < -1.15e16

    1. Initial program 100.0%

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

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

    if -1.15e16 < l < 3.29999999999999988e34

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3 \cdot 10^{+81}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -1.15 \cdot 10^{+16}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 7: 78.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+34}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* 0.3333333333333333 (pow l 3.0)))))
   (if (<= l -1.9e+81)
     t_0
     (if (<= l -5.2e+15)
       (pow U -4.0)
       (if (<= l 4.2e+34) (+ U (* (cos (/ K 2.0)) (* l (* J 2.0)))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * pow(l, 3.0));
	double tmp;
	if (l <= -1.9e+81) {
		tmp = t_0;
	} else if (l <= -5.2e+15) {
		tmp = pow(U, -4.0);
	} else if (l <= 4.2e+34) {
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	} else {
		tmp = t_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 = j * (0.3333333333333333d0 * (l ** 3.0d0))
    if (l <= (-1.9d+81)) then
        tmp = t_0
    else if (l <= (-5.2d+15)) then
        tmp = u ** (-4.0d0)
    else if (l <= 4.2d+34) then
        tmp = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * Math.pow(l, 3.0));
	double tmp;
	if (l <= -1.9e+81) {
		tmp = t_0;
	} else if (l <= -5.2e+15) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 4.2e+34) {
		tmp = U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (0.3333333333333333 * math.pow(l, 3.0))
	tmp = 0
	if l <= -1.9e+81:
		tmp = t_0
	elif l <= -5.2e+15:
		tmp = math.pow(U, -4.0)
	elif l <= 4.2e+34:
		tmp = U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))
	tmp = 0.0
	if (l <= -1.9e+81)
		tmp = t_0;
	elseif (l <= -5.2e+15)
		tmp = U ^ -4.0;
	elseif (l <= 4.2e+34)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (0.3333333333333333 * (l ^ 3.0));
	tmp = 0.0;
	if (l <= -1.9e+81)
		tmp = t_0;
	elseif (l <= -5.2e+15)
		tmp = U ^ -4.0;
	elseif (l <= 4.2e+34)
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.9e+81], t$95$0, If[LessEqual[l, -5.2e+15], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 4.2e+34], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -1.9 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\
\;\;\;\;{U}^{-4}\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.9e81 or 4.20000000000000035e34 < 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. Taylor expanded in l around 0 91.1%

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

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)} + U \]
    4. Taylor expanded in l around inf 60.1%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    5. Step-by-step derivation
      1. *-commutative60.1%

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

        \[\leadsto \color{blue}{J \cdot \left({\ell}^{3} \cdot 0.3333333333333333\right)} \]
      3. *-commutative60.1%

        \[\leadsto J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]
    6. Simplified60.1%

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]

    if -1.9e81 < l < -5.2e15

    1. Initial program 100.0%

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

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

    if -5.2e15 < l < 4.20000000000000035e34

    1. Initial program 74.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+81}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+34}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 8: 77.3% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;J \leq -6.9 \cdot 10^{+90} \lor \neg \left(J \leq 1.1 \cdot 10^{+112}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right) + U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= J -6.9e+90) (not (<= J 1.1e+112)))
   (+ U (* (cos (/ K 2.0)) (* l (* J 2.0))))
   (+ (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((J <= -6.9e+90) || !(J <= 1.1e+112)) {
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	} else {
		tmp = (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) + 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 ((j <= (-6.9d+90)) .or. (.not. (j <= 1.1d+112))) then
        tmp = u + (cos((k / 2.0d0)) * (l * (j * 2.0d0)))
    else
        tmp = (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))) + u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((J <= -6.9e+90) || !(J <= 1.1e+112)) {
		tmp = U + (Math.cos((K / 2.0)) * (l * (J * 2.0)));
	} else {
		tmp = (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) + U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (J <= -6.9e+90) or not (J <= 1.1e+112):
		tmp = U + (math.cos((K / 2.0)) * (l * (J * 2.0)))
	else:
		tmp = (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) + U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((J <= -6.9e+90) || !(J <= 1.1e+112))
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(J * 2.0))));
	else
		tmp = Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) + U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((J <= -6.9e+90) || ~((J <= 1.1e+112)))
		tmp = U + (cos((K / 2.0)) * (l * (J * 2.0)));
	else
		tmp = (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) + U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[J, -6.9e+90], N[Not[LessEqual[J, 1.1e+112]], $MachinePrecision]], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;J \leq -6.9 \cdot 10^{+90} \lor \neg \left(J \leq 1.1 \cdot 10^{+112}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -6.89999999999999955e90 or 1.1e112 < J

    1. Initial program 72.8%

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

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

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

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

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

    if -6.89999999999999955e90 < J < 1.1e112

    1. Initial program 94.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -6.9 \cdot 10^{+90} \lor \neg \left(J \leq 1.1 \cdot 10^{+112}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right) + U\\ \end{array} \]

Alternative 9: 72.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -1.26 \cdot 10^{+82}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (* 0.3333333333333333 (pow l 3.0)))))
   (if (<= l -1.26e+82)
     t_0
     (if (<= l -5.2e+15)
       (pow U -4.0)
       (if (<= l 3.3e+34) (+ U (* l (* J 2.0))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * pow(l, 3.0));
	double tmp;
	if (l <= -1.26e+82) {
		tmp = t_0;
	} else if (l <= -5.2e+15) {
		tmp = pow(U, -4.0);
	} else if (l <= 3.3e+34) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = t_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 = j * (0.3333333333333333d0 * (l ** 3.0d0))
    if (l <= (-1.26d+82)) then
        tmp = t_0
    else if (l <= (-5.2d+15)) then
        tmp = u ** (-4.0d0)
    else if (l <= 3.3d+34) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (0.3333333333333333 * Math.pow(l, 3.0));
	double tmp;
	if (l <= -1.26e+82) {
		tmp = t_0;
	} else if (l <= -5.2e+15) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= 3.3e+34) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (0.3333333333333333 * math.pow(l, 3.0))
	tmp = 0
	if l <= -1.26e+82:
		tmp = t_0
	elif l <= -5.2e+15:
		tmp = math.pow(U, -4.0)
	elif l <= 3.3e+34:
		tmp = U + (l * (J * 2.0))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))
	tmp = 0.0
	if (l <= -1.26e+82)
		tmp = t_0;
	elseif (l <= -5.2e+15)
		tmp = U ^ -4.0;
	elseif (l <= 3.3e+34)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (0.3333333333333333 * (l ^ 3.0));
	tmp = 0.0;
	if (l <= -1.26e+82)
		tmp = t_0;
	elseif (l <= -5.2e+15)
		tmp = U ^ -4.0;
	elseif (l <= 3.3e+34)
		tmp = U + (l * (J * 2.0));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.26e+82], t$95$0, If[LessEqual[l, -5.2e+15], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, 3.3e+34], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -1.26 \cdot 10^{+82}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\
\;\;\;\;{U}^{-4}\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.2600000000000001e82 or 3.29999999999999988e34 < 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. Taylor expanded in l around 0 91.1%

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

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)} + U \]
    4. Taylor expanded in l around inf 60.1%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    5. Step-by-step derivation
      1. *-commutative60.1%

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

        \[\leadsto \color{blue}{J \cdot \left({\ell}^{3} \cdot 0.3333333333333333\right)} \]
      3. *-commutative60.1%

        \[\leadsto J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]
    6. Simplified60.1%

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)} \]

    if -1.2600000000000001e82 < l < -5.2e15

    1. Initial program 100.0%

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

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

    if -5.2e15 < l < 3.29999999999999988e34

    1. Initial program 74.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.26 \cdot 10^{+82}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 10: 54.6% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -9.5 \cdot 10^{+82} \lor \neg \left(\ell \leq -5.2 \cdot 10^{+15}\right) \land \ell \leq 850:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-4}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -9.5e+82) (and (not (<= l -5.2e+15)) (<= l 850.0)))
   (+ U (* l (* J 2.0)))
   (pow U -4.0)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -9.5e+82) || (!(l <= -5.2e+15) && (l <= 850.0))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = pow(U, -4.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 ((l <= (-9.5d+82)) .or. (.not. (l <= (-5.2d+15))) .and. (l <= 850.0d0)) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u ** (-4.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -9.5e+82) || (!(l <= -5.2e+15) && (l <= 850.0))) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = Math.pow(U, -4.0);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -9.5e+82) or (not (l <= -5.2e+15) and (l <= 850.0)):
		tmp = U + (l * (J * 2.0))
	else:
		tmp = math.pow(U, -4.0)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -9.5e+82) || (!(l <= -5.2e+15) && (l <= 850.0)))
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = U ^ -4.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -9.5e+82) || (~((l <= -5.2e+15)) && (l <= 850.0)))
		tmp = U + (l * (J * 2.0));
	else
		tmp = U ^ -4.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -9.5e+82], And[N[Not[LessEqual[l, -5.2e+15]], $MachinePrecision], LessEqual[l, 850.0]]], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[U, -4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -9.5 \cdot 10^{+82} \lor \neg \left(\ell \leq -5.2 \cdot 10^{+15}\right) \land \ell \leq 850:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;{U}^{-4}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -9.50000000000000049e82 or -5.2e15 < l < 850

    1. Initial program 80.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    6. Simplified72.1%

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

    if -9.50000000000000049e82 < l < -5.2e15 or 850 < 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. Applied egg-rr31.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.5 \cdot 10^{+82} \lor \neg \left(\ell \leq -5.2 \cdot 10^{+15}\right) \land \ell \leq 850:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-4}\\ \end{array} \]

Alternative 11: 52.8% accurate, 9.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 - K \cdot -0.03125\\ \mathbf{if}\;\ell \leq 0.05:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\frac{K \cdot -0.03125 - t_0 \cdot t_0}{K \cdot -0.03125 + \left(K \cdot -0.03125 - -4\right)} + J \cdot 0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- -4.0 (* K -0.03125))))
   (if (<= l 0.05)
     (+ U (* l (* J 2.0)))
     (+
      U
      (+
       (/
        (- (* K -0.03125) (* t_0 t_0))
        (+ (* K -0.03125) (- (* K -0.03125) -4.0)))
       (* J 0.25))))))
double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (K * -0.03125);
	double tmp;
	if (l <= 0.05) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((((K * -0.03125) - (t_0 * t_0)) / ((K * -0.03125) + ((K * -0.03125) - -4.0))) + (J * 0.25));
	}
	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 = (-4.0d0) - (k * (-0.03125d0))
    if (l <= 0.05d0) then
        tmp = u + (l * (j * 2.0d0))
    else
        tmp = u + ((((k * (-0.03125d0)) - (t_0 * t_0)) / ((k * (-0.03125d0)) + ((k * (-0.03125d0)) - (-4.0d0)))) + (j * 0.25d0))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (K * -0.03125);
	double tmp;
	if (l <= 0.05) {
		tmp = U + (l * (J * 2.0));
	} else {
		tmp = U + ((((K * -0.03125) - (t_0 * t_0)) / ((K * -0.03125) + ((K * -0.03125) - -4.0))) + (J * 0.25));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = -4.0 - (K * -0.03125)
	tmp = 0
	if l <= 0.05:
		tmp = U + (l * (J * 2.0))
	else:
		tmp = U + ((((K * -0.03125) - (t_0 * t_0)) / ((K * -0.03125) + ((K * -0.03125) - -4.0))) + (J * 0.25))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(-4.0 - Float64(K * -0.03125))
	tmp = 0.0
	if (l <= 0.05)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	else
		tmp = Float64(U + Float64(Float64(Float64(Float64(K * -0.03125) - Float64(t_0 * t_0)) / Float64(Float64(K * -0.03125) + Float64(Float64(K * -0.03125) - -4.0))) + Float64(J * 0.25)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = -4.0 - (K * -0.03125);
	tmp = 0.0;
	if (l <= 0.05)
		tmp = U + (l * (J * 2.0));
	else
		tmp = U + ((((K * -0.03125) - (t_0 * t_0)) / ((K * -0.03125) + ((K * -0.03125) - -4.0))) + (J * 0.25));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(-4.0 - N[(K * -0.03125), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, 0.05], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(N[(N[(K * -0.03125), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[(K * -0.03125), $MachinePrecision] + N[(N[(K * -0.03125), $MachinePrecision] - -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 - K \cdot -0.03125\\
\mathbf{if}\;\ell \leq 0.05:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;U + \left(\frac{K \cdot -0.03125 - t_0 \cdot t_0}{K \cdot -0.03125 + \left(K \cdot -0.03125 - -4\right)} + J \cdot 0.25\right)\\


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

    1. Initial program 81.1%

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

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

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

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

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    6. Simplified68.9%

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

    if 0.050000000000000003 < 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. Applied egg-rr4.7%

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

      \[\leadsto \color{blue}{\left(-0.03125 \cdot \left(J \cdot {K}^{2}\right) + 0.25 \cdot J\right)} + U \]
    4. Applied egg-rr18.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 0.05:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\frac{K \cdot -0.03125 - \left(-4 - K \cdot -0.03125\right) \cdot \left(-4 - K \cdot -0.03125\right)}{K \cdot -0.03125 + \left(K \cdot -0.03125 - -4\right)} + J \cdot 0.25\right)\\ \end{array} \]

Alternative 12: 42.4% accurate, 34.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-4 - U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -3.0) (* U U) (if (<= l 3.3e+34) U (- -4.0 (* U U)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.0) {
		tmp = U * U;
	} else if (l <= 3.3e+34) {
		tmp = U;
	} else {
		tmp = -4.0 - (U * 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 <= (-3.0d0)) then
        tmp = u * u
    else if (l <= 3.3d+34) then
        tmp = u
    else
        tmp = (-4.0d0) - (u * u)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.0) {
		tmp = U * U;
	} else if (l <= 3.3e+34) {
		tmp = U;
	} else {
		tmp = -4.0 - (U * U);
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -3.0:
		tmp = U * U
	elif l <= 3.3e+34:
		tmp = U
	else:
		tmp = -4.0 - (U * U)
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -3.0)
		tmp = Float64(U * U);
	elseif (l <= 3.3e+34)
		tmp = U;
	else
		tmp = Float64(-4.0 - Float64(U * U));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -3.0)
		tmp = U * U;
	elseif (l <= 3.3e+34)
		tmp = U;
	else
		tmp = -4.0 - (U * U);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -3.0], N[(U * U), $MachinePrecision], If[LessEqual[l, 3.3e+34], U, N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;-4 - U \cdot U\\


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

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Applied egg-rr15.8%

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

    if -3 < l < 3.29999999999999988e34

    1. Initial program 73.8%

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

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

    if 3.29999999999999988e34 < 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. Step-by-step derivation
      1. associate-*l*100.0%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Applied egg-rr14.2%

      \[\leadsto \color{blue}{-4 + \left(-U\right) \cdot U} \]
    5. Step-by-step derivation
      1. cancel-sign-sub-inv14.2%

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    6. Simplified14.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+34}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-4 - U \cdot U\\ \end{array} \]

Alternative 13: 42.1% accurate, 43.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3 \lor \neg \left(\ell \leq 1.9 \cdot 10^{+58}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -3.0) (not (<= l 1.9e+58))) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.0) || !(l <= 1.9e+58)) {
		tmp = U * U;
	} 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 <= (-3.0d0)) .or. (.not. (l <= 1.9d+58))) then
        tmp = u * u
    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 <= -3.0) || !(l <= 1.9e+58)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -3.0) or not (l <= 1.9e+58):
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -3.0) || !(l <= 1.9e+58))
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -3.0) || ~((l <= 1.9e+58)))
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3.0], N[Not[LessEqual[l, 1.9e+58]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3 \lor \neg \left(\ell \leq 1.9 \cdot 10^{+58}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3 or 1.8999999999999999e58 < 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. Applied egg-rr13.7%

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

    if -3 < l < 1.8999999999999999e58

    1. Initial program 75.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3 \lor \neg \left(\ell \leq 1.9 \cdot 10^{+58}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 14: 55.1% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + \ell \cdot \left(J \cdot 2\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* l (* J 2.0))))
double code(double J, double l, double K, double U) {
	return U + (l * (J * 2.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 = u + (l * (j * 2.0d0))
end function
public static double code(double J, double l, double K, double U) {
	return U + (l * (J * 2.0));
}
def code(J, l, K, U):
	return U + (l * (J * 2.0))
function code(J, l, K, U)
	return Float64(U + Float64(l * Float64(J * 2.0)))
end
function tmp = code(J, l, K, U)
	tmp = U + (l * (J * 2.0));
end
code[J_, l_, K_, U_] := N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
  6. Simplified54.1%

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

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]

Alternative 15: 2.7% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (J l K U) :precision binary64 1.0)
double code(double J, double l, double K, double U) {
	return 1.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 = 1.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 1.0;
}
def code(J, l, K, U):
	return 1.0
function code(J, l, K, U)
	return 1.0
end
function tmp = code(J, l, K, U)
	tmp = 1.0;
end
code[J_, l_, K_, U_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 86.2%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Applied egg-rr2.7%

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  3. Step-by-step derivation
    1. *-inverses2.7%

      \[\leadsto \color{blue}{1} \]
  4. Simplified2.7%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification2.7%

    \[\leadsto 1 \]

Alternative 16: 37.0% 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 86.2%

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification38.1%

    \[\leadsto U \]

Reproduce

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