Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.8% → 99.8%
Time: 10.8s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 86.8% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

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

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

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

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

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

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


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

    1. Initial program 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-4

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

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

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

Alternative 3: 99.9% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 72.0%

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

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

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

Alternative 5: 94.2% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -8.5 \cdot 10^{+78} \lor \neg \left(\ell \leq -0.23 \lor \neg \left(\ell \leq 31000000\right) \land \ell \leq 6.6 \cdot 10^{+88}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8.50000000000000079e78 or -0.23000000000000001 < l < 3.1e7 or 6.6000000000000006e88 < l

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

    if -8.50000000000000079e78 < l < -0.23000000000000001 or 3.1e7 < l < 6.6000000000000006e88

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8.5 \cdot 10^{+78} \lor \neg \left(\ell \leq -0.23 \lor \neg \left(\ell \leq 31000000\right) \land \ell \leq 6.6 \cdot 10^{+88}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \end{array} \]

Alternative 6: 95.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+91} \lor \neg \left(\ell \leq -0.15 \lor \neg \left(\ell \leq 26\right) \land \ell \leq 1.45 \cdot 10^{+93}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -1.55e+91)
         (not (or (<= l -0.15) (and (not (<= l 26.0)) (<= l 1.45e+93)))))
   (+
    U
    (* (cos (/ K 2.0)) (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
   (+ U (* (+ (* -0.125 (* K K)) 1.0) (* (- (exp l) (exp (- l))) J)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.55e+91) || !((l <= -0.15) || (!(l <= 26.0) && (l <= 1.45e+93)))) {
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))));
	} else {
		tmp = U + (((-0.125 * (K * K)) + 1.0) * ((exp(l) - exp(-l)) * J));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-1.55d+91)) .or. (.not. (l <= (-0.15d0)) .or. (.not. (l <= 26.0d0)) .and. (l <= 1.45d+93))) then
        tmp = u + (cos((k / 2.0d0)) * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    else
        tmp = u + ((((-0.125d0) * (k * k)) + 1.0d0) * ((exp(l) - exp(-l)) * j))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.55e+91) || !((l <= -0.15) || (!(l <= 26.0) && (l <= 1.45e+93)))) {
		tmp = U + (Math.cos((K / 2.0)) * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else {
		tmp = U + (((-0.125 * (K * K)) + 1.0) * ((Math.exp(l) - Math.exp(-l)) * J));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -1.55e+91) or not ((l <= -0.15) or (not (l <= 26.0) and (l <= 1.45e+93))):
		tmp = U + (math.cos((K / 2.0)) * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	else:
		tmp = U + (((-0.125 * (K * K)) + 1.0) * ((math.exp(l) - math.exp(-l)) * J))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -1.55e+91) || !((l <= -0.15) || (!(l <= 26.0) && (l <= 1.45e+93))))
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	else
		tmp = Float64(U + Float64(Float64(Float64(-0.125 * Float64(K * K)) + 1.0) * Float64(Float64(exp(l) - exp(Float64(-l))) * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -1.55e+91) || ~(((l <= -0.15) || (~((l <= 26.0)) && (l <= 1.45e+93)))))
		tmp = U + (cos((K / 2.0)) * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	else
		tmp = U + (((-0.125 * (K * K)) + 1.0) * ((exp(l) - exp(-l)) * J));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1.55e+91], N[Not[Or[LessEqual[l, -0.15], And[N[Not[LessEqual[l, 26.0]], $MachinePrecision], LessEqual[l, 1.45e+93]]]], $MachinePrecision]], 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], N[(U + N[(N[(N[(-0.125 * N[(K * K), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.55 \cdot 10^{+91} \lor \neg \left(\ell \leq -0.15 \lor \neg \left(\ell \leq 26\right) \land \ell \leq 1.45 \cdot 10^{+93}\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.54999999999999999e91 or -0.149999999999999994 < l < 26 or 1.4499999999999999e93 < l

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

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

    if -1.54999999999999999e91 < l < -0.149999999999999994 or 26 < l < 1.4499999999999999e93

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.55 \cdot 10^{+91} \lor \neg \left(\ell \leq -0.15 \lor \neg \left(\ell \leq 26\right) \land \ell \leq 1.45 \cdot 10^{+93}\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \end{array} \]

Alternative 7: 86.8% accurate, 1.5× speedup?

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

\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 l < -0.025000000000000001 or 4.50000000000000028e-5 < 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 74.9%

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

    if -0.025000000000000001 < l < 4.50000000000000028e-5

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

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

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

Alternative 8: 63.6% accurate, 2.8× speedup?

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

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

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

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

Alternative 9: 46.8% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.8 \cdot 10^{+32}:\\
\;\;\;\;{U}^{-8}\\

\mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+14}:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.79999999999999983e32 or 5.2e14 < l

    1. Initial program 100.0%

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

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

    if -4.79999999999999983e32 < l < 5.2e14

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.8 \cdot 10^{+32}:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+14}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;{U}^{-8}\\ \end{array} \]

Alternative 10: 43.5% accurate, 20.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.1999999999999999e84 or 380 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -7.1999999999999999e84 < l < 380

    1. Initial program 75.1%

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

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

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

Alternative 11: 42.9% accurate, 34.2× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;U \cdot \left(U - -8\right)\\


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

    1. Initial program 99.9%

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

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

    if -0.00365000000000000003 < l < 2.1e11

    1. Initial program 73.1%

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

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

    if 2.1e11 < 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-rr12.2%

      \[\leadsto \color{blue}{U \cdot \left(U - -8\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification40.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.00365:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 210000000000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U - -8\right)\\ \end{array} \]

Alternative 12: 42.9% accurate, 43.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.00365000000000000003 or 1.75e11 < 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. Applied egg-rr11.1%

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

    if -0.00365000000000000003 < l < 1.75e11

    1. Initial program 73.1%

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

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

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

Alternative 13: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 14: 36.9% accurate, 312.0× speedup?

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

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

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

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

    \[\leadsto U \]

Reproduce

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