Average Error: 10.3 → 0.0
Time: 21.6s
Precision: 64
\[\frac{x + y \cdot \left(z - x\right)}{z}\]
\[\mathsf{fma}\left(1, \frac{x}{z} + y, \left(-y\right) \cdot \frac{x}{z}\right)\]
\frac{x + y \cdot \left(z - x\right)}{z}
\mathsf{fma}\left(1, \frac{x}{z} + y, \left(-y\right) \cdot \frac{x}{z}\right)
double f(double x, double y, double z) {
        double r476614 = x;
        double r476615 = y;
        double r476616 = z;
        double r476617 = r476616 - r476614;
        double r476618 = r476615 * r476617;
        double r476619 = r476614 + r476618;
        double r476620 = r476619 / r476616;
        return r476620;
}

double f(double x, double y, double z) {
        double r476621 = 1.0;
        double r476622 = x;
        double r476623 = z;
        double r476624 = r476622 / r476623;
        double r476625 = y;
        double r476626 = r476624 + r476625;
        double r476627 = -r476625;
        double r476628 = r476627 * r476624;
        double r476629 = fma(r476621, r476626, r476628);
        return r476629;
}

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. Simplified10.3

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

    \[\leadsto \color{blue}{\left(\frac{x}{z} + y\right) - \frac{x \cdot y}{z}}\]
  4. Using strategy rm
  5. Applied *-un-lft-identity3.4

    \[\leadsto \color{blue}{1 \cdot \left(\frac{x}{z} + y\right)} - \frac{x \cdot y}{z}\]
  6. Applied fma-neg3.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{x}{z} + y, -\frac{x \cdot y}{z}\right)}\]
  7. Simplified0.0

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

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

Reproduce

herbie shell --seed 2019322 +o rules:numerics
(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))