Average Error: 15.0 → 0.3
Time: 12.9s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -812775362484110256794557743104 \lor \neg \left(x \le 3.77258026262028000276346495510928850917 \cdot 10^{-75}\right):\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{-1 + \frac{x}{y}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -812775362484110256794557743104 \lor \neg \left(x \le 3.77258026262028000276346495510928850917 \cdot 10^{-75}\right):\\
\;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 2}{-1 + \frac{x}{y}}\\

\end{array}
double f(double x, double y) {
        double r434890 = x;
        double r434891 = 2.0;
        double r434892 = r434890 * r434891;
        double r434893 = y;
        double r434894 = r434892 * r434893;
        double r434895 = r434890 - r434893;
        double r434896 = r434894 / r434895;
        return r434896;
}

double f(double x, double y) {
        double r434897 = x;
        double r434898 = -8.127753624841103e+29;
        bool r434899 = r434897 <= r434898;
        double r434900 = 3.77258026262028e-75;
        bool r434901 = r434897 <= r434900;
        double r434902 = !r434901;
        bool r434903 = r434899 || r434902;
        double r434904 = 2.0;
        double r434905 = r434897 * r434904;
        double r434906 = y;
        double r434907 = r434897 - r434906;
        double r434908 = r434905 / r434907;
        double r434909 = r434908 * r434906;
        double r434910 = -1.0;
        double r434911 = r434897 / r434906;
        double r434912 = r434910 + r434911;
        double r434913 = r434905 / r434912;
        double r434914 = r434903 ? r434909 : r434913;
        return r434914;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.0
Target0.3
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt -1.721044263414944729490876394165887012892 \cdot 10^{81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 83645045635564432:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -8.127753624841103e+29 or 3.77258026262028e-75 < x

    1. Initial program 15.2

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*12.9

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied associate-/r/0.5

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

    if -8.127753624841103e+29 < x < 3.77258026262028e-75

    1. Initial program 14.7

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*0.1

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Taylor expanded around 0 0.1

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\frac{x}{y} - 1}}\]
    5. Simplified0.1

      \[\leadsto \frac{x \cdot 2}{\color{blue}{-1 + \frac{x}{y}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -812775362484110256794557743104 \lor \neg \left(x \le 3.77258026262028000276346495510928850917 \cdot 10^{-75}\right):\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{-1 + \frac{x}{y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019306 +o rules:numerics
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

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