Average Error: 7.0 → 5.8
Time: 13.2s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\frac{x \cdot 2}{\mathsf{fma}\left(y, z, -z \cdot t\right)}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\frac{x \cdot 2}{\mathsf{fma}\left(y, z, -z \cdot t\right)}
double f(double x, double y, double z, double t) {
        double r22442846 = x;
        double r22442847 = 2.0;
        double r22442848 = r22442846 * r22442847;
        double r22442849 = y;
        double r22442850 = z;
        double r22442851 = r22442849 * r22442850;
        double r22442852 = t;
        double r22442853 = r22442852 * r22442850;
        double r22442854 = r22442851 - r22442853;
        double r22442855 = r22442848 / r22442854;
        return r22442855;
}

double f(double x, double y, double z, double t) {
        double r22442856 = x;
        double r22442857 = 2.0;
        double r22442858 = r22442856 * r22442857;
        double r22442859 = y;
        double r22442860 = z;
        double r22442861 = t;
        double r22442862 = r22442860 * r22442861;
        double r22442863 = -r22442862;
        double r22442864 = fma(r22442859, r22442860, r22442863);
        double r22442865 = r22442858 / r22442864;
        return r22442865;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.0
Target2.0
Herbie5.8
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -2.559141628295061113708240820439530037456 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt 1.045027827330126029709547581125571222799 \cdot 10^{-269}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \end{array}\]

Derivation

  1. Initial program 7.0

    \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
  2. Using strategy rm
  3. Applied fma-neg5.8

    \[\leadsto \frac{x \cdot 2}{\color{blue}{\mathsf{fma}\left(y, z, -t \cdot z\right)}}\]
  4. Final simplification5.8

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

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"

  :herbie-target
  (if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

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