Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.0% → 99.5%
Time: 18.6s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 86.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

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

    1. Initial program 73.7%

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

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

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

Alternative 3: 87.5% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -1.00000000000000005e-4 or 1 < (-.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 \]
    2. Taylor expanded in K around 0 69.6%

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

    if -1.00000000000000005e-4 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1

    1. Initial program 74.0%

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

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

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

Alternative 4: 77.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{if}\;t_0 \leq -0.535:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -0.35:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;t_0 \leq -0.02:\\ \;\;\;\;t_1\\ \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
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* 2.0 (* J (+ l (* l (* -0.125 (* K K)))))))))
   (if (<= t_0 -0.535)
     t_1
     (if (<= t_0 -0.35)
       (+ U (* t_0 (* J (* l 2.0))))
       (if (<= t_0 -0.02)
         t_1
         (+ U (* 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 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double tmp;
	if (t_0 <= -0.535) {
		tmp = t_1;
	} else if (t_0 <= -0.35) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (t_0 <= -0.02) {
		tmp = t_1;
	} 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = u + (2.0d0 * (j * (l + (l * ((-0.125d0) * (k * k))))))
    if (t_0 <= (-0.535d0)) then
        tmp = t_1
    else if (t_0 <= (-0.35d0)) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else if (t_0 <= (-0.02d0)) then
        tmp = t_1
    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 t_0 = Math.cos((K / 2.0));
	double t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double tmp;
	if (t_0 <= -0.535) {
		tmp = t_1;
	} else if (t_0 <= -0.35) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (t_0 <= -0.02) {
		tmp = t_1;
	} else {
		tmp = U + (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 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))))
	tmp = 0
	if t_0 <= -0.535:
		tmp = t_1
	elif t_0 <= -0.35:
		tmp = U + (t_0 * (J * (l * 2.0)))
	elif t_0 <= -0.02:
		tmp = t_1
	else:
		tmp = U + (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(U + Float64(2.0 * Float64(J * Float64(l + Float64(l * Float64(-0.125 * Float64(K * K)))))))
	tmp = 0.0
	if (t_0 <= -0.535)
		tmp = t_1;
	elseif (t_0 <= -0.35)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	elseif (t_0 <= -0.02)
		tmp = t_1;
	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)
	t_0 = cos((K / 2.0));
	t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	tmp = 0.0;
	if (t_0 <= -0.535)
		tmp = t_1;
	elseif (t_0 <= -0.35)
		tmp = U + (t_0 * (J * (l * 2.0)));
	elseif (t_0 <= -0.02)
		tmp = t_1;
	else
		tmp = U + (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[(U + N[(2.0 * N[(J * N[(l + N[(l * N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.535], t$95$1, If[LessEqual[t$95$0, -0.35], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.02], t$95$1, 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}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\
\mathbf{if}\;t_0 \leq -0.535:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;t_0 \leq -0.02:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 (/.f64 K 2)) < -0.535000000000000031 or -0.34999999999999998 < (cos.f64 (/.f64 K 2)) < -0.0200000000000000004

    1. Initial program 90.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 48.8%

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

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

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

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

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

    if -0.535000000000000031 < (cos.f64 (/.f64 K 2)) < -0.34999999999999998

    1. Initial program 82.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 65.6%

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

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

    1. Initial program 86.5%

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

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

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

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

Alternative 5: 94.6% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;\ell \leq 2.2 \cdot 10^{+100}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -9.99999999999999983e76 or 2.2000000000000001e100 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -9.99999999999999983e76 < l < -0.035000000000000003 or 15500 < l < 2.2000000000000001e100

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

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

    if -0.035000000000000003 < l < 15500

    1. Initial program 74.3%

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

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

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

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

Alternative 6: 94.6% accurate, 1.4× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 15500:\\
\;\;\;\;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.8 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -9.99999999999999983e76 or 1.8e100 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -9.99999999999999983e76 < l < -0.23000000000000001 or 15500 < l < 1.8e100

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

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

    if -0.23000000000000001 < l < 15500

    1. Initial program 74.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+77}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.23:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 15500:\\ \;\;\;\;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.8 \cdot 10^{+100}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 7: 94.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\ell \leq 1.8 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -9.99999999999999983e76 or 1.8e100 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -9.99999999999999983e76 < l < -8.39999999999999954e-5 or 15500 < l < 1.8e100

    1. Initial program 99.6%

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

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

    if -8.39999999999999954e-5 < l < 15500

    1. Initial program 74.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 98.2%

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

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

Alternative 8: 68.9% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

    1. Initial program 86.5%

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

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

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

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

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

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

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

Alternative 9: 77.1% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ t_2 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -50000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 190000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+200} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* (* K K) -64.0) 512.0))))
        (t_1 (+ U (* 2.0 (* J (+ l (* l (* -0.125 (* K K))))))))
        (t_2 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -1.4e+101)
     t_2
     (if (<= l -6e+77)
       t_1
       (if (<= l -1.25e+41)
         t_0
         (if (<= l -50000000000.0)
           (* U U)
           (if (<= l -8.4e-5)
             t_0
             (if (<= l 190000.0)
               (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
               (if (or (<= l 1.45e+200) (not (<= l 5e+251))) t_2 t_1)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double t_2 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -1.4e+101) {
		tmp = t_2;
	} else if (l <= -6e+77) {
		tmp = t_1;
	} else if (l <= -1.25e+41) {
		tmp = t_0;
	} else if (l <= -50000000000.0) {
		tmp = U * U;
	} else if (l <= -8.4e-5) {
		tmp = t_0;
	} else if (l <= 190000.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if ((l <= 1.45e+200) || !(l <= 5e+251)) {
		tmp = t_2;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = u + (j * (((k * k) * (-64.0d0)) + 512.0d0))
    t_1 = u + (2.0d0 * (j * (l + (l * ((-0.125d0) * (k * k))))))
    t_2 = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    if (l <= (-1.4d+101)) then
        tmp = t_2
    else if (l <= (-6d+77)) then
        tmp = t_1
    else if (l <= (-1.25d+41)) then
        tmp = t_0
    else if (l <= (-50000000000.0d0)) then
        tmp = u * u
    else if (l <= (-8.4d-5)) then
        tmp = t_0
    else if (l <= 190000.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if ((l <= 1.45d+200) .or. (.not. (l <= 5d+251))) then
        tmp = t_2
    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 = U + (J * (((K * K) * -64.0) + 512.0));
	double t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double t_2 = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -1.4e+101) {
		tmp = t_2;
	} else if (l <= -6e+77) {
		tmp = t_1;
	} else if (l <= -1.25e+41) {
		tmp = t_0;
	} else if (l <= -50000000000.0) {
		tmp = U * U;
	} else if (l <= -8.4e-5) {
		tmp = t_0;
	} else if (l <= 190000.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if ((l <= 1.45e+200) || !(l <= 5e+251)) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (((K * K) * -64.0) + 512.0))
	t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))))
	t_2 = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	tmp = 0
	if l <= -1.4e+101:
		tmp = t_2
	elif l <= -6e+77:
		tmp = t_1
	elif l <= -1.25e+41:
		tmp = t_0
	elif l <= -50000000000.0:
		tmp = U * U
	elif l <= -8.4e-5:
		tmp = t_0
	elif l <= 190000.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif (l <= 1.45e+200) or not (l <= 5e+251):
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * -64.0) + 512.0)))
	t_1 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(l * Float64(-0.125 * Float64(K * K)))))))
	t_2 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -1.4e+101)
		tmp = t_2;
	elseif (l <= -6e+77)
		tmp = t_1;
	elseif (l <= -1.25e+41)
		tmp = t_0;
	elseif (l <= -50000000000.0)
		tmp = Float64(U * U);
	elseif (l <= -8.4e-5)
		tmp = t_0;
	elseif (l <= 190000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif ((l <= 1.45e+200) || !(l <= 5e+251))
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	t_2 = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -1.4e+101)
		tmp = t_2;
	elseif (l <= -6e+77)
		tmp = t_1;
	elseif (l <= -1.25e+41)
		tmp = t_0;
	elseif (l <= -50000000000.0)
		tmp = U * U;
	elseif (l <= -8.4e-5)
		tmp = t_0;
	elseif (l <= 190000.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif ((l <= 1.45e+200) || ~((l <= 5e+251)))
		tmp = t_2;
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(U + N[(2.0 * N[(J * N[(l + N[(l * N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.4e+101], t$95$2, If[LessEqual[l, -6e+77], t$95$1, If[LessEqual[l, -1.25e+41], t$95$0, If[LessEqual[l, -50000000000.0], N[(U * U), $MachinePrecision], If[LessEqual[l, -8.4e-5], t$95$0, If[LessEqual[l, 190000.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 1.45e+200], N[Not[LessEqual[l, 5e+251]], $MachinePrecision]], t$95$2, t$95$1]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\
t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\
t_2 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -1.4 \cdot 10^{+101}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq -6 \cdot 10^{+77}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+41}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -50000000000:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+200} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -1.39999999999999991e101 or 1.9e5 < l < 1.4499999999999999e200 or 5.0000000000000005e251 < 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 86.1%

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

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

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

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

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

    if -1.39999999999999991e101 < l < -5.9999999999999996e77 or 1.4499999999999999e200 < l < 5.0000000000000005e251

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

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

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

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

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

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

    if -5.9999999999999996e77 < l < -1.25000000000000006e41 or -5e10 < l < -8.39999999999999954e-5

    1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

    if -1.25000000000000006e41 < l < -5e10

    1. Initial program 100.0%

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

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

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

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

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

    if -8.39999999999999954e-5 < l < 1.9e5

    1. Initial program 74.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 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+101}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+77}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+41}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -50000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq 190000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+200} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \end{array} \]

Alternative 10: 77.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ t_2 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -17000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 29000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (+ (* (* K K) -64.0) 512.0))))
        (t_1 (+ U (* 2.0 (* J (+ l (* l (* -0.125 (* K K))))))))
        (t_2 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -3.2e+103)
     t_2
     (if (<= l -4.4e+77)
       t_1
       (if (<= l -1.5e+39)
         t_0
         (if (<= l -17000000000.0)
           (* U U)
           (if (<= l -8.4e-5)
             t_0
             (if (<= l 29000.0)
               (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
               (if (or (<= l 4.9e+197) (not (<= l 5e+251))) t_2 t_1)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	double t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double t_2 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -3.2e+103) {
		tmp = t_2;
	} else if (l <= -4.4e+77) {
		tmp = t_1;
	} else if (l <= -1.5e+39) {
		tmp = t_0;
	} else if (l <= -17000000000.0) {
		tmp = U * U;
	} else if (l <= -8.4e-5) {
		tmp = t_0;
	} else if (l <= 29000.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if ((l <= 4.9e+197) || !(l <= 5e+251)) {
		tmp = t_2;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = u + (j * (((k * k) * (-64.0d0)) + 512.0d0))
    t_1 = u + (2.0d0 * (j * (l + (l * ((-0.125d0) * (k * k))))))
    t_2 = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    if (l <= (-3.2d+103)) then
        tmp = t_2
    else if (l <= (-4.4d+77)) then
        tmp = t_1
    else if (l <= (-1.5d+39)) then
        tmp = t_0
    else if (l <= (-17000000000.0d0)) then
        tmp = u * u
    else if (l <= (-8.4d-5)) then
        tmp = t_0
    else if (l <= 29000.0d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else if ((l <= 4.9d+197) .or. (.not. (l <= 5d+251))) then
        tmp = t_2
    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 = U + (J * (((K * K) * -64.0) + 512.0));
	double t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double t_2 = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	double tmp;
	if (l <= -3.2e+103) {
		tmp = t_2;
	} else if (l <= -4.4e+77) {
		tmp = t_1;
	} else if (l <= -1.5e+39) {
		tmp = t_0;
	} else if (l <= -17000000000.0) {
		tmp = U * U;
	} else if (l <= -8.4e-5) {
		tmp = t_0;
	} else if (l <= 29000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if ((l <= 4.9e+197) || !(l <= 5e+251)) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (((K * K) * -64.0) + 512.0))
	t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))))
	t_2 = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	tmp = 0
	if l <= -3.2e+103:
		tmp = t_2
	elif l <= -4.4e+77:
		tmp = t_1
	elif l <= -1.5e+39:
		tmp = t_0
	elif l <= -17000000000.0:
		tmp = U * U
	elif l <= -8.4e-5:
		tmp = t_0
	elif l <= 29000.0:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif (l <= 4.9e+197) or not (l <= 5e+251):
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * -64.0) + 512.0)))
	t_1 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(l * Float64(-0.125 * Float64(K * K)))))))
	t_2 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -3.2e+103)
		tmp = t_2;
	elseif (l <= -4.4e+77)
		tmp = t_1;
	elseif (l <= -1.5e+39)
		tmp = t_0;
	elseif (l <= -17000000000.0)
		tmp = Float64(U * U);
	elseif (l <= -8.4e-5)
		tmp = t_0;
	elseif (l <= 29000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif ((l <= 4.9e+197) || !(l <= 5e+251))
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (((K * K) * -64.0) + 512.0));
	t_1 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	t_2 = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	tmp = 0.0;
	if (l <= -3.2e+103)
		tmp = t_2;
	elseif (l <= -4.4e+77)
		tmp = t_1;
	elseif (l <= -1.5e+39)
		tmp = t_0;
	elseif (l <= -17000000000.0)
		tmp = U * U;
	elseif (l <= -8.4e-5)
		tmp = t_0;
	elseif (l <= 29000.0)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	elseif ((l <= 4.9e+197) || ~((l <= 5e+251)))
		tmp = t_2;
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(U + N[(2.0 * N[(J * N[(l + N[(l * N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.2e+103], t$95$2, If[LessEqual[l, -4.4e+77], t$95$1, If[LessEqual[l, -1.5e+39], t$95$0, If[LessEqual[l, -17000000000.0], N[(U * U), $MachinePrecision], If[LessEqual[l, -8.4e-5], t$95$0, If[LessEqual[l, 29000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 4.9e+197], N[Not[LessEqual[l, 5e+251]], $MachinePrecision]], t$95$2, t$95$1]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\
t_1 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\
t_2 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\
\mathbf{if}\;\ell \leq -3.2 \cdot 10^{+103}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+77}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+39}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -17000000000:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -3.19999999999999993e103 or 29000 < l < 4.90000000000000026e197 or 5.0000000000000005e251 < 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 86.1%

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

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

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

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

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

    if -3.19999999999999993e103 < l < -4.4000000000000001e77 or 4.90000000000000026e197 < l < 5.0000000000000005e251

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

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

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

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

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

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

    if -4.4000000000000001e77 < l < -1.5e39 or -1.7e10 < l < -8.39999999999999954e-5

    1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

    if -1.5e39 < l < -1.7e10

    1. Initial program 100.0%

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

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

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

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

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

    if -8.39999999999999954e-5 < l < 29000

    1. Initial program 74.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 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+103}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -4.4 \cdot 10^{+77}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+39}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -17000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq 29000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \end{array} \]

Alternative 11: 77.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ t_1 := U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{if}\;\ell \leq -3.4 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+39}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -50000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;U + \mathsf{fma}\left(J, 0.125, \left(K \cdot K\right) \cdot \left(J \cdot -0.015625\right)\right)\\ \mathbf{elif}\;\ell \leq 210000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (+ l (* l (* -0.125 (* K K))))))))
        (t_1 (+ U (* 0.3333333333333333 (* J (pow l 3.0))))))
   (if (<= l -3.4e+105)
     t_1
     (if (<= l -4e+77)
       t_0
       (if (<= l -1.25e+39)
         (+ U (* J (+ (* (* K K) -64.0) 512.0)))
         (if (<= l -50000000000.0)
           (* U U)
           (if (<= l -8.4e-5)
             (+ U (fma J 0.125 (* (* K K) (* J -0.015625))))
             (if (<= l 210000.0)
               (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
               (if (or (<= l 4.9e+197) (not (<= l 5e+251))) t_1 t_0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (l * (-0.125 * (K * K))))));
	double t_1 = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	double tmp;
	if (l <= -3.4e+105) {
		tmp = t_1;
	} else if (l <= -4e+77) {
		tmp = t_0;
	} else if (l <= -1.25e+39) {
		tmp = U + (J * (((K * K) * -64.0) + 512.0));
	} else if (l <= -50000000000.0) {
		tmp = U * U;
	} else if (l <= -8.4e-5) {
		tmp = U + fma(J, 0.125, ((K * K) * (J * -0.015625)));
	} else if (l <= 210000.0) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if ((l <= 4.9e+197) || !(l <= 5e+251)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(l * Float64(-0.125 * Float64(K * K)))))))
	t_1 = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))
	tmp = 0.0
	if (l <= -3.4e+105)
		tmp = t_1;
	elseif (l <= -4e+77)
		tmp = t_0;
	elseif (l <= -1.25e+39)
		tmp = Float64(U + Float64(J * Float64(Float64(Float64(K * K) * -64.0) + 512.0)));
	elseif (l <= -50000000000.0)
		tmp = Float64(U * U);
	elseif (l <= -8.4e-5)
		tmp = Float64(U + fma(J, 0.125, Float64(Float64(K * K) * Float64(J * -0.015625))));
	elseif (l <= 210000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif ((l <= 4.9e+197) || !(l <= 5e+251))
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l + N[(l * N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.4e+105], t$95$1, If[LessEqual[l, -4e+77], t$95$0, If[LessEqual[l, -1.25e+39], N[(U + N[(J * N[(N[(N[(K * K), $MachinePrecision] * -64.0), $MachinePrecision] + 512.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -50000000000.0], N[(U * U), $MachinePrecision], If[LessEqual[l, -8.4e-5], N[(U + N[(J * 0.125 + N[(N[(K * K), $MachinePrecision] * N[(J * -0.015625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 210000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 4.9e+197], N[Not[LessEqual[l, 5e+251]], $MachinePrecision]], t$95$1, t$95$0]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -4 \cdot 10^{+77}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+39}:\\
\;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\

\mathbf{elif}\;\ell \leq -50000000000:\\
\;\;\;\;U \cdot U\\

\mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\
\;\;\;\;U + \mathsf{fma}\left(J, 0.125, \left(K \cdot K\right) \cdot \left(J \cdot -0.015625\right)\right)\\

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

\mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if l < -3.3999999999999999e105 or 2.1e5 < l < 4.90000000000000026e197 or 5.0000000000000005e251 < 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 86.1%

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

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

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

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

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

    if -3.3999999999999999e105 < l < -3.99999999999999993e77 or 4.90000000000000026e197 < l < 5.0000000000000005e251

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

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

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

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

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

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

    if -3.99999999999999993e77 < l < -1.25000000000000004e39

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

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

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

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

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

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

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

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

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

    if -1.25000000000000004e39 < l < -5e10

    1. Initial program 100.0%

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

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

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

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

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

    if -5e10 < l < -8.39999999999999954e-5

    1. Initial program 95.1%

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

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

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

        \[\leadsto \color{blue}{\left(0.125 \cdot J + -0.015625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      2. *-commutative34.1%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, 0.125, -0.015625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      4. *-commutative34.1%

        \[\leadsto \mathsf{fma}\left(J, 0.125, \color{blue}{\left(J \cdot {K}^{2}\right) \cdot -0.015625}\right) + U \]
      5. *-commutative34.1%

        \[\leadsto \mathsf{fma}\left(J, 0.125, \color{blue}{\left({K}^{2} \cdot J\right)} \cdot -0.015625\right) + U \]
      6. associate-*l*34.1%

        \[\leadsto \mathsf{fma}\left(J, 0.125, \color{blue}{{K}^{2} \cdot \left(J \cdot -0.015625\right)}\right) + U \]
      7. unpow234.1%

        \[\leadsto \mathsf{fma}\left(J, 0.125, \color{blue}{\left(K \cdot K\right)} \cdot \left(J \cdot -0.015625\right)\right) + U \]
    5. Simplified34.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, 0.125, \left(K \cdot K\right) \cdot \left(J \cdot -0.015625\right)\right)} + U \]

    if -8.39999999999999954e-5 < l < 2.1e5

    1. Initial program 74.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 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.4 \cdot 10^{+105}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{+77}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.25 \cdot 10^{+39}:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{elif}\;\ell \leq -50000000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;U + \mathsf{fma}\left(J, 0.125, \left(K \cdot K\right) \cdot \left(J \cdot -0.015625\right)\right)\\ \mathbf{elif}\;\ell \leq 210000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.9 \cdot 10^{+197} \lor \neg \left(\ell \leq 5 \cdot 10^{+251}\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \end{array} \]

Alternative 12: 61.6% accurate, 16.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+20} \lor \neg \left(\ell \leq 75\right):\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1e20 or 75 < 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 26.5%

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

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

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

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

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

    if -1e20 < l < 75

    1. Initial program 75.3%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    3. Taylor expanded in l around 0 82.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+20} \lor \neg \left(\ell \leq 75\right):\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \end{array} \]

Alternative 13: 41.9% accurate, 43.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -8.4 \cdot 10^{-5}:\\
\;\;\;\;U \cdot U\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8.39999999999999954e-5 or 0.38 < l

    1. Initial program 99.9%

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

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

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

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

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

    if -8.39999999999999954e-5 < l < 0.38

    1. Initial program 73.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.4 \cdot 10^{-5}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 0.38:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 14: 55.1% accurate, 44.6× speedup?

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

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

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

    \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Taylor expanded in l around 0 52.9%

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

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

Alternative 15: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1} \]
  6. Simplified3.0%

    \[\leadsto \color{blue}{1} \]
  7. Final simplification3.0%

    \[\leadsto 1 \]

Alternative 16: 37.2% accurate, 312.0× speedup?

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

\\
U
\end{array}
Derivation
  1. Initial program 87.4%

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification35.4%

    \[\leadsto U \]

Reproduce

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