Average Error: 7.1 → 2.0
Time: 4.5s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.67001758597271323 \cdot 10^{-63} \lor \neg \left(x \le 5.06956684508544874 \cdot 10^{-32}\right):\\ \;\;\;\;\frac{\frac{x}{\frac{y - t}{2}}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -1.67001758597271323 \cdot 10^{-63} \lor \neg \left(x \le 5.06956684508544874 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{\frac{x}{\frac{y - t}{2}}}{z}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r569427 = x;
        double r569428 = 2.0;
        double r569429 = r569427 * r569428;
        double r569430 = y;
        double r569431 = z;
        double r569432 = r569430 * r569431;
        double r569433 = t;
        double r569434 = r569433 * r569431;
        double r569435 = r569432 - r569434;
        double r569436 = r569429 / r569435;
        return r569436;
}

double f(double x, double y, double z, double t) {
        double r569437 = x;
        double r569438 = -1.6700175859727132e-63;
        bool r569439 = r569437 <= r569438;
        double r569440 = 5.069566845085449e-32;
        bool r569441 = r569437 <= r569440;
        double r569442 = !r569441;
        bool r569443 = r569439 || r569442;
        double r569444 = y;
        double r569445 = t;
        double r569446 = r569444 - r569445;
        double r569447 = 2.0;
        double r569448 = r569446 / r569447;
        double r569449 = r569437 / r569448;
        double r569450 = z;
        double r569451 = r569449 / r569450;
        double r569452 = r569437 / r569450;
        double r569453 = r569452 / r569448;
        double r569454 = r569443 ? r569451 : r569453;
        return r569454;
}

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
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -2.559141628295061 \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.04502782733012586 \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 x < -1.6700175859727132e-63 or 5.069566845085449e-32 < x

    1. Initial program 9.9

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

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

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied associate-/r*9.3

      \[\leadsto \color{blue}{\frac{\frac{x}{\frac{z}{1}}}{\frac{y - t}{2}}}\]
    7. Simplified9.3

      \[\leadsto \frac{\color{blue}{\frac{x}{z}}}{\frac{y - t}{2}}\]
    8. Using strategy rm
    9. Applied div-inv9.4

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

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

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

    if -1.6700175859727132e-63 < x < 5.069566845085449e-32

    1. Initial program 3.8

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

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

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied associate-/r*1.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.67001758597271323 \cdot 10^{-63} \lor \neg \left(x \le 5.06956684508544874 \cdot 10^{-32}\right):\\ \;\;\;\;\frac{\frac{x}{\frac{y - t}{2}}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020020 +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.0450278273301259e-269) (/ (* (/ x z) 2) (- y t)) (* (/ x (* (- y t) z)) 2)))

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