Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.6% → 99.8%
Time: 17.2s
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.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0.04\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot t_0\right)\right) + \left(0.016666666666666666 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{5}\right)\right) + \left(0.3333333333333333 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{3}\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 0.04)))
     (+ (* (* t_1 J) (cos (/ K 2.0))) U)
     (+
      U
      (+
       (* 0.0003968253968253968 (* J (* (pow l 7.0) t_0)))
       (+
        (* 0.016666666666666666 (* J (* t_0 (pow l 5.0))))
        (+
         (* 0.3333333333333333 (* J (* t_0 (pow l 3.0))))
         (* 2.0 (* J (* l t_0))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 0.04)) {
		tmp = ((t_1 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + ((0.0003968253968253968 * (J * (pow(l, 7.0) * t_0))) + ((0.016666666666666666 * (J * (t_0 * pow(l, 5.0)))) + ((0.3333333333333333 * (J * (t_0 * pow(l, 3.0)))) + (2.0 * (J * (l * t_0))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 0.04)) {
		tmp = ((t_1 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + ((0.0003968253968253968 * (J * (Math.pow(l, 7.0) * t_0))) + ((0.016666666666666666 * (J * (t_0 * Math.pow(l, 5.0)))) + ((0.3333333333333333 * (J * (t_0 * Math.pow(l, 3.0)))) + (2.0 * (J * (l * t_0))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 0.04):
		tmp = ((t_1 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + ((0.0003968253968253968 * (J * (math.pow(l, 7.0) * t_0))) + ((0.016666666666666666 * (J * (t_0 * math.pow(l, 5.0)))) + ((0.3333333333333333 * (J * (t_0 * math.pow(l, 3.0)))) + (2.0 * (J * (l * t_0))))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 0.04))
		tmp = Float64(Float64(Float64(t_1 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(Float64(0.0003968253968253968 * Float64(J * Float64((l ^ 7.0) * t_0))) + Float64(Float64(0.016666666666666666 * Float64(J * Float64(t_0 * (l ^ 5.0)))) + Float64(Float64(0.3333333333333333 * Float64(J * Float64(t_0 * (l ^ 3.0)))) + Float64(2.0 * Float64(J * Float64(l * t_0)))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 0.04)))
		tmp = ((t_1 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + ((0.0003968253968253968 * (J * ((l ^ 7.0) * t_0))) + ((0.016666666666666666 * (J * (t_0 * (l ^ 5.0)))) + ((0.3333333333333333 * (J * (t_0 * (l ^ 3.0)))) + (2.0 * (J * (l * t_0))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 0.04]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(0.0003968253968253968 * N[(J * N[(N[Power[l, 7.0], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[(J * N[(t$95$0 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[(J * N[(t$95$0 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;U + \left(0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot t_0\right)\right) + \left(0.016666666666666666 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{5}\right)\right) + \left(0.3333333333333333 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{3}\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\right)\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 0.0400000000000000008 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

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

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

Alternative 2: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0.04\right):\\ \;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\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 0.04)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       J
       (*
        (cos (* K 0.5))
        (+
         (* 0.016666666666666666 (pow l 5.0))
         (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.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 <= 0.04)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (cos((K * 0.5)) * ((0.016666666666666666 * pow(l, 5.0)) + ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.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 <= 0.04)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (Math.cos((K * 0.5)) * ((0.016666666666666666 * Math.pow(l, 5.0)) + ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.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 <= 0.04):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (J * (math.cos((K * 0.5)) * ((0.016666666666666666 * math.pow(l, 5.0)) + ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.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 <= 0.04))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(J * Float64(cos(Float64(K * 0.5)) * Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.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 <= 0.04)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (J * (cos((K * 0.5)) * ((0.016666666666666666 * (l ^ 5.0)) + ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.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, 0.04]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.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 0.04\right):\\
\;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

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

    1. Initial program 100.0%

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

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

    1. Initial program 78.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*78.6%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Taylor expanded in l around 0 99.9%

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

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

Alternative 3: 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 0\right):\\ \;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{fma}\left(2, \ell, 0.3333333333333333 \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 0.0)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+
      U
      (*
       J
       (* (cos (* K 0.5)) (fma 2.0 l (* 0.3333333333333333 (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 <= 0.0)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (J * (cos((K * 0.5)) * fma(2.0, l, (0.3333333333333333 * 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 <= 0.0))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(J * Float64(cos(Float64(K * 0.5)) * fma(2.0, l, Float64(0.3333333333333333 * (l ^ 3.0))))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 * l + N[(0.3333333333333333 * 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 0\right):\\
\;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{fma}\left(2, \ell, 0.3333333333333333 \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 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    1. Initial program 78.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Taylor expanded in l around 0 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 \left(0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)} + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right) + U \]
      2. associate-*r*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 0.0)))
     (+ (* (* t_1 J) t_0) U)
     (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 0.0)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 0.0)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 0.0):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 0.0))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 0.0)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\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 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    1. Initial program 78.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Taylor expanded in l around 0 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 2 regimes into one program.
  4. Final simplification99.9%

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

Alternative 5: 97.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ t_1 := \left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \mathbf{if}\;\ell \leq -1.1 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -850:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.35:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+61}:\\ \;\;\;\;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 (* (* (cos (* K 0.5)) (pow l 5.0)) (* J 0.016666666666666666))))
   (if (<= l -1.1e+58)
     t_1
     (if (<= l -850.0)
       t_0
       (if (<= l 0.35)
         (+
          U
          (*
           (cos (/ K 2.0))
           (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
         (if (<= l 2.45e+61) 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 = (cos((K * 0.5)) * pow(l, 5.0)) * (J * 0.016666666666666666);
	double tmp;
	if (l <= -1.1e+58) {
		tmp = t_1;
	} else if (l <= -850.0) {
		tmp = t_0;
	} else if (l <= 0.35) {
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.45e+61) {
		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 = (cos((k * 0.5d0)) * (l ** 5.0d0)) * (j * 0.016666666666666666d0)
    if (l <= (-1.1d+58)) then
        tmp = t_1
    else if (l <= (-850.0d0)) then
        tmp = t_0
    else if (l <= 0.35d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    else if (l <= 2.45d+61) 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 = (Math.cos((K * 0.5)) * Math.pow(l, 5.0)) * (J * 0.016666666666666666);
	double tmp;
	if (l <= -1.1e+58) {
		tmp = t_1;
	} else if (l <= -850.0) {
		tmp = t_0;
	} else if (l <= 0.35) {
		tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.45e+61) {
		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 = (math.cos((K * 0.5)) * math.pow(l, 5.0)) * (J * 0.016666666666666666)
	tmp = 0
	if l <= -1.1e+58:
		tmp = t_1
	elif l <= -850.0:
		tmp = t_0
	elif l <= 0.35:
		tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	elif l <= 2.45e+61:
		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(Float64(cos(Float64(K * 0.5)) * (l ^ 5.0)) * Float64(J * 0.016666666666666666))
	tmp = 0.0
	if (l <= -1.1e+58)
		tmp = t_1;
	elseif (l <= -850.0)
		tmp = t_0;
	elseif (l <= 0.35)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	elseif (l <= 2.45e+61)
		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 = (cos((K * 0.5)) * (l ^ 5.0)) * (J * 0.016666666666666666);
	tmp = 0.0;
	if (l <= -1.1e+58)
		tmp = t_1;
	elseif (l <= -850.0)
		tmp = t_0;
	elseif (l <= 0.35)
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	elseif (l <= 2.45e+61)
		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[(N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * N[(J * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.1e+58], t$95$1, If[LessEqual[l, -850.0], t$95$0, If[LessEqual[l, 0.35], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.45e+61], 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 := \left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\
\mathbf{if}\;\ell \leq -1.1 \cdot 10^{+58}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.1e58 or 2.45000000000000013e61 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Taylor expanded in l around 0 99.1%

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

      \[\leadsto \color{blue}{0.016666666666666666 \cdot \left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative99.1%

        \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 0.016666666666666666} \]
      2. *-commutative99.1%

        \[\leadsto \color{blue}{\left(\left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)} \cdot 0.016666666666666666 \]
      3. associate-*l*99.1%

        \[\leadsto \color{blue}{\left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(J \cdot 0.016666666666666666\right)} \]
    7. Simplified99.1%

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

    if -1.1e58 < l < -850 or 0.34999999999999998 < l < 2.45000000000000013e61

    1. Initial program 100.0%

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

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

    if -850 < l < 0.34999999999999998

    1. Initial program 78.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 98.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 simplification95.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.1 \cdot 10^{+58}:\\ \;\;\;\;\left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \mathbf{elif}\;\ell \leq -850:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.35:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.45 \cdot 10^{+61}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;\left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \end{array} \]

Alternative 6: 97.0% 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 := \left(t_1 \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \mathbf{if}\;\ell \leq -1.02 \cdot 10^{+58}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -850:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.0145:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_1\right)\right)\\ \mathbf{elif}\;\ell \leq 4.45 \cdot 10^{+61}:\\ \;\;\;\;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 (* (* t_1 (pow l 5.0)) (* J 0.016666666666666666))))
   (if (<= l -1.02e+58)
     t_2
     (if (<= l -850.0)
       t_0
       (if (<= l 0.0145)
         (+ U (* 2.0 (* J (* l t_1))))
         (if (<= l 4.45e+61) 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 = (t_1 * pow(l, 5.0)) * (J * 0.016666666666666666);
	double tmp;
	if (l <= -1.02e+58) {
		tmp = t_2;
	} else if (l <= -850.0) {
		tmp = t_0;
	} else if (l <= 0.0145) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 4.45e+61) {
		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 = (t_1 * (l ** 5.0d0)) * (j * 0.016666666666666666d0)
    if (l <= (-1.02d+58)) then
        tmp = t_2
    else if (l <= (-850.0d0)) then
        tmp = t_0
    else if (l <= 0.0145d0) then
        tmp = u + (2.0d0 * (j * (l * t_1)))
    else if (l <= 4.45d+61) 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 = (t_1 * Math.pow(l, 5.0)) * (J * 0.016666666666666666);
	double tmp;
	if (l <= -1.02e+58) {
		tmp = t_2;
	} else if (l <= -850.0) {
		tmp = t_0;
	} else if (l <= 0.0145) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 4.45e+61) {
		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 = (t_1 * math.pow(l, 5.0)) * (J * 0.016666666666666666)
	tmp = 0
	if l <= -1.02e+58:
		tmp = t_2
	elif l <= -850.0:
		tmp = t_0
	elif l <= 0.0145:
		tmp = U + (2.0 * (J * (l * t_1)))
	elif l <= 4.45e+61:
		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(Float64(t_1 * (l ^ 5.0)) * Float64(J * 0.016666666666666666))
	tmp = 0.0
	if (l <= -1.02e+58)
		tmp = t_2;
	elseif (l <= -850.0)
		tmp = t_0;
	elseif (l <= 0.0145)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_1))));
	elseif (l <= 4.45e+61)
		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 = (t_1 * (l ^ 5.0)) * (J * 0.016666666666666666);
	tmp = 0.0;
	if (l <= -1.02e+58)
		tmp = t_2;
	elseif (l <= -850.0)
		tmp = t_0;
	elseif (l <= 0.0145)
		tmp = U + (2.0 * (J * (l * t_1)));
	elseif (l <= 4.45e+61)
		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[(N[(t$95$1 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * N[(J * 0.016666666666666666), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.02e+58], t$95$2, If[LessEqual[l, -850.0], t$95$0, If[LessEqual[l, 0.0145], N[(U + N[(2.0 * N[(J * N[(l * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 4.45e+61], 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 := \left(t_1 \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\
\mathbf{if}\;\ell \leq -1.02 \cdot 10^{+58}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;\ell \leq 0.0145:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_1\right)\right)\\

\mathbf{elif}\;\ell \leq 4.45 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.02000000000000005e58 or 4.45000000000000002e61 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Taylor expanded in l around 0 99.1%

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

      \[\leadsto \color{blue}{0.016666666666666666 \cdot \left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative99.1%

        \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 0.016666666666666666} \]
      2. *-commutative99.1%

        \[\leadsto \color{blue}{\left(\left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)} \cdot 0.016666666666666666 \]
      3. associate-*l*99.1%

        \[\leadsto \color{blue}{\left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \left(J \cdot 0.016666666666666666\right)} \]
    7. Simplified99.1%

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

    if -1.02000000000000005e58 < l < -850 or 0.0145000000000000007 < l < 4.45000000000000002e61

    1. Initial program 100.0%

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

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

    if -850 < l < 0.0145000000000000007

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.02 \cdot 10^{+58}:\\ \;\;\;\;\left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \mathbf{elif}\;\ell \leq -850:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.0145:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 4.45 \cdot 10^{+61}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;\left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{5}\right) \cdot \left(J \cdot 0.016666666666666666\right)\\ \end{array} \]

Alternative 7: 87.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -850 \lor \neg \left(\ell \leq 0.0128\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 -850.0) (not (<= l 0.0128)))
   (+ (* (- (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 <= -850.0) || !(l <= 0.0128)) {
		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 <= (-850.0d0)) .or. (.not. (l <= 0.0128d0))) 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 <= -850.0) || !(l <= 0.0128)) {
		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 <= -850.0) or not (l <= 0.0128):
		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 <= -850.0) || !(l <= 0.0128))
		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 <= -850.0) || ~((l <= 0.0128)))
		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, -850.0], N[Not[LessEqual[l, 0.0128]], $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 -850 \lor \neg \left(\ell \leq 0.0128\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 < -850 or 0.0128000000000000006 < l

    1. Initial program 100.0%

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

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

    if -850 < l < 0.0128000000000000006

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -850 \lor \neg \left(\ell \leq 0.0128\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 8: 64.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{if}\;\ell \leq -5.2 \cdot 10^{+164}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -9.5 \cdot 10^{+33}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 980 \lor \neg \left(\ell \leq 1.7 \cdot 10^{+226}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
   (if (<= l -5.2e+164)
     t_0
     (if (<= l -9.5e+33)
       (pow U -3.0)
       (if (or (<= l 980.0) (not (<= l 1.7e+226))) t_0 (log1p (expm1 U)))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * cos((K * 0.5)))));
	double tmp;
	if (l <= -5.2e+164) {
		tmp = t_0;
	} else if (l <= -9.5e+33) {
		tmp = pow(U, -3.0);
	} else if ((l <= 980.0) || !(l <= 1.7e+226)) {
		tmp = t_0;
	} else {
		tmp = log1p(expm1(U));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	double tmp;
	if (l <= -5.2e+164) {
		tmp = t_0;
	} else if (l <= -9.5e+33) {
		tmp = Math.pow(U, -3.0);
	} else if ((l <= 980.0) || !(l <= 1.7e+226)) {
		tmp = t_0;
	} else {
		tmp = Math.log1p(Math.expm1(U));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	tmp = 0
	if l <= -5.2e+164:
		tmp = t_0
	elif l <= -9.5e+33:
		tmp = math.pow(U, -3.0)
	elif (l <= 980.0) or not (l <= 1.7e+226):
		tmp = t_0
	else:
		tmp = math.log1p(math.expm1(U))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))))
	tmp = 0.0
	if (l <= -5.2e+164)
		tmp = t_0;
	elseif (l <= -9.5e+33)
		tmp = U ^ -3.0;
	elseif ((l <= 980.0) || !(l <= 1.7e+226))
		tmp = t_0;
	else
		tmp = log1p(expm1(U));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.2e+164], t$95$0, If[LessEqual[l, -9.5e+33], N[Power[U, -3.0], $MachinePrecision], If[Or[LessEqual[l, 980.0], N[Not[LessEqual[l, 1.7e+226]], $MachinePrecision]], t$95$0, N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{+164}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -9.5 \cdot 10^{+33}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 980 \lor \neg \left(\ell \leq 1.7 \cdot 10^{+226}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.1999999999999998e164 or -9.5000000000000003e33 < l < 980 or 1.69999999999999989e226 < l

    1. Initial program 84.9%

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

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

    if -5.1999999999999998e164 < l < -9.5000000000000003e33

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

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

    if 980 < l < 1.69999999999999989e226

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{+164}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -9.5 \cdot 10^{+33}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 980 \lor \neg \left(\ell \leq 1.7 \cdot 10^{+226}\right):\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \end{array} \]

Alternative 9: 43.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 - U \cdot U\\ \mathbf{if}\;\ell \leq -2.05 \cdot 10^{+104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -2.5 \cdot 10^{+40}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -820:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 2.9 \cdot 10^{+119} \lor \neg \left(\ell \leq 8.2 \cdot 10^{+174}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-3}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- -4.0 (* U U))))
   (if (<= l -2.05e+104)
     t_0
     (if (<= l -2.5e+40)
       (pow U -3.0)
       (if (<= l -820.0)
         t_0
         (if (<= l 7200000.0)
           U
           (if (or (<= l 2.9e+119) (not (<= l 8.2e+174)))
             (* U U)
             (pow U -3.0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (U * U);
	double tmp;
	if (l <= -2.05e+104) {
		tmp = t_0;
	} else if (l <= -2.5e+40) {
		tmp = pow(U, -3.0);
	} else if (l <= -820.0) {
		tmp = t_0;
	} else if (l <= 7200000.0) {
		tmp = U;
	} else if ((l <= 2.9e+119) || !(l <= 8.2e+174)) {
		tmp = U * U;
	} else {
		tmp = pow(U, -3.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-4.0d0) - (u * u)
    if (l <= (-2.05d+104)) then
        tmp = t_0
    else if (l <= (-2.5d+40)) then
        tmp = u ** (-3.0d0)
    else if (l <= (-820.0d0)) then
        tmp = t_0
    else if (l <= 7200000.0d0) then
        tmp = u
    else if ((l <= 2.9d+119) .or. (.not. (l <= 8.2d+174))) then
        tmp = u * u
    else
        tmp = u ** (-3.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (U * U);
	double tmp;
	if (l <= -2.05e+104) {
		tmp = t_0;
	} else if (l <= -2.5e+40) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= -820.0) {
		tmp = t_0;
	} else if (l <= 7200000.0) {
		tmp = U;
	} else if ((l <= 2.9e+119) || !(l <= 8.2e+174)) {
		tmp = U * U;
	} else {
		tmp = Math.pow(U, -3.0);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = -4.0 - (U * U)
	tmp = 0
	if l <= -2.05e+104:
		tmp = t_0
	elif l <= -2.5e+40:
		tmp = math.pow(U, -3.0)
	elif l <= -820.0:
		tmp = t_0
	elif l <= 7200000.0:
		tmp = U
	elif (l <= 2.9e+119) or not (l <= 8.2e+174):
		tmp = U * U
	else:
		tmp = math.pow(U, -3.0)
	return tmp
function code(J, l, K, U)
	t_0 = Float64(-4.0 - Float64(U * U))
	tmp = 0.0
	if (l <= -2.05e+104)
		tmp = t_0;
	elseif (l <= -2.5e+40)
		tmp = U ^ -3.0;
	elseif (l <= -820.0)
		tmp = t_0;
	elseif (l <= 7200000.0)
		tmp = U;
	elseif ((l <= 2.9e+119) || !(l <= 8.2e+174))
		tmp = Float64(U * U);
	else
		tmp = U ^ -3.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = -4.0 - (U * U);
	tmp = 0.0;
	if (l <= -2.05e+104)
		tmp = t_0;
	elseif (l <= -2.5e+40)
		tmp = U ^ -3.0;
	elseif (l <= -820.0)
		tmp = t_0;
	elseif (l <= 7200000.0)
		tmp = U;
	elseif ((l <= 2.9e+119) || ~((l <= 8.2e+174)))
		tmp = U * U;
	else
		tmp = U ^ -3.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.05e+104], t$95$0, If[LessEqual[l, -2.5e+40], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, -820.0], t$95$0, If[LessEqual[l, 7200000.0], U, If[Or[LessEqual[l, 2.9e+119], N[Not[LessEqual[l, 8.2e+174]], $MachinePrecision]], N[(U * U), $MachinePrecision], N[Power[U, -3.0], $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 - U \cdot U\\
\mathbf{if}\;\ell \leq -2.05 \cdot 10^{+104}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -2.5 \cdot 10^{+40}:\\
\;\;\;\;{U}^{-3}\\

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

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

\mathbf{elif}\;\ell \leq 2.9 \cdot 10^{+119} \lor \neg \left(\ell \leq 8.2 \cdot 10^{+174}\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.04999999999999992e104 or -2.50000000000000002e40 < l < -820

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

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

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

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

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

    if -2.04999999999999992e104 < l < -2.50000000000000002e40 or 2.90000000000000007e119 < l < 8.20000000000000061e174

    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-rr42.4%

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

    if -820 < l < 7.2e6

    1. Initial program 79.0%

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

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

    if 7.2e6 < l < 2.90000000000000007e119 or 8.20000000000000061e174 < 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-rr28.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.05 \cdot 10^{+104}:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq -2.5 \cdot 10^{+40}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq -820:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 2.9 \cdot 10^{+119} \lor \neg \left(\ell \leq 8.2 \cdot 10^{+174}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-3}\\ \end{array} \]

Alternative 10: 63.7% 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 90.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 61.6%

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

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

Alternative 11: 44.1% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 - U \cdot U\\ \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1.55 \cdot 10^{+26}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq -800:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- -4.0 (* U U))))
   (if (<= l -4.8e+104)
     t_0
     (if (<= l -1.55e+26)
       (pow U -4.0)
       (if (<= l -800.0) t_0 (if (<= l 7200000.0) U (* U U)))))))
double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (U * U);
	double tmp;
	if (l <= -4.8e+104) {
		tmp = t_0;
	} else if (l <= -1.55e+26) {
		tmp = pow(U, -4.0);
	} else if (l <= -800.0) {
		tmp = t_0;
	} else if (l <= 7200000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-4.0d0) - (u * u)
    if (l <= (-4.8d+104)) then
        tmp = t_0
    else if (l <= (-1.55d+26)) then
        tmp = u ** (-4.0d0)
    else if (l <= (-800.0d0)) then
        tmp = t_0
    else if (l <= 7200000.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = -4.0 - (U * U);
	double tmp;
	if (l <= -4.8e+104) {
		tmp = t_0;
	} else if (l <= -1.55e+26) {
		tmp = Math.pow(U, -4.0);
	} else if (l <= -800.0) {
		tmp = t_0;
	} else if (l <= 7200000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = -4.0 - (U * U)
	tmp = 0
	if l <= -4.8e+104:
		tmp = t_0
	elif l <= -1.55e+26:
		tmp = math.pow(U, -4.0)
	elif l <= -800.0:
		tmp = t_0
	elif l <= 7200000.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	t_0 = Float64(-4.0 - Float64(U * U))
	tmp = 0.0
	if (l <= -4.8e+104)
		tmp = t_0;
	elseif (l <= -1.55e+26)
		tmp = U ^ -4.0;
	elseif (l <= -800.0)
		tmp = t_0;
	elseif (l <= 7200000.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = -4.0 - (U * U);
	tmp = 0.0;
	if (l <= -4.8e+104)
		tmp = t_0;
	elseif (l <= -1.55e+26)
		tmp = U ^ -4.0;
	elseif (l <= -800.0)
		tmp = t_0;
	elseif (l <= 7200000.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.8e+104], t$95$0, If[LessEqual[l, -1.55e+26], N[Power[U, -4.0], $MachinePrecision], If[LessEqual[l, -800.0], t$95$0, If[LessEqual[l, 7200000.0], U, N[(U * U), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 - U \cdot U\\
\mathbf{if}\;\ell \leq -4.8 \cdot 10^{+104}:\\
\;\;\;\;t_0\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.8e104 or -1.55e26 < l < -800

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

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

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

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    6. Simplified30.3%

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

    if -4.8e104 < l < -1.55e26

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

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

    if -800 < l < 7.2e6

    1. Initial program 79.0%

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

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

    if 7.2e6 < 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-rr24.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+104}:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq -1.55 \cdot 10^{+26}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{elif}\;\ell \leq -800:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 12: 43.1% accurate, 43.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.7999999999999996e84 or 7.2e6 < l

    1. Initial program 100.0%

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

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

    if -6.7999999999999996e84 < l < 7.2e6

    1. Initial program 81.1%

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

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

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

Alternative 13: 43.5% accurate, 43.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -620:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -620.0) (- -4.0 (* U U)) (if (<= l 7200000.0) U (* U U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -620.0) {
		tmp = -4.0 - (U * U);
	} else if (l <= 7200000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-620.0d0)) then
        tmp = (-4.0d0) - (u * u)
    else if (l <= 7200000.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -620.0) {
		tmp = -4.0 - (U * U);
	} else if (l <= 7200000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -620.0:
		tmp = -4.0 - (U * U)
	elif l <= 7200000.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -620.0)
		tmp = Float64(-4.0 - Float64(U * U));
	elseif (l <= 7200000.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -620.0)
		tmp = -4.0 - (U * U);
	elseif (l <= 7200000.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -620.0], N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7200000.0], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

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

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

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

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

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    6. Simplified25.3%

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

    if -620 < l < 7.2e6

    1. Initial program 79.0%

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

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

    if 7.2e6 < 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-rr24.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -620:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq 7200000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 14: 37.8% 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 90.0%

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

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

    \[\leadsto U \]

Reproduce

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