Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.9% → 99.9%
Time: 11.0s
Alternatives: 17
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 17 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: 85.9% 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 -2 \cdot 10^{+58} \lor \neg \left(t_1 \leq 0.0005\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.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\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 -2e+58) (not (<= t_1 0.0005)))
     (+ (* t_0 (* t_1 J)) U)
     (+
      U
      (*
       t_0
       (*
        J
        (+
         (* 0.3333333333333333 (pow l 3.0))
         (+
          (* 0.0003968253968253968 (pow l 7.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 <= -2e+58) || !(t_1 <= 0.0005)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + ((0.0003968253968253968 * pow(l, 7.0)) + ((0.016666666666666666 * pow(l, 5.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 <= (-2d+58)) .or. (.not. (t_1 <= 0.0005d0))) then
        tmp = (t_0 * (t_1 * j)) + u
    else
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + ((0.0003968253968253968d0 * (l ** 7.0d0)) + ((0.016666666666666666d0 * (l ** 5.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 <= -2e+58) || !(t_1 <= 0.0005)) {
		tmp = (t_0 * (t_1 * J)) + U;
	} else {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + ((0.0003968253968253968 * Math.pow(l, 7.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 <= -2e+58) or not (t_1 <= 0.0005):
		tmp = (t_0 * (t_1 * J)) + U
	else:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + ((0.0003968253968253968 * math.pow(l, 7.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 <= -2e+58) || !(t_1 <= 0.0005))
		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.0003968253968253968 * (l ^ 7.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 <= -2e+58) || ~((t_1 <= 0.0005)))
		tmp = (t_0 * (t_1 * J)) + U;
	else
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + ((0.0003968253968253968 * (l ^ 7.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, -2e+58], N[Not[LessEqual[t$95$1, 0.0005]], $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.0003968253968253968 * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+58} \lor \neg \left(t_1 \leq 0.0005\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.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\right)\\


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

    1. Initial program 70.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} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + 2 \cdot \ell\right)\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 -2 \cdot 10^{+58} \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.0005\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.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\right)\\ \end{array} \]

Alternative 2: 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.05 \lor \neg \left(t_1 \leq 0.0005\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.05) (not (<= t_1 0.0005)))
     (+ (* 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.05) || !(t_1 <= 0.0005)) {
		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.05d0)) .or. (.not. (t_1 <= 0.0005d0))) 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.05) || !(t_1 <= 0.0005)) {
		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.05) or not (t_1 <= 0.0005):
		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.05) || !(t_1 <= 0.0005))
		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.05) || ~((t_1 <= 0.0005)))
		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.05], N[Not[LessEqual[t$95$1, 0.0005]], $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.05 \lor \neg \left(t_1 \leq 0.0005\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.050000000000000003 or 5.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 -0.050000000000000003 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.0000000000000001e-4

    1. Initial program 70.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Taylor expanded in 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.05 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0.0005\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 3: 77.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t_0 \leq -0.75:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;t_0 \leq -0.15:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 -0.75)
     (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
     (if (<= t_0 -0.15)
       (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))
       (+ U (* J (* l (fma 0.3333333333333333 (* l 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.75) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (t_0 <= -0.15) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = U + (J * (l * fma(0.3333333333333333, (l * 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.75)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (t_0 <= -0.15)
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	else
		tmp = Float64(U + Float64(J * Float64(l * fma(0.3333333333333333, Float64(l * l), 2.0))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.75], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.15], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 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.75:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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

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


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

    1. Initial program 90.0%

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

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

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

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

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

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

    if -0.75 < (cos.f64 (/.f64 K 2)) < -0.149999999999999994

    1. Initial program 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(2 \cdot \ell + 0.3333333333333333 \cdot \color{blue}{\left(\left(\ell \cdot \ell\right) \cdot \ell\right)}\right) + U \]
      5. associate-*r*81.2%

        \[\leadsto J \cdot \left(2 \cdot \ell + \color{blue}{\left(0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right) \cdot \ell}\right) + U \]
      6. distribute-rgt-out81.2%

        \[\leadsto J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)} + U \]
      7. +-commutative81.2%

        \[\leadsto J \cdot \left(\ell \cdot \color{blue}{\left(0.3333333333333333 \cdot \left(\ell \cdot \ell\right) + 2\right)}\right) + U \]
      8. fma-def81.2%

        \[\leadsto J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)}\right) + U \]
    5. Simplified81.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.75:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.15:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\ \end{array} \]

Alternative 4: 95.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -62:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 5.6:\\ \;\;\;\;U + t_0 \cdot \left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* t_0 (* (pow l 7.0) (* J 0.0003968253968253968))))))
   (if (<= l -1.25e+96)
     t_1
     (if (<= l -62.0)
       (* (- (exp l) (exp (- l))) J)
       (if (<= l 5.6)
         (+
          U
          (* t_0 (+ (* 2.0 (* l J)) (* 0.3333333333333333 (* J (pow l 3.0))))))
         t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = U + (t_0 * (pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.25e+96) {
		tmp = t_1;
	} else if (l <= -62.0) {
		tmp = (exp(l) - exp(-l)) * J;
	} else if (l <= 5.6) {
		tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * pow(l, 3.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 / 2.0d0))
    t_1 = u + (t_0 * ((l ** 7.0d0) * (j * 0.0003968253968253968d0)))
    if (l <= (-1.25d+96)) then
        tmp = t_1
    else if (l <= (-62.0d0)) then
        tmp = (exp(l) - exp(-l)) * j
    else if (l <= 5.6d0) then
        tmp = u + (t_0 * ((2.0d0 * (l * j)) + (0.3333333333333333d0 * (j * (l ** 3.0d0)))))
    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 / 2.0));
	double t_1 = U + (t_0 * (Math.pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.25e+96) {
		tmp = t_1;
	} else if (l <= -62.0) {
		tmp = (Math.exp(l) - Math.exp(-l)) * J;
	} else if (l <= 5.6) {
		tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * Math.pow(l, 3.0)))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (math.pow(l, 7.0) * (J * 0.0003968253968253968)))
	tmp = 0
	if l <= -1.25e+96:
		tmp = t_1
	elif l <= -62.0:
		tmp = (math.exp(l) - math.exp(-l)) * J
	elif l <= 5.6:
		tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * math.pow(l, 3.0)))))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(U + Float64(t_0 * Float64((l ^ 7.0) * Float64(J * 0.0003968253968253968))))
	tmp = 0.0
	if (l <= -1.25e+96)
		tmp = t_1;
	elseif (l <= -62.0)
		tmp = Float64(Float64(exp(l) - exp(Float64(-l))) * J);
	elseif (l <= 5.6)
		tmp = Float64(U + Float64(t_0 * Float64(Float64(2.0 * Float64(l * J)) + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * ((l ^ 7.0) * (J * 0.0003968253968253968)));
	tmp = 0.0;
	if (l <= -1.25e+96)
		tmp = t_1;
	elseif (l <= -62.0)
		tmp = (exp(l) - exp(-l)) * J;
	elseif (l <= 5.6)
		tmp = U + (t_0 * ((2.0 * (l * J)) + (0.3333333333333333 * (J * (l ^ 3.0)))));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(N[Power[l, 7.0], $MachinePrecision] * N[(J * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.25e+96], t$95$1, If[LessEqual[l, -62.0], N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision], If[LessEqual[l, 5.6], N[(U + N[(t$95$0 * N[(N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\
\mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.2500000000000001e96 or 5.5999999999999996 < l

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(0.0003968253968253968 \cdot {\ell}^{7}\right) \cdot J\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative95.7%

        \[\leadsto \left(\color{blue}{\left({\ell}^{7} \cdot 0.0003968253968253968\right)} \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. associate-*l*95.7%

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

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

    if -1.2500000000000001e96 < l < -62

    1. Initial program 99.9%

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

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

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

    if -62 < l < 5.5999999999999996

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{elif}\;\ell \leq -62:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 5.6:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \end{array} \]

Alternative 5: 95.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{if}\;\ell \leq -1.5 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -105:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 5.6:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* t_0 (* (pow l 7.0) (* J 0.0003968253968253968))))))
   (if (<= l -1.5e+96)
     t_1
     (if (<= l -105.0)
       (* (- (exp l) (exp (- l))) J)
       (if (<= l 5.6)
         (+ U (* t_0 (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))))
         t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = U + (t_0 * (pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.5e+96) {
		tmp = t_1;
	} else if (l <= -105.0) {
		tmp = (exp(l) - exp(-l)) * J;
	} else if (l <= 5.6) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.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 / 2.0d0))
    t_1 = u + (t_0 * ((l ** 7.0d0) * (j * 0.0003968253968253968d0)))
    if (l <= (-1.5d+96)) then
        tmp = t_1
    else if (l <= (-105.0d0)) then
        tmp = (exp(l) - exp(-l)) * j
    else if (l <= 5.6d0) then
        tmp = u + (t_0 * (j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))))
    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 / 2.0));
	double t_1 = U + (t_0 * (Math.pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.5e+96) {
		tmp = t_1;
	} else if (l <= -105.0) {
		tmp = (Math.exp(l) - Math.exp(-l)) * J;
	} else if (l <= 5.6) {
		tmp = U + (t_0 * (J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (math.pow(l, 7.0) * (J * 0.0003968253968253968)))
	tmp = 0
	if l <= -1.5e+96:
		tmp = t_1
	elif l <= -105.0:
		tmp = (math.exp(l) - math.exp(-l)) * J
	elif l <= 5.6:
		tmp = U + (t_0 * (J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(U + Float64(t_0 * Float64((l ^ 7.0) * Float64(J * 0.0003968253968253968))))
	tmp = 0.0
	if (l <= -1.5e+96)
		tmp = t_1;
	elseif (l <= -105.0)
		tmp = Float64(Float64(exp(l) - exp(Float64(-l))) * J);
	elseif (l <= 5.6)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * ((l ^ 7.0) * (J * 0.0003968253968253968)));
	tmp = 0.0;
	if (l <= -1.5e+96)
		tmp = t_1;
	elseif (l <= -105.0)
		tmp = (exp(l) - exp(-l)) * J;
	elseif (l <= 5.6)
		tmp = U + (t_0 * (J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(N[Power[l, 7.0], $MachinePrecision] * N[(J * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.5e+96], t$95$1, If[LessEqual[l, -105.0], N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision], If[LessEqual[l, 5.6], 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], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\
\mathbf{if}\;\ell \leq -1.5 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.5e96 or 5.5999999999999996 < l

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(0.0003968253968253968 \cdot {\ell}^{7}\right) \cdot J\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative95.7%

        \[\leadsto \left(\color{blue}{\left({\ell}^{7} \cdot 0.0003968253968253968\right)} \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. associate-*l*95.7%

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

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

    if -1.5e96 < l < -105

    1. Initial program 99.9%

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

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

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

    if -105 < l < 5.5999999999999996

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.5 \cdot 10^{+96}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{elif}\;\ell \leq -105:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 5.6:\\ \;\;\;\;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 + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \end{array} \]

Alternative 6: 95.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -118:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 4:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0)))
        (t_1 (+ U (* t_0 (* (pow l 7.0) (* J 0.0003968253968253968))))))
   (if (<= l -1.25e+96)
     t_1
     (if (<= l -118.0)
       (* (- (exp l) (exp (- l))) J)
       (if (<= l 4.0) (+ U (* t_0 (* J (* l 2.0)))) t_1)))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double t_1 = U + (t_0 * (pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.25e+96) {
		tmp = t_1;
	} else if (l <= -118.0) {
		tmp = (exp(l) - exp(-l)) * J;
	} else if (l <= 4.0) {
		tmp = U + (t_0 * (J * (l * 2.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 / 2.0d0))
    t_1 = u + (t_0 * ((l ** 7.0d0) * (j * 0.0003968253968253968d0)))
    if (l <= (-1.25d+96)) then
        tmp = t_1
    else if (l <= (-118.0d0)) then
        tmp = (exp(l) - exp(-l)) * j
    else if (l <= 4.0d0) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    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 / 2.0));
	double t_1 = U + (t_0 * (Math.pow(l, 7.0) * (J * 0.0003968253968253968)));
	double tmp;
	if (l <= -1.25e+96) {
		tmp = t_1;
	} else if (l <= -118.0) {
		tmp = (Math.exp(l) - Math.exp(-l)) * J;
	} else if (l <= 4.0) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	t_1 = U + (t_0 * (math.pow(l, 7.0) * (J * 0.0003968253968253968)))
	tmp = 0
	if l <= -1.25e+96:
		tmp = t_1
	elif l <= -118.0:
		tmp = (math.exp(l) - math.exp(-l)) * J
	elif l <= 4.0:
		tmp = U + (t_0 * (J * (l * 2.0)))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	t_1 = Float64(U + Float64(t_0 * Float64((l ^ 7.0) * Float64(J * 0.0003968253968253968))))
	tmp = 0.0
	if (l <= -1.25e+96)
		tmp = t_1;
	elseif (l <= -118.0)
		tmp = Float64(Float64(exp(l) - exp(Float64(-l))) * J);
	elseif (l <= 4.0)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	t_1 = U + (t_0 * ((l ^ 7.0) * (J * 0.0003968253968253968)));
	tmp = 0.0;
	if (l <= -1.25e+96)
		tmp = t_1;
	elseif (l <= -118.0)
		tmp = (exp(l) - exp(-l)) * J;
	elseif (l <= 4.0)
		tmp = U + (t_0 * (J * (l * 2.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(t$95$0 * N[(N[Power[l, 7.0], $MachinePrecision] * N[(J * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.25e+96], t$95$1, If[LessEqual[l, -118.0], N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision], If[LessEqual[l, 4.0], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U + t_0 \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\
\mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.2500000000000001e96 or 4 < l

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(0.0003968253968253968 \cdot {\ell}^{7}\right) \cdot J\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative95.7%

        \[\leadsto \left(\color{blue}{\left({\ell}^{7} \cdot 0.0003968253968253968\right)} \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. associate-*l*95.7%

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

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

    if -1.2500000000000001e96 < l < -118

    1. Initial program 99.9%

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

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

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

    if -118 < l < 4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.25 \cdot 10^{+96}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \mathbf{elif}\;\ell \leq -118:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 4:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right)\\ \end{array} \]

Alternative 7: 85.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -130:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{-9}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.65 \cdot 10^{+221}:\\ \;\;\;\;U + t_0\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (- (exp l) (exp (- l))) J)))
   (if (<= l -130.0)
     t_0
     (if (<= l 1.65e-9)
       (+ U (* (cos (/ K 2.0)) (* J (* l 2.0))))
       (if (<= l 2.65e+221)
         (+ U t_0)
         (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = (exp(l) - exp(-l)) * J;
	double tmp;
	if (l <= -130.0) {
		tmp = t_0;
	} else if (l <= 1.65e-9) {
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 2.65e+221) {
		tmp = U + t_0;
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (exp(l) - exp(-l)) * j
    if (l <= (-130.0d0)) then
        tmp = t_0
    else if (l <= 1.65d-9) then
        tmp = u + (cos((k / 2.0d0)) * (j * (l * 2.0d0)))
    else if (l <= 2.65d+221) then
        tmp = u + t_0
    else
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = (Math.exp(l) - Math.exp(-l)) * J;
	double tmp;
	if (l <= -130.0) {
		tmp = t_0;
	} else if (l <= 1.65e-9) {
		tmp = U + (Math.cos((K / 2.0)) * (J * (l * 2.0)));
	} else if (l <= 2.65e+221) {
		tmp = U + t_0;
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = (math.exp(l) - math.exp(-l)) * J
	tmp = 0
	if l <= -130.0:
		tmp = t_0
	elif l <= 1.65e-9:
		tmp = U + (math.cos((K / 2.0)) * (J * (l * 2.0)))
	elif l <= 2.65e+221:
		tmp = U + t_0
	else:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	tmp = 0.0
	if (l <= -130.0)
		tmp = t_0;
	elseif (l <= 1.65e-9)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * 2.0))));
	elseif (l <= 2.65e+221)
		tmp = Float64(U + t_0);
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = (exp(l) - exp(-l)) * J;
	tmp = 0.0;
	if (l <= -130.0)
		tmp = t_0;
	elseif (l <= 1.65e-9)
		tmp = U + (cos((K / 2.0)) * (J * (l * 2.0)));
	elseif (l <= 2.65e+221)
		tmp = U + t_0;
	else
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, If[LessEqual[l, -130.0], t$95$0, If[LessEqual[l, 1.65e-9], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.65e+221], N[(U + t$95$0), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -130:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{-9}:\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 2.65 \cdot 10^{+221}:\\
\;\;\;\;U + t_0\\

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


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

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

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

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

    if -130 < l < 1.65000000000000009e-9

    1. Initial program 70.5%

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

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

    if 1.65000000000000009e-9 < l < 2.6499999999999998e221

    1. Initial program 99.6%

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

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

    if 2.6499999999999998e221 < 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 46.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out88.2%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2} + 2\right)} + U \]
      4. *-commutative88.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -130:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{-9}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.65 \cdot 10^{+221}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 8: 84.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -17:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 2.65 \cdot 10^{+221}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -17 or 2.4499999999999999e-4 < l < 2.6499999999999998e221

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

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

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

    if -17 < l < 2.4499999999999999e-4

    1. Initial program 70.7%

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

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

    if 2.6499999999999998e221 < 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 46.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out88.2%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(-0.25 \cdot {K}^{2} + 2\right)} + U \]
      4. *-commutative88.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -17:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.000245:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 2.65 \cdot 10^{+221}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 9: 69.6% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.8 \cdot 10^{+118}:\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+153}:\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.79999999999999986e118

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

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

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

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

    if -2.79999999999999986e118 < l < 1.5e36

    1. Initial program 75.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 86.3%

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

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

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

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

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

    if 1.5e36 < l < 1.2999999999999999e153

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

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

    if 1.2999999999999999e153 < 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 40.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+118}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 1.5 \cdot 10^{+36}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+153}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 10: 58.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{if}\;\ell \leq -520:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))
   (if (<= l -520.0)
     t_0
     (if (<= l 1.4e+36)
       (fma (* l 2.0) J U)
       (if (<= l 2.1e+152) (* U U) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	double tmp;
	if (l <= -520.0) {
		tmp = t_0;
	} else if (l <= 1.4e+36) {
		tmp = fma((l * 2.0), J, U);
	} else if (l <= 2.1e+152) {
		tmp = U * U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))))
	tmp = 0.0
	if (l <= -520.0)
		tmp = t_0;
	elseif (l <= 1.4e+36)
		tmp = fma(Float64(l * 2.0), J, U);
	elseif (l <= 2.1e+152)
		tmp = Float64(U * U);
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -520.0], t$95$0, If[LessEqual[l, 1.4e+36], N[(N[(l * 2.0), $MachinePrecision] * J + U), $MachinePrecision], If[LessEqual[l, 2.1e+152], N[(U * U), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\
\mathbf{if}\;\ell \leq -520:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\

\mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+152}:\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -520 or 2.1000000000000002e152 < 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 35.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out48.6%

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

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

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

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

    if -520 < l < 1.4e36

    1. Initial program 72.5%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(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}{2 \cdot \left(\ell \cdot J\right) + U} \]
    4. Step-by-step derivation
      1. associate-*r*86.1%

        \[\leadsto \color{blue}{\left(2 \cdot \ell\right) \cdot J} + U \]
      2. fma-def86.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \ell, J, U\right)} \]
      3. *-commutative86.1%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\ell \cdot 2}, J, U\right) \]
    5. Simplified86.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\ell \cdot 2, J, U\right)} \]

    if 1.4e36 < l < 2.1000000000000002e152

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -520:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 11: 64.4% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -9.8 \cdot 10^{+39}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -9.8e+39)
   (* 0.3333333333333333 (* J (pow l 3.0)))
   (if (<= l 2.1e+36)
     (fma (* l 2.0) J U)
     (if (<= l 2.6e+152)
       (* U U)
       (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -9.8e+39) {
		tmp = 0.3333333333333333 * (J * pow(l, 3.0));
	} else if (l <= 2.1e+36) {
		tmp = fma((l * 2.0), J, U);
	} else if (l <= 2.6e+152) {
		tmp = U * U;
	} else {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -9.8e+39)
		tmp = Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)));
	elseif (l <= 2.1e+36)
		tmp = fma(Float64(l * 2.0), J, U);
	elseif (l <= 2.6e+152)
		tmp = Float64(U * U);
	else
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -9.8e+39], N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.1e+36], N[(N[(l * 2.0), $MachinePrecision] * J + U), $MachinePrecision], If[LessEqual[l, 2.6e+152], N[(U * U), $MachinePrecision], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -9.8 \cdot 10^{+39}:\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

\mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\

\mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+152}:\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -9.79999999999999974e39

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

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

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

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

    if -9.79999999999999974e39 < l < 2.10000000000000004e36

    1. Initial program 73.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 92.2%

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

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

        \[\leadsto \color{blue}{\left(2 \cdot \ell\right) \cdot J} + U \]
      2. fma-def83.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \ell, J, U\right)} \]
      3. *-commutative83.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\ell \cdot 2}, J, U\right) \]
    5. Simplified83.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\ell \cdot 2, J, U\right)} \]

    if 2.10000000000000004e36 < l < 2.6000000000000001e152

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

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

    if 2.6000000000000001e152 < 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 40.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.8 \cdot 10^{+39}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot 2, J, U\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 12: 58.7% accurate, 16.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{if}\;\ell \leq -350:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 2.05 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))))
   (if (<= l -350.0)
     t_0
     (if (<= l 2.1e+36)
       (+ U (* 2.0 (* l J)))
       (if (<= l 2.05e+152) (* U U) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	double tmp;
	if (l <= -350.0) {
		tmp = t_0;
	} else if (l <= 2.1e+36) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 2.05e+152) {
		tmp = U * U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    if (l <= (-350.0d0)) then
        tmp = t_0
    else if (l <= 2.1d+36) then
        tmp = u + (2.0d0 * (l * j))
    else if (l <= 2.05d+152) then
        tmp = u * u
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	double tmp;
	if (l <= -350.0) {
		tmp = t_0;
	} else if (l <= 2.1e+36) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 2.05e+152) {
		tmp = U * U;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	tmp = 0
	if l <= -350.0:
		tmp = t_0
	elif l <= 2.1e+36:
		tmp = U + (2.0 * (l * J))
	elif l <= 2.05e+152:
		tmp = U * U
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))))
	tmp = 0.0
	if (l <= -350.0)
		tmp = t_0;
	elseif (l <= 2.1e+36)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	elseif (l <= 2.05e+152)
		tmp = Float64(U * U);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	tmp = 0.0;
	if (l <= -350.0)
		tmp = t_0;
	elseif (l <= 2.1e+36)
		tmp = U + (2.0 * (l * J));
	elseif (l <= 2.05e+152)
		tmp = U * U;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -350.0], t$95$0, If[LessEqual[l, 2.1e+36], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.05e+152], N[(U * U), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\
\mathbf{if}\;\ell \leq -350:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\

\mathbf{elif}\;\ell \leq 2.05 \cdot 10^{+152}:\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -350 or 2.0499999999999999e152 < 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 35.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)} + 2 \cdot \left(\ell \cdot J\right)\right) + U \]
      3. distribute-rgt-out48.6%

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

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

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

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

    if -350 < l < 2.10000000000000004e36

    1. Initial program 72.5%

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

      \[\leadsto \left(J \cdot \color{blue}{\left(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}{2 \cdot \left(\ell \cdot J\right) + U} \]

    if 2.10000000000000004e36 < l < 2.0499999999999999e152

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -350:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{elif}\;\ell \leq 2.1 \cdot 10^{+36}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 2.05 \cdot 10^{+152}:\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \end{array} \]

Alternative 13: 43.8% accurate, 34.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq -1.9 \cdot 10^{+76} \lor \neg \left(J \leq 6.9 \cdot 10^{+165}\right):\\
\;\;\;\;2 \cdot \left(\ell \cdot J\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -1.90000000000000012e76 or 6.90000000000000006e165 < J

    1. Initial program 64.0%

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

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

      \[\leadsto \color{blue}{2 \cdot \left(\ell \cdot J\right) + U} \]
    4. Taylor expanded in l around inf 56.8%

      \[\leadsto \color{blue}{2 \cdot \left(\ell \cdot J\right)} \]

    if -1.90000000000000012e76 < J < 6.90000000000000006e165

    1. Initial program 94.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;J \leq -1.9 \cdot 10^{+76} \lor \neg \left(J \leq 6.9 \cdot 10^{+165}\right):\\ \;\;\;\;2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 14: 53.0% accurate, 34.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.4 \cdot 10^{+36}:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.4e36

    1. Initial program 81.5%

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

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

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

    if 1.4e36 < 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-rr32.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.4 \cdot 10^{+36}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 15: 43.0% accurate, 43.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -130 or 2.4499999999999999e-4 < 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-rr22.5%

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

    if -130 < l < 2.4499999999999999e-4

    1. Initial program 70.7%

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

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

Alternative 16: 2.8% 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 84.8%

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

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

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

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

    \[\leadsto 1 \]

Alternative 17: 37.1% accurate, 312.0× speedup?

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

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

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

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

    \[\leadsto U \]

Reproduce

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