Average Error: 6.9 → 2.5
Time: 3.0s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.9443547244995207 \cdot 10^{78}:\\ \;\;\;\;\frac{x}{\frac{\left(y - t\right) \cdot z}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y - t} \cdot \left(\frac{1}{z} \cdot 2\right)\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\
\;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r519089 = x;
        double r519090 = 2.0;
        double r519091 = r519089 * r519090;
        double r519092 = y;
        double r519093 = z;
        double r519094 = r519092 * r519093;
        double r519095 = t;
        double r519096 = r519095 * r519093;
        double r519097 = r519094 - r519096;
        double r519098 = r519091 / r519097;
        return r519098;
}

double f(double x, double y, double z, double t) {
        double r519099 = z;
        double r519100 = -5.163511120146309e-59;
        bool r519101 = r519099 <= r519100;
        double r519102 = x;
        double r519103 = r519102 / r519099;
        double r519104 = y;
        double r519105 = t;
        double r519106 = r519104 - r519105;
        double r519107 = 2.0;
        double r519108 = r519106 / r519107;
        double r519109 = r519103 / r519108;
        double r519110 = 1.9443547244995207e+78;
        bool r519111 = r519099 <= r519110;
        double r519112 = r519106 * r519099;
        double r519113 = r519112 / r519107;
        double r519114 = r519102 / r519113;
        double r519115 = r519102 / r519106;
        double r519116 = 1.0;
        double r519117 = r519116 / r519099;
        double r519118 = r519117 * r519107;
        double r519119 = r519115 * r519118;
        double r519120 = r519111 ? r519114 : r519119;
        double r519121 = r519101 ? r519109 : r519120;
        return r519121;
}

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.9
Target2.1
Herbie2.5
\[\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 < -5.163511120146309e-59

    1. Initial program 9.2

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

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

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

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

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

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

    if -5.163511120146309e-59 < z < 1.9443547244995207e+78

    1. Initial program 2.5

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

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

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

    if 1.9443547244995207e+78 < z

    1. Initial program 13.8

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

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

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

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

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

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

      \[\leadsto \frac{\frac{x}{z}}{\color{blue}{\left(y - t\right) \cdot \frac{1}{2}}}\]
    10. Applied div-inv2.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.1635111201463088 \cdot 10^{-59}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{y - t}{2}}\\ \mathbf{elif}\;z \le 1.9443547244995207 \cdot 10^{78}:\\ \;\;\;\;\frac{x}{\frac{\left(y - t\right) \cdot z}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y - t} \cdot \left(\frac{1}{z} \cdot 2\right)\\ \end{array}\]

Reproduce

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