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

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

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

\end{array}
double f(double x, double y) {
        double r19083028 = x;
        double r19083029 = 2.0;
        double r19083030 = r19083028 * r19083029;
        double r19083031 = y;
        double r19083032 = r19083030 * r19083031;
        double r19083033 = r19083028 - r19083031;
        double r19083034 = r19083032 / r19083033;
        return r19083034;
}

double f(double x, double y) {
        double r19083035 = x;
        double r19083036 = -2.781519413694764e-10;
        bool r19083037 = r19083035 <= r19083036;
        double r19083038 = y;
        double r19083039 = 2.0;
        double r19083040 = r19083038 * r19083039;
        double r19083041 = r19083035 - r19083038;
        double r19083042 = r19083035 / r19083041;
        double r19083043 = r19083040 * r19083042;
        double r19083044 = 1.7651574500804557e+52;
        bool r19083045 = r19083035 <= r19083044;
        double r19083046 = r19083035 * r19083039;
        double r19083047 = r19083038 / r19083041;
        double r19083048 = r19083046 * r19083047;
        double r19083049 = r19083045 ? r19083048 : r19083043;
        double r19083050 = r19083037 ? r19083043 : r19083049;
        return r19083050;
}

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 < -2.781519413694764e-10 or 1.7651574500804557e+52 < x

    1. Initial program 15.2

      \[\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 div-inv16.9

      \[\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.1

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

    if -2.781519413694764e-10 < x < 1.7651574500804557e+52

    1. Initial program 13.8

      \[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity13.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.781519413694764 \cdot 10^{-10}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 1.7651574500804557 \cdot 10^{+52}:\\ \;\;\;\;\left(x \cdot 2.0\right) \cdot \frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \end{array}\]

Reproduce

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