Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 87.6% → 99.5%
Time: 13.4s
Alternatives: 17
Speedup: 1.4×

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

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.0)))
     (+ (* (cos (/ K 2.0)) (* t_0 J)) U)
     (fma (* J (* l 2.0)) (cos (* K 0.5)) U))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.0)) {
		tmp = (cos((K / 2.0)) * (t_0 * J)) + U;
	} else {
		tmp = fma((J * (l * 2.0)), cos((K * 0.5)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.0))
		tmp = Float64(Float64(cos(Float64(K / 2.0)) * Float64(t_0 * J)) + U);
	else
		tmp = fma(Float64(J * Float64(l * 2.0)), cos(Float64(K * 0.5)), U);
	end
	return 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, (-Infinity)], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 0.0 < (-.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 \]

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

    1. Initial program 71.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(J \cdot \color{blue}{\left(\ell \cdot 2\right)}, \cos \left(\frac{K}{2}\right), U\right) \]
      3. div-inv99.9%

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
      5. *-commutative99.9%

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

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

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

Alternative 2: 94.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(K \cdot 0.5\right)\\ t_2 := U + t_1 \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -0.00084:\\ \;\;\;\;U + t_0\\ \mathbf{elif}\;\ell \leq 11.2:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), t_1, U\right)\\ \mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+82}:\\ \;\;\;\;U + t_0 \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (- (exp l) (exp (- l))) J))
        (t_1 (cos (* K 0.5)))
        (t_2 (+ U (* t_1 (* (pow l 3.0) (* J 0.3333333333333333))))))
   (if (<= l -7.5e+139)
     t_2
     (if (<= l -0.00084)
       (+ U t_0)
       (if (<= l 11.2)
         (fma (* J (* l 2.0)) t_1 U)
         (if (<= l 3.5e+82) (+ U (* t_0 (+ (* -0.125 (* K K)) 1.0))) t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = (exp(l) - exp(-l)) * J;
	double t_1 = cos((K * 0.5));
	double t_2 = U + (t_1 * (pow(l, 3.0) * (J * 0.3333333333333333)));
	double tmp;
	if (l <= -7.5e+139) {
		tmp = t_2;
	} else if (l <= -0.00084) {
		tmp = U + t_0;
	} else if (l <= 11.2) {
		tmp = fma((J * (l * 2.0)), t_1, U);
	} else if (l <= 3.5e+82) {
		tmp = U + (t_0 * ((-0.125 * (K * K)) + 1.0));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	t_1 = cos(Float64(K * 0.5))
	t_2 = Float64(U + Float64(t_1 * Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))))
	tmp = 0.0
	if (l <= -7.5e+139)
		tmp = t_2;
	elseif (l <= -0.00084)
		tmp = Float64(U + t_0);
	elseif (l <= 11.2)
		tmp = fma(Float64(J * Float64(l * 2.0)), t_1, U);
	elseif (l <= 3.5e+82)
		tmp = Float64(U + Float64(t_0 * Float64(Float64(-0.125 * Float64(K * K)) + 1.0)));
	else
		tmp = t_2;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(t$95$1 * N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -7.5e+139], t$95$2, If[LessEqual[l, -0.00084], N[(U + t$95$0), $MachinePrecision], If[LessEqual[l, 11.2], N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * t$95$1 + U), $MachinePrecision], If[LessEqual[l, 3.5e+82], N[(U + N[(t$95$0 * N[(N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -0.00084:\\
\;\;\;\;U + t_0\\

\mathbf{elif}\;\ell \leq 11.2:\\
\;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), t_1, U\right)\\

\mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+82}:\\
\;\;\;\;U + t_0 \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 1\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -7.49999999999999992e139 or 3.5e82 < 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 98.9%

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot J + \color{blue}{\left(0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) \cdot J}\right) + U \]
      5. distribute-rgt-out98.9%

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

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

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

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

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      10. distribute-rgt-out98.9%

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)}\right) + U \]
      12. fma-def98.9%

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified98.9%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in l around inf 98.9%

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

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

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

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

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

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

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

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

    if -7.49999999999999992e139 < l < -8.4000000000000003e-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. Taylor expanded in K around 0 85.2%

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

    if -8.4000000000000003e-4 < l < 11.199999999999999

    1. Initial program 71.7%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      4. metadata-eval99.3%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
      5. *-commutative99.3%

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

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

    if 11.199999999999999 < l < 3.5e82

    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 0.0%

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

        \[\leadsto \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J + \color{blue}{\left(-0.125 \cdot {K}^{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)}\right) + U \]
      2. distribute-rgt1-in83.3%

        \[\leadsto \color{blue}{\left(-0.125 \cdot {K}^{2} + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} + U \]
      3. unpow283.3%

        \[\leadsto \left(-0.125 \cdot \color{blue}{\left(K \cdot K\right)} + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) + U \]
    4. Simplified83.3%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)} + U \]
  3. Recombined 4 regimes into one program.
  4. Final simplification96.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+139}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00084:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 11.2:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 3.5 \cdot 10^{+82}:\\ \;\;\;\;U + \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 1\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \end{array} \]

Alternative 3: 93.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + t_0 \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ t_2 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -0.0052:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq 300000:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), t_0, U\right)\\ \mathbf{elif}\;\ell \leq 1.22 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5)))
        (t_1 (+ U (* t_0 (* (pow l 3.0) (* J 0.3333333333333333)))))
        (t_2 (+ U (* (- (exp l) (exp (- l))) J))))
   (if (<= l -7.5e+139)
     t_1
     (if (<= l -0.0052)
       t_2
       (if (<= l 300000.0)
         (fma (* J (* l 2.0)) t_0 U)
         (if (<= l 1.22e+79) t_2 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + (t_0 * (pow(l, 3.0) * (J * 0.3333333333333333)));
	double t_2 = U + ((exp(l) - exp(-l)) * J);
	double tmp;
	if (l <= -7.5e+139) {
		tmp = t_1;
	} else if (l <= -0.0052) {
		tmp = t_2;
	} else if (l <= 300000.0) {
		tmp = fma((J * (l * 2.0)), t_0, U);
	} else if (l <= 1.22e+79) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U + Float64(t_0 * Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))))
	t_2 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	tmp = 0.0
	if (l <= -7.5e+139)
		tmp = t_1;
	elseif (l <= -0.0052)
		tmp = t_2;
	elseif (l <= 300000.0)
		tmp = fma(Float64(J * Float64(l * 2.0)), t_0, U);
	elseif (l <= 1.22e+79)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -7.5e+139], t$95$1, If[LessEqual[l, -0.0052], t$95$2, If[LessEqual[l, 300000.0], N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * t$95$0 + U), $MachinePrecision], If[LessEqual[l, 1.22e+79], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -0.0052:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 300000:\\
\;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), t_0, U\right)\\

\mathbf{elif}\;\ell \leq 1.22 \cdot 10^{+79}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.49999999999999992e139 or 1.22000000000000002e79 < 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 97.7%

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot J + \color{blue}{\left(0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) \cdot J}\right) + U \]
      5. distribute-rgt-out97.7%

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

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

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

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

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      10. distribute-rgt-out97.7%

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)}\right) + U \]
      12. fma-def97.7%

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified97.7%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in l around inf 97.7%

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

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

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

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

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

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

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

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

    if -7.49999999999999992e139 < l < -0.0051999999999999998 or 3e5 < l < 1.22000000000000002e79

    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 83.3%

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

    if -0.0051999999999999998 < l < 3e5

    1. Initial program 71.9%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \left(2 \cdot \ell\right), \cos \left(\frac{K}{2}\right), U\right)} \]
      2. *-commutative98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \color{blue}{\left(\ell \cdot 2\right)}, \cos \left(\frac{K}{2}\right), U\right) \]
      3. div-inv98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      4. metadata-eval98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
      5. *-commutative98.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+139}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0052:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 300000:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \mathbf{elif}\;\ell \leq 1.22 \cdot 10^{+79}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)\\ \end{array} \]

Alternative 4: 87.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -0.0115 \lor \neg \left(\ell \leq 300000\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -0.0115) (not (<= l 300000.0)))
   (+ U (* (- (exp l) (exp (- l))) J))
   (fma (* J (* l 2.0)) (cos (* K 0.5)) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -0.0115) || !(l <= 300000.0)) {
		tmp = U + ((exp(l) - exp(-l)) * J);
	} else {
		tmp = fma((J * (l * 2.0)), cos((K * 0.5)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -0.0115) || !(l <= 300000.0))
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J));
	else
		tmp = fma(Float64(J * Float64(l * 2.0)), cos(Float64(K * 0.5)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.0115], N[Not[LessEqual[l, 300000.0]], $MachinePrecision]], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], N[(N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.0115 or 3e5 < 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 74.2%

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

    if -0.0115 < l < 3e5

    1. Initial program 71.9%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \left(2 \cdot \ell\right), \cos \left(\frac{K}{2}\right), U\right)} \]
      2. *-commutative98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \color{blue}{\left(\ell \cdot 2\right)}, \cos \left(\frac{K}{2}\right), U\right) \]
      3. div-inv98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \color{blue}{\left(K \cdot \frac{1}{2}\right)}, U\right) \]
      4. metadata-eval98.6%

        \[\leadsto \mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot \color{blue}{0.5}\right), U\right) \]
      5. *-commutative98.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.0115 \lor \neg \left(\ell \leq 300000\right):\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \left(\ell \cdot 2\right), \cos \left(K \cdot 0.5\right), U\right)\\ \end{array} \]

Alternative 5: 87.1% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.042 \lor \neg \left(\ell \leq 300000\right):\\
\;\;\;\;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 2\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.0420000000000000026 or 3e5 < 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 74.2%

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

    if -0.0420000000000000026 < l < 3e5

    1. Initial program 71.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.042 \lor \neg \left(\ell \leq 300000\right):\\ \;\;\;\;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 2\right)\right)\\ \end{array} \]

Alternative 6: 78.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -5.3 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 1800000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+101}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* l 2.0) (* (pow l 3.0) 0.3333333333333333))))))
   (if (<= l -5.3e+67)
     t_0
     (if (<= l 1800000.0)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (if (<= l 3.4e+101) (log1p (expm1 U)) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * ((l * 2.0) + (pow(l, 3.0) * 0.3333333333333333)));
	double tmp;
	if (l <= -5.3e+67) {
		tmp = t_0;
	} else if (l <= 1800000.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 3.4e+101) {
		tmp = log1p(expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * ((l * 2.0) + (Math.pow(l, 3.0) * 0.3333333333333333)));
	double tmp;
	if (l <= -5.3e+67) {
		tmp = t_0;
	} else if (l <= 1800000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 3.4e+101) {
		tmp = Math.log1p(Math.expm1(U));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * ((l * 2.0) + (math.pow(l, 3.0) * 0.3333333333333333)))
	tmp = 0
	if l <= -5.3e+67:
		tmp = t_0
	elif l <= 1800000.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif l <= 3.4e+101:
		tmp = math.log1p(math.expm1(U))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(l * 2.0) + Float64((l ^ 3.0) * 0.3333333333333333))))
	tmp = 0.0
	if (l <= -5.3e+67)
		tmp = t_0;
	elseif (l <= 1800000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 3.4e+101)
		tmp = log1p(expm1(U));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(N[(l * 2.0), $MachinePrecision] + N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.3e+67], t$95$0, If[LessEqual[l, 1800000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.4e+101], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.3e67 or 3.40000000000000017e101 < 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 95.8%

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot J + \color{blue}{\left(0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) \cdot J}\right) + U \]
      5. distribute-rgt-out95.8%

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

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

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

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

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      10. distribute-rgt-out95.8%

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)}\right) + U \]
      12. fma-def95.8%

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified95.8%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 69.9%

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

    if -5.3e67 < l < 1.8e6

    1. Initial program 74.6%

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

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

    if 1.8e6 < l < 3.40000000000000017e101

    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-rr57.5%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.3 \cdot 10^{+67}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 1800000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 3.4 \cdot 10^{+101}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \end{array} \]

Alternative 7: 76.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -620:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 300000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+102}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -620.0)
   (log1p (expm1 (- (/ -8.0 U) U)))
   (if (<= l 300000.0)
     (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
     (if (<= l 1.8e+102)
       (log1p (expm1 U))
       (+ U (* J (+ (* l 2.0) (* (pow l 3.0) 0.3333333333333333))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -620.0) {
		tmp = log1p(expm1(((-8.0 / U) - U)));
	} else if (l <= 300000.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 1.8e+102) {
		tmp = log1p(expm1(U));
	} else {
		tmp = U + (J * ((l * 2.0) + (pow(l, 3.0) * 0.3333333333333333)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -620.0) {
		tmp = Math.log1p(Math.expm1(((-8.0 / U) - U)));
	} else if (l <= 300000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 1.8e+102) {
		tmp = Math.log1p(Math.expm1(U));
	} else {
		tmp = U + (J * ((l * 2.0) + (Math.pow(l, 3.0) * 0.3333333333333333)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -620.0:
		tmp = math.log1p(math.expm1(((-8.0 / U) - U)))
	elif l <= 300000.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif l <= 1.8e+102:
		tmp = math.log1p(math.expm1(U))
	else:
		tmp = U + (J * ((l * 2.0) + (math.pow(l, 3.0) * 0.3333333333333333)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -620.0)
		tmp = log1p(expm1(Float64(Float64(-8.0 / U) - U)));
	elseif (l <= 300000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 1.8e+102)
		tmp = log1p(expm1(U));
	else
		tmp = Float64(U + Float64(J * Float64(Float64(l * 2.0) + Float64((l ^ 3.0) * 0.3333333333333333))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -620.0], N[Log[1 + N[(Exp[N[(N[(-8.0 / U), $MachinePrecision] - U), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 300000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.8e+102], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], N[(U + N[(J * N[(N[(l * 2.0), $MachinePrecision] + N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -620:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\

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

\mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\

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


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

    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-rr3.0%

      \[\leadsto \color{blue}{\frac{-8}{U} - U} \]
    3. Step-by-step derivation
      1. log1p-expm1-u57.1%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)} \]
    4. Applied egg-rr57.1%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)} \]

    if -620 < l < 3e5

    1. Initial program 71.9%

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

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

    if 3e5 < l < 1.8000000000000001e102

    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-rr57.5%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]

    if 1.8000000000000001e102 < 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 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -620:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-8}{U} - U\right)\right)\\ \mathbf{elif}\;\ell \leq 300000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+102}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \end{array} \]

Alternative 8: 77.5% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -2 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{+20}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* l 2.0) (* (pow l 3.0) 0.3333333333333333))))))
   (if (<= l -2e+67)
     t_0
     (if (<= l 1.26e+20)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (if (<= l 5.2e+81) (/ (* U (fma U U -64.0)) (+ U -8.0)) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * ((l * 2.0) + (pow(l, 3.0) * 0.3333333333333333)));
	double tmp;
	if (l <= -2e+67) {
		tmp = t_0;
	} else if (l <= 1.26e+20) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 5.2e+81) {
		tmp = (U * fma(U, U, -64.0)) / (U + -8.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(l * 2.0) + Float64((l ^ 3.0) * 0.3333333333333333))))
	tmp = 0.0
	if (l <= -2e+67)
		tmp = t_0;
	elseif (l <= 1.26e+20)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 5.2e+81)
		tmp = Float64(Float64(U * fma(U, U, -64.0)) / Float64(U + -8.0));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(N[(l * 2.0), $MachinePrecision] + N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2e+67], t$95$0, If[LessEqual[l, 1.26e+20], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.2e+81], N[(N[(U * N[(U * U + -64.0), $MachinePrecision]), $MachinePrecision] / N[(U + -8.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.99999999999999997e67 or 5.19999999999999984e81 < 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 95.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified95.0%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 69.1%

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

    if -1.99999999999999997e67 < l < 1.26e20

    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 l around 0 89.7%

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

    if 1.26e20 < l < 5.19999999999999984e81

    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-rr37.0%

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
    3. Step-by-step derivation
      1. *-commutative37.0%

        \[\leadsto \color{blue}{\left(U - -8\right) \cdot U} \]
      2. flip--37.0%

        \[\leadsto \color{blue}{\frac{U \cdot U - -8 \cdot -8}{U + -8}} \cdot U \]
      3. associate-*l/50.3%

        \[\leadsto \color{blue}{\frac{\left(U \cdot U - -8 \cdot -8\right) \cdot U}{U + -8}} \]
      4. fma-neg50.3%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(U, U, --8 \cdot -8\right)} \cdot U}{U + -8} \]
      5. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, -\color{blue}{64}\right) \cdot U}{U + -8} \]
      6. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, \color{blue}{-64}\right) \cdot U}{U + -8} \]
    4. Applied egg-rr50.3%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(U, U, -64\right) \cdot U}{U + -8}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2 \cdot 10^{+67}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{+20}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + {\ell}^{3} \cdot 0.3333333333333333\right)\\ \end{array} \]

Alternative 9: 58.8% accurate, 2.7× speedup?

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

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

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


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

    1. Initial program 79.7%

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

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)} + U \]
      2. associate-*r*46.8%

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out51.1%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2} + 2\right)} + U \]
      4. *-commutative51.1%

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

        \[\leadsto \left(\ell \cdot J\right) \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.25 + 2\right) + U \]
    5. Simplified51.1%

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

    if -0.0400000000000000008 < (cos.f64 (/.f64 K 2))

    1. Initial program 87.7%

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

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

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

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

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

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

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

Alternative 10: 63.6% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 8.5 \cdot 10^{+19}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+179}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l 8.5e+19)
   (+ U (* J (* (cos (* K 0.5)) (* l 2.0))))
   (if (<= l 6.2e+81)
     (/ (* U (fma U U -64.0)) (+ U -8.0))
     (if (<= l 1.25e+179)
       (+ U (* J (+ (* (* K K) 0.0625) -0.5)))
       (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 8.5e+19) {
		tmp = U + (J * (cos((K * 0.5)) * (l * 2.0)));
	} else if (l <= 6.2e+81) {
		tmp = (U * fma(U, U, -64.0)) / (U + -8.0);
	} else if (l <= 1.25e+179) {
		tmp = U + (J * (((K * K) * 0.0625) + -0.5));
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 8.5e+19)
		tmp = Float64(U + Float64(J * Float64(cos(Float64(K * 0.5)) * Float64(l * 2.0))));
	elseif (l <= 6.2e+81)
		tmp = Float64(Float64(U * fma(U, U, -64.0)) / Float64(U + -8.0));
	elseif (l <= 1.25e+179)
		tmp = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * 0.0625) + -0.5)));
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, 8.5e+19], N[(U + N[(J * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.2e+81], N[(N[(U * N[(U * U + -64.0), $MachinePrecision]), $MachinePrecision] / N[(U + -8.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.25e+179], N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * 0.0625), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\

\mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+179}:\\
\;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\

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


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

    1. Initial program 80.6%

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

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

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

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

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

        \[\leadsto \left(\left(2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot J + \color{blue}{\left(0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) \cdot J}\right) + U \]
      5. distribute-rgt-out90.1%

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

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

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

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

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      10. distribute-rgt-out90.1%

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)}\right) + U \]
      12. fma-def90.1%

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified90.1%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in l around 0 77.3%

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

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

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

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

    if 8.5e19 < l < 6.2e81

    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-rr37.0%

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
    3. Step-by-step derivation
      1. *-commutative37.0%

        \[\leadsto \color{blue}{\left(U - -8\right) \cdot U} \]
      2. flip--37.0%

        \[\leadsto \color{blue}{\frac{U \cdot U - -8 \cdot -8}{U + -8}} \cdot U \]
      3. associate-*l/50.3%

        \[\leadsto \color{blue}{\frac{\left(U \cdot U - -8 \cdot -8\right) \cdot U}{U + -8}} \]
      4. fma-neg50.3%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(U, U, --8 \cdot -8\right)} \cdot U}{U + -8} \]
      5. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, -\color{blue}{64}\right) \cdot U}{U + -8} \]
      6. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, \color{blue}{-64}\right) \cdot U}{U + -8} \]
    4. Applied egg-rr50.3%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(U, U, -64\right) \cdot U}{U + -8}} \]

    if 6.2e81 < l < 1.25e179

    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-rr2.3%

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

      \[\leadsto \color{blue}{\left(0.0625 \cdot \left({K}^{2} \cdot J\right) + -0.5 \cdot J\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*37.6%

        \[\leadsto \left(\color{blue}{\left(0.0625 \cdot {K}^{2}\right) \cdot J} + -0.5 \cdot J\right) + U \]
      2. distribute-rgt-out37.6%

        \[\leadsto \color{blue}{J \cdot \left(0.0625 \cdot {K}^{2} + -0.5\right)} + U \]
      3. *-commutative37.6%

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot 0.0625} + -0.5\right) + U \]
      4. unpow237.6%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot 0.0625 + -0.5\right) + U \]
    5. Simplified37.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)} + U \]

    if 1.25e179 < 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 45.0%

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)} + U \]
      2. associate-*r*20.2%

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out47.2%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2} + 2\right)} + U \]
      4. *-commutative47.2%

        \[\leadsto \left(\ell \cdot J\right) \cdot \left(\color{blue}{{K}^{2} \cdot -0.25} + 2\right) + U \]
      5. unpow247.2%

        \[\leadsto \left(\ell \cdot J\right) \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.25 + 2\right) + U \]
    5. Simplified47.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 8.5 \cdot 10^{+19}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+179}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 11: 63.5% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 8.5 \cdot 10^{+19}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 8.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+182}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l 8.5e+19)
   (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
   (if (<= l 8.2e+81)
     (/ (* U (fma U U -64.0)) (+ U -8.0))
     (if (<= l 1.35e+182)
       (+ U (* J (+ (* (* K K) 0.0625) -0.5)))
       (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 8.5e+19) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 8.2e+81) {
		tmp = (U * fma(U, U, -64.0)) / (U + -8.0);
	} else if (l <= 1.35e+182) {
		tmp = U + (J * (((K * K) * 0.0625) + -0.5));
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 8.5e+19)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 8.2e+81)
		tmp = Float64(Float64(U * fma(U, U, -64.0)) / Float64(U + -8.0));
	elseif (l <= 1.35e+182)
		tmp = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * 0.0625) + -0.5)));
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, 8.5e+19], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8.2e+81], N[(N[(U * N[(U * U + -64.0), $MachinePrecision]), $MachinePrecision] / N[(U + -8.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.35e+182], N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * 0.0625), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq 8.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\

\mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+182}:\\
\;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\

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


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

    1. Initial program 80.6%

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

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

    if 8.5e19 < l < 8.20000000000000024e81

    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-rr37.0%

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
    3. Step-by-step derivation
      1. *-commutative37.0%

        \[\leadsto \color{blue}{\left(U - -8\right) \cdot U} \]
      2. flip--37.0%

        \[\leadsto \color{blue}{\frac{U \cdot U - -8 \cdot -8}{U + -8}} \cdot U \]
      3. associate-*l/50.3%

        \[\leadsto \color{blue}{\frac{\left(U \cdot U - -8 \cdot -8\right) \cdot U}{U + -8}} \]
      4. fma-neg50.3%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(U, U, --8 \cdot -8\right)} \cdot U}{U + -8} \]
      5. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, -\color{blue}{64}\right) \cdot U}{U + -8} \]
      6. metadata-eval50.3%

        \[\leadsto \frac{\mathsf{fma}\left(U, U, \color{blue}{-64}\right) \cdot U}{U + -8} \]
    4. Applied egg-rr50.3%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(U, U, -64\right) \cdot U}{U + -8}} \]

    if 8.20000000000000024e81 < l < 1.3500000000000001e182

    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-rr2.3%

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

      \[\leadsto \color{blue}{\left(0.0625 \cdot \left({K}^{2} \cdot J\right) + -0.5 \cdot J\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*37.6%

        \[\leadsto \left(\color{blue}{\left(0.0625 \cdot {K}^{2}\right) \cdot J} + -0.5 \cdot J\right) + U \]
      2. distribute-rgt-out37.6%

        \[\leadsto \color{blue}{J \cdot \left(0.0625 \cdot {K}^{2} + -0.5\right)} + U \]
      3. *-commutative37.6%

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot 0.0625} + -0.5\right) + U \]
      4. unpow237.6%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot 0.0625 + -0.5\right) + U \]
    5. Simplified37.6%

      \[\leadsto \color{blue}{J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)} + U \]

    if 1.3500000000000001e182 < 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 45.0%

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + 2 \cdot \left(\ell \cdot J\right)\right)} + U \]
      2. associate-*r*20.2%

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out47.2%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2} + 2\right)} + U \]
      4. *-commutative47.2%

        \[\leadsto \left(\ell \cdot J\right) \cdot \left(\color{blue}{{K}^{2} \cdot -0.25} + 2\right) + U \]
      5. unpow247.2%

        \[\leadsto \left(\ell \cdot J\right) \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.25 + 2\right) + U \]
    5. Simplified47.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 8.5 \cdot 10^{+19}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 8.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{U \cdot \mathsf{fma}\left(U, U, -64\right)}{U + -8}\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{+182}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 12: 54.3% accurate, 20.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.16 \cdot 10^{+85} \lor \neg \left(\ell \leq 1.55 \cdot 10^{+201}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.15999999999999995e85 or 1.5499999999999999e201 < l

    1. Initial program 83.9%

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

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

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

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

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

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

    if 1.15999999999999995e85 < l < 1.5499999999999999e201

    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-rr2.3%

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

      \[\leadsto \color{blue}{\left(0.0625 \cdot \left({K}^{2} \cdot J\right) + -0.5 \cdot J\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*36.2%

        \[\leadsto \left(\color{blue}{\left(0.0625 \cdot {K}^{2}\right) \cdot J} + -0.5 \cdot J\right) + U \]
      2. distribute-rgt-out36.2%

        \[\leadsto \color{blue}{J \cdot \left(0.0625 \cdot {K}^{2} + -0.5\right)} + U \]
      3. *-commutative36.2%

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot 0.0625} + -0.5\right) + U \]
      4. unpow236.2%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot 0.0625 + -0.5\right) + U \]
    5. Simplified36.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.16 \cdot 10^{+85} \lor \neg \left(\ell \leq 1.55 \cdot 10^{+201}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \end{array} \]

Alternative 13: 43.9% accurate, 34.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.28 \cdot 10^{+22}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 400000000000:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(U - -8\right)\\


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

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

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

    if -1.28e22 < l < 4e11

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

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

    if 4e11 < 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-rr20.9%

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification44.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.28 \cdot 10^{+22}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 400000000000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U - -8\right)\\ \end{array} \]

Alternative 14: 43.8% accurate, 43.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.5 \cdot 10^{+21}:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+19}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.5e21 or 1.4e19 < 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-rr17.9%

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

    if -7.5e21 < l < 1.4e19

    1. Initial program 73.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+21}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 15: 54.8% 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 85.5%

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

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

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

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

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

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

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

Alternative 16: 2.8% 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 85.5%

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

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

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

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

    \[\leadsto 1 \]

Alternative 17: 38.2% 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 85.5%

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification37.2%

    \[\leadsto U \]

Reproduce

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