Average Error: 6.9 → 2.7
Time: 7.0s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.031032483723507254 \lor \neg \left(x \le 3.6948490856919295 \cdot 10^{-142}\right):\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -0.031032483723507254 \lor \neg \left(x \le 3.6948490856919295 \cdot 10^{-142}\right):\\
\;\;\;\;\frac{1}{z} \cdot \frac{x}{\frac{y - t}{2}}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r477447 = x;
        double r477448 = 2.0;
        double r477449 = r477447 * r477448;
        double r477450 = y;
        double r477451 = z;
        double r477452 = r477450 * r477451;
        double r477453 = t;
        double r477454 = r477453 * r477451;
        double r477455 = r477452 - r477454;
        double r477456 = r477449 / r477455;
        return r477456;
}

double f(double x, double y, double z, double t) {
        double r477457 = x;
        double r477458 = -0.031032483723507254;
        bool r477459 = r477457 <= r477458;
        double r477460 = 3.6948490856919295e-142;
        bool r477461 = r477457 <= r477460;
        double r477462 = !r477461;
        bool r477463 = r477459 || r477462;
        double r477464 = 1.0;
        double r477465 = z;
        double r477466 = r477464 / r477465;
        double r477467 = y;
        double r477468 = t;
        double r477469 = r477467 - r477468;
        double r477470 = 2.0;
        double r477471 = r477469 / r477470;
        double r477472 = r477457 / r477471;
        double r477473 = r477466 * r477472;
        double r477474 = r477470 / r477469;
        double r477475 = r477474 / r477465;
        double r477476 = r477457 * r477475;
        double r477477 = r477463 ? r477473 : r477476;
        return r477477;
}

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.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 2 regimes
  2. if x < -0.031032483723507254 or 3.6948490856919295e-142 < x

    1. Initial program 9.5

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

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

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

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{y - t}{2}}}\]
    6. Applied *-un-lft-identity8.5

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

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

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

    if -0.031032483723507254 < x < 3.6948490856919295e-142

    1. Initial program 3.3

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

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

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

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

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

Reproduce

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