Average Error: 7.1 → 0.3
Time: 13.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 r23960097 = x;
        double r23960098 = 2.0;
        double r23960099 = r23960097 * r23960098;
        double r23960100 = y;
        double r23960101 = z;
        double r23960102 = r23960100 * r23960101;
        double r23960103 = t;
        double r23960104 = r23960103 * r23960101;
        double r23960105 = r23960102 - r23960104;
        double r23960106 = r23960099 / r23960105;
        return r23960106;
}

double f(double x, double y, double z, double t) {
        double r23960107 = y;
        double r23960108 = z;
        double r23960109 = r23960107 * r23960108;
        double r23960110 = t;
        double r23960111 = r23960110 * r23960108;
        double r23960112 = r23960109 - r23960111;
        double r23960113 = -inf.0;
        bool r23960114 = r23960112 <= r23960113;
        double r23960115 = 2.0;
        double r23960116 = r23960107 - r23960110;
        double r23960117 = r23960115 / r23960116;
        double r23960118 = x;
        double r23960119 = r23960108 / r23960118;
        double r23960120 = r23960117 / r23960119;
        double r23960121 = -1.206747795160849e-244;
        bool r23960122 = r23960112 <= r23960121;
        double r23960123 = r23960118 * r23960115;
        double r23960124 = r23960123 / r23960112;
        double r23960125 = 0.0;
        bool r23960126 = r23960112 <= r23960125;
        double r23960127 = 1.0;
        double r23960128 = r23960127 / r23960116;
        double r23960129 = r23960118 * r23960128;
        double r23960130 = r23960115 / r23960108;
        double r23960131 = r23960129 * r23960130;
        double r23960132 = 1.9511248466113264e+240;
        bool r23960133 = r23960112 <= r23960132;
        double r23960134 = r23960133 ? r23960124 : r23960120;
        double r23960135 = r23960126 ? r23960131 : r23960134;
        double r23960136 = r23960122 ? r23960124 : r23960135;
        double r23960137 = r23960114 ? r23960120 : r23960136;
        return r23960137;
}

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