Average Error: 6.6 → 2.4
Time: 11.8s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.037157504084274034815349795281714872542 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \mathbf{elif}\;z \le 3.818366843617034597316373479678641130316 \cdot 10^{83}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -2.037157504084274034815349795281714872542 \cdot 10^{-36}:\\
\;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r453634 = x;
        double r453635 = 2.0;
        double r453636 = r453634 * r453635;
        double r453637 = y;
        double r453638 = z;
        double r453639 = r453637 * r453638;
        double r453640 = t;
        double r453641 = r453640 * r453638;
        double r453642 = r453639 - r453641;
        double r453643 = r453636 / r453642;
        return r453643;
}

double f(double x, double y, double z, double t) {
        double r453644 = z;
        double r453645 = -2.037157504084274e-36;
        bool r453646 = r453644 <= r453645;
        double r453647 = x;
        double r453648 = 2.0;
        double r453649 = r453647 * r453648;
        double r453650 = r453649 / r453644;
        double r453651 = y;
        double r453652 = t;
        double r453653 = r453651 - r453652;
        double r453654 = r453650 / r453653;
        double r453655 = 3.8183668436170346e+83;
        bool r453656 = r453644 <= r453655;
        double r453657 = r453644 * r453653;
        double r453658 = r453649 / r453657;
        double r453659 = r453649 / r453653;
        double r453660 = r453659 / r453644;
        double r453661 = r453656 ? r453658 : r453660;
        double r453662 = r453646 ? r453654 : r453661;
        return r453662;
}

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.6
Target2.2
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 3 regimes
  2. if z < -2.037157504084274e-36

    1. Initial program 9.3

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

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

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

    if -2.037157504084274e-36 < z < 3.8183668436170346e+83

    1. Initial program 2.5

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{1}{z \cdot \left(y - t\right)}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt2.9

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

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

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

      \[\leadsto \left(x \cdot 2\right) \cdot \left(\frac{1}{z} \cdot \color{blue}{\frac{1}{y - t}}\right)\]
    10. Using strategy rm
    11. Applied frac-times2.9

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\frac{1 \cdot 1}{z \cdot \left(y - t\right)}}\]
    12. Applied associate-*r/2.5

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

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

    if 3.8183668436170346e+83 < z

    1. Initial program 12.9

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{1}{z \cdot \left(y - t\right)}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt10.3

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

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

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

      \[\leadsto \left(x \cdot 2\right) \cdot \left(\frac{1}{z} \cdot \color{blue}{\frac{1}{y - t}}\right)\]
    10. Using strategy rm
    11. Applied pow19.6

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

      \[\leadsto \left(x \cdot 2\right) \cdot \left(\color{blue}{{\left(\frac{1}{z}\right)}^{1}} \cdot {\left(\frac{1}{y - t}\right)}^{1}\right)\]
    13. Applied pow-prod-down9.6

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

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

      \[\leadsto \left(\color{blue}{{x}^{1}} \cdot {2}^{1}\right) \cdot {\left(\frac{1}{z} \cdot \frac{1}{y - t}\right)}^{1}\]
    16. Applied pow-prod-down9.6

      \[\leadsto \color{blue}{{\left(x \cdot 2\right)}^{1}} \cdot {\left(\frac{1}{z} \cdot \frac{1}{y - t}\right)}^{1}\]
    17. Applied pow-prod-down9.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.037157504084274034815349795281714872542 \cdot 10^{-36}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \mathbf{elif}\;z \le 3.818366843617034597316373479678641130316 \cdot 10^{83}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{y - t}}{z}\\ \end{array}\]

Reproduce

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

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