Average Error: 15.4 → 0.8
Time: 1.5s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.9668118683841495 \cdot 10^{107} \lor \neg \left(x \le 1.3220637101071684 \cdot 10^{-86}\right):\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{1 \cdot \left(\frac{x}{y} - 1\right)}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -8.9668118683841495 \cdot 10^{107} \lor \neg \left(x \le 1.3220637101071684 \cdot 10^{-86}\right):\\
\;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\

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

\end{array}
double f(double x, double y) {
        double r471336 = x;
        double r471337 = 2.0;
        double r471338 = r471336 * r471337;
        double r471339 = y;
        double r471340 = r471338 * r471339;
        double r471341 = r471336 - r471339;
        double r471342 = r471340 / r471341;
        return r471342;
}

double f(double x, double y) {
        double r471343 = x;
        double r471344 = -8.96681186838415e+107;
        bool r471345 = r471343 <= r471344;
        double r471346 = 1.3220637101071684e-86;
        bool r471347 = r471343 <= r471346;
        double r471348 = !r471347;
        bool r471349 = r471345 || r471348;
        double r471350 = 2.0;
        double r471351 = r471343 * r471350;
        double r471352 = y;
        double r471353 = r471343 - r471352;
        double r471354 = r471351 / r471353;
        double r471355 = r471354 * r471352;
        double r471356 = 1.0;
        double r471357 = r471343 / r471352;
        double r471358 = r471357 - r471356;
        double r471359 = r471356 * r471358;
        double r471360 = r471351 / r471359;
        double r471361 = r471349 ? r471355 : r471360;
        return r471361;
}

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.4
Target0.4
Herbie0.8
\[\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 2 regimes
  2. if x < -8.96681186838415e+107 or 1.3220637101071684e-86 < x

    1. Initial program 16.1

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

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

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

    if -8.96681186838415e+107 < x < 1.3220637101071684e-86

    1. Initial program 14.7

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.7

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.9668118683841495 \cdot 10^{107} \lor \neg \left(x \le 1.3220637101071684 \cdot 10^{-86}\right):\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{1 \cdot \left(\frac{x}{y} - 1\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020039 
(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)))