Average Error: 15.3 → 0.2
Time: 9.8s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.265176501060393527459433738249772183337 \cdot 10^{-8} \lor \neg \left(x \le 1.380838334167765802158493056540698774022 \cdot 10^{61}\right):\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \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}\;x \le -9.265176501060393527459433738249772183337 \cdot 10^{-8} \lor \neg \left(x \le 1.380838334167765802158493056540698774022 \cdot 10^{61}\right):\\
\;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\

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

\end{array}
double f(double x, double y) {
        double r295008 = x;
        double r295009 = 2.0;
        double r295010 = r295008 * r295009;
        double r295011 = y;
        double r295012 = r295010 * r295011;
        double r295013 = r295008 - r295011;
        double r295014 = r295012 / r295013;
        return r295014;
}

double f(double x, double y) {
        double r295015 = x;
        double r295016 = -9.265176501060394e-08;
        bool r295017 = r295015 <= r295016;
        double r295018 = 1.3808383341677658e+61;
        bool r295019 = r295015 <= r295018;
        double r295020 = !r295019;
        bool r295021 = r295017 || r295020;
        double r295022 = y;
        double r295023 = r295015 - r295022;
        double r295024 = r295015 / r295023;
        double r295025 = 2.0;
        double r295026 = r295025 * r295022;
        double r295027 = r295024 * r295026;
        double r295028 = r295015 * r295025;
        double r295029 = r295022 / r295023;
        double r295030 = r295028 * r295029;
        double r295031 = r295021 ? r295027 : r295030;
        return r295031;
}

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
Herbie0.2
\[\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 < -9.265176501060394e-08 or 1.3808383341677658e+61 < x

    1. Initial program 17.4

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

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

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

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

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

    if -9.265176501060394e-08 < x < 1.3808383341677658e+61

    1. Initial program 13.5

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{1}{\frac{x - y}{y}}}\]
    6. Simplified0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.265176501060393527459433738249772183337 \cdot 10^{-8} \lor \neg \left(x \le 1.380838334167765802158493056540698774022 \cdot 10^{61}\right):\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \end{array}\]

Reproduce

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