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

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r368774 = x;
        double r368775 = 2.0;
        double r368776 = r368774 * r368775;
        double r368777 = y;
        double r368778 = z;
        double r368779 = r368777 * r368778;
        double r368780 = t;
        double r368781 = r368780 * r368778;
        double r368782 = r368779 - r368781;
        double r368783 = r368776 / r368782;
        return r368783;
}

double f(double x, double y, double z, double t) {
        double r368784 = z;
        double r368785 = -2.274561628042614e+53;
        bool r368786 = r368784 <= r368785;
        double r368787 = x;
        double r368788 = 2.0;
        double r368789 = r368787 * r368788;
        double r368790 = r368789 / r368784;
        double r368791 = y;
        double r368792 = t;
        double r368793 = r368791 - r368792;
        double r368794 = r368790 / r368793;
        double r368795 = 2.2688982000271057e-08;
        bool r368796 = r368784 <= r368795;
        double r368797 = r368784 * r368793;
        double r368798 = r368789 / r368797;
        double r368799 = r368789 / r368793;
        double r368800 = r368799 / r368784;
        double r368801 = r368796 ? r368798 : r368800;
        double r368802 = r368786 ? r368794 : r368801;
        return r368802;
}

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.2
\[\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.274561628042614e+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 associate-/r*2.0

      \[\leadsto \color{blue}{\frac{\frac{x \cdot 2}{z}}{y - t}}\]
    5. Using strategy rm
    6. Applied div-inv2.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z} \cdot \frac{1}{y - t}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity2.0

      \[\leadsto \color{blue}{\left(1 \cdot \frac{x \cdot 2}{z}\right)} \cdot \frac{1}{y - t}\]
    9. Applied associate-*l*2.0

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

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

    if -2.274561628042614e+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 associate-/r*2.0

      \[\leadsto \color{blue}{\frac{\frac{x \cdot 2}{z}}{y - t}}\]
    5. Using strategy rm
    6. Applied div-inv2.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{z} \cdot \frac{1}{y - t}}\]
    7. Using strategy rm
    8. Applied associate-*l/2.3

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

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

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

Reproduce

herbie shell --seed 2019304 +o rules:numerics
(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))))