Average Error: 6.8 → 2.8
Time: 6.9s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \le -3.4278553939664262 \cdot 10^{-49} \lor \neg \left(x \cdot 2 \le 1.0146296550947617 \cdot 10^{-158}\right):\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z \cdot \frac{y - t}{2}}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \cdot 2 \le -3.4278553939664262 \cdot 10^{-49} \lor \neg \left(x \cdot 2 \le 1.0146296550947617 \cdot 10^{-158}\right):\\
\;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r521163 = x;
        double r521164 = 2.0;
        double r521165 = r521163 * r521164;
        double r521166 = y;
        double r521167 = z;
        double r521168 = r521166 * r521167;
        double r521169 = t;
        double r521170 = r521169 * r521167;
        double r521171 = r521168 - r521170;
        double r521172 = r521165 / r521171;
        return r521172;
}

double f(double x, double y, double z, double t) {
        double r521173 = x;
        double r521174 = 2.0;
        double r521175 = r521173 * r521174;
        double r521176 = -3.427855393966426e-49;
        bool r521177 = r521175 <= r521176;
        double r521178 = 1.0146296550947617e-158;
        bool r521179 = r521175 <= r521178;
        double r521180 = !r521179;
        bool r521181 = r521177 || r521180;
        double r521182 = 1.0;
        double r521183 = z;
        double r521184 = r521182 / r521183;
        double r521185 = y;
        double r521186 = t;
        double r521187 = r521185 - r521186;
        double r521188 = r521187 / r521174;
        double r521189 = r521173 / r521188;
        double r521190 = r521184 * r521189;
        double r521191 = r521183 * r521188;
        double r521192 = r521173 / r521191;
        double r521193 = r521181 ? r521190 : r521192;
        return r521193;
}

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.0
Herbie2.8
\[\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 2.0) < -3.427855393966426e-49 or 1.0146296550947617e-158 < (* x 2.0)

    1. Initial program 8.7

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

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

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

      \[\leadsto \frac{x}{\color{blue}{z \cdot \frac{y - t}{2}}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity7.7

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{z \cdot \frac{y - t}{2}}\]
    8. Applied times-frac3.1

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

    if -3.427855393966426e-49 < (* x 2.0) < 1.0146296550947617e-158

    1. Initial program 3.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 2 \le -3.4278553939664262 \cdot 10^{-49} \lor \neg \left(x \cdot 2 \le 1.0146296550947617 \cdot 10^{-158}\right):\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z \cdot \frac{y - t}{2}}\\ \end{array}\]

Reproduce

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