Average Error: 14.5 → 0.1
Time: 10.1s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5429547294769742 \cdot 10^{+40}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 8733142429638575.0:\\ \;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -1.5429547294769742 \cdot 10^{+40}:\\
\;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\

\mathbf{elif}\;x \le 8733142429638575.0:\\
\;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r13704886 = x;
        double r13704887 = 2.0;
        double r13704888 = r13704886 * r13704887;
        double r13704889 = y;
        double r13704890 = r13704888 * r13704889;
        double r13704891 = r13704886 - r13704889;
        double r13704892 = r13704890 / r13704891;
        return r13704892;
}

double f(double x, double y) {
        double r13704893 = x;
        double r13704894 = -1.5429547294769742e+40;
        bool r13704895 = r13704893 <= r13704894;
        double r13704896 = 2.0;
        double r13704897 = r13704896 * r13704893;
        double r13704898 = y;
        double r13704899 = r13704893 - r13704898;
        double r13704900 = r13704897 / r13704899;
        double r13704901 = r13704900 * r13704898;
        double r13704902 = 8733142429638575.0;
        bool r13704903 = r13704893 <= r13704902;
        double r13704904 = r13704893 / r13704898;
        double r13704905 = 1.0;
        double r13704906 = r13704904 - r13704905;
        double r13704907 = r13704897 / r13704906;
        double r13704908 = r13704903 ? r13704907 : r13704901;
        double r13704909 = r13704895 ? r13704901 : r13704908;
        return r13704909;
}

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.5
Target0.4
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -1.5429547294769742e+40 or 8733142429638575.0 < x

    1. Initial program 16.6

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

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

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

    if -1.5429547294769742e+40 < x < 8733142429638575.0

    1. Initial program 12.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5429547294769742 \cdot 10^{+40}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 8733142429638575.0:\\ \;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Reproduce

herbie shell --seed 2019158 +o rules:numerics
(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)))