Average Error: 6.7 → 2.9
Time: 15.8s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \le -4.082997335416073103530238461094942047904 \cdot 10^{-59}:\\ \;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\ \mathbf{elif}\;x \cdot 2 \le -1.26004965952634262675149776359190053847 \cdot 10^{-299}:\\ \;\;\;\;\frac{1}{\frac{z}{x} \cdot \frac{y - t}{2}}\\ \mathbf{elif}\;x \cdot 2 \le 3.150439875880527469243981674889617959112 \cdot 10^{104}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\ \end{array}\]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
\mathbf{if}\;x \cdot 2 \le -4.082997335416073103530238461094942047904 \cdot 10^{-59}:\\
\;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\

\mathbf{elif}\;x \cdot 2 \le -1.26004965952634262675149776359190053847 \cdot 10^{-299}:\\
\;\;\;\;\frac{1}{\frac{z}{x} \cdot \frac{y - t}{2}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r107192902 = x;
        double r107192903 = 2.0;
        double r107192904 = r107192902 * r107192903;
        double r107192905 = y;
        double r107192906 = z;
        double r107192907 = r107192905 * r107192906;
        double r107192908 = t;
        double r107192909 = r107192908 * r107192906;
        double r107192910 = r107192907 - r107192909;
        double r107192911 = r107192904 / r107192910;
        return r107192911;
}

double f(double x, double y, double z, double t) {
        double r107192912 = x;
        double r107192913 = 2.0;
        double r107192914 = r107192912 * r107192913;
        double r107192915 = -4.082997335416073e-59;
        bool r107192916 = r107192914 <= r107192915;
        double r107192917 = 1.0;
        double r107192918 = z;
        double r107192919 = r107192917 / r107192918;
        double r107192920 = y;
        double r107192921 = t;
        double r107192922 = r107192920 - r107192921;
        double r107192923 = r107192917 / r107192922;
        double r107192924 = r107192914 * r107192923;
        double r107192925 = r107192919 * r107192924;
        double r107192926 = -1.2600496595263426e-299;
        bool r107192927 = r107192914 <= r107192926;
        double r107192928 = r107192918 / r107192912;
        double r107192929 = r107192922 / r107192913;
        double r107192930 = r107192928 * r107192929;
        double r107192931 = r107192917 / r107192930;
        double r107192932 = 3.1504398758805275e+104;
        bool r107192933 = r107192914 <= r107192932;
        double r107192934 = r107192918 * r107192922;
        double r107192935 = r107192914 / r107192934;
        double r107192936 = r107192933 ? r107192935 : r107192925;
        double r107192937 = r107192927 ? r107192931 : r107192936;
        double r107192938 = r107192916 ? r107192925 : r107192937;
        return r107192938;
}

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.9
\[\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 (* x 2.0) < -4.082997335416073e-59 or 3.1504398758805275e+104 < (* x 2.0)

    1. Initial program 10.7

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{z}}{1} \cdot \frac{\frac{\sqrt[3]{1}}{y - t}}{\frac{1}{x \cdot 2}}}\]
    13. Simplified3.4

      \[\leadsto \color{blue}{\frac{1}{z}} \cdot \frac{\frac{\sqrt[3]{1}}{y - t}}{\frac{1}{x \cdot 2}}\]
    14. Simplified3.4

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

    if -4.082997335416073e-59 < (* x 2.0) < -1.2600496595263426e-299

    1. Initial program 3.6

      \[\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 clear-num2.7

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

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

    if -1.2600496595263426e-299 < (* x 2.0) < 3.1504398758805275e+104

    1. Initial program 3.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot 2 \le -4.082997335416073103530238461094942047904 \cdot 10^{-59}:\\ \;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\ \mathbf{elif}\;x \cdot 2 \le -1.26004965952634262675149776359190053847 \cdot 10^{-299}:\\ \;\;\;\;\frac{1}{\frac{z}{x} \cdot \frac{y - t}{2}}\\ \mathbf{elif}\;x \cdot 2 \le 3.150439875880527469243981674889617959112 \cdot 10^{104}:\\ \;\;\;\;\frac{x \cdot 2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z} \cdot \left(\left(x \cdot 2\right) \cdot \frac{1}{y - t}\right)\\ \end{array}\]

Reproduce

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