Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.8% → 100.0%
Time: 15.2s
Alternatives: 26
Speedup: 2.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 26 alternatives:

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

Initial Program: 85.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.5× speedup?

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

\\
\mathsf{fma}\left(\left(J \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \sinh \ell, 2, U\right)
\end{array}
Derivation
  1. Initial program 86.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-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 60.8% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-159}:\\
\;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K #s(literal 2 binary64)))) < -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-*.f6430.6

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

      \[\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 U + \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)} \]
    7. Step-by-step derivation
      1. Applied rewrites33.4%

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

      if -inf.0 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K #s(literal 2 binary64)))) < 1.99999999999999998e-159

      1. Initial program 72.9%

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

        \[\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-*.f6499.5

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

        \[\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 U + \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites86.3%

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

        if 1.99999999999999998e-159 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K #s(literal 2 binary64))))

        1. Initial program 99.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-*.f6433.2

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

          \[\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 2 \cdot \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(\frac{1}{2} \cdot K\right)\right)\right)} \]
        7. Step-by-step derivation
          1. Applied rewrites31.3%

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

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

              \[\leadsto \left(\frac{-1}{4} \cdot \left({K}^{2} \cdot \ell\right) + 2 \cdot \ell\right) \cdot J \]
            3. Step-by-step derivation
              1. Applied rewrites34.7%

                \[\leadsto \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.25, 2\right)\right) \cdot J \]
            4. Recombined 3 regimes into one program.
            5. Final simplification60.8%

              \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(J \cdot \ell, \mathsf{fma}\left(-0.25, K \cdot K, 2\right), U\right)\\ \mathbf{elif}\;\cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \leq 2 \cdot 10^{-159}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(\ell \cdot \mathsf{fma}\left(K \cdot K, -0.25, 2\right)\right)\\ \end{array} \]
            6. Add Preprocessing

            Reproduce

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