Average Error: 15.3 → 1.4
Time: 4.0s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(\left(x \cdot 2\right) \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{x - y} \cdot \sqrt[3]{x - y}}\right) \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{x - y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.5055267344693184 \cdot 10^{-5}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\
\;\;\;\;\left(\left(x \cdot 2\right) \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{x - y} \cdot \sqrt[3]{x - y}}\right) \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{x - y}}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.5055267344693184 \cdot 10^{-5}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r478353 = x;
        double r478354 = 2.0;
        double r478355 = r478353 * r478354;
        double r478356 = y;
        double r478357 = r478355 * r478356;
        double r478358 = r478353 - r478356;
        double r478359 = r478357 / r478358;
        return r478359;
}

double f(double x, double y) {
        double r478360 = x;
        double r478361 = 2.0;
        double r478362 = r478360 * r478361;
        double r478363 = y;
        double r478364 = r478362 * r478363;
        double r478365 = r478360 - r478363;
        double r478366 = r478364 / r478365;
        double r478367 = -0.0;
        bool r478368 = r478366 <= r478367;
        double r478369 = cbrt(r478363);
        double r478370 = r478369 * r478369;
        double r478371 = cbrt(r478365);
        double r478372 = r478371 * r478371;
        double r478373 = r478370 / r478372;
        double r478374 = r478362 * r478373;
        double r478375 = r478369 / r478371;
        double r478376 = r478374 * r478375;
        double r478377 = 1.5055267344693184e-05;
        bool r478378 = r478366 <= r478377;
        double r478379 = r478365 / r478363;
        double r478380 = r478362 / r478379;
        double r478381 = r478378 ? r478366 : r478380;
        double r478382 = r478368 ? r478376 : r478381;
        return r478382;
}

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.3
Target0.4
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \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 3 regimes
  2. if (/ (* (* x 2.0) y) (- x y)) < -0.0

    1. Initial program 19.5

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity19.5

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right)} \cdot \frac{y}{x - y}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt7.5

      \[\leadsto \left(x \cdot 2\right) \cdot \frac{y}{\color{blue}{\left(\sqrt[3]{x - y} \cdot \sqrt[3]{x - y}\right) \cdot \sqrt[3]{x - y}}}\]
    8. Applied add-cube-cbrt6.9

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

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\left(\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{x - y} \cdot \sqrt[3]{x - y}} \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{x - y}}\right)}\]
    10. Applied associate-*r*2.3

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

    if -0.0 < (/ (* (* x 2.0) y) (- x y)) < 1.5055267344693184e-05

    1. Initial program 0.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]

    if 1.5055267344693184e-05 < (/ (* (* x 2.0) y) (- x y))

    1. Initial program 31.5

      \[\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}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(\left(x \cdot 2\right) \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{x - y} \cdot \sqrt[3]{x - y}}\right) \cdot \frac{\sqrt[3]{y}}{\sqrt[3]{x - y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.5055267344693184 \cdot 10^{-5}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

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