Average Error: 0.0 → 0.1
Time: 3.4s
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 r654783 = x;
        double r654784 = y;
        double r654785 = r654783 - r654784;
        double r654786 = z;
        double r654787 = r654786 - r654784;
        double r654788 = r654785 / r654787;
        return r654788;
}

double f(double x, double y, double z) {
        double r654789 = x;
        double r654790 = 1.0;
        double r654791 = z;
        double r654792 = y;
        double r654793 = r654791 - r654792;
        double r654794 = r654790 / r654793;
        double r654795 = r654792 / r654793;
        double r654796 = -r654795;
        double r654797 = fma(r654789, r654794, r654796);
        return r654797;
}

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)))