Average Error: 14.9 → 0.1
Time: 26.4s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -817211854313671552:\\ \;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{x}}{2}}\\ \mathbf{elif}\;y \le 4.039124438402000313213123565631371136853 \cdot 10^{-9}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -817211854313671552:\\
\;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{x}}{2}}\\

\mathbf{elif}\;y \le 4.039124438402000313213123565631371136853 \cdot 10^{-9}:\\
\;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\

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

\end{array}
double f(double x, double y) {
        double r174021 = x;
        double r174022 = 2.0;
        double r174023 = r174021 * r174022;
        double r174024 = y;
        double r174025 = r174023 * r174024;
        double r174026 = r174021 - r174024;
        double r174027 = r174025 / r174026;
        return r174027;
}

double f(double x, double y) {
        double r174028 = y;
        double r174029 = -8.172118543136716e+17;
        bool r174030 = r174028 <= r174029;
        double r174031 = 1.0;
        double r174032 = x;
        double r174033 = r174032 / r174028;
        double r174034 = r174033 - r174031;
        double r174035 = r174034 / r174032;
        double r174036 = 2.0;
        double r174037 = r174035 / r174036;
        double r174038 = r174031 / r174037;
        double r174039 = 4.039124438402e-09;
        bool r174040 = r174028 <= r174039;
        double r174041 = r174032 * r174036;
        double r174042 = r174032 - r174028;
        double r174043 = r174041 / r174042;
        double r174044 = r174043 * r174028;
        double r174045 = r174041 / r174034;
        double r174046 = r174040 ? r174044 : r174045;
        double r174047 = r174030 ? r174038 : r174046;
        return r174047;
}

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.1
\[\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 3 regimes
  2. if y < -8.172118543136716e+17

    1. Initial program 17.3

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

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

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

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

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

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

      \[\leadsto \frac{x \cdot 2}{1 \cdot \color{blue}{\left(\frac{x}{y} - 1\right)}}\]
    9. Using strategy rm
    10. Applied clear-num0.2

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

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

    if -8.172118543136716e+17 < y < 4.039124438402e-09

    1. Initial program 13.3

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity15.0

      \[\leadsto \frac{x \cdot 2}{\frac{x - y}{\color{blue}{1 \cdot y}}}\]
    5. Applied *-un-lft-identity15.0

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

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{2}{x - y} \cdot y\right)}\]
    10. Using strategy rm
    11. Applied associate-*r*0.2

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

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

    if 4.039124438402e-09 < y

    1. Initial program 15.7

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -817211854313671552:\\ \;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{x}}{2}}\\ \mathbf{elif}\;y \le 4.039124438402000313213123565631371136853 \cdot 10^{-9}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \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)))