Average Error: 7.0 → 2.5
Time: 9.0s
Precision: 64
\[\frac{x \cdot 2}{y \cdot z - t \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \le -8882633821861867 \lor \neg \left(x \cdot 2 \le 7.5458448607072867 \cdot 10^{-72}\right):\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{\frac{x}{\frac{y - t}{2}}}{z}\\ \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 -8882633821861867 \lor \neg \left(x \cdot 2 \le 7.5458448607072867 \cdot 10^{-72}\right):\\
\;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{\frac{x}{\frac{y - t}{2}}}{z}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r518788 = x;
        double r518789 = 2.0;
        double r518790 = r518788 * r518789;
        double r518791 = y;
        double r518792 = z;
        double r518793 = r518791 * r518792;
        double r518794 = t;
        double r518795 = r518794 * r518792;
        double r518796 = r518793 - r518795;
        double r518797 = r518790 / r518796;
        return r518797;
}

double f(double x, double y, double z, double t) {
        double r518798 = x;
        double r518799 = 2.0;
        double r518800 = r518798 * r518799;
        double r518801 = -8882633821861867.0;
        bool r518802 = r518800 <= r518801;
        double r518803 = 7.545844860707287e-72;
        bool r518804 = r518800 <= r518803;
        double r518805 = !r518804;
        bool r518806 = r518802 || r518805;
        double r518807 = 1.0;
        double r518808 = sqrt(r518807);
        double r518809 = r518808 / r518807;
        double r518810 = y;
        double r518811 = t;
        double r518812 = r518810 - r518811;
        double r518813 = r518812 / r518799;
        double r518814 = r518798 / r518813;
        double r518815 = z;
        double r518816 = r518814 / r518815;
        double r518817 = r518809 * r518816;
        double r518818 = r518798 / r518815;
        double r518819 = r518818 / r518813;
        double r518820 = r518806 ? r518817 : r518819;
        return r518820;
}

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

Original7.0
Target2.1
Herbie2.5
\[\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 2.0) < -8882633821861867.0 or 7.545844860707287e-72 < (* x 2.0)

    1. Initial program 10.7

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

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

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

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

      \[\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}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity3.0

      \[\leadsto \frac{1}{\color{blue}{1 \cdot z}} \cdot \frac{x}{\frac{y - t}{2}}\]
    11. Applied add-sqr-sqrt3.0

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

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

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

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

    if -8882633821861867.0 < (* x 2.0) < 7.545844860707287e-72

    1. Initial program 3.2

      \[\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 *-un-lft-identity2.0

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

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

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

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

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

Reproduce

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

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