Average Error: 7.1 → 0.3
Time: 15.2s
Precision: 64
\[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z = -\infty:\\ \;\;\;\;\frac{\frac{2.0}{y - t}}{\frac{z}{x}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le -1.206747795160849 \cdot 10^{-244}:\\ \;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 0.0:\\ \;\;\;\;\left(x \cdot \frac{1}{y - t}\right) \cdot \frac{2.0}{z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.9511248466113264 \cdot 10^{+240}:\\ \;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2.0}{y - t}}{\frac{z}{x}}\\ \end{array}\]
\frac{x \cdot 2.0}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;y \cdot z - t \cdot z = -\infty:\\
\;\;\;\;\frac{\frac{2.0}{y - t}}{\frac{z}{x}}\\

\mathbf{elif}\;y \cdot z - t \cdot z \le -1.206747795160849 \cdot 10^{-244}:\\
\;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\

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

\mathbf{elif}\;y \cdot z - t \cdot z \le 1.9511248466113264 \cdot 10^{+240}:\\
\;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r24359086 = x;
        double r24359087 = 2.0;
        double r24359088 = r24359086 * r24359087;
        double r24359089 = y;
        double r24359090 = z;
        double r24359091 = r24359089 * r24359090;
        double r24359092 = t;
        double r24359093 = r24359092 * r24359090;
        double r24359094 = r24359091 - r24359093;
        double r24359095 = r24359088 / r24359094;
        return r24359095;
}

double f(double x, double y, double z, double t) {
        double r24359096 = y;
        double r24359097 = z;
        double r24359098 = r24359096 * r24359097;
        double r24359099 = t;
        double r24359100 = r24359099 * r24359097;
        double r24359101 = r24359098 - r24359100;
        double r24359102 = -inf.0;
        bool r24359103 = r24359101 <= r24359102;
        double r24359104 = 2.0;
        double r24359105 = r24359096 - r24359099;
        double r24359106 = r24359104 / r24359105;
        double r24359107 = x;
        double r24359108 = r24359097 / r24359107;
        double r24359109 = r24359106 / r24359108;
        double r24359110 = -1.206747795160849e-244;
        bool r24359111 = r24359101 <= r24359110;
        double r24359112 = r24359107 * r24359104;
        double r24359113 = r24359112 / r24359101;
        double r24359114 = 0.0;
        bool r24359115 = r24359101 <= r24359114;
        double r24359116 = 1.0;
        double r24359117 = r24359116 / r24359105;
        double r24359118 = r24359107 * r24359117;
        double r24359119 = r24359104 / r24359097;
        double r24359120 = r24359118 * r24359119;
        double r24359121 = 1.9511248466113264e+240;
        bool r24359122 = r24359101 <= r24359121;
        double r24359123 = r24359122 ? r24359113 : r24359109;
        double r24359124 = r24359115 ? r24359120 : r24359123;
        double r24359125 = r24359111 ? r24359113 : r24359124;
        double r24359126 = r24359103 ? r24359109 : r24359125;
        return r24359126;
}

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

Original7.1
Target2.1
Herbie0.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 3 regimes
  2. if (- (* y z) (* t z)) < -inf.0 or 1.9511248466113264e+240 < (- (* y z) (* t z))

    1. Initial program 21.3

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

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

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

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

    if -inf.0 < (- (* y z) (* t z)) < -1.206747795160849e-244 or 0.0 < (- (* y z) (* t z)) < 1.9511248466113264e+240

    1. Initial program 0.3

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

    if -1.206747795160849e-244 < (- (* y z) (* t z)) < 0.0

    1. Initial program 35.3

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{2.0}{y - t}}{\frac{z}{x}}}\]
    7. Using strategy rm
    8. Applied div-inv0.7

      \[\leadsto \frac{\frac{2.0}{y - t}}{\color{blue}{z \cdot \frac{1}{x}}}\]
    9. Applied div-inv0.7

      \[\leadsto \frac{\color{blue}{2.0 \cdot \frac{1}{y - t}}}{z \cdot \frac{1}{x}}\]
    10. Applied times-frac1.3

      \[\leadsto \color{blue}{\frac{2.0}{z} \cdot \frac{\frac{1}{y - t}}{\frac{1}{x}}}\]
    11. Simplified1.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z = -\infty:\\ \;\;\;\;\frac{\frac{2.0}{y - t}}{\frac{z}{x}}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le -1.206747795160849 \cdot 10^{-244}:\\ \;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 0.0:\\ \;\;\;\;\left(x \cdot \frac{1}{y - t}\right) \cdot \frac{2.0}{z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \le 1.9511248466113264 \cdot 10^{+240}:\\ \;\;\;\;\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2.0}{y - t}}{\frac{z}{x}}\\ \end{array}\]

Reproduce

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