Average Error: 15.1 → 0.4
Time: 26.4s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\ \;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\
\;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\

\mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\
\;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r24413071 = x;
        double r24413072 = 2.0;
        double r24413073 = r24413071 * r24413072;
        double r24413074 = y;
        double r24413075 = r24413073 * r24413074;
        double r24413076 = r24413071 - r24413074;
        double r24413077 = r24413075 / r24413076;
        return r24413077;
}

double f(double x, double y) {
        double r24413078 = y;
        double r24413079 = -1.4392061780489917e-16;
        bool r24413080 = r24413078 <= r24413079;
        double r24413081 = x;
        double r24413082 = 2.0;
        double r24413083 = r24413081 * r24413082;
        double r24413084 = r24413081 / r24413078;
        double r24413085 = 1.0;
        double r24413086 = r24413084 - r24413085;
        double r24413087 = r24413083 / r24413086;
        double r24413088 = 2.279321042838855e-104;
        bool r24413089 = r24413078 <= r24413088;
        double r24413090 = r24413082 * r24413078;
        double r24413091 = r24413081 - r24413078;
        double r24413092 = r24413081 / r24413091;
        double r24413093 = r24413090 * r24413092;
        double r24413094 = r24413089 ? r24413093 : r24413087;
        double r24413095 = r24413080 ? r24413087 : r24413094;
        return r24413095;
}

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.1
Target0.3
Herbie0.4
\[\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 y < -1.4392061780489917e-16 or 2.279321042838855e-104 < y

    1. Initial program 14.2

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

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

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

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

    if -1.4392061780489917e-16 < y < 2.279321042838855e-104

    1. Initial program 16.4

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\ \;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \end{array}\]

Reproduce

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