Average Error: 6.8 → 2.3
Time: 13.6s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.776525036283727903159592037753472003598 \cdot 10^{53}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\ \mathbf{elif}\;z \le 2.268898200027105692764604438597941804545 \cdot 10^{-8}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -2.776525036283727903159592037753472003598 \cdot 10^{53}:\\
\;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\

\mathbf{elif}\;z \le 2.268898200027105692764604438597941804545 \cdot 10^{-8}:\\
\;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r345860 = x;
        double r345861 = 2.0;
        double r345862 = r345860 * r345861;
        double r345863 = y;
        double r345864 = z;
        double r345865 = r345863 * r345864;
        double r345866 = t;
        double r345867 = r345866 * r345864;
        double r345868 = r345865 - r345867;
        double r345869 = r345862 / r345868;
        return r345869;
}

double f(double x, double y, double z, double t) {
        double r345870 = z;
        double r345871 = -2.776525036283728e+53;
        bool r345872 = r345870 <= r345871;
        double r345873 = x;
        double r345874 = r345873 / r345870;
        double r345875 = 2.0;
        double r345876 = y;
        double r345877 = t;
        double r345878 = r345876 - r345877;
        double r345879 = r345875 / r345878;
        double r345880 = r345874 * r345879;
        double r345881 = 2.2688982000271057e-08;
        bool r345882 = r345870 <= r345881;
        double r345883 = r345873 * r345875;
        double r345884 = r345870 * r345878;
        double r345885 = r345883 / r345884;
        double r345886 = r345873 * r345879;
        double r345887 = r345886 / r345870;
        double r345888 = r345882 ? r345885 : r345887;
        double r345889 = r345872 ? r345880 : r345888;
        return r345889;
}

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.8
Target2.0
Herbie2.3
\[\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. Split input into 3 regimes
  2. if z < -2.776525036283728e+53

    1. Initial program 12.4

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
    2. Simplified10.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied times-frac2.0

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

    if -2.776525036283728e+53 < z < 2.2688982000271057e-08

    1. Initial program 2.4

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]

    if 2.2688982000271057e-08 < z

    1. Initial program 10.0

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied times-frac2.0

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \frac{2}{y - t}}\]
    5. Using strategy rm
    6. Applied associate-*l/2.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.776525036283727903159592037753472003598 \cdot 10^{53}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\ \mathbf{elif}\;z \le 2.268898200027105692764604438597941804545 \cdot 10^{-8}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2019304 
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
  :precision binary64

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

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