Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.4% → 99.7%
Time: 13.1s
Alternatives: 19
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 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.4% 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 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(2 \cdot \left(\ell \cdot J\right) + \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e-10)))
     (+ (* t_0 (* t_1 J)) U)
     (+
      U
      (*
       t_0
       (+
        (* 2.0 (* l J))
        (+
         (* 0.3333333333333333 (* J (pow l 3.0)))
         (* 0.016666666666666666 (* J (pow l 5.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 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * ((2.0 * (l * J)) + ((0.3333333333333333 * (J * pow(l, 3.0))) + (0.016666666666666666 * (J * pow(l, 5.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 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * ((2.0 * (l * J)) + ((0.3333333333333333 * (J * Math.pow(l, 3.0))) + (0.016666666666666666 * (J * Math.pow(l, 5.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 <= 1e-10):
		tmp = (t_0 * (t_1 * J)) + U
	else:
		tmp = U + (t_0 * ((2.0 * (l * J)) + ((0.3333333333333333 * (J * math.pow(l, 3.0))) + (0.016666666666666666 * (J * math.pow(l, 5.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 <= 1e-10))
		tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(Float64(2.0 * Float64(l * J)) + Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))) + Float64(0.016666666666666666 * Float64(J * (l ^ 5.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 <= 1e-10)))
		tmp = (t_0 * (t_1 * J)) + U;
	else
		tmp = U + (t_0 * ((2.0 * (l * J)) + ((0.3333333333333333 * (J * (l ^ 3.0))) + (0.016666666666666666 * (J * (l ^ 5.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, 1e-10]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(2 \cdot \left(\ell \cdot J\right) + \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\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 1.00000000000000004e-10 < (-.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))) < 1.00000000000000004e-10

    1. Initial program 69.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 \left(J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + 2 \cdot \ell\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. Step-by-step derivation
      1. associate-+r+99.9%

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

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

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

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

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

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

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

Alternative 2: 99.7% 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 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e-10)))
     (+ (* t_0 (* t_1 J)) U)
     (+
      U
      (*
       t_0
       (*
        J
        (+
         (* 0.3333333333333333 (pow l 3.0))
         (+ (* 0.016666666666666666 (pow l 5.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 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + ((0.016666666666666666 * pow(l, 5.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 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + ((0.016666666666666666 * Math.pow(l, 5.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 <= 1e-10):
		tmp = (t_0 * (t_1 * J)) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + ((0.016666666666666666 * math.pow(l, 5.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 <= 1e-10))
		tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(Float64(0.016666666666666666 * (l ^ 5.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 <= 1e-10)))
		tmp = (t_0 * (t_1 * J)) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + ((0.016666666666666666 * (l ^ 5.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, 1e-10]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$0 * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $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 10^{-10}\right):\\
\;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + \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 1.00000000000000004e-10 < (-.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))) < 1.00000000000000004e-10

    1. Initial program 69.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 \left(J \cdot \color{blue}{\left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + 2 \cdot \ell\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

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

Alternative 3: 99.8% accurate, 0.4× speedup?

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

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

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

    1. Initial program 99.9%

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

    if -2e-3 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000004e-10

    1. Initial program 69.2%

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + 0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) + U \]
      7. associate-*r*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(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) + U \]
      8. *-commutative99.9%

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + 0.3333333333333333 \cdot \color{blue}{\left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)}\right) + U \]
      9. associate-*r*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 \]
      10. 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 \]
      11. +-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 \]
      12. fma-def99.9%

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

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

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

Alternative 4: 99.8% 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 -0.002 \lor \neg \left(t_1 \leq 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + 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 -0.002) (not (<= t_1 1e-10)))
     (+ (* t_0 (* t_1 J)) 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 <= -0.002) || !(t_1 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-0.002d0)) .or. (.not. (t_1 <= 1d-10))) then
        tmp = (t_0 * (t_1 * j)) + u
    else
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -0.002) || !(t_1 <= 1e-10)) {
		tmp = (t_0 * (t_1 * J)) + 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 <= -0.002) or not (t_1 <= 1e-10):
		tmp = (t_0 * (t_1 * J)) + 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 <= -0.002) || !(t_1 <= 1e-10))
		tmp = Float64(Float64(t_0 * Float64(t_1 * J)) + 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 <= -0.002) || ~((t_1 <= 1e-10)))
		tmp = (t_0 * (t_1 * J)) + 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, -0.002], N[Not[LessEqual[t$95$1, 1e-10]], $MachinePrecision]], N[(N[(t$95$0 * N[(t$95$1 * J), $MachinePrecision]), $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 -0.002 \lor \neg \left(t_1 \leq 10^{-10}\right):\\
\;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + 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))) < -2e-3 or 1.00000000000000004e-10 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 99.9%

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

    if -2e-3 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1.00000000000000004e-10

    1. Initial program 69.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -0.002 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 10^{-10}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\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: 95.2% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.3:\\
\;\;\;\;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 4.2 \cdot 10^{+61}:\\
\;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5 or 4.2000000000000002e61 < 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 96.1%

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

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

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

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

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

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

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

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

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

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

    if -5 < l < 3.2999999999999998

    1. Initial program 69.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.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 \]

    if 3.2999999999999998 < l < 4.2000000000000002e61

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 3.3:\\ \;\;\;\;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 4.2 \cdot 10^{+61}:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 95.1% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 0.21:\\
\;\;\;\;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 1.65 \cdot 10^{+53}:\\
\;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5 or 1.6500000000000001e53 < 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 94.8%

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

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

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

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

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

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

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

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

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

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

    if -5 < l < 0.209999999999999992

    1. Initial program 69.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.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 \]

    if 0.209999999999999992 < l < 1.6500000000000001e53

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 0.21:\\ \;\;\;\;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 1.65 \cdot 10^{+53}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 7: 94.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot t_0\right)\\ \mathbf{if}\;\ell \leq -3.3:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 0.00039:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+53}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5)))
        (t_1 (+ U (* (* J (pow l 5.0)) (* 0.016666666666666666 t_0)))))
   (if (<= l -3.3)
     t_1
     (if (<= l 0.00039)
       (+ U (* J (* 2.0 (* l t_0))))
       (if (<= l 1.65e+53) (+ U (* (- (exp l) (exp (- l))) J)) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + ((J * pow(l, 5.0)) * (0.016666666666666666 * t_0));
	double tmp;
	if (l <= -3.3) {
		tmp = t_1;
	} else if (l <= 0.00039) {
		tmp = U + (J * (2.0 * (l * t_0)));
	} else if (l <= 1.65e+53) {
		tmp = U + ((exp(l) - exp(-l)) * J);
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    t_1 = u + ((j * (l ** 5.0d0)) * (0.016666666666666666d0 * t_0))
    if (l <= (-3.3d0)) then
        tmp = t_1
    else if (l <= 0.00039d0) then
        tmp = u + (j * (2.0d0 * (l * t_0)))
    else if (l <= 1.65d+53) then
        tmp = u + ((exp(l) - exp(-l)) * j)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + ((J * Math.pow(l, 5.0)) * (0.016666666666666666 * t_0));
	double tmp;
	if (l <= -3.3) {
		tmp = t_1;
	} else if (l <= 0.00039) {
		tmp = U + (J * (2.0 * (l * t_0)));
	} else if (l <= 1.65e+53) {
		tmp = U + ((Math.exp(l) - Math.exp(-l)) * J);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U + ((J * math.pow(l, 5.0)) * (0.016666666666666666 * t_0))
	tmp = 0
	if l <= -3.3:
		tmp = t_1
	elif l <= 0.00039:
		tmp = U + (J * (2.0 * (l * t_0)))
	elif l <= 1.65e+53:
		tmp = U + ((math.exp(l) - math.exp(-l)) * J)
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U + Float64(Float64(J * (l ^ 5.0)) * Float64(0.016666666666666666 * t_0)))
	tmp = 0.0
	if (l <= -3.3)
		tmp = t_1;
	elseif (l <= 0.00039)
		tmp = Float64(U + Float64(J * Float64(2.0 * Float64(l * t_0))));
	elseif (l <= 1.65e+53)
		tmp = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = U + ((J * (l ^ 5.0)) * (0.016666666666666666 * t_0));
	tmp = 0.0;
	if (l <= -3.3)
		tmp = t_1;
	elseif (l <= 0.00039)
		tmp = U + (J * (2.0 * (l * t_0)));
	elseif (l <= 1.65e+53)
		tmp = U + ((exp(l) - exp(-l)) * J);
	else
		tmp = t_1;
	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[(U + N[(N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * N[(0.016666666666666666 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.3], t$95$1, If[LessEqual[l, 0.00039], N[(U + N[(J * N[(2.0 * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.65e+53], N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot t_0\right)\\
\mathbf{if}\;\ell \leq -3.3:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.2999999999999998 or 1.6500000000000001e53 < 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 94.8%

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

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

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

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

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

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

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

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

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

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

    if -3.2999999999999998 < l < 3.89999999999999993e-4

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + 0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) + U \]
      7. associate-*r*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(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{3}\right)\right) + U \]
      8. *-commutative99.9%

        \[\leadsto J \cdot \left(\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right) + 0.3333333333333333 \cdot \color{blue}{\left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)}\right) + U \]
      9. associate-*r*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 \]
      10. 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 \]
      11. +-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 \]
      12. fma-def99.9%

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

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

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

    if 3.89999999999999993e-4 < l < 1.6500000000000001e53

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 0.00039:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+53}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 8: 78.8% accurate, 1.4× speedup?

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

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


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

    1. Initial program 91.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 87.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.23499999999999999 < (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 90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 81.1% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq -2.2 \cdot 10^{+107} \lor \neg \left(J \leq 3250000\right):\\
\;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -2.2e107 or 3.25e6 < J

    1. Initial program 72.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 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.2e107 < J < 3.25e6

    1. Initial program 96.9%

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

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

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

Alternative 10: 47.3% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := U + {K}^{4} \cdot \left(J \cdot -0.0013020833333333333\right)\\
\mathbf{if}\;\ell \leq -1.7 \cdot 10^{+271}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -650:\\
\;\;\;\;{U}^{-8}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.70000000000000013e271 or 420 < 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-rr2.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\left(\color{blue}{\left(K \cdot K\right)} \cdot 0.0625 + -0.5\right) + -0.0013020833333333333 \cdot {K}^{4}\right) + U \]
      9. *-commutative13.5%

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

      \[\leadsto \color{blue}{J \cdot \left(\left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right) + {K}^{4} \cdot -0.0013020833333333333\right)} + U \]
    6. Taylor expanded in K around inf 33.2%

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

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

        \[\leadsto \color{blue}{{K}^{4} \cdot \left(J \cdot -0.0013020833333333333\right)} + U \]
    8. Simplified32.3%

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

    if -1.70000000000000013e271 < l < -650

    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-rr38.1%

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

    if -650 < l < 420

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.7 \cdot 10^{+271}:\\ \;\;\;\;U + {K}^{4} \cdot \left(J \cdot -0.0013020833333333333\right)\\ \mathbf{elif}\;\ell \leq -650:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 420:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U + {K}^{4} \cdot \left(J \cdot -0.0013020833333333333\right)\\ \end{array} \]

Alternative 11: 64.4% accurate, 2.8× speedup?

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

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\left(0.3333333333333333 \cdot {\ell}^{3} + 0.016666666666666666 \cdot {\ell}^{5}\right) + 2 \cdot \ell\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. +-commutative93.6%

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

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

      \[\leadsto \left(J \cdot \mathsf{fma}\left(2, \ell, \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 0.016666666666666666 \cdot {\ell}^{5}\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Simplified93.6%

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

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

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

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

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

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

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

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

Alternative 12: 64.4% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 46.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{if}\;\ell \leq -1.45 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -510:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* (* K K) -64.0) 512.0)))))
   (if (<= l -1.45e+269)
     t_0
     (if (<= l -510.0) (pow U -8.0) (if (<= l 7.4e-19) U t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double tmp;
	if (l <= -1.45e+269) {
		tmp = t_0;
	} else if (l <= -510.0) {
		tmp = pow(U, -8.0);
	} else if (l <= 7.4e-19) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (((k * k) * (-64.0d0)) + 512.0d0))
    if (l <= (-1.45d+269)) then
        tmp = t_0
    else if (l <= (-510.0d0)) then
        tmp = u ** (-8.0d0)
    else if (l <= 7.4d-19) then
        tmp = u
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double tmp;
	if (l <= -1.45e+269) {
		tmp = t_0;
	} else if (l <= -510.0) {
		tmp = Math.pow(U, -8.0);
	} else if (l <= 7.4e-19) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (((K * K) * -64.0) + 512.0))
	tmp = 0
	if l <= -1.45e+269:
		tmp = t_0
	elif l <= -510.0:
		tmp = math.pow(U, -8.0)
	elif l <= 7.4e-19:
		tmp = U
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * -64.0) + 512.0)))
	tmp = 0.0
	if (l <= -1.45e+269)
		tmp = t_0;
	elseif (l <= -510.0)
		tmp = U ^ -8.0;
	elseif (l <= 7.4e-19)
		tmp = U;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	tmp = 0.0;
	if (l <= -1.45e+269)
		tmp = t_0;
	elseif (l <= -510.0)
		tmp = U ^ -8.0;
	elseif (l <= 7.4e-19)
		tmp = U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * -64.0), $MachinePrecision] + 512.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.45e+269], t$95$0, If[LessEqual[l, -510.0], N[Power[U, -8.0], $MachinePrecision], If[LessEqual[l, 7.4e-19], U, t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\
\mathbf{if}\;\ell \leq -1.45 \cdot 10^{+269}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -510:\\
\;\;\;\;{U}^{-8}\\

\mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.45000000000000013e269 or 7.40000000000000011e-19 < l

    1. Initial program 99.4%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-64 \cdot {K}^{2}\right) \cdot J} + 512 \cdot J\right) + U \]
      2. distribute-rgt-out27.5%

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

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot -64} + 512\right) + U \]
      4. unpow227.5%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -64 + 512\right) + U \]
    5. Simplified27.5%

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

    if -1.45000000000000013e269 < l < -510

    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-rr38.1%

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

    if -510 < l < 7.40000000000000011e-19

    1. Initial program 69.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.45 \cdot 10^{+269}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -510:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \end{array} \]

Alternative 14: 45.2% accurate, 18.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1850000000000:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* (* K K) -64.0) 512.0)))))
   (if (<= l -1.3e+269)
     t_0
     (if (<= l -1850000000000.0)
       (+ U (* J (+ (* (* K K) 0.0625) -0.5)))
       (if (<= l 7.4e-19) U t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double tmp;
	if (l <= -1.3e+269) {
		tmp = t_0;
	} else if (l <= -1850000000000.0) {
		tmp = U + (J * (((K * K) * 0.0625) + -0.5));
	} else if (l <= 7.4e-19) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (((k * k) * (-64.0d0)) + 512.0d0))
    if (l <= (-1.3d+269)) then
        tmp = t_0
    else if (l <= (-1850000000000.0d0)) then
        tmp = u + (j * (((k * k) * 0.0625d0) + (-0.5d0)))
    else if (l <= 7.4d-19) then
        tmp = u
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double tmp;
	if (l <= -1.3e+269) {
		tmp = t_0;
	} else if (l <= -1850000000000.0) {
		tmp = U + (J * (((K * K) * 0.0625) + -0.5));
	} else if (l <= 7.4e-19) {
		tmp = U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (((K * K) * -64.0) + 512.0))
	tmp = 0
	if l <= -1.3e+269:
		tmp = t_0
	elif l <= -1850000000000.0:
		tmp = U + (J * (((K * K) * 0.0625) + -0.5))
	elif l <= 7.4e-19:
		tmp = U
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * -64.0) + 512.0)))
	tmp = 0.0
	if (l <= -1.3e+269)
		tmp = t_0;
	elseif (l <= -1850000000000.0)
		tmp = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * 0.0625) + -0.5)));
	elseif (l <= 7.4e-19)
		tmp = U;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	tmp = 0.0;
	if (l <= -1.3e+269)
		tmp = t_0;
	elseif (l <= -1850000000000.0)
		tmp = U + (J * (((K * K) * 0.0625) + -0.5));
	elseif (l <= 7.4e-19)
		tmp = U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * -64.0), $MachinePrecision] + 512.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.3e+269], t$95$0, If[LessEqual[l, -1850000000000.0], N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * 0.0625), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.4e-19], U, t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\
\mathbf{if}\;\ell \leq -1.3 \cdot 10^{+269}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.3e269 or 7.40000000000000011e-19 < l

    1. Initial program 99.4%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-64 \cdot {K}^{2}\right) \cdot J} + 512 \cdot J\right) + U \]
      2. distribute-rgt-out27.5%

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

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot -64} + 512\right) + U \]
      4. unpow227.5%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -64 + 512\right) + U \]
    5. Simplified27.5%

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

    if -1.3e269 < l < -1.85e12

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if -1.85e12 < l < 7.40000000000000011e-19

    1. Initial program 70.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+269}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -1850000000000:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \end{array} \]

Alternative 15: 44.3% accurate, 20.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -120000000 \lor \neg \left(\ell \leq 7.4 \cdot 10^{-19}\right):\\
\;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.2e8 or 7.40000000000000011e-19 < l

    1. Initial program 99.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-64 \cdot {K}^{2}\right) \cdot J} + 512 \cdot J\right) + U \]
      2. distribute-rgt-out21.5%

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

        \[\leadsto J \cdot \left(\color{blue}{{K}^{2} \cdot -64} + 512\right) + U \]
      4. unpow221.5%

        \[\leadsto J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -64 + 512\right) + U \]
    5. Simplified21.5%

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

    if -1.2e8 < l < 7.40000000000000011e-19

    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 J around 0 67.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -120000000 \lor \neg \left(\ell \leq 7.4 \cdot 10^{-19}\right):\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 16: 42.3% accurate, 43.8× speedup?

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

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

\mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-11}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.35e8 or 2.6000000000000001e-11 < l

    1. Initial program 99.6%

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

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

    if -1.35e8 < l < 2.6000000000000001e-11

    1. Initial program 70.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -135000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-11}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 17: 42.2% accurate, 43.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -8.6 \cdot 10^{+15}:\\
\;\;\;\;U \cdot \left(U - -8\right)\\

\mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-11}:\\
\;\;\;\;U\\

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


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

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

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]

    if -8.6e15 < l < 2.6000000000000001e-11

    1. Initial program 70.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 66.3%

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

    if 2.6000000000000001e-11 < l

    1. Initial program 99.3%

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

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

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

Alternative 18: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 19: 37.1% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 86.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 32.0%

    \[\leadsto \color{blue}{U} \]
  3. Final simplification32.0%

    \[\leadsto U \]

Reproduce

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