Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.9%
Time: 13.5s
Alternatives: 19
Speedup: 2.1×

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

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

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

Alternative 1: 99.9% accurate, 1.5× speedup?

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

\\
\mathsf{fma}\left(\left(2 \cdot \sinh \ell\right) \cdot \cos \left(K \cdot 0.5\right), J, U\right)
\end{array}
Derivation
  1. Initial program 85.7%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \left(J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. lift-neg.f64N/A

      \[\leadsto \left(J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. lift-exp.f64N/A

      \[\leadsto \left(J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. flip--N/A

      \[\leadsto \left(J \cdot \color{blue}{\frac{e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. associate-*r/N/A

      \[\leadsto \color{blue}{\frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. lift-/.f64N/A

      \[\leadsto \frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}} \cdot \cos \color{blue}{\left(\frac{K}{2}\right)} + U \]
    7. lift-cos.f64N/A

      \[\leadsto \frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}} \cdot \color{blue}{\cos \left(\frac{K}{2}\right)} + U \]
    8. associate-*r/N/A

      \[\leadsto \color{blue}{\left(J \cdot \frac{e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    9. flip--N/A

      \[\leadsto \left(J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    10. lift--.f64N/A

      \[\leadsto \left(J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    11. associate-*l*N/A

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(2 \cdot \sinh \ell\right) \cdot \cos \left(K \cdot 0.5\right), J, U\right)} \]
  5. Add Preprocessing

Alternative 2: 94.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;t\_0 \leq 0.995:\\ \;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot 0.3333333333333333, 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (/ K 2.0))))
   (if (<= t_0 0.995)
     (+ U (* t_0 (* J (* l (fma l (* l 0.3333333333333333) 2.0)))))
     (fma (* (sinh l) J) 2.0 U))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K / 2.0));
	double tmp;
	if (t_0 <= 0.995) {
		tmp = U + (t_0 * (J * (l * fma(l, (l * 0.3333333333333333), 2.0))));
	} else {
		tmp = fma((sinh(l) * J), 2.0, U);
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (t_0 <= 0.995)
		tmp = Float64(U + Float64(t_0 * Float64(J * Float64(l * fma(l, Float64(l * 0.3333333333333333), 2.0)))));
	else
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	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.995], N[(U + N[(t$95$0 * N[(J * N[(l * N[(l * N[(l * 0.3333333333333333), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision]]]
\begin{array}{l}

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

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6491.9

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites91.9%

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

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

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6489.9

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites89.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6499.1

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

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

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

Alternative 3: 92.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.995:\\ \;\;\;\;\mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \ell \cdot 0.3333333333333333, 2\right) \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.995)
   (fma l (* (fma l (* l 0.3333333333333333) 2.0) (* J (cos (* K 0.5)))) U)
   (fma (* (sinh l) J) 2.0 U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.995) {
		tmp = fma(l, (fma(l, (l * 0.3333333333333333), 2.0) * (J * cos((K * 0.5)))), U);
	} else {
		tmp = fma((sinh(l) * J), 2.0, U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.995)
		tmp = fma(l, Float64(fma(l, Float64(l * 0.3333333333333333), 2.0) * Float64(J * cos(Float64(K * 0.5)))), U);
	else
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.995], N[(l * N[(N[(l * N[(l * 0.3333333333333333), $MachinePrecision] + 2.0), $MachinePrecision] * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision]]
\begin{array}{l}

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

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


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

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

      \[\leadsto \color{blue}{U + \ell \cdot \left(\frac{1}{3} \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \left(J \cdot \left({\ell}^{2} \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + 2 \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \ell \cdot \left(\frac{1}{3} \cdot \left(J \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot K\right) \cdot {\ell}^{2}\right)}\right) + 2 \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U \]
      3. associate-*r*N/A

        \[\leadsto \ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right) \cdot {\ell}^{2}\right)} + 2 \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U \]
      4. associate-*l*N/A

        \[\leadsto \ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) \cdot {\ell}^{2}} + 2 \cdot \left(J \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U \]
      5. lower-fma.f64N/A

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

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

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

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6489.9

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites89.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6499.1

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

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

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

Alternative 4: 88.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(K \cdot 0.5\right), J \cdot \left(2 \cdot \ell\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma (cos (* K 0.5)) (* J (* 2.0 l)) U)
   (fma (* (sinh l) J) 2.0 U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(cos((K * 0.5)), (J * (2.0 * l)), U);
	} else {
		tmp = fma((sinh(l) * J), 2.0, U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(cos(Float64(K * 0.5)), Float64(J * Float64(2.0 * l)), U);
	else
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\cos \left(K \cdot 0.5\right), J \cdot \left(2 \cdot \ell\right), U\right)\\

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


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

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

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)} + U \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)} + U \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\left(2 \cdot J\right) \cdot \ell\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \left(2 \cdot J\right) \cdot \ell, U\right)} \]
      6. lower-cos.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos \left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \color{blue}{\left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{\left(J \cdot 2\right)} \cdot \ell, U\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
      12. lower-*.f6474.3

        \[\leadsto \mathsf{fma}\left(\cos \left(0.5 \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
    5. Applied rewrites74.3%

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

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6495.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(K \cdot 0.5\right), J \cdot \left(2 \cdot \ell\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 57.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;J \cdot \left(e^{\ell} - e^{-\ell}\right) \leq -\infty:\\ \;\;\;\;J \cdot \left(\ell \cdot \mathsf{fma}\left(-0.25, K \cdot K, 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, 2 \cdot \ell, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (* J (- (exp l) (exp (- l)))) (- INFINITY))
   (* J (* l (fma -0.25 (* K K) 2.0)))
   (fma J (* 2.0 l) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((J * (exp(l) - exp(-l))) <= -((double) INFINITY)) {
		tmp = J * (l * fma(-0.25, (K * K), 2.0));
	} else {
		tmp = fma(J, (2.0 * l), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(J * Float64(exp(l) - exp(Float64(-l)))) <= Float64(-Inf))
		tmp = Float64(J * Float64(l * fma(-0.25, Float64(K * K), 2.0)));
	else
		tmp = fma(J, Float64(2.0 * l), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(J * N[(l * N[(-0.25 * N[(K * K), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(J * N[(2.0 * l), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;J \cdot \left(e^{\ell} - e^{-\ell}\right) \leq -\infty:\\
\;\;\;\;J \cdot \left(\ell \cdot \mathsf{fma}\left(-0.25, K \cdot K, 2\right)\right)\\

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


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

    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

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)} + U \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)} + U \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\left(2 \cdot J\right) \cdot \ell\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \left(2 \cdot J\right) \cdot \ell, U\right)} \]
      6. lower-cos.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos \left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \color{blue}{\left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{\left(J \cdot 2\right)} \cdot \ell, U\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
      12. lower-*.f6424.3

        \[\leadsto \mathsf{fma}\left(\cos \left(0.5 \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
    5. Applied rewrites24.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot K\right), J \cdot \left(\ell \cdot 2\right), U\right)} \]
    6. Taylor expanded in J around inf

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto 2 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right)\right)} \cdot \cos \left(\frac{1}{2} \cdot K\right) \]
      5. lower-*.f64N/A

        \[\leadsto \left(2 \cdot \color{blue}{\left(J \cdot \ell\right)}\right) \cdot \cos \left(\frac{1}{2} \cdot K\right) \]
      6. lower-cos.f64N/A

        \[\leadsto \left(2 \cdot \left(J \cdot \ell\right)\right) \cdot \color{blue}{\cos \left(\frac{1}{2} \cdot K\right)} \]
      7. lower-*.f6424.7

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

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

      \[\leadsto \color{blue}{\frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)} \]
    10. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) + \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell + \frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right)} \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + \frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto 2 \cdot \left(J \cdot \ell\right) + \frac{-1}{4} \cdot \left(J \cdot \color{blue}{\left(\ell \cdot {K}^{2}\right)}\right) \]
      5. associate-*r*N/A

        \[\leadsto 2 \cdot \left(J \cdot \ell\right) + \frac{-1}{4} \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot {K}^{2}\right)} \]
      6. associate-*l*N/A

        \[\leadsto 2 \cdot \left(J \cdot \ell\right) + \color{blue}{\left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}} \]
      7. *-commutativeN/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} + \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2} \]
      8. associate-*r*N/A

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2} \]
      9. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \ell\right)} + \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, 2 \cdot \ell, \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}\right)} \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot 2}, \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}\right) \]
      12. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot 2}, \left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}\right) \]
      13. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \color{blue}{\frac{-1}{4} \cdot \left(\left(J \cdot \ell\right) \cdot {K}^{2}\right)}\right) \]
      14. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \frac{-1}{4} \cdot \color{blue}{\left(J \cdot \left(\ell \cdot {K}^{2}\right)\right)}\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \frac{-1}{4} \cdot \left(J \cdot \color{blue}{\left({K}^{2} \cdot \ell\right)}\right)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \color{blue}{\left(J \cdot \left({K}^{2} \cdot \ell\right)\right) \cdot \frac{-1}{4}}\right) \]
      17. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \color{blue}{J \cdot \left(\left({K}^{2} \cdot \ell\right) \cdot \frac{-1}{4}\right)}\right) \]
      18. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, \color{blue}{J \cdot \left(\left({K}^{2} \cdot \ell\right) \cdot \frac{-1}{4}\right)}\right) \]
      19. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot 2, J \cdot \color{blue}{\left(\left({K}^{2} \cdot \ell\right) \cdot \frac{-1}{4}\right)}\right) \]
    11. Applied rewrites32.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, J \cdot \left(\left(\ell \cdot \left(K \cdot K\right)\right) \cdot -0.25\right)\right)} \]
    12. Taylor expanded in J around 0

      \[\leadsto \color{blue}{J \cdot \left(\frac{-1}{4} \cdot \left({K}^{2} \cdot \ell\right) + 2 \cdot \ell\right)} \]
    13. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{J \cdot \left(\frac{-1}{4} \cdot \left({K}^{2} \cdot \ell\right) + 2 \cdot \ell\right)} \]
      2. +-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \ell + \frac{-1}{4} \cdot \left({K}^{2} \cdot \ell\right)\right)} \]
      3. associate-*r*N/A

        \[\leadsto J \cdot \left(2 \cdot \ell + \color{blue}{\left(\frac{-1}{4} \cdot {K}^{2}\right) \cdot \ell}\right) \]
      4. distribute-rgt-inN/A

        \[\leadsto J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{-1}{4} \cdot {K}^{2}\right)\right)} \]
      5. lower-*.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{-1}{4} \cdot {K}^{2}\right)\right)} \]
      6. +-commutativeN/A

        \[\leadsto J \cdot \left(\ell \cdot \color{blue}{\left(\frac{-1}{4} \cdot {K}^{2} + 2\right)}\right) \]
      7. lower-fma.f64N/A

        \[\leadsto J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{4}, {K}^{2}, 2\right)}\right) \]
      8. unpow2N/A

        \[\leadsto J \cdot \left(\ell \cdot \mathsf{fma}\left(\frac{-1}{4}, \color{blue}{K \cdot K}, 2\right)\right) \]
      9. lower-*.f6432.7

        \[\leadsto J \cdot \left(\ell \cdot \mathsf{fma}\left(-0.25, \color{blue}{K \cdot K}, 2\right)\right) \]
    14. Applied rewrites32.7%

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

    if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))))

    1. Initial program 82.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6477.2

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites77.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Taylor expanded in l around 0

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

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

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

Alternative 6: 87.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (*
     (* K K)
     (* (fma 0.3333333333333333 (* l l) 2.0) (fma l -0.125 (/ l (* K K)))))
    U)
   (fma (* (sinh l) J) 2.0 U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((K * K) * (fma(0.3333333333333333, (l * l), 2.0) * fma(l, -0.125, (l / (K * K))))), U);
	} else {
		tmp = fma((sinh(l) * J), 2.0, U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(K * K) * Float64(fma(0.3333333333333333, Float64(l * l), 2.0) * fma(l, -0.125, Float64(l / Float64(K * K))))), U);
	else
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(K * K), $MachinePrecision] * N[(N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision] * N[(l * -0.125 + N[(l / N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in K around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{-1}{8} \cdot \ell\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \frac{\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \ell}}{{K}^{2}}\right), U\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \frac{\ell}{{K}^{2}}}\right), U\right) \]
      8. distribute-lft-outN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \left(\color{blue}{\ell \cdot \frac{-1}{8}} + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{{K}^{2}}\right)}\right), U\right) \]
      16. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \color{blue}{\frac{\ell}{{K}^{2}}}\right)\right), U\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
      18. lower-*.f6452.6

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
    11. Applied rewrites52.6%

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

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6495.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 83.6% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-J, \frac{\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}{U}, -1\right) \cdot \left(-U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (*
     (* K K)
     (* (fma 0.3333333333333333 (* l l) 2.0) (fma l -0.125 (/ l (* K K)))))
    U)
   (*
    (fma
     (- J)
     (/
      (*
       l
       (fma
        (* l l)
        (fma
         (* l l)
         (fma (* l l) 0.0003968253968253968 0.016666666666666666)
         0.3333333333333333)
        2.0))
      U)
     -1.0)
    (- U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((K * K) * (fma(0.3333333333333333, (l * l), 2.0) * fma(l, -0.125, (l / (K * K))))), U);
	} else {
		tmp = fma(-J, ((l * fma((l * l), fma((l * l), fma((l * l), 0.0003968253968253968, 0.016666666666666666), 0.3333333333333333), 2.0)) / U), -1.0) * -U;
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(K * K) * Float64(fma(0.3333333333333333, Float64(l * l), 2.0) * fma(l, -0.125, Float64(l / Float64(K * K))))), U);
	else
		tmp = Float64(fma(Float64(-J), Float64(Float64(l * fma(Float64(l * l), fma(Float64(l * l), fma(Float64(l * l), 0.0003968253968253968, 0.016666666666666666), 0.3333333333333333), 2.0)) / U), -1.0) * Float64(-U));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(K * K), $MachinePrecision] * N[(N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision] * N[(l * -0.125 + N[(l / N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[((-J) * N[(N[(l * N[(N[(l * l), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968 + 0.016666666666666666), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision] + -1.0), $MachinePrecision] * (-U)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-J, \frac{\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}{U}, -1\right) \cdot \left(-U\right)\\


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in K around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{-1}{8} \cdot \ell\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \frac{\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \ell}}{{K}^{2}}\right), U\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \frac{\ell}{{K}^{2}}}\right), U\right) \]
      8. distribute-lft-outN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \left(\color{blue}{\ell \cdot \frac{-1}{8}} + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{{K}^{2}}\right)}\right), U\right) \]
      16. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \color{blue}{\frac{\ell}{{K}^{2}}}\right)\right), U\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
      18. lower-*.f6452.6

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
    11. Applied rewrites52.6%

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

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right)}, U\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right), U\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)} + 2\right), U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right), 2\right)}, U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)}, 2\right), U\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}\right)}, 2\right), U\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right)}, 2\right), U\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\frac{1}{2520} \cdot {\ell}^{2} + \frac{1}{60}}, \frac{1}{3}\right), 2\right), U\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \frac{1}{2520}} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \frac{1}{2520} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      14. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\ell \cdot \left(\ell \cdot \frac{1}{2520}\right)} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \frac{1}{2520}, \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right), U\right) \]
      16. lower-*.f6492.4

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.0003968253968253968}, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right) \]
    8. Applied rewrites92.4%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}, U\right) \]
    9. Taylor expanded in U around -inf

      \[\leadsto \color{blue}{-1 \cdot \left(U \cdot \left(-1 \cdot \frac{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}{U} - 1\right)\right)} \]
    10. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(U \cdot \left(-1 \cdot \frac{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}{U} - 1\right)\right)} \]
      2. lower-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(U \cdot \left(-1 \cdot \frac{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}{U} - 1\right)\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{U \cdot \left(-1 \cdot \frac{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}{U} - 1\right)}\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{neg}\left(U \cdot \color{blue}{\left(-1 \cdot \frac{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}{U} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right) \]
      5. associate-/l*N/A

        \[\leadsto \mathsf{neg}\left(U \cdot \left(-1 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}{U}\right)} + \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      6. associate-*r*N/A

        \[\leadsto \mathsf{neg}\left(U \cdot \left(\color{blue}{\left(-1 \cdot J\right) \cdot \frac{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}{U}} + \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{neg}\left(U \cdot \left(\left(-1 \cdot J\right) \cdot \frac{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}{U} + \color{blue}{-1}\right)\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{neg}\left(U \cdot \color{blue}{\mathsf{fma}\left(-1 \cdot J, \frac{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}{U}, -1\right)}\right) \]
    11. Applied rewrites92.7%

      \[\leadsto \color{blue}{-U \cdot \mathsf{fma}\left(-J, \frac{\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}{U}, -1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-J, \frac{\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}{U}, -1\right) \cdot \left(-U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 88.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 1e-115)
   (fma (* (sinh l) J) 2.0 U)
   (+
    U
    (*
     (*
      J
      (*
       l
       (fma
        (* l l)
        (fma
         l
         (* l (fma (* l l) 0.0003968253968253968 0.016666666666666666))
         0.3333333333333333)
        2.0)))
     (cos (/ K 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 1e-115) {
		tmp = fma((sinh(l) * J), 2.0, U);
	} else {
		tmp = U + ((J * (l * fma((l * l), fma(l, (l * fma((l * l), 0.0003968253968253968, 0.016666666666666666)), 0.3333333333333333), 2.0))) * cos((K / 2.0)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 1e-115)
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	else
		tmp = Float64(U + Float64(Float64(J * Float64(l * fma(Float64(l * l), fma(l, Float64(l * fma(Float64(l * l), 0.0003968253968253968, 0.016666666666666666)), 0.3333333333333333), 2.0))) * cos(Float64(K / 2.0))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 1e-115], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision], N[(U + N[(N[(J * N[(l * N[(N[(l * l), $MachinePrecision] * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * 0.0003968253968253968 + 0.016666666666666666), $MachinePrecision]), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 10^{-115}:\\
\;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\

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


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

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6481.2

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites81.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6488.1

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

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

    if 1.0000000000000001e-115 < (/.f64 K #s(literal 2 binary64))

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right), 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. lower-*.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. associate-*l*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)} + \frac{1}{3}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      9. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right), \frac{1}{3}\right)}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. lower-*.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)}, \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      11. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\left(\frac{1}{2520} \cdot {\ell}^{2} + \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      12. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \left(\color{blue}{{\ell}^{2} \cdot \frac{1}{2520}} + \frac{1}{60}\right), \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      13. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{2520}, \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      14. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{2520}, \frac{1}{60}\right), \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      15. lower-*.f6496.8

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 83.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (*
     (* K K)
     (* (fma 0.3333333333333333 (* l l) 2.0) (fma l -0.125 (/ l (* K K)))))
    U)
   (fma
    J
    (*
     l
     (fma
      l
      (*
       l
       (fma
        (* l l)
        (fma l (* l 0.0003968253968253968) 0.016666666666666666)
        0.3333333333333333))
      2.0))
    U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((K * K) * (fma(0.3333333333333333, (l * l), 2.0) * fma(l, -0.125, (l / (K * K))))), U);
	} else {
		tmp = fma(J, (l * fma(l, (l * fma((l * l), fma(l, (l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(K * K) * Float64(fma(0.3333333333333333, Float64(l * l), 2.0) * fma(l, -0.125, Float64(l / Float64(K * K))))), U);
	else
		tmp = fma(J, Float64(l * fma(l, Float64(l * fma(Float64(l * l), fma(l, Float64(l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(K * K), $MachinePrecision] * N[(N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision] * N[(l * -0.125 + N[(l / N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * N[(l * N[(l * 0.0003968253968253968), $MachinePrecision] + 0.016666666666666666), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{K \cdot K}\right)\right), U\right)\\

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in K around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right)}, U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{-1}{8} \cdot \ell\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right)} + \frac{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}{{K}^{2}}\right), U\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \frac{\color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \ell}}{{K}^{2}}\right), U\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell\right) + \color{blue}{\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \frac{\ell}{{K}^{2}}}\right), U\right) \]
      8. distribute-lft-outN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \color{blue}{\left(\left(2 + \frac{1}{3} \cdot {\ell}^{2}\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right)}, U\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)} \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right) \cdot \left(\frac{-1}{8} \cdot \ell + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \left(\color{blue}{\ell \cdot \frac{-1}{8}} + \frac{\ell}{{K}^{2}}\right)\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{{K}^{2}}\right)}\right), U\right) \]
      16. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \color{blue}{\frac{\ell}{{K}^{2}}}\right)\right), U\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(\frac{1}{3}, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, \frac{-1}{8}, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
      18. lower-*.f6452.6

        \[\leadsto \mathsf{fma}\left(J, \left(K \cdot K\right) \cdot \left(\mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right) \cdot \mathsf{fma}\left(\ell, -0.125, \frac{\ell}{\color{blue}{K \cdot K}}\right)\right), U\right) \]
    11. Applied rewrites52.6%

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

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right)}, U\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right), U\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)} + 2\right), U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right), 2\right)}, U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)}, 2\right), U\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}\right)}, 2\right), U\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right)}, 2\right), U\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\frac{1}{2520} \cdot {\ell}^{2} + \frac{1}{60}}, \frac{1}{3}\right), 2\right), U\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \frac{1}{2520}} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \frac{1}{2520} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      14. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\ell \cdot \left(\ell \cdot \frac{1}{2520}\right)} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \frac{1}{2520}, \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right), U\right) \]
      16. lower-*.f6492.4

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.0003968253968253968}, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right) \]
    8. Applied rewrites92.4%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}, U\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 88.1% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 10^{-13}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 1e-13)
   (fma (* (sinh l) J) 2.0 U)
   (+
    U
    (*
     (cos (/ K 2.0))
     (*
      J
      (*
       l
       (fma
        (* l l)
        (fma (* l l) 0.016666666666666666 0.3333333333333333)
        2.0)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 1e-13) {
		tmp = fma((sinh(l) * J), 2.0, U);
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (l * fma((l * l), fma((l * l), 0.016666666666666666, 0.3333333333333333), 2.0))));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 1e-13)
		tmp = fma(Float64(sinh(l) * J), 2.0, U);
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(l * fma(Float64(l * l), fma(Float64(l * l), 0.016666666666666666, 0.3333333333333333), 2.0)))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 1e-13], N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(l * N[(N[(l * l), $MachinePrecision] * N[(N[(l * l), $MachinePrecision] * 0.016666666666666666 + 0.3333333333333333), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\

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


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

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6489.7

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

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

    if 1e-13 < (/.f64 K #s(literal 2 binary64))

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right) + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. lower-*.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\frac{1}{60} \cdot {\ell}^{2} + \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \frac{1}{60}} + \frac{1}{3}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{60}, \frac{1}{3}\right)}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      9. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60}, \frac{1}{3}\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. lower-*.f6494.3

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites94.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 10^{-13}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 83.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, K \cdot K, 1\right), J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    (fma -0.125 (* K K) 1.0)
    (*
     J
     (*
      l
      (fma l (* l (fma (* l l) 0.016666666666666666 0.3333333333333333)) 2.0)))
    U)
   (fma
    J
    (*
     l
     (fma
      l
      (*
       l
       (fma
        (* l l)
        (fma l (* l 0.0003968253968253968) 0.016666666666666666)
        0.3333333333333333))
      2.0))
    U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(fma(-0.125, (K * K), 1.0), (J * (l * fma(l, (l * fma((l * l), 0.016666666666666666, 0.3333333333333333)), 2.0))), U);
	} else {
		tmp = fma(J, (l * fma(l, (l * fma((l * l), fma(l, (l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(fma(-0.125, Float64(K * K), 1.0), Float64(J * Float64(l * fma(l, Float64(l * fma(Float64(l * l), 0.016666666666666666, 0.3333333333333333)), 2.0))), U);
	else
		tmp = fma(J, Float64(l * fma(l, Float64(l * fma(Float64(l * l), fma(l, Float64(l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(N[(-0.125 * N[(K * K), $MachinePrecision] + 1.0), $MachinePrecision] * N[(J * N[(l * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * 0.016666666666666666 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * N[(l * N[(l * 0.0003968253968253968), $MachinePrecision] + 0.016666666666666666), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, K \cdot K, 1\right), J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right), U\right)\\

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


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

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

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(\ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right) + 2 \cdot J\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(\ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*l*N/A

        \[\leadsto \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)} + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. lower-fma.f64N/A

        \[\leadsto \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right), 2 \cdot J\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites90.3%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right)\right) + \ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right)\right) + \ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right) + U} \]
      2. associate-*r*N/A

        \[\leadsto \left(\color{blue}{\left(\frac{-1}{8} \cdot {K}^{2}\right) \cdot \left(\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right)} + \ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right) + U \]
      3. distribute-lft1-inN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot {K}^{2} + 1\right) \cdot \left(\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right)} + U \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{\left(1 + \frac{-1}{8} \cdot {K}^{2}\right)} \cdot \left(\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)\right) + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 + \frac{-1}{8} \cdot {K}^{2}, \ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right), U\right)} \]
    8. Applied rewrites52.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(-0.125, K \cdot K, 1\right), J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right)\right), U\right)} \]

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right)}, U\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right), U\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)} + 2\right), U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right), 2\right)}, U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)}, 2\right), U\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}\right)}, 2\right), U\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right)}, 2\right), U\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\frac{1}{2520} \cdot {\ell}^{2} + \frac{1}{60}}, \frac{1}{3}\right), 2\right), U\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \frac{1}{2520}} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \frac{1}{2520} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      14. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\ell \cdot \left(\ell \cdot \frac{1}{2520}\right)} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \frac{1}{2520}, \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right), U\right) \]
      16. lower-*.f6492.4

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.0003968253968253968}, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right) \]
    8. Applied rewrites92.4%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}, U\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 84.5% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (* (* l l) (* l (fma (* K K) -0.041666666666666664 0.3333333333333333)))
    U)
   (fma
    J
    (*
     l
     (fma
      l
      (*
       l
       (fma
        (* l l)
        (fma l (* l 0.0003968253968253968) 0.016666666666666666)
        0.3333333333333333))
      2.0))
    U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((l * l) * (l * fma((K * K), -0.041666666666666664, 0.3333333333333333))), U);
	} else {
		tmp = fma(J, (l * fma(l, (l * fma((l * l), fma(l, (l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(l * l) * Float64(l * fma(Float64(K * K), -0.041666666666666664, 0.3333333333333333))), U);
	else
		tmp = fma(J, Float64(l * fma(l, Float64(l * fma(Float64(l * l), fma(l, Float64(l * 0.0003968253968253968), 0.016666666666666666), 0.3333333333333333)), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(l * l), $MachinePrecision] * N[(l * N[(N[(K * K), $MachinePrecision] * -0.041666666666666664 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * N[(l * N[(l * 0.0003968253968253968), $MachinePrecision] + 0.016666666666666666), $MachinePrecision] + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in l around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{3} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)}, U\right) \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\left(\ell \cdot \ell\right) \cdot \ell\right)} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\color{blue}{{\ell}^{2}} \cdot \ell\right) \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\left(\frac{-1}{24} \cdot {K}^{2} + \frac{1}{3}\right)}\right), U\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \left(\color{blue}{{K}^{2} \cdot \frac{-1}{24}} + \frac{1}{3}\right)\right), U\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left({K}^{2}, \frac{-1}{24}, \frac{1}{3}\right)}\right), U\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, \frac{-1}{24}, \frac{1}{3}\right)\right), U\right) \]
      12. lower-*.f6452.2

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, -0.041666666666666664, 0.3333333333333333\right)\right), U\right) \]
    11. Applied rewrites52.2%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right)}, U\right) \]

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

    1. Initial program 88.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 K around 0

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6488.1

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
    5. Applied rewrites88.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)}, U\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right)}, U\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right) + 2\right), U\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)\right)} + 2\right), U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right), 2\right)}, U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{3} + {\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right)\right)}, 2\right), U\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}\right) + \frac{1}{3}\right)}, 2\right), U\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \color{blue}{\mathsf{fma}\left({\ell}^{2}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right)}, 2\right), U\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\color{blue}{\ell \cdot \ell}, \frac{1}{60} + \frac{1}{2520} \cdot {\ell}^{2}, \frac{1}{3}\right), 2\right), U\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\frac{1}{2520} \cdot {\ell}^{2} + \frac{1}{60}}, \frac{1}{3}\right), 2\right), U\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{{\ell}^{2} \cdot \frac{1}{2520}} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \frac{1}{2520} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      14. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\ell \cdot \left(\ell \cdot \frac{1}{2520}\right)} + \frac{1}{60}, \frac{1}{3}\right), 2\right), U\right) \]
      15. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \frac{1}{2520}, \frac{1}{60}\right)}, \frac{1}{3}\right), 2\right), U\right) \]
      16. lower-*.f6492.4

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.0003968253968253968}, 0.016666666666666666\right), 0.3333333333333333\right), 2\right), U\right) \]
    8. Applied rewrites92.4%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, \mathsf{fma}\left(\ell, \ell \cdot 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2\right)}, U\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 92.9% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ t_1 := \cos \left(K \cdot 0.5\right)\\ t_2 := \left(\ell \cdot J\right) \cdot \left(t\_1 \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\ \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+124}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq -0.0072:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 0.0092:\\ \;\;\;\;\mathsf{fma}\left(t\_1 \cdot \left(2 \cdot \ell\right), J, U\right)\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (fma (* (sinh l) J) 2.0 U))
        (t_1 (cos (* K 0.5)))
        (t_2 (* (* l J) (* t_1 (fma 0.3333333333333333 (* l l) 2.0)))))
   (if (<= l -2.4e+124)
     t_2
     (if (<= l -0.0072)
       t_0
       (if (<= l 0.0092)
         (fma (* t_1 (* 2.0 l)) J U)
         (if (<= l 1.3e+92) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = fma((sinh(l) * J), 2.0, U);
	double t_1 = cos((K * 0.5));
	double t_2 = (l * J) * (t_1 * fma(0.3333333333333333, (l * l), 2.0));
	double tmp;
	if (l <= -2.4e+124) {
		tmp = t_2;
	} else if (l <= -0.0072) {
		tmp = t_0;
	} else if (l <= 0.0092) {
		tmp = fma((t_1 * (2.0 * l)), J, U);
	} else if (l <= 1.3e+92) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = fma(Float64(sinh(l) * J), 2.0, U)
	t_1 = cos(Float64(K * 0.5))
	t_2 = Float64(Float64(l * J) * Float64(t_1 * fma(0.3333333333333333, Float64(l * l), 2.0)))
	tmp = 0.0
	if (l <= -2.4e+124)
		tmp = t_2;
	elseif (l <= -0.0072)
		tmp = t_0;
	elseif (l <= 0.0092)
		tmp = fma(Float64(t_1 * Float64(2.0 * l)), J, U);
	elseif (l <= 1.3e+92)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[Sinh[l], $MachinePrecision] * J), $MachinePrecision] * 2.0 + U), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(l * J), $MachinePrecision] * N[(t$95$1 * N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.4e+124], t$95$2, If[LessEqual[l, -0.0072], t$95$0, If[LessEqual[l, 0.0092], N[(N[(t$95$1 * N[(2.0 * l), $MachinePrecision]), $MachinePrecision] * J + U), $MachinePrecision], If[LessEqual[l, 1.3e+92], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\
t_1 := \cos \left(K \cdot 0.5\right)\\
t_2 := \left(\ell \cdot J\right) \cdot \left(t\_1 \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\
\mathbf{if}\;\ell \leq -2.4 \cdot 10^{+124}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\ell \leq -0.0072:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.40000000000000006e124 or 1.2999999999999999e92 < 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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f64100.0

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right)} \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) \]
      4. lower-*.f64N/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \color{blue}{\left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
      5. lower-cos.f64N/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\color{blue}{\cos \left(\frac{1}{2} \cdot K\right)} \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) \]
      6. lower-*.f64N/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\cos \color{blue}{\left(\frac{1}{2} \cdot K\right)} \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right) \]
      8. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)}\right) \]
      9. unpow2N/A

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right)\right) \]
      10. lower-*.f6496.4

        \[\leadsto \left(J \cdot \ell\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, \color{blue}{\ell \cdot \ell}, 2\right)\right) \]
    8. Applied rewrites96.4%

      \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)} \]

    if -2.40000000000000006e124 < l < -0.0071999999999999998 or 0.0091999999999999998 < l < 1.2999999999999999e92

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

      \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
      3. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      4. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
      5. lower-exp.f64N/A

        \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
      6. lower-neg.f6486.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
    6. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      4. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      5. lift--.f64N/A

        \[\leadsto J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} + U \]
      6. lift-exp.f64N/A

        \[\leadsto J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right) + U \]
      7. lift-exp.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      8. lift-neg.f64N/A

        \[\leadsto J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right) + U \]
      9. sinh-undefN/A

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \sinh \ell\right)} + U \]
      10. lift-sinh.f64N/A

        \[\leadsto J \cdot \left(2 \cdot \color{blue}{\sinh \ell}\right) + U \]
      11. *-commutativeN/A

        \[\leadsto J \cdot \color{blue}{\left(\sinh \ell \cdot 2\right)} + U \]
      12. associate-*r*N/A

        \[\leadsto \color{blue}{\left(J \cdot \sinh \ell\right) \cdot 2} + U \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \sinh \ell, 2, U\right)} \]
      14. lower-*.f6486.7

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

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

    if -0.0071999999999999998 < l < 0.0091999999999999998

    1. Initial program 72.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \left(J \cdot \left(\color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. lift-neg.f64N/A

        \[\leadsto \left(J \cdot \left(e^{\ell} - e^{\color{blue}{\mathsf{neg}\left(\ell\right)}}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. lift-exp.f64N/A

        \[\leadsto \left(J \cdot \left(e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. flip--N/A

        \[\leadsto \left(J \cdot \color{blue}{\frac{e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}} \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lift-/.f64N/A

        \[\leadsto \frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}} \cdot \cos \color{blue}{\left(\frac{K}{2}\right)} + U \]
      7. lift-cos.f64N/A

        \[\leadsto \frac{J \cdot \left(e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}\right)}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}} \cdot \color{blue}{\cos \left(\frac{K}{2}\right)} + U \]
      8. associate-*r/N/A

        \[\leadsto \color{blue}{\left(J \cdot \frac{e^{\ell} \cdot e^{\ell} - e^{\mathsf{neg}\left(\ell\right)} \cdot e^{\mathsf{neg}\left(\ell\right)}}{e^{\ell} + e^{\mathsf{neg}\left(\ell\right)}}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      9. flip--N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      10. lift--.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      11. associate-*l*N/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(2 \cdot \sinh \ell\right) \cdot \cos \left(K \cdot 0.5\right), J, U\right)} \]
    5. Taylor expanded in l around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(2 \cdot \ell\right)} \cdot \cos \left(K \cdot \frac{1}{2}\right), J, U\right) \]
    6. Step-by-step derivation
      1. lower-*.f6499.5

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(2 \cdot \ell\right)} \cdot \cos \left(K \cdot 0.5\right), J, U\right) \]
    7. Applied rewrites99.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+124}:\\ \;\;\;\;\left(\ell \cdot J\right) \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\ \mathbf{elif}\;\ell \leq -0.0072:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{elif}\;\ell \leq 0.0092:\\ \;\;\;\;\mathsf{fma}\left(\cos \left(K \cdot 0.5\right) \cdot \left(2 \cdot \ell\right), J, U\right)\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{+92}:\\ \;\;\;\;\mathsf{fma}\left(\sinh \ell \cdot J, 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\ell \cdot J\right) \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 83.0% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (* (* l l) (* l (fma (* K K) -0.041666666666666664 0.3333333333333333)))
    U)
   (fma
    J
    (*
     l
     (fma l (* l (fma (* l l) 0.016666666666666666 0.3333333333333333)) 2.0))
    U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((l * l) * (l * fma((K * K), -0.041666666666666664, 0.3333333333333333))), U);
	} else {
		tmp = fma(J, (l * fma(l, (l * fma((l * l), 0.016666666666666666, 0.3333333333333333)), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(l * l) * Float64(l * fma(Float64(K * K), -0.041666666666666664, 0.3333333333333333))), U);
	else
		tmp = fma(J, Float64(l * fma(l, Float64(l * fma(Float64(l * l), 0.016666666666666666, 0.3333333333333333)), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(l * l), $MachinePrecision] * N[(l * N[(N[(K * K), $MachinePrecision] * -0.041666666666666664 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(l * N[(l * N[(N[(l * l), $MachinePrecision] * 0.016666666666666666 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in l around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{3} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)}, U\right) \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\left(\ell \cdot \ell\right) \cdot \ell\right)} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\color{blue}{{\ell}^{2}} \cdot \ell\right) \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\left(\frac{-1}{24} \cdot {K}^{2} + \frac{1}{3}\right)}\right), U\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \left(\color{blue}{{K}^{2} \cdot \frac{-1}{24}} + \frac{1}{3}\right)\right), U\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left({K}^{2}, \frac{-1}{24}, \frac{1}{3}\right)}\right), U\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, \frac{-1}{24}, \frac{1}{3}\right)\right), U\right) \]
      12. lower-*.f6452.2

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, -0.041666666666666664, 0.3333333333333333\right)\right), U\right) \]
    11. Applied rewrites52.2%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right)}, U\right) \]

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

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

      \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\ell \cdot \left(2 \cdot J + {\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(\ell \cdot \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right) + 2 \cdot J\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(\ell \cdot \left(\color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right) + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*l*N/A

        \[\leadsto \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right)\right)} + 2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. lower-fma.f64N/A

        \[\leadsto \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{60} \cdot \left(J \cdot {\ell}^{2}\right) + \frac{1}{3} \cdot J\right), 2 \cdot J\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites91.2%

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

      \[\leadsto \color{blue}{U + \ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\ell \cdot \left(2 \cdot J + J \cdot \left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \ell \cdot \left(2 \cdot J + \color{blue}{\left({\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right) \cdot J}\right) + U \]
      3. distribute-rgt-inN/A

        \[\leadsto \ell \cdot \color{blue}{\left(J \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)} + U \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\ell \cdot J\right) \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)} + U \]
      5. *-commutativeN/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right)} \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right) + U \]
      6. associate-*r*N/A

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right)\right)} + U \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot \left(2 + {\ell}^{2} \cdot \left(\frac{1}{3} + \frac{1}{60} \cdot {\ell}^{2}\right)\right), U\right)} \]
    8. Applied rewrites89.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\ell, \ell \cdot \mathsf{fma}\left(\ell \cdot \ell, 0.016666666666666666, 0.3333333333333333\right), 2\right), U\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 79.5% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma
    J
    (* (* l l) (* l (fma (* K K) -0.041666666666666664 0.3333333333333333)))
    U)
   (fma J (* l (fma 0.3333333333333333 (* l l) 2.0)) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma(J, ((l * l) * (l * fma((K * K), -0.041666666666666664, 0.3333333333333333))), U);
	} else {
		tmp = fma(J, (l * fma(0.3333333333333333, (l * l), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(J, Float64(Float64(l * l) * Float64(l * fma(Float64(K * K), -0.041666666666666664, 0.3333333333333333))), U);
	else
		tmp = fma(J, Float64(l * fma(0.3333333333333333, Float64(l * l), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(J * N[(N[(l * l), $MachinePrecision] * N[(l * N[(N[(K * K), $MachinePrecision] * -0.041666666666666664 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right), U\right)\\

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


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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6488.1

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites88.1%

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

      \[\leadsto \color{blue}{U + \left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{8} \cdot \left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right)\right) \cdot \frac{-1}{8}} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      3. associate-*l*N/A

        \[\leadsto \left(\color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8}\right)} + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) + U \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{J \cdot \left(\left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left({K}^{2} \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)\right) \cdot \frac{-1}{8} + \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    8. Applied rewrites26.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \mathsf{fma}\left(K \cdot \left(K \cdot \left(\ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right)\right), -0.125, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right)\right), U\right)} \]
    9. Taylor expanded in l around inf

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{3} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)}, U\right) \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\left(\ell \cdot \ell\right) \cdot \ell\right)} \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\color{blue}{{\ell}^{2}} \cdot \ell\right) \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right), U\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{{\ell}^{2} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right)} \cdot \left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right), U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot \left(\frac{1}{3} + \frac{-1}{24} \cdot {K}^{2}\right)\right)}, U\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\left(\frac{-1}{24} \cdot {K}^{2} + \frac{1}{3}\right)}\right), U\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \left(\color{blue}{{K}^{2} \cdot \frac{-1}{24}} + \frac{1}{3}\right)\right), U\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left({K}^{2}, \frac{-1}{24}, \frac{1}{3}\right)}\right), U\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, \frac{-1}{24}, \frac{1}{3}\right)\right), U\right) \]
      12. lower-*.f6452.2

        \[\leadsto \mathsf{fma}\left(J, \left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(\color{blue}{K \cdot K}, -0.041666666666666664, 0.3333333333333333\right)\right), U\right) \]
    11. Applied rewrites52.2%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\left(\ell \cdot \ell\right) \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.041666666666666664, 0.3333333333333333\right)\right)}, U\right) \]

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6487.7

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites87.7%

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

      \[\leadsto \color{blue}{U + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}, U\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}, U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)}, U\right) \]
      6. unpow2N/A

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

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \color{blue}{\ell \cdot \ell}, 2\right), U\right) \]
    8. Applied rewrites83.1%

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

Alternative 16: 76.3% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot J, \mathsf{fma}\left(-0.25, K \cdot K, 2\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right), U\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) -0.01)
   (fma (* l J) (fma -0.25 (* K K) 2.0) U)
   (fma J (* l (fma 0.3333333333333333 (* l l) 2.0)) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= -0.01) {
		tmp = fma((l * J), fma(-0.25, (K * K), 2.0), U);
	} else {
		tmp = fma(J, (l * fma(0.3333333333333333, (l * l), 2.0)), U);
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.01)
		tmp = fma(Float64(l * J), fma(-0.25, Float64(K * K), 2.0), U);
	else
		tmp = fma(J, Float64(l * fma(0.3333333333333333, Float64(l * l), 2.0)), U);
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.01], N[(N[(l * J), $MachinePrecision] * N[(-0.25 * N[(K * K), $MachinePrecision] + 2.0), $MachinePrecision] + U), $MachinePrecision], N[(J * N[(l * N[(0.3333333333333333 * N[(l * l), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\ell \cdot J, \mathsf{fma}\left(-0.25, K \cdot K, 2\right), U\right)\\

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


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

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

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right) + U} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)} + U \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(\frac{1}{2} \cdot K\right)} + U \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\left(2 \cdot J\right) \cdot \ell\right)} + U \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \left(2 \cdot J\right) \cdot \ell, U\right)} \]
      6. lower-cos.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos \left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \color{blue}{\left(\frac{1}{2} \cdot K\right)}, \left(2 \cdot J\right) \cdot \ell, U\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{\left(J \cdot 2\right)} \cdot \ell, U\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), \color{blue}{J \cdot \left(2 \cdot \ell\right)}, U\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos \left(\frac{1}{2} \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
      12. lower-*.f6474.3

        \[\leadsto \mathsf{fma}\left(\cos \left(0.5 \cdot K\right), J \cdot \color{blue}{\left(\ell \cdot 2\right)}, U\right) \]
    5. Applied rewrites74.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(0.5 \cdot K\right), J \cdot \left(\ell \cdot 2\right), U\right)} \]
    6. Taylor expanded in K around 0

      \[\leadsto \color{blue}{U + \left(\frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{-1}{4} \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right) + U} \]
      2. *-commutativeN/A

        \[\leadsto \left(\frac{-1}{4} \cdot \left(J \cdot \color{blue}{\left(\ell \cdot {K}^{2}\right)}\right) + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
      3. associate-*r*N/A

        \[\leadsto \left(\frac{-1}{4} \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot {K}^{2}\right)} + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
      4. associate-*l*N/A

        \[\leadsto \left(\color{blue}{\left(\frac{-1}{4} \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}} + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(\left(J \cdot \ell\right) \cdot \frac{-1}{4}\right)} \cdot {K}^{2} + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
      6. associate-*l*N/A

        \[\leadsto \left(\color{blue}{\left(J \cdot \ell\right) \cdot \left(\frac{-1}{4} \cdot {K}^{2}\right)} + 2 \cdot \left(J \cdot \ell\right)\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(\left(J \cdot \ell\right) \cdot \left(\frac{-1}{4} \cdot {K}^{2}\right) + \color{blue}{\left(J \cdot \ell\right) \cdot 2}\right) + U \]
      8. distribute-lft-outN/A

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot \left(\frac{-1}{4} \cdot {K}^{2} + 2\right)} + U \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \ell, \frac{-1}{4} \cdot {K}^{2} + 2, U\right)} \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{J \cdot \ell}, \frac{-1}{4} \cdot {K}^{2} + 2, U\right) \]
      11. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J \cdot \ell, \color{blue}{\mathsf{fma}\left(\frac{-1}{4}, {K}^{2}, 2\right)}, U\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J \cdot \ell, \mathsf{fma}\left(\frac{-1}{4}, \color{blue}{K \cdot K}, 2\right), U\right) \]
      13. lower-*.f6448.6

        \[\leadsto \mathsf{fma}\left(J \cdot \ell, \mathsf{fma}\left(-0.25, \color{blue}{K \cdot K}, 2\right), U\right) \]
    8. Applied rewrites48.6%

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. +-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. unpow2N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      4. associate-*r*N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      5. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      6. lower-fma.f64N/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      7. *-commutativeN/A

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      8. lower-*.f6487.7

        \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied rewrites87.7%

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

      \[\leadsto \color{blue}{U + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + U} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}, U\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}, U\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)}, U\right) \]
      6. unpow2N/A

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

        \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \color{blue}{\ell \cdot \ell}, 2\right), U\right) \]
    8. Applied rewrites83.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.01:\\ \;\;\;\;\mathsf{fma}\left(\ell \cdot J, \mathsf{fma}\left(-0.25, K \cdot K, 2\right), U\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right), U\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 72.0% accurate, 14.3× speedup?

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

\\
\mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \ell \cdot \ell, 2\right), U\right)
\end{array}
Derivation
  1. Initial program 85.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

    \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  4. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. +-commutativeN/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    3. unpow2N/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(\frac{1}{3} \cdot \color{blue}{\left(\ell \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. associate-*r*N/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\left(\frac{1}{3} \cdot \ell\right) \cdot \ell} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. *-commutativeN/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(\color{blue}{\ell \cdot \left(\frac{1}{3} \cdot \ell\right)} + 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. lower-fma.f64N/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{3} \cdot \ell, 2\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. *-commutativeN/A

      \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{1}{3}}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. lower-*.f6487.8

      \[\leadsto \left(J \cdot \left(\ell \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot 0.3333333333333333}, 2\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  5. Applied rewrites87.8%

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

    \[\leadsto \color{blue}{U + J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)\right) + U} \]
    2. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right), U\right)} \]
    3. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 + \frac{1}{3} \cdot {\ell}^{2}\right)}, U\right) \]
    4. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\left(\frac{1}{3} \cdot {\ell}^{2} + 2\right)}, U\right) \]
    5. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \ell \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{3}, {\ell}^{2}, 2\right)}, U\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(\frac{1}{3}, \color{blue}{\ell \cdot \ell}, 2\right), U\right) \]
    7. lower-*.f6473.9

      \[\leadsto \mathsf{fma}\left(J, \ell \cdot \mathsf{fma}\left(0.3333333333333333, \color{blue}{\ell \cdot \ell}, 2\right), U\right) \]
  8. Applied rewrites73.9%

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

Alternative 18: 54.1% accurate, 27.5× speedup?

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

\\
\mathsf{fma}\left(J, 2 \cdot \ell, U\right)
\end{array}
Derivation
  1. Initial program 85.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 K around 0

    \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
    2. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
    3. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
    4. lower-exp.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
    5. lower-exp.f64N/A

      \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
    6. lower-neg.f6478.0

      \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
  5. Applied rewrites78.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
  6. Taylor expanded in l around 0

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

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

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

Alternative 19: 19.8% accurate, 30.0× speedup?

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

\\
J \cdot \left(2 \cdot \ell\right)
\end{array}
Derivation
  1. Initial program 85.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 K around 0

    \[\leadsto \color{blue}{U + J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}\right) + U} \]
    2. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}, U\right)} \]
    3. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell} - e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
    4. lower-exp.f64N/A

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{e^{\ell}} - e^{\mathsf{neg}\left(\ell\right)}, U\right) \]
    5. lower-exp.f64N/A

      \[\leadsto \mathsf{fma}\left(J, e^{\ell} - \color{blue}{e^{\mathsf{neg}\left(\ell\right)}}, U\right) \]
    6. lower-neg.f6478.0

      \[\leadsto \mathsf{fma}\left(J, e^{\ell} - e^{\color{blue}{-\ell}}, U\right) \]
  5. Applied rewrites78.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, e^{\ell} - e^{-\ell}, U\right)} \]
  6. Taylor expanded in l around 0

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

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

    \[\leadsto \mathsf{fma}\left(J, \color{blue}{2 \cdot \ell}, U\right) \]
  9. Taylor expanded in J around inf

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
  10. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} \]
    2. associate-*r*N/A

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} \]
    3. *-commutativeN/A

      \[\leadsto J \cdot \color{blue}{\left(2 \cdot \ell\right)} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell\right)} \]
    5. *-commutativeN/A

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

      \[\leadsto J \cdot \color{blue}{\left(\ell \cdot 2\right)} \]
  11. Applied rewrites18.9%

    \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} \]
  12. Final simplification18.9%

    \[\leadsto J \cdot \left(2 \cdot \ell\right) \]
  13. Add Preprocessing

Reproduce

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