Average Error: 6.7 → 2.6
Time: 1.7m
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -290087027822663264673900375158619635712:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \mathbf{elif}\;z \le 2227808434386880537429847553387528192:\\ \;\;\;\;\frac{2}{z \cdot \left(y - t\right)} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -290087027822663264673900375158619635712:\\
\;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r24586951 = x;
        double r24586952 = 2.0;
        double r24586953 = r24586951 * r24586952;
        double r24586954 = y;
        double r24586955 = z;
        double r24586956 = r24586954 * r24586955;
        double r24586957 = t;
        double r24586958 = r24586957 * r24586955;
        double r24586959 = r24586956 - r24586958;
        double r24586960 = r24586953 / r24586959;
        return r24586960;
}

double f(double x, double y, double z, double t) {
        double r24586961 = z;
        double r24586962 = -2.9008702782266326e+38;
        bool r24586963 = r24586961 <= r24586962;
        double r24586964 = 2.0;
        double r24586965 = y;
        double r24586966 = t;
        double r24586967 = r24586965 - r24586966;
        double r24586968 = r24586964 / r24586967;
        double r24586969 = x;
        double r24586970 = r24586961 / r24586969;
        double r24586971 = r24586968 / r24586970;
        double r24586972 = 2.2278084343868805e+36;
        bool r24586973 = r24586961 <= r24586972;
        double r24586974 = r24586961 * r24586967;
        double r24586975 = r24586964 / r24586974;
        double r24586976 = r24586975 * r24586969;
        double r24586977 = r24586973 ? r24586976 : r24586971;
        double r24586978 = r24586963 ? r24586971 : r24586977;
        return r24586978;
}

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.7
Target2.2
Herbie2.6
\[\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 2 regimes
  2. if z < -2.9008702782266326e+38 or 2.2278084343868805e+36 < z

    1. Initial program 11.5

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot 2}}{\frac{z}{x} \cdot \left(y - t\right)}\]
    5. Applied times-frac2.5

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

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

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

    if -2.9008702782266326e+38 < z < 2.2278084343868805e+36

    1. Initial program 2.5

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

      \[\leadsto \color{blue}{\frac{2}{\frac{z}{x} \cdot \left(y - t\right)}}\]
    3. Using strategy rm
    4. Applied associate-*l/2.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -290087027822663264673900375158619635712:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \mathbf{elif}\;z \le 2227808434386880537429847553387528192:\\ \;\;\;\;\frac{2}{z \cdot \left(y - t\right)} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{y - t}}{\frac{z}{x}}\\ \end{array}\]

Reproduce

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