Average Error: 6.8 → 2.5
Time: 5.4s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.9425230437440893 \cdot 10^{45}:\\ \;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\ \mathbf{elif}\;z \le 3.0712348216511889 \cdot 10^{72}:\\ \;\;\;\;\frac{x \cdot 2}{\left(y - t\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y - t}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -3.9425230437440893 \cdot 10^{45}:\\
\;\;\;\;\frac{x \cdot 2}{y - t} \cdot \frac{1}{z}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r695192 = x;
        double r695193 = 2.0;
        double r695194 = r695192 * r695193;
        double r695195 = y;
        double r695196 = z;
        double r695197 = r695195 * r695196;
        double r695198 = t;
        double r695199 = r695198 * r695196;
        double r695200 = r695197 - r695199;
        double r695201 = r695194 / r695200;
        return r695201;
}

double f(double x, double y, double z, double t) {
        double r695202 = z;
        double r695203 = -3.942523043744089e+45;
        bool r695204 = r695202 <= r695203;
        double r695205 = x;
        double r695206 = 2.0;
        double r695207 = r695205 * r695206;
        double r695208 = y;
        double r695209 = t;
        double r695210 = r695208 - r695209;
        double r695211 = r695207 / r695210;
        double r695212 = 1.0;
        double r695213 = r695212 / r695202;
        double r695214 = r695211 * r695213;
        double r695215 = 3.071234821651189e+72;
        bool r695216 = r695202 <= r695215;
        double r695217 = r695210 * r695202;
        double r695218 = r695207 / r695217;
        double r695219 = r695205 / r695202;
        double r695220 = r695206 / r695210;
        double r695221 = r695219 * r695220;
        double r695222 = r695216 ? r695218 : r695221;
        double r695223 = r695204 ? r695214 : r695222;
        return r695223;
}

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.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 < -3.942523043744089e+45

    1. Initial program 11.7

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

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

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

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

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

    if -3.942523043744089e+45 < z < 3.071234821651189e+72

    1. Initial program 2.7

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

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

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

    if 3.071234821651189e+72 < z

    1. Initial program 12.3

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

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

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

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

Reproduce

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