Average Error: 8.0 → 8.0
Time: 3.3s
Precision: 64
\[\frac{x \cdot y - z \cdot t}{a}\]
\[\frac{\mathsf{fma}\left(-y, x, z \cdot t\right)}{-a}\]
\frac{x \cdot y - z \cdot t}{a}
\frac{\mathsf{fma}\left(-y, x, z \cdot t\right)}{-a}
double f(double x, double y, double z, double t, double a) {
        double r789104 = x;
        double r789105 = y;
        double r789106 = r789104 * r789105;
        double r789107 = z;
        double r789108 = t;
        double r789109 = r789107 * r789108;
        double r789110 = r789106 - r789109;
        double r789111 = a;
        double r789112 = r789110 / r789111;
        return r789112;
}

double f(double x, double y, double z, double t, double a) {
        double r789113 = y;
        double r789114 = -r789113;
        double r789115 = x;
        double r789116 = z;
        double r789117 = t;
        double r789118 = r789116 * r789117;
        double r789119 = fma(r789114, r789115, r789118);
        double r789120 = a;
        double r789121 = -r789120;
        double r789122 = r789119 / r789121;
        return r789122;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original8.0
Target6.2
Herbie8.0
\[\begin{array}{l} \mathbf{if}\;z \lt -2.46868496869954822 \cdot 10^{170}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{elif}\;z \lt 6.30983112197837121 \cdot 10^{-71}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \end{array}\]

Derivation

  1. Initial program 8.0

    \[\frac{x \cdot y - z \cdot t}{a}\]
  2. Using strategy rm
  3. Applied frac-2neg8.0

    \[\leadsto \color{blue}{\frac{-\left(x \cdot y - z \cdot t\right)}{-a}}\]
  4. Simplified8.0

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-y, x, z \cdot t\right)}}{-a}\]
  5. Final simplification8.0

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

Reproduce

herbie shell --seed 2020039 +o rules:numerics
(FPCore (x y z t a)
  :name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
  :precision binary64

  :herbie-target
  (if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))

  (/ (- (* x y) (* z t)) a))