Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.7% → 99.9%
Time: 13.3s
Alternatives: 16
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% 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 -20000 \lor \neg \left(t_1 \leq 0.01\right):\\ \;\;\;\;\left(t_1 \cdot J\right) \cdot t_0 + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))) (t_1 (- (exp l) (exp (- l)))))
   (if (or (<= t_1 -20000.0) (not (<= t_1 0.01)))
     (+ (* (* t_1 J) t_0) U)
     (+
      U
      (*
       t_0
       (*
        J
        (+
         (* 0.016666666666666666 (pow l 5.0))
         (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if ((t_1 <= -20000.0) || !(t_1 <= 0.01)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.016666666666666666 * pow(l, 5.0)) + ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    t_1 = exp(l) - exp(-l)
    if ((t_1 <= (-20000.0d0)) .or. (.not. (t_1 <= 0.01d0))) then
        tmp = ((t_1 * j) * t_0) + u
    else
        tmp = u + (t_0 * (j * ((0.016666666666666666d0 * (l ** 5.0d0)) + ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_1 <= -20000.0) || !(t_1 <= 0.01)) {
		tmp = ((t_1 * J) * t_0) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.016666666666666666 * Math.pow(l, 5.0)) + ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_1 <= -20000.0) or not (t_1 <= 0.01):
		tmp = ((t_1 * J) * t_0) + U
	else:
		tmp = U + (t_0 * (J * ((0.016666666666666666 * math.pow(l, 5.0)) + ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_1 <= -20000.0) || !(t_1 <= 0.01))
		tmp = Float64(Float64(Float64(t_1 * J) * t_0) + U);
	else
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.016666666666666666 * (l ^ 5.0)) + Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_1 <= -20000.0) || ~((t_1 <= 0.01)))
		tmp = ((t_1 * J) * t_0) + U;
	else
		tmp = U + (t_0 * (J * ((0.016666666666666666 * (l ^ 5.0)) + ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[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, -20000.0], N[Not[LessEqual[t$95$1, 0.01]], $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.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -20000 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.01\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.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right)\\ \end{array} \]

Alternative 2: 99.8% accurate, 0.4× speedup?

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

    1. Initial program 99.9%

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

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

    1. Initial program 69.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -20000 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.002\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: 77.5% accurate, 0.7× speedup?

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

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


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

    1. Initial program 83.9%

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

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

    if 0.209999999999999992 < (cos.f64 (/.f64 K 2)) < 0.77000000000000002 or 0.994999999999999996 < (cos.f64 (/.f64 K 2))

    1. Initial program 85.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Taylor expanded in l around 0 86.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 K around 0 86.1%

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

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

Alternative 4: 96.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ t_1 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -8.5:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 0.0031:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* 0.016666666666666666 (* (* J (pow l 5.0)) (cos (* K 0.5))))))
        (t_1 (+ U (* (- (exp l) (exp (- l))) (+ J (* J (* K (* K -0.125))))))))
   (if (<= l -4.5e+61)
     t_0
     (if (<= l -8.5)
       t_1
       (if (<= l 0.0031)
         (+
          U
          (*
           (cos (/ K 2.0))
           (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
         (if (<= l 2.3e+52) t_1 t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (0.016666666666666666 * ((J * pow(l, 5.0)) * cos((K * 0.5))));
	double t_1 = U + ((exp(l) - exp(-l)) * (J + (J * (K * (K * -0.125)))));
	double tmp;
	if (l <= -4.5e+61) {
		tmp = t_0;
	} else if (l <= -8.5) {
		tmp = t_1;
	} else if (l <= 0.0031) {
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.3e+52) {
		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.016666666666666666d0 * ((j * (l ** 5.0d0)) * cos((k * 0.5d0))))
    t_1 = u + ((exp(l) - exp(-l)) * (j + (j * (k * (k * (-0.125d0))))))
    if (l <= (-4.5d+61)) then
        tmp = t_0
    else if (l <= (-8.5d0)) then
        tmp = t_1
    else if (l <= 0.0031d0) then
        tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    else if (l <= 2.3d+52) 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.016666666666666666 * ((J * Math.pow(l, 5.0)) * Math.cos((K * 0.5))));
	double t_1 = U + ((Math.exp(l) - Math.exp(-l)) * (J + (J * (K * (K * -0.125)))));
	double tmp;
	if (l <= -4.5e+61) {
		tmp = t_0;
	} else if (l <= -8.5) {
		tmp = t_1;
	} else if (l <= 0.0031) {
		tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.3e+52) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (0.016666666666666666 * ((J * math.pow(l, 5.0)) * math.cos((K * 0.5))))
	t_1 = U + ((math.exp(l) - math.exp(-l)) * (J + (J * (K * (K * -0.125)))))
	tmp = 0
	if l <= -4.5e+61:
		tmp = t_0
	elif l <= -8.5:
		tmp = t_1
	elif l <= 0.0031:
		tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	elif l <= 2.3e+52:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(0.016666666666666666 * Float64(Float64(J * (l ^ 5.0)) * cos(Float64(K * 0.5)))))
	t_1 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * Float64(J + Float64(J * Float64(K * Float64(K * -0.125))))))
	tmp = 0.0
	if (l <= -4.5e+61)
		tmp = t_0;
	elseif (l <= -8.5)
		tmp = t_1;
	elseif (l <= 0.0031)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	elseif (l <= 2.3e+52)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (0.016666666666666666 * ((J * (l ^ 5.0)) * cos((K * 0.5))));
	t_1 = U + ((exp(l) - exp(-l)) * (J + (J * (K * (K * -0.125)))));
	tmp = 0.0;
	if (l <= -4.5e+61)
		tmp = t_0;
	elseif (l <= -8.5)
		tmp = t_1;
	elseif (l <= 0.0031)
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	elseif (l <= 2.3e+52)
		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.016666666666666666 * N[(N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * N[(J + N[(J * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.5e+61], t$95$0, If[LessEqual[l, -8.5], t$95$1, If[LessEqual[l, 0.0031], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.3e+52], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 2.3 \cdot 10^{+52}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.5e61 or 2.3e52 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -4.5e61 < l < -8.5 or 0.00309999999999999989 < l < 2.3e52

    1. Initial program 99.7%

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

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

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

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

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

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

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

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + \color{blue}{\left(J \cdot -0.125\right)} \cdot {K}^{2}\right) + U \]
      7. associate-*l*87.7%

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

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

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.125\right)\right) + U \]
      10. associate-*l*87.7%

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

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

    if -8.5 < l < 0.00309999999999999989

    1. Initial program 69.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -8.5:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 0.0031:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{+52}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 5: 94.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot t_0\right)\\ \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -0.00016:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 360000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+51}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\ \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.016666666666666666 (* (* J (pow l 5.0)) t_0)))))
   (if (<= l -2.6e+44)
     t_1
     (if (<= l -0.00016)
       (+ (* (- (exp l) (exp (- l))) J) U)
       (if (<= l 360000.0)
         (+ U (* 2.0 (* J (* l t_0))))
         (if (<= l 3.2e+51)
           (+ U (* 2.0 (* J (+ l (log1p (expm1 (* l (* K (* K -0.125)))))))))
           t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + (0.016666666666666666 * ((J * pow(l, 5.0)) * t_0));
	double tmp;
	if (l <= -2.6e+44) {
		tmp = t_1;
	} else if (l <= -0.00016) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else if (l <= 360000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 3.2e+51) {
		tmp = U + (2.0 * (J * (l + log1p(expm1((l * (K * (K * -0.125))))))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + (0.016666666666666666 * ((J * Math.pow(l, 5.0)) * t_0));
	double tmp;
	if (l <= -2.6e+44) {
		tmp = t_1;
	} else if (l <= -0.00016) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} else if (l <= 360000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 3.2e+51) {
		tmp = U + (2.0 * (J * (l + Math.log1p(Math.expm1((l * (K * (K * -0.125))))))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U + (0.016666666666666666 * ((J * math.pow(l, 5.0)) * t_0))
	tmp = 0
	if l <= -2.6e+44:
		tmp = t_1
	elif l <= -0.00016:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	elif l <= 360000.0:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif l <= 3.2e+51:
		tmp = U + (2.0 * (J * (l + math.log1p(math.expm1((l * (K * (K * -0.125))))))))
	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.016666666666666666 * Float64(Float64(J * (l ^ 5.0)) * t_0)))
	tmp = 0.0
	if (l <= -2.6e+44)
		tmp = t_1;
	elseif (l <= -0.00016)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	elseif (l <= 360000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (l <= 3.2e+51)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l + log1p(expm1(Float64(l * Float64(K * Float64(K * -0.125)))))))));
	else
		tmp = t_1;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(0.016666666666666666 * N[(N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.6e+44], t$95$1, If[LessEqual[l, -0.00016], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 360000.0], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.2e+51], N[(U + N[(2.0 * N[(J * N[(l + N[Log[1 + N[(Exp[N[(l * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+51}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.5999999999999999e44 or 3.2000000000000002e51 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -2.5999999999999999e44 < l < -1.60000000000000013e-4

    1. Initial program 98.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 83.2%

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

    if -1.60000000000000013e-4 < l < 3.6e5

    1. Initial program 69.7%

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

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

    if 3.6e5 < l < 3.2000000000000002e51

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

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

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

        \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \left(\left(-0.125 \cdot {K}^{2}\right) \cdot \ell + \color{blue}{\left(0.0026041666666666665 \cdot {K}^{4}\right) \cdot \ell}\right)\right)\right) + U \]
      3. distribute-rgt-out0.9%

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

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

      \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 0.0026041666666666665 \cdot {K}^{4}\right)\right)}\right) + U \]
    6. Taylor expanded in K around 0 34.3%

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \color{blue}{\left(K \cdot \left(K \cdot -0.125\right)\right)}\right)\right) + U \]
    9. Step-by-step derivation
      1. log1p-expm1-u67.5%

        \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)}\right)\right) + U \]
    10. Applied egg-rr67.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+44}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00016:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 360000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+51}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 94.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;\ell \leq -2.7 \cdot 10^{+40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -0.75:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 4800000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+51}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* 0.016666666666666666 (* (* J (pow l 5.0)) (cos (* K 0.5)))))))
   (if (<= l -2.7e+40)
     t_0
     (if (<= l -0.75)
       (+ (* (- (exp l) (exp (- l))) J) U)
       (if (<= l 4800000000.0)
         (+
          U
          (*
           (cos (/ K 2.0))
           (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
         (if (<= l 2.4e+51)
           (+ U (* 2.0 (* J (+ l (log1p (expm1 (* l (* K (* K -0.125)))))))))
           t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (0.016666666666666666 * ((J * pow(l, 5.0)) * cos((K * 0.5))));
	double tmp;
	if (l <= -2.7e+40) {
		tmp = t_0;
	} else if (l <= -0.75) {
		tmp = ((exp(l) - exp(-l)) * J) + U;
	} else if (l <= 4800000000.0) {
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.4e+51) {
		tmp = U + (2.0 * (J * (l + log1p(expm1((l * (K * (K * -0.125))))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (0.016666666666666666 * ((J * Math.pow(l, 5.0)) * Math.cos((K * 0.5))));
	double tmp;
	if (l <= -2.7e+40) {
		tmp = t_0;
	} else if (l <= -0.75) {
		tmp = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	} else if (l <= 4800000000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else if (l <= 2.4e+51) {
		tmp = U + (2.0 * (J * (l + Math.log1p(Math.expm1((l * (K * (K * -0.125))))))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (0.016666666666666666 * ((J * math.pow(l, 5.0)) * math.cos((K * 0.5))))
	tmp = 0
	if l <= -2.7e+40:
		tmp = t_0
	elif l <= -0.75:
		tmp = ((math.exp(l) - math.exp(-l)) * J) + U
	elif l <= 4800000000.0:
		tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	elif l <= 2.4e+51:
		tmp = U + (2.0 * (J * (l + math.log1p(math.expm1((l * (K * (K * -0.125))))))))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(0.016666666666666666 * Float64(Float64(J * (l ^ 5.0)) * cos(Float64(K * 0.5)))))
	tmp = 0.0
	if (l <= -2.7e+40)
		tmp = t_0;
	elseif (l <= -0.75)
		tmp = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U);
	elseif (l <= 4800000000.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 <= 2.4e+51)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l + log1p(expm1(Float64(l * Float64(K * Float64(K * -0.125)))))))));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(0.016666666666666666 * N[(N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.7e+40], t$95$0, If[LessEqual[l, -0.75], N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 4800000000.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, 2.4e+51], N[(U + N[(2.0 * N[(J * N[(l + N[Log[1 + N[(Exp[N[(l * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+51}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.70000000000000009e40 or 2.3999999999999999e51 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -2.70000000000000009e40 < l < -0.75

    1. Initial program 99.8%

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

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

    if -0.75 < l < 4.8e9

    1. Initial program 70.2%

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

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

    if 4.8e9 < l < 2.3999999999999999e51

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

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

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

        \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \left(\left(-0.125 \cdot {K}^{2}\right) \cdot \ell + \color{blue}{\left(0.0026041666666666665 \cdot {K}^{4}\right) \cdot \ell}\right)\right)\right) + U \]
      3. distribute-rgt-out0.9%

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

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

      \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 0.0026041666666666665 \cdot {K}^{4}\right)\right)}\right) + U \]
    6. Taylor expanded in K around 0 34.3%

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \color{blue}{\left(K \cdot \left(K \cdot -0.125\right)\right)}\right)\right) + U \]
    9. Step-by-step derivation
      1. log1p-expm1-u67.5%

        \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)}\right)\right) + U \]
    10. Applied egg-rr67.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.7 \cdot 10^{+40}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq -0.75:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 4800000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{+51}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 0.016666666666666666 \cdot \left(\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(K \cdot 0.5\right)\right)\\ \end{array} \]

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

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

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

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

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


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

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

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

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

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

    if -2.49999999999999987e48 < l < -1.15e-4

    1. Initial program 98.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 83.2%

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

    if -1.15e-4 < l < 3.2999999999999998

    1. Initial program 69.4%

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

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

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

Alternative 8: 87.3% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.60000000000000013e-4 or 6.4999999999999997e-4 < l

    1. Initial program 99.8%

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

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

    if -1.60000000000000013e-4 < l < 6.4999999999999997e-4

    1. Initial program 69.2%

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

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

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

Alternative 9: 57.1% accurate, 2.7× speedup?

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

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

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


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

    1. Initial program 86.1%

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

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

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

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

        \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \left(\left(-0.125 \cdot {K}^{2}\right) \cdot \ell + \color{blue}{\left(0.0026041666666666665 \cdot {K}^{4}\right) \cdot \ell}\right)\right)\right) + U \]
      3. distribute-rgt-out7.5%

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

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

      \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\left(\ell + \ell \cdot \left(-0.125 \cdot \left(K \cdot K\right) + 0.0026041666666666665 \cdot {K}^{4}\right)\right)}\right) + U \]
    6. Taylor expanded in K around 0 59.0%

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

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

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

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

      \[\leadsto 2 \cdot \left(J \cdot \left(\ell + \ell \cdot \color{blue}{\left(K \cdot \left(K \cdot -0.125\right)\right)}\right)\right) + U \]
    9. Taylor expanded in K around inf 59.0%

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

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

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

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

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

    1. Initial program 84.8%

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

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

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

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

Alternative 10: 64.0% accurate, 2.8× speedup?

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

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

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

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

Alternative 11: 42.0% accurate, 27.9× speedup?

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

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

\mathbf{elif}\;\ell \leq 8 \cdot 10^{+32}:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 8 \cdot 10^{+257}:\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot 0.125\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.2e18 or 8.00000000000000043e32 < l < 8.00000000000000024e257

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

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

    if -2.2e18 < l < 8.00000000000000043e32

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

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

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

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

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

    if 8.00000000000000024e257 < l

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.125 \cdot J} + U \]
    4. Step-by-step derivation
      1. *-commutative4.4%

        \[\leadsto \color{blue}{J \cdot 0.125} + U \]
    5. Simplified4.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+18}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+32}:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+257}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot 0.125\\ \end{array} \]

Alternative 12: 42.0% accurate, 34.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+17}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+31}:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+259}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -6e+17)
   (* U U)
   (if (<= l 3.8e+31) U (if (<= l 5.1e+259) (* U U) U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -6e+17) {
		tmp = U * U;
	} else if (l <= 3.8e+31) {
		tmp = U;
	} else if (l <= 5.1e+259) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-6d+17)) then
        tmp = u * u
    else if (l <= 3.8d+31) then
        tmp = u
    else if (l <= 5.1d+259) then
        tmp = u * u
    else
        tmp = u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -6e+17) {
		tmp = U * U;
	} else if (l <= 3.8e+31) {
		tmp = U;
	} else if (l <= 5.1e+259) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -6e+17:
		tmp = U * U
	elif l <= 3.8e+31:
		tmp = U
	elif l <= 5.1e+259:
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -6e+17)
		tmp = Float64(U * U);
	elseif (l <= 3.8e+31)
		tmp = U;
	elseif (l <= 5.1e+259)
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -6e+17)
		tmp = U * U;
	elseif (l <= 3.8e+31)
		tmp = U;
	elseif (l <= 5.1e+259)
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -6e+17], N[(U * U), $MachinePrecision], If[LessEqual[l, 3.8e+31], U, If[LessEqual[l, 5.1e+259], N[(U * U), $MachinePrecision], U]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+31}:\\
\;\;\;\;U\\

\mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+259}:\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6e17 or 3.8000000000000001e31 < l < 5.1000000000000002e259

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

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

    if -6e17 < l < 3.8000000000000001e31 or 5.1000000000000002e259 < l

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+17}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+31}:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 5.1 \cdot 10^{+259}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 13: 42.0% accurate, 34.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+17}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+31}:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+253}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + -8\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -6e+17)
   (* U U)
   (if (<= l 1.4e+31) U (if (<= l 2.5e+253) (* U U) (+ U -8.0)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -6e+17) {
		tmp = U * U;
	} else if (l <= 1.4e+31) {
		tmp = U;
	} else if (l <= 2.5e+253) {
		tmp = U * U;
	} else {
		tmp = U + -8.0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-6d+17)) then
        tmp = u * u
    else if (l <= 1.4d+31) then
        tmp = u
    else if (l <= 2.5d+253) then
        tmp = u * u
    else
        tmp = u + (-8.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -6e+17) {
		tmp = U * U;
	} else if (l <= 1.4e+31) {
		tmp = U;
	} else if (l <= 2.5e+253) {
		tmp = U * U;
	} else {
		tmp = U + -8.0;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -6e+17:
		tmp = U * U
	elif l <= 1.4e+31:
		tmp = U
	elif l <= 2.5e+253:
		tmp = U * U
	else:
		tmp = U + -8.0
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -6e+17)
		tmp = Float64(U * U);
	elseif (l <= 1.4e+31)
		tmp = U;
	elseif (l <= 2.5e+253)
		tmp = Float64(U * U);
	else
		tmp = Float64(U + -8.0);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -6e+17)
		tmp = U * U;
	elseif (l <= 1.4e+31)
		tmp = U;
	elseif (l <= 2.5e+253)
		tmp = U * U;
	else
		tmp = U + -8.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -6e+17], N[(U * U), $MachinePrecision], If[LessEqual[l, 1.4e+31], U, If[LessEqual[l, 2.5e+253], N[(U * U), $MachinePrecision], N[(U + -8.0), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+253}:\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;U + -8\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6e17 or 1.40000000000000008e31 < l < 2.4999999999999998e253

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

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

    if -6e17 < l < 1.40000000000000008e31

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

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

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

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

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

    if 2.4999999999999998e253 < l

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{U + -8} \]
    6. Simplified3.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+17}:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+31}:\\ \;\;\;\;U\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{+253}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + -8\\ \end{array} \]

Alternative 14: 54.1% accurate, 44.6× speedup?

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

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

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

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

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

    \[\leadsto U + 2 \cdot \left(\ell \cdot J\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 85.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*85.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  3. Simplified85.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-rr2.7%

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

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

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

    \[\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 85.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*85.0%

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

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

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

    \[\leadsto \color{blue}{U} \]
  5. Final simplification34.1%

    \[\leadsto U \]

Reproduce

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