Average Error: 0.1 → 0.1
Time: 7.2s
Precision: binary64
\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
\[\mathsf{fma}\left(\sqrt{y}, \sqrt{y}, \log y \cdot \left(-0.25 - y\right) - \mathsf{fma}\left(0.5, \log \left(\sqrt{y}\right), z\right)\right) + x \]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\mathsf{fma}\left(\sqrt{y}, \sqrt{y}, \log y \cdot \left(-0.25 - y\right) - \mathsf{fma}\left(0.5, \log \left(\sqrt{y}\right), z\right)\right) + x
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z)
 :precision binary64
 (+
  (fma
   (sqrt y)
   (sqrt y)
   (- (* (log y) (- -0.25 y)) (fma 0.5 (log (sqrt y)) z)))
  x))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
double code(double x, double y, double z) {
	return fma(sqrt(y), sqrt(y), ((log(y) * (-0.25 - y)) - fma(0.5, log(sqrt(y)), z))) + x;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.1
Target0.1
Herbie0.1
\[\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y \]

Derivation

  1. Initial program 0.1

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Simplified0.1

    \[\leadsto \color{blue}{y - \left(\mathsf{fma}\left(y + 0.5, \log y, z\right) - x\right)} \]
  3. Taylor expanded in y around 0 0.1

    \[\leadsto y - \left(\color{blue}{\left(z + \left(y \cdot \log y + 0.5 \cdot \log y\right)\right)} - x\right) \]
  4. Applied associate--r-_binary640.1

    \[\leadsto \color{blue}{\left(y - \left(z + \left(y \cdot \log y + 0.5 \cdot \log y\right)\right)\right) + x} \]
  5. Applied add-sqr-sqrt_binary640.1

    \[\leadsto \left(y - \left(z + \left(y \cdot \log y + 0.5 \cdot \log \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)}\right)\right)\right) + x \]
  6. Applied log-prod_binary640.1

    \[\leadsto \left(y - \left(z + \left(y \cdot \log y + 0.5 \cdot \color{blue}{\left(\log \left(\sqrt{y}\right) + \log \left(\sqrt{y}\right)\right)}\right)\right)\right) + x \]
  7. Applied distribute-lft-in_binary640.1

    \[\leadsto \left(y - \left(z + \left(y \cdot \log y + \color{blue}{\left(0.5 \cdot \log \left(\sqrt{y}\right) + 0.5 \cdot \log \left(\sqrt{y}\right)\right)}\right)\right)\right) + x \]
  8. Applied associate-+r+_binary640.1

    \[\leadsto \left(y - \left(z + \color{blue}{\left(\left(y \cdot \log y + 0.5 \cdot \log \left(\sqrt{y}\right)\right) + 0.5 \cdot \log \left(\sqrt{y}\right)\right)}\right)\right) + x \]
  9. Simplified0.1

    \[\leadsto \left(y - \left(z + \left(\color{blue}{\mathsf{fma}\left(y, \log y, \log y \cdot 0.25\right)} + 0.5 \cdot \log \left(\sqrt{y}\right)\right)\right)\right) + x \]
  10. Applied add-sqr-sqrt_binary640.1

    \[\leadsto \left(\color{blue}{\sqrt{y} \cdot \sqrt{y}} - \left(z + \left(\mathsf{fma}\left(y, \log y, \log y \cdot 0.25\right) + 0.5 \cdot \log \left(\sqrt{y}\right)\right)\right)\right) + x \]
  11. Applied fma-neg_binary640.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{y}, \sqrt{y}, -\left(z + \left(\mathsf{fma}\left(y, \log y, \log y \cdot 0.25\right) + 0.5 \cdot \log \left(\sqrt{y}\right)\right)\right)\right)} + x \]
  12. Simplified0.1

    \[\leadsto \mathsf{fma}\left(\sqrt{y}, \sqrt{y}, \color{blue}{\log y \cdot \left(-0.25 - y\right) - \mathsf{fma}\left(0.5, \log \left(\sqrt{y}\right), z\right)}\right) + x \]
  13. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(\sqrt{y}, \sqrt{y}, \log y \cdot \left(-0.25 - y\right) - \mathsf{fma}\left(0.5, \log \left(\sqrt{y}\right), z\right)\right) + x \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (- (- (+ y x) z) (* (+ y 0.5) (log y)))

  (- (+ (- x (* (+ y 0.5) (log y))) y) z))