Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.8% → 99.3%
Time: 16.5s
Alternatives: 17
Speedup: 1.3×

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: 86.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot \left(J \cdot 2\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (log1p (expm1 (* (cos (* 0.5 K)) l))) (* J 2.0)) U))
double code(double J, double l, double K, double U) {
	return (log1p(expm1((cos((0.5 * K)) * l))) * (J * 2.0)) + U;
}
public static double code(double J, double l, double K, double U) {
	return (Math.log1p(Math.expm1((Math.cos((0.5 * K)) * l))) * (J * 2.0)) + U;
}
def code(J, l, K, U):
	return (math.log1p(math.expm1((math.cos((0.5 * K)) * l))) * (J * 2.0)) + U
function code(J, l, K, U)
	return Float64(Float64(log1p(expm1(Float64(cos(Float64(0.5 * K)) * l))) * Float64(J * 2.0)) + U)
end
code[J_, l_, K_, U_] := N[(N[(N[Log[1 + N[(Exp[N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * l), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision] * N[(J * 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right) \cdot \left(J \cdot 2\right) + U
\end{array}
Derivation
  1. Initial program 84.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} \cdot \left(J \cdot 2\right) + U \]
  11. Add Preprocessing

Alternative 2: 87.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot K\right)\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_1 \leq -0.82:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{t\_0 \cdot \ell}{U}\right)\right)\\ \mathbf{elif}\;t\_1 \leq -0.55:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\ \mathbf{elif}\;t\_1 \leq -0.005:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(t\_0 \cdot J\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* 0.5 K))) (t_1 (cos (/ K 2.0))))
   (if (<= t_1 -0.82)
     (* U (+ 1.0 (* 2.0 (* J (/ (* t_0 l) U)))))
     (if (<= t_1 -0.55)
       (+ U (* (* J 2.0) (+ l (* l (* -0.125 (pow K 2.0))))))
       (if (<= t_1 -0.005)
         (+ U (* 2.0 (* l (* t_0 J))))
         (+ U (* (* J 2.0) (log1p (expm1 l)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((0.5 * K));
	double t_1 = cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.82) {
		tmp = U * (1.0 + (2.0 * (J * ((t_0 * l) / U))));
	} else if (t_1 <= -0.55) {
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * pow(K, 2.0)))));
	} else if (t_1 <= -0.005) {
		tmp = U + (2.0 * (l * (t_0 * J)));
	} else {
		tmp = U + ((J * 2.0) * log1p(expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((0.5 * K));
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (t_1 <= -0.82) {
		tmp = U * (1.0 + (2.0 * (J * ((t_0 * l) / U))));
	} else if (t_1 <= -0.55) {
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * Math.pow(K, 2.0)))));
	} else if (t_1 <= -0.005) {
		tmp = U + (2.0 * (l * (t_0 * J)));
	} else {
		tmp = U + ((J * 2.0) * Math.log1p(Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((0.5 * K))
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if t_1 <= -0.82:
		tmp = U * (1.0 + (2.0 * (J * ((t_0 * l) / U))))
	elif t_1 <= -0.55:
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * math.pow(K, 2.0)))))
	elif t_1 <= -0.005:
		tmp = U + (2.0 * (l * (t_0 * J)))
	else:
		tmp = U + ((J * 2.0) * math.log1p(math.expm1(l)))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(0.5 * K))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_1 <= -0.82)
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(t_0 * l) / U)))));
	elseif (t_1 <= -0.55)
		tmp = Float64(U + Float64(Float64(J * 2.0) * Float64(l + Float64(l * Float64(-0.125 * (K ^ 2.0))))));
	elseif (t_1 <= -0.005)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(t_0 * J))));
	else
		tmp = Float64(U + Float64(Float64(J * 2.0) * log1p(expm1(l))));
	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[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -0.82], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(N[(t$95$0 * l), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.55], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[(l + N[(l * N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.005], N[(U + N[(2.0 * N[(l * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot K\right)\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_1 \leq -0.82:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{t\_0 \cdot \ell}{U}\right)\right)\\

\mathbf{elif}\;t\_1 \leq -0.55:\\
\;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\

\mathbf{elif}\;t\_1 \leq -0.005:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(t\_0 \cdot J\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.819999999999999951

    1. Initial program 73.4%

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

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

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

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

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*75.7%

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

        \[\leadsto U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\color{blue}{\cos \left(0.5 \cdot K\right) \cdot \ell}}{U}\right)\right) \]
    8. Simplified75.7%

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

    if -0.819999999999999951 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.55000000000000004

    1. Initial program 97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.55000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0050000000000000001

    1. Initial program 65.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} \cdot \left(J \cdot 2\right) + U \]
    11. Taylor expanded in K around inf 72.2%

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

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

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

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

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

    if -0.0050000000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 85.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.82:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \ell}{U}\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.55:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.005:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 79.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \ell}{U}\right)\right)\\
\mathbf{if}\;t\_0 \leq -0.82:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq -0.55:\\
\;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\

\mathbf{elif}\;t\_0 \leq 0.2:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.819999999999999951 or -0.55000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.20000000000000001

    1. Initial program 71.2%

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

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

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

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

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*74.3%

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

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

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

    if -0.819999999999999951 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.55000000000000004

    1. Initial program 97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.20000000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 86.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.82:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \ell}{U}\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq -0.55:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.2:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\cos \left(0.5 \cdot K\right) \cdot \ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq -0.55:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.4:\\ \;\;\;\;U + 2 \cdot \left(\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \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.55)
     (+ U (* (* J 2.0) (+ l (* l (* -0.125 (pow K 2.0))))))
     (if (<= t_0 0.4)
       (+ U (* 2.0 (* (* (cos (* 0.5 K)) l) J)))
       (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow 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.55) {
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * pow(K, 2.0)))));
	} else if (t_0 <= 0.4) {
		tmp = U + (2.0 * ((cos((0.5 * K)) * l) * J));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos((k / 2.0d0))
    if (t_0 <= (-0.55d0)) then
        tmp = u + ((j * 2.0d0) * (l + (l * ((-0.125d0) * (k ** 2.0d0)))))
    else if (t_0 <= 0.4d0) then
        tmp = u + (2.0d0 * ((cos((0.5d0 * k)) * l) * j))
    else
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= -0.55) {
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * Math.pow(K, 2.0)))));
	} else if (t_0 <= 0.4) {
		tmp = U + (2.0 * ((Math.cos((0.5 * K)) * l) * J));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= -0.55:
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * math.pow(K, 2.0)))))
	elif t_0 <= 0.4:
		tmp = U + (2.0 * ((math.cos((0.5 * K)) * l) * J))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(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.55)
		tmp = Float64(U + Float64(Float64(J * 2.0) * Float64(l + Float64(l * Float64(-0.125 * (K ^ 2.0))))));
	elseif (t_0 <= 0.4)
		tmp = Float64(U + Float64(2.0 * Float64(Float64(cos(Float64(0.5 * K)) * l) * J)));
	else
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K / 2.0));
	tmp = 0.0;
	if (t_0 <= -0.55)
		tmp = U + ((J * 2.0) * (l + (l * (-0.125 * (K ^ 2.0)))));
	elseif (t_0 <= 0.4)
		tmp = U + (2.0 * ((cos((0.5 * K)) * l) * J));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -0.55], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[(l + N[(l * N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.4], N[(U + N[(2.0 * N[(N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * l), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq -0.55:\\
\;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.55000000000000004

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.55000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.40000000000000002

    1. Initial program 66.8%

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

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

    if 0.40000000000000002 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.55:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \left(\ell + \ell \cdot \left(-0.125 \cdot {K}^{2}\right)\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \leq 0.4:\\ \;\;\;\;U + 2 \cdot \left(\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 93.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.5:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.5)
     (+ U (* t_0 (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
     (+ U (* (* J 2.0) (log1p (expm1 l)))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.5) {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else {
		tmp = U + ((J * 2.0) * log1p(expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.5) {
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else {
		tmp = U + ((J * 2.0) * Math.log1p(Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K / 2.0))
	tmp = 0
	if t_0 <= 0.5:
		tmp = U + (t_0 * (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	else:
		tmp = U + ((J * 2.0) * math.log1p(math.expm1(l)))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.5)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	else
		tmp = Float64(U + Float64(Float64(J * 2.0) * log1p(expm1(l))));
	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.5], N[(U + N[(t$95$0 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;t\_0 \leq 0.5:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.5

    1. Initial program 76.5%

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

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

    if 0.5 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.5:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 93.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.5:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.5)
   (+
    U
    (* J (* l (* (cos (* 0.5 K)) (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
   (+ U (* (* J 2.0) (log1p (expm1 l))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.5) {
		tmp = U + (J * (l * (cos((0.5 * K)) * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else {
		tmp = U + ((J * 2.0) * log1p(expm1(l)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= 0.5) {
		tmp = U + (J * (l * (Math.cos((0.5 * K)) * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else {
		tmp = U + ((J * 2.0) * Math.log1p(Math.expm1(l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.5:
		tmp = U + (J * (l * (math.cos((0.5 * K)) * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	else:
		tmp = U + ((J * 2.0) * math.log1p(math.expm1(l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.5)
		tmp = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(0.5 * K)) * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	else
		tmp = Float64(U + Float64(Float64(J * 2.0) * log1p(expm1(l))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.5], N[(U + N[(J * N[(l * N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.5

    1. Initial program 76.5%

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

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

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

    if 0.5 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 87.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.5:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 95.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -340:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{elif}\;\ell \leq 5.9 \cdot 10^{-5}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+99}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* (cos (/ K 2.0)) (* 0.3333333333333333 (* J (pow l 3.0)))))))
   (if (<= l -2.6e+119)
     t_0
     (if (<= l -340.0)
       (+ U (* (* J 2.0) (log1p (expm1 l))))
       (if (<= l 5.9e-5)
         (+ U (* 2.0 (* l (* (cos (* 0.5 K)) J))))
         (if (<= l 7.8e+99) (+ U (* J (- (exp l) (exp (- l))))) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (cos((K / 2.0)) * (0.3333333333333333 * (J * pow(l, 3.0))));
	double tmp;
	if (l <= -2.6e+119) {
		tmp = t_0;
	} else if (l <= -340.0) {
		tmp = U + ((J * 2.0) * log1p(expm1(l)));
	} else if (l <= 5.9e-5) {
		tmp = U + (2.0 * (l * (cos((0.5 * K)) * J)));
	} else if (l <= 7.8e+99) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (Math.cos((K / 2.0)) * (0.3333333333333333 * (J * Math.pow(l, 3.0))));
	double tmp;
	if (l <= -2.6e+119) {
		tmp = t_0;
	} else if (l <= -340.0) {
		tmp = U + ((J * 2.0) * Math.log1p(Math.expm1(l)));
	} else if (l <= 5.9e-5) {
		tmp = U + (2.0 * (l * (Math.cos((0.5 * K)) * J)));
	} else if (l <= 7.8e+99) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.cos((K / 2.0)) * (0.3333333333333333 * (J * math.pow(l, 3.0))))
	tmp = 0
	if l <= -2.6e+119:
		tmp = t_0
	elif l <= -340.0:
		tmp = U + ((J * 2.0) * math.log1p(math.expm1(l)))
	elif l <= 5.9e-5:
		tmp = U + (2.0 * (l * (math.cos((0.5 * K)) * J)))
	elif l <= 7.8e+99:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)))))
	tmp = 0.0
	if (l <= -2.6e+119)
		tmp = t_0;
	elseif (l <= -340.0)
		tmp = Float64(U + Float64(Float64(J * 2.0) * log1p(expm1(l))));
	elseif (l <= 5.9e-5)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(cos(Float64(0.5 * K)) * J))));
	elseif (l <= 7.8e+99)
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.6e+119], t$95$0, If[LessEqual[l, -340.0], N[(U + N[(N[(J * 2.0), $MachinePrecision] * N[Log[1 + N[(Exp[l] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.9e-5], N[(U + N[(2.0 * N[(l * N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.8e+99], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\
\mathbf{if}\;\ell \leq -2.6 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -340:\\
\;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.6e119 or 7.79999999999999989e99 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 89.5%

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

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

    if -2.6e119 < l < -340

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -340 < l < 5.8999999999999998e-5

    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} \cdot \left(J \cdot 2\right) + U \]
    11. Taylor expanded in K around inf 99.4%

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

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

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

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

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

    if 5.8999999999999998e-5 < l < 7.79999999999999989e99

    1. Initial program 98.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -340:\\ \;\;\;\;U + \left(J \cdot 2\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell\right)\right)\\ \mathbf{elif}\;\ell \leq 5.9 \cdot 10^{-5}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+99}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 78.0% accurate, 2.6× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if -5.30000000000000028e42 < l < 1.0200000000000001e-5

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} \cdot \left(J \cdot 2\right) + U \]
    11. Taylor expanded in K around inf 91.5%

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

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

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

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

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

    if 1.0200000000000001e-5 < l

    1. Initial program 99.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.3 \cdot 10^{+42}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 1.02 \cdot 10^{-5}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.8% accurate, 2.6× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if -5.4000000000000001e42 < l < 2.70000000000000003e-4

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right)\right)} \cdot \left(J \cdot 2\right) + U \]
    11. Taylor expanded in K around inf 91.5%

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

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

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

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

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

    if 2.70000000000000003e-4 < l

    1. Initial program 99.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{+42}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 0.00027:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot J\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 77.8% accurate, 2.6× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if -5.30000000000000028e42 < l < 2.70000000000000003e-4

    1. Initial program 69.3%

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

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

    if 2.70000000000000003e-4 < l

    1. Initial program 99.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.3 \cdot 10^{+42}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 0.00027:\\ \;\;\;\;U + 2 \cdot \left(\left(\cos \left(0.5 \cdot K\right) \cdot \ell\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 71.0% accurate, 2.6× speedup?

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

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

\mathbf{elif}\;\ell \leq 0.00027:\\
\;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

    if -2.20000000000000007e26 < l < 2.70000000000000003e-4

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.70000000000000003e-4 < l

    1. Initial program 99.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+26}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 0.00027:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 71.1% accurate, 2.6× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if -2.3000000000000001e26 < l < 9.0000000000000007e32

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.0000000000000007e32 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 69.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.3 \cdot 10^{+26}:\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq 9 \cdot 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 71.1% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+26} \lor \neg \left(\ell \leq 2000000000000\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -2.2e+26) (not (<= l 2000000000000.0)))
   (* 0.3333333333333333 (* J (pow l 3.0)))
   (fma l (* J 2.0) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -2.2e+26) || !(l <= 2000000000000.0)) {
		tmp = 0.3333333333333333 * (J * pow(l, 3.0));
	} else {
		tmp = fma(l, (J * 2.0), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -2.2e+26) || !(l <= 2000000000000.0))
		tmp = Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)));
	else
		tmp = fma(l, Float64(J * 2.0), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -2.2e+26], N[Not[LessEqual[l, 2000000000000.0]], $MachinePrecision]], N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.2 \cdot 10^{+26} \lor \neg \left(\ell \leq 2000000000000\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.20000000000000007e26 or 2e12 < 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. Add Preprocessing
    3. Taylor expanded in l around 0 67.7%

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

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

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

    if -2.20000000000000007e26 < l < 2e12

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
    12. Step-by-step derivation
      1. +-commutative74.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+26} \lor \neg \left(\ell \leq 2000000000000\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\ell, J \cdot 2, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 53.1% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\ell, J \cdot 2, U\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (fma l (* J 2.0) U))
double code(double J, double l, double K, double U) {
	return fma(l, (J * 2.0), U);
}
function code(J, l, K, U)
	return fma(l, Float64(J * 2.0), U)
end
code[J_, l_, K_, U_] := N[(l * N[(J * 2.0), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\ell, J \cdot 2, U\right)
\end{array}
Derivation
  1. Initial program 84.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(\ell, J \cdot 2, U\right) \]
  15. Add Preprocessing

Alternative 15: 53.1% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]
  10. Add Preprocessing

Alternative 16: 39.0% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(J \cdot -6\right)} + U \]
  11. Simplified34.1%

    \[\leadsto \color{blue}{\ell \cdot \left(J \cdot -6\right)} + U \]
  12. Final simplification34.1%

    \[\leadsto U + \ell \cdot \left(J \cdot -6\right) \]
  13. Add Preprocessing

Alternative 17: 36.0% 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.0%

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

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

    \[\leadsto \color{blue}{U} \]
  5. Add Preprocessing

Reproduce

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