Average Error: 17.1 → 0.6
Time: 5.6s
Precision: 64
\[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U\]
\[\mathsf{fma}\left(2, \left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \ell, U\right)\]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\mathsf{fma}\left(2, \left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot \ell, U\right)
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, ((J * cos((0.5 * K))) * l), U);
}

Error

Bits error versus J

Bits error versus l

Bits error versus K

Bits error versus U

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 17.1

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

    \[\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 around 0 0.6

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \ell\right), U\right)}\]
  6. Using strategy rm
  7. Applied associate-*r*0.6

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

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

Reproduce

herbie shell --seed 2020053 +o rules:numerics
(FPCore (J l K U)
  :name "Maksimov and Kolovsky, Equation (4)"
  :precision binary64
  (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2))) U))