Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.6%
Time: 11.6s
Alternatives: 16
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 86.3% 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.6% 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.02 \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;U + \left(t_1 \cdot J\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(\ell \cdot J\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.02) (not (<= t_1 0.0)))
     (+ U (* (* t_1 J) t_0))
     (+
      U
      (* t_0 (+ (* 0.3333333333333333 (* J (pow l 3.0))) (* 2.0 (* l J))))))))
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.02) || !(t_1 <= 0.0)) {
		tmp = U + ((t_1 * J) * t_0);
	} else {
		tmp = U + (t_0 * ((0.3333333333333333 * (J * pow(l, 3.0))) + (2.0 * (l * J))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: 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.02d0)) .or. (.not. (t_1 <= 0.0d0))) then
        tmp = u + ((t_1 * j) * t_0)
    else
        tmp = u + (t_0 * ((0.3333333333333333d0 * (j * (l ** 3.0d0))) + (2.0d0 * (l * j))))
    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.02) || !(t_1 <= 0.0)) {
		tmp = U + ((t_1 * J) * t_0);
	} else {
		tmp = U + (t_0 * ((0.3333333333333333 * (J * Math.pow(l, 3.0))) + (2.0 * (l * J))));
	}
	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.02) or not (t_1 <= 0.0):
		tmp = U + ((t_1 * J) * t_0)
	else:
		tmp = U + (t_0 * ((0.3333333333333333 * (J * math.pow(l, 3.0))) + (2.0 * (l * J))))
	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.02) || !(t_1 <= 0.0))
		tmp = Float64(U + Float64(Float64(t_1 * J) * t_0));
	else
		tmp = Float64(U + Float64(t_0 * Float64(Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))) + Float64(2.0 * Float64(l * J)))));
	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.02) || ~((t_1 <= 0.0)))
		tmp = U + ((t_1 * J) * t_0);
	else
		tmp = U + (t_0 * ((0.3333333333333333 * (J * (l ^ 3.0))) + (2.0 * (l * J))));
	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.02], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(U + N[(N[(t$95$1 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(U + N[(t$95$0 * N[(N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(l * J), $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.02 \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;U + \left(t_1 \cdot J\right) \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;U + t_0 \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(\ell \cdot J\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.0200000000000000004 or 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 99.9%

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

    if -0.0200000000000000004 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

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

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(J \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.02 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 0\right):\\ \;\;\;\;U + \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 2 \cdot \left(\ell \cdot J\right)\right)\\ \end{array} \]

Alternative 2: 97.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq 0.01:\\ \;\;\;\;\mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot t_0, \mathsf{fma}\left(0.016666666666666666, t_0 \cdot \left(J \cdot {\ell}^{5}\right), 0.3333333333333333 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{3}\right)\right) + 2 \cdot \left(t_0 \cdot \left(\ell \cdot J\right)\right)\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(t_1 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* 0.5 K))) (t_1 (- (exp l) (exp (- l)))))
   (if (<= t_1 0.01)
     (+
      (fma
       0.0003968253968253968
       (* (* (pow l 7.0) J) t_0)
       (fma
        0.016666666666666666
        (* t_0 (* J (pow l 5.0)))
        (+
         (* 0.3333333333333333 (* J (* t_0 (pow l 3.0))))
         (* 2.0 (* t_0 (* l J))))))
      U)
     (+ U (* (* t_1 J) (cos (/ K 2.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((0.5 * K));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if (t_1 <= 0.01) {
		tmp = fma(0.0003968253968253968, ((pow(l, 7.0) * J) * t_0), fma(0.016666666666666666, (t_0 * (J * pow(l, 5.0))), ((0.3333333333333333 * (J * (t_0 * pow(l, 3.0)))) + (2.0 * (t_0 * (l * J)))))) + U;
	} else {
		tmp = U + ((t_1 * J) * cos((K / 2.0)));
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = cos(Float64(0.5 * K))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if (t_1 <= 0.01)
		tmp = Float64(fma(0.0003968253968253968, Float64(Float64((l ^ 7.0) * J) * t_0), fma(0.016666666666666666, Float64(t_0 * Float64(J * (l ^ 5.0))), Float64(Float64(0.3333333333333333 * Float64(J * Float64(t_0 * (l ^ 3.0)))) + Float64(2.0 * Float64(t_0 * Float64(l * J)))))) + U);
	else
		tmp = Float64(U + Float64(Float64(t_1 * J) * cos(Float64(K / 2.0))));
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.01], N[(N[(0.0003968253968253968 * N[(N[(N[Power[l, 7.0], $MachinePrecision] * J), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(0.016666666666666666 * N[(t$95$0 * N[(J * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 * N[(J * N[(t$95$0 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(t$95$0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(t$95$1 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot K\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_1 \leq 0.01:\\
\;\;\;\;\mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot t_0, \mathsf{fma}\left(0.016666666666666666, t_0 \cdot \left(J \cdot {\ell}^{5}\right), 0.3333333333333333 \cdot \left(J \cdot \left(t_0 \cdot {\ell}^{3}\right)\right) + 2 \cdot \left(t_0 \cdot \left(\ell \cdot J\right)\right)\right)\right) + U\\

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


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

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

      \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + \left(0.016666666666666666 \cdot \left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. fma-def97.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.0003968253968253968, J \cdot \left({\ell}^{7} \cdot \cos \left(0.5 \cdot K\right)\right), 0.016666666666666666 \cdot \left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + \left(0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)\right)} + U \]
      2. associate-*r*97.9%

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

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

        \[\leadsto \mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\mathsf{fma}\left(0.016666666666666666, J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right), 0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}\right) + U \]
      5. associate-*r*97.9%

        \[\leadsto \mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \mathsf{fma}\left(0.016666666666666666, \color{blue}{\left(J \cdot {\ell}^{5}\right) \cdot \cos \left(0.5 \cdot K\right)}, 0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)\right) + U \]
      6. *-commutative97.9%

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

        \[\leadsto \mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \mathsf{fma}\left(0.016666666666666666, \left({\ell}^{5} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\mathsf{fma}\left(0.3333333333333333, J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right), 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}\right)\right) + U \]
      8. associate-*r*97.9%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \mathsf{fma}\left(0.016666666666666666, \left({\ell}^{5} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \mathsf{fma}\left(0.3333333333333333, J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right), 2 \cdot \left(\left(\ell \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)\right)} + U \]
    5. Step-by-step derivation
      1. fma-udef97.9%

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

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

        \[\leadsto \mathsf{fma}\left(0.0003968253968253968, \left({\ell}^{7} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), \mathsf{fma}\left(0.016666666666666666, \left({\ell}^{5} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right), 0.3333333333333333 \cdot \left(J \cdot \left({\ell}^{3} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + 2 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\left(J \cdot \ell\right)}\right)\right)\right) + U \]
    6. Applied egg-rr97.9%

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

    if 0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

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

Alternative 3: 97.5% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t_0 \leq 0.01:\\
\;\;\;\;U + t_1 \cdot \left(J \cdot \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + \left(t_0 \cdot J\right) \cdot t_1\\


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

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

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

    if 0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

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

Alternative 4: 96.5% accurate, 0.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + \left(t_0 \cdot J\right) \cdot t_1\\


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

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

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

    if 0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

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

Alternative 5: 96.5% accurate, 0.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + \left(t_0 \cdot J\right) \cdot t_1\\


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

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

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

    if 0.0100000000000000002 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

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

Alternative 6: 87.2% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 0.0002:\\
\;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\

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


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

    1. Initial program 85.3%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative76.6%

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
      2. fma-def76.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(e^{\ell} - e^{-\ell}, J, U\right)} \]
      3. sinh-undef86.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \sinh \ell}, J, U\right) \]
    4. Applied egg-rr86.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \sinh \ell, J, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef86.7%

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

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    6. Applied egg-rr86.7%

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

    if 2.0000000000000001e-4 < (/.f64 K 2)

    1. Initial program 89.5%

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

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

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

Alternative 7: 87.2% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 0.0002:\\
\;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\

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

    1. Initial program 85.3%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative76.6%

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot J} + U \]
      2. fma-def76.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(e^{\ell} - e^{-\ell}, J, U\right)} \]
      3. sinh-undef86.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \sinh \ell}, J, U\right) \]
    4. Applied egg-rr86.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \sinh \ell, J, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef86.7%

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

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    6. Applied egg-rr86.7%

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

    if 2.0000000000000001e-4 < (/.f64 K 2)

    1. Initial program 89.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 0.0002:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\ \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 8: 96.0% 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(0.0003968253968253968 \cdot J\right)\right)\\ \mathbf{if}\;\ell \leq -4.2:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-28}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.1 \cdot 10^{+44}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\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) (* 0.0003968253968253968 J))))))
   (if (<= l -4.2)
     t_1
     (if (<= l 1.45e-28)
       (+ U (* t_0 (* J (* l 2.0))))
       (if (<= l 1.1e+44) (+ U (* J (* 2.0 (sinh l)))) 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) * (0.0003968253968253968 * J)));
	double tmp;
	if (l <= -4.2) {
		tmp = t_1;
	} else if (l <= 1.45e-28) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 1.1e+44) {
		tmp = U + (J * (2.0 * sinh(l)));
	} 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) * (0.0003968253968253968d0 * j)))
    if (l <= (-4.2d0)) then
        tmp = t_1
    else if (l <= 1.45d-28) then
        tmp = u + (t_0 * (j * (l * 2.0d0)))
    else if (l <= 1.1d+44) then
        tmp = u + (j * (2.0d0 * sinh(l)))
    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) * (0.0003968253968253968 * J)));
	double tmp;
	if (l <= -4.2) {
		tmp = t_1;
	} else if (l <= 1.45e-28) {
		tmp = U + (t_0 * (J * (l * 2.0)));
	} else if (l <= 1.1e+44) {
		tmp = U + (J * (2.0 * Math.sinh(l)));
	} 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) * (0.0003968253968253968 * J)))
	tmp = 0
	if l <= -4.2:
		tmp = t_1
	elif l <= 1.45e-28:
		tmp = U + (t_0 * (J * (l * 2.0)))
	elif l <= 1.1e+44:
		tmp = U + (J * (2.0 * math.sinh(l)))
	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(0.0003968253968253968 * J))))
	tmp = 0.0
	if (l <= -4.2)
		tmp = t_1;
	elseif (l <= 1.45e-28)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * 2.0))));
	elseif (l <= 1.1e+44)
		tmp = Float64(U + Float64(J * Float64(2.0 * sinh(l))));
	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) * (0.0003968253968253968 * J)));
	tmp = 0.0;
	if (l <= -4.2)
		tmp = t_1;
	elseif (l <= 1.45e-28)
		tmp = U + (t_0 * (J * (l * 2.0)));
	elseif (l <= 1.1e+44)
		tmp = U + (J * (2.0 * sinh(l)));
	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[(0.0003968253968253968 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.2], t$95$1, If[LessEqual[l, 1.45e-28], N[(U + N[(t$95$0 * N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.1e+44], N[(U + N[(J * N[(2.0 * N[Sinh[l], $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(0.0003968253968253968 \cdot J\right)\right)\\
\mathbf{if}\;\ell \leq -4.2:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.20000000000000018 or 1.09999999999999998e44 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -4.20000000000000018 < l < 1.45000000000000006e-28

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

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

    if 1.45000000000000006e-28 < l < 1.09999999999999998e44

    1. Initial program 92.4%

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(e^{\ell} - e^{-\ell}, J, U\right)} \]
      3. sinh-undef92.3%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \sinh \ell, J, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef92.3%

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

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    6. Applied egg-rr92.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(0.0003968253968253968 \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-28}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.1 \cdot 10^{+44}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \sinh \ell\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left({\ell}^{7} \cdot \left(0.0003968253968253968 \cdot J\right)\right)\\ \end{array} \]

Alternative 9: 85.2% accurate, 1.5× speedup?

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

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

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


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

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

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

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

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

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

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

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

    1. Initial program 85.4%

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(e^{\ell} - e^{-\ell}, J, U\right)} \]
      3. sinh-undef93.6%

        \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot \sinh \ell}, J, U\right) \]
    4. Applied egg-rr93.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot \sinh \ell, J, U\right)} \]
    5. Step-by-step derivation
      1. fma-udef93.6%

        \[\leadsto \color{blue}{\left(2 \cdot \sinh \ell\right) \cdot J + U} \]
      2. *-commutative93.6%

        \[\leadsto \color{blue}{J \cdot \left(2 \cdot \sinh \ell\right)} + U \]
    6. Applied egg-rr93.6%

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

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

Alternative 10: 59.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{if}\;\ell \leq -2.55 \cdot 10^{+82}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -880:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 0.00335:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 4 \cdot 10^{+98} \lor \neg \left(\ell \leq 1.26 \cdot 10^{+194}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{U}^{-8}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (+ l (* -0.125 (* l (* K K)))))))))
   (if (<= l -2.55e+82)
     t_0
     (if (<= l -880.0)
       (pow U -8.0)
       (if (<= l 0.00335)
         (+ U (* J (* l 2.0)))
         (if (or (<= l 4e+98) (not (<= l 1.26e+194))) t_0 (pow U -8.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * (K * K))))));
	double tmp;
	if (l <= -2.55e+82) {
		tmp = t_0;
	} else if (l <= -880.0) {
		tmp = pow(U, -8.0);
	} else if (l <= 0.00335) {
		tmp = U + (J * (l * 2.0));
	} else if ((l <= 4e+98) || !(l <= 1.26e+194)) {
		tmp = t_0;
	} else {
		tmp = pow(U, -8.0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (2.0d0 * (j * (l + ((-0.125d0) * (l * (k * k))))))
    if (l <= (-2.55d+82)) then
        tmp = t_0
    else if (l <= (-880.0d0)) then
        tmp = u ** (-8.0d0)
    else if (l <= 0.00335d0) then
        tmp = u + (j * (l * 2.0d0))
    else if ((l <= 4d+98) .or. (.not. (l <= 1.26d+194))) then
        tmp = t_0
    else
        tmp = u ** (-8.0d0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l + (-0.125 * (l * (K * K))))));
	double tmp;
	if (l <= -2.55e+82) {
		tmp = t_0;
	} else if (l <= -880.0) {
		tmp = Math.pow(U, -8.0);
	} else if (l <= 0.00335) {
		tmp = U + (J * (l * 2.0));
	} else if ((l <= 4e+98) || !(l <= 1.26e+194)) {
		tmp = t_0;
	} else {
		tmp = Math.pow(U, -8.0);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l + (-0.125 * (l * (K * K))))))
	tmp = 0
	if l <= -2.55e+82:
		tmp = t_0
	elif l <= -880.0:
		tmp = math.pow(U, -8.0)
	elif l <= 0.00335:
		tmp = U + (J * (l * 2.0))
	elif (l <= 4e+98) or not (l <= 1.26e+194):
		tmp = t_0
	else:
		tmp = math.pow(U, -8.0)
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l + Float64(-0.125 * Float64(l * Float64(K * K)))))))
	tmp = 0.0
	if (l <= -2.55e+82)
		tmp = t_0;
	elseif (l <= -880.0)
		tmp = U ^ -8.0;
	elseif (l <= 0.00335)
		tmp = Float64(U + Float64(J * Float64(l * 2.0)));
	elseif ((l <= 4e+98) || !(l <= 1.26e+194))
		tmp = t_0;
	else
		tmp = U ^ -8.0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (2.0 * (J * (l + (-0.125 * (l * (K * K))))));
	tmp = 0.0;
	if (l <= -2.55e+82)
		tmp = t_0;
	elseif (l <= -880.0)
		tmp = U ^ -8.0;
	elseif (l <= 0.00335)
		tmp = U + (J * (l * 2.0));
	elseif ((l <= 4e+98) || ~((l <= 1.26e+194)))
		tmp = t_0;
	else
		tmp = U ^ -8.0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l + N[(-0.125 * N[(l * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.55e+82], t$95$0, If[LessEqual[l, -880.0], N[Power[U, -8.0], $MachinePrecision], If[LessEqual[l, 0.00335], N[(U + N[(J * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 4e+98], N[Not[LessEqual[l, 1.26e+194]], $MachinePrecision]], t$95$0, N[Power[U, -8.0], $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 4 \cdot 10^{+98} \lor \neg \left(\ell \leq 1.26 \cdot 10^{+194}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.5500000000000001e82 or 0.00335000000000000011 < l < 3.99999999999999999e98 or 1.26e194 < l

    1. Initial program 99.9%

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

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

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

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

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

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

    if -2.5500000000000001e82 < l < -880 or 3.99999999999999999e98 < l < 1.26e194

    1. Initial program 100.0%

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

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

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

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

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

    if -880 < l < 0.00335000000000000011

    1. Initial program 71.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.55 \cdot 10^{+82}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -880:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 0.00335:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 4 \cdot 10^{+98} \lor \neg \left(\ell \leq 1.26 \cdot 10^{+194}\right):\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-8}\\ \end{array} \]

Alternative 11: 59.4% accurate, 16.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.00000000000000001e76 or 0.00335000000000000011 < l

    1. Initial program 99.9%

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

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

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

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

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

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

    if -7.00000000000000001e76 < l < 0.00335000000000000011

    1. Initial program 73.1%

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

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

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

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

Alternative 12: 44.1% accurate, 34.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.3 \cdot 10^{-29} \lor \neg \left(\ell \leq 1.15 \cdot 10^{-62}\right):\\
\;\;\;\;\ell \cdot \left(J \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.30000000000000028e-29 or 1.15e-62 < l

    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 K around 0 69.3%

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

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
    5. Step-by-step derivation
      1. *-commutative23.6%

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} \]
      2. *-commutative23.6%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right)} \cdot 2 \]
      3. associate-*r*23.6%

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

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

    if -3.30000000000000028e-29 < l < 1.15e-62

    1. Initial program 75.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{-29} \lor \neg \left(\ell \leq 1.15 \cdot 10^{-62}\right):\\ \;\;\;\;\ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 13: 41.5% accurate, 43.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -0.0115 or 860 < l

    1. Initial program 100.0%

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

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

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

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

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

    if -0.0115 < l < 860

    1. Initial program 71.5%

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

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

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

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

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

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

Alternative 14: 53.8% accurate, 44.6× speedup?

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

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

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

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

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

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

Alternative 15: 2.7% accurate, 312.0× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto 1 \]

Alternative 16: 36.3% accurate, 312.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto U \]

Reproduce

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