Average Error: 6.6 → 2.3
Time: 1.8m
Precision: 64
\[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.6423821146328647 \cdot 10^{-56}:\\ \;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\ \mathbf{elif}\;z \le 6920936089083.012:\\ \;\;\;\;\frac{2.0 \cdot x}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\ \end{array}\]
\frac{x \cdot 2.0}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -3.6423821146328647 \cdot 10^{-56}:\\
\;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\

\mathbf{elif}\;z \le 6920936089083.012:\\
\;\;\;\;\frac{2.0 \cdot x}{\left(y - t\right) \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r27997807 = x;
        double r27997808 = 2.0;
        double r27997809 = r27997807 * r27997808;
        double r27997810 = y;
        double r27997811 = z;
        double r27997812 = r27997810 * r27997811;
        double r27997813 = t;
        double r27997814 = r27997813 * r27997811;
        double r27997815 = r27997812 - r27997814;
        double r27997816 = r27997809 / r27997815;
        return r27997816;
}

double f(double x, double y, double z, double t) {
        double r27997817 = z;
        double r27997818 = -3.6423821146328647e-56;
        bool r27997819 = r27997817 <= r27997818;
        double r27997820 = 2.0;
        double r27997821 = x;
        double r27997822 = r27997817 / r27997821;
        double r27997823 = r27997820 / r27997822;
        double r27997824 = y;
        double r27997825 = t;
        double r27997826 = r27997824 - r27997825;
        double r27997827 = r27997823 / r27997826;
        double r27997828 = 6920936089083.012;
        bool r27997829 = r27997817 <= r27997828;
        double r27997830 = r27997820 * r27997821;
        double r27997831 = r27997826 * r27997817;
        double r27997832 = r27997830 / r27997831;
        double r27997833 = r27997829 ? r27997832 : r27997827;
        double r27997834 = r27997819 ? r27997827 : r27997833;
        return r27997834;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.6
Target2.1
Herbie2.3
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z} \lt -2.559141628295061 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2.0\\ \mathbf{elif}\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z} \lt 1.045027827330126 \cdot 10^{-269}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2.0}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2.0\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -3.6423821146328647e-56 or 6920936089083.012 < z

    1. Initial program 9.7

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Simplified2.2

      \[\leadsto \color{blue}{\frac{\frac{2.0}{\frac{z}{x}}}{y - t}}\]

    if -3.6423821146328647e-56 < z < 6920936089083.012

    1. Initial program 2.5

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Simplified9.8

      \[\leadsto \color{blue}{\frac{\frac{2.0}{\frac{z}{x}}}{y - t}}\]
    3. Using strategy rm
    4. Applied associate-/l/9.3

      \[\leadsto \color{blue}{\frac{2.0}{\left(y - t\right) \cdot \frac{z}{x}}}\]
    5. Using strategy rm
    6. Applied associate-*r/2.8

      \[\leadsto \frac{2.0}{\color{blue}{\frac{\left(y - t\right) \cdot z}{x}}}\]
    7. Applied associate-/r/2.7

      \[\leadsto \color{blue}{\frac{2.0}{\left(y - t\right) \cdot z} \cdot x}\]
    8. Using strategy rm
    9. Applied associate-*l/2.5

      \[\leadsto \color{blue}{\frac{2.0 \cdot x}{\left(y - t\right) \cdot z}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.6423821146328647 \cdot 10^{-56}:\\ \;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\ \mathbf{elif}\;z \le 6920936089083.012:\\ \;\;\;\;\frac{2.0 \cdot x}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2.0}{\frac{z}{x}}}{y - t}\\ \end{array}\]

Reproduce

herbie shell --seed 2019164 +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))))