Average Error: 14.9 → 0.5
Time: 32.2s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{elif}\;x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{\frac{\frac{x - y}{y}}{x \cdot 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17}:\\
\;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\

\mathbf{elif}\;x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}:\\
\;\;\;\;\frac{1}{\frac{\frac{x - y}{y}}{x \cdot 2}}\\

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

\end{array}
double f(double x, double y) {
        double r37565571 = x;
        double r37565572 = 2.0;
        double r37565573 = r37565571 * r37565572;
        double r37565574 = y;
        double r37565575 = r37565573 * r37565574;
        double r37565576 = r37565571 - r37565574;
        double r37565577 = r37565575 / r37565576;
        return r37565577;
}

double f(double x, double y) {
        double r37565578 = x;
        double r37565579 = -5.795611421145837e-17;
        bool r37565580 = r37565578 <= r37565579;
        double r37565581 = y;
        double r37565582 = r37565578 - r37565581;
        double r37565583 = r37565578 / r37565582;
        double r37565584 = 2.0;
        double r37565585 = r37565584 * r37565581;
        double r37565586 = r37565583 * r37565585;
        double r37565587 = 3.2475885478147857e-105;
        bool r37565588 = r37565578 <= r37565587;
        double r37565589 = 1.0;
        double r37565590 = r37565582 / r37565581;
        double r37565591 = r37565578 * r37565584;
        double r37565592 = r37565590 / r37565591;
        double r37565593 = r37565589 / r37565592;
        double r37565594 = r37565588 ? r37565593 : r37565586;
        double r37565595 = r37565580 ? r37565586 : r37565594;
        return r37565595;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
Target0.4
Herbie0.5
\[\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 < -5.795611421145837e-17 or 3.2475885478147857e-105 < x

    1. Initial program 14.4

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv12.7

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\left(x - y\right) \cdot \frac{1}{y}}}\]
    6. Applied times-frac0.8

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

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

    if -5.795611421145837e-17 < x < 3.2475885478147857e-105

    1. Initial program 15.6

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied clear-num0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{elif}\;x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{\frac{\frac{x - y}{y}}{x \cdot 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

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