Average Error: 15.6 → 0.2
Time: 27.9s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.765741735083720076145748917317845894104 \cdot 10^{-6} \lor \neg \left(y \le 1.933492041772309948480324899511033862876 \cdot 10^{50}\right):\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot y\right) \cdot \frac{x}{x - y}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -1.765741735083720076145748917317845894104 \cdot 10^{-6} \lor \neg \left(y \le 1.933492041772309948480324899511033862876 \cdot 10^{50}\right):\\
\;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r320813 = x;
        double r320814 = 2.0;
        double r320815 = r320813 * r320814;
        double r320816 = y;
        double r320817 = r320815 * r320816;
        double r320818 = r320813 - r320816;
        double r320819 = r320817 / r320818;
        return r320819;
}

double f(double x, double y) {
        double r320820 = y;
        double r320821 = -1.76574173508372e-06;
        bool r320822 = r320820 <= r320821;
        double r320823 = 1.93349204177231e+50;
        bool r320824 = r320820 <= r320823;
        double r320825 = !r320824;
        bool r320826 = r320822 || r320825;
        double r320827 = x;
        double r320828 = 2.0;
        double r320829 = r320827 * r320828;
        double r320830 = r320827 / r320820;
        double r320831 = 1.0;
        double r320832 = r320830 - r320831;
        double r320833 = r320829 / r320832;
        double r320834 = r320828 * r320820;
        double r320835 = r320827 - r320820;
        double r320836 = r320827 / r320835;
        double r320837 = r320834 * r320836;
        double r320838 = r320826 ? r320833 : r320837;
        return r320838;
}

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.6
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 y < -1.76574173508372e-06 or 1.93349204177231e+50 < y

    1. Initial program 17.6

      \[\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)}}\]

    if -1.76574173508372e-06 < y < 1.93349204177231e+50

    1. Initial program 13.8

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.765741735083720076145748917317845894104 \cdot 10^{-6} \lor \neg \left(y \le 1.933492041772309948480324899511033862876 \cdot 10^{50}\right):\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot y\right) \cdot \frac{x}{x - y}\\ \end{array}\]

Reproduce

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