Average Error: 14.8 → 0.2
Time: 2.0s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -4.83541869403854545 \cdot 10^{-17}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;y \le 9.96429858992283365 \cdot 10^{-58}:\\ \;\;\;\;\frac{1}{\frac{x - y}{x \cdot 2}} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -4.83541869403854545 \cdot 10^{-17}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

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

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

\end{array}
double f(double x, double y) {
        double r490502 = x;
        double r490503 = 2.0;
        double r490504 = r490502 * r490503;
        double r490505 = y;
        double r490506 = r490504 * r490505;
        double r490507 = r490502 - r490505;
        double r490508 = r490506 / r490507;
        return r490508;
}

double f(double x, double y) {
        double r490509 = y;
        double r490510 = -4.8354186940385455e-17;
        bool r490511 = r490509 <= r490510;
        double r490512 = x;
        double r490513 = 2.0;
        double r490514 = r490512 * r490513;
        double r490515 = r490512 - r490509;
        double r490516 = r490515 / r490509;
        double r490517 = r490514 / r490516;
        double r490518 = 9.964298589922834e-58;
        bool r490519 = r490509 <= r490518;
        double r490520 = 1.0;
        double r490521 = r490515 / r490514;
        double r490522 = r490520 / r490521;
        double r490523 = r490522 * r490509;
        double r490524 = r490509 / r490515;
        double r490525 = r490514 * r490524;
        double r490526 = r490519 ? r490523 : r490525;
        double r490527 = r490511 ? r490517 : r490526;
        return r490527;
}

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.8
Target0.3
Herbie0.2
\[\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 y < -4.8354186940385455e-17

    1. Initial program 14.8

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

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

    if -4.8354186940385455e-17 < y < 9.964298589922834e-58

    1. Initial program 15.2

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

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

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

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

    if 9.964298589922834e-58 < y

    1. Initial program 14.1

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

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

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

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

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

Reproduce

herbie shell --seed 2020035 +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)))