Average Error: 9.6 → 2.6
Time: 7.3s
Precision: binary64
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\mathsf{fma}\left(x, \frac{y}{z}, x\right) \]
\frac{x \cdot \left(y + z\right)}{z}
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z) :precision binary64 (fma x (/ y z) x))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	return fma(x, (y / z), x);
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original9.6
Target2.4
Herbie2.6
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Initial program 9.6

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Simplified2.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
  3. Final simplification2.6

    \[\leadsto \mathsf{fma}\left(x, \frac{y}{z}, x\right) \]

Reproduce

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

  :herbie-target
  (/ x (/ z (+ y z)))

  (/ (* x (+ y z)) z))