Average Error: 6.6 → 4.2
Time: 15.4s
Precision: 64
\[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.6736547781701635 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{z \cdot \frac{\frac{y - t}{2.0}}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2.0}}\\ \end{array}\]
\frac{x \cdot 2.0}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -5.6736547781701635 \cdot 10^{+88}:\\
\;\;\;\;\frac{1}{z \cdot \frac{\frac{y - t}{2.0}}{x}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2.0}}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r20692045 = x;
        double r20692046 = 2.0;
        double r20692047 = r20692045 * r20692046;
        double r20692048 = y;
        double r20692049 = z;
        double r20692050 = r20692048 * r20692049;
        double r20692051 = t;
        double r20692052 = r20692051 * r20692049;
        double r20692053 = r20692050 - r20692052;
        double r20692054 = r20692047 / r20692053;
        return r20692054;
}

double f(double x, double y, double z, double t) {
        double r20692055 = z;
        double r20692056 = -5.6736547781701635e+88;
        bool r20692057 = r20692055 <= r20692056;
        double r20692058 = 1.0;
        double r20692059 = y;
        double r20692060 = t;
        double r20692061 = r20692059 - r20692060;
        double r20692062 = 2.0;
        double r20692063 = r20692061 / r20692062;
        double r20692064 = x;
        double r20692065 = r20692063 / r20692064;
        double r20692066 = r20692055 * r20692065;
        double r20692067 = r20692058 / r20692066;
        double r20692068 = r20692055 * r20692061;
        double r20692069 = r20692068 / r20692062;
        double r20692070 = r20692064 / r20692069;
        double r20692071 = r20692057 ? r20692067 : r20692070;
        return r20692071;
}

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.6
Target2.2
Herbie4.2
\[\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 2 regimes
  2. if z < -5.6736547781701635e+88

    1. Initial program 12.6

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Using strategy rm
    3. Applied associate-/l*12.5

      \[\leadsto \color{blue}{\frac{x}{\frac{y \cdot z - t \cdot z}{2.0}}}\]
    4. Simplified9.8

      \[\leadsto \frac{x}{\color{blue}{\frac{z \cdot \left(y - t\right)}{2.0}}}\]
    5. Using strategy rm
    6. Applied clear-num10.1

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z \cdot \left(y - t\right)}{2.0}}{x}}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity10.1

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

      \[\leadsto \frac{1}{\frac{\frac{z \cdot \left(y - t\right)}{\color{blue}{1 \cdot 2.0}}}{1 \cdot x}}\]
    10. Applied times-frac10.1

      \[\leadsto \frac{1}{\frac{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2.0}}}{1 \cdot x}}\]
    11. Applied times-frac2.7

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{z}{1}}{1} \cdot \frac{\frac{y - t}{2.0}}{x}}}\]
    12. Simplified2.7

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

    if -5.6736547781701635e+88 < z

    1. Initial program 5.2

      \[\frac{x \cdot 2.0}{y \cdot z - t \cdot z}\]
    2. Using strategy rm
    3. Applied associate-/l*5.2

      \[\leadsto \color{blue}{\frac{x}{\frac{y \cdot z - t \cdot z}{2.0}}}\]
    4. Simplified4.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.6736547781701635 \cdot 10^{+88}:\\ \;\;\;\;\frac{1}{z \cdot \frac{\frac{y - t}{2.0}}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2.0}}\\ \end{array}\]

Reproduce

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