Average Error: 6.8 → 2.7
Time: 5.6s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{elif}\;z \le 4.5360233662522261 \cdot 10^{-37}:\\ \;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\
\;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r677323 = x;
        double r677324 = 2.0;
        double r677325 = r677323 * r677324;
        double r677326 = y;
        double r677327 = z;
        double r677328 = r677326 * r677327;
        double r677329 = t;
        double r677330 = r677329 * r677327;
        double r677331 = r677328 - r677330;
        double r677332 = r677325 / r677331;
        return r677332;
}

double f(double x, double y, double z, double t) {
        double r677333 = z;
        double r677334 = -6.93799498024277e-128;
        bool r677335 = r677333 <= r677334;
        double r677336 = x;
        double r677337 = 2.0;
        double r677338 = y;
        double r677339 = t;
        double r677340 = r677338 - r677339;
        double r677341 = r677337 / r677340;
        double r677342 = r677336 * r677341;
        double r677343 = r677342 / r677333;
        double r677344 = 4.536023366252226e-37;
        bool r677345 = r677333 <= r677344;
        double r677346 = r677336 * r677337;
        double r677347 = r677340 * r677333;
        double r677348 = r677346 / r677347;
        double r677349 = r677346 / r677333;
        double r677350 = r677349 / r677340;
        double r677351 = r677345 ? r677348 : r677350;
        double r677352 = r677335 ? r677343 : r677351;
        return r677352;
}

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.2
Herbie2.7
\[\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 3 regimes
  2. if z < -6.93799498024277e-128

    1. Initial program 7.5

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

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

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

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

    if -6.93799498024277e-128 < z < 4.536023366252226e-37

    1. Initial program 3.5

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

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

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

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

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

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

    if 4.536023366252226e-37 < z

    1. Initial program 9.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -6.9379949802427703 \cdot 10^{-128}:\\ \;\;\;\;\frac{x \cdot \frac{2}{y - t}}{z}\\ \mathbf{elif}\;z \le 4.5360233662522261 \cdot 10^{-37}:\\ \;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 
(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))))