Average Error: 10.3 → 0.0
Time: 2.9s
Precision: binary64
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\mathsf{fma}\left(\frac{x}{z}, 1 - y, y\right) \]
\frac{x + y \cdot \left(z - x\right)}{z}
\mathsf{fma}\left(\frac{x}{z}, 1 - y, y\right)
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z) :precision binary64 (fma (/ x z) (- 1.0 y) y))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
	return fma((x / z), (1.0 - y), y);
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.3
Target0.0
Herbie0.0
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation

  1. Initial program 10.3

    \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  2. Taylor expanded in x around 0 3.4

    \[\leadsto \color{blue}{\left(y + \frac{x}{z}\right) - \frac{y \cdot x}{z}} \]
  3. Simplified3.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - y}{z}, x, y\right)} \]
  4. Taylor expanded in y around 0 3.4

    \[\leadsto \color{blue}{\left(y + \frac{x}{z}\right) - \frac{y \cdot x}{z}} \]
  5. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, 1 - y, y\right)} \]
  6. Final simplification0.0

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

Reproduce

herbie shell --seed 2022077 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

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

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