Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.7% → 99.7%
Time: 12.8s
Alternatives: 14
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 86.7% 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.7% 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 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2, {\ell}^{3} \cdot 0.3333333333333333\right) \cdot \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 2e-5)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (fma
      J
      (* (fma l 2.0 (* (pow l 3.0) 0.3333333333333333)) (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 <= 2e-5)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = fma(J, (fma(l, 2.0, (pow(l, 3.0) * 0.3333333333333333)) * 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 <= 2e-5))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = fma(J, Float64(fma(l, 2.0, Float64((l ^ 3.0) * 0.3333333333333333)) * 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, 2e-5]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(N[(l * 2.0 + N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $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 2 \cdot 10^{-5}\right):\\
\;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2, {\ell}^{3} \cdot 0.3333333333333333\right) \cdot \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 2.00000000000000016e-5 < (-.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))) < 2.00000000000000016e-5

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.6% 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 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot \left(J \cdot 2\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\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 2e-5)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       (cos (* K 0.5))
       (+ (* l (* J 2.0)) (* 0.3333333333333333 (* J (pow l 3.0)))))))))
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 <= 2e-5)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (cos((K * 0.5)) * ((l * (J * 2.0)) + (0.3333333333333333 * (J * pow(l, 3.0)))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 2e-5)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (Math.cos((K * 0.5)) * ((l * (J * 2.0)) + (0.3333333333333333 * (J * Math.pow(l, 3.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 2e-5):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (math.cos((K * 0.5)) * ((l * (J * 2.0)) + (0.3333333333333333 * (J * math.pow(l, 3.0)))))
	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 <= 2e-5))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(cos(Float64(K * 0.5)) * Float64(Float64(l * Float64(J * 2.0)) + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 2e-5)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (cos((K * 0.5)) * ((l * (J * 2.0)) + (0.3333333333333333 * (J * (l ^ 3.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e-5]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 2 \cdot 10^{-5}\right):\\
\;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + \cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot \left(J \cdot 2\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\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 2.00000000000000016e-5 < (-.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))) < 2.00000000000000016e-5

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 94.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.07:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 0.092:\\
\;\;\;\;U + t_1 \cdot \left(\ell \cdot \left(J \cdot 2\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\

\mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.39999999999999983e137 or 2.34999999999999985e101 < 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999983e137 < l < -0.070000000000000007 or 0.091999999999999998 < l < 2.34999999999999985e101

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

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

    if -0.070000000000000007 < l < 0.091999999999999998

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 94.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.14:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+100}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.39999999999999983e137 or 2.0999999999999999e100 < 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999983e137 < l < -0.14000000000000001 or 0.125 < l < 2.0999999999999999e100

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

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

    if -0.14000000000000001 < l < 0.125

    1. Initial program 69.8%

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

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

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

Alternative 5: 94.8% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.00052:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.39999999999999983e137 or 1.05e101 < 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999983e137 < l < -5.19999999999999954e-4 or 7.99999999999999964e-6 < l < 1.05e101

    1. Initial program 99.6%

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

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

    if -5.19999999999999954e-4 < l < 7.99999999999999964e-6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+137}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00052:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{-6}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.05 \cdot 10^{+101}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 6: 78.6% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.5% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 86.8% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.0045999999999999999 or 7.99999999999999964e-6 < l

    1. Initial program 99.8%

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

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

    if -0.0045999999999999999 < l < 7.99999999999999964e-6

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

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

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

Alternative 9: 51.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.67:\\ \;\;\;\;U - J \cdot {K}^{2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.67) (- U (* J (pow K 2.0))) (fma J (* l 2.0) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.67) {
		tmp = U - (J * pow(K, 2.0));
	} else {
		tmp = fma(J, (l * 2.0), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.67)
		tmp = Float64(U - Float64(J * (K ^ 2.0)));
	else
		tmp = fma(J, Float64(l * 2.0), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.67], N[(U - N[(J * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.67:\\
\;\;\;\;U - J \cdot {K}^{2}\\

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


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

    1. Initial program 89.6%

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

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

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

        \[\leadsto \color{blue}{\left(8 \cdot J + -1 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      2. mul-1-neg42.7%

        \[\leadsto \left(8 \cdot J + \color{blue}{\left(-J \cdot {K}^{2}\right)}\right) + U \]
      3. unsub-neg42.7%

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

        \[\leadsto \left(\color{blue}{J \cdot 8} - J \cdot {K}^{2}\right) + U \]
    5. Simplified42.7%

      \[\leadsto \color{blue}{\left(J \cdot 8 - J \cdot {K}^{2}\right)} + U \]
    6. Taylor expanded in K around inf 42.7%

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

        \[\leadsto \color{blue}{\left(-1 \cdot J\right) \cdot {K}^{2}} + U \]
      2. neg-mul-142.7%

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

        \[\leadsto \color{blue}{{K}^{2} \cdot \left(-J\right)} + U \]
    8. Simplified42.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
      4. *-commutative55.3%

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \ell\right)} + U \]
      5. fma-def55.3%

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

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot 2}, U\right) \]
    7. Simplified55.3%

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

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

Alternative 10: 62.9% accurate, 2.8× speedup?

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

\\
U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)
\end{array}
Derivation
  1. Initial program 85.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 60.8%

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

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

Alternative 11: 53.4% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(J, \ell \cdot 2, U\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (fma J (* l 2.0) U))
double code(double J, double l, double K, double U) {
	return fma(J, (l * 2.0), U);
}
function code(J, l, K, U)
	return fma(J, Float64(l * 2.0), U)
end
code[J_, l_, K_, U_] := N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(J, \ell \cdot 2, U\right)
\end{array}
Derivation
  1. Initial program 85.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 60.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot 2}, U\right) \]
  7. Simplified50.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
  8. Final simplification50.2%

    \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, U\right) \]

Alternative 12: 41.7% accurate, 43.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{+17} \lor \neg \left(\ell \leq 2.5 \cdot 10^{+16}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.2e17 or 2.5e16 < 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.1%

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

    if -5.2e17 < l < 2.5e16

    1. Initial program 71.2%

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

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

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

Alternative 13: 53.4% accurate, 44.6× speedup?

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

\\
U + J \cdot \left(\ell \cdot 2\right)
\end{array}
Derivation
  1. Initial program 85.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 60.8%

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

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

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

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

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

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

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

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

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

Alternative 14: 35.9% 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.6%

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification33.8%

    \[\leadsto U \]

Reproduce

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