Average Error: 6.7 → 2.4
Time: 9.2s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \le -481070734274871.125 \lor \neg \left(x \cdot 2 \le 1.210211364392590254969677374177425362512 \cdot 10^{-59}\right):\\ \;\;\;\;\frac{\sqrt{1}}{z} \cdot \frac{\left(x \cdot 2\right) \cdot 1}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{\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 -481070734274871.125 \lor \neg \left(x \cdot 2 \le 1.210211364392590254969677374177425362512 \cdot 10^{-59}\right):\\
\;\;\;\;\frac{\sqrt{1}}{z} \cdot \frac{\left(x \cdot 2\right) \cdot 1}{y - t}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r443461 = x;
        double r443462 = 2.0;
        double r443463 = r443461 * r443462;
        double r443464 = y;
        double r443465 = z;
        double r443466 = r443464 * r443465;
        double r443467 = t;
        double r443468 = r443467 * r443465;
        double r443469 = r443466 - r443468;
        double r443470 = r443463 / r443469;
        return r443470;
}

double f(double x, double y, double z, double t) {
        double r443471 = x;
        double r443472 = 2.0;
        double r443473 = r443471 * r443472;
        double r443474 = -481070734274871.1;
        bool r443475 = r443473 <= r443474;
        double r443476 = 1.2102113643925903e-59;
        bool r443477 = r443473 <= r443476;
        double r443478 = !r443477;
        bool r443479 = r443475 || r443478;
        double r443480 = 1.0;
        double r443481 = sqrt(r443480);
        double r443482 = z;
        double r443483 = r443481 / r443482;
        double r443484 = r443473 * r443480;
        double r443485 = y;
        double r443486 = t;
        double r443487 = r443485 - r443486;
        double r443488 = r443484 / r443487;
        double r443489 = r443483 * r443488;
        double r443490 = r443471 / r443482;
        double r443491 = r443487 / r443472;
        double r443492 = r443490 / r443491;
        double r443493 = r443479 ? r443489 : r443492;
        return r443493;
}

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.7
Target2.1
Herbie2.4
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} \lt -2.559141628295061113708240820439530037456 \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.045027827330126029709547581125571222799 \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) < -481070734274871.1 or 1.2102113643925903e-59 < (* x 2.0)

    1. Initial program 9.7

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

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

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

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

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

      \[\leadsto \frac{1}{z \cdot \left(y - t\right)} \cdot \color{blue}{\left(x \cdot 2\right)}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt8.7

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{z} \cdot \left(\frac{\sqrt{1}}{y - t} \cdot \left(x \cdot 2\right)\right)}\]
    12. Simplified3.0

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

    if -481070734274871.1 < (* x 2.0) < 1.2102113643925903e-59

    1. Initial program 3.7

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

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019298 
(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.045027827330126e-269) (/ (* (/ x z) 2) (- y t)) (* (/ x (* (- y t) z)) 2)))

  (/ (* x 2) (- (* y z) (* t z))))