Average Error: 0.0 → 0.1
Time: 3.5s
Precision: 64
\[\frac{x - y}{z - y}\]
\[\mathsf{fma}\left(x, \frac{1}{z - y}, -\frac{y}{z - y}\right)\]
\frac{x - y}{z - y}
\mathsf{fma}\left(x, \frac{1}{z - y}, -\frac{y}{z - y}\right)
double f(double x, double y, double z) {
        double r555049 = x;
        double r555050 = y;
        double r555051 = r555049 - r555050;
        double r555052 = z;
        double r555053 = r555052 - r555050;
        double r555054 = r555051 / r555053;
        return r555054;
}

double f(double x, double y, double z) {
        double r555055 = x;
        double r555056 = 1.0;
        double r555057 = z;
        double r555058 = y;
        double r555059 = r555057 - r555058;
        double r555060 = r555056 / r555059;
        double r555061 = r555058 / r555059;
        double r555062 = -r555061;
        double r555063 = fma(r555055, r555060, r555062);
        return r555063;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.0
Target0.0
Herbie0.1
\[\frac{x}{z - y} - \frac{y}{z - y}\]

Derivation

  1. Initial program 0.0

    \[\frac{x - y}{z - y}\]
  2. Using strategy rm
  3. Applied div-sub0.0

    \[\leadsto \color{blue}{\frac{x}{z - y} - \frac{y}{z - y}}\]
  4. Using strategy rm
  5. Applied div-inv0.1

    \[\leadsto \color{blue}{x \cdot \frac{1}{z - y}} - \frac{y}{z - y}\]
  6. Applied fma-neg0.1

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

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

Reproduce

herbie shell --seed 2020062 +o rules:numerics
(FPCore (x y z)
  :name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
  :precision binary64

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

  (/ (- x y) (- z y)))