Average Error: 17.3 → 0.6
Time: 8.3s
Precision: binary64
\[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
\[\mathsf{fma}\left(2, \ell \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right), U\right) \]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\mathsf{fma}\left(2, \ell \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right), U\right)
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
(FPCore (J l K U) :precision binary64 (fma 2.0 (* l (* J (cos (* 0.5 K)))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos(K / 2.0)) + U;
}
double code(double J, double l, double K, double U) {
	return fma(2.0, (l * (J * cos(0.5 * K))), U);
}

Error

Bits error versus J

Bits error versus l

Bits error versus K

Bits error versus U

Derivation

  1. Initial program 17.3

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

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

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

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

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

Reproduce

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