Average Error: 6.8 → 3.5
Time: 11.2s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.003813290600453366675533312675622490873 \cdot 10^{-64}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\ \mathbf{elif}\;x \le 3.776987495373950477434401189617111597882 \cdot 10^{-260}:\\ \;\;\;\;\frac{2 \cdot x}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -3.003813290600453366675533312675622490873 \cdot 10^{-64}:\\
\;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r22503746 = x;
        double r22503747 = 2.0;
        double r22503748 = r22503746 * r22503747;
        double r22503749 = y;
        double r22503750 = z;
        double r22503751 = r22503749 * r22503750;
        double r22503752 = t;
        double r22503753 = r22503752 * r22503750;
        double r22503754 = r22503751 - r22503753;
        double r22503755 = r22503748 / r22503754;
        return r22503755;
}

double f(double x, double y, double z, double t) {
        double r22503756 = x;
        double r22503757 = -3.0038132906004534e-64;
        bool r22503758 = r22503756 <= r22503757;
        double r22503759 = 2.0;
        double r22503760 = r22503759 * r22503756;
        double r22503761 = y;
        double r22503762 = t;
        double r22503763 = r22503761 - r22503762;
        double r22503764 = r22503760 / r22503763;
        double r22503765 = z;
        double r22503766 = r22503764 / r22503765;
        double r22503767 = 3.7769874953739505e-260;
        bool r22503768 = r22503756 <= r22503767;
        double r22503769 = r22503765 * r22503763;
        double r22503770 = r22503760 / r22503769;
        double r22503771 = r22503768 ? r22503770 : r22503766;
        double r22503772 = r22503758 ? r22503766 : r22503771;
        return r22503772;
}

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.1
Herbie3.5
\[\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 < -3.0038132906004534e-64 or 3.7769874953739505e-260 < x

    1. Initial program 8.0

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{z} \cdot \frac{2}{\frac{y - t}{x}}}\]
    10. Using strategy rm
    11. Applied associate-*l/4.3

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

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

    if -3.0038132906004534e-64 < x < 3.7769874953739505e-260

    1. Initial program 3.4

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{z} \cdot \frac{2}{\frac{y - t}{x}}}\]
    10. Using strategy rm
    11. Applied associate-*l/10.2

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.003813290600453366675533312675622490873 \cdot 10^{-64}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\ \mathbf{elif}\;x \le 3.776987495373950477434401189617111597882 \cdot 10^{-260}:\\ \;\;\;\;\frac{2 \cdot x}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"

  :herbie-target
  (if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

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